88 DynamicFormLayoutService ,
99 DynamicFormValidationService
1010} from '@ng-dynamic-forms/core' ;
11- import { distinctUntilChanged , filter , map , take } from 'rxjs/operators' ;
11+ import { distinctUntilChanged , filter , map , take , tap } from 'rxjs/operators' ;
1212import { Observable , of as observableOf } from 'rxjs' ;
1313import { NgbModal } from '@ng-bootstrap/ng-bootstrap' ;
1414
@@ -61,6 +61,8 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
6161 public otherInfoValues : string [ ] = [ ] ;
6262 public otherInfoValuesUnformatted : string [ ] = [ ] ;
6363
64+ multiValueOnGenerator : boolean ;
65+
6466 protected constructor ( protected vocabularyService : VocabularyService ,
6567 protected layoutService : DynamicFormLayoutService ,
6668 protected validationService : DynamicFormValidationService ,
@@ -174,6 +176,7 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
174176 this . vocabulary$ = this . vocabularyService . findVocabularyById ( this . model . vocabularyOptions . name ) . pipe (
175177 getFirstSucceededRemoteDataPayload ( ) ,
176178 distinctUntilChanged ( ) ,
179+ tap ( ( vocabulary : Vocabulary ) => this . multiValueOnGenerator = vocabulary . multiValueOnGenerator ) ,
177180 ) ;
178181 }
179182
@@ -256,12 +259,14 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
256259 for ( const key in otherInformation ) {
257260 if ( otherInformation . hasOwnProperty ( key ) && key . startsWith ( 'data-' ) ) {
258261 const fieldId = key . replace ( 'data-' , '' ) ;
259- const newValue : FormFieldMetadataValueObject = this . getOtherInformationValue ( otherInformation [ key ] , key ) ;
260- if ( isNotEmpty ( newValue ) ) {
261- const updatedModel = this . formBuilderService . updateModelValue ( fieldId , newValue ) ;
262- if ( isNotEmpty ( updatedModel ) ) {
263- updatedModels . push ( updatedModel ) ;
264- }
262+ const newValues : FormFieldMetadataValueObject [ ] = this . getOtherInformationValue ( otherInformation [ key ] , key ) ;
263+ if ( isNotEmpty ( newValues ) ) {
264+ newValues . forEach ( ( newValue ) => {
265+ const updatedModel = this . formBuilderService . updateModelValue ( fieldId , newValue ) ;
266+ if ( isNotEmpty ( updatedModel ) ) {
267+ updatedModels . push ( updatedModel ) ;
268+ }
269+ } ) ;
265270 }
266271 }
267272 }
@@ -276,43 +281,53 @@ export abstract class DsDynamicVocabularyComponent extends DynamicFormControlCom
276281 }
277282 }
278283
279- getOtherInformationValue ( value : string , key : string ) : FormFieldMetadataValueObject {
284+ getOtherInformationValue ( value : string , key : string ) : FormFieldMetadataValueObject [ ] {
280285 if ( isEmpty ( value ) || key === 'alternative-names' ) {
281286 return null ;
282287 }
283288
284- let returnValue ;
289+ let returnValue = [ ] ;
290+ if ( value . indexOf ( '|||' ) === - 1 ) {
291+ returnValue . push ( this . generateFormField ( value ) ) ;
292+ } else if ( value . indexOf ( '|||' ) !== - 1 && this . otherInfoValue ) {
293+ const otherValues : string [ ] = value . split ( '|||' ) ;
294+ if ( this . multiValueOnGenerator ) {
295+ otherValues . forEach ( ( tmpValue ) => returnValue . push ( this . generateFormField ( tmpValue ) ) ) ;
296+ } else {
297+ const unformattedValue = this . otherInfoValuesUnformatted . find ( otherInfoValue => otherInfoValue . includes ( this . otherInfoValue || this . otherName ) ) ;
298+ const authorityValue = hasValue ( unformattedValue ) ? unformattedValue . substring ( unformattedValue . lastIndexOf ( '::' ) + 2 ) : null ;
299+ let otherInfo = { } ;
300+ let alternativeValue : string ;
301+ otherInfo [ key ] = value ;
302+ if ( hasValue ( this . otherName ) ) {
303+ alternativeValue = otherValues [ 0 ] . substring ( 0 , otherValues [ 0 ] . lastIndexOf ( '::' ) ) ;
304+ }
305+ returnValue . push ( new FormFieldMetadataValueObject (
306+ hasValue ( alternativeValue ) ? alternativeValue : this . otherInfoValue ,
307+ null ,
308+ null ,
309+ authorityValue ,
310+ null ,
311+ null ,
312+ null ,
313+ otherInfo
314+ ) ) ;
315+ }
316+ }
317+ return returnValue ;
318+ }
319+
320+ private generateFormField ( value : string ) : FormFieldMetadataValueObject {
285321 if ( value . indexOf ( '::' ) === - 1 ) {
286- returnValue = new FormFieldMetadataValueObject ( value ) ;
287- } else if ( value . indexOf ( '|||' ) === - 1 ) {
288- returnValue = new FormFieldMetadataValueObject (
322+ return new FormFieldMetadataValueObject ( value ) ;
323+ } else {
324+ return new FormFieldMetadataValueObject (
289325 value . substring ( 0 , value . lastIndexOf ( '::' ) ) ,
290326 null ,
291327 null ,
292328 value . substring ( value . lastIndexOf ( '::' ) + 2 )
293329 ) ;
294- } else if ( value . indexOf ( '|||' ) !== - 1 && this . otherInfoValue ) {
295- const unformattedValue = this . otherInfoValuesUnformatted . find ( otherInfoValue => otherInfoValue . includes ( this . otherInfoValue || this . otherName ) ) ;
296- const authorityValue = hasValue ( unformattedValue ) ? unformattedValue . substring ( unformattedValue . lastIndexOf ( '::' ) + 2 ) : null ;
297- let otherInfo = { } ;
298- let alternativeValue ;
299- otherInfo [ key ] = value ;
300- if ( hasValue ( this . otherName ) ) {
301- const otherValues = value . split ( '|||' ) ;
302- alternativeValue = otherValues [ 0 ] . substring ( 0 , otherValues [ 0 ] . lastIndexOf ( '::' ) ) ;
303- }
304- returnValue = new FormFieldMetadataValueObject (
305- hasValue ( alternativeValue ) ? alternativeValue : this . otherInfoValue ,
306- null ,
307- null ,
308- authorityValue ,
309- null ,
310- null ,
311- null ,
312- otherInfo
313- ) ;
314330 }
315- return returnValue ;
316331 }
317332
318333 private hasValidAuthority ( formMetadataValue : FormFieldMetadataValueObject ) {
0 commit comments