Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10352598
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/crud.ts b/src/crud.ts
index bb0422d..c914e2b 100644
--- a/src/crud.ts
+++ b/src/crud.ts
@@ -1,99 +1,99 @@
import { Context } from "koa";
import { FormField, HTMLFunc, Mountable } from "@sealcode/sealgen";
import type Router from "@koa/router";
import { Collection, CollectionItem, ExtractFieldInput } from "sealious";
import CRUDListPage, {
ListFieldDisplayInfo,
ListFieldFilterInfo,
} from "./list.js";
import CRUDCreatePage from "./create.js";
import type { FormControl } from "@sealcode/sealgen/@types/src/forms/controls/controls.js";
type CRUDArguments<C extends Collection> = {
collection: C;
nice_collection_name: string;
fields_for_filters: ListFieldFilterInfo<C>[];
fields_for_display: ListFieldDisplayInfo<C>[];
html: HTMLFunc;
list_title?: string;
create_title?: string;
create_button_text?: string;
edit_button_text?: string;
delete_button_text?: string;
back_to_list_button_text?: string;
make_delete_question?: (item: CollectionItem<C>) => string;
edit_fields: Record<string, FormField>;
edit_controls: FormControl[];
form_value_to_sealious_value: {
[field in keyof C["fields"]]?: (
data: unknown
) => ExtractFieldInput<C["fields"][field]>;
};
};
export class CRUD<C extends Collection> extends Mountable {
collection: C;
constructor(public args: CRUDArguments<C>) {
super();
this.collection = args.collection;
}
async canAccess(ctx: Context) {
const policy = this.collection.getPolicy("list");
const response = await policy.check(ctx.$context);
return {
canAccess: response == null ? true : response?.allowed || false,
message: response?.reason || "",
};
}
mount(router: Router, base_url: string) {
const {
collection,
nice_collection_name,
list_title,
create_title,
create_button_text,
edit_button_text,
delete_button_text,
back_to_list_button_text,
make_delete_question,
html,
fields_for_display,
fields_for_filters,
edit_fields,
edit_controls,
form_value_to_sealious_value,
} = this.args;
new CRUDListPage({
collection,
fields_for_filters,
fields_for_display,
html,
title: list_title || nice_collection_name,
create_url: base_url + "create/",
edit_url: (id: string) => `${base_url}edit/${id}/`,
delete_url: (id: string) => `${base_url}delete/${id}/`,
create_button_text: create_button_text || "Create",
edit_button_text: edit_button_text || "Edit",
delete_button_text: delete_button_text || "Delete",
make_delete_question: make_delete_question,
}).mount(router, base_url);
- new CRUDCreatePage({
+ const create_page = new CRUDCreatePage({
collection,
fields: edit_fields,
controls: edit_controls,
create_title:
create_title ||
"Create " + (nice_collection_name || collection.name),
html,
base_url,
back_to_list_button_text: back_to_list_button_text || "Back",
form_value_to_sealious_value,
- })
- .mount(router, base_url + "create/")
- .init();
+ });
+ create_page.mount(router, base_url + "create/");
+ create_page.init();
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Nov 2, 17:27 (14 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1030455
Default Alt Text
(3 KB)
Attached To
Mode
rCUI crud-ui
Attached
Detach File
Event Timeline
Log In to Comment