@@ -22,6 +22,7 @@ import {
2222 filter ,
2323 map ,
2424 take ,
25+ tap ,
2526} from 'rxjs/operators' ;
2627
2728import { Metadata } from '../../../../../core/shared/metadata.utils' ;
@@ -76,6 +77,8 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
7677 public otherInfoValues : string [ ] = [ ] ;
7778 public otherInfoValuesUnformatted : string [ ] = [ ] ;
7879
80+ multiValueOnGenerator : boolean ;
81+
7982 protected constructor ( protected vocabularyService : VocabularyService ,
8083 protected layoutService : DynamicFormLayoutService ,
8184 protected validationService : DynamicFormValidationService ,
@@ -195,6 +198,7 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
195198 this . vocabulary$ = this . vocabularyService . findVocabularyById ( this . model . vocabularyOptions . name ) . pipe (
196199 getFirstSucceededRemoteDataPayload ( ) ,
197200 distinctUntilChanged ( ) ,
201+ tap ( ( vocabulary : Vocabulary ) => this . multiValueOnGenerator = vocabulary . multiValueOnGenerator ) ,
198202 ) ;
199203 }
200204
@@ -277,12 +281,14 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
277281 for ( const key in otherInformation ) {
278282 if ( otherInformation . hasOwnProperty ( key ) && key . startsWith ( 'data-' ) ) {
279283 const fieldId = key . replace ( 'data-' , '' ) ;
280- const newValue : FormFieldMetadataValueObject = this . getOtherInformationValue ( otherInformation [ key ] , key ) ;
281- if ( isNotEmpty ( newValue ) ) {
282- const updatedModel = this . formBuilderService . updateModelValue ( fieldId , newValue ) ;
283- if ( isNotEmpty ( updatedModel ) ) {
284- updatedModels . push ( updatedModel ) ;
285- }
284+ const newValues : FormFieldMetadataValueObject [ ] = this . getOtherInformationValue ( otherInformation [ key ] , key ) ;
285+ if ( isNotEmpty ( newValues ) ) {
286+ newValues . forEach ( ( newValue ) => {
287+ const updatedModel = this . formBuilderService . updateModelValue ( fieldId , newValue ) ;
288+ if ( isNotEmpty ( updatedModel ) ) {
289+ updatedModels . push ( updatedModel ) ;
290+ }
291+ } ) ;
286292 }
287293 }
288294 }
@@ -297,43 +303,53 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
297303 }
298304 }
299305
300- getOtherInformationValue ( value : string , key : string ) : FormFieldMetadataValueObject {
306+ getOtherInformationValue ( value : string , key : string ) : FormFieldMetadataValueObject [ ] {
301307 if ( isEmpty ( value ) || key === 'alternative-names' ) {
302308 return null ;
303309 }
304310
305- let returnValue ;
311+ const returnValue = [ ] ;
312+ if ( value . indexOf ( '|||' ) === - 1 ) {
313+ returnValue . push ( this . generateFormField ( value ) ) ;
314+ } else if ( value . indexOf ( '|||' ) !== - 1 && this . otherInfoValue ) {
315+ const otherValues : string [ ] = value . split ( '|||' ) ;
316+ if ( this . multiValueOnGenerator ) {
317+ otherValues . forEach ( ( tmpValue ) => returnValue . push ( this . generateFormField ( tmpValue ) ) ) ;
318+ } else {
319+ const unformattedValue = this . otherInfoValuesUnformatted . find ( otherInfoValue => otherInfoValue . includes ( this . otherInfoValue || this . otherName ) ) ;
320+ const authorityValue = hasValue ( unformattedValue ) ? unformattedValue . substring ( unformattedValue . lastIndexOf ( '::' ) + 2 ) : null ;
321+ const otherInfo = { } ;
322+ let alternativeValue : string ;
323+ otherInfo [ key ] = value ;
324+ if ( hasValue ( this . otherName ) ) {
325+ alternativeValue = otherValues [ 0 ] . substring ( 0 , otherValues [ 0 ] . lastIndexOf ( '::' ) ) ;
326+ }
327+ returnValue . push ( new FormFieldMetadataValueObject (
328+ hasValue ( alternativeValue ) ? alternativeValue : this . otherInfoValue ,
329+ null ,
330+ null ,
331+ authorityValue ,
332+ null ,
333+ null ,
334+ null ,
335+ otherInfo ,
336+ ) ) ;
337+ }
338+ }
339+ return returnValue ;
340+ }
341+
342+ private generateFormField ( value : string ) : FormFieldMetadataValueObject {
306343 if ( value . indexOf ( '::' ) === - 1 ) {
307- returnValue = new FormFieldMetadataValueObject ( value ) ;
308- } else if ( value . indexOf ( '|||' ) === - 1 ) {
309- returnValue = new FormFieldMetadataValueObject (
344+ return new FormFieldMetadataValueObject ( value ) ;
345+ } else {
346+ return new FormFieldMetadataValueObject (
310347 value . substring ( 0 , value . lastIndexOf ( '::' ) ) ,
311348 null ,
312349 null ,
313350 value . substring ( value . lastIndexOf ( '::' ) + 2 ) ,
314351 ) ;
315- } else if ( value . indexOf ( '|||' ) !== - 1 && this . otherInfoValue ) {
316- const unformattedValue = this . otherInfoValuesUnformatted . find ( otherInfoValue => otherInfoValue . includes ( this . otherInfoValue || this . otherName ) ) ;
317- const authorityValue = hasValue ( unformattedValue ) ? unformattedValue . substring ( unformattedValue . lastIndexOf ( '::' ) + 2 ) : null ;
318- const otherInfo = { } ;
319- let alternativeValue ;
320- otherInfo [ key ] = value ;
321- if ( hasValue ( this . otherName ) ) {
322- const otherValues = value . split ( '|||' ) ;
323- alternativeValue = otherValues [ 0 ] . substring ( 0 , otherValues [ 0 ] . lastIndexOf ( '::' ) ) ;
324- }
325- returnValue = new FormFieldMetadataValueObject (
326- hasValue ( alternativeValue ) ? alternativeValue : this . otherInfoValue ,
327- null ,
328- null ,
329- authorityValue ,
330- null ,
331- null ,
332- null ,
333- otherInfo ,
334- ) ;
335352 }
336- return returnValue ;
337353 }
338354
339355 private hasValidAuthority ( formMetadataValue : FormFieldMetadataValueObject ) {
0 commit comments