1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | const Base = require('../base/Base');
|
7 |
|
8 | module.exports = class DataProvider extends Base {
|
9 |
|
10 | constructor (config) {
|
11 | super({
|
12 | pagination: {},
|
13 | sort: null,
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | ...config
|
19 | });
|
20 | }
|
21 |
|
22 | createPagination (config) {
|
23 | if (!config) {
|
24 | return null;
|
25 | }
|
26 | const defaults = {
|
27 | Class: require('./Pagination'),
|
28 | controller: this.controller,
|
29 | totalCount: this.totalCount
|
30 | };
|
31 | if (this.id) {
|
32 | defaults.pageParam = `${this.id}-page`;
|
33 | defaults.pageSizeParam = `${this.id}-pageSize`;
|
34 | }
|
35 | return ClassHelper.spawn(Object.assign(defaults, config));
|
36 | }
|
37 |
|
38 | createSort (config) {
|
39 | if (!config) {
|
40 | return null;
|
41 | }
|
42 | const defaults = {
|
43 | Class: require('./Sort'),
|
44 | controller: this.controller
|
45 | };
|
46 | if (this.id) {
|
47 | defaults.sortParam = `${this.id}-sort`;
|
48 | }
|
49 | return ClassHelper.spawn(Object.assign(defaults, config));
|
50 | }
|
51 |
|
52 | async prepare () {
|
53 | this.totalCount = await this.prepareTotalCount();
|
54 | this.pagination = this.createPagination(this.pagination);
|
55 | this.sort = this.createSort(this.sort);
|
56 | this.models = await this.prepareModels();
|
57 | }
|
58 | };
|
59 |
|
60 | const ClassHelper = require('../helper/ClassHelper'); |
\ | No newline at end of file |