Skip to content

Commit

Permalink
Merged in DSC-1669-main (pull request DSpace#1865)
Browse files Browse the repository at this point in the history
DSC-1669 main
  • Loading branch information
Davide Negretti committed Jun 25, 2024
2 parents 78a059b + 0270bf0 commit 7cf69ea
Show file tree
Hide file tree
Showing 33 changed files with 95,415 additions and 28,646 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ export abstract class MetadataGroupComponent extends RenderingTypeStructuredMode
/**
* The prefix used for box field label's i18n key
*/
fieldI18nPrefix = 'layout.field.label.';
readonly fieldI18nPrefix = 'layout.field.label';

/**
* The prefix used for box field label's
*/
readonly nestedMetadataPrefix = 'NESTED';

/**
* A boolean representing if component is initialized
Expand Down Expand Up @@ -80,17 +85,23 @@ export abstract class MetadataGroupComponent extends RenderingTypeStructuredMode
}

/**
* Returns a string representing the label of field if exists
* Returns the translated label, if exists, otherwiuse returns a fallback value
*/
getLabel(field: LayoutField): string {
const fieldLabelI18nKey = this.fieldI18nPrefix + field.label;
const header: string = this.translateService.instant(fieldLabelI18nKey);
if (header === fieldLabelI18nKey) {
// if translation does not exist return the value present in the header property
return this.translateService.instant(field.label);
} else {
return header;
}
return this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.item.entityType}.${this.nestedMetadataPrefix}[${field.metadata}]}`) ??
this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.item.entityType}.[${field.metadata}]`) ??
this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.item.entityType}.${field.metadata}`) ?? // old syntax - do not use
this.getTranslationIfExists(`${this.fieldI18nPrefix}.[${field.metadata}]`) ??
this.getTranslationIfExists(`${this.fieldI18nPrefix}.${field.label}`) ?? // old syntax - do not use
field.label; // the untranslated value from the CRIS layout
}

/**
* Return the translated label, if exists, otherwise returns null
*/
getTranslationIfExists(key: string): string {
const translation: string = this.translateService.instant(key);
return translation !== key ? translation : null;
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div *ngIf="metadataFieldRenderOptions" class="{{containerStyle}}">
<div class="d-flex" [class.flex-column]="field.labelAsHeading">
<span *ngIf="hasLabel"
class="{{labelStyle}}" [innerHTML]="label">
class="{{labelStyle}}" [innerHTML]="getLabel()">
</span>

<div *ngIf="!isStructured" class="d-flex col flex-wrap" [class.flex-column]="!field.valuesInline">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CrisLayoutBox, LayoutField, LayoutFieldType } from '../../../../../../.
import {
FieldRenderingType,
getMetadataBoxFieldRendering,
MetadataBoxFieldRenderOptions
MetadataBoxFieldRenderOptions,
} from '../../rendering-types/metadata-box.decorator';
import { hasValue, isEmpty, isNotEmpty } from '../../../../../../../shared/empty.util';
import { TranslateService } from '@ngx-translate/core';
Expand All @@ -13,11 +13,11 @@ import { MetadataValue } from '../../../../../../../core/shared/metadata.models'
import { Bitstream } from '../../../../../../../core/shared/bitstream.model';
import { getFirstCompletedRemoteData } from '../../../../../../../core/shared/operators';
import { map, take } from 'rxjs/operators';
import { BitstreamDataService } from '../../../../../../../core/data/bitstream-data.service';
import { MetadataFilter } from '../../../../../../../core/data/bitstream-data.service';
import { BitstreamDataService, MetadataFilter } from '../../../../../../../core/data/bitstream-data.service';
import { RemoteData } from '../../../../../../../core/data/remote-data';
import { PaginatedList } from '../../../../../../../core/data/paginated-list.model';
import { Observable } from 'rxjs';
import { inject } from '@angular/core';

@Component({
selector: 'ds-metadata-container',
Expand Down Expand Up @@ -46,7 +46,7 @@ export class MetadataContainerComponent implements OnInit {
/**
* The prefix used for box field label's i18n key
*/
fieldI18nPrefix = 'layout.field.label.';
readonly fieldI18nPrefix = 'layout.field.label';

/**
* A boolean representing if metadata rendering type is structured or not
Expand All @@ -58,12 +58,9 @@ export class MetadataContainerComponent implements OnInit {
*/
metadataFieldRenderOptions: MetadataBoxFieldRenderOptions;

constructor(
protected bitstreamDataService: BitstreamDataService,
protected translateService: TranslateService,
protected cd: ChangeDetectorRef
) {
}
protected readonly bitstreamDataService = inject(BitstreamDataService);
protected readonly translateService = inject(TranslateService);
protected readonly cd = inject(ChangeDetectorRef);

/**
* Returns all metadata values in the item
Expand All @@ -82,17 +79,29 @@ export class MetadataContainerComponent implements OnInit {
/**
* Returns a string representing the label of field if exists
*/
get label(): string {
const fieldLabelI18nKey = this.fieldI18nPrefix + this.item.entityType + '.' + this.field.metadata;
const header: string = this.translateService.instant(fieldLabelI18nKey);
if (header === fieldLabelI18nKey) {
// if translation does not exist return the value present in the header property
return this.translateService.instant(this.field.label);
getLabel(): string {
if (this.field.fieldType === LayoutFieldType.BITSTREAM) {
return (hasValue(this.field.bitstream.metadataValue) ?
this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.item.entityType}.BITSTREAM[${this.field.bitstream.metadataValue}]`) :
this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.item.entityType}.BITSTREAM`)
) ?? this.field.label;
} else {
return header;
return this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.item.entityType}.[${this.field.metadata}]`) ??
this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.item.entityType}.${this.field.metadata}`) ?? // old syntax - do not use
this.getTranslationIfExists(`${this.fieldI18nPrefix}.[${this.field.metadata}]`) ??
this.getTranslationIfExists(`${this.fieldI18nPrefix}.${this.field.label}`) ?? // old syntax - do not use
this.field.label; // the untranslated value from the CRIS layout
}
}

/**
* Return the translated label, if exists, otherwise returns null
*/
getTranslationIfExists(key: string): string {
const translation: string = this.translateService.instant(key);
return translation !== key ? translation : null;
}

/**
* Returns a string representing the style of field container if exists
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
[attr.data-link-target]="remark | dsListMetricProps : 'data-link-target' : isListElement"
></div>
</div>
<div class="font-weight-bold" *ngIf="!hideLabel">
<div class="font-weight-bold" *ngIf="!hideLabel && (showAltmetricLabel$ | async)">
{{ "item.page.metric.label." + metric.metricType | translate }}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { AfterViewChecked, Component, OnInit } from '@angular/core';
import { AfterViewChecked, AfterViewInit, Component, OnInit, Renderer2 } from '@angular/core';
import { BaseEmbeddedMetricComponent } from '../metric-loader/base-embedded-metric.component';
import { DomSanitizer } from '@angular/platform-browser';
import { hasValue } from '../../empty.util';
import { BehaviorSubject } from 'rxjs';

declare let _altmetric_embed_init: any;

Expand All @@ -10,10 +11,14 @@ declare let _altmetric_embed_init: any;
templateUrl: './metric-altmetric.component.html',
styleUrls: ['./metric-altmetric.component.scss', '../metric-loader/base-metric.component.scss']
})
export class MetricAltmetricComponent extends BaseEmbeddedMetricComponent implements OnInit, AfterViewChecked {
export class MetricAltmetricComponent extends BaseEmbeddedMetricComponent implements OnInit, AfterViewChecked, AfterViewInit {
remark: JSON;
/**
* Flag to show the altmetric label
*/
showAltmetricLabel$: BehaviorSubject<boolean> = new BehaviorSubject(false);

constructor(protected sr: DomSanitizer) {
constructor(protected sr: DomSanitizer, private renderer: Renderer2) {
super(sr);
}

Expand All @@ -33,4 +38,11 @@ export class MetricAltmetricComponent extends BaseEmbeddedMetricComponent implem
this.hide.emit(true);
}
}

ngAfterViewInit(): void {
// Show the altmetric label only when the altmetric component is ready
this.renderer.listen(this.metricChild.nativeElement, 'altmetric:show', () => {
this.showAltmetricLabel$.next(true);
});
}
}
Loading

0 comments on commit 7cf69ea

Please sign in to comment.