diff --git a/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/cris-layout-metadata-box.component.ts b/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/cris-layout-metadata-box.component.ts index 109458c4e24..f0d3166dad0 100644 --- a/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/cris-layout-metadata-box.component.ts +++ b/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/cris-layout-metadata-box.component.ts @@ -36,7 +36,7 @@ export class CrisLayoutMetadataBoxComponent extends CrisLayoutBoxModelComponent subs: Subscription[] = []; constructor( - public cd: ChangeDetectorRef, + public cdr: ChangeDetectorRef, protected translateService: TranslateService, @Inject('boxProvider') public boxProvider: CrisLayoutBox, @Inject('itemProvider') public itemProvider: Item @@ -55,6 +55,7 @@ export class CrisLayoutMetadataBoxComponent extends CrisLayoutBoxModelComponent */ setMetadataComponents(metadatacomponents: MetadataBoxConfiguration) { this.metadataBoxConfiguration = metadatacomponents; + this.cdr.detectChanges(); } /** diff --git a/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metrics/cris-layout-metrics-box.component.ts b/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metrics/cris-layout-metrics-box.component.ts index 20d28855e79..4356141256d 100644 --- a/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metrics/cris-layout-metrics-box.component.ts +++ b/src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metrics/cris-layout-metrics-box.component.ts @@ -1,4 +1,4 @@ -import { Component, Inject, OnDestroy, OnInit } from '@angular/core'; +import { Component, Inject, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core'; import { BehaviorSubject, Subscription } from 'rxjs'; import { TranslateService } from '@ngx-translate/core'; @@ -13,6 +13,7 @@ import { ItemDataService } from '../../../../../core/data/item-data.service'; import { CrisLayoutBox, MetricsBoxConfiguration, } from '../../../../../core/layout/models/box.model'; import { Item } from '../../../../../core/shared/item.model'; import { CrisLayoutMetricRow } from '../../../../../core/layout/models/tab.model'; +import { isPlatformBrowser } from '@angular/common'; /** * This component renders the metadata boxes of items @@ -54,7 +55,8 @@ export class CrisLayoutMetricsBoxComponent extends CrisLayoutBoxModelComponent i protected itemService: ItemDataService, protected translateService: TranslateService, @Inject('boxProvider') public boxProvider: CrisLayoutBox, - @Inject('itemProvider') public itemProvider: Item + @Inject('itemProvider') public itemProvider: Item, + @Inject(PLATFORM_ID) protected platformId: Object ) { super(translateService, boxProvider, itemProvider); } @@ -62,17 +64,19 @@ export class CrisLayoutMetricsBoxComponent extends CrisLayoutBoxModelComponent i ngOnInit() { super.ngOnInit(); - this.metricsBoxConfiguration = this.box.configuration as MetricsBoxConfiguration; - this.subs.push( - this.itemService.getMetrics(this.item.uuid).pipe(getFirstSucceededRemoteDataPayload()) - .subscribe((result) => { - const matchingMetrics = this.metricsComponentService.getMatchingMetrics( - result.page, - this.metricsBoxConfiguration.maxColumns, - this.metricsBoxConfiguration.metrics - ); - this.metricRows.next(matchingMetrics); - })); + if (isPlatformBrowser(this.platformId)) { + this.metricsBoxConfiguration = this.box.configuration as MetricsBoxConfiguration; + this.subs.push( + this.itemService.getMetrics(this.item.uuid).pipe(getFirstSucceededRemoteDataPayload()) + .subscribe((result) => { + const matchingMetrics = this.metricsComponentService.getMatchingMetrics( + result.page, + this.metricsBoxConfiguration.maxColumns, + this.metricsBoxConfiguration.metrics + ); + this.metricRows.next(matchingMetrics); + })); + } } /** diff --git a/src/app/shared/object-list/metric-donuts/metric-donuts.component.html b/src/app/shared/object-list/metric-donuts/metric-donuts.component.html index 539c0839236..f6621ab77b6 100644 --- a/src/app/shared/object-list/metric-donuts/metric-donuts.component.html +++ b/src/app/shared/object-list/metric-donuts/metric-donuts.component.html @@ -1,5 +1,5 @@
- + = new BehaviorSubject([]); + + constructor(private linkService: LinkService, @Inject(PLATFORM_ID) protected platformId: Object) { } ngOnInit() { this.linkService.resolveLink(this.item, followLink('metrics')); + if (isPlatformBrowser(this.platformId)) { + this.retrieveMetrics().subscribe((metrics: Metric[]) => { + this.metrics$.next(metrics); + }) + } } /** - * Filter metrics with a positive metricCount value. + * Retrieve metrics from item object. */ - donuts(): Observable { - if (!hasValue(this.item.metrics)) { + private retrieveMetrics(): Observable { + if (isEmpty(this.item.metrics)) { return of([]); + } else { + return this.item.metrics.pipe( + getFirstCompletedRemoteData(), + map((metricsRD: RemoteData>) => { + if (metricsRD.hasSucceeded) { + return metricsRD.payload.page.filter(metric => allowedDonuts.includes(metric.metricType)); + } else { + return []; + } + })); } - return this.item.metrics.pipe( - getFirstSucceededRemoteListPayload(), - map((metrics: Metric[]) => { - return metrics.filter(metric => allowedDonuts.includes(metric.metricType)); - })); } identify(index, item) { diff --git a/src/app/shared/search/search-charts/search-charts.component.html b/src/app/shared/search/search-charts/search-charts.component.html index 6dfdf360751..86df679aad4 100644 --- a/src/app/shared/search/search-charts/search-charts.component.html +++ b/src/app/shared/search/search-charts/search-charts.component.html @@ -1,4 +1,4 @@ -
+
diff --git a/src/app/shared/search/search-charts/search-charts.component.ts b/src/app/shared/search/search-charts/search-charts.component.ts index 79041aa4d09..cd549726bc7 100644 --- a/src/app/shared/search/search-charts/search-charts.component.ts +++ b/src/app/shared/search/search-charts/search-charts.component.ts @@ -1,15 +1,17 @@ -import { getRemoteDataPayload } from './../../../core/shared/operators'; -import { SEARCH_CONFIG_SERVICE } from './../../../my-dspace-page/my-dspace-page.component'; -import { SearchConfigurationService } from './../../../core/shared/search/search-configuration.service'; -import { SearchService } from './../../../core/shared/search/search.service'; -import { Component, Inject, Input, OnInit } from '@angular/core'; +import { isPlatformBrowser } from '@angular/common'; +import { ChangeDetectorRef, Component, Inject, Input, OnInit, PLATFORM_ID } from '@angular/core'; import { BehaviorSubject, Observable, of } from 'rxjs'; -import { filter, map, switchMap, take, tap, mergeMap } from 'rxjs/operators'; +import { filter, map, mergeMap, switchMap, take, tap } from 'rxjs/operators'; + import { RemoteData } from '../../../core/data/remote-data'; import { SearchFilterConfig } from '../models/search-filter-config.model'; import { shrinkInOut } from '../../animations/shrink'; import { hasValue, isNotEmpty } from '../../empty.util'; +import { getRemoteDataPayload } from '../../../core/shared/operators'; +import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component'; +import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service'; +import { SearchService } from '../../../core/shared/search/search.service'; @Component({ selector: 'ds-search-charts', @@ -57,25 +59,37 @@ export class SearchChartsComponent implements OnInit { */ selectedFilter: SearchFilterConfig; + /** + * Whether a platform id represents a browser platform. + */ + isPlatformBrowser: boolean; - constructor(private searchService: SearchService, + constructor( + private cdr: ChangeDetectorRef, + private searchService: SearchService, + @Inject(PLATFORM_ID) protected platformId: Object, @Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService) { } ngOnInit(): void { - this.filters.pipe( - filter((rd: RemoteData) => isNotEmpty(rd)), - take(1), - mergeMap((rd: RemoteData) => { - return this.hasFacetValues(rd.payload[0]).pipe( - tap((hasValues) => { - this.selectedFilter = this.selectedFilter - ? this.selectedFilter - : rd.hasSucceeded && hasValues ? rd.payload[0] : null; - }) - ); - }), - ).subscribe(); + this.isPlatformBrowser = isPlatformBrowser(this.platformId); + + if (isPlatformBrowser(this.platformId)) { + this.filters.pipe( + filter((rd: RemoteData) => isNotEmpty(rd)), + take(1), + mergeMap((rd: RemoteData) => { + return this.hasFacetValues(rd.payload[0]).pipe( + tap((hasValues) => { + this.selectedFilter = this.selectedFilter + ? this.selectedFilter + : rd.hasSucceeded && hasValues ? rd.payload[0] : null; + this.cdr.detectChanges(); + }) + ); + }), + ).subscribe(); + } } /** diff --git a/src/app/social/social.component.ts b/src/app/social/social.component.ts index d058e6458d1..1c128b69001 100644 --- a/src/app/social/social.component.ts +++ b/src/app/social/social.component.ts @@ -1,9 +1,5 @@ -import { - Component, - Inject, OnDestroy, - OnInit, -} from '@angular/core'; -import { DOCUMENT } from '@angular/common'; +import { Component, Inject, OnDestroy, OnInit, PLATFORM_ID, } from '@angular/core'; +import { DOCUMENT, isPlatformBrowser } from '@angular/common'; import { ActivatedRoute } from '@angular/router'; import { SocialService } from './social.service'; @@ -13,7 +9,7 @@ import { SocialService } from './social.service'; styleUrls: ['./social.component.scss'] }) /** - * Component to render dinamically the social2 buttons using addThis plugin + * Component to render dynamically the social2 buttons using addThis plugin */ export class SocialComponent implements OnInit, OnDestroy { @@ -25,19 +21,22 @@ export class SocialComponent implements OnInit, OnDestroy { subscription; constructor(@Inject(DOCUMENT) private _document: Document, + @Inject(PLATFORM_ID) protected platformId: Object, private socialService: SocialService, private activatedRoute: ActivatedRoute, ) { } ngOnInit() { - this.subscription = this.socialService.showSocialButtons(this.activatedRoute).subscribe((show) => { - if (show) { - this.showSocialButtons(); - } else { - this.hideSocialButtons(); - } - }); + if (isPlatformBrowser(this.platformId)) { + this.subscription = this.socialService.showSocialButtons(this.activatedRoute).subscribe((show) => { + if (show) { + this.showSocialButtons(); + } else { + this.hideSocialButtons(); + } + }); + } } showSocialButtons() { diff --git a/src/app/social/social.service.ts b/src/app/social/social.service.ts index 7757685d78b..0e6b52e3bab 100644 --- a/src/app/social/social.service.ts +++ b/src/app/social/social.service.ts @@ -1,10 +1,12 @@ import { Injectable } from '@angular/core'; +import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; + +import { BehaviorSubject, combineLatest, Observable, of } from 'rxjs'; +import { distinctUntilChanged, filter, map, mergeMap, switchMap, take } from 'rxjs/operators'; + import { environment } from '../../environments/environment'; import { CookieService } from '../core/services/cookie.service'; -import { distinctUntilChanged, filter, map, mergeMap, switchMap, take } from 'rxjs/operators'; -import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; import { AuthService } from '../core/auth/auth.service'; -import { BehaviorSubject, combineLatest, Observable, of } from 'rxjs'; export const APP_THIS_ID_SELECTOR = '#at4-share'; @@ -29,7 +31,7 @@ export class SocialService { } initializeAddThisScript(_document: Document): any { - // console.log('Initializing the addThisCookie script'); + // Initializing the addThisCookie script const script = _document.createElement('script'); script.type = 'text/javascript'; script.src = environment.addThisPlugin.scriptUrl + environment.addThisPlugin.siteId; @@ -37,22 +39,21 @@ export class SocialService { } hide(_document: Document) { - // console.log('Hiding social buttons'); + // Hiding social buttons const socialButtons: HTMLElement = _document.querySelector(APP_THIS_ID_SELECTOR); if (socialButtons) { - // console.log('HTML Element found, setting display to none'); + // HTML Element found, setting display to none socialButtons.style.display = 'none'; } } show(_document: Document) { - // console.log('Showing social buttons'); + // Showing social buttons const socialButtons: HTMLElement = _document.querySelector(APP_THIS_ID_SELECTOR); if (socialButtons) { - // console.log('HTML Element found, setting display to block'); + // HTML Element found, setting display to block socialButtons.style.display = 'block'; } - // console.error('No HTML Elements to show'); } protected initialize(activatedRoute: ActivatedRoute) { @@ -89,7 +90,6 @@ export class SocialService { // Listen to every cookies / user state changes and evaluate sharing state combineLatest([cookies$, userUUId$]).subscribe(([cookieMap, userUUID]) => { - // console.log('COOKIE/USER change detected. Evaluating.', cookieMap, userUUID); this.evaluateShowHide(cookieMap, userUUID); }); @@ -119,17 +119,10 @@ export class SocialService { } protected isAddThisCookieEnabled(cookieMap, userUUID) { - // console.log(cookieMap, userUUID); - // if (userUUID) { - // console.log('The user is authenticated, checking klaro-' + userUUID); - // } else { - // console.log('The user is not authenticated, checking klaro-anonymous'); - // } const cookie = userUUID ? this.cookie.get('klaro-' + userUUID) : this.cookie.get('klaro-anonymous'); const addThisCookie = cookie ? cookie['add-this'] : false; - // console.log('AddThisCookie is ' + addThisCookie); + return addThisCookie; } - }