Skip to content

Commit 71f0529

Browse files
committed
[DSC-1974] Refactoring of browse most component in order to use preventMetadataSecurity projection as default
1 parent fa2d395 commit 71f0529

7 files changed

Lines changed: 104 additions & 38 deletions

File tree

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

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { followLink } from '../utils/follow-link-config.model';
22
import { CollectionElementLinkType } from '../object-collection/collection-element-link.type';
3-
import { TopSection } from '../../core/layout/models/section.model';
43
import { Component, Input, OnChanges, OnInit, PLATFORM_ID, inject } from '@angular/core';
54
import { isPlatformServer } from '@angular/common';
65

@@ -31,17 +30,42 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang
3130
protected readonly platformId = inject(PLATFORM_ID);
3231
protected readonly searchService = inject(SearchService);
3332

34-
protected followThumbnailLink: boolean; // to be overridden
33+
protected abstract followMetricsLink: boolean; // to be overridden
34+
protected abstract followThumbnailLink: boolean; // to be overridden
3535

36+
/**
37+
* The context of listable object
38+
*/
39+
@Input() context: Context;
40+
41+
/**
42+
* The pagination options
43+
*/
3644
@Input() paginatedSearchOptions: PaginatedSearchOptions;
3745

38-
@Input() context: Context;
46+
/**
47+
* Optional projection to use during the search
48+
*/
49+
@Input() projection = 'preventMetadataSecurity';
50+
51+
/**
52+
* Whether to show the badge label or not
53+
*/
54+
@Input() showLabel: boolean;
3955

40-
@Input() topSection: TopSection;
56+
/**
57+
* Whether to show the metrics badges
58+
*/
59+
@Input() showMetrics = this.appConfig.browseBy.showMetrics;
60+
61+
/**
62+
* Whether to show the thumbnail preview
63+
*/
64+
@Input() showThumbnails = this.appConfig.browseBy.showThumbnails;
4165

4266
public collectionElementLinkTypeEnum = CollectionElementLinkType;
4367

44-
paginatedSearchOptionsBS: BehaviorSubject<PaginatedSearchOptions>;
68+
paginatedSearchOptions$: BehaviorSubject<PaginatedSearchOptions>;
4569

4670
searchResults$: Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>;
4771

@@ -51,13 +75,23 @@ export abstract class AbstractBrowseElementsComponent implements OnInit, OnChang
5175
if (isPlatformServer(this.platformId)) {
5276
return;
5377
}
54-
this.paginatedSearchOptionsBS?.next(this.paginatedSearchOptions);
78+
this.paginatedSearchOptions$?.next(this.paginatedSearchOptions);
5579
}
5680

5781
ngOnInit() {
58-
const followLinks = this.followThumbnailLink ? [followLink('thumbnail'), followLink('metrics')] : [followLink('metrics')];
59-
this.paginatedSearchOptionsBS = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions);
60-
this.searchResults$ = this.paginatedSearchOptionsBS.asObservable().pipe(
82+
const followLinks = [];
83+
if (this.followThumbnailLink) {
84+
followLinks.push(followLink('thumbnail'));
85+
}
86+
if (this.followMetricsLink) {
87+
followLinks.push(followLink('metrics'));
88+
}
89+
90+
this.paginatedSearchOptions = Object.assign(new PaginatedSearchOptions({}), this.paginatedSearchOptions, {
91+
projection: this.projection
92+
});
93+
this.paginatedSearchOptions$ = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions);
94+
this.searchResults$ = this.paginatedSearchOptions$.asObservable().pipe(
6195
mergeMap((paginatedSearchOptions) =>
6296
this.searchService.search(paginatedSearchOptions, null, true, true, ...followLinks),
6397
),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<ng-container *ngSwitchDefault>
44
<ds-themed-default-browse-elements
55
[showMetrics]="showMetrics"
6-
[showThumbnails]="topSection.showThumbnails"
6+
[showThumbnails]="showThumbnails ?? topSection.showThumbnails"
77
[topSection]="topSection"
88
[showLabel]="showLabel"
9-
[paginatedSearchOptions]="paginatedSearchOptionsBS.asObservable() | async"
9+
[paginatedSearchOptions]="paginatedSearchOptions$.asObservable() | async"
1010
[context]="context"
1111
></ds-themed-default-browse-elements>
1212
</ng-container>
Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TopSection, TopSectionTemplateType } from './../../core/layout/models/section.model';
1+
import { TopSection, TopSectionTemplateType } from '../../core/layout/models/section.model';
22
import { Component, Input, OnChanges, OnInit } from '@angular/core';
33
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
44
import { Context } from '../../core/shared/context.model';
@@ -12,19 +12,42 @@ import { BehaviorSubject } from 'rxjs';
1212

1313
export class BrowseMostElementsComponent implements OnInit, OnChanges {
1414

15+
/**
16+
* The pagination options
17+
*/
1518
@Input() paginatedSearchOptions: PaginatedSearchOptions;
1619

20+
/**
21+
* The context of listable object
22+
*/
1723
@Input() context: Context;
1824

19-
showLabel: boolean;
20-
21-
showMetrics = true;
22-
25+
/**
26+
* Optional projection to use during the search
27+
*/
28+
@Input() projection = 'preventMetadataSecurity';
29+
30+
/**
31+
* Whether to show the badge label or not
32+
*/
33+
@Input() showLabel: boolean;
34+
35+
/**
36+
* Whether to show the metrics badges
37+
*/
38+
@Input() showMetrics: boolean;
39+
40+
/**
41+
* Whether to show the thumbnail preview
42+
*/
43+
@Input() showThumbnails: boolean;
44+
45+
/*
46+
* The top section object
47+
*/
2348
@Input() topSection: TopSection;
2449

25-
paginatedSearchOptionsBS = new BehaviorSubject<PaginatedSearchOptions>(null);
26-
27-
templateTypeEnum = TopSectionTemplateType;
50+
paginatedSearchOptions$ = new BehaviorSubject<PaginatedSearchOptions>(null);
2851

2952
sectionTemplateType: TopSectionTemplateType;
3053

@@ -33,6 +56,6 @@ export class BrowseMostElementsComponent implements OnInit, OnChanges {
3356
}
3457

3558
ngOnChanges() { // trigger change detection on child components
36-
this.paginatedSearchOptionsBS.next(this.paginatedSearchOptions);
59+
this.paginatedSearchOptions$.next(this.paginatedSearchOptions);
3760
}
3861
}
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnChanges, OnInit } from '@angular/core';
1+
import { Component, OnChanges, OnInit } from '@angular/core';
22
import { AbstractBrowseElementsComponent } from '../abstract-browse-elements.component';
33

44
@Component({
@@ -8,17 +8,12 @@ import { AbstractBrowseElementsComponent } from '../abstract-browse-elements.com
88
})
99
export class DefaultBrowseElementsComponent extends AbstractBrowseElementsComponent implements OnInit, OnChanges {
1010

11-
/**
12-
* Whether to show the metrics badges
13-
*/
14-
@Input() showMetrics = this.appConfig.browseBy.showMetrics;
11+
protected followMetricsLink: boolean;
12+
protected followThumbnailLink: boolean;
1513

16-
/**
17-
* Whether to show the thumbnail preview
18-
*/
19-
@Input() showThumbnails = this.appConfig.browseBy.showThumbnails;
20-
21-
@Input() showLabel: boolean;
22-
23-
protected followThumbnailLink = this.appConfig.browseBy.showThumbnails;
14+
ngOnInit() {
15+
this.followMetricsLink = this.showMetrics ?? this.appConfig.browseBy.showMetrics;
16+
this.followThumbnailLink = this.showThumbnails ?? this.appConfig.browseBy.showThumbnails;
17+
super.ngOnInit();
18+
}
2419
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ export class ThemedDefaultBrowseElementsComponent extends ThemedComponent<Defaul
2525

2626
// DefaultBrowseElementsComponent I/O variables
2727

28+
@Input() projection: string;
29+
2830
@Input() showMetrics: boolean;
2931

3032
@Input() showThumbnails: boolean;
3133

3234
@Input() showLabel: boolean;
3335

34-
protected inAndOutputNames: (keyof DefaultBrowseElementsComponent & keyof this)[] = ['paginatedSearchOptions', 'context', 'topSection', 'showMetrics', 'showThumbnails', 'showLabel'];
36+
protected inAndOutputNames: (keyof DefaultBrowseElementsComponent & keyof this)[] = ['paginatedSearchOptions', 'context', 'showMetrics', 'showThumbnails', 'showLabel', 'projection'];
3537

3638
protected getComponentName(): string {
3739
return 'DefaultBrowseElementsComponent';

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { TopSection } from './../../core/layout/models/section.model';
1+
import { TopSection } from '../../core/layout/models/section.model';
22
import { Component, Input } from '@angular/core';
33
import { ThemedComponent } from '../theme-support/themed.component';
44
import { BrowseMostElementsComponent } from './browse-most-elements.component';
5-
import { Context } from 'vm';
5+
import { Context } from '../../core/shared/context.model';
66
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model';
77

88
/**
@@ -19,9 +19,17 @@ export class ThemedBrowseMostElementsComponent extends ThemedComponent<BrowseMos
1919

2020
@Input() paginatedSearchOptions: PaginatedSearchOptions;
2121

22+
@Input() projection = 'preventMetadataSecurity';
23+
24+
@Input() showLabel: boolean;
25+
26+
@Input() showMetrics: boolean;
27+
28+
@Input() showThumbnails: boolean;
29+
2230
@Input() topSection: TopSection;
2331

24-
protected inAndOutputNames: (keyof BrowseMostElementsComponent & keyof this)[] = ['context', 'paginatedSearchOptions', 'topSection'];
32+
protected inAndOutputNames: (keyof BrowseMostElementsComponent & keyof this)[] = ['context', 'paginatedSearchOptions', 'projection', 'showLabel', 'showMetrics', 'showThumbnails', 'topSection'];
2533

2634
protected getComponentName(): string {
2735
return 'BrowseMostElementsComponent';

src/app/shared/explore/section-component/top-section/top-section.component.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<div *ngIf="topSection.titleKey" class="card-header">{{ 'explore.index.' + topSection.titleKey | translate }}</div>
44
<div *ngIf="!topSection.titleKey" class="card-header">{{ 'explore.index.' + topSection.sortField | translate }}</div>
55
<div class="card-body p-0">
6-
<ds-themed-browse-most-elements [context]="context" [paginatedSearchOptions]="paginatedSearchOptions" [topSection]="topSection"></ds-themed-browse-most-elements>
6+
<ds-themed-browse-most-elements [context]="context"
7+
[paginatedSearchOptions]="paginatedSearchOptions"
8+
[showLabel]="true"
9+
[showMetrics]="true"
10+
[topSection]="topSection"></ds-themed-browse-most-elements>
711
</div>
812
</div>
913
</div>

0 commit comments

Comments
 (0)