@sealcode/sealgen 0.10.5 → 0.10.6
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/@types/page/sealious-list.d.ts +1 -0
- package/lib/page/sealious-list.js +13 -0
- package/lib/templates/list.js +17 -28
- package/package.json +1 -1
- package/src/page/sealious-list.ts +14 -0
- package/src/templates/list.ts +17 -28
|
@@ -10,6 +10,7 @@ export declare abstract class SealiousItemListPage<C extends Collection, F exten
|
|
|
10
10
|
protected addFilter(ctx: Context, list: ItemList<C>): Promise<void>;
|
|
11
11
|
makeQuery(ctx: Context): Promise<ItemList<C>>;
|
|
12
12
|
getItems(ctx: Context, page: number, itemsPerPage: number): Promise<CollectionItem<C>[]>;
|
|
13
|
+
getFilterValues(ctx: Context): Promise<Record<string, string | undefined>>;
|
|
13
14
|
renderItem(_: Context, item: CollectionItem<C>, index: number): Promise<FlatTemplatable>;
|
|
14
15
|
canAccess: (ctx: Context) => Promise<{
|
|
15
16
|
canAccess: boolean;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.SealiousItemListPage = void 0;
|
|
4
7
|
const list_1 = require("./list");
|
|
5
8
|
const access_control_1 = require("./access-control");
|
|
9
|
+
const qs_1 = __importDefault(require("qs"));
|
|
10
|
+
const ts_predicates_1 = require("@sealcode/ts-predicates");
|
|
6
11
|
class SealiousItemListPage extends list_1.ListPage {
|
|
7
12
|
constructor(collection) {
|
|
8
13
|
super();
|
|
@@ -45,6 +50,14 @@ class SealiousItemListPage extends list_1.ListPage {
|
|
|
45
50
|
.fetch();
|
|
46
51
|
return items;
|
|
47
52
|
}
|
|
53
|
+
async getFilterValues(ctx) {
|
|
54
|
+
const query_params = qs_1.default.parse(ctx.search.slice(1));
|
|
55
|
+
const _filter_values = query_params?.filter || {};
|
|
56
|
+
let filter_values = (0, ts_predicates_1.is)(_filter_values, ts_predicates_1.predicates.record(ts_predicates_1.predicates.string, ts_predicates_1.predicates.string))
|
|
57
|
+
? _filter_values
|
|
58
|
+
: {};
|
|
59
|
+
return filter_values;
|
|
60
|
+
}
|
|
48
61
|
async renderItem(_, item, index) {
|
|
49
62
|
return `<div>${item.id}</div>`;
|
|
50
63
|
}
|
package/lib/templates/list.js
CHANGED
|
@@ -87,22 +87,6 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
87
87
|
> {
|
|
88
88
|
fields = BaseListPageFields;
|
|
89
89
|
|
|
90
|
-
async render(ctx: Context) {
|
|
91
|
-
return html(
|
|
92
|
-
ctx,
|
|
93
|
-
"${action_name}",
|
|
94
|
-
tempstream/* HTML */ \`<div>
|
|
95
|
-
<h2>${action_name}</h2>
|
|
96
|
-
<table class="sealious-list">
|
|
97
|
-
\${this.renderTableHead(ctx, displayFields)}
|
|
98
|
-
<tbody>
|
|
99
|
-
\${super.render(ctx)}
|
|
100
|
-
</tbody>
|
|
101
|
-
</table>
|
|
102
|
-
</div>\`
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
90
|
async renderFilters(ctx: Context): Promise<FlatTemplatable> {
|
|
107
91
|
const query_params = qs.parse(ctx.search.slice(1));
|
|
108
92
|
query_params.page = "1";
|
|
@@ -132,18 +116,6 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
132
116
|
</form>\`;
|
|
133
117
|
}
|
|
134
118
|
|
|
135
|
-
async getFilterValues(ctx: Context) {
|
|
136
|
-
const query_params = qs.parse(ctx.search.slice(1));
|
|
137
|
-
const _filter_values = query_params?.filter || {};
|
|
138
|
-
let filter_values: Record<string, string | undefined> = is(
|
|
139
|
-
_filter_values,
|
|
140
|
-
predicates.record(predicates.string, predicates.string)
|
|
141
|
-
)
|
|
142
|
-
? _filter_values
|
|
143
|
-
: {};
|
|
144
|
-
return filter_values;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
119
|
async renderItem(_: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
148
120
|
return tempstream/* HTML */ \`<tr>
|
|
149
121
|
\${displayFields.map(({ field, format }) => {
|
|
@@ -152,6 +124,23 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
152
124
|
})}
|
|
153
125
|
</tr>\`;
|
|
154
126
|
}
|
|
127
|
+
|
|
128
|
+
async render(ctx: Context) {
|
|
129
|
+
return html(
|
|
130
|
+
ctx,
|
|
131
|
+
"${action_name}",
|
|
132
|
+
tempstream/* HTML */ \`<div>
|
|
133
|
+
<h2>${action_name}</h2>
|
|
134
|
+
<table class="sealious-list">
|
|
135
|
+
\${this.renderTableHead(ctx, displayFields)}
|
|
136
|
+
<tbody>
|
|
137
|
+
\${super.render(ctx)}
|
|
138
|
+
</tbody>
|
|
139
|
+
</table>
|
|
140
|
+
</div>\`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
155
144
|
})(${uppercase_collection});
|
|
156
145
|
`;
|
|
157
146
|
};
|
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
} from "sealious";
|
|
10
10
|
import { FlatTemplatable } from "tempstream";
|
|
11
11
|
import { peopleWhoCan } from "./access-control";
|
|
12
|
+
import qs from "qs";
|
|
13
|
+
import { is, predicates } from "@sealcode/ts-predicates";
|
|
12
14
|
|
|
13
15
|
export abstract class SealiousItemListPage<
|
|
14
16
|
C extends Collection,
|
|
@@ -64,6 +66,18 @@ export abstract class SealiousItemListPage<
|
|
|
64
66
|
return items;
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
async getFilterValues(ctx: Context) {
|
|
70
|
+
const query_params = qs.parse(ctx.search.slice(1));
|
|
71
|
+
const _filter_values = query_params?.filter || {};
|
|
72
|
+
let filter_values: Record<string, string | undefined> = is(
|
|
73
|
+
_filter_values,
|
|
74
|
+
predicates.record(predicates.string, predicates.string)
|
|
75
|
+
)
|
|
76
|
+
? _filter_values
|
|
77
|
+
: {};
|
|
78
|
+
return filter_values;
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
async renderItem(
|
|
68
82
|
_: Context,
|
|
69
83
|
item: CollectionItem<C>,
|
package/src/templates/list.ts
CHANGED
|
@@ -98,22 +98,6 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
98
98
|
> {
|
|
99
99
|
fields = BaseListPageFields;
|
|
100
100
|
|
|
101
|
-
async render(ctx: Context) {
|
|
102
|
-
return html(
|
|
103
|
-
ctx,
|
|
104
|
-
"${action_name}",
|
|
105
|
-
tempstream/* HTML */ \`<div>
|
|
106
|
-
<h2>${action_name}</h2>
|
|
107
|
-
<table class="sealious-list">
|
|
108
|
-
\${this.renderTableHead(ctx, displayFields)}
|
|
109
|
-
<tbody>
|
|
110
|
-
\${super.render(ctx)}
|
|
111
|
-
</tbody>
|
|
112
|
-
</table>
|
|
113
|
-
</div>\`
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
101
|
async renderFilters(ctx: Context): Promise<FlatTemplatable> {
|
|
118
102
|
const query_params = qs.parse(ctx.search.slice(1));
|
|
119
103
|
query_params.page = "1";
|
|
@@ -143,18 +127,6 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
143
127
|
</form>\`;
|
|
144
128
|
}
|
|
145
129
|
|
|
146
|
-
async getFilterValues(ctx: Context) {
|
|
147
|
-
const query_params = qs.parse(ctx.search.slice(1));
|
|
148
|
-
const _filter_values = query_params?.filter || {};
|
|
149
|
-
let filter_values: Record<string, string | undefined> = is(
|
|
150
|
-
_filter_values,
|
|
151
|
-
predicates.record(predicates.string, predicates.string)
|
|
152
|
-
)
|
|
153
|
-
? _filter_values
|
|
154
|
-
: {};
|
|
155
|
-
return filter_values;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
130
|
async renderItem(_: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
159
131
|
return tempstream/* HTML */ \`<tr>
|
|
160
132
|
\${displayFields.map(({ field, format }) => {
|
|
@@ -163,6 +135,23 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
163
135
|
})}
|
|
164
136
|
</tr>\`;
|
|
165
137
|
}
|
|
138
|
+
|
|
139
|
+
async render(ctx: Context) {
|
|
140
|
+
return html(
|
|
141
|
+
ctx,
|
|
142
|
+
"${action_name}",
|
|
143
|
+
tempstream/* HTML */ \`<div>
|
|
144
|
+
<h2>${action_name}</h2>
|
|
145
|
+
<table class="sealious-list">
|
|
146
|
+
\${this.renderTableHead(ctx, displayFields)}
|
|
147
|
+
<tbody>
|
|
148
|
+
\${super.render(ctx)}
|
|
149
|
+
</tbody>
|
|
150
|
+
</table>
|
|
151
|
+
</div>\`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
166
155
|
})(${uppercase_collection});
|
|
167
156
|
`;
|
|
168
157
|
};
|