11import { HttpErrorResponse } from '@angular/common/http' ;
22import { 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' ;
45import { APIService } from '@services/api.service' ;
56import { AuthService } from '@services/auth.service' ;
67import { APIItem } from '@services/item' ;
8+ import { LanguageService } from '@services/language' ;
79import { UserService } from '@services/user' ;
810import {
911 getAttrDescriptionTranslation ,
@@ -21,7 +23,6 @@ import {
2123 APIAttrUnit ,
2224 APIAttrUserValue ,
2325 APIAttrUserValueGetResponse ,
24- APIAttrValue ,
2526 AttrAttributeTreeItem ,
2627} from '../../../api/attrs/attrs.service' ;
2728import { 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