Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1751 (pull request DSpace#1852)
Browse files Browse the repository at this point in the history
[DSC-1751] Hide the altmetric label when there is no data available

Approved-by: Francesco Molinaro
  • Loading branch information
alisaismailati authored and FrancescoMolinaro committed Jun 21, 2024
2 parents 1792515 + e427b87 commit 27fd154
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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);
});
}
}

0 comments on commit 27fd154

Please sign in to comment.