@itrocks/list 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/columns.d.ts +10 -0
- package/cjs/columns.js +18 -0
- package/cjs/feed.d.ts +13 -0
- package/cjs/feed.js +27 -0
- package/cjs/filter.d.ts +8 -0
- package/cjs/filter.js +15 -0
- package/cjs/list.d.ts +8 -1
- package/cjs/list.html +2 -2
- package/cjs/list.js +20 -13
- package/cjs/sort.d.ts +8 -0
- package/cjs/sort.js +14 -0
- package/package.json +5 -1
package/cjs/columns.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Type } from '@itrocks/class-type';
|
|
2
|
+
import { ReflectProperty } from '@itrocks/reflect';
|
|
3
|
+
import { Request } from '@itrocks/request-response';
|
|
4
|
+
import { Option } from '@itrocks/storage';
|
|
5
|
+
export declare class Columns<T extends object> implements Iterable<ReflectProperty<T>> {
|
|
6
|
+
properties: ReflectProperty<T>[];
|
|
7
|
+
[Symbol.iterator](): ArrayIterator<ReflectProperty<T>>;
|
|
8
|
+
getParams(_request: Request, type: Type<T>): void;
|
|
9
|
+
readOptions(options?: Option[]): Option[];
|
|
10
|
+
}
|
package/cjs/columns.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Columns = void 0;
|
|
4
|
+
const list_properties_1 = require("@itrocks/list-properties");
|
|
5
|
+
class Columns {
|
|
6
|
+
properties = new Array;
|
|
7
|
+
[Symbol.iterator]() {
|
|
8
|
+
return this.properties[Symbol.iterator]();
|
|
9
|
+
}
|
|
10
|
+
getParams(_request, type) {
|
|
11
|
+
this.properties = new list_properties_1.ListReflectClass(type).listProperties();
|
|
12
|
+
}
|
|
13
|
+
readOptions(options = new Array) {
|
|
14
|
+
return options;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.Columns = Columns;
|
|
18
|
+
//# sourceMappingURL=columns.js.map
|
package/cjs/feed.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Request } from '@itrocks/request-response';
|
|
2
|
+
import { Option } from '@itrocks/storage';
|
|
3
|
+
export declare class Feed {
|
|
4
|
+
static DEFAULT_LIMIT: number;
|
|
5
|
+
static DEFAULT_LINE_HEIGHT: number;
|
|
6
|
+
static DEFAULT_OFFSET: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
lineHeight: number;
|
|
9
|
+
offset: number;
|
|
10
|
+
template: string;
|
|
11
|
+
getParams(request: Request): void;
|
|
12
|
+
readOptions(options?: Option[]): Option[];
|
|
13
|
+
}
|
package/cjs/feed.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Feed = void 0;
|
|
4
|
+
const storage_1 = require("@itrocks/storage");
|
|
5
|
+
class Feed {
|
|
6
|
+
static DEFAULT_LIMIT = 50;
|
|
7
|
+
static DEFAULT_LINE_HEIGHT = 30;
|
|
8
|
+
static DEFAULT_OFFSET = 0;
|
|
9
|
+
limit = Feed.DEFAULT_LIMIT;
|
|
10
|
+
lineHeight = Feed.DEFAULT_LINE_HEIGHT;
|
|
11
|
+
offset = Feed.DEFAULT_OFFSET;
|
|
12
|
+
template = __dirname + '/feed.html';
|
|
13
|
+
getParams(request) {
|
|
14
|
+
const header = request.headers['xhr-info'];
|
|
15
|
+
const xhrInfo = header ? JSON.parse(header) : {};
|
|
16
|
+
this.limit = xhrInfo.targetHeight
|
|
17
|
+
? Math.ceil(xhrInfo.targetHeight / this.lineHeight)
|
|
18
|
+
: (xhrInfo.visibleRows ?? Feed.DEFAULT_LIMIT);
|
|
19
|
+
this.offset = +request.data.offset;
|
|
20
|
+
}
|
|
21
|
+
readOptions(options = new Array) {
|
|
22
|
+
options.push(new storage_1.Limit(this.limit, this.offset));
|
|
23
|
+
return options;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Feed = Feed;
|
|
27
|
+
//# sourceMappingURL=feed.js.map
|
package/cjs/filter.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Type } from '@itrocks/class-type';
|
|
2
|
+
import { Request } from '@itrocks/request-response';
|
|
3
|
+
import { Option } from '@itrocks/storage';
|
|
4
|
+
export declare class Filter {
|
|
5
|
+
getParams(_request: Request): void;
|
|
6
|
+
readOptions(options?: Option[]): Option[];
|
|
7
|
+
searchObject(type: Type): any;
|
|
8
|
+
}
|
package/cjs/filter.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Filter = void 0;
|
|
4
|
+
class Filter {
|
|
5
|
+
getParams(_request) {
|
|
6
|
+
}
|
|
7
|
+
readOptions(options = new Array) {
|
|
8
|
+
return options;
|
|
9
|
+
}
|
|
10
|
+
searchObject(type) {
|
|
11
|
+
return Object.setPrototypeOf({}, type.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.Filter = Filter;
|
|
15
|
+
//# sourceMappingURL=filter.js.map
|
package/cjs/list.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { Action } from '@itrocks/action';
|
|
2
2
|
import { Request } from '@itrocks/action-request';
|
|
3
|
+
import { Columns } from './columns';
|
|
4
|
+
import { Feed } from './feed';
|
|
5
|
+
import { Filter } from './filter';
|
|
6
|
+
import { Sort } from './sort';
|
|
3
7
|
export declare class List<T extends object = object> extends Action<T> {
|
|
4
|
-
|
|
8
|
+
columns: Columns<object>;
|
|
9
|
+
feed: Feed;
|
|
10
|
+
filter: Filter;
|
|
11
|
+
sort: Sort<object>;
|
|
5
12
|
html(request: Request<T>): Promise<import("@itrocks/core-responses").HtmlResponse>;
|
|
6
13
|
json(request: Request<T>): Promise<import("@itrocks/core-responses").JsonResponse>;
|
|
7
14
|
}
|
package/cjs/list.html
CHANGED
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
<table class="objects">
|
|
29
29
|
<thead>
|
|
30
30
|
<tr class="properties">
|
|
31
|
-
<th class="select"
|
|
32
|
-
<!--
|
|
31
|
+
<th class="select"><input name="select" type="checkbox" value="all"></th>
|
|
32
|
+
<!--columns-->
|
|
33
33
|
<th data-property="{name}">{@display}</th>
|
|
34
34
|
<!--end-->
|
|
35
35
|
</tr>
|
package/cjs/list.js
CHANGED
|
@@ -41,8 +41,10 @@ const action_3 = require("@itrocks/action");
|
|
|
41
41
|
const route_1 = require("@itrocks/route");
|
|
42
42
|
const route_2 = require("@itrocks/route");
|
|
43
43
|
const storage_1 = require("@itrocks/storage");
|
|
44
|
-
const
|
|
45
|
-
const
|
|
44
|
+
const columns_1 = require("./columns");
|
|
45
|
+
const feed_1 = require("./feed");
|
|
46
|
+
const filter_1 = require("./filter");
|
|
47
|
+
const sort_1 = require("./sort");
|
|
46
48
|
let List = (() => {
|
|
47
49
|
let _classDecorators = [(0, action_3.Need)('Store', 'new'), (0, route_1.Route)('/list')];
|
|
48
50
|
let _classDescriptor;
|
|
@@ -58,18 +60,23 @@ let List = (() => {
|
|
|
58
60
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
59
61
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
60
62
|
}
|
|
61
|
-
|
|
63
|
+
columns = new columns_1.Columns;
|
|
64
|
+
feed = new feed_1.Feed;
|
|
65
|
+
filter = new filter_1.Filter;
|
|
66
|
+
sort = new sort_1.Sort;
|
|
62
67
|
async html(request) {
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
: (xhrInfo.visibleRows ?? 50);
|
|
68
|
-
const offset = request.request.data.offset;
|
|
68
|
+
const columns = this.columns;
|
|
69
|
+
const feed = this.feed;
|
|
70
|
+
const filter = this.filter;
|
|
71
|
+
const sort = this.sort;
|
|
69
72
|
const type = request.type;
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
columns.getParams(request.request, type);
|
|
74
|
+
feed.getParams(request.request);
|
|
75
|
+
filter.getParams(request.request);
|
|
76
|
+
sort.getParams(request.request, type, columns);
|
|
77
|
+
const objects = await (0, storage_1.dataSource)().search(type, filter.searchObject(type), feed.readOptions(filter.readOptions(sort.readOptions())));
|
|
78
|
+
if (feed.offset) {
|
|
79
|
+
return this.htmlTemplateResponse({ objects, type }, request, feed.template);
|
|
73
80
|
}
|
|
74
81
|
const count = await (0, storage_1.dataSource)().count(type);
|
|
75
82
|
const route = (0, route_2.routeOf)(this);
|
|
@@ -79,7 +86,7 @@ let List = (() => {
|
|
|
79
86
|
const actions = (action.need === 'object') ? selectionActions : generalActions;
|
|
80
87
|
actions.push(action);
|
|
81
88
|
}
|
|
82
|
-
return this.htmlTemplateResponse({ count, generalActions, objects, selectionActions, type }, request, __dirname + '/list.html');
|
|
89
|
+
return this.htmlTemplateResponse({ columns, count, generalActions, objects, selectionActions, type }, request, __dirname + '/list.html');
|
|
83
90
|
}
|
|
84
91
|
async json(request) {
|
|
85
92
|
const objects = await (0, storage_1.dataSource)().search(request.type);
|
package/cjs/sort.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Type } from '@itrocks/class-type';
|
|
2
|
+
import { Request } from '@itrocks/request-response';
|
|
3
|
+
import { Option } from '@itrocks/storage';
|
|
4
|
+
import { Columns } from './columns';
|
|
5
|
+
export declare class Sort<T extends object> {
|
|
6
|
+
getParams(_request: Request, _type: Type, _columns: Columns<T>): void;
|
|
7
|
+
readOptions(options?: Option[]): Option[];
|
|
8
|
+
}
|
package/cjs/sort.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sort = void 0;
|
|
4
|
+
const storage_1 = require("@itrocks/storage");
|
|
5
|
+
class Sort {
|
|
6
|
+
getParams(_request, _type, _columns) {
|
|
7
|
+
}
|
|
8
|
+
readOptions(options = new Array) {
|
|
9
|
+
options.push(storage_1.Sort);
|
|
10
|
+
return options;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Sort = Sort;
|
|
14
|
+
//# sourceMappingURL=sort.js.map
|
package/package.json
CHANGED
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@itrocks/action-pack": "latest",
|
|
8
8
|
"@itrocks/build": "latest",
|
|
9
|
+
"@itrocks/class-type": "latest",
|
|
10
|
+
"@itrocks/list-properties": "latest",
|
|
11
|
+
"@itrocks/reflect": "latest",
|
|
12
|
+
"@itrocks/request-response": "latest",
|
|
9
13
|
"@itrocks/table": "latest",
|
|
10
14
|
"@itrocks/xtarget": "latest"
|
|
11
15
|
},
|
|
@@ -67,5 +71,5 @@
|
|
|
67
71
|
"build:front": "tsc -p esm/tsconfig.json && ../prepare-module/prepare-module.js esm"
|
|
68
72
|
},
|
|
69
73
|
"types": "./cjs/list.d.ts",
|
|
70
|
-
"version": "0.1.
|
|
74
|
+
"version": "0.1.4"
|
|
71
75
|
}
|