Skip to content

Commit 688e58c

Browse files
FrancescoMolinaroatarix83
authored andcommitted
Merged in metrics_text_2023_02_x_DSC_1522 (pull request DSpace#1301)
Metrics text 2023 02 x DSC-1522 Approved-by: Giuseppe Digilio
2 parents cc0f6aa + 8277450 commit 688e58c

5 files changed

Lines changed: 65 additions & 3 deletions

File tree

src/app/shared/cookies/browser-klaro.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,8 @@ export class BrowserKlaroService extends KlaroService {
359359
const manager = getManager(this.klaroConfig);
360360
const consentsSubject$ = this.consentsUpdates$;
361361
let lastCookiesConsents = this.lastCookiesConsents;
362+
363+
consentsSubject$.next(manager.consents);
362364
manager.watch({
363365
update(_, eventName, consents) {
364366

src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<div [ngClass]="showThumbnails ? 'col-9 col-xl-10' : 'col-12'">
1414
<div class="d-flex justify-content-between">
1515
<div class="flex-fill">
16+
<small class="d-flex text-muted" *ngIf="!(hasLoadedThirdPartyMetrics$ | async) && showMetrics">
17+
{{ "third-party-metrics-blocked" | translate }}&nbsp;
18+
<div role="button" class="btn-link" (click)="showSettings()">{{ "third-party-metrics-cookies.consent-settings" | translate }}</div>
19+
</small>
1620
<div class="d-flex">
1721
<ds-themed-badges *ngIf="showLabel" [object]="dso" [context]="context" [showAccessStatus]="true"></ds-themed-badges>
1822
</div>

src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { DSONameService } from '../../../../../../core/breadcrumbs/dso-name.serv
1111
import { DSONameServiceMock, UNDEFINED_NAME } from '../../../../../mocks/dso-name.service.mock';
1212
import { VarDirective } from '../../../../../utils/var.directive';
1313
import { APP_CONFIG } from '../../../../../../../config/app-config.interface';
14+
import { TranslateModule } from '@ngx-translate/core';
1415

1516
let publicationListElementComponent: ItemSearchResultListElementComponent;
1617
let fixture: ComponentFixture<ItemSearchResultListElementComponent>;
@@ -188,13 +189,13 @@ const enviromentNoThumbs = {
188189
describe('ItemSearchResultListElementComponent', () => {
189190
beforeEach(waitForAsync(() => {
190191
TestBed.configureTestingModule({
192+
imports: [TranslateModule.forRoot()],
191193
declarations: [ItemSearchResultListElementComponent, TruncatePipe, VarDirective],
192194
providers: [
193195
{ provide: TruncatableService, useValue: {} },
194196
{ provide: DSONameService, useClass: DSONameServiceMock },
195197
{ provide: APP_CONFIG, useValue: environmentUseThumbs }
196198
],
197-
198199
schemas: [NO_ERRORS_SCHEMA]
199200
}).overrideComponent(ItemSearchResultListElementComponent, {
200201
set: { changeDetection: ChangeDetectionStrategy.Default }
@@ -371,6 +372,7 @@ describe('ItemSearchResultListElementComponent', () => {
371372

372373
beforeEach(waitForAsync(() => {
373374
TestBed.configureTestingModule({
375+
imports: [TranslateModule.forRoot()],
374376
declarations: [ItemSearchResultListElementComponent, TruncatePipe],
375377
providers: [
376378
{provide: TruncatableService, useValue: {}},

src/app/shared/object-list/search-result-list-element/item-search-result/item-types/item/item-search-result-list-element.component.ts

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { AfterViewInit, Component, Inject, Input, OnInit, Optional } from '@angular/core';
22
import {
33
listableObjectComponent
44
} from '../../../../../object-collection/shared/listable-object/listable-object.decorator';
@@ -9,6 +9,13 @@ import { Item } from '../../../../../../core/shared/item.model';
99
import { getItemPageRoute } from '../../../../../../item-page/item-page-routing-paths';
1010
import { Context } from '../../../../../../core/shared/context.model';
1111
import { environment } from '../../../../../../../environments/environment';
12+
import { KlaroService } from '../../../../../cookies/klaro.service';
13+
import { combineLatest, Observable } from 'rxjs';
14+
import { TruncatableService } from '../../../../../truncatable/truncatable.service';
15+
import { DSONameService } from '../../../../../../core/breadcrumbs/dso-name.service';
16+
import { APP_CONFIG, AppConfig } from '../../../../../../../config/app-config.interface';
17+
import { getFirstSucceededRemoteListPayload } from '../../../../../../core/shared/operators';
18+
import { map } from 'rxjs/operators';
1219

1320
@listableObjectComponent('PublicationSearchResult', ViewMode.ListElement)
1421
@listableObjectComponent(ItemSearchResult, ViewMode.ListElement)
@@ -21,7 +28,7 @@ import { environment } from '../../../../../../../environments/environment';
2128
/**
2229
* The component for displaying a list element for an item search result of the type Publication
2330
*/
24-
export class ItemSearchResultListElementComponent extends SearchResultListElementComponent<ItemSearchResult, Item> implements OnInit {
31+
export class ItemSearchResultListElementComponent extends SearchResultListElementComponent<ItemSearchResult, Item> implements OnInit, AfterViewInit {
2532

2633
/**
2734
* Whether to show the metrics badges
@@ -35,10 +42,55 @@ export class ItemSearchResultListElementComponent extends SearchResultListElemen
3542

3643
authorMetadata = environment.searchResult.authorMetadata;
3744

45+
hasLoadedThirdPartyMetrics$: Observable<boolean>;
46+
47+
private thirdPartyMetrics = environment.info.metricsConsents.filter(metric => metric.enabled).map(metric => metric.key);
48+
49+
50+
constructor(
51+
protected truncatableService: TruncatableService,
52+
public dsoNameService: DSONameService,
53+
@Inject(APP_CONFIG) protected appConfig?: AppConfig,
54+
@Optional() private klaroService?: KlaroService,
55+
) {
56+
super(truncatableService, dsoNameService);
57+
}
58+
3859
ngOnInit(): void {
3960
super.ngOnInit();
4061
this.showThumbnails = this.showThumbnails ?? this.appConfig.browseBy.showThumbnails;
4162
this.itemPageRoute = getItemPageRoute(this.dso);
4263
}
4364

65+
/**
66+
* Check if item has Third-party metrics blocked by consents
67+
*/
68+
ngAfterViewInit() {
69+
if (this.showMetrics && this.klaroService) {
70+
this.klaroService.watchConsentUpdates();
71+
72+
this.hasLoadedThirdPartyMetrics$ = combineLatest([
73+
this.klaroService.consentsUpdates$,
74+
this.dso.metrics?.pipe(
75+
getFirstSucceededRemoteListPayload(),
76+
map(metrics => {
77+
return metrics.filter(metric => this.thirdPartyMetrics.includes(metric.metricType));
78+
})
79+
)
80+
]).pipe(
81+
map(([consents, metrics]) => {
82+
return metrics.reduce((previous, current) => {
83+
return consents[current.metricType] && previous;
84+
}, true);
85+
})
86+
);
87+
}
88+
}
89+
90+
/**
91+
* Prompt user for consents settings
92+
*/
93+
showSettings() {
94+
this.klaroService.showSettings();
95+
}
4496
}

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7308,4 +7308,6 @@
73087308
"third-party-metrics-cookies.message": "{{ metricType }} badge is blocked by your ",
73097309

73107310
"third-party-metrics-cookies.consent-settings": "consent settings",
7311+
7312+
"third-party-metrics-blocked": "Some of the metrics are blocked by your",
73117313
}

0 commit comments

Comments
 (0)