]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/models/cd-table-fetch-data-context.ts
7937d82e6f3e62cf2d04e7eb872b12c9bed09a4d
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / models / cd-table-fetch-data-context.ts
1 import { HttpParams } from '@angular/common/http';
2
3 import { PageInfo } from './cd-table-paging';
4
5 export class CdTableFetchDataContext {
6 errorConfig = {
7 resetData: true, // Force data table to show no data
8 displayError: true // Show an error panel above the data table
9 };
10
11 /**
12 * The function that should be called from within the error handler
13 * of the 'fetchData' function to display the error panel and to
14 * reset the data table to the correct state.
15 */
16 error: Function;
17 pageInfo: PageInfo = new PageInfo();
18 search = '';
19 sort = '+name';
20
21 constructor(error: () => void) {
22 this.error = error;
23 }
24
25 toParams(): HttpParams {
26 if (this.pageInfo.limit === null) {
27 this.pageInfo.limit = 0;
28 }
29 if (!this.search) {
30 this.search = '';
31 }
32 if (!this.sort || this.sort.length < 2) {
33 this.sort = '+name';
34 }
35 return new HttpParams({
36 fromObject: {
37 offset: String(this.pageInfo.offset * this.pageInfo.limit),
38 limit: String(this.pageInfo.limit),
39 search: this.search,
40 sort: this.sort
41 }
42 });
43 }
44 }