diff --git a/src/app/+collection-page/collection-page.component.ts b/src/app/+collection-page/collection-page.component.ts index ec94ed4404..646a8944ee 100644 --- a/src/app/+collection-page/collection-page.component.ts +++ b/src/app/+collection-page/collection-page.component.ts @@ -19,6 +19,10 @@ import { fadeIn, fadeInOut } from '../shared/animations/fade'; import { hasValue, isNotEmpty } from '../shared/empty.util'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; import { filter, flatMap, map } from 'rxjs/operators'; +import { SearchService } from '../+search-page/search-service/search.service'; +import { PaginatedSearchOptions } from '../+search-page/paginated-search-options.model'; +import { SearchResult } from '../+search-page/search-result.model'; +import { toDSpaceObjectListRD } from '../core/shared/operators'; @Component({ selector: 'ds-collection-page', @@ -41,7 +45,7 @@ export class CollectionPageComponent implements OnInit, OnDestroy { constructor( private collectionDataService: CollectionDataService, - private itemDataService: ItemDataService, + private searchService: SearchService, private metadata: MetadataService, private route: ActivatedRoute ) { @@ -82,12 +86,13 @@ export class CollectionPageComponent implements OnInit, OnDestroy { } updatePage(searchOptions) { - this.itemRD$ = this.itemDataService.findAll({ - scopeID: this.collectionId, - currentPage: searchOptions.pagination.currentPage, - elementsPerPage: searchOptions.pagination.pageSize, - sort: searchOptions.sort - }); + this.itemRD$ = this.searchService.search( + new PaginatedSearchOptions({ + scope: this.collectionId, + pagination: searchOptions.pagination, + sort: searchOptions.sort, + filters: {type: 2} + })).pipe(toDSpaceObjectListRD()) as Observable>>; } ngOnDestroy(): void { diff --git a/src/app/+collection-page/collection-page.module.ts b/src/app/+collection-page/collection-page.module.ts index d0bc918b22..85462e67a3 100644 --- a/src/app/+collection-page/collection-page.module.ts +++ b/src/app/+collection-page/collection-page.module.ts @@ -5,11 +5,13 @@ import { SharedModule } from '../shared/shared.module'; import { CollectionPageComponent } from './collection-page.component'; import { CollectionPageRoutingModule } from './collection-page-routing.module'; +import { SearchPageModule } from '../+search-page/search-page.module'; @NgModule({ imports: [ CommonModule, SharedModule, + SearchPageModule, CollectionPageRoutingModule ], declarations: [ diff --git a/src/app/+search-page/paginated-search-options.model.spec.ts b/src/app/+search-page/paginated-search-options.model.spec.ts index 312e170f1b..f12d148f7a 100644 --- a/src/app/+search-page/paginated-search-options.model.spec.ts +++ b/src/app/+search-page/paginated-search-options.model.spec.ts @@ -12,12 +12,7 @@ describe('PaginatedSearchOptions', () => { const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47'; const baseUrl = 'www.rest.com'; beforeEach(() => { - options = new PaginatedSearchOptions(); - options.sort = sortOptions; - options.pagination = pageOptions; - options.filters = filters; - options.query = query; - options.scope = scope; + options = new PaginatedSearchOptions({sort: sortOptions, pagination: pageOptions, filters: filters, query: query, scope: scope}); }); describe('when toRestUrl is called', () => { diff --git a/src/app/+search-page/paginated-search-options.model.ts b/src/app/+search-page/paginated-search-options.model.ts index a1d147fb9d..c565c5da49 100644 --- a/src/app/+search-page/paginated-search-options.model.ts +++ b/src/app/+search-page/paginated-search-options.model.ts @@ -10,6 +10,12 @@ export class PaginatedSearchOptions extends SearchOptions { pagination?: PaginationComponentOptions; sort?: SortOptions; + constructor(options: {scope?: string, query?: string, filters?: any, pagination?: PaginationComponentOptions, sort?: SortOptions}) { + super(options) + this.pagination = options.pagination; + this.sort = options.sort; + } + /** * Method to generate the URL that can be used to request a certain page with specific sort options * @param {string} url The URL to the REST endpoint diff --git a/src/app/+search-page/search-options.model.spec.ts b/src/app/+search-page/search-options.model.spec.ts index fc4c9278d8..7da9348cc4 100644 --- a/src/app/+search-page/search-options.model.spec.ts +++ b/src/app/+search-page/search-options.model.spec.ts @@ -9,10 +9,7 @@ describe('SearchOptions', () => { const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47'; const baseUrl = 'www.rest.com'; beforeEach(() => { - options = new SearchOptions(); - options.filters = filters; - options.query = query; - options.scope = scope; + options = new SearchOptions({filters: filters, query: query, scope: scope}); }); describe('when toRestUrl is called', () => { diff --git a/src/app/+search-page/search-options.model.ts b/src/app/+search-page/search-options.model.ts index 6ac606f5cc..c29d786c58 100644 --- a/src/app/+search-page/search-options.model.ts +++ b/src/app/+search-page/search-options.model.ts @@ -10,6 +10,12 @@ export class SearchOptions { query?: string; filters?: any; + constructor(options: {scope?: string, query?: string, filters?: any}) { + this.scope = options.scope; + this.query = options.query; + this.filters = options.filters; + } + /** * Method to generate the URL that can be used request information about a search request * @param {string} url The URL to the REST endpoint diff --git a/src/app/+search-page/search-page.component.spec.ts b/src/app/+search-page/search-page.component.spec.ts index 57b8caaddc..63eb0a045b 100644 --- a/src/app/+search-page/search-page.component.spec.ts +++ b/src/app/+search-page/search-page.component.spec.ts @@ -37,7 +37,7 @@ describe('SearchPageComponent', () => { pagination.currentPage = 1; pagination.pageSize = 10; const sort: SortOptions = new SortOptions('score', SortDirection.DESC); - const mockResults = Observable.of(new RemoteData(false, false, true, null,['test', 'data'])); + const mockResults = Observable.of(new RemoteData(false, false, true, null, ['test', 'data'])); const searchServiceStub = jasmine.createSpyObj('SearchService', { search: mockResults, getSearchLink: '/search', @@ -46,11 +46,11 @@ describe('SearchPageComponent', () => { const queryParam = 'test query'; const scopeParam = '7669c72a-3f2a-451f-a3b9-9210e7a4c02f'; const paginatedSearchOptions = { - query: queryParam, - scope: scopeParam, - pagination, - sort - }; + query: queryParam, + scope: scopeParam, + pagination, + sort + }; const activatedRouteStub = { queryParams: Observable.of({ query: queryParam, @@ -178,5 +178,4 @@ describe('SearchPageComponent', () => { }); }); -}) -; +}); \ No newline at end of file diff --git a/src/app/+search-page/search-service/search-configuration.service.spec.ts b/src/app/+search-page/search-service/search-configuration.service.spec.ts index af1b19f06a..eb10273731 100644 --- a/src/app/+search-page/search-service/search-configuration.service.spec.ts +++ b/src/app/+search-page/search-service/search-configuration.service.spec.ts @@ -14,7 +14,7 @@ describe('SearchConfigurationService', () => { 'f.date.min': ['2013'], 'f.date.max': ['2018'] }; - const defaults = Object.assign(new PaginatedSearchOptions(), { + const defaults = new PaginatedSearchOptions( { pagination: Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }), sort: new SortOptions('score', SortDirection.DESC), query: '', diff --git a/src/app/+search-page/search-service/search-configuration.service.ts b/src/app/+search-page/search-service/search-configuration.service.ts index 35462debc4..79574f95a7 100644 --- a/src/app/+search-page/search-service/search-configuration.service.ts +++ b/src/app/+search-page/search-service/search-configuration.service.ts @@ -174,7 +174,7 @@ export class SearchConfigurationService implements OnDestroy { this.getFiltersPart() ).subscribe((update) => { const currentValue: SearchOptions = this.searchOptions.getValue(); - const updatedValue: SearchOptions = Object.assign(new SearchOptions(), currentValue, update); + const updatedValue: SearchOptions = Object.assign(currentValue, update); this.searchOptions.next(updatedValue); }); } @@ -193,7 +193,7 @@ export class SearchConfigurationService implements OnDestroy { this.getFiltersPart() ).subscribe((update) => { const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue(); - const updatedValue: PaginatedSearchOptions = Object.assign(new PaginatedSearchOptions(), currentValue, update); + const updatedValue: PaginatedSearchOptions = Object.assign(currentValue, update); this.paginatedSearchOptions.next(updatedValue); }); } @@ -203,7 +203,7 @@ export class SearchConfigurationService implements OnDestroy { */ get defaults(): Observable> { if (hasNoValue(this._defaults)) { - const options = Object.assign(new PaginatedSearchOptions(), { + const options = new PaginatedSearchOptions({ pagination: this.defaultPagination, sort: this.defaultSort, scope: this.defaultScope, diff --git a/src/app/+search-page/search-service/search.service.spec.ts b/src/app/+search-page/search-service/search.service.spec.ts index 4cd911e2e6..569821fb91 100644 --- a/src/app/+search-page/search-service/search.service.spec.ts +++ b/src/app/+search-page/search-service/search.service.spec.ts @@ -155,7 +155,7 @@ describe('SearchService', () => { describe('when search is called', () => { const endPoint = 'http://endpoint.com/test/test'; - const searchOptions = new PaginatedSearchOptions(); + const searchOptions = new PaginatedSearchOptions({}); const queryResponse = Object.assign(new SearchQueryResponse(), { objects: [] }); const response = new SearchSuccessResponse(queryResponse, '200'); const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response }); diff --git a/src/app/core/shared/operators.ts b/src/app/core/shared/operators.ts index af41c9c56b..fcb4c2c256 100644 --- a/src/app/core/shared/operators.ts +++ b/src/app/core/shared/operators.ts @@ -8,6 +8,9 @@ import { RemoteData } from '../data/remote-data'; import { RestRequest } from '../data/request.models'; import { RequestEntry } from '../data/request.reducer'; import { RequestService } from '../data/request.service'; +import { DSpaceObject } from './dspace-object.model'; +import { PaginatedList } from '../data/paginated-list'; +import { SearchResult } from '../../+search-page/search-result.model'; /** * This file contains custom RxJS operators that can be used in multiple places @@ -49,3 +52,13 @@ export const getRemoteDataPayload = () => export const getSucceededRemoteData = () => (source: Observable>): Observable> => source.pipe(first((rd: RemoteData) => rd.hasSucceeded)); + +export const toDSpaceObjectListRD = () => + (source: Observable>>>): Observable>> => + source.pipe( + map((rd: RemoteData>>) => { + const dsoPage: T[] = rd.payload.page.map((searchResult: SearchResult) => searchResult.dspaceObject); + const payload = Object.assign(rd.payload, { page: dsoPage }) as PaginatedList; + return Object.assign(rd, {payload: payload}); + }) + );