Skip to content

Commit e98c97a

Browse files
Merge branch 'dspace-cris-2023_02_x' into metrics_text_2023_02_x_DSC_1522
2 parents 643e97d + cc0f6aa commit e98c97a

9 files changed

Lines changed: 67 additions & 74 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { TranslateService } from '@ngx-translate/core';
55
import { environment } from '../../../environments/environment';
66
import { map, switchMap, take } from 'rxjs/operators';
77
import { EPerson } from '../../core/eperson/models/eperson.model';
8-
import { KlaroService } from './klaro.service';
8+
import { CookieConsents, KlaroService } from './klaro.service';
99
import { hasValue, isEmpty, isNotEmpty } from '../empty.util';
1010
import { CookieService } from '../../core/services/cookie.service';
1111
import { EPersonDataService } from '../../core/eperson/eperson-data.service';
@@ -18,9 +18,6 @@ import { ConfigurationDataService } from '../../core/data/configuration-data.ser
1818
import { CAPTCHA_NAME } from '../../core/google-recaptcha/google-recaptcha.service';
1919
import isEqual from 'lodash/isEqual';
2020

21-
export interface CookieConsents {
22-
[key: string]: boolean;
23-
}
2421
/**
2522
* Metadata field to store a user's cookie consent preferences in
2623
*/
@@ -106,8 +103,8 @@ export class BrowserKlaroService extends KlaroService {
106103
this.klaroConfig.translations.zz.consentNotice.description = 'cookies.consent.content-notice.description.no-privacy';
107104
}
108105

109-
if (hasValue(environment.metricsConsents)) {
110-
environment.metricsConsents.forEach((metric) => {
106+
if (hasValue(environment.info.metricsConsents)) {
107+
environment.info.metricsConsents.forEach((metric) => {
111108
if (metric.enabled) {
112109
this.klaroConfig.services.push(
113110
{
@@ -357,7 +354,7 @@ export class BrowserKlaroService extends KlaroService {
357354
return 'klaro-' + identifier;
358355
}
359356

360-
watchConsentUpdates() {
357+
watchConsentUpdates(): void {
361358
this.lazyKlaro.then(({getManager}) => {
362359
const manager = getManager(this.klaroConfig);
363360
const consentsSubject$ = this.consentsUpdates$;
Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { Injectable } from '@angular/core';
22

3-
import { Observable } from 'rxjs';
4-
3+
import { BehaviorSubject, Observable } from 'rxjs';
4+
export interface CookieConsents {
5+
[key: string]: boolean;
6+
}
57
/**
68
* Abstract class representing a service for handling Klaro consent preferences and UI
79
*/
@@ -10,15 +12,25 @@ export abstract class KlaroService {
1012
/**
1113
* Initializes the service
1214
*/
13-
abstract initialize();
15+
abstract initialize(): void;
1416

1517
/**
1618
* Shows a dialog with the current consent preferences
1719
*/
18-
abstract showSettings();
20+
abstract showSettings(): void;
1921

2022
/**
2123
* Return saved preferences stored in the klaro cookie
2224
*/
2325
abstract getSavedPreferences(): Observable<any>;
26+
27+
/**
28+
* Watch for changes in consents
29+
*/
30+
abstract watchConsentUpdates(): void;
31+
32+
/**
33+
* Subject to emit updates in the consents
34+
*/
35+
abstract consentsUpdates$: BehaviorSubject<CookieConsents>;
2436
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import { MetricLoaderService } from './metric-loader.service';
88
import { metric1Mock } from '../../../cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metrics/cris-layout-metrics-box.component.spec';
99
import { MetricStyleConfigPipe } from '../pipes/metric-style-config/metric-style-config.pipe';
1010
import SpyObj = jasmine.SpyObj;
11-
import { KlaroService } from '../../cookies/klaro.service';
12-
import { CookieConsents } from '../../cookies/browser-klaro.service';
11+
import { CookieConsents, KlaroService } from '../../cookies/klaro.service';
1312
import { BaseMetricComponent } from './base-metric.component';
1413

1514

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ import { Metric } from '../../../core/shared/metric.model';
1414
import { BaseMetricComponent } from './base-metric.component';
1515
import { MetricLoaderService } from './metric-loader.service';
1616
import { hasValue } from '../../empty.util';
17-
import { BrowserKlaroService, CookieConsents } from '../../cookies/browser-klaro.service';
18-
import { KlaroService } from '../../cookies/klaro.service';
19-
import { startWith } from 'rxjs/operators';
20-
import { environment } from '../../../../environments/environment';
17+
import { CookieConsents, KlaroService } from '../../cookies/klaro.service';
18+
import { startWith } from 'rxjs/operators';
2119

2220
@Component({
2321
// eslint-disable-next-line @angular-eslint/component-selector
@@ -49,9 +47,7 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
4947

5048
settingsSubscription: Subscription;
5149

52-
private thirdPartyMetrics = environment.metricsConsents.filter(metric => metric.enabled).map(metric => metric.key);
53-
54-
private browserKlaroService: BrowserKlaroService;
50+
private thirdPartyMetrics = ['plumX', 'altmetric', 'dimensions'];
5551

5652
private hasLoadedScript: boolean;
5753

@@ -60,13 +56,12 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
6056
private metricLoaderService: MetricLoaderService,
6157
private klaroService: KlaroService,
6258
) {
63-
this.browserKlaroService = (this.klaroService as BrowserKlaroService);
64-
this.browserKlaroService.watchConsentUpdates();
65-
this.consentUpdates$ = this.browserKlaroService.consentsUpdates$;
59+
this.klaroService.watchConsentUpdates();
60+
this.consentUpdates$ = this.klaroService.consentsUpdates$;
6661
}
6762

6863
ngOnInit() {
69-
this.cookiesSubscription = this.browserKlaroService.getSavedPreferences().subscribe((consents) => {
64+
this.cookiesSubscription = this.klaroService.getSavedPreferences().subscribe((consents) => {
7065
this.loadComponent(this.metric, this.getCanLoadScript(consents));
7166
});
7267
}
@@ -77,10 +72,6 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
7772
}
7873
this.hasLoadedScript = !!canLoadScript;
7974
this.metricLoaderService.loadMetricTypeComponent(metric.metricType, canLoadScript).then((component) => {
80-
if (hasValue(this.cookiesSubscription) && canLoadScript) {
81-
this.container.clear();
82-
this.cookiesSubscription.unsubscribe();
83-
}
8475
this.instantiateComponent(component, metric, canLoadScript, forceRendering);
8576
});
8677
}
@@ -97,6 +88,8 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
9788
instantiateComponent(component: any, metric: Metric, canLoadScript: boolean, forceRendering?: boolean) {
9889
const factory = this.componentFactoryResolver.resolveComponentFactory(component);
9990
this.componentType = component;
91+
this.container.clear();
92+
10093
const ref = this.container.createComponent(factory);
10194
const componentInstance = ref.instance as BaseMetricComponent;
10295
componentInstance.metric = metric;
@@ -134,14 +127,18 @@ export class MetricLoaderComponent implements OnInit, OnDestroy {
134127
* @private
135128
*/
136129
private reloadComponentOnConsentsChange(componentInstance: BaseMetricComponent, canLoadScript: boolean): void {
130+
if (hasValue(this.settingsSubscription)) {
131+
return;
132+
}
133+
137134
this.settingsSubscription = combineLatest([
138135
this.consentUpdates$,
139136
componentInstance.requestSettingsConsent.pipe(startWith(undefined))
140137
]).subscribe(([consents, request]) => {
141138
canLoadScript = this.getCanLoadScript(consents);
142139

143140
if (request && !canLoadScript) {
144-
this.browserKlaroService.showSettings();
141+
this.klaroService.showSettings();
145142
}
146143

147144
if (canLoadScript && !this.hasLoadedScript) {

src/app/shared/metric/metrics.module.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { MetricBadgesComponent } from '../object-list/metric-badges/metric-badge
1919
import { MetricDonutsComponent } from '../object-list/metric-donuts/metric-donuts.component';
2020
import { FormsModule } from '@angular/forms';
2121
import { DirectivesModule } from '../../directives/directives.module';
22-
import { BrowserKlaroService } from '../cookies/browser-klaro.service';
2322

2423
const PIPES = [
2524
MetricStyleConfigPipe,
@@ -45,11 +44,6 @@ const COMPONENTS = [
4544
MetricLoaderComponent,
4645
MetricDefaultComponent
4746
];
48-
49-
const PROVIDERS = [
50-
BrowserKlaroService
51-
];
52-
5347
@NgModule({
5448
declarations: [
5549
...PIPES,
@@ -62,9 +56,6 @@ const PROVIDERS = [
6256
useDefaultLang: true
6357
}),
6458
],
65-
providers: [
66-
...PROVIDERS
67-
],
6859
exports: [
6960
...COMPONENTS,
7061
]

src/config/app-config.interface.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { FollowAuthorityMetadata } from './search-follow-metadata.interface';
3131
import { AdvancedAttachmentRenderingConfig } from './advanced-attachment-rendering.config';
3232
import { AttachmentRenderingConfig } from './attachment-rendering.config';
3333
import { SearchResultConfig } from './search-result-config.interface';
34-
import { ThirdPartyMetric } from './third-party-metric-config';
3534

3635
interface AppConfig extends Config {
3736
ui: UIServerConfig;
@@ -69,7 +68,6 @@ interface AppConfig extends Config {
6968
attachmentRendering: AttachmentRenderingConfig;
7069
advancedAttachmentRendering: AdvancedAttachmentRenderingConfig;
7170
searchResult: SearchResultConfig;
72-
metricsConsents: ThirdPartyMetric[];
7371
}
7472

7573
/**

src/config/default-app-config.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
} from './advanced-attachment-rendering.config';
3535
import { AttachmentRenderingConfig } from './attachment-rendering.config';
3636
import { SearchResultConfig } from './search-result-config.interface';
37-
import { ThirdPartyMetric } from './third-party-metric-config';
3837

3938
export class DefaultAppConfig implements AppConfig {
4039
production = false;
@@ -481,7 +480,22 @@ export class DefaultAppConfig implements AppConfig {
481480
// - All mentions of the privacy policy being removed from the UI (e.g. in the footer)
482481
info: InfoConfig = {
483482
enableEndUserAgreement: true,
484-
enablePrivacyStatement: true
483+
enablePrivacyStatement: true,
484+
//Configuration for third-party metrics in Klaro
485+
metricsConsents: [
486+
{
487+
key: 'plumX',
488+
enabled: true
489+
},
490+
{
491+
key: 'altmetric',
492+
enabled: true
493+
},
494+
{
495+
key: 'dimensions',
496+
enabled: true
497+
},
498+
]
485499
};
486500

487501
// Whether to enable Markdown (https://commonmark.org/) and MathJax (https://www.mathjax.org/)
@@ -736,20 +750,4 @@ export class DefaultAppConfig implements AppConfig {
736750
additionalMetadataFields: [],
737751
authorMetadata: ['dc.contributor.author', 'dc.creator', 'dc.contributor.*'],
738752
};
739-
740-
//Configuration for third-party metrics in Klaro
741-
metricsConsents: ThirdPartyMetric[] = [
742-
{
743-
key: 'plumX',
744-
enabled: true
745-
},
746-
{
747-
key: 'altmetric',
748-
enabled: true
749-
},
750-
{
751-
key: 'dimensions',
752-
enabled: true
753-
},
754-
];
755753
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Config } from './config.interface';
2+
import { ThirdPartyMetric } from './third-party-metric-config';
23

34
export interface InfoConfig extends Config {
45
enableEndUserAgreement: boolean;
56
enablePrivacyStatement: boolean;
7+
metricsConsents: ThirdPartyMetric[];
68
}

src/environments/environment.test.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,21 @@ export const environment: BuildConfig = {
323323
info: {
324324
enableEndUserAgreement: true,
325325
enablePrivacyStatement: true,
326+
//Configuration for third-party metrics in Klaro
327+
metricsConsents: [
328+
{
329+
key: 'plumX',
330+
enabled: true
331+
},
332+
{
333+
key: 'altmetric',
334+
enabled: true
335+
},
336+
{
337+
key: 'dimensions',
338+
enabled: true
339+
},
340+
]
326341
},
327342
markdown: {
328343
enabled: false,
@@ -553,20 +568,4 @@ export const environment: BuildConfig = {
553568
],
554569
authorMetadata: ['dc.contributor.author', 'dc.contributor.editor', 'dc.contributor.contributor', 'dc.creator'],
555570
},
556-
557-
//Configuration for third-party metrics in Klaro
558-
metricsConsents: [
559-
{
560-
key: 'plumX',
561-
enabled: true
562-
},
563-
{
564-
key: 'altmetric',
565-
enabled: true
566-
},
567-
{
568-
key: 'dimensions',
569-
enabled: true
570-
},
571-
],
572571
};

0 commit comments

Comments
 (0)