1
1
import { HttpErrorResponse } from '@angular/common/http' ;
2
2
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' ;
4
5
import { APIService } from '@services/api.service' ;
5
6
import { AuthService } from '@services/auth.service' ;
6
7
import { APIItem } from '@services/item' ;
8
+ import { LanguageService } from '@services/language' ;
7
9
import { UserService } from '@services/user' ;
8
10
import {
9
11
getAttrDescriptionTranslation ,
@@ -21,7 +23,6 @@ import {
21
23
APIAttrUnit ,
22
24
APIAttrUserValue ,
23
25
APIAttrUserValueGetResponse ,
24
- APIAttrValue ,
25
26
AttrAttributeTreeItem ,
26
27
} from '../../../api/attrs/attrs.service' ;
27
28
import { ToastsService } from '../../../toasts/toasts.service' ;
@@ -130,6 +131,8 @@ export class CarsSpecificationsEditorSpecComponent {
130
131
private readonly auth : AuthService ,
131
132
private readonly toastService : ToastsService ,
132
133
private readonly userService : UserService ,
134
+ private readonly attrsClient : AttrsClient ,
135
+ private readonly languageService : LanguageService ,
133
136
) { }
134
137
135
138
private applyUserValues ( userValues : Map < number , AttrUserValueWithUser [ ] > , items : APIAttrUserValue [ ] ) {
@@ -148,18 +151,19 @@ export class CarsSpecificationsEditorSpecComponent {
148
151
protected readonly values$ = combineLatest ( [ this . item$ , this . change$ ] ) . pipe (
149
152
switchMap ( ( [ item ] ) =>
150
153
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
+ )
157
161
: EMPTY ,
158
162
) ,
159
163
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 ) ;
163
167
}
164
168
return values ;
165
169
} ) ,
@@ -197,6 +201,19 @@ export class CarsSpecificationsEditorSpecComponent {
197
201
value . value = + value . value ;
198
202
}
199
203
}
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
+
200
217
if ( attribute && attribute . isMultiple ) {
201
218
if ( ! ( value . value instanceof Array ) ) {
202
219
value . value = [ value . value ? value . value . toString ( ) : '' ] ;
0 commit comments