added search link fixes

This commit is contained in:
lotte
2019-05-15 15:34:46 +02:00
parent f34c19717d
commit c216e35a23
31 changed files with 271 additions and 106 deletions

View File

@@ -1,7 +1,7 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { filter, flatMap, map, take } from 'rxjs/operators';
import { filter, flatMap, map, switchMap, take } from 'rxjs/operators';
import { PaginatedSearchOptions } from '../+search-page/paginated-search-options.model';
import { SearchService } from '../+search-page/search-service/search.service';
import { SortDirection, SortOptions } from '../core/cache/models/sort-options.model';
@@ -15,7 +15,11 @@ import { Bitstream } from '../core/shared/bitstream.model';
import { Collection } from '../core/shared/collection.model';
import { DSpaceObjectType } from '../core/shared/dspace-object-type.model';
import { Item } from '../core/shared/item.model';
import { getSucceededRemoteData, toDSpaceObjectListRD } from '../core/shared/operators';
import {
getSucceededRemoteData,
redirectToPageNotFoundOn404,
toDSpaceObjectListRD
} from '../core/shared/operators';
import { fadeIn, fadeInOut } from '../shared/animations/fade';
import { hasValue, isNotEmpty } from '../shared/empty.util';
@@ -31,22 +35,19 @@ import { PaginationComponentOptions } from '../shared/pagination/pagination-comp
fadeInOut
]
})
export class CollectionPageComponent implements OnInit, OnDestroy {
export class CollectionPageComponent implements OnInit {
collectionRD$: Observable<RemoteData<Collection>>;
itemRD$: Observable<RemoteData<PaginatedList<Item>>>;
logoRD$: Observable<RemoteData<Bitstream>>;
paginationConfig: PaginationComponentOptions;
sortConfig: SortOptions;
private subs: Subscription[] = [];
private collectionId: string;
private currentPage: number;
private pageSize: number;
constructor(
private collectionDataService: CollectionDataService,
private searchService: SearchService,
private metadata: MetadataService,
private route: ActivatedRoute
private route: ActivatedRoute,
private router: Router
) {
this.paginationConfig = new PaginationComponentOptions();
this.paginationConfig.id = 'collection-page-pagination';
@@ -57,7 +58,8 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.collectionRD$ = this.route.data.pipe(
map((data) => data.collection),
map((data) => data.collection as RemoteData<Collection>),
redirectToPageNotFoundOn404(this.router),
take(1)
);
this.logoRD$ = this.collectionRD$.pipe(
@@ -65,42 +67,26 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
filter((collection: Collection) => hasValue(collection)),
flatMap((collection: Collection) => collection.logo)
);
this.subs.push(
this.route.queryParams.subscribe((params) => {
this.metadata.processRemoteData(this.collectionRD$);
const page = +params.page || this.paginationConfig.currentPage;
const pageSize = +params.pageSize || this.paginationConfig.pageSize;
this.collectionRD$.subscribe((rd: RemoteData<Collection>) => {
this.collectionId = rd.payload.id;
this.updatePage(page, pageSize);
});
})
);
this.route.queryParams.pipe(take(1)).subscribe((params) => {
this.metadata.processRemoteData(this.collectionRD$);
this.onPaginationChange(params)
})
}
updatePage(currentPage: number, pageSize: number) {
this.itemRD$ = this.searchService.search(
new PaginatedSearchOptions({
scope: this.collectionId,
pagination: {
currentPage,
pageSize
} as PaginationComponentOptions,
sort: this.sortConfig,
dsoType: DSpaceObjectType.ITEM
})).pipe(
toDSpaceObjectListRD(),
updatePage() {
this.itemRD$ = this.collectionRD$.pipe(
getSucceededRemoteData(),
take(1),
) as Observable<RemoteData<PaginatedList<Item>>>;
this.currentPage = currentPage;
this.pageSize = pageSize;
}
ngOnDestroy(): void {
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
map((rd) => rd.payload.id),
switchMap((id: string) => {
return this.searchService.search(
new PaginatedSearchOptions({
scope: id,
pagination: this.paginationConfig,
sort: this.sortConfig,
dsoType: DSpaceObjectType.ITEM
})).pipe(toDSpaceObjectListRD()) as Observable<RemoteData<PaginatedList<Item>>>;
})
)
}
isNotEmpty(object: any) {
@@ -108,8 +94,10 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
}
onPaginationChange(event) {
if (this.currentPage !== event.page || this.pageSize !== event.pageSize) {
this.updatePage(event.page, event.pageSize);
}
this.paginationConfig.currentPage = +event.page || this.paginationConfig.currentPage;
this.paginationConfig.pageSize = +event.pageSize || this.paginationConfig.pageSize;
this.sortConfig.direction = event.sortDirection || this.sortConfig.direction;
this.sortConfig.field = event.sortField || this.sortConfig.field;
this.updatePage();
}
}