Skip to content

Commit b3cae70

Browse files
committed
[DSC-1379] feature: init security level for chips group
1 parent e0a9e40 commit b3cae70

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

src/app/shared/form/builder/ds-dynamic-form-ui/models/relation-group/modal/dynamic-relation-group-modal.components.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
6969

7070
public formModel: DynamicFormControlModel[];
7171
public vocabulary$: Observable<Vocabulary>;
72+
public securityLevelParent: number;
7273

7374
private subs: Subscription[] = [];
7475

@@ -113,10 +114,8 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
113114
if (isNotEmpty(nextValue)) {
114115
model.value = nextValue;
115116
}
116-
// as the value doesn't support the security level, add into the big model
117-
if (value && typeof value !== 'string') {
118-
(model as any).securityLevel = value.securityLevel;
119-
}
117+
118+
this.initSecurityLevelConfig(model, modelRow);
120119
});
121120
});
122121
}
@@ -262,6 +261,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
262261
modelRow.group.forEach((model: DynamicInputModel) => {
263262
if (model.name === this.model.mandatoryField) {
264263
mandatoryFieldModel = model;
264+
this.initSecurityLevelConfig(model, modelRow);
265265
return;
266266
}
267267
});
@@ -293,12 +293,16 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
293293
const item = Object.create({});
294294
this.formModel.forEach((row) => {
295295
const modelRow = row as DynamicFormGroupModel;
296+
const mainRow = modelRow.group.find(model => model.name === this.model.name);
296297
modelRow.group.forEach((control: DynamicInputModel) => {
297298
const controlValue: any = (control?.value as any)?.value || control?.value || PLACEHOLDER_PARENT_METADATA;
298299
const controlAuthority: any = (control?.value as any)?.authority || null;
300+
299301
item[control.name] =
300302
new FormFieldMetadataValueObject(
301-
controlValue, (control as any)?.language, (control as any)?.securityLevel, controlAuthority,
303+
controlValue, (control as any)?.language,
304+
(mainRow as any).securityLevel,
305+
controlAuthority,
302306
null, 0, null,
303307
(control?.value as any)?.otherInformation || null
304308
);
@@ -307,6 +311,26 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
307311
return item;
308312
}
309313

314+
private initSecurityLevelConfig(chipModel: DynamicInputModel, modelGroup: DynamicFormGroupModel) {
315+
if (this.model.name === chipModel.name) {
316+
if (modelGroup.group.some((item: any) => item.securityConfigLevel.length > 0)) {
317+
(chipModel as any).securityConfigLevel = [0, 1, 2];
318+
(chipModel as any).toggleSecurityVisibility = true;
319+
}
320+
321+
const mainRow = modelGroup.group.find(itemModel => itemModel.name === this.model.name);
322+
323+
(chipModel as any).securityLevel = (mainRow as any).securityLevel || 0;
324+
this.securityLevelParent = (mainRow as any).securityLevel || 0;
325+
modelGroup.group.forEach((item: any) => {
326+
if (item.name !== this.model.name) {
327+
item.toggleSecurityVisibility = false;
328+
item.securityLevel = this.securityLevelParent || 0;
329+
}
330+
});
331+
}
332+
}
333+
310334
private retrieveVocabulary(vocabularyOptions: VocabularyOptions): void {
311335
this.vocabulary$ = this.vocabularyService.findVocabularyById(vocabularyOptions.name).pipe(
312336
getFirstSucceededRemoteDataPayload(),

0 commit comments

Comments
 (0)