@itrocks/list 0.1.3 → 0.2.0
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 +2 -2
- package/cjs/feed.js +1 -1
- package/cjs/filter.d.ts +8 -0
- package/cjs/filter.js +15 -0
- package/cjs/list.d.ts +6 -0
- package/cjs/list.html +3 -3
- package/cjs/list.js +15 -4
- package/cjs/sort.d.ts +8 -0
- package/cjs/sort.js +29 -0
- package/list.css +24 -0
- package/package.json +7 -2
- package/sort.svg +1 -0
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
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Option } from '@itrocks/storage';
|
|
2
1
|
import { Request } from '@itrocks/request-response';
|
|
2
|
+
import { Option } from '@itrocks/storage';
|
|
3
3
|
export declare class Feed {
|
|
4
4
|
static DEFAULT_LIMIT: number;
|
|
5
5
|
static DEFAULT_LINE_HEIGHT: number;
|
|
@@ -9,5 +9,5 @@ export declare class Feed {
|
|
|
9
9
|
offset: number;
|
|
10
10
|
template: string;
|
|
11
11
|
getParams(request: Request): void;
|
|
12
|
-
readOptions(options
|
|
12
|
+
readOptions(options?: Option[]): Option[];
|
|
13
13
|
}
|
package/cjs/feed.js
CHANGED
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,8 +1,14 @@
|
|
|
1
1
|
import { Action } from '@itrocks/action';
|
|
2
2
|
import { Request } from '@itrocks/action-request';
|
|
3
|
+
import { Columns } from './columns';
|
|
3
4
|
import { Feed } from './feed';
|
|
5
|
+
import { Filter } from './filter';
|
|
6
|
+
import { Sort } from './sort';
|
|
4
7
|
export declare class List<T extends object = object> extends Action<T> {
|
|
8
|
+
columns: Columns<object>;
|
|
5
9
|
feed: Feed;
|
|
10
|
+
filter: Filter;
|
|
11
|
+
sort: Sort<object>;
|
|
6
12
|
html(request: Request<T>): Promise<import("@itrocks/core-responses").HtmlResponse>;
|
|
7
13
|
json(request: Request<T>): Promise<import("@itrocks/core-responses").JsonResponse>;
|
|
8
14
|
}
|
package/cjs/list.html
CHANGED
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
<table class="objects">
|
|
29
29
|
<thead>
|
|
30
30
|
<tr class="properties">
|
|
31
|
-
<th class="select"
|
|
32
|
-
<!--
|
|
33
|
-
<th data-property="{name}">{@display}</th>
|
|
31
|
+
<th class="select"><input name="select" type="checkbox" value="all"></th>
|
|
32
|
+
<!--columns-->
|
|
33
|
+
<th data-property="{name}" data-reverse="{?reverse}" data-sort="{?sort}">{@display}</th>
|
|
34
34
|
<!--end-->
|
|
35
35
|
</tr>
|
|
36
36
|
</thead>
|
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
|
|
44
|
+
const columns_1 = require("./columns");
|
|
45
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,12 +60,21 @@ 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
|
}
|
|
63
|
+
columns = new columns_1.Columns;
|
|
61
64
|
feed = new feed_1.Feed;
|
|
65
|
+
filter = new filter_1.Filter;
|
|
66
|
+
sort = new sort_1.Sort;
|
|
62
67
|
async html(request) {
|
|
68
|
+
const columns = this.columns;
|
|
63
69
|
const feed = this.feed;
|
|
64
|
-
|
|
70
|
+
const filter = this.filter;
|
|
71
|
+
const sort = this.sort;
|
|
65
72
|
const type = request.type;
|
|
66
|
-
|
|
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())));
|
|
67
78
|
if (feed.offset) {
|
|
68
79
|
return this.htmlTemplateResponse({ objects, type }, request, feed.template);
|
|
69
80
|
}
|
|
@@ -75,7 +86,7 @@ let List = (() => {
|
|
|
75
86
|
const actions = (action.need === 'object') ? selectionActions : generalActions;
|
|
76
87
|
actions.push(action);
|
|
77
88
|
}
|
|
78
|
-
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');
|
|
79
90
|
}
|
|
80
91
|
async json(request) {
|
|
81
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,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Sort = void 0;
|
|
4
|
+
const sort_1 = require("@itrocks/sort");
|
|
5
|
+
const sort_2 = require("@itrocks/sort");
|
|
6
|
+
const storage_1 = require("@itrocks/storage");
|
|
7
|
+
class Sort {
|
|
8
|
+
getParams(_request, type, columns) {
|
|
9
|
+
let sortProperties;
|
|
10
|
+
for (const option of this.readOptions()) {
|
|
11
|
+
if (option instanceof storage_1.Sort) {
|
|
12
|
+
sortProperties = option.properties;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
sortProperties ??= (0, sort_2.sortOf)(type);
|
|
16
|
+
const sortPropertyNames = sortProperties.map(property => '' + property);
|
|
17
|
+
for (const column of columns) {
|
|
18
|
+
const sortIndex = sortPropertyNames.indexOf(column.name) + 1;
|
|
19
|
+
column.reverse = !!(sortIndex && (sortProperties[sortIndex - 1] instanceof sort_1.Reverse));
|
|
20
|
+
column.sort = sortIndex ? sortIndex : undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
readOptions(options = new Array) {
|
|
24
|
+
options.push(storage_1.Sort);
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.Sort = Sort;
|
|
29
|
+
//# sourceMappingURL=sort.js.map
|
package/list.css
CHANGED
|
@@ -27,6 +27,30 @@ table.objects {
|
|
|
27
27
|
table.objects th {
|
|
28
28
|
background: #f8f8f8;
|
|
29
29
|
}
|
|
30
|
+
table.objects th[data-sort] {
|
|
31
|
+
padding-right: calc(0.6em + 16px);
|
|
32
|
+
}
|
|
33
|
+
table.objects th[data-sort]::after {
|
|
34
|
+
content: "";
|
|
35
|
+
height: 24px;
|
|
36
|
+
mask: url("sort.svg") right center/24px 24px no-repeat;
|
|
37
|
+
position: absolute;
|
|
38
|
+
right: 0;
|
|
39
|
+
top: calc(50% - 12px);
|
|
40
|
+
width: 24px;
|
|
41
|
+
}
|
|
42
|
+
table.objects th[data-sort][data-reverse]::after {
|
|
43
|
+
transform: scaleY(-1);
|
|
44
|
+
}
|
|
45
|
+
table.objects th[data-sort][data-sort="1"]::after {
|
|
46
|
+
background-color: #444;
|
|
47
|
+
}
|
|
48
|
+
table.objects th[data-sort][data-sort="2"]::after {
|
|
49
|
+
background-color: #888;
|
|
50
|
+
}
|
|
51
|
+
table.objects th[data-sort][data-sort="3"]::after {
|
|
52
|
+
background-color: #ccc;
|
|
53
|
+
}
|
|
30
54
|
table.objects tr td, table.objects tr th {
|
|
31
55
|
border-bottom: 1px solid #d8d8d8;
|
|
32
56
|
border-spacing: 0;
|
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
|
},
|
|
@@ -26,6 +30,7 @@
|
|
|
26
30
|
"LICENSE",
|
|
27
31
|
"README.md",
|
|
28
32
|
"cjs/*",
|
|
33
|
+
"/*.svg",
|
|
29
34
|
"*.css",
|
|
30
35
|
"*.d.ts",
|
|
31
36
|
"*.js",
|
|
@@ -63,9 +68,9 @@
|
|
|
63
68
|
"scripts": {
|
|
64
69
|
"build": "npm run build:cjs && npm run build:css && npm run build:front",
|
|
65
70
|
"build:cjs": "tsc -p tsconfig.cjs.json && cp src/*.html cjs/",
|
|
66
|
-
"build:css": "sass --no-source-map src/list.scss:list.css",
|
|
71
|
+
"build:css": "sass --no-source-map src/list.scss:list.css && cp src/*.svg ./",
|
|
67
72
|
"build:front": "tsc -p esm/tsconfig.json && ../prepare-module/prepare-module.js esm"
|
|
68
73
|
},
|
|
69
74
|
"types": "./cjs/list.d.ts",
|
|
70
|
-
"version": "0.
|
|
75
|
+
"version": "0.2.0"
|
|
71
76
|
}
|
package/sort.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M7 15l10 0-5-5z"/></svg>
|