Skip to content

Commit 90460b6

Browse files
atarix83vins01-4science
authored andcommitted
Merged in task/main-cris/DSC-1236 (pull request DSpace#3763)
[DSC-1236] add language support to metadata group handling Approved-by: Andrea Barbasso
2 parents 54e2531 + a816a12 commit 90460b6

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
143143
if (this.item) {
144144
this.formModel.forEach((row) => {
145145
const modelRow = row as DynamicFormGroupModel;
146-
modelRow.group.forEach((model: DynamicInputModel) => {
146+
modelRow.group.forEach((model: DsDynamicInputModel) => {
147147
const value = (this.item[model.name] === PLACEHOLDER_PARENT_METADATA
148148
|| this.item[model.name].value === PLACEHOLDER_PARENT_METADATA)
149149
? null
@@ -152,6 +152,9 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
152152
value.value : value;
153153
if (isNotEmpty(nextValue)) {
154154
model.value = nextValue;
155+
if (isNotEmpty(nextValue?.language)) {
156+
model.language = nextValue.language;
157+
}
155158
}
156159

157160
this.initSecurityLevelConfig(model, modelRow);
@@ -258,6 +261,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
258261
const model = this.getMandatoryFieldModel();
259262
const currentValue: string = (model.value instanceof FormFieldMetadataValueObject
260263
|| model.value instanceof VocabularyEntry) ? model.value.value : model.value;
264+
const currentLang: string = (model.value instanceof FormFieldMetadataValueObject) ? model.value.language : model.language;
261265
let security = null;
262266
if (this.model.value instanceof VocabularyEntry) {
263267
security = this.model.value.securityLevel;
@@ -266,7 +270,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
266270
security = this.model.metadataValue.securityLevel;
267271
}
268272
}
269-
const valueWithAuthority: any = new FormFieldMetadataValueObject(currentValue, null, security, authority);
273+
const valueWithAuthority: any = new FormFieldMetadataValueObject(currentValue, currentLang, security, authority);
270274
model.value = valueWithAuthority;
271275
this.modifyChip();
272276
setTimeout(() => {
@@ -346,7 +350,8 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
346350

347351
item[control.name] =
348352
new FormFieldMetadataValueObject(
349-
controlValue, (control as any)?.language,
353+
controlValue,
354+
mainModel?.language,
350355
controlValue === PLACEHOLDER_PARENT_METADATA ? null : mainModel.securityLevel,
351356
controlAuthority,
352357
null, 0, null,

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export class DsDynamicRelationInlineGroupComponent extends DynamicFormControlCom
216216
}
217217

218218
model.securityLevel = mainSecurityLevel;
219+
model.language = (mainRow as any).language ?? null;
219220

220221
modelGroup.group.forEach((item: any) => {
221222
if (item.name !== this.model.name) {
@@ -236,29 +237,30 @@ export class DsDynamicRelationInlineGroupComponent extends DynamicFormControlCom
236237

237238
private getRowValue(formGroup: DynamicFormGroupModel, securityLevel?: number) {
238239
let mainSecurityLevel;
240+
const mainRow = formGroup.group.find(itemModel => itemModel.name === this.model.name);
239241
if (isNotEmpty(securityLevel)) {
240242
mainSecurityLevel = securityLevel;
241243
} else {
242-
const mainRow = formGroup.group.find(itemModel => itemModel.name === this.model.name);
243244
mainSecurityLevel = (mainRow as any).securityLevel;
244245
}
246+
const mainLanguage = (mainRow as any).language ?? null;
245247
const groupValue = Object.create({});
246248
formGroup.group.forEach((model: any) => {
247249
if (model.name !== this.model.mandatoryField) {
248250
if (isEmpty(model.value)) {
249251
groupValue[model.name] = PLACEHOLDER_PARENT_METADATA;
250252
} else {
251253
if (typeof model.value === 'string') {
252-
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, null, mainSecurityLevel);
254+
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, mainLanguage, mainSecurityLevel);
253255
} else {
254-
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { securityLevel: mainSecurityLevel || null });
256+
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { language: mainLanguage, securityLevel: mainSecurityLevel || null });
255257
}
256258
}
257259
} else {
258260
if (typeof model.value === 'string') {
259-
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, null, mainSecurityLevel);
261+
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, mainLanguage, mainSecurityLevel);
260262
} else {
261-
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { securityLevel: mainSecurityLevel || null });
263+
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { language: mainLanguage, securityLevel: mainSecurityLevel || null });
262264
}
263265
}
264266
});

0 commit comments

Comments
 (0)