Skip to content

Commit c19ecb9

Browse files
DSC-1522: implement unified text for blocked third-party metrics
1 parent e093431 commit c19ecb9

7 files changed

Lines changed: 76 additions & 10 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('ThumbnailComponent', () => {
152152
}));
153153

154154
it('should show default thumbnail', () => {
155-
expect(component.default).toBe('assets/images/person-placeholder.svg');
155+
expect(component.default).toBe('assets/images/file-placeholder.svg');
156156
});
157157

158158
});
@@ -172,7 +172,7 @@ describe('ThumbnailComponent', () => {
172172
}));
173173

174174
it('should show default thumbnail', () => {
175-
expect(component.default).toBe('assets/images/person-placeholder.svg');
175+
expect(component.default).toBe('assets/images/file-placeholder.svg');
176176
});
177177

178178
});
@@ -239,7 +239,7 @@ describe('ThumbnailComponent', () => {
239239
});
240240

241241
it('should show default thumbnail', () => {
242-
expect(component.default).toBe('assets/images/person-placeholder.svg');
242+
expect(component.default).toBe('assets/images/file-placeholder.svg');
243243
});
244244

245245
});
@@ -254,7 +254,7 @@ describe('ThumbnailComponent', () => {
254254
});
255255

256256
it('should not show bitstream content image src but the default image', () => {
257-
expect(component.default).toBe('assets/images/person-placeholder.svg');
257+
expect(component.default).toBe('assets/images/file-placeholder.svg');
258258
});
259259

260260
});
@@ -269,7 +269,7 @@ describe('ThumbnailComponent', () => {
269269
});
270270

271271
it('should not show thumbnail content image src but the default image', () => {
272-
expect(component.default).toBe('assets/images/person-placeholder.svg');
272+
expect(component.default).toBe('assets/images/file-placeholder.svg');
273273
});
274274

275275
});
@@ -284,7 +284,7 @@ describe('ThumbnailComponent', () => {
284284
});
285285

286286
it('should not show thumbnail content image src but the default image', () => {
287-
expect(component.default).toBe('assets/images/person-placeholder.svg');
287+
expect(component.default).toBe('assets/images/file-placeholder.svg');
288288
});
289289

290290
});

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ export class BrowserKlaroService extends KlaroService {
362362
const manager = getManager(this.klaroConfig);
363363
const consentsSubject$ = this.consentsUpdates$;
364364
let lastCookiesConsents = this.lastCookiesConsents;
365+
366+
consentsSubject$.next(manager.consents);
365367
manager.watch({
366368
update(_, eventName, consents) {
367369

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { hasValue } from '../../empty.util';
1717
import { BrowserKlaroService, CookieConsents } from '../../cookies/browser-klaro.service';
1818
import { KlaroService } from '../../cookies/klaro.service';
1919
import { startWith } from 'rxjs/operators';
20+
import { environment } from '../../../../environments/environment';
2021

2122
@Component({
2223
// eslint-disable-next-line @angular-eslint/component-selector
@@ -48,7 +49,7 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
4849

4950
settingsSubscription: Subscription;
5051

51-
private thirdPartyMetrics = ['plumX', 'altmetric', 'dimensions'];
52+
private thirdPartyMetrics = environment.metricsConsents.map(metrics => metrics.key);
5253

5354
private browserKlaroService: BrowserKlaroService;
5455

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: 57 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,14 @@ 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 { BrowserKlaroService } from '../../../../../cookies/browser-klaro.service';
13+
import { KlaroService } from '../../../../../cookies/klaro.service';
14+
import { combineLatest, Observable } from 'rxjs';
15+
import { TruncatableService } from '../../../../../truncatable/truncatable.service';
16+
import { DSONameService } from '../../../../../../core/breadcrumbs/dso-name.service';
17+
import { APP_CONFIG, AppConfig } from '../../../../../../../config/app-config.interface';
18+
import { getFirstSucceededRemoteListPayload } from '../../../../../../core/shared/operators';
19+
import { map } from 'rxjs/operators';
1220

1321
@listableObjectComponent('PublicationSearchResult', ViewMode.ListElement)
1422
@listableObjectComponent(ItemSearchResult, ViewMode.ListElement)
@@ -21,7 +29,7 @@ import { environment } from '../../../../../../../environments/environment';
2129
/**
2230
* The component for displaying a list element for an item search result of the type Publication
2331
*/
24-
export class ItemSearchResultListElementComponent extends SearchResultListElementComponent<ItemSearchResult, Item> implements OnInit {
32+
export class ItemSearchResultListElementComponent extends SearchResultListElementComponent<ItemSearchResult, Item> implements OnInit, AfterViewInit {
2533

2634
/**
2735
* Whether to show the metrics badges
@@ -35,10 +43,57 @@ export class ItemSearchResultListElementComponent extends SearchResultListElemen
3543

3644
authorMetadata = environment.searchResult.authorMetadata;
3745

46+
hasLoadedThirdPartyMetrics$: Observable<boolean>;
47+
48+
private thirdPartyMetrics = environment.metricsConsents.map(metrics => metrics.key);
49+
50+
private browserKlaroService: BrowserKlaroService;
51+
52+
constructor(
53+
protected truncatableService: TruncatableService,
54+
public dsoNameService: DSONameService,
55+
@Inject(APP_CONFIG) protected appConfig?: AppConfig,
56+
@Optional() private klaroService?: KlaroService,
57+
) {
58+
super(truncatableService, dsoNameService);
59+
this.browserKlaroService = (this.klaroService as BrowserKlaroService);
60+
}
61+
3862
ngOnInit(): void {
3963
super.ngOnInit();
4064
this.showThumbnails = this.showThumbnails ?? this.appConfig.browseBy.showThumbnails;
4165
this.itemPageRoute = getItemPageRoute(this.dso);
4266
}
4367

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

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)