Skip to content

Commit fdb88bf

Browse files
committed
feat: attrs values in editor using gRPC API
1 parent 019a4ea commit fdb88bf

File tree

5 files changed

+872
-17
lines changed

5 files changed

+872
-17
lines changed

src/app/api/attrs/attrs.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface APIAttrValuesGetOptions {
5656
export interface APIAttrValue {
5757
attribute_id: number;
5858
value: APIAttrAttributeValue;
59+
value_text: string;
5960
}
6061

6162
export interface APIAttrValuesGetResponse {

src/app/cars/specifications-editor/spec/spec.component.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ <h4>{{ getAttrsTranslation(attribute.name) }}</h4>
5757
[class.is-invalid]="invalidParams && invalidParams.items[+attribute.id]"
5858
>
5959
@for (option of attribute.options$ | async; track option.id) {
60-
<option [value]="option.id">
60+
<option [ngValue]="option.id">
6161
{{ option.name }}
6262
</option>
6363
}
@@ -74,7 +74,7 @@ <h4>{{ getAttrsTranslation(attribute.name) }}</h4>
7474
[class.is-invalid]="invalidParams && invalidParams.items[+attribute.id]"
7575
>
7676
@for (option of attribute.options$ | async; track option.id) {
77-
<option [value]="option.id">
77+
<option [ngValue]="option.id">
7878
{{ option.name }}
7979
</option>
8080
}
@@ -91,7 +91,7 @@ <h4>{{ getAttrsTranslation(attribute.name) }}</h4>
9191
style="height: 100%"
9292
>
9393
@for (option of attribute.options$ | async; track option.id) {
94-
<option [value]="option.id">
94+
<option [ngValue]="option.id">
9595
{{ option.name }}
9696
</option>
9797
}
@@ -152,13 +152,13 @@ <h4>{{ getAttrsTranslation(attribute.name) }}</h4>
152152
</td>
153153
<td class="actual">
154154
@if (values$ | async; as values) {
155-
@if (values.has(+attribute.id)) {
155+
@if (values.get(attribute.id); as value) {
156156
<div>
157-
@if (values.get(+attribute.id)['value'] === null) {
157+
@if (value.value.isEmpty) {
158158
<em i18n>none</em>
159159
} @else {
160160
<span>
161-
{{ values.get(+attribute.id)['value_text'] }}
161+
{{ value.valueText }}
162162
@if (attribute.unitId !== '0') {
163163
<span
164164
class="unit"

src/app/cars/specifications-editor/spec/spec.component.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {HttpErrorResponse} from '@angular/common/http';
22
import {Component, Input} from '@angular/core';
3-
import {APIUser, AttrAttributeType, AttrListOption} from '@grpc/spec.pb';
3+
import {APIUser, AttrAttributeType, AttrListOption, AttrValue, AttrValuesRequest} from '@grpc/spec.pb';
4+
import {AttrsClient} from '@grpc/spec.pbsc';
45
import {APIService} from '@services/api.service';
56
import {AuthService} from '@services/auth.service';
67
import {APIItem} from '@services/item';
8+
import {LanguageService} from '@services/language';
79
import {UserService} from '@services/user';
810
import {
911
getAttrDescriptionTranslation,
@@ -21,7 +23,6 @@ import {
2123
APIAttrUnit,
2224
APIAttrUserValue,
2325
APIAttrUserValueGetResponse,
24-
APIAttrValue,
2526
AttrAttributeTreeItem,
2627
} from '../../../api/attrs/attrs.service';
2728
import {ToastsService} from '../../../toasts/toasts.service';
@@ -130,6 +131,8 @@ export class CarsSpecificationsEditorSpecComponent {
130131
private readonly auth: AuthService,
131132
private readonly toastService: ToastsService,
132133
private readonly userService: UserService,
134+
private readonly attrsClient: AttrsClient,
135+
private readonly languageService: LanguageService,
133136
) {}
134137

135138
private applyUserValues(userValues: Map<number, AttrUserValueWithUser[]>, items: APIAttrUserValue[]) {
@@ -148,18 +151,19 @@ export class CarsSpecificationsEditorSpecComponent {
148151
protected readonly values$ = combineLatest([this.item$, this.change$]).pipe(
149152
switchMap(([item]) =>
150153
item
151-
? this.attrsService.getValues$({
152-
fields: 'value,value_text',
153-
item_id: item.id,
154-
limit: 500,
155-
zone_id: item.attr_zone_id,
156-
})
154+
? this.attrsClient.getValues(
155+
new AttrValuesRequest({
156+
itemId: '' + item.id,
157+
language: this.languageService.language,
158+
zoneId: '' + item.attr_zone_id,
159+
}),
160+
)
157161
: EMPTY,
158162
),
159163
map((response) => {
160-
const values = new Map<number, APIAttrValue>();
161-
for (const value of response.items) {
162-
values.set(value.attribute_id, value);
164+
const values = new Map<string, AttrValue>();
165+
for (const value of response?.items || []) {
166+
values.set(value.attributeId, value);
163167
}
164168
return values;
165169
}),
@@ -197,6 +201,19 @@ export class CarsSpecificationsEditorSpecComponent {
197201
value.value = +value.value;
198202
}
199203
}
204+
205+
// cast list user values to string
206+
if (
207+
attribute &&
208+
(attribute.typeId === AttrAttributeType.Id.LIST ||
209+
attribute.typeId === AttrAttributeType.Id.TREE ||
210+
attribute.typeId === AttrAttributeType.Id.BOOLEAN)
211+
) {
212+
if (value.value !== null) {
213+
value.value = '' + value.value;
214+
}
215+
}
216+
200217
if (attribute && attribute.isMultiple) {
201218
if (!(value.value instanceof Array)) {
202219
value.value = [value.value ? value.value.toString() : ''];

0 commit comments

Comments
 (0)