Skip to content

Commit 1d8426d

Browse files
vNovskiatarix83
authored andcommitted
Merged in DSC-1336-improve-handling-of-dynamic-content-in-ssr (pull request DSpace#992)
DSC-1336 improve handling of dynamic content in ssr Approved-by: Giuseppe Digilio
2 parents f4f87cf + f1d1f5b commit 1d8426d

9 files changed

Lines changed: 51 additions & 11 deletions

File tree

src/app/collection-page/collection-page.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h3 class="sr-only">{{'collection.page.browse.recent.head' | translate}}</h3>
7474
</div>
7575
<ds-error *ngIf="collectionRD?.hasFailed"
7676
message="{{'error.collection' | translate}}"></ds-error>
77-
<ds-themed-loading *ngIf="collectionRD?.isLoading"
77+
<ds-themed-loading *ngIf="!collectionRD || collectionRD?.isLoading"
7878
message="{{'loading.collection' | translate}}"></ds-themed-loading>
7979
</div>
8080
</div>

src/app/collection-page/collection-page.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ChangeDetectionStrategy, Component, OnInit, Inject } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, OnInit, Inject, PLATFORM_ID } from '@angular/core';
2+
import { isPlatformServer } from '@angular/common';
23
import { ActivatedRoute, Router } from '@angular/router';
34
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subject } from 'rxjs';
45
import { filter, map, mergeMap, startWith, switchMap, take } from 'rxjs/operators';
@@ -62,6 +63,7 @@ export class CollectionPageComponent implements OnInit {
6263
collectionPageRoute$: Observable<string>;
6364

6465
constructor(
66+
@Inject(PLATFORM_ID) private platformId: Object,
6567
private collectionDataService: CollectionDataService,
6668
private searchService: SearchService,
6769
private route: ActivatedRoute,
@@ -82,6 +84,10 @@ export class CollectionPageComponent implements OnInit {
8284
}
8385

8486
ngOnInit(): void {
87+
if (isPlatformServer(this.platformId)) {
88+
return;
89+
}
90+
8591
this.collectionRD$ = this.route.data.pipe(
8692
map((data) => data.dso as RemoteData<Collection>),
8793
redirectOn4xx(this.router, this.authService),

src/app/home-page/recent-item-list/recent-item-list.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { ChangeDetectionStrategy, Component, ElementRef, Inject, OnInit, PLATFORM_ID } from '@angular/core';
2+
import { isPlatformServer } from '@angular/common';
3+
24
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
35
import { fadeIn, fadeInOut } from '../../shared/animations/fade';
46
import { RemoteData } from '../../core/data/remote-data';
@@ -62,6 +64,10 @@ export class RecentItemListComponent implements OnInit {
6264
this.sortConfig = new SortOptions(environment.homePage.recentSubmissions.sortField, SortDirection.DESC);
6365
}
6466
ngOnInit(): void {
67+
if (isPlatformServer(this.platformId)) {
68+
return;
69+
}
70+
6571
const linksToFollow: FollowLinkConfig<Item>[] = [];
6672
if (this.appConfig.browseBy.showThumbnails) {
6773
linksToFollow.push(followLink('thumbnail'));

src/app/search-page/configuration-search-page.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HostWindowService } from '../shared/host-window.service';
22
import { SidebarService } from '../shared/sidebar/sidebar.service';
33
import { SearchComponent } from '../shared/search/search.component';
4-
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
4+
import { ChangeDetectionStrategy, Component, Inject, PLATFORM_ID } from '@angular/core';
55
import { pushInOut } from '../shared/animations/push';
66
import { SEARCH_CONFIG_SERVICE } from '../my-dspace-page/my-dspace-page.component';
77
import { SearchConfigurationService } from '../core/shared/search/search-configuration.service';
@@ -32,9 +32,10 @@ export class ConfigurationSearchPageComponent extends SearchComponent {
3232
protected searchManager: SearchManager,
3333
protected sidebarService: SidebarService,
3434
protected windowService: HostWindowService,
35+
@Inject(PLATFORM_ID) public platformId: any,
3536
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
3637
protected routeService: RouteService,
3738
protected router: Router) {
38-
super(service, searchManager, sidebarService, windowService, searchConfigService, routeService, router);
39+
super(service, searchManager, sidebarService, windowService, searchConfigService, platformId, routeService, router);
3940
}
4041
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<ds-themed-search [showCharts]="true" [showCsvExport]="false" [showExport]="true" [trackStatistics]="true"></ds-themed-search>
1+
<ds-themed-search [renderOnServerSide]="false" [showCharts]="true" [showCsvExport]="false" [showExport]="true" [trackStatistics]="true"></ds-themed-search>

src/app/shared/browse-most-elements/browse-most-elements.component.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ChangeDetectorRef, Component, Inject, Input, OnInit } from '@angular/core';
1+
import { ChangeDetectorRef, Component, Inject, Input, OnInit, PLATFORM_ID } from '@angular/core';
2+
import { isPlatformServer } from '@angular/common';
23

34
import { SearchService } from '../../core/shared/search/search.service';
45
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
@@ -37,12 +38,17 @@ export class BrowseMostElementsComponent implements OnInit {
3738

3839
constructor(
3940
@Inject(APP_CONFIG) protected appConfig: AppConfig,
41+
@Inject(PLATFORM_ID) private platformId: Object,
4042
private searchService: SearchService,
4143
private cdr: ChangeDetectorRef) {
4244

4345
}
4446

4547
ngOnInit() {
48+
if (isPlatformServer(this.platformId)) {
49+
return;
50+
}
51+
4652
const showThumbnails = this.showThumbnails ?? this.appConfig.browseBy.showThumbnails;
4753
const followLinks = showThumbnails ? [followLink('thumbnail')] : [];
4854
this.searchService.search(this.paginatedSearchOptions, null, true, true, ...followLinks).pipe(

src/app/shared/explore/section-component/counters-section/counters-section.component.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Component, Inject, Input, OnInit } from '@angular/core';
1+
import { Component, Inject, Input, OnInit, PLATFORM_ID } from '@angular/core';
2+
import { isPlatformServer } from '@angular/common';
23

34
import { BehaviorSubject, forkJoin, Observable } from 'rxjs';
45
import { map } from 'rxjs/operators';
@@ -39,11 +40,16 @@ export class CountersSectionComponent implements OnInit {
3940

4041
constructor(private searchService: SearchService,
4142
private uuidService: UUIDService,
42-
@Inject(NativeWindowService) protected _window: NativeWindowRef) {
43+
@Inject(PLATFORM_ID) private platformId: Object,
44+
@Inject(NativeWindowService) protected _window: NativeWindowRef,) {
4345

4446
}
4547

4648
ngOnInit() {
49+
if (isPlatformServer(this.platformId)) {
50+
return;
51+
}
52+
4753
this.counterData$ = forkJoin(
4854
this.countersSection.counterSettingsList.map((counterSettings: CountersSettings) =>
4955
this.searchService.search(new PaginatedSearchOptions({

src/app/shared/search/search.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
Input,
77
OnDestroy,
88
OnInit,
9-
Output
9+
Output,
10+
PLATFORM_ID
1011
} from '@angular/core';
1112
import { NavigationStart, Router } from '@angular/router';
1213

@@ -49,6 +50,7 @@ import { COLLECTION_MODULE_PATH } from '../../collection-page/collection-page-ro
4950
import { COMMUNITY_MODULE_PATH } from '../../community-page/community-page-routing-paths';
5051
import { SearchManager } from '../../core/browse/search-manager';
5152
import { AlertType } from '../alert/alert-type';
53+
import { isPlatformServer } from '@angular/common';
5254

5355
@Component({
5456
selector: 'ds-search',
@@ -222,6 +224,11 @@ export class SearchComponent implements OnInit, OnDestroy {
222224
*/
223225
@Input() showFilterToggle = false;
224226

227+
/**
228+
* Defines whether to show the toggle button to Show/Hide filter
229+
*/
230+
@Input() renderOnServerSide = true;
231+
225232
/**
226233
* Defines whether to show the toggle button to Show/Hide chart
227234
*/
@@ -358,9 +365,10 @@ export class SearchComponent implements OnInit, OnDestroy {
358365
protected searchManager: SearchManager,
359366
protected sidebarService: SidebarService,
360367
protected windowService: HostWindowService,
368+
@Inject(PLATFORM_ID) public platformId: any,
361369
@Inject(SEARCH_CONFIG_SERVICE) public searchConfigService: SearchConfigurationService,
362370
protected routeService: RouteService,
363-
protected router: Router) {
371+
protected router: Router,) {
364372
this.isXsOrSm$ = this.windowService.isXsOrSm();
365373
}
366374

@@ -372,6 +380,11 @@ export class SearchComponent implements OnInit, OnDestroy {
372380
* If something changes, update the list of scopes for the dropdown
373381
*/
374382
ngOnInit(): void {
383+
if (!this.renderOnServerSide && isPlatformServer(this.platformId)) {
384+
this.initialized$.next(true);
385+
return;
386+
}
387+
375388
if (this.useUniquePageId) {
376389
// Create an unique pagination id related to the instance of the SearchComponent
377390
this.paginationId = uniqueId(this.paginationId);

src/app/shared/search/themed-search.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { AlertType } from '../alert/alert-type';
2020
templateUrl: '../theme-support/themed.component.html',
2121
})
2222
export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
23-
protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = ['configurationList', 'context', 'configuration', 'fixedFilterQuery', 'forcedEmbeddedKeys', 'useCachedVersionIfAvailable', 'collapseCharts', 'collapseFilters', 'inPlaceSearch', 'linkType', 'paginationId', 'projection', 'searchEnabled', 'sideBarWidth', 'searchFormPlaceholder', 'selectable', 'selectionConfig', 'showCharts', 'showExport', 'showSidebar', 'showThumbnails', 'showViewModes', 'useUniquePageId', 'viewModeList', 'showScopeSelector', 'showFilterToggle', 'showChartsToggle', 'showCsvExport', 'resultFound', 'deselectObject', 'selectObject', 'customEvent', 'trackStatistics', 'query', 'searchResultNotice', 'searchResultNoticeType', 'showSearchResultNotice'];
23+
protected inAndOutputNames: (keyof SearchComponent & keyof this)[] = ['configurationList', 'context', 'configuration', 'fixedFilterQuery', 'forcedEmbeddedKeys', 'useCachedVersionIfAvailable', 'collapseCharts', 'collapseFilters', 'inPlaceSearch', 'linkType', 'paginationId', 'projection', 'searchEnabled', 'sideBarWidth', 'searchFormPlaceholder', 'selectable', 'selectionConfig', 'showCharts', 'showExport', 'showSidebar', 'showThumbnails', 'showViewModes', 'useUniquePageId', 'viewModeList', 'showScopeSelector', 'showFilterToggle', 'showChartsToggle', 'showCsvExport', 'resultFound', 'deselectObject', 'selectObject', 'customEvent', 'trackStatistics', 'query', 'searchResultNotice', 'searchResultNoticeType', 'showSearchResultNotice', 'renderOnServerSide'];
2424

2525
@Input() configurationList: SearchConfigurationOption[];
2626

@@ -88,6 +88,8 @@ export class ThemedSearchComponent extends ThemedComponent<SearchComponent> {
8888

8989
@Input() query: string;
9090

91+
@Input() renderOnServerSide = false;
92+
9193
@Output() resultFound: EventEmitter<SearchObjects<DSpaceObject>> = new EventEmitter();
9294

9395
@Output() deselectObject: EventEmitter<ListableObject> = new EventEmitter();

0 commit comments

Comments
 (0)