reworked items list on collection page

This commit is contained in:
lotte
2018-08-22 16:30:28 +02:00
parent 1ea0e0ecfc
commit f5fed28722
11 changed files with 53 additions and 30 deletions

View File

@@ -19,6 +19,10 @@ import { fadeIn, fadeInOut } from '../shared/animations/fade';
import { hasValue, isNotEmpty } from '../shared/empty.util'; import { hasValue, isNotEmpty } from '../shared/empty.util';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model'; import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { filter, flatMap, map } from 'rxjs/operators'; 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({ @Component({
selector: 'ds-collection-page', selector: 'ds-collection-page',
@@ -41,7 +45,7 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
constructor( constructor(
private collectionDataService: CollectionDataService, private collectionDataService: CollectionDataService,
private itemDataService: ItemDataService, private searchService: SearchService,
private metadata: MetadataService, private metadata: MetadataService,
private route: ActivatedRoute private route: ActivatedRoute
) { ) {
@@ -82,12 +86,13 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
} }
updatePage(searchOptions) { updatePage(searchOptions) {
this.itemRD$ = this.itemDataService.findAll({ this.itemRD$ = this.searchService.search(
scopeID: this.collectionId, new PaginatedSearchOptions({
currentPage: searchOptions.pagination.currentPage, scope: this.collectionId,
elementsPerPage: searchOptions.pagination.pageSize, pagination: searchOptions.pagination,
sort: searchOptions.sort sort: searchOptions.sort,
}); filters: {type: 2}
})).pipe(toDSpaceObjectListRD()) as Observable<RemoteData<PaginatedList<Item>>>;
} }
ngOnDestroy(): void { ngOnDestroy(): void {

View File

@@ -5,11 +5,13 @@ import { SharedModule } from '../shared/shared.module';
import { CollectionPageComponent } from './collection-page.component'; import { CollectionPageComponent } from './collection-page.component';
import { CollectionPageRoutingModule } from './collection-page-routing.module'; import { CollectionPageRoutingModule } from './collection-page-routing.module';
import { SearchPageModule } from '../+search-page/search-page.module';
@NgModule({ @NgModule({
imports: [ imports: [
CommonModule, CommonModule,
SharedModule, SharedModule,
SearchPageModule,
CollectionPageRoutingModule CollectionPageRoutingModule
], ],
declarations: [ declarations: [

View File

@@ -12,12 +12,7 @@ describe('PaginatedSearchOptions', () => {
const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47'; const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47';
const baseUrl = 'www.rest.com'; const baseUrl = 'www.rest.com';
beforeEach(() => { beforeEach(() => {
options = new PaginatedSearchOptions(); options = new PaginatedSearchOptions({sort: sortOptions, pagination: pageOptions, filters: filters, query: query, scope: scope});
options.sort = sortOptions;
options.pagination = pageOptions;
options.filters = filters;
options.query = query;
options.scope = scope;
}); });
describe('when toRestUrl is called', () => { describe('when toRestUrl is called', () => {

View File

@@ -10,6 +10,12 @@ export class PaginatedSearchOptions extends SearchOptions {
pagination?: PaginationComponentOptions; pagination?: PaginationComponentOptions;
sort?: SortOptions; 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 * 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 * @param {string} url The URL to the REST endpoint

View File

@@ -9,10 +9,7 @@ describe('SearchOptions', () => {
const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47'; const scope = '0fde1ecb-82cc-425a-b600-ac3576d76b47';
const baseUrl = 'www.rest.com'; const baseUrl = 'www.rest.com';
beforeEach(() => { beforeEach(() => {
options = new SearchOptions(); options = new SearchOptions({filters: filters, query: query, scope: scope});
options.filters = filters;
options.query = query;
options.scope = scope;
}); });
describe('when toRestUrl is called', () => { describe('when toRestUrl is called', () => {

View File

@@ -10,6 +10,12 @@ export class SearchOptions {
query?: string; query?: string;
filters?: any; 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 * Method to generate the URL that can be used request information about a search request
* @param {string} url The URL to the REST endpoint * @param {string} url The URL to the REST endpoint

View File

@@ -37,7 +37,7 @@ describe('SearchPageComponent', () => {
pagination.currentPage = 1; pagination.currentPage = 1;
pagination.pageSize = 10; pagination.pageSize = 10;
const sort: SortOptions = new SortOptions('score', SortDirection.DESC); 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', { const searchServiceStub = jasmine.createSpyObj('SearchService', {
search: mockResults, search: mockResults,
getSearchLink: '/search', getSearchLink: '/search',
@@ -178,5 +178,4 @@ describe('SearchPageComponent', () => {
}); });
}); });
}) });
;

View File

@@ -14,7 +14,7 @@ describe('SearchConfigurationService', () => {
'f.date.min': ['2013'], 'f.date.min': ['2013'],
'f.date.max': ['2018'] 'f.date.max': ['2018']
}; };
const defaults = Object.assign(new PaginatedSearchOptions(), { const defaults = new PaginatedSearchOptions( {
pagination: Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }), pagination: Object.assign(new PaginationComponentOptions(), { currentPage: 1, pageSize: 20 }),
sort: new SortOptions('score', SortDirection.DESC), sort: new SortOptions('score', SortDirection.DESC),
query: '', query: '',

View File

@@ -174,7 +174,7 @@ export class SearchConfigurationService implements OnDestroy {
this.getFiltersPart() this.getFiltersPart()
).subscribe((update) => { ).subscribe((update) => {
const currentValue: SearchOptions = this.searchOptions.getValue(); 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); this.searchOptions.next(updatedValue);
}); });
} }
@@ -193,7 +193,7 @@ export class SearchConfigurationService implements OnDestroy {
this.getFiltersPart() this.getFiltersPart()
).subscribe((update) => { ).subscribe((update) => {
const currentValue: PaginatedSearchOptions = this.paginatedSearchOptions.getValue(); 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); this.paginatedSearchOptions.next(updatedValue);
}); });
} }
@@ -203,7 +203,7 @@ export class SearchConfigurationService implements OnDestroy {
*/ */
get defaults(): Observable<RemoteData<PaginatedSearchOptions>> { get defaults(): Observable<RemoteData<PaginatedSearchOptions>> {
if (hasNoValue(this._defaults)) { if (hasNoValue(this._defaults)) {
const options = Object.assign(new PaginatedSearchOptions(), { const options = new PaginatedSearchOptions({
pagination: this.defaultPagination, pagination: this.defaultPagination,
sort: this.defaultSort, sort: this.defaultSort,
scope: this.defaultScope, scope: this.defaultScope,

View File

@@ -155,7 +155,7 @@ describe('SearchService', () => {
describe('when search is called', () => { describe('when search is called', () => {
const endPoint = 'http://endpoint.com/test/test'; const endPoint = 'http://endpoint.com/test/test';
const searchOptions = new PaginatedSearchOptions(); const searchOptions = new PaginatedSearchOptions({});
const queryResponse = Object.assign(new SearchQueryResponse(), { objects: [] }); const queryResponse = Object.assign(new SearchQueryResponse(), { objects: [] });
const response = new SearchSuccessResponse(queryResponse, '200'); const response = new SearchSuccessResponse(queryResponse, '200');
const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response }); const responseEntry = Object.assign(new ResponseCacheEntry(), { response: response });

View File

@@ -8,6 +8,9 @@ import { RemoteData } from '../data/remote-data';
import { RestRequest } from '../data/request.models'; import { RestRequest } from '../data/request.models';
import { RequestEntry } from '../data/request.reducer'; import { RequestEntry } from '../data/request.reducer';
import { RequestService } from '../data/request.service'; 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 * This file contains custom RxJS operators that can be used in multiple places
@@ -49,3 +52,13 @@ export const getRemoteDataPayload = () =>
export const getSucceededRemoteData = () => export const getSucceededRemoteData = () =>
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> => <T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
source.pipe(first((rd: RemoteData<T>) => rd.hasSucceeded)); source.pipe(first((rd: RemoteData<T>) => rd.hasSucceeded));
export const toDSpaceObjectListRD = () =>
<T extends DSpaceObject>(source: Observable<RemoteData<PaginatedList<SearchResult<T>>>>): Observable<RemoteData<PaginatedList<T>>> =>
source.pipe(
map((rd: RemoteData<PaginatedList<SearchResult<T>>>) => {
const dsoPage: T[] = rd.payload.page.map((searchResult: SearchResult<T>) => searchResult.dspaceObject);
const payload = Object.assign(rd.payload, { page: dsoPage }) as PaginatedList<T>;
return Object.assign(rd, {payload: payload});
})
);