forked from 4Science/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in task/dspace-cris-2023_02_x/DSC-1650-davide (pull request DS…
…pace#1929) Task/dspace cris 2023 02 x/DSC-1650 davide Approved-by: Francesco Molinaro
- Loading branch information
Showing
20 changed files
with
266 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/app/shared/browse-most-elements/abstract-browse-elements.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { followLink } from '../utils/follow-link-config.model'; | ||
import { CollectionElementLinkType } from '../object-collection/collection-element-link.type'; | ||
import { TopSection } from '../../core/layout/models/section.model'; | ||
import { Component, Input, OnChanges, OnInit, PLATFORM_ID, inject } from '@angular/core'; | ||
import { isPlatformServer } from '@angular/common'; | ||
|
||
import { SearchService } from '../../core/shared/search/search.service'; | ||
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model'; | ||
import { DSpaceObject } from '../../core/shared/dspace-object.model'; | ||
import { SearchResult } from '../search/models/search-result.model'; | ||
import { Context } from '../../core/shared/context.model'; | ||
import { RemoteData } from '../../core/data/remote-data'; | ||
import { PaginatedList } from '../../core/data/paginated-list.model'; | ||
import { | ||
getAllCompletedRemoteData, | ||
getPaginatedListPayload, | ||
getRemoteDataPayload, | ||
toDSpaceObjectListRD, | ||
} from '../../core/shared/operators'; | ||
import { APP_CONFIG } from '../../../config/app-config.interface'; | ||
import { BehaviorSubject, Observable, mergeMap } from 'rxjs'; | ||
import { Item } from '../../core/shared/item.model'; | ||
import { getItemPageRoute } from '../../item-page/item-page-routing-paths'; | ||
|
||
@Component({ | ||
template: '' | ||
}) | ||
export abstract class AbstractBrowseElementsComponent implements OnInit, OnChanges { | ||
|
||
protected readonly appConfig = inject(APP_CONFIG); | ||
protected readonly platformId = inject(PLATFORM_ID); | ||
protected readonly searchService = inject(SearchService); | ||
|
||
protected followThumbnailLink: boolean; // to be overridden | ||
|
||
@Input() paginatedSearchOptions: PaginatedSearchOptions; | ||
|
||
@Input() context: Context; | ||
|
||
@Input() topSection: TopSection; | ||
|
||
public collectionElementLinkTypeEnum = CollectionElementLinkType; | ||
|
||
paginatedSearchOptionsBS: BehaviorSubject<PaginatedSearchOptions>; | ||
|
||
searchResults$: Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>>; | ||
|
||
searchResultArray$: Observable<DSpaceObject[]>; | ||
|
||
ngOnChanges() { | ||
if (isPlatformServer(this.platformId)) { | ||
return; | ||
} | ||
this.paginatedSearchOptionsBS?.next(this.paginatedSearchOptions); | ||
} | ||
|
||
ngOnInit() { | ||
const followLinks = this.followThumbnailLink ? [followLink('thumbnail')] : []; | ||
this.paginatedSearchOptionsBS = new BehaviorSubject<PaginatedSearchOptions>(this.paginatedSearchOptions); | ||
this.searchResults$ = this.paginatedSearchOptionsBS.asObservable().pipe( | ||
mergeMap((paginatedSearchOptions) => | ||
this.searchService.search(paginatedSearchOptions, null, true, true, ...followLinks), | ||
), | ||
getAllCompletedRemoteData(), | ||
); | ||
|
||
this.searchResultArray$ = this.searchResults$.pipe( | ||
toDSpaceObjectListRD(), | ||
getRemoteDataPayload(), | ||
getPaginatedListPayload(), | ||
); | ||
} | ||
|
||
getItemPageRoute(item: DSpaceObject | Item) { | ||
return getItemPageRoute(item as Item); | ||
} | ||
} |
32 changes: 13 additions & 19 deletions
32
src/app/shared/browse-most-elements/browse-most-elements.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
<div class="m-2"> | ||
<ng-container *ngIf="searchResults"> | ||
<ul *ngIf="searchResults?.hasSucceeded" class="list-unstyled"> | ||
<li *ngFor="let object of searchResults?.payload?.page; let i = index; let last = last" class="mt-4 mb-4 d-flex" [class.border-bottom]="true && !last"> | ||
<ds-listable-object-component-loader [context]="context" | ||
[index]="i" | ||
[listID]="paginatedSearchOptions.configuration" | ||
[object]="object" | ||
[showLabel]="showLabel" | ||
[showMetrics]="showMetrics" | ||
[showThumbnails]="showThumbnails" | ||
[viewMode]="paginatedSearchOptions.view"></ds-listable-object-component-loader> | ||
</li> | ||
</ul> | ||
<div *ngIf="searchResults?.hasFailed"> | ||
{{ 'remote.error' | translate }} | ||
</div> | ||
</ng-container> | ||
<ds-loading *ngIf="!searchResults"></ds-loading> | ||
<div [ngSwitch]="(sectionTemplateType | lowercase)"> | ||
|
||
<ng-container *ngSwitchDefault> | ||
<ds-themed-default-browse-elements | ||
[showMetrics]="showMetrics" | ||
[showThumbnails]="topSection.showThumbnails" | ||
[topSection]="topSection" | ||
[showLabel]="showLabel" | ||
[paginatedSearchOptions]="paginatedSearchOptionsBS.asObservable() | async" | ||
[context]="context" | ||
></ds-themed-default-browse-elements> | ||
</ng-container> | ||
|
||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 15 additions & 43 deletions
58
src/app/shared/browse-most-elements/browse-most-elements.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,38 @@ | ||
import { ChangeDetectorRef, Component, Inject, Input, OnInit, PLATFORM_ID } from '@angular/core'; | ||
import { isPlatformServer } from '@angular/common'; | ||
|
||
import { SearchManager } from '../../core/browse/search-manager'; | ||
import { TopSection, TopSectionTemplateType } from './../../core/layout/models/section.model'; | ||
import { Component, Input, OnChanges, OnInit } from '@angular/core'; | ||
import { PaginatedSearchOptions } from '../search/models/paginated-search-options.model'; | ||
import { DSpaceObject } from '../../core/shared/dspace-object.model'; | ||
import { SearchResult } from '../search/models/search-result.model'; | ||
import { Context } from '../../core/shared/context.model'; | ||
import { RemoteData } from '../../core/data/remote-data'; | ||
import { PaginatedList } from '../../core/data/paginated-list.model'; | ||
import { getFirstCompletedRemoteData } from '../../core/shared/operators'; | ||
import { followLink } from '../utils/follow-link-config.model'; | ||
import { APP_CONFIG, AppConfig } from '../../../config/app-config.interface'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
@Component({ | ||
selector: 'ds-browse-most-elements', | ||
styleUrls: ['./browse-most-elements.component.scss'], | ||
templateUrl: './browse-most-elements.component.html' | ||
}) | ||
|
||
export class BrowseMostElementsComponent implements OnInit { | ||
export class BrowseMostElementsComponent implements OnInit, OnChanges { | ||
|
||
@Input() paginatedSearchOptions: PaginatedSearchOptions; | ||
|
||
@Input() context: Context; | ||
/** | ||
* Whether to show the badge label or not | ||
*/ | ||
@Input() showLabel: boolean; | ||
|
||
/** | ||
* Whether to show the metrics badges | ||
*/ | ||
@Input() showMetrics: boolean; | ||
showLabel: boolean; | ||
|
||
/** | ||
* Whether to show the thumbnail preview | ||
*/ | ||
@Input() showThumbnails: boolean; | ||
showMetrics = true; | ||
|
||
searchResults: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>; | ||
@Input() topSection: TopSection; | ||
|
||
constructor( | ||
@Inject(APP_CONFIG) protected appConfig: AppConfig, | ||
@Inject(PLATFORM_ID) private platformId: Object, | ||
private searchService: SearchManager, | ||
private cdr: ChangeDetectorRef) { | ||
paginatedSearchOptionsBS = new BehaviorSubject<PaginatedSearchOptions>(null); | ||
|
||
} | ||
templateTypeEnum = TopSectionTemplateType; | ||
|
||
ngOnInit() { | ||
if (isPlatformServer(this.platformId)) { | ||
return; | ||
} | ||
sectionTemplateType: TopSectionTemplateType; | ||
|
||
const showThumbnails = this.showThumbnails ?? this.appConfig.browseBy.showThumbnails; | ||
const followLinks = showThumbnails ? [followLink('thumbnail')] : []; | ||
this.searchService.search(this.paginatedSearchOptions, null, true, true, ...followLinks).pipe( | ||
getFirstCompletedRemoteData(), | ||
).subscribe((response: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) => { | ||
this.searchResults = response as any; | ||
this.cdr.detectChanges(); | ||
}); | ||
ngOnInit(): void { | ||
this.sectionTemplateType = this.topSection?.template ?? TopSectionTemplateType.DEFAULT; | ||
} | ||
|
||
ngOnChanges() { // trigger change detection on child components | ||
this.paginatedSearchOptionsBS.next(this.paginatedSearchOptions); | ||
} | ||
} |
Oops, something went wrong.