44024: search service changes

This commit is contained in:
Lotte Hofstede
2017-09-21 13:58:24 +02:00
parent 1bcb37f1b0
commit 93a5580258
5 changed files with 45 additions and 41 deletions

View File

@@ -35,7 +35,6 @@
<div *ngIf="(itemData.hasSucceeded | async)"> <div *ngIf="(itemData.hasSucceeded | async)">
<h2>{{'collection.page.browse.recent.head' | translate}}</h2> <h2>{{'collection.page.browse.recent.head' | translate}}</h2>
<ds-object-list [config]="paginationConfig" [sortConfig]="sortConfig" <ds-object-list [config]="paginationConfig" [sortConfig]="sortConfig"
[objects]="itemData" [hideGear]="false" [objects]="itemData" [hideGear]="false"></ds-object-list>
(paginationChange)="updatePage($event)"></ds-object-list>
</div> </div>
</div> </div>

View File

@@ -53,6 +53,15 @@ export class SearchService {
if (isNotEmpty(searchOptions) && hasValue(searchOptions.pagination.currentPage)) { if (isNotEmpty(searchOptions) && hasValue(searchOptions.pagination.currentPage)) {
self += `&page=${searchOptions.pagination.currentPage}`; self += `&page=${searchOptions.pagination.currentPage}`;
} }
if (isNotEmpty(searchOptions) && hasValue(searchOptions.pagination.pageSize)) {
self += `&pageSize=${searchOptions.pagination.pageSize}`;
}
if (isNotEmpty(searchOptions) && hasValue(searchOptions.sort.direction)) {
self += `&sortDirection=${searchOptions.sort.direction}`;
}
if (isNotEmpty(searchOptions) && hasValue(searchOptions.sort.field)) {
self += `&sortField=${searchOptions.sort.field}`;
}
const requestPending = Observable.of(false); const requestPending = Observable.of(false);
const responsePending = Observable.of(false); const responsePending = Observable.of(false);
const errorMessage = Observable.of(undefined); const errorMessage = Observable.of(undefined);
@@ -66,22 +75,26 @@ export class SearchService {
returningPageInfo.elementsPerPage = 10; returningPageInfo.elementsPerPage = 10;
returningPageInfo.currentPage = 1; returningPageInfo.currentPage = 1;
} }
returningPageInfo.totalPages = this.totalPages;
returningPageInfo.totalElements = returningPageInfo.elementsPerPage * returningPageInfo.totalPages;
const pageInfo = Observable.of(returningPageInfo);
const itemsRD = this.itemDataService.findAll({ elementsPerPage: 10 }); const itemsRD = this.itemDataService.findAll({
scopeID: scopeId,
currentPage: returningPageInfo.currentPage,
elementsPerPage: returningPageInfo.elementsPerPage
});
const pageInfo = itemsRD.pageInfo;
const payload = itemsRD.payload.map((items: Item[]) => { const payload = itemsRD.payload.map((items: Item[]) => {
return shuffle(items) return shuffle(items)
.map((item: Item, index: number) => { .map((item: Item, index: number) => {
const mockResult: SearchResult<DSpaceObject> = new ItemSearchResult(); const mockResult: SearchResult<DSpaceObject> = new ItemSearchResult();
mockResult.dspaceObject = item; mockResult.dspaceObject = item;
const highlight = new Metadatum(); const highlight = new Metadatum();
highlight.key = 'dc.description.abstract'; highlight.key = 'dc.description.abstract';
highlight.value = this.mockedHighlights[index % this.mockedHighlights.length]; highlight.value = this.mockedHighlights[index % this.mockedHighlights.length];
mockResult.hitHighlights = new Array(highlight); mockResult.hitHighlights = new Array(highlight);
return mockResult; return mockResult;
}); });
}); });
return new RemoteData( return new RemoteData(

View File

@@ -69,6 +69,7 @@ export class ObjectListComponent implements OnChanges, OnInit {
ngOnInit(): void { ngOnInit(): void {
this.pageInfo = this.objects.pageInfo; this.pageInfo = this.objects.pageInfo;
this.pageInfo.subscribe((info) => console.log(info));
} }
/** /**

View File

@@ -3,7 +3,7 @@
<div class="row"> <div class="row">
<div class="col pagination-info"> <div class="col pagination-info">
<span class="align-middle hidden-xs-down">{{ 'pagination.showing.label' | translate }}</span> <span class="align-middle hidden-xs-down">{{ 'pagination.showing.label' | translate }}</span>
<span class="align-middle">{{ 'pagination.showing.detail' | translate:showingDetail }}</span> <span class="align-middle" *ngIf="collectionSize">{{ 'pagination.showing.detail' | translate:getShowingDetails(collectionSize)}}</span>
</div> </div>
<div class="col"> <div class="col">
<div ngbDropdown #paginationControls="ngbDropdown" class="d-inline-block float-right"> <div ngbDropdown #paginationControls="ngbDropdown" class="d-inline-block float-right">
@@ -17,7 +17,7 @@
</div> </div>
</div> </div>
</div> </div>
</div>
<ng-content></ng-content> <ng-content></ng-content>
<div *ngIf="shouldShowBottomPager" class="pagination justify-content-center clearfix bottom"> <div *ngIf="shouldShowBottomPager" class="pagination justify-content-center clearfix bottom">

View File

@@ -162,14 +162,6 @@ export class PaginationComponent implements OnDestroy, OnInit {
*/ */
private subs: Subscription[] = []; private subs: Subscription[] = [];
/**
* An object that represents pagination details of the current viewed page
*/
public showingDetail: any = {
range: null,
total: null
};
/** /**
* Method provided by Angular. Invoked after the constructor. * Method provided by Angular. Invoked after the constructor.
*/ */
@@ -193,7 +185,6 @@ export class PaginationComponent implements OnDestroy, OnInit {
this.fixRoute(fixedProperties); this.fixRoute(fixedProperties);
} }
this.setFields(); this.setFields();
this.setShowingDetail();
} }
})); }));
} }
@@ -228,7 +219,6 @@ export class PaginationComponent implements OnDestroy, OnInit {
sortDirection: this.sortDirection, sortDirection: this.sortDirection,
sortField: this.sortField sortField: this.sortField
}; };
this.setShowingDetail();
} }
/** /**
@@ -353,23 +343,24 @@ export class PaginationComponent implements OnDestroy, OnInit {
} }
/** /**
* Method to set pagination details of the current viewed page. * Method to get pagination details of the current viewed page.
*/ */
private setShowingDetail() { public getShowingDetails(collectionSize: number): any {
let firstItem; let showingDetails = { range: null + ' - ' + null, total: null };
let lastItem; if (collectionSize) {
const pageMax = this.pageSize * this.currentPage; let firstItem;
let lastItem;
const pageMax = this.pageSize * this.currentPage;
firstItem = this.pageSize * (this.currentPage - 1) + 1; firstItem = this.pageSize * (this.currentPage - 1) + 1;
if (this.collectionSize > pageMax) { if (collectionSize > pageMax) {
lastItem = pageMax; lastItem = pageMax;
} else { } else {
lastItem = this.collectionSize; lastItem = collectionSize;
} }
this.showingDetail = { showingDetails = { range: firstItem + ' - ' + lastItem, total: collectionSize };
range: firstItem + ' - ' + lastItem,
total: this.collectionSize
} }
return showingDetails;
} }
/** /**