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 { 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<RemoteData<PaginatedList<Item>>>;
}
ngOnDestroy(): void {

View File

@@ -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: [

View File

@@ -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', () => {

View File

@@ -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

View File

@@ -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', () => {

View File

@@ -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

View File

@@ -178,5 +178,4 @@ describe('SearchPageComponent', () => {
});
});
})
;
});

View File

@@ -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: '',

View File

@@ -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<RemoteData<PaginatedSearchOptions>> {
if (hasNoValue(this._defaults)) {
const options = Object.assign(new PaginatedSearchOptions(), {
const options = new PaginatedSearchOptions({
pagination: this.defaultPagination,
sort: this.defaultSort,
scope: this.defaultScope,

View File

@@ -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 });

View File

@@ -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 = () =>
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
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});
})
);