@itrocks/list 0.30.0 → 0.32.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/access.d.ts +15 -0
- package/cjs/access.js +4 -0
- package/cjs/columns.d.ts +14 -2
- package/cjs/columns.js +44 -9
- package/cjs/filter.d.ts +2 -1
- package/cjs/filter.js +22 -14
- package/cjs/list.d.ts +1 -1
- package/cjs/list.html +1 -0
- package/cjs/list.js +39 -27
- package/cjs/projection.d.ts +4 -2
- package/cjs/projection.js +9 -1
- package/cjs/search.d.ts +2 -1
- package/cjs/search.js +2 -2
- package/docs/dependencies.md +15 -0
- package/list.css +6 -0
- package/package.json +1 -1
- package/cjs/search-expression.d.ts +0 -9
- package/cjs/search-expression.js +0 -93
package/cjs/access.d.ts
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { Request } from '@itrocks/action-request';
|
|
2
|
+
import type { Type } from '@itrocks/class-type';
|
|
2
3
|
import type { StateRecord } from '@itrocks/property-select';
|
|
4
|
+
import type { ResolvedPropertyPath } from '@itrocks/reflect-path';
|
|
3
5
|
import type { Response } from '@itrocks/request-response';
|
|
6
|
+
import type { ProjectionCell } from '@itrocks/storage';
|
|
7
|
+
import type { Sort } from '@itrocks/storage';
|
|
8
|
+
import type { ListColumn } from './projection';
|
|
4
9
|
import type { ListSearch } from './search';
|
|
5
10
|
export type ListAccess = {
|
|
6
11
|
authorise(path: string): Promise<void>;
|
|
7
12
|
bootstrap?(paths: string[], state: StateRecord): Promise<object>;
|
|
8
13
|
root?: string;
|
|
9
14
|
};
|
|
15
|
+
export type ListColumnOutput = (column: ListColumn, cell: ProjectionCell, property: ListColumn['property']) => string | undefined | Promise<string | undefined>;
|
|
16
|
+
export type ListColumnsView = {
|
|
17
|
+
objectFields?: (column: ListColumn) => readonly string[] | undefined;
|
|
18
|
+
output?: ListColumnOutput;
|
|
19
|
+
searchOnOwner?: (property: ResolvedPropertyPath) => boolean;
|
|
20
|
+
sort?: Sort;
|
|
21
|
+
view?: ListView;
|
|
22
|
+
};
|
|
10
23
|
export type ListDependencies = {
|
|
11
24
|
access: (request: Request) => Promise<ListAccess>;
|
|
25
|
+
columnsView?: (type: Type, primarySort?: Readonly<[string, boolean]>) => ListColumnsView | undefined;
|
|
12
26
|
view: (request: Request) => Promise<ListView | undefined>;
|
|
13
27
|
selection?: {
|
|
14
28
|
update: (request: Request) => Promise<Response | undefined>;
|
|
@@ -32,3 +46,4 @@ export declare function listSelection(): {
|
|
|
32
46
|
footerSummary?: ListView;
|
|
33
47
|
}>;
|
|
34
48
|
} | undefined;
|
|
49
|
+
export declare function listColumnsView(type: Type, primarySort?: Readonly<[string, boolean]>): ListColumnsView | undefined;
|
package/cjs/access.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.listAccess = listAccess;
|
|
|
4
4
|
exports.listDependsOn = listDependsOn;
|
|
5
5
|
exports.listView = listView;
|
|
6
6
|
exports.listSelection = listSelection;
|
|
7
|
+
exports.listColumnsView = listColumnsView;
|
|
7
8
|
const dependencies = {
|
|
8
9
|
access: async () => ({ authorise: async () => { } }),
|
|
9
10
|
view: async () => undefined
|
|
@@ -20,4 +21,7 @@ function listView(request) {
|
|
|
20
21
|
function listSelection() {
|
|
21
22
|
return dependencies.selection;
|
|
22
23
|
}
|
|
24
|
+
function listColumnsView(type, primarySort) {
|
|
25
|
+
return dependencies.columnsView?.(type, primarySort);
|
|
26
|
+
}
|
|
23
27
|
//# sourceMappingURL=access.js.map
|
package/cjs/columns.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
import { Type } from '@itrocks/class-type';
|
|
2
2
|
import { Request } from '@itrocks/request-response';
|
|
3
|
+
import type { Identifier } from '@itrocks/storage';
|
|
3
4
|
import { Option } from '@itrocks/storage';
|
|
4
5
|
import { ProjectionResult } from '@itrocks/storage';
|
|
5
6
|
import { SearchType } from '@itrocks/storage';
|
|
7
|
+
import type { ListAccess } from './access';
|
|
8
|
+
import type { ListColumnOutput } from './access';
|
|
9
|
+
import type { ListColumnsView } from './access';
|
|
6
10
|
import { Parameter } from './parameter';
|
|
7
11
|
import { ListColumn } from './projection';
|
|
12
|
+
type ColumnObject = (column: ListColumn, id: Identifier) => object | undefined;
|
|
8
13
|
export declare class Columns<T extends object> extends Parameter implements Iterable<ListColumn> {
|
|
9
14
|
private configured;
|
|
10
15
|
properties: ListColumn[];
|
|
@@ -12,8 +17,8 @@ export declare class Columns<T extends object> extends Parameter implements Iter
|
|
|
12
17
|
getParams(request: Request, type: Type<T>): void;
|
|
13
18
|
get length(): number;
|
|
14
19
|
map<R>(callback: (value: ListColumn) => R): R[];
|
|
15
|
-
projected(result: ProjectionResult): Promise<{
|
|
16
|
-
id:
|
|
20
|
+
projected(result: ProjectionResult, output?: ListColumnOutput, objectOf?: ColumnObject): Promise<{
|
|
21
|
+
id: Identifier;
|
|
17
22
|
properties: {
|
|
18
23
|
outputOptionalContainer: string;
|
|
19
24
|
}[];
|
|
@@ -24,4 +29,11 @@ export declare class Columns<T extends object> extends Parameter implements Iter
|
|
|
24
29
|
unserialize(data: string[], type: Type<T>): void;
|
|
25
30
|
unshift(property: ListColumn): number;
|
|
26
31
|
}
|
|
32
|
+
export declare function projectColumnOutput<T extends object>(type: Type<T>, source: Columns<T> | readonly ListColumn[], search: SearchType<T>, options: Option[], access: ListAccess, view?: ListColumnsView): Promise<{
|
|
33
|
+
id: Identifier;
|
|
34
|
+
properties: {
|
|
35
|
+
outputOptionalContainer: string;
|
|
36
|
+
}[];
|
|
37
|
+
}[]>;
|
|
27
38
|
export declare function projectColumns<T extends object>(type: Type<T>, columns: readonly ListColumn[], search: SearchType<T>, options: Option[]): Promise<ProjectionResult<T>>;
|
|
39
|
+
export {};
|
package/cjs/columns.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Columns = void 0;
|
|
4
|
+
exports.projectColumnOutput = projectColumnOutput;
|
|
4
5
|
exports.projectColumns = projectColumns;
|
|
5
6
|
const list_properties_1 = require("@itrocks/list-properties");
|
|
6
7
|
const storage_1 = require("@itrocks/storage");
|
|
@@ -42,15 +43,8 @@ class Columns extends parameter_1.Parameter {
|
|
|
42
43
|
map(callback) {
|
|
43
44
|
return this.properties.map(callback);
|
|
44
45
|
}
|
|
45
|
-
async projected(result) {
|
|
46
|
-
|
|
47
|
-
|| (result.columns.length !== this.length)) {
|
|
48
|
-
throw new Error('Projection columns do not match the list');
|
|
49
|
-
}
|
|
50
|
-
return Promise.all(result.rows.map(async (row) => ({
|
|
51
|
-
id: row.rootId,
|
|
52
|
-
properties: await Promise.all(row.cells.map(async (cell, index) => ({ outputOptionalContainer: await this.properties[index].output(cell) })))
|
|
53
|
-
})));
|
|
46
|
+
async projected(result, output, objectOf) {
|
|
47
|
+
return renderProjectedRows(result, this.properties, output, objectOf);
|
|
54
48
|
}
|
|
55
49
|
readOptions(options = new Array) {
|
|
56
50
|
return options;
|
|
@@ -77,6 +71,34 @@ class Columns extends parameter_1.Parameter {
|
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
exports.Columns = Columns;
|
|
74
|
+
async function projectColumnOutput(type, source, search, options, access, view) {
|
|
75
|
+
const columns = [...source];
|
|
76
|
+
const objectColumns = new Set();
|
|
77
|
+
const authorised = new Set();
|
|
78
|
+
for (const column of columns) {
|
|
79
|
+
const fields = view?.objectFields?.(column);
|
|
80
|
+
if (!fields)
|
|
81
|
+
continue;
|
|
82
|
+
objectColumns.add(column);
|
|
83
|
+
for (const field of fields) {
|
|
84
|
+
if (authorised.has(field))
|
|
85
|
+
continue;
|
|
86
|
+
await access.authorise(field);
|
|
87
|
+
authorised.add(field);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const result = await projectColumns(type, columns, search, options);
|
|
91
|
+
const objects = objectColumns.size && result.rows.length
|
|
92
|
+
? await (0, storage_1.dataSource)().search(type, search, [new storage_2.Identifiers(result.rows.map(row => row.rootId))])
|
|
93
|
+
: [];
|
|
94
|
+
const byId = new Map(objects.map(object => [String(object.id), object]));
|
|
95
|
+
const objectOf = objectColumns.size
|
|
96
|
+
? (column, id) => objectColumns.has(column) ? byId.get(String(id)) : undefined
|
|
97
|
+
: undefined;
|
|
98
|
+
return 'projected' in source
|
|
99
|
+
? source.projected(result, view?.output, objectOf)
|
|
100
|
+
: renderProjectedRows(result, columns, view?.output, objectOf);
|
|
101
|
+
}
|
|
80
102
|
async function projectColumns(type, columns, search, options) {
|
|
81
103
|
const singular = columns.filter(column => !column.multiple);
|
|
82
104
|
const selections = singular.map(column => column.selection());
|
|
@@ -163,4 +185,17 @@ async function projectColumns(type, columns, search, options) {
|
|
|
163
185
|
}))
|
|
164
186
|
};
|
|
165
187
|
}
|
|
188
|
+
function renderProjectedRows(result, columns, output, objectOf) {
|
|
189
|
+
if (result.columns.some((column, index) => column.path !== columns[index]?.name)
|
|
190
|
+
|| (result.columns.length !== columns.length)) {
|
|
191
|
+
throw new Error('Projection columns do not match the list');
|
|
192
|
+
}
|
|
193
|
+
return Promise.all(result.rows.map(async (row) => ({
|
|
194
|
+
id: row.rootId,
|
|
195
|
+
properties: await Promise.all(columns.map(async (column, index) => {
|
|
196
|
+
const object = objectOf?.(column, row.rootId);
|
|
197
|
+
return { outputOptionalContainer: await column.output(row.cells[index], output, object) };
|
|
198
|
+
}))
|
|
199
|
+
})));
|
|
200
|
+
}
|
|
166
201
|
//# sourceMappingURL=columns.js.map
|
package/cjs/filter.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Request } from '@itrocks/request-response';
|
|
|
3
3
|
import { Option } from '@itrocks/storage';
|
|
4
4
|
import { SearchType } from '@itrocks/storage';
|
|
5
5
|
import { SearchExpression } from './front/search-expression';
|
|
6
|
+
import type { ListColumnsView } from './access';
|
|
6
7
|
import { Columns } from './columns';
|
|
7
8
|
import { Parameter } from './parameter';
|
|
8
9
|
type Search = {
|
|
@@ -16,7 +17,7 @@ export declare class Filter<T extends object> extends Parameter {
|
|
|
16
17
|
protected condition(type: Type, property: string, expression: SearchExpression, ancestors?: readonly Type[]): SearchType;
|
|
17
18
|
getParams(request: Request, _type?: Type): void;
|
|
18
19
|
readOptions(options?: Option[]): Option[];
|
|
19
|
-
searchObject(type: Type): any;
|
|
20
|
+
searchObject(type: Type, searchOnOwner?: ListColumnsView['searchOnOwner']): any;
|
|
20
21
|
serialize(): Search;
|
|
21
22
|
unserialize(data: Search): void;
|
|
22
23
|
}
|
package/cjs/filter.js
CHANGED
|
@@ -124,35 +124,40 @@ class Filter extends parameter_1.Parameter {
|
|
|
124
124
|
expression = (0, search_expression_2.searchExpression)(value);
|
|
125
125
|
}
|
|
126
126
|
catch (error) {
|
|
127
|
-
if (!(error instanceof SyntaxError))
|
|
127
|
+
if (!(error instanceof SyntaxError)) {
|
|
128
128
|
throw error;
|
|
129
|
-
|
|
129
|
+
}
|
|
130
|
+
return property ? { [property]: (0, sql_functions_15.or)() } : { [sql_functions_2.OR]: [] };
|
|
130
131
|
}
|
|
131
132
|
return this.condition(type, property, expression);
|
|
132
133
|
}
|
|
133
134
|
condition(type, property, expression, ancestors = []) {
|
|
134
|
-
const resolved = (0, reflect_path_1.resolvePropertyPath)(type, property);
|
|
135
|
-
if (!resolved.target) {
|
|
135
|
+
const resolved = property ? (0, reflect_path_1.resolvePropertyPath)(type, property) : undefined;
|
|
136
|
+
if (resolved && !resolved.target) {
|
|
136
137
|
const value = searchValue(scalarType(resolved.property.type), expression);
|
|
137
|
-
if (value === undefined && !ancestors.length)
|
|
138
|
+
if ((value === undefined) && !ancestors.length) {
|
|
138
139
|
return {};
|
|
140
|
+
}
|
|
139
141
|
return { [property]: value ?? (0, sql_functions_15.or)() };
|
|
140
142
|
}
|
|
141
143
|
if (!('value' in expression)) {
|
|
142
144
|
const operator = (expression.operator === 'AND') ? sql_functions_1.AND : sql_functions_2.OR;
|
|
143
145
|
return { [operator]: expression.operands.map(operand => this.condition(type, property, operand, ancestors)) };
|
|
144
146
|
}
|
|
145
|
-
if (resolved
|
|
147
|
+
if ((resolved?.targetMultiplicity === 'one') && (expression.comparison === undefined)) {
|
|
146
148
|
const empty = emptyCriterion(expression.value);
|
|
147
|
-
if (empty)
|
|
148
|
-
return { [property]: empty === 'empty' ? (0, sql_functions_9.isNull)() : (0, sql_functions_8.isNotNull)() };
|
|
149
|
+
if (empty) {
|
|
150
|
+
return { [property]: (empty === 'empty') ? (0, sql_functions_9.isNull)() : (0, sql_functions_8.isNotNull)() };
|
|
151
|
+
}
|
|
149
152
|
}
|
|
150
|
-
|
|
153
|
+
const target = resolved?.target ?? type;
|
|
154
|
+
if (ancestors.includes(target)) {
|
|
151
155
|
throw new Error(`Cyclic search representation: ${property}`);
|
|
152
|
-
|
|
156
|
+
}
|
|
157
|
+
const branch = [...ancestors, target];
|
|
158
|
+
const prefix = property ? `${property}.` : '';
|
|
153
159
|
return {
|
|
154
|
-
[sql_functions_2.OR]: (0, class_view_1.representativeOf)(
|
|
155
|
-
.map(name => this.condition(type, `${property}.${String(name)}`, expression, branch))
|
|
160
|
+
[sql_functions_2.OR]: (0, class_view_1.representativeOf)(target).map(name => this.condition(type, prefix + String(name), expression, branch))
|
|
156
161
|
};
|
|
157
162
|
}
|
|
158
163
|
getParams(request, _type) {
|
|
@@ -189,13 +194,16 @@ class Filter extends parameter_1.Parameter {
|
|
|
189
194
|
readOptions(options = new Array) {
|
|
190
195
|
return options;
|
|
191
196
|
}
|
|
192
|
-
searchObject(type) {
|
|
197
|
+
searchObject(type, searchOnOwner) {
|
|
193
198
|
const search = {};
|
|
194
199
|
const groups = [];
|
|
195
200
|
for (const [property, value] of Object.entries(this.search)) {
|
|
196
201
|
if (value === '')
|
|
197
202
|
continue;
|
|
198
|
-
const
|
|
203
|
+
const path = searchOnOwner?.((0, reflect_path_1.resolvePropertyPath)(type, property))
|
|
204
|
+
? property.substring(0, property.lastIndexOf('.'))
|
|
205
|
+
: property;
|
|
206
|
+
const condition = this.columnCondition(type, path, value);
|
|
199
207
|
if (Object.hasOwn(condition, sql_functions_1.AND) || Object.hasOwn(condition, sql_functions_2.OR)) {
|
|
200
208
|
groups.push(condition);
|
|
201
209
|
}
|
package/cjs/list.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Feed } from './feed';
|
|
|
8
8
|
import { Filter } from './filter';
|
|
9
9
|
import { Sort } from './sort';
|
|
10
10
|
export { listAccess, listDependsOn } from './access';
|
|
11
|
-
export type { ListAccess, ListDependencies, ListView } from './access';
|
|
11
|
+
export type { ListAccess, ListColumnOutput, ListColumnsView, ListDependencies, ListView } from './access';
|
|
12
12
|
export declare class List<T extends object = object> extends Action<T> {
|
|
13
13
|
columns: Columns<object>;
|
|
14
14
|
columnWidths: ColumnWidths<object>;
|
package/cjs/list.html
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
<article data-action="list" data-class="{type.name}" data-route="{type.@route}" data-property-root="{?root}"
|
|
19
19
|
data-selector-key="{?selectorKey}" data-selector-bootstrap="{?selectorBootstrap}">
|
|
20
20
|
<!--view-->{{template}}<!--end-->
|
|
21
|
+
<!--columnsView-->{{template}}<!--end-->
|
|
21
22
|
<header>
|
|
22
23
|
<h2>{type.@output.ucFirst} list</h2>
|
|
23
24
|
<div class="list-toolbar">
|
package/cjs/list.js
CHANGED
|
@@ -46,6 +46,7 @@ const storage_3 = require("@itrocks/storage");
|
|
|
46
46
|
const access_1 = require("./access");
|
|
47
47
|
const access_2 = require("./access");
|
|
48
48
|
const access_3 = require("./access");
|
|
49
|
+
const access_4 = require("./access");
|
|
49
50
|
const column_widths_1 = require("./column-widths");
|
|
50
51
|
const columns_1 = require("./columns");
|
|
51
52
|
const columns_2 = require("./columns");
|
|
@@ -62,9 +63,9 @@ const selector_state_1 = require("./selector-state");
|
|
|
62
63
|
const selector_state_2 = require("./selector-state");
|
|
63
64
|
const session_state_1 = require("./session-state");
|
|
64
65
|
const sort_1 = require("./sort");
|
|
65
|
-
var
|
|
66
|
-
Object.defineProperty(exports, "listAccess", { enumerable: true, get: function () { return
|
|
67
|
-
Object.defineProperty(exports, "listDependsOn", { enumerable: true, get: function () { return
|
|
66
|
+
var access_5 = require("./access");
|
|
67
|
+
Object.defineProperty(exports, "listAccess", { enumerable: true, get: function () { return access_5.listAccess; } });
|
|
68
|
+
Object.defineProperty(exports, "listDependsOn", { enumerable: true, get: function () { return access_5.listDependsOn; } });
|
|
68
69
|
let List = (() => {
|
|
69
70
|
let _classDecorators = [(0, action_3.Need)('Store', 'new'), (0, route_1.Route)('/list')];
|
|
70
71
|
let _classDescriptor;
|
|
@@ -97,7 +98,7 @@ let List = (() => {
|
|
|
97
98
|
const filter = this.filter;
|
|
98
99
|
const sort = this.sort;
|
|
99
100
|
const type = request.type;
|
|
100
|
-
const selection = (0,
|
|
101
|
+
const selection = (0, access_3.listSelection)();
|
|
101
102
|
const updated = await selection?.update(request);
|
|
102
103
|
if (updated)
|
|
103
104
|
return updated;
|
|
@@ -132,15 +133,18 @@ let List = (() => {
|
|
|
132
133
|
for (const column of columns)
|
|
133
134
|
column.search = filter.search[column.name] ?? '';
|
|
134
135
|
sort.getParams(request.request, type);
|
|
135
|
-
const
|
|
136
|
-
|
|
136
|
+
const columnsView = (0, access_2.listColumnsView)(type, Object.entries(sort.sorted ?? {})[0]);
|
|
137
|
+
const activeSearch = await (0, search_2.listSearch)(request, filter, access, scope, columnsView?.searchOnOwner);
|
|
138
|
+
if ((0, search_1.captureListSearch)(request, activeSearch)) {
|
|
137
139
|
return this.htmlResponse('', 204);
|
|
138
|
-
|
|
140
|
+
}
|
|
141
|
+
if (!batch) {
|
|
139
142
|
(0, persist_2.save)(this, request.request, type);
|
|
140
|
-
|
|
143
|
+
}
|
|
141
144
|
const search = activeSearch.criteria;
|
|
142
|
-
for (const path of Object.keys(sort.sorted ?? {}))
|
|
145
|
+
for (const path of Object.keys(sort.sorted ?? {})) {
|
|
143
146
|
await access.authorise(path);
|
|
147
|
+
}
|
|
144
148
|
if (batch) {
|
|
145
149
|
try {
|
|
146
150
|
const names = request.request.data.loadColumns.split(',').filter(Boolean);
|
|
@@ -155,15 +159,18 @@ let List = (() => {
|
|
|
155
159
|
await access.authorise(`${column.name}.${field}`);
|
|
156
160
|
}
|
|
157
161
|
const ids = request.request.data.rowIds;
|
|
158
|
-
if (typeof ids !== 'string')
|
|
162
|
+
if (typeof ids !== 'string') {
|
|
159
163
|
throw new Error('Visible row identities are required');
|
|
160
|
-
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
164
|
+
}
|
|
165
|
+
const rows = requested.length
|
|
166
|
+
? await (0, columns_2.projectColumnOutput)(type, requested, search, [new storage_2.Identifiers(ids ? ids.split(',') : [])], access, columnsView)
|
|
167
|
+
: [];
|
|
168
|
+
const response = requested.map((column, index) => ({
|
|
169
|
+
label: column.label,
|
|
170
|
+
path: column.name,
|
|
171
|
+
sortable: column.sortable,
|
|
172
|
+
rows: rows.map(row => ({ id: row.id, html: row.properties[index].outputOptionalContainer }))
|
|
173
|
+
}));
|
|
167
174
|
(0, persist_2.save)(this, request.request, type);
|
|
168
175
|
return this.jsonResponse({ columns: response });
|
|
169
176
|
}
|
|
@@ -178,17 +185,19 @@ let List = (() => {
|
|
|
178
185
|
const column = new projection_1.ListColumn(type, path);
|
|
179
186
|
for (const field of column.fields ?? [])
|
|
180
187
|
await access.authorise(`${path}.${field}`);
|
|
181
|
-
if (request.request.data.validate === '1')
|
|
188
|
+
if (request.request.data.validate === '1') {
|
|
182
189
|
return this.jsonResponse({ label: column.label, path, sortable: column.sortable });
|
|
190
|
+
}
|
|
183
191
|
const ids = request.request.data.rowIds;
|
|
184
|
-
if (typeof ids !== 'string')
|
|
192
|
+
if (typeof ids !== 'string') {
|
|
185
193
|
throw new Error('Visible row identities are required');
|
|
186
|
-
|
|
194
|
+
}
|
|
195
|
+
const rows = await (0, columns_2.projectColumnOutput)(type, [column], search, [new storage_2.Identifiers(ids ? ids.split(',') : [])], access, columnsView);
|
|
187
196
|
return this.jsonResponse({
|
|
188
|
-
label: column.label,
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}))
|
|
197
|
+
label: column.label,
|
|
198
|
+
path,
|
|
199
|
+
sortable: column.sortable,
|
|
200
|
+
rows: rows.map(row => ({ id: row.id, html: row.properties[0].outputOptionalContainer }))
|
|
192
201
|
});
|
|
193
202
|
}
|
|
194
203
|
catch (error) {
|
|
@@ -198,7 +207,9 @@ let List = (() => {
|
|
|
198
207
|
return this.jsonResponse({ error: message }, 400);
|
|
199
208
|
}
|
|
200
209
|
}
|
|
201
|
-
const
|
|
210
|
+
const sortOptions = columnsView?.sort ? [columnsView.sort] : sort.readOptions();
|
|
211
|
+
const options = feed.readOptions(filter.readOptions(sortOptions));
|
|
212
|
+
const objects = await (0, columns_2.projectColumnOutput)(type, columns, search, options, access, columnsView);
|
|
202
213
|
if (feed.offset) {
|
|
203
214
|
return this.htmlTemplateResponse({ objects, type }, request, feed.template);
|
|
204
215
|
}
|
|
@@ -219,11 +230,12 @@ let List = (() => {
|
|
|
219
230
|
const focus = request.request.method === 'POST' ? request.request.data.focusListColumn : undefined;
|
|
220
231
|
const focusColumn = [...columns].find(column => column.field === focus)?.field ?? '';
|
|
221
232
|
return this.htmlTemplateResponse({
|
|
222
|
-
canResize, columns, count, filterBar: this.filterBar(request), focusColumn,
|
|
233
|
+
canResize, columns, columnsView: columnsView?.view, count, filterBar: this.filterBar(request), focusColumn,
|
|
234
|
+
generalActions, objects,
|
|
223
235
|
root: access.root, search: filter.search,
|
|
224
236
|
selectionActions, selectorBootstrap, selectorKey: (0, selector_state_2.selectorStateKey)(request), type,
|
|
225
237
|
selection: selectionActions.length ? await selection?.view(request, activeSearch, count) : undefined,
|
|
226
|
-
view: await (0,
|
|
238
|
+
view: await (0, access_4.listView)(request)
|
|
227
239
|
}, request, __dirname + '/list.html');
|
|
228
240
|
}
|
|
229
241
|
async json(request, scope) {
|
package/cjs/projection.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Type } from '@itrocks/class-type';
|
|
2
|
+
import { ReflectPropertyPath } from '@itrocks/reflect-path';
|
|
2
3
|
import { resolvePropertyPath } from '@itrocks/reflect-path';
|
|
3
4
|
import { ProjectionCell } from '@itrocks/storage';
|
|
4
5
|
import { Selection } from '@itrocks/storage';
|
|
6
|
+
import type { ListColumnOutput } from './access';
|
|
5
7
|
type RepresentationProperty = ReturnType<typeof resolvePropertyPath>['property'];
|
|
6
8
|
export type RepresentationDependencies = {
|
|
7
9
|
fields?: (type: Type, ancestors: readonly Type[], property?: RepresentationProperty) => readonly string[] | undefined;
|
|
@@ -22,7 +24,7 @@ export declare class ListColumn {
|
|
|
22
24
|
readonly fields?: readonly string[];
|
|
23
25
|
readonly label: string;
|
|
24
26
|
readonly multiple: boolean;
|
|
25
|
-
readonly property:
|
|
27
|
+
readonly property: ReflectPropertyPath<Record<string, unknown>, string>;
|
|
26
28
|
readonly sortable: boolean;
|
|
27
29
|
readonly target?: Type;
|
|
28
30
|
reverse: boolean;
|
|
@@ -31,7 +33,7 @@ export declare class ListColumn {
|
|
|
31
33
|
width?: number;
|
|
32
34
|
constructor(root: Type, name: string);
|
|
33
35
|
get escapedSearch(): string;
|
|
34
|
-
output(cell: ProjectionCell): Promise<string>;
|
|
36
|
+
output(cell: ProjectionCell, output?: ListColumnOutput, object?: object): Promise<string>;
|
|
35
37
|
selection(): Selection;
|
|
36
38
|
sortPaths(): string[];
|
|
37
39
|
}
|
package/cjs/projection.js
CHANGED
|
@@ -101,7 +101,15 @@ class ListColumn {
|
|
|
101
101
|
get escapedSearch() {
|
|
102
102
|
return (0, filter_summary_1.escapeFilterText)(this.search);
|
|
103
103
|
}
|
|
104
|
-
async output(cell) {
|
|
104
|
+
async output(cell, output, object) {
|
|
105
|
+
if (output) {
|
|
106
|
+
const property = object
|
|
107
|
+
? new reflect_path_1.ReflectPropertyPath(object, this.name)
|
|
108
|
+
: this.property;
|
|
109
|
+
const rendered = await output(this, cell, property);
|
|
110
|
+
if (rendered !== undefined)
|
|
111
|
+
return rendered;
|
|
112
|
+
}
|
|
105
113
|
if (cell.kind === 'absent')
|
|
106
114
|
return '';
|
|
107
115
|
if (cell.kind === 'unloaded')
|
package/cjs/search.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Request } from '@itrocks/action-request';
|
|
2
2
|
import type { SearchType } from '@itrocks/storage';
|
|
3
3
|
import type { ListAccess } from './access';
|
|
4
|
+
import type { ListColumnsView } from './access';
|
|
4
5
|
import type { Filter } from './filter';
|
|
5
6
|
export type ListSearch = {
|
|
6
7
|
criteria: SearchType;
|
|
@@ -8,7 +9,7 @@ export type ListSearch = {
|
|
|
8
9
|
};
|
|
9
10
|
export declare function resolveListSearch(request: Request, run: (request: Request) => Promise<unknown>): Promise<ListSearch | undefined>;
|
|
10
11
|
export declare function captureListSearch(request: Request, search: ListSearch): boolean;
|
|
11
|
-
export declare function listSearch<T extends object>(request: Request<T>, filter: Filter<T>, access: ListAccess, scope?: SearchType<T
|
|
12
|
+
export declare function listSearch<T extends object>(request: Request<T>, filter: Filter<T>, access: ListAccess, scope?: SearchType<T>, searchOnOwner?: ListColumnsView['searchOnOwner']): Promise<{
|
|
12
13
|
criteria: SearchType<T>;
|
|
13
14
|
filters: Record<string, string>;
|
|
14
15
|
}>;
|
package/cjs/search.js
CHANGED
|
@@ -26,8 +26,8 @@ function captureListSearch(request, search) {
|
|
|
26
26
|
lookup.search = search;
|
|
27
27
|
return true;
|
|
28
28
|
}
|
|
29
|
-
async function listSearch(request, filter, access, scope) {
|
|
30
|
-
const filters = filter.searchObject(request.type);
|
|
29
|
+
async function listSearch(request, filter, access, scope, searchOnOwner) {
|
|
30
|
+
const filters = filter.searchObject(request.type, searchOnOwner);
|
|
31
31
|
// Scope values override direct user criteria; logical groups remain cumulative.
|
|
32
32
|
for (const path of Object.keys(scope ?? {}))
|
|
33
33
|
delete filters[path];
|
package/docs/dependencies.md
CHANGED
|
@@ -40,3 +40,18 @@ The host owns the supplied template and its data; the list does not depend on th
|
|
|
40
40
|
and after the selection actions, and a handler for updates. The view callback receives the request, effective list
|
|
41
41
|
criteria and result count. `resolveListSearch` from `@itrocks/list/search` captures the criteria from the routed HTML
|
|
42
42
|
list action, including its mandatory scope and path authorisation.
|
|
43
|
+
|
|
44
|
+
`listDependsOn({ columnsView })` supplies a renderer for selected cells and an optional view fragment for the full
|
|
45
|
+
list. The callback receives the list type and its first applied sort entry, if any. Its
|
|
46
|
+
`output(column, cell, property)` callback can return HTML, including an empty string, or `undefined` to use the
|
|
47
|
+
standard renderer. It may also return a promise. The third argument is a `ReflectPropertyPath` with the full column
|
|
48
|
+
path and the root class. Return the display dependency paths from `objectFields(column)` to attach the source
|
|
49
|
+
object to that reflection. List authorises the paths before loading objects for the selected row IDs with the
|
|
50
|
+
effective search criteria. Extensions declare the paths whose values they display. The same callback
|
|
51
|
+
applies to the initial list, feed rows, and cells added by the column selector. The optional `view` follows the
|
|
52
|
+
usual `{ template, ...data }` contract. The optional `sort` replaces the storage sort for the initial list and
|
|
53
|
+
feed rows while retaining the applied sort and direction in the interface.
|
|
54
|
+
|
|
55
|
+
With `searchOnOwner(property)`, a column extension can make a filter search the object owning the configured
|
|
56
|
+
property. List applies the same representative matching used for object columns and authorises the resulting
|
|
57
|
+
paths. For a property at the root, the filter searches the listed object.
|
package/list.css
CHANGED
|
@@ -43,6 +43,12 @@ table.objects tr td, table.objects tr th {
|
|
|
43
43
|
table.objects tr td:nth-last-child(1 of :not([hidden])), table.objects tr th:nth-last-child(1 of :not([hidden])) {
|
|
44
44
|
border-right: 1px solid #d8d8d8;
|
|
45
45
|
}
|
|
46
|
+
table.objects > :is(thead, tbody) > tr > :nth-child(1 of th.select:not([hidden]) ~ :not([hidden])) {
|
|
47
|
+
border-left: 1px solid #d8d8d8;
|
|
48
|
+
}
|
|
49
|
+
table.objects > :is(thead, tbody) > tr > :nth-child(1 of th.select:not([hidden]) ~ :not([hidden])) > input[data-property-filter] {
|
|
50
|
+
border-left-width: 0;
|
|
51
|
+
}
|
|
46
52
|
table.objects > * > tr > .column-reorder {
|
|
47
53
|
--column-reorder-tint: inset 0 0 0 100vmax rgb(0 0 0 / 2%);
|
|
48
54
|
box-shadow: var(--column-reorder-tint);
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export type SearchComparison = ':' | '=' | '!=' | '<' | '<=' | '>' | '>=';
|
|
2
|
-
export type SearchExpression = {
|
|
3
|
-
comparison?: SearchComparison;
|
|
4
|
-
value: string;
|
|
5
|
-
} | {
|
|
6
|
-
operator: 'AND' | 'OR';
|
|
7
|
-
operands: SearchExpression[];
|
|
8
|
-
};
|
|
9
|
-
export declare function searchExpression(input: string): SearchExpression;
|
package/cjs/search-expression.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.searchExpression = searchExpression;
|
|
4
|
-
function searchExpression(input) {
|
|
5
|
-
// Preserve ordinary input exactly, including spaces used by existing scalar criteria.
|
|
6
|
-
if (!/[,|&+()"\\]/.test(input))
|
|
7
|
-
return { value: input };
|
|
8
|
-
return new SearchParser(input).parse();
|
|
9
|
-
}
|
|
10
|
-
class SearchParser {
|
|
11
|
-
input;
|
|
12
|
-
position = 0;
|
|
13
|
-
constructor(input) {
|
|
14
|
-
this.input = input;
|
|
15
|
-
}
|
|
16
|
-
and() {
|
|
17
|
-
const operands = [this.primary()];
|
|
18
|
-
while (this.take('&+'))
|
|
19
|
-
operands.push(this.primary());
|
|
20
|
-
return (operands.length === 1) ? operands[0] : { operator: 'AND', operands };
|
|
21
|
-
}
|
|
22
|
-
fail(message) {
|
|
23
|
-
throw new SyntaxError(`${message} at position ${this.position + 1}`);
|
|
24
|
-
}
|
|
25
|
-
or() {
|
|
26
|
-
const operands = [this.and()];
|
|
27
|
-
while (this.take(',|'))
|
|
28
|
-
operands.push(this.and());
|
|
29
|
-
return (operands.length === 1) ? operands[0] : { operator: 'OR', operands };
|
|
30
|
-
}
|
|
31
|
-
parse() {
|
|
32
|
-
const expression = this.or();
|
|
33
|
-
this.space();
|
|
34
|
-
if (this.position !== this.input.length)
|
|
35
|
-
this.fail('Unexpected character');
|
|
36
|
-
return expression;
|
|
37
|
-
}
|
|
38
|
-
primary() {
|
|
39
|
-
if (this.take('(')) {
|
|
40
|
-
const expression = this.or();
|
|
41
|
-
if (!this.take(')')) {
|
|
42
|
-
this.fail('Missing closing parenthesis');
|
|
43
|
-
}
|
|
44
|
-
return expression;
|
|
45
|
-
}
|
|
46
|
-
let value = '';
|
|
47
|
-
let length = 0;
|
|
48
|
-
let quoted = false;
|
|
49
|
-
let seen = false;
|
|
50
|
-
while (this.position < this.input.length) {
|
|
51
|
-
const character = this.input[this.position];
|
|
52
|
-
if (!quoted && ',|&+()'.includes(character))
|
|
53
|
-
break;
|
|
54
|
-
this.position++;
|
|
55
|
-
if ((character === '\\')
|
|
56
|
-
&& (this.position < this.input.length)
|
|
57
|
-
&& ',|&+()"\\'.includes(this.input[this.position])) {
|
|
58
|
-
value += this.input[this.position++];
|
|
59
|
-
length = value.length;
|
|
60
|
-
seen = true;
|
|
61
|
-
}
|
|
62
|
-
else if (character === '"') {
|
|
63
|
-
quoted = !quoted;
|
|
64
|
-
seen = true;
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
value += character;
|
|
68
|
-
if (quoted || character.trim())
|
|
69
|
-
length = value.length;
|
|
70
|
-
seen ||= !!character.trim();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (quoted)
|
|
74
|
-
this.fail('Unclosed quote');
|
|
75
|
-
if (!seen)
|
|
76
|
-
this.fail('Missing criterion');
|
|
77
|
-
return { value: value.slice(0, length) };
|
|
78
|
-
}
|
|
79
|
-
space() {
|
|
80
|
-
while ((this.position < this.input.length) && /\s/.test(this.input[this.position])) {
|
|
81
|
-
this.position++;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
take(characters) {
|
|
85
|
-
this.space();
|
|
86
|
-
if ((this.position === this.input.length) || !characters.includes(this.input[this.position])) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
this.position++;
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
//# sourceMappingURL=search-expression.js.map
|