@sealcode/sealgen 0.15.11 → 0.15.13
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/src/forms/controls/array.d.ts +1 -1
- package/@types/src/forms/controls/multiple-files.d.ts +1 -1
- package/@types/src/forms/fields/collection-field.d.ts +5 -5
- package/@types/src/forms/fields/existing-sealious-value.d.ts +1 -1
- package/@types/src/forms/fields/field.test.d.ts +1 -0
- package/@types/src/forms/fields/structured-array.d.ts +1 -1
- package/@types/src/page/default-list-filters.d.ts +3 -3
- package/lib/forms/controls/array.js +4 -1
- package/lib/forms/controls/multiple-files.js +1 -0
- package/lib/forms/fields/field.test.js +58 -0
- package/lib/templates/list.js +22 -3
- package/package.json +2 -2
- package/src/forms/controls/array.ts +5 -2
- package/src/forms/controls/multiple-files.ts +2 -1
- package/src/forms/fields/collection-field.ts +9 -7
- package/src/forms/fields/existing-sealious-value.ts +2 -2
- package/src/forms/fields/field.test.ts +67 -0
- package/src/forms/fields/structured-array.ts +1 -1
- package/src/page/default-list-filters.ts +6 -3
- package/src/templates/list.ts +21 -3
|
@@ -16,7 +16,7 @@ export type UnboundControlStorage<F extends {
|
|
|
16
16
|
export declare function UnboundControl<F extends {
|
|
17
17
|
new (...args: any): FormFieldControl;
|
|
18
18
|
}>(controlClass: F, arbitrary_field_name: string, params: ConstructorParameters<F>["1"]): UnboundControlStorage;
|
|
19
|
-
export declare class StructuredArray<Subfields extends Record<string, Field
|
|
19
|
+
export declare class StructuredArray<Subfields extends Record<string, Field<any>>> extends FormFieldControl {
|
|
20
20
|
field: StructuredArrayField<Subfields>;
|
|
21
21
|
item_controls: Array<FormControl | UnboundControlStorage>;
|
|
22
22
|
constructor(field: StructuredArrayField<Subfields>, item_controls: Array<FormControl | UnboundControlStorage>);
|
|
@@ -26,7 +26,7 @@ export declare class MultipleFiles extends FormFieldControl {
|
|
|
26
26
|
renderFrame(_ctx: Context, content?: FlatTemplatable): import("stream").Readable;
|
|
27
27
|
render(fctx: FormControlContext): FlatTemplatable | Promise<FlatTemplatable>;
|
|
28
28
|
getReferencingCollection(): Collection;
|
|
29
|
-
getFileField(): SealiousField | null;
|
|
29
|
+
getFileField(): SealiousField<any> | null;
|
|
30
30
|
extractFileFromItem(item: CollectionItem<Collection>): Promise<FilePointer | null>;
|
|
31
31
|
renderFileItemPreview(_fileItem: CollectionItem, file: FilePointer): Promise<FlatTemplatable>;
|
|
32
32
|
renderFileItem(fileItem: CollectionItem, file: FilePointer): Promise<FlatTemplatable>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
|
-
import {
|
|
2
|
+
import { ExtractFieldDecoded, Field } from "sealious";
|
|
3
3
|
import { FormDataValue } from "../form-types.js";
|
|
4
4
|
import { FieldParseResult, FormField, FormFieldValidationResponse } from "./field.js";
|
|
5
|
-
export declare class CollectionField<F extends Field
|
|
5
|
+
export declare class CollectionField<F extends Field<any>, Required extends boolean> extends FormField<Required, ExtractFieldDecoded<F> | null> {
|
|
6
6
|
sealiousField: F;
|
|
7
7
|
constructor(required: Required, sealiousField: F);
|
|
8
8
|
predicate: (v: unknown, w: unknown) => {
|
|
9
9
|
readonly match: true;
|
|
10
10
|
readonly wildcard: unknown;
|
|
11
11
|
};
|
|
12
|
-
parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<
|
|
13
|
-
isValueValid(ctx: Context, value:
|
|
14
|
-
getEmptyValue():
|
|
12
|
+
parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<ExtractFieldDecoded<F> | null>>;
|
|
13
|
+
isValueValid(ctx: Context, value: ExtractFieldDecoded<F>): Promise<FormFieldValidationResponse>;
|
|
14
|
+
getEmptyValue(): ExtractFieldDecoded<F>;
|
|
15
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Field } from "sealious";
|
|
2
2
|
import { PickFromListField } from "./pick-from-list.js";
|
|
3
3
|
export declare class ExistingSealiousValue<Required extends boolean> extends PickFromListField<Required> {
|
|
4
|
-
constructor(required: Required, field: Field);
|
|
4
|
+
constructor(required: Required, field: Field<unknown>);
|
|
5
5
|
getEmptyValue(): string;
|
|
6
6
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,7 +2,7 @@ import { Context } from "koa";
|
|
|
2
2
|
import { Field, FieldsetOutput, FieldTypes } from "sealious";
|
|
3
3
|
import { FormDataValue } from "../form-types.js";
|
|
4
4
|
import { FormField } from "./field.js";
|
|
5
|
-
export declare class StructuredArrayField<Fields extends Record<string, Field
|
|
5
|
+
export declare class StructuredArrayField<Fields extends Record<string, Field<unknown>>> extends FormField<true, FieldTypes.ArrayStorageInput<FieldsetOutput<Fields>>> {
|
|
6
6
|
sealious_field: FieldTypes.StructuredArray<Fields>;
|
|
7
7
|
constructor(sealious_field: FieldTypes.StructuredArray<Fields>);
|
|
8
8
|
parse(_context: Context, value: FormDataValue): Promise<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Field } from "sealious";
|
|
2
2
|
import { FlatTemplatable } from "tempstream";
|
|
3
|
-
export type ListFilterRender = (value: string, field: Field) => FlatTemplatable;
|
|
4
|
-
export declare const BooleanListFilter: (value: string, field: Field) => string;
|
|
5
|
-
export declare const SimpleTextFilter: (value: string, field: Field) => string;
|
|
3
|
+
export type ListFilterRender = (value: string, field: Field<any>) => FlatTemplatable;
|
|
4
|
+
export declare const BooleanListFilter: (value: string, field: Field<any>) => string;
|
|
5
|
+
export declare const SimpleTextFilter: (value: string, field: Field<any>) => string;
|
|
6
6
|
export declare const DefaultListFilters: Record<string, ListFilterRender>;
|
|
@@ -87,6 +87,7 @@ class MultipleFiles extends FormFieldControl {
|
|
|
87
87
|
const result = this.field.collection_field.app.collections[this.field.collection_field.referencing_collection];
|
|
88
88
|
return result;
|
|
89
89
|
}
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
91
|
getFileField() {
|
|
91
92
|
for (const [_, field] of Object.entries(
|
|
92
93
|
this.getReferencingCollection().fields
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import Router from "@koa/router";
|
|
2
|
+
import getPort from "get-port";
|
|
3
|
+
import Koa from "koa";
|
|
4
|
+
import { mount } from "../../mount.js";
|
|
5
|
+
import { Form } from "../form.js";
|
|
6
|
+
import { getBrowser } from "../../utils/browser-creator.js";
|
|
7
|
+
import { SimpleFormField } from "./simple-form-field.js";
|
|
8
|
+
import { SimpleInput } from "../controls/simple-input.js";
|
|
9
|
+
describe("basic field", () => {
|
|
10
|
+
describe("basic tests", async () => {
|
|
11
|
+
let server;
|
|
12
|
+
let browser;
|
|
13
|
+
let page;
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
server.close();
|
|
16
|
+
});
|
|
17
|
+
it("sends the values", async () => {
|
|
18
|
+
const port = await getPort();
|
|
19
|
+
console.log(`Using port ${port} form checkboxed-list-input.test.ts`);
|
|
20
|
+
const app = new Koa();
|
|
21
|
+
const router = new Router();
|
|
22
|
+
const fields = {
|
|
23
|
+
text: new SimpleFormField(true)
|
|
24
|
+
};
|
|
25
|
+
let received_values;
|
|
26
|
+
mount(
|
|
27
|
+
router,
|
|
28
|
+
"/",
|
|
29
|
+
new class extends Form {
|
|
30
|
+
constructor() {
|
|
31
|
+
super(...arguments);
|
|
32
|
+
this.fields = fields;
|
|
33
|
+
this.controls = [new SimpleInput(fields.text)];
|
|
34
|
+
}
|
|
35
|
+
async onSubmit(ctx, data) {
|
|
36
|
+
received_values = await this.getParsedValues(ctx);
|
|
37
|
+
const { parsed: email } = await this.fields.text.getValue(
|
|
38
|
+
ctx,
|
|
39
|
+
data.raw_values
|
|
40
|
+
);
|
|
41
|
+
email?.padStart(2, "0");
|
|
42
|
+
}
|
|
43
|
+
async canAccess(_) {
|
|
44
|
+
return { canAccess: true, message: "" };
|
|
45
|
+
}
|
|
46
|
+
}(),
|
|
47
|
+
true
|
|
48
|
+
);
|
|
49
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
50
|
+
server = app.listen(port);
|
|
51
|
+
browser = await getBrowser();
|
|
52
|
+
const context = await browser.newContext();
|
|
53
|
+
page = await context.newPage();
|
|
54
|
+
await page.goto(`http://localhost:${port}`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=field.test.js.map
|
package/lib/templates/list.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _locreq from "locreq";
|
|
2
|
+
import { curryImportPath } from "../utils/import-path.js";
|
|
2
3
|
import prompts from "prompts";
|
|
3
4
|
import { listCollections } from "../utils/list-collections.js";
|
|
4
5
|
import { extractCollectionClassname } from "../generate-collections.js";
|
|
@@ -25,12 +26,15 @@ const listTemplate = async (action_name, newfilefullpath) => {
|
|
|
25
26
|
),
|
|
26
27
|
extract_fields_from_collection(collection_name)
|
|
27
28
|
]);
|
|
29
|
+
const importPath = curryImportPath(newfilefullpath);
|
|
28
30
|
const result = `import type { Context } from "koa";
|
|
29
31
|
import type { CollectionItem } from "sealious";
|
|
30
32
|
import type { FlatTemplatable } from "tempstream";
|
|
31
33
|
import { TempstreamJSX } from "tempstream";
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
+
import { ${uppercase_collection} } from "${importPath(
|
|
35
|
+
target_locreq.resolve("src/back/collections/collections.ts")
|
|
36
|
+
)}";
|
|
37
|
+
import html from "${importPath(target_locreq.resolve("src/back/html.ts"))}";
|
|
34
38
|
import type { ListFilterRender } from "@sealcode/sealgen";
|
|
35
39
|
import {
|
|
36
40
|
SealiousItemListPage,
|
|
@@ -38,6 +42,10 @@ import {
|
|
|
38
42
|
DefaultListFilters,
|
|
39
43
|
} from "@sealcode/sealgen";
|
|
40
44
|
import qs from "qs";
|
|
45
|
+
import type { FilePointer } from "@sealcode/file-manager";
|
|
46
|
+
import { imageRouter } from "${importPath(
|
|
47
|
+
target_locreq.resolve("src/back/image-router.ts")
|
|
48
|
+
)}";
|
|
41
49
|
|
|
42
50
|
export const actionName = "${action_name}";
|
|
43
51
|
|
|
@@ -71,6 +79,17 @@ ${collection_fields.map((field) => {
|
|
|
71
79
|
},
|
|
72
80
|
}`;
|
|
73
81
|
}
|
|
82
|
+
if (field.type == "image") {
|
|
83
|
+
return `{
|
|
84
|
+
field: "${field.name}",
|
|
85
|
+
label: "${field.name}",
|
|
86
|
+
format: async (value: FilePointer) => {
|
|
87
|
+
return imageRouter.image(await value.getPath(), {
|
|
88
|
+
container: { width: 45, height: 45 },
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
}`;
|
|
92
|
+
}
|
|
74
93
|
return ` { field: "${field.name}", label: "${field.name}" }`;
|
|
75
94
|
}).join(",\n")}
|
|
76
95
|
] as {
|
|
@@ -114,7 +133,7 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
114
133
|
</form>;
|
|
115
134
|
}
|
|
116
135
|
|
|
117
|
-
async renderItem(
|
|
136
|
+
async renderItem(ctx: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
118
137
|
return <tr>
|
|
119
138
|
{displayFields.map(({ field, format }) => {
|
|
120
139
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/sealgen",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.13",
|
|
4
4
|
"description": "Module to automate adding routes and collections to a sealious application",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -80,6 +80,6 @@
|
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"koa": "^2.13.0",
|
|
82
82
|
"koa-responsive-image-router": "^0.2.24",
|
|
83
|
-
"sealious": "^0.19.
|
|
83
|
+
"sealious": "^0.19.8"
|
|
84
84
|
}
|
|
85
85
|
}
|
|
@@ -30,7 +30,7 @@ export function UnboundControl<
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export class StructuredArray<
|
|
33
|
-
Subfields extends Record<string, Field
|
|
33
|
+
Subfields extends Record<string, Field<any>>
|
|
34
34
|
> extends FormFieldControl {
|
|
35
35
|
constructor(
|
|
36
36
|
public field: StructuredArrayField<Subfields>,
|
|
@@ -224,7 +224,10 @@ export class StructuredArray<
|
|
|
224
224
|
ctx.body = this._render(
|
|
225
225
|
ctx,
|
|
226
226
|
form_id,
|
|
227
|
-
await item.getDecodedBody(
|
|
227
|
+
(await item.getDecodedBody(
|
|
228
|
+
ctx.$context,
|
|
229
|
+
{}
|
|
230
|
+
)) as unknown as Record<string, FormDataValue>
|
|
228
231
|
);
|
|
229
232
|
});
|
|
230
233
|
}
|
|
@@ -128,7 +128,8 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
128
128
|
return result;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
+
getFileField(): SealiousField<any> | null {
|
|
132
133
|
for (const [_, field] of Object.entries(
|
|
133
134
|
this.getReferencingCollection().fields
|
|
134
135
|
)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { predicates } from "@sealcode/ts-predicates";
|
|
2
2
|
import { Context } from "koa";
|
|
3
|
-
import { Depromisify,
|
|
3
|
+
import { Depromisify, ExtractFieldDecoded, Field } from "sealious";
|
|
4
4
|
import { FormDataValue } from "../form-types.js";
|
|
5
5
|
|
|
6
6
|
import {
|
|
@@ -10,9 +10,10 @@ import {
|
|
|
10
10
|
} from "./field.js";
|
|
11
11
|
|
|
12
12
|
export class CollectionField<
|
|
13
|
-
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
F extends Field<any>,
|
|
14
15
|
Required extends boolean
|
|
15
|
-
> extends FormField<Required,
|
|
16
|
+
> extends FormField<Required, ExtractFieldDecoded<F> | null> {
|
|
16
17
|
constructor(required: Required, public sealiousField: F) {
|
|
17
18
|
super(required);
|
|
18
19
|
}
|
|
@@ -22,7 +23,7 @@ export class CollectionField<
|
|
|
22
23
|
async parse(
|
|
23
24
|
ctx: Context,
|
|
24
25
|
raw_value: FormDataValue
|
|
25
|
-
): Promise<FieldParseResult<
|
|
26
|
+
): Promise<FieldParseResult<ExtractFieldDecoded<F> | null>> {
|
|
26
27
|
if (raw_value === undefined) {
|
|
27
28
|
return { parsable: true, parsed_value: null, error: null };
|
|
28
29
|
}
|
|
@@ -45,7 +46,7 @@ export class CollectionField<
|
|
|
45
46
|
|
|
46
47
|
public async isValueValid(
|
|
47
48
|
ctx: Context,
|
|
48
|
-
value:
|
|
49
|
+
value: ExtractFieldDecoded<F>
|
|
49
50
|
): Promise<FormFieldValidationResponse> {
|
|
50
51
|
const { valid, reason } = await this.sealiousField.checkValue(
|
|
51
52
|
ctx.$context,
|
|
@@ -56,7 +57,8 @@ export class CollectionField<
|
|
|
56
57
|
return { valid, message: reason || (!valid ? "Wrong value" : "") };
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
public getEmptyValue():
|
|
60
|
-
|
|
60
|
+
public getEmptyValue(): ExtractFieldDecoded<F> {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
62
|
+
return "" as unknown as ExtractFieldDecoded<F>;
|
|
61
63
|
}
|
|
62
64
|
}
|
|
@@ -4,13 +4,13 @@ import { PickFromListField } from "./pick-from-list.js";
|
|
|
4
4
|
export class ExistingSealiousValue<
|
|
5
5
|
Required extends boolean
|
|
6
6
|
> extends PickFromListField<Required> {
|
|
7
|
-
constructor(required: Required, field: Field) {
|
|
7
|
+
constructor(required: Required, field: Field<unknown>) {
|
|
8
8
|
super(required, async (ctx) => {
|
|
9
9
|
const { items } = await field.collection.list(ctx.$context).fetch();
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
11
11
|
return Object.fromEntries(
|
|
12
12
|
items.map((item) => {
|
|
13
|
-
const value = item.get(field.name);
|
|
13
|
+
const value = item.get(field.name) as unknown;
|
|
14
14
|
return [value, value];
|
|
15
15
|
})
|
|
16
16
|
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import Router from "@koa/router";
|
|
2
|
+
import getPort from "get-port";
|
|
3
|
+
import { Browser, Page } from "playwright";
|
|
4
|
+
import type { Context } from "koa";
|
|
5
|
+
import Koa from "koa";
|
|
6
|
+
import { mount } from "../../mount.js";
|
|
7
|
+
import { Form } from "../form.js";
|
|
8
|
+
import { getBrowser } from "../../utils/browser-creator.js";
|
|
9
|
+
import assert from "assert";
|
|
10
|
+
import { SimpleFormField } from "./simple-form-field.js";
|
|
11
|
+
import { SimpleInput } from "../controls/simple-input.js";
|
|
12
|
+
import { FormData } from "../form-types.js";
|
|
13
|
+
|
|
14
|
+
describe("basic field", () => {
|
|
15
|
+
describe("basic tests", async () => {
|
|
16
|
+
let server: ReturnType<Koa["listen"]>;
|
|
17
|
+
let browser: Browser;
|
|
18
|
+
let page: Page;
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
server.close();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("sends the values", async () => {
|
|
25
|
+
const port = await getPort();
|
|
26
|
+
console.log(`Using port ${port} form checkboxed-list-input.test.ts`);
|
|
27
|
+
const app = new Koa();
|
|
28
|
+
const router = new Router();
|
|
29
|
+
|
|
30
|
+
const fields = {
|
|
31
|
+
text: new SimpleFormField(true),
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let received_values: unknown;
|
|
35
|
+
|
|
36
|
+
mount(
|
|
37
|
+
router,
|
|
38
|
+
"/",
|
|
39
|
+
new (class extends Form<typeof fields, unknown> {
|
|
40
|
+
fields = fields;
|
|
41
|
+
controls = [new SimpleInput(fields.text)];
|
|
42
|
+
|
|
43
|
+
async onSubmit(ctx: Context, data: FormData) {
|
|
44
|
+
received_values = await this.getParsedValues(ctx);
|
|
45
|
+
const { parsed: email } = await this.fields.text.getValue(
|
|
46
|
+
ctx,
|
|
47
|
+
data.raw_values
|
|
48
|
+
);
|
|
49
|
+
email?.padStart(2, "0"); // if the typechecks are ok, this will not throw
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async canAccess(_: Context) {
|
|
53
|
+
return { canAccess: true, message: "" };
|
|
54
|
+
}
|
|
55
|
+
})(),
|
|
56
|
+
true
|
|
57
|
+
);
|
|
58
|
+
app.use(router.routes()).use(router.allowedMethods());
|
|
59
|
+
server = app.listen(port);
|
|
60
|
+
|
|
61
|
+
browser = await getBrowser();
|
|
62
|
+
const context = await browser.newContext();
|
|
63
|
+
page = await context.newPage();
|
|
64
|
+
await page.goto(`http://localhost:${port}`);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -4,7 +4,7 @@ import { FormDataValue } from "../form-types.js";
|
|
|
4
4
|
import { FormField } from "./field.js";
|
|
5
5
|
|
|
6
6
|
export class StructuredArrayField<
|
|
7
|
-
Fields extends Record<string, Field
|
|
7
|
+
Fields extends Record<string, Field<unknown>>
|
|
8
8
|
> extends FormField<
|
|
9
9
|
true,
|
|
10
10
|
FieldTypes.ArrayStorageInput<FieldsetOutput<Fields>>
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { Field } from "sealious";
|
|
2
2
|
import { FlatTemplatable } from "tempstream";
|
|
3
3
|
|
|
4
|
-
export type ListFilterRender = (
|
|
4
|
+
export type ListFilterRender = (
|
|
5
|
+
value: string,
|
|
6
|
+
field: Field<any>
|
|
7
|
+
) => FlatTemplatable;
|
|
5
8
|
|
|
6
|
-
export const BooleanListFilter = (value: string, field: Field) => {
|
|
9
|
+
export const BooleanListFilter = (value: string, field: Field<any>) => {
|
|
7
10
|
return /* HTML */ `<label>
|
|
8
11
|
${field.name}
|
|
9
12
|
<select name="filter[${field.name}]" autocomplete="off">
|
|
@@ -28,7 +31,7 @@ export const BooleanListFilter = (value: string, field: Field) => {
|
|
|
28
31
|
</label>`;
|
|
29
32
|
};
|
|
30
33
|
|
|
31
|
-
export const SimpleTextFilter = (value: string, field: Field) => {
|
|
34
|
+
export const SimpleTextFilter = (value: string, field: Field<any>) => {
|
|
32
35
|
return /* HTML */ `<label>
|
|
33
36
|
${field.name}
|
|
34
37
|
<input
|
package/src/templates/list.ts
CHANGED
|
@@ -32,12 +32,15 @@ export const listTemplate = async (
|
|
|
32
32
|
),
|
|
33
33
|
extract_fields_from_collection(collection_name),
|
|
34
34
|
]);
|
|
35
|
+
const importPath = curryImportPath(newfilefullpath);
|
|
35
36
|
const result = `import type { Context } from "koa";
|
|
36
37
|
import type { CollectionItem } from "sealious";
|
|
37
38
|
import type { FlatTemplatable } from "tempstream";
|
|
38
39
|
import { TempstreamJSX } from "tempstream";
|
|
39
|
-
import {
|
|
40
|
-
|
|
40
|
+
import { ${uppercase_collection} } from "${importPath(
|
|
41
|
+
target_locreq.resolve("src/back/collections/collections.ts")
|
|
42
|
+
)}";
|
|
43
|
+
import html from "${importPath(target_locreq.resolve("src/back/html.ts"))}";
|
|
41
44
|
import type { ListFilterRender } from "@sealcode/sealgen";
|
|
42
45
|
import {
|
|
43
46
|
SealiousItemListPage,
|
|
@@ -45,6 +48,10 @@ import {
|
|
|
45
48
|
DefaultListFilters,
|
|
46
49
|
} from "@sealcode/sealgen";
|
|
47
50
|
import qs from "qs";
|
|
51
|
+
import type { FilePointer } from "@sealcode/file-manager";
|
|
52
|
+
import { imageRouter } from "${importPath(
|
|
53
|
+
target_locreq.resolve("src/back/image-router.ts")
|
|
54
|
+
)}";
|
|
48
55
|
|
|
49
56
|
export const actionName = "${action_name}";
|
|
50
57
|
|
|
@@ -86,6 +93,17 @@ ${collection_fields
|
|
|
86
93
|
},
|
|
87
94
|
}`;
|
|
88
95
|
}
|
|
96
|
+
if (field.type == "image") {
|
|
97
|
+
return `{
|
|
98
|
+
field: "${field.name}",
|
|
99
|
+
label: "${field.name}",
|
|
100
|
+
format: async (value: FilePointer) => {
|
|
101
|
+
return imageRouter.image(await value.getPath(), {
|
|
102
|
+
container: { width: 45, height: 45 },
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
}`;
|
|
106
|
+
}
|
|
89
107
|
return ` { field: "${field.name}", label: "${field.name}" }`;
|
|
90
108
|
})
|
|
91
109
|
.join(",\n")}
|
|
@@ -130,7 +148,7 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
130
148
|
</form>;
|
|
131
149
|
}
|
|
132
150
|
|
|
133
|
-
async renderItem(
|
|
151
|
+
async renderItem(ctx: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
134
152
|
return <tr>
|
|
135
153
|
{displayFields.map(({ field, format }) => {
|
|
136
154
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|