Skip to content

Commit 4b13163

Browse files
[DSC-1669] - Add handling of the label structure layout.field.label.ENTITY_TYPE.nested.[NESTED_METADATA]
1 parent 5855d88 commit 4b13163

4 files changed

Lines changed: 60 additions & 36 deletions

File tree

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadataGroup/inline/inline.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { FieldRenderingType, MetadataBoxFieldRendering } from '../../metadata-bo
66
import { Item } from '../../../../../../../../core/shared/item.model';
77
import { LayoutField } from '../../../../../../../../core/layout/models/box.model';
88
import { MetadataGroupComponent } from '../metadata-group.component';
9-
import { TranslationUtilityService } from '../../../../../../../services/translation.service';
109

1110
/**
1211
* This component renders the inline metadata group fields
@@ -24,10 +23,9 @@ export class InlineComponent extends MetadataGroupComponent implements OnInit {
2423
@Inject('itemProvider') public itemProvider: Item,
2524
@Inject('renderingSubTypeProvider') public renderingSubTypeProvider: string,
2625
@Inject('tabNameProvider') public tabNameProvider: string,
27-
protected translateService: TranslateService,
28-
protected translationUtilityService: TranslationUtilityService,
26+
protected translateService: TranslateService
2927
) {
30-
super(fieldProvider, itemProvider, renderingSubTypeProvider, tabNameProvider, translateService, translationUtilityService);
28+
super(fieldProvider, itemProvider, renderingSubTypeProvider, tabNameProvider, translateService);
3129
}
3230

3331
}

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/metadataGroup/metadata-group.component.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { TranslateService } from '@ngx-translate/core';
66
import { isNotEmpty } from '../../../../../../../shared/empty.util';
77
import { MetadataValue } from '../../../../../../../core/shared/metadata.models';
88
import { BehaviorSubject } from 'rxjs';
9-
import { TranslationUtilityService } from '../../../../../../services/translation.service';
109

1110

1211
export interface NestedMetadataGroupEntry {
@@ -35,6 +34,11 @@ export abstract class MetadataGroupComponent extends RenderingTypeStructuredMode
3534
*/
3635
fieldI18nPrefix = 'layout.field.label.';
3736

37+
/**
38+
* The prefix used for box field label's
39+
*/
40+
nestedName = 'nested';
41+
3842
/**
3943
* A boolean representing if component is initialized
4044
*/
@@ -45,8 +49,7 @@ export abstract class MetadataGroupComponent extends RenderingTypeStructuredMode
4549
@Inject('itemProvider') public itemProvider: Item,
4650
@Inject('renderingSubTypeProvider') public renderingSubTypeProvider: string,
4751
@Inject('tabNameProvider') public tabNameProvider: string,
48-
protected translateService: TranslateService,
49-
protected translationUtilityService: TranslationUtilityService
52+
protected translateService: TranslateService
5053
) {
5154
super(fieldProvider, itemProvider, renderingSubTypeProvider, tabNameProvider, translateService);
5255
}
@@ -85,15 +88,27 @@ export abstract class MetadataGroupComponent extends RenderingTypeStructuredMode
8588
* Returns a string representing the label of field if exists
8689
*/
8790
getLabel(field: LayoutField): string {
88-
return this.translationUtilityService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.[' + field.metadata + ']') ??
89-
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.[' + field.metadata + ']') ??
90-
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.' + field.metadata) ??
91-
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + '[' + field.metadata + ']') ??
92-
this.translationUtilityService.getTranslation(this.fieldI18nPrefix + field.label) ??
91+
return this.getTranslationIfExists(this.fieldI18nPrefix + this.item.entityType + '.' + this.nestedName + '.[' + field.metadata + ']') ??
92+
this.getTranslationIfExists(this.fieldI18nPrefix + this.item.entityType + '.[' + field.metadata + ']') ??
93+
this.getTranslationIfExists(this.fieldI18nPrefix + this.item.entityType + '.[' + field.metadata + ']') ??
94+
this.getTranslationIfExists(this.fieldI18nPrefix + this.item.entityType + '.' + field.metadata) ??
95+
this.getTranslationIfExists(this.fieldI18nPrefix + '[' + field.metadata + ']') ??
96+
this.getTranslationIfExists(this.fieldI18nPrefix + field.label) ??
9397
field.label ??
9498
field.metadata;
9599
}
96100

101+
/**
102+
* If the translation haven't found return null otherwise return translated label
103+
*/
104+
getTranslationIfExists(fieldLabelI18nKey: string): string {
105+
const header: string = this.translateService.instant(fieldLabelI18nKey);
106+
if (header !== fieldLabelI18nKey) {
107+
return header;
108+
}
109+
return null;
110+
}
111+
97112
ngOnDestroy(): void {
98113
this.componentsToBeRenderedMap = null;
99114
}

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/row/metadata-container/metadata-container.component.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,25 @@ export class MetadataContainerComponent implements OnInit {
8585
* Returns a string representing the label of field if exists
8686
*/
8787
get label(): string {
88-
return this.translationService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.[' + this.field.metadata + ']') ??
89-
this.translationService.getTranslation(this.fieldI18nPrefix + this.item.entityType + '.' + this.field.metadata) ??
90-
this.translationService.getTranslation(this.fieldI18nPrefix + '[' + this.field.metadata + ']') ??
91-
this.translationService.getTranslation(this.fieldI18nPrefix + this.field.label) ??
88+
return this.getTranslationIfExists(this.fieldI18nPrefix + this.item.entityType + '.[' + this.field.metadata + ']') ??
89+
this.getTranslationIfExists(this.fieldI18nPrefix + this.item.entityType + '.' + this.field.metadata) ??
90+
this.getTranslationIfExists(this.fieldI18nPrefix + '[' + this.field.metadata + ']') ??
91+
this.getTranslationIfExists(this.fieldI18nPrefix + this.field.label) ??
9292
this.field.label ??
9393
this.field.metadata;
9494
}
9595

96+
/**
97+
* If the translation haven't found return null otherwise return translated label
98+
*/
99+
getTranslationIfExists(fieldLabelI18nKey: string): string {
100+
const header: string = this.translateService.instant(fieldLabelI18nKey);
101+
if (header !== fieldLabelI18nKey) {
102+
return header;
103+
}
104+
return null;
105+
}
106+
96107
/**
97108
* Returns a string representing the style of field container if exists
98109
*/

src/assets/i18n/en.json5

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7528,7 +7528,7 @@
75287528
"layout.field.label.Publication.[dc.relation.ispartof]": "Journal",
75297529
"layout.field.label.Publication.[dc.relation.issn]": "ISSN",
75307530
"layout.field.label.Publication.[dc.date.issued]": "Date Issued",
7531-
"layout.field.label.Publication.[dc.contributor.author]": "Author 228",
7531+
"layout.field.label.Publication.[dc.contributor.author]": "Author(s)",
75327532
"layout.field.label.Publication.[dc.contributor.editor]": "Editor(s)",
75337533
"layout.field.label.Publication.[dc.identifier.doi]": "DOI",
75347534
"layout.field.label.Publication.[dc.description.abstract]": "Abstract",
@@ -7562,25 +7562,25 @@
75627562

75637563
// Layout - Autogenerated i18n keys: metadata groups
75647564

7565-
"layout.field.label.Person.[crisrp.qualification].[crisrp.qualification]": "Title",
7566-
"layout.field.label.Person.[crisrp.qualification].[crisrp.qualification.start]": "Start",
7567-
"layout.field.label.Person.[crisrp.qualification].[crisrp.qualification.end]": "End",
7568-
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.affiliation.role]": "Role",
7569-
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.person.affiliation]": "Organisation",
7570-
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.affiliation.startDate]": "Start",
7571-
"layout.field.label.Person.[oairecerif.person.affiliation].[oairecerif.affiliation.endDate]": "End",
7572-
"layout.field.label.Person.[crisrp.education].[crisrp.education.role]": "Role",
7573-
"layout.field.label.Person.[crisrp.education].[crisrp.education]": "Organisation",
7574-
"layout.field.label.Person.[crisrp.education].[crisrp.education.start]": "Start",
7575-
"layout.field.label.Person.[crisrp.education].[crisrp.education.end]": "End",
7576-
"layout.field.label.Publication.[dc.contributor.author].[dc.contributor.author]": "Author",
7577-
"layout.field.label.Publication.[dc.contributor.author].[oairecerif.author.affiliation]": "Affiliation",
7578-
"layout.field.label.Publication.[dc.contributor.editor].[dc.contributor.editor]": "Editor",
7579-
"layout.field.label.Publication.[dc.contributor.editor].[oairecerif.editor.affiliation]": "Affiliation",
7580-
"layout.field.label.Product.[dc.contributor.author].[dc.contributor.author]": "Creator",
7581-
"layout.field.label.Product.[dc.contributor.author].[oairecerif.author.affiliation]": "Affiliation",
7582-
"layout.field.label.Patent.[dc.contributor.author].[dc.contributor.author]": "Inventor",
7583-
"layout.field.label.Patent.[dc.contributor.author].[oairecerif.author.affiliation]": "Affiliation",
7565+
"layout.field.label.Person.nested.[crisrp.qualification]": "Title",
7566+
"layout.field.label.Person.nested.[crisrp.qualification.start]": "Start",
7567+
"layout.field.label.Person.nested.[crisrp.qualification.end]": "End",
7568+
"layout.field.label.Person.nested.[oairecerif.affiliation.role]": "Role",
7569+
"layout.field.label.Person.nested.[oairecerif.person.affiliation]": "Organisation",
7570+
"layout.field.label.Person.nested.[oairecerif.affiliation.startDate]": "Start",
7571+
"layout.field.label.Person.nested.[oairecerif.affiliation.endDate]": "End",
7572+
"layout.field.label.Person.nested.[crisrp.education.role]": "Role",
7573+
"layout.field.label.Person.nested.[crisrp.education]": "Organisation",
7574+
"layout.field.label.Person.nested.[crisrp.education.start]": "Start",
7575+
"layout.field.label.Person.nested.[crisrp.education.end]": "End",
7576+
"layout.field.label.Publication.nested.[dc.contributor.author]": "Author",
7577+
"layout.field.label.Publication.nested.[oairecerif.author.affiliation]": "Affiliation",
7578+
"layout.field.label.Publication.nested.[dc.contributor.editor]": "Editor",
7579+
"layout.field.label.Publication.nested.[oairecerif.editor.affiliation]": "Affiliation",
7580+
"layout.field.label.Product.nested.[dc.contributor.author]": "Creator",
7581+
"layout.field.label.Product.nested.[oairecerif.author.affiliation]": "Affiliation",
7582+
"layout.field.label.Patent.nested.[dc.contributor.author]": "Inventor",
7583+
"layout.field.label.Patent.nested.[oairecerif.author.affiliation]": "Affiliation",
75847584

75857585

75867586
// Do not add new labels below layout ones

0 commit comments

Comments
 (0)