@sealcode/sealgen 0.15.11 → 0.15.12
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/lib/templates/list.js +22 -3
- package/package.json +1 -1
- package/src/templates/list.ts +21 -3
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
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
|