Skip to content

Commit 27fd154

Browse files
alisaismailatiFrancescoMolinaro
authored andcommitted
Merged in task/dspace-cris-2023_02_x/DSC-1751 (pull request DSpace#1852)
[DSC-1751] Hide the altmetric label when there is no data available Approved-by: Francesco Molinaro
2 parents 1792515 + e427b87 commit 27fd154

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/app/shared/metric/metric-altmetric/metric-altmetric.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
[attr.data-link-target]="remark | dsListMetricProps : 'data-link-target' : isListElement"
1818
></div>
1919
</div>
20-
<div class="font-weight-bold" *ngIf="!hideLabel">
20+
<div class="font-weight-bold" *ngIf="!hideLabel && (showAltmetricLabel$ | async)">
2121
{{ "item.page.metric.label." + metric.metricType | translate }}
2222
</div>
2323
</div>

src/app/shared/metric/metric-altmetric/metric-altmetric.component.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { AfterViewChecked, Component, OnInit } from '@angular/core';
1+
import { AfterViewChecked, AfterViewInit, Component, OnInit, Renderer2 } from '@angular/core';
22
import { BaseEmbeddedMetricComponent } from '../metric-loader/base-embedded-metric.component';
33
import { DomSanitizer } from '@angular/platform-browser';
44
import { hasValue } from '../../empty.util';
5+
import { BehaviorSubject } from 'rxjs';
56

67
declare let _altmetric_embed_init: any;
78

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

16-
constructor(protected sr: DomSanitizer) {
21+
constructor(protected sr: DomSanitizer, private renderer: Renderer2) {
1722
super(sr);
1823
}
1924

@@ -33,4 +38,11 @@ export class MetricAltmetricComponent extends BaseEmbeddedMetricComponent implem
3338
this.hide.emit(true);
3439
}
3540
}
41+
42+
ngAfterViewInit(): void {
43+
// Show the altmetric label only when the altmetric component is ready
44+
this.renderer.listen(this.metricChild.nativeElement, 'altmetric:show', () => {
45+
this.showAltmetricLabel$.next(true);
46+
});
47+
}
3648
}

0 commit comments

Comments
 (0)