mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 18:14:17 +00:00
added support for pagination in findAll rest calls
This commit is contained in:
@@ -12,7 +12,7 @@ import { ItemDataService } from "./data/item-data.service";
|
||||
import { RequestService } from "./data/request.service";
|
||||
import { RemoteDataBuildService } from "./cache/builders/remote-data-build.service";
|
||||
import { CommunityDataService } from "./data/community-data.service";
|
||||
import { PaginationOptions } from "./cache/models/pagination-options.model";
|
||||
import { PaginationComponentOptions } from "../shared/pagination/pagination-component-options.model";
|
||||
|
||||
const IMPORTS = [
|
||||
CommonModule,
|
||||
@@ -33,7 +33,7 @@ const PROVIDERS = [
|
||||
ItemDataService,
|
||||
DSpaceRESTv2Service,
|
||||
ObjectCacheService,
|
||||
PaginationOptions,
|
||||
PaginationComponentOptions,
|
||||
ResponseCacheService,
|
||||
RequestService,
|
||||
RemoteDataBuildService
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { ObjectCacheService } from "../cache/object-cache.service";
|
||||
import { ResponseCacheService } from "../cache/response-cache.service";
|
||||
import { CacheableObject } from "../cache/object-cache.reducer";
|
||||
import { hasValue } from "../../shared/empty.util";
|
||||
import { hasValue, isNotEmpty } from "../../shared/empty.util";
|
||||
import { RemoteData } from "./remote-data";
|
||||
import { FindAllRequest, FindByIDRequest, Request } from "./request.models";
|
||||
import { FindAllOptions, FindAllRequest, FindByIDRequest, Request } from "./request.models";
|
||||
import { Store } from "@ngrx/store";
|
||||
import { RequestConfigureAction, RequestExecuteAction } from "./request.actions";
|
||||
import { CoreState } from "../core.reducers";
|
||||
@@ -29,17 +29,35 @@ export abstract class DataService<TNormalized extends CacheableObject, TDomain>
|
||||
|
||||
}
|
||||
|
||||
protected getFindAllHref(scopeID?): string {
|
||||
protected getFindAllHref(options: FindAllOptions = {}): string {
|
||||
let result = this.endpoint;
|
||||
if (hasValue(scopeID)) {
|
||||
result += `?scope=${scopeID}`
|
||||
let args = [];
|
||||
|
||||
if (hasValue(options.scopeID)) {
|
||||
args.push(`scope=${options.scopeID}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.currentPage)) {
|
||||
args.push(`page=${options.currentPage}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.elementsPerPage)) {
|
||||
args.push(`size=${options.elementsPerPage}`);
|
||||
}
|
||||
|
||||
if (hasValue(options.sort)) {
|
||||
args.push(`sort=${options.sort.field},${options.sort.direction}`);
|
||||
}
|
||||
|
||||
if (isNotEmpty(args)) {
|
||||
result = `${result}?${args.join('&')}`;
|
||||
}
|
||||
return new RESTURLCombiner(this.EnvConfig, result).toString();
|
||||
}
|
||||
|
||||
findAll(scopeID?: string): RemoteData<Array<TDomain>> {
|
||||
const href = this.getFindAllHref(scopeID);
|
||||
const request = new FindAllRequest(href, scopeID);
|
||||
findAll(options: FindAllOptions = {}): RemoteData<Array<TDomain>> {
|
||||
const href = this.getFindAllHref(options);
|
||||
const request = new FindAllRequest(href, options);
|
||||
this.requestService.configure(request);
|
||||
return this.rdbService.buildList<TNormalized, TDomain>(href, this.normalizedResourceType);
|
||||
// return this.rdbService.buildList(href);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { SortOptions } from "../cache/models/sort-options.model";
|
||||
import { PaginationOptions } from "../cache/models/pagination-options.model";
|
||||
import { PaginationComponentOptions } from "../../shared/pagination/pagination-component-options.model";
|
||||
import { GenericConstructor } from "../shared/generic-constructor";
|
||||
|
||||
export class Request<T> {
|
||||
@@ -17,12 +17,17 @@ export class FindByIDRequest<T> extends Request<T> {
|
||||
}
|
||||
}
|
||||
|
||||
export class FindAllOptions {
|
||||
scopeID?: string;
|
||||
elementsPerPage?: number;
|
||||
currentPage?: number;
|
||||
sort?: SortOptions;
|
||||
}
|
||||
|
||||
export class FindAllRequest<T> extends Request<T> {
|
||||
constructor(
|
||||
href: string,
|
||||
public scopeID?: string,
|
||||
public paginationOptions?: PaginationOptions,
|
||||
public sortOptions?: SortOptions
|
||||
public options?: FindAllOptions,
|
||||
) {
|
||||
super(href);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { NgbPaginationConfig } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
export class PaginationOptions extends NgbPaginationConfig {
|
||||
export class PaginationComponentOptions extends NgbPaginationConfig {
|
||||
/**
|
||||
* ID for the pagination instance. Only useful if you wish to
|
||||
* have more than once instance at a time in a given component.
|
@@ -25,7 +25,7 @@ import { Ng2PaginationModule } from 'ng2-pagination';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { PaginationComponent } from './pagination.component';
|
||||
import { PaginationOptions } from '../../core/cache/models/pagination-options.model';
|
||||
import { PaginationComponentOptions } from './pagination-component-options.model';
|
||||
import { MockTranslateLoader } from "../testing/mock-translate-loader";
|
||||
|
||||
import { GLOBAL_CONFIG, EnvConfig } from '../../../config';
|
||||
@@ -307,7 +307,7 @@ class TestComponent {
|
||||
|
||||
collection: string[] = [];
|
||||
collectionSize: number;
|
||||
paginationOptions = new PaginationOptions();
|
||||
paginationOptions = new PaginationComponentOptions();
|
||||
|
||||
constructor() {
|
||||
this.collection = Array.from(new Array(100), (x, i) => `item ${i + 1}`);
|
||||
|
@@ -17,7 +17,7 @@ import { DEFAULT_TEMPLATE, DEFAULT_STYLES } from 'ng2-pagination/dist/template';
|
||||
|
||||
import { HostWindowService } from "../host-window.service";
|
||||
import { HostWindowState } from "../host-window.reducer";
|
||||
import { PaginationOptions } from '../../core/cache/models/pagination-options.model';
|
||||
import { PaginationComponentOptions } from './pagination-component-options.model';
|
||||
|
||||
/**
|
||||
* The default pagination controls component.
|
||||
@@ -39,7 +39,7 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
||||
/**
|
||||
* Configuration for the NgbPagination component.
|
||||
*/
|
||||
@Input() paginationOptions: PaginationOptions;
|
||||
@Input() paginationOptions: PaginationComponentOptions;
|
||||
|
||||
/**
|
||||
* An event fired when the page is changed.
|
||||
|
@@ -5118,7 +5118,7 @@ rollup@0.37.0:
|
||||
dependencies:
|
||||
source-map-support "^0.4.0"
|
||||
|
||||
rxjs@5.0.0-beta.12:
|
||||
rxjs@5.0.0-beta.12, rxjs@^5.0.0-beta.12:
|
||||
version "5.0.0-beta.12"
|
||||
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.0.0-beta.12.tgz#cdfde2d8c4639d20ae7794bff8fddf32da7ad337"
|
||||
dependencies:
|
||||
|
Reference in New Issue
Block a user