Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F3010981
list.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
list.ts
View Options
import
{
curryImportPath
}
from
"../utils/import-path"
;
import
prompts
=
require
(
"prompts"
);
import
{
listCollections
}
from
"../utils/list-collections"
;
export
const
listTemplate
=
async
(
action_name
:
string
,
newfilefullpath
:
string
)
:
Promise
<
string
>
=>
{
const
response
=
await
prompts
({
type
:
"autocomplete"
,
name
:
"collection"
,
message
:
"Which sealious collection do you want to list?"
,
choices
:
(
await
listCollections
()
).
map
((
collection
)
=>
({
title
:
collection
,
value
:
collection
,
})),
});
const
collection
=
response
.
collection
as
string
;
const
uppercase_collection
=
collection
[
0
].
toLocaleUpperCase
()
+
collection
.
slice
(
1
);
const
rel
=
curryImportPath
(
newfilefullpath
);
return
`import { Context } from "koa";
import { CollectionItem } from "sealious";
import { tempstream } from "tempstream";
import {
${
uppercase_collection
}
} from "
${
rel
(
"src/back/collections/collections"
)
}
";
import html from "
${
rel
(
"src/back/html.ts"
)
}
";
import { SealiousItemListPage, BaseListPageFields } from "@sealcode/sealgen";
export const actionName = "
${
action_name
}
";
const filterFields = {};
export default new (class
${
action_name
}
Page extends SealiousItemListPage<
typeof
${
uppercase_collection
}
,
typeof BaseListPageFields
> {
fields = BaseListPageFields;
filterFields = filterFields;
filterControls = [];
async render(ctx: Context) {
return html(
ctx,
"
${
uppercase_collection
}
",
tempstream/* HTML */ \`<div>
<h2>
${
uppercase_collection
}
List</h2>
<table>
<thead>
<th>id</th>
\${Object.keys(
${
uppercase_collection
}
.fields).map(
(fieldname) => \`<th>\${fieldname}</th>\`
)}
</thead>
<tbody>
\${super.render(ctx)}
</tbody>
</table>
</div>\`
);
}
async renderItem(_: Context, item: CollectionItem<typeof
${
uppercase_collection
}
>) {
return tempstream\`<tr><td>\${item.id}</td>\${Object.keys(
${
uppercase_collection
}
.fields).map(
(fieldname: keyof typeof
${
uppercase_collection
}
["fields"]) =>
tempstream\`<td>\${item.get(fieldname)}</td>\`
)}</tr>\`;
}
})(
${
uppercase_collection
}
);
`
;
};
File Metadata
Details
Attached
Mime Type
text/html
Expires
Wed, May 7, 19:50 (3 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
628611
Default Alt Text
list.ts (2 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline
Log In to Comment