Paginated entities service updates (sorting)
This commit is contained in:
parent
d4b69a18a9
commit
696e7f6f6d
@ -13,7 +13,12 @@ interface PaginatedResponse<Interface> {
|
|||||||
totalHits: number;
|
totalHits: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PaginatedConfig<Options> {
|
export interface SortOption {
|
||||||
|
sortDirection?: 'ASC' | 'DESC';
|
||||||
|
sortProperty?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PaginatedConfig<Options> extends SortOption {
|
||||||
readonly options: Options;
|
readonly options: Options;
|
||||||
readonly page: number;
|
readonly page: number;
|
||||||
readonly pageSize: number;
|
readonly pageSize: number;
|
||||||
@ -67,11 +72,15 @@ export abstract class PaginatedEntitiesService<
|
|||||||
return this.loadPage(this._currentConfig.page);
|
return this.loadPage(this._currentConfig.page);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPage(page = 0, pageSize?: number, searchOptions?: SearchOptions): Observable<Class[]> {
|
loadPage(page = 0, pageSize?: number, searchOptions?: SearchOptions, sortOptions?: SortOption): Observable<Class[]> {
|
||||||
const options = searchOptions ?? this._currentConfig.options;
|
const options = searchOptions ?? this._currentConfig.options;
|
||||||
const size = pageSize ?? this._currentConfig.pageSize;
|
const size = pageSize ?? this._currentConfig.pageSize;
|
||||||
|
const sOptions = sortOptions ?? {
|
||||||
|
sortDirection: this._currentConfig.sortDirection,
|
||||||
|
sortProperty: this._currentConfig.sortProperty,
|
||||||
|
};
|
||||||
|
|
||||||
return super._post<PaginatedResponse<Interface>>({ page, size, options }).pipe(
|
return super._post<PaginatedResponse<Interface>>({ page, size, options, ...sOptions }).pipe(
|
||||||
tap(
|
tap(
|
||||||
response =>
|
response =>
|
||||||
(this._currentConfig = {
|
(this._currentConfig = {
|
||||||
@ -79,6 +88,8 @@ export abstract class PaginatedEntitiesService<
|
|||||||
page: response.page,
|
page: response.page,
|
||||||
pageSize: response.pageSize,
|
pageSize: response.pageSize,
|
||||||
totalHits: response.totalHits,
|
totalHits: response.totalHits,
|
||||||
|
sortDirection: sOptions.sortDirection,
|
||||||
|
sortProperty: sOptions.sortProperty,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
map(response => response.data),
|
map(response => response.data),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user