Skip to content

Commit f43a55a

Browse files
atarix83vins01-4science
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-1236_new (pull request DSpace#3765)
[DSC-1236] add language support to metadata group handling Approved-by: Andrea Barbasso
2 parents 8322a8a + d21d218 commit f43a55a

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

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
@@ -104,7 +104,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
104104
if (this.item) {
105105
this.formModel.forEach((row) => {
106106
const modelRow = row as DynamicFormGroupModel;
107-
modelRow.group.forEach((model: DynamicInputModel) => {
107+
modelRow.group.forEach((model: DsDynamicInputModel) => {
108108
const value = (this.item[model.name] === PLACEHOLDER_PARENT_METADATA
109109
|| this.item[model.name].value === PLACEHOLDER_PARENT_METADATA)
110110
? null
@@ -113,6 +113,9 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
113113
value.value : value;
114114
if (isNotEmpty(nextValue)) {
115115
model.value = nextValue;
116+
if (isNotEmpty(nextValue?.language)) {
117+
model.language = nextValue.language;
118+
}
116119
}
117120

118121
this.initSecurityLevelConfig(model, modelRow);
@@ -219,6 +222,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
219222
const model = this.getMandatoryFieldModel();
220223
const currentValue: string = (model.value instanceof FormFieldMetadataValueObject
221224
|| model.value instanceof VocabularyEntry) ? model.value.value : model.value;
225+
const currentLang: string = (model.value instanceof FormFieldMetadataValueObject) ? model.value.language : model.language;
222226
let security = null;
223227
if (this.model.value instanceof VocabularyEntry) {
224228
security = this.model.value.securityLevel;
@@ -227,7 +231,7 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
227231
security = this.model.metadataValue.securityLevel;
228232
}
229233
}
230-
const valueWithAuthority: any = new FormFieldMetadataValueObject(currentValue, null, security, authority);
234+
const valueWithAuthority: any = new FormFieldMetadataValueObject(currentValue, currentLang, security, authority);
231235
model.value = valueWithAuthority;
232236
this.modifyChip();
233237
setTimeout(() => {
@@ -307,7 +311,8 @@ export class DsDynamicRelationGroupModalComponent extends DynamicFormControlComp
307311

308312
item[control.name] =
309313
new FormFieldMetadataValueObject(
310-
controlValue, (control as any)?.language,
314+
controlValue,
315+
mainModel?.language,
311316
controlValue === PLACEHOLDER_PARENT_METADATA ? null : mainModel.securityLevel,
312317
controlAuthority,
313318
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
@@ -190,6 +190,7 @@ export class DsDynamicRelationInlineGroupComponent extends DynamicFormControlCom
190190
}
191191

192192
model.securityLevel = mainSecurityLevel;
193+
model.language = (mainRow as any).language ?? null;
193194

194195
modelGroup.group.forEach((item: any) => {
195196
if (item.name !== this.model.name) {
@@ -210,29 +211,30 @@ export class DsDynamicRelationInlineGroupComponent extends DynamicFormControlCom
210211

211212
private getRowValue(formGroup: DynamicFormGroupModel, securityLevel?: number) {
212213
let mainSecurityLevel;
214+
const mainRow = formGroup.group.find(itemModel => itemModel.name === this.model.name);
213215
if (isNotEmpty(securityLevel)) {
214216
mainSecurityLevel = securityLevel;
215217
} else {
216-
const mainRow = formGroup.group.find(itemModel => itemModel.name === this.model.name);
217218
mainSecurityLevel = (mainRow as any).securityLevel;
218219
}
220+
const mainLanguage = (mainRow as any).language ?? null;
219221
const groupValue = Object.create({});
220222
formGroup.group.forEach((model: any) => {
221223
if (model.name !== this.model.mandatoryField) {
222224
if (isEmpty(model.value)) {
223225
groupValue[model.name] = PLACEHOLDER_PARENT_METADATA;
224226
} else {
225227
if (typeof model.value === 'string') {
226-
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, null, mainSecurityLevel);
228+
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, mainLanguage, mainSecurityLevel);
227229
} else {
228-
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { securityLevel: mainSecurityLevel || null });
230+
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { language: mainLanguage, securityLevel: mainSecurityLevel || null });
229231
}
230232
}
231233
} else {
232234
if (typeof model.value === 'string') {
233-
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, null, mainSecurityLevel);
235+
groupValue[model.name] = new FormFieldMetadataValueObject(model.value, mainLanguage, mainSecurityLevel);
234236
} else {
235-
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { securityLevel: mainSecurityLevel || null });
237+
groupValue[model.name] = Object.assign(new FormFieldMetadataValueObject(), model.value, { language: mainLanguage, securityLevel: mainSecurityLevel || null });
236238
}
237239
}
238240
});

0 commit comments

Comments
 (0)