}) => {
+ console.log({ arg, opt });
+ let type = "input";
+ if (["int", "string", "text"].includes(arg.type)) {
+ if (["int"].includes(arg.type)) {
+ return createItem({
+ component: {
+ id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
+ props: {
+ name: arg.name,
+ label: formatName(arg.name),
+ type,
+ sub_type: "number",
+ child: {
+ childs: [],
+ },
+ },
+ },
+ });
+ } else {
+ return createItem({
+ component: {
+ id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
+ props: {
+ name: arg.name,
+ label: formatName(arg.name),
+ type,
+ sub_type: "text",
+ child: {
+ childs: [],
+ },
+ },
+ },
+ });
+ }
+ } else if (["timestamptz", "date"].includes(arg.type) && arg.relation) {
+ return createItem({
+ component: {
+ id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
+ props: {
+ name: arg.name,
+ label: formatName(arg.name),
+ type: "date",
+ sub_type: "datetime",
+ child: {
+ childs: [],
+ },
+ },
+ },
+ });
+ } else if (["has-many", "has-one"].includes(arg.type) && arg.relation) {
+ if(["has-one"].includes(arg.type)){
+ return createItem({
+ component: {
+ id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
+ props: {
+ name: arg.name,
+ label: formatName(arg.name),
+ type: "single-option",
+ sub_type: "dropdown",
+ rel__gen_table: arg.name,
+ rel__gen_fields: [`[${opt.value.join(",")}]`],
+ child: {
+ childs: [],
+ },
+ },
+ },
+ });
+ // return {
+ // name: "item",
+ // type: "item",
+ // component: {
+ // id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
+ // props: {
+ // name: {
+ // mode: "string",
+ // value: arg.name
+ // },
+ // label: {
+ // mode: "string",
+ // value: formatName(arg.name)
+ // },
+ // type: {
+ // mode: "string",
+ // value: "single-option"
+ // },
+ // sub_type: {
+ // mode: "string",
+ // value: "dropdown"
+ // },
+ // rel__gen_table: {
+ // mode: "string",
+ // value: arg.name
+ // },
+ // rel__gen_fields: {
+ // mode: "raw",
+ // value: `${JSON.stringify(opt.val)}`
+ // }
+ // },
+ // },
+ // };
+ }else{
+ return createItem({
+ component: {
+ id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
+ props: {
+ name: arg.name,
+ label: formatName(arg.name),
+ type: "date",
+ sub_type: "datetime",
+ child: {
+ childs: [],
+ },
+ },
+ },
+ });
+ }
+
+ } else {
+ // type not found,
+ return createItem({
+ component: {
+ id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
+ props: {
+ name: arg.name,
+ label: formatName(arg.name),
+ type,
+ sub_type: "text",
+ child: {
+ childs: [],
+ },
+ },
+ },
+ });
+ }
+};
+export const formatName = (name: string) => {
+ return (name || "")
+ .split("_")
+ .filter((e) => e.length > 1)
+ .map((e) => capitalize(e))
+ .join(" ");
+};
diff --git a/comps/md/gen/form/on_load.ts b/comps/md/gen/form/on_load.ts
new file mode 100755
index 0000000..230864d
--- /dev/null
+++ b/comps/md/gen/form/on_load.ts
@@ -0,0 +1,66 @@
+import { GFCol } from "./fields";
+
+export const on_load = ({
+ pk,
+ table,
+ select,
+ pks,
+ opt,
+}: {
+ pk: GFCol;
+ table: string;
+ select: any;
+ pks: Record
;
+ opt?: {
+ before_load: string;
+ after_load: string;
+ };
+}) => {
+ const sample: any = {};
+ for (const [k, v] of Object.entries(select) as any) {
+ if (typeof v === "object") {
+ sample[k] = {};
+
+ Object.keys(v.select).map((e) => {
+ sample[k][e] = "sample";
+ });
+ } else {
+ sample[k] = "sample";
+ }
+ }
+
+ return `\
+async (opt) => {
+ if (isEditor) return ${JSON.stringify(sample)};
+
+ let raw_id = params.id;
+ if (typeof md === 'object' && md.selected && md.pk) {
+ const pk = md.pk?.name;
+ if (md.selected[pk]) {
+ raw_id = md.selected[pk];
+ }
+ }
+
+ ${
+ opt?.before_load
+ ? opt.before_load
+ : `let id = ${pk.type === "int" ? "parseInt(raw_id)" : "raw_id"};`
+ }
+
+ let item = {};
+ if (id){
+ item = await db.${table}.findFirst({
+ where: {
+ ${pk.name}: id,
+ },
+ select: ${JSON.stringify(select, null, 2).split("\n").join("\n ")},
+ });
+
+ ${opt?.after_load ? opt?.after_load : ""}
+
+ return item;
+ } else {
+ ${opt?.after_load ? opt?.after_load : ""}
+ }
+}`;
+};
diff --git a/comps/md/gen/gen-form.ts b/comps/md/gen/gen-form.ts
new file mode 100755
index 0000000..026b5f9
--- /dev/null
+++ b/comps/md/gen/gen-form.ts
@@ -0,0 +1,75 @@
+import { createItem, parseGenField } from "lib/gen/utils";
+import get from "lodash.get";
+import { generateTableList } from "./gen-table-list";
+import { generateSelect } from "./md-select";
+import { on_load } from "./tbl-list/on_load";
+import { on_submit } from "./tbl-list/on_submit";
+import { newField } from "./form/fields";
+import { createId } from "@paralleldrive/cuid2";
+
+export const generateForm = async (
+ modify: (data: any) => void,
+ data: any,
+ item: PrasiItem,
+ commit: boolean
+) => {
+ const table = JSON.parse(data.gen_table.value);
+ console.log("halo");
+ console.log(table);
+ const raw_fields = JSON.parse(data.gen_fields.value) as (
+ | string
+ | { value: string; checked: string[] }
+ )[];
+ let pk = "";
+ console.log({ raw_fields });
+ let pks: Record = {};
+ const fields = parseGenField(raw_fields);
+ // convert ke bahasa prisma untuk select
+ const res = generateSelect(fields);
+ pk = res.pk;
+ const select = res.select as any;
+ const result: Record = {};
+ if (!pk) {
+ alert("Failed to generate! Primary Key not found. ");
+ return;
+ }
+ if (pk) {
+ console.log("masuk");
+ if (data["on_load"]) {
+ result.on_load = {
+ mode: "raw",
+ value: on_load({ pk, table, select, pks }),
+ };
+ }
+ if (data["on_submit"]) {
+ result.on_submit = {
+ mode: "raw",
+ value: on_submit({ pk, table, select, pks }),
+ };
+ }
+ result.body = data["body"];
+
+ console.log({ fields, result });
+ const childs = [];
+ for (const item of fields.filter((e) => !e.is_pk)) {
+ let value = [] as Array;
+ if(["has-one", "has-many"].includes(item.type)){
+ value = get(item, "value.checked") as any;
+ }
+ const field = newField(item, { parent_table: table, value });
+ childs.push(field);
+ }
+ if (commit) {
+ const body = item.edit.childs[0] as PrasiItem;
+ item.edit.setProp("body", {
+ mode: "jsx",
+ value: createItem({
+ childs: childs,
+ }),
+ });
+ // await item.edit.commit();
+ } else {
+
+ }
+ }
+};
diff --git a/comps/md/gen/gen-table-list.ts b/comps/md/gen/gen-table-list.ts
new file mode 100755
index 0000000..8349821
--- /dev/null
+++ b/comps/md/gen/gen-table-list.ts
@@ -0,0 +1,129 @@
+import capitalize from "lodash.capitalize";
+import { GFCol, createItem, parseGenField } from "../../../gen/utils";
+import { generateSelect } from "./md-select";
+import { on_load } from "./tbl-list/on_load";
+import { modeTableList } from "./mode-table-list";
+import get from "lodash.get";
+import set from "lodash.set";
+
+export const generateTableList = async (
+ modify: (data: any) => void,
+ data: any,
+ item: PrasiItem,
+ arg: { mode: "table" | "list" | "grid" | "auto"; id_parent?: string },
+ commit: boolean
+) => {
+ const table = JSON.parse(data.gen_table.value) as string;
+ const raw_fields = JSON.parse(data.gen_fields.value) as (
+ | string
+ | { value: string; checked: string[] }
+ )[];
+ let pk = "";
+ let pks: Record = {};
+ const fields = parseGenField(raw_fields);
+ // convert ke bahasa prisma untuk select
+ const res = generateSelect(fields);
+ pk = res.pk;
+ const select = res.select as any;
+ const result: Record = {};
+ if (arg.id_parent) {
+ select[arg.id_parent] = true;
+ }
+ if (!pk) {
+ alert("Failed to generate! Primary Key not found. ");
+ return;
+ }
+ let childs = [] as any;
+ if (pk) {
+ let sub_name = modeTableList(arg.mode);
+ let rows = Array.isArray(get(data, "child.content.childs"))
+ ? get(data, "child.content.childs")
+ : Array.isArray(get(data, "child.childs"))
+ ? get(data, "child.childs")
+ : [];
+
+ rows = rows.filter((e: PrasiItem) => e.name !== sub_name);
+ childs = childs.concat(rows);
+
+ if (data["on_load"]) {
+ result.on_load = {
+ mode: "raw",
+ value: on_load({ pk, table, select, pks }),
+ };
+ }
+ let first = true;
+
+ const child_sub_name = createItem({
+ name: sub_name,
+ childs: fields
+ .map((e, idx) => {
+ if (idx >= 1 && arg.mode === "list") {
+ return;
+ }
+ if (e.is_pk && arg.mode === "table") return;
+ let tree_depth = "";
+ let tree_depth_built = "";
+ if (first) {
+ tree_depth = `tree_depth={col.depth}`;
+ tree_depth_built = `tree_depth:col.depth`;
+ first = false;
+ }
+ return {
+ component: {
+ id: "297023a4-d552-464a-971d-f40dcd940b77",
+ props: {
+ name: e.name,
+ title: formatName(e.name),
+ child: createItem({
+ childs: [
+ createItem({
+ name: "cell",
+ padding: {
+ l: 8,
+ b: 0,
+ t: 0,
+ r: 8,
+ },
+ adv: {
+ js: `\
+
+
+
`,
+ jsBuilt: `\
+render(React.createElement("div", Object.assign({}, props, { className: cx(props.className, "") }),React.createElement(FormatValue, { value: col.value, name: col.name, gen_fields: gen_fields, ${tree_depth_built} })));
+ `,
+ },
+ }),
+ ],
+ }),
+ },
+ },
+ };
+ })
+ .filter((e) => e) as any,
+ });
+ childs.push(child_sub_name);
+
+ if (commit) {
+ Object.keys(result).map((e) => {
+ item.edit.setProp(e, result[e]);
+ });
+ console.log({ childs });
+ item.edit.setChilds(childs);
+ await item.edit.commit();
+ } else {
+ set(data, "child.value.childs", childs);
+ Object.keys(result).map((e) => {
+ set(data, e, result[e]);
+ });
+ }
+ }
+};
+
+const formatName = (name: string) => {
+ return name
+ .split("_")
+ .filter((e) => e.length > 1)
+ .map((e) => capitalize(e))
+ .join(" ");
+};
diff --git a/comps/md/gen/md-form.ts b/comps/md/gen/md-form.ts
new file mode 100755
index 0000000..2ffb5fe
--- /dev/null
+++ b/comps/md/gen/md-form.ts
@@ -0,0 +1,122 @@
+import { createItem } from "lib/gen/utils";
+import get from "lodash.get";
+import { generateTableList } from "./gen-table-list";
+
+export const generateMDForm = async (
+ arg: { item: PrasiItem; table: string; fields: any },
+ data: any,
+ commit: boolean
+) => {
+ const item = arg.item;
+ const tab_master = item.edit.childs[0].edit.childs.find(
+ (e) => get(e, "component.id") === "c68415ca-dac5-44fe-aeb6-936caf8cc491"
+ );
+ const props: Record = {
+ gen_table: {
+ mode: "string",
+ value: arg.table,
+ },
+ name: {
+ mode: "string",
+ value: arg.table,
+ },
+ generate: {
+ mode: "string",
+ value: "y",
+ },
+ on_load: {
+ mode: "string",
+ value: "",
+ },
+ row_click: {
+ mode: "raw",
+ value: `\
+({ row, rows, idx, event }: OnRowClick) => {
+md.selected = row;
+md.internal.action_should_refresh = true;
+md.params.apply();
+md.render();
+};
+
+type OnRowClick = {
+row: any;
+rows: any[];
+idx: any;
+event: React.MouseEvent;
+}
+`,
+ },
+ selected: {
+ mode: "raw",
+ value: `\
+({ row, rows, idx }: SelectedRow) => {
+try {
+if (typeof md === "object") {
+if (Array.isArray(md.selected)) {
+if (md.selected.length) {
+ let select = md.selected.find((e) => e === row)
+ if(select) return true
+}
+} else {
+if (md.selected === row) {
+ return true;
+}
+}
+}
+} catch (e) {
+
+}
+return false;
+};
+
+type SelectedRow = {
+row: any;
+rows: any[];
+idx: any;
+}`,
+ },
+ gen_fields: {
+ mode: "raw",
+ value: `${JSON.stringify(arg.fields)}`,
+ },
+ child: {
+ mode: "jsx",
+ value: createItem({
+ name: "halo",
+ childs: [],
+ }),
+ },
+ };
+ const tablelist: any = {
+ type: "item",
+ name: "item",
+ component: {
+ id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
+ props,
+ },
+ };
+ generateTableList(
+ async (props: any) => {},
+ props,
+ tablelist,
+ { mode: "table" },
+ false
+ );
+ tab_master?.edit.setChilds([ {
+ type: "item",
+ name: "item",
+ component: {
+ id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
+ props,
+ },
+ }]);
+ console.log({
+ type: "item",
+ name: "item",
+ component: {
+ id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
+ props,
+ },
+ })
+ // console.log(tablelist);
+};
diff --git a/comps/md/gen/md-list.ts b/comps/md/gen/md-list.ts
index 094acdf..1f75aac 100755
--- a/comps/md/gen/md-list.ts
+++ b/comps/md/gen/md-list.ts
@@ -1,6 +1,6 @@
import { createItem } from "lib/gen/utils";
import get from "lodash.get";
-import { generateTableList } from "./md-table-list";
+import { generateTableList } from "./gen-table-list";
export const generateList = async (
arg: { item: PrasiItem; table: string; fields: any },
@@ -82,47 +82,32 @@ idx: any;
child: {
mode: "jsx",
value: createItem({
- name: "halo"
- })
- }
+ name: "halo",
+ childs: [],
+ }),
+ },
};
- // console.log(true);
- console.log({ tab_master });
- const tablelist = tab_master?.childs[0];
-// generateTableList(
-// async (props: any) => {},
-// props,
-// tablelist,
-// { mode: "table" },
-// false
-// );
- // // console.log({modify: async (props: any) => {}, data, item, arg: { mode: "table" }});
- // const tablelist: PrasiItem= get(item,"edit.childs[0].edit.childs[0].edit.childs[0]");
- // const data_tbl = get(tablelist, "component.props")
- // console.log({tablelist, data_tbl})
- // if(typeof tab_master === "object"){
- // // const master_child: PrasiItem= tab_master;
- // // const prop_tablelist = get(tablelist, "component.props")
- // // console.log({tablelist})
- // //
- // }
-
- // tab_master?.edit.setChilds([
- // {
- // type: "item",
- // name: "item",
- // component: {
- // id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
- // props,
- // },
- // },
- // ]);
- console.log({
+ const tablelist: any = {
type: "item",
name: "item",
component: {
id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
props,
},
- })
+ };
+ generateTableList(
+ async (props: any) => {},
+ props,
+ tablelist,
+ { mode: "table" },
+ false
+ );
+ tab_master?.edit.setChilds([ {
+ type: "item",
+ name: "item",
+ component: {
+ id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
+ props,
+ },
+ }]);
};
diff --git a/comps/md/gen/md-table-list.ts b/comps/md/gen/md-table-list.ts
deleted file mode 100755
index 34f3ae1..0000000
--- a/comps/md/gen/md-table-list.ts
+++ /dev/null
@@ -1,241 +0,0 @@
-import capitalize from "lodash.capitalize";
-import { GFCol, createItem, parseGenField } from "../../../gen/utils";
-import { generateSelect } from "./md-select";
-import { on_load } from "./tbl-list/on_load";
-import { modeTableList } from "./mode-table-list";
-import get from "lodash.get";
-import set from "lodash.set";
-
-export const generateTableList = async (
- modify: (data: any) => void,
- data: any,
- item: PrasiItem,
- arg: { mode: "table" | "list" | "grid" | "auto"; id_parent?: string },
- commit: boolean
-) => {
-
- item.edit.setChilds([
- {
- type: "item",
- name: "1",
- },
- {
- type: "item",
- name: "2",
- },
- ]);
- await item.edit.commit();
-// console.log({ data, item, arg });
-// const table = data.gen_table.value as string;
-// const raw_fields = JSON.parse(data.gen_fields.value) as (
-// | string
-// | { value: string; checked: string[] }
-// )[];
-// let pk = "";
-// let pks: Record = {};
-// const fields = parseGenField(raw_fields);
-// // const result = {} as any;
-// // generate value dari raw_field array string convert ke value selected prisma
-// const res = generateSelect(fields);
-// pk = res.pk;
-// const select = res.select as any;
-// const result: Record = {};
-// if (arg.id_parent) {
-// select[arg.id_parent] = true;
-// }
-// if (!pk) {
-// alert("Failed to generate! Primary Key not found. ");
-// return;
-// }
-// let childs = [] as any;
-// if (pk) {
-// let sub_name = modeTableList(arg.mode);
-// let rows = Array.isArray(get(data, "child.content.childs"))
-// ? get(data, "child.content.childs")
-// : Array.isArray(get(data, "child.childs"))
-// ? get(data, "child.childs")
-// : [];
-
-// rows = rows.filter((e: PrasiItem) => e.name !== sub_name);
-// childs = childs.concat(rows);
-
-// if (data["on_load"]) {
-// result.on_load = {
-// mode: "raw",
-// value: on_load({ pk, table, select, pks }),
-// };
-// }
-// let first = true;
-
-// const child_sub_name = createItem({
-// name: sub_name,
-// childs: fields
-// .map((e, idx) => {
-// if (idx >= 1 && arg.mode === "list") {
-// return;
-// }
-// if (e.is_pk && arg.mode === "table") return;
-// let tree_depth = "";
-// let tree_depth_built = "";
-// if (first) {
-// tree_depth = `tree_depth={col.depth}`;
-// tree_depth_built = `tree_depth:col.depth`;
-// first = false;
-// }
-// return {
-// component: {
-// id: "297023a4-d552-464a-971d-f40dcd940b77",
-// props: {
-// name: e.name,
-// title: formatName(e.name),
-// child: createItem({
-// childs: [
-// createItem({
-// name: "cell",
-// padding: {
-// l: 8,
-// b: 0,
-// t: 0,
-// r: 8,
-// },
-// adv: {
-// js: `\
-//
-//
-//
`,
-// jsBuilt: `\
-// render(React.createElement("div", Object.assign({}, props, { className: cx(props.className, "") }),React.createElement(FormatValue, { value: col.value, name: col.name, gen_fields: gen_fields, ${tree_depth_built} })));
-// `,
-// },
-// }),
-// ],
-// }),
-// },
-// },
-// };
-// })
-// .filter((e) => e) as any,
-// });
-// childs.push(child_sub_name);
-
-// // result.child = {
-// // mode: "jsx",
-// // value: createItem({ name: "child", childs: [child] }),
-// // };
-// // item.edit.setChilds([child]);
-
-// if (commit) {
-// Object.keys(result).map((e) => {
-// item.edit.setProp(e, result[e]);
-// });
-// console.log({ childs });
-// item.edit.setChilds([
-// {
-// name: sub_name,
-// },
-// {
-// name: "123",
-// },
-// ]);
-// await item.edit.commit();
-// } else {
-// set(item, "childs", childs);
-// Object.keys(result).map((e) => {
-// set(data, e, result[e]);
-// });
-// }
-
-// console.log({ res, item });
-// console.log({ data });
-// console.log({ result });
-// }
-// return;
- // if (pk) {
- // console.log("pk");
- // const code = {} as any;
- // if (data["on_load"]) {
- // result["on_load"] = data["on_load"];
- // result["on_load"].value = on_load({ pk, table, select, pks });
- // delete result["on_load"].valueBuilt;
- // code.on_load = result["on_load"].value;
- // }
- // let sub_name = "fields";
- // switch (arg.mode) {
- // case "table":
- // sub_name = "tbl-col";
- // break;
- // case "list":
- // sub_name = "md-list";
- // break;
- // }
- // let first = true;
- // console.log(sub_name);
- // const child = {
- // name: sub_name,
- // childs: fields
- // .map((e, idx) => {
- // if (idx >= 1 && arg.mode === "list") {
- // return;
- // }
- // if (e.is_pk && arg.mode === "table") return;
- // let tree_depth = "";
- // let tree_depth_built = "";
- // if (first) {
- // tree_depth = `tree_depth={col.depth}`;
- // tree_depth_built = `tree_depth:col.depth`;
- // first = false;
- // }
- // return {
- // component: {
- // id: "297023a4-d552-464a-971d-f40dcd940b77",
- // props: {
- // name: {
- // mode: "string",
- // value: e.name
- // },
- // title: {
- // mode: "string",
- // value: formatName(e.name)
- // },
- // child: createItem({
- // childs: [
- // createItem({
- // name: "cell",
- // padding: {
- // l: 8,
- // b: 0,
- // t: 0,
- // r: 8,
- // },
- // adv: {
- // js: `\
- //
- //
- //
`,
- // jsBuilt: `\
- // render(React.createElement("div", Object.assign({}, props, { className: cx(props.className, "") }),React.createElement(FormatValue, { value: col.value, name: col.name, gen_fields: gen_fields, ${tree_depth_built} })));
- // `,
- // },
- // }),
- // ],
- // }),
- // },
- // },
- // };
- // })
- // .filter((e) => e) as any,
- // };
- // data.child.value = child;
- // result["child"] = data.child
- // }
- // modify(result);
- // console.log({ child: data["child"] });
-};
-
-const formatName = (name: string) => {
- return name
- .split("_")
- .filter((e) => e.length > 1)
- .map((e) => capitalize(e))
- .join(" ");
-};
diff --git a/comps/md/gen/tbl-list/on_submit.ts b/comps/md/gen/tbl-list/on_submit.ts
new file mode 100755
index 0000000..d0715aa
--- /dev/null
+++ b/comps/md/gen/tbl-list/on_submit.ts
@@ -0,0 +1,85 @@
+import { GFCol } from "lib/gen/utils";
+
+
+export const on_submit = ({
+ pk,
+ table,
+ select,
+ pks,
+}: {
+ pk: string;
+ table: string;
+ select: any;
+ pks: Record;
+}) => {
+ const id = pk;
+
+ return `\
+async ({ form, error }: IForm) => {
+ if (typeof form !== "object") return false;
+ if (typeof error === "object" && Object.keys(error).length > 0) return false;
+
+ let original_actions = [];
+ if (typeof md === "object") {
+ original_actions = md.actions;
+ md.actions = [{ label: <>...> }];
+ md.render();
+ }
+
+ let result = false;
+ try {
+ const data = { ...form };
+ delete data.${id};
+
+ if (data) {
+ const pks = ${JSON.stringify(pks)};
+ for (const [k, v] of Object.entries(pks)) {
+ if (typeof data[k] === 'object') {
+ if (data[k] === null) {
+ data[k] = {
+ disconnect: true
+ }
+ }
+ if (data[k][v]) {
+ data[k] = {
+ connect: {
+ [v]: data[k][v]
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (form.${id}) {
+ await db.${table}.update({
+ where: {
+ ${id}: form.${id},
+ },
+ data,
+ });
+ } else {
+ const res = await db.${table}.create({
+ data,
+ select: { ${id}: true },
+ });
+ if (res) form.${id} = res.${id};
+ }
+
+ result = true;
+ } catch (e) {
+ console.error(e);
+ result = false;
+ }
+
+ if (typeof md === "object") {
+ md.actions = original_actions;
+ md.selected = null;
+ md.render();
+ }
+
+ return result;
+};
+
+type IForm = { form: any; error: Record }`;
+};
diff --git a/comps/md/parts/MDMaster.tsx b/comps/md/parts/MDMaster.tsx
index aea3195..db807ba 100755
--- a/comps/md/parts/MDMaster.tsx
+++ b/comps/md/parts/MDMaster.tsx
@@ -38,7 +38,18 @@ export const MDMaster: FC<{ md: MDLocal; mdr: MDRef }> = ({ md, mdr }) => {
return (
<>
{md.props.show_head === "only-master" && }
- {mdr.master}
+ div {
+ flex: 1;
+ }
+ `,
+ "c-flex c-flex-1"
+ )}
+ >
+
{mdr.master}
+
>
);
};
diff --git a/comps/md/utils/editor-init.tsx b/comps/md/utils/editor-init.tsx
index 7b08e1a..7d49119 100755
--- a/comps/md/utils/editor-init.tsx
+++ b/comps/md/utils/editor-init.tsx
@@ -19,7 +19,6 @@ export const editorMDInit = (md: MDLocal, mdr: MDRef, arg: MDProps) => {
md.props.gen_table = gen_table;
md.props.on_init = on_init;
- console.log(get(mdr, "master.edit.childs.0"));
if (!mdr.master || (mdr.master && !get(mdr, "master.edit.childs.0.childs.length"))) {
md.breadcrumb = [
{
diff --git a/exports.ts b/exports.ts
index c65f8ea..973e8be 100755
--- a/exports.ts
+++ b/exports.ts
@@ -34,13 +34,18 @@ export const ExportExcel = lazify(
/** Filter */
export const MasterFilter = lazify(
- async () => (await import("@/comps/filter/Filter")).MasterFilter
+ async () => (await import("@/comps/filter/MasterFilter")).MasterFilter
+);
+
+export const FilterField = lazify(
+ async () => (await import("@/comps/filter/FilterField")).FilterField
);
/** Generator */
export { generateMasterDetail } from "lib/comps/md/gen/md-gen";
/** ETC */
+export { filterWhere } from "@/comps/filter/utils/filter-where";
export {
FMLocal,
FieldTypeCustom,
@@ -54,7 +59,8 @@ export { TableListType } from "lib/comps/list/utils/typings";
export { Button, FloatButton } from "@/comps/ui/button";
export { prasi_gen } from "@/gen/prasi_gen";
export { password } from "@/utils/password";
-export {generateTableList} from "@/comps/md/gen/md-table-list"
+export { generateTableList } from "@/comps/md/gen/gen-table-list";
+export { generateForm } from "@/comps/md/gen/gen-form";
/** Session */
export {
diff --git a/gen/utils.ts b/gen/utils.ts
index 0edf73d..c431e83 100755
--- a/gen/utils.ts
+++ b/gen/utils.ts
@@ -10,11 +10,13 @@ export const parseGenField = (fields: PropOptRaw) => {
if (typeof f === "string") {
try {
const field = JSON.parse(f);
+ field["value"] = f
result.push(field);
} catch (e) {}
} else {
const field = JSON.parse(f.value);
field.relation.fields = parseGenField(f.checked);
+ field["value"] = f
result.push(field);
}
}
@@ -46,6 +48,7 @@ export type GFCol = {
to: { table: string; fields: string[] };
fields: GFCol[];
};
+ value: Array | string;
};
export const formatName = (name: string) => {
diff --git a/preset/login/Login.tsx b/preset/login/Login.tsx
index e4424f1..c91507f 100755
--- a/preset/login/Login.tsx
+++ b/preset/login/Login.tsx
@@ -1,4 +1,5 @@
import { FC } from "react";
+import { prasi_user } from "./utils/user";
const w = window as unknown as {
prasi_home: Record;
@@ -7,11 +8,15 @@ const w = window as unknown as {
export type LGProps = {
salt: string;
url_home: Array>;
- body: any
+ body: any;
};
export const Login: FC = (props) => {
w.prasi_home = props.url_home[0];
- console.log(w.prasi_home)
+ try {
+ const home = prasi_user.prasi_home[prasi_user.user.m_role.name];
+ navigate(home);
+ } catch (e: any) {
+ }
return <>{props.body}>;
};
diff --git a/preset/login/utils/user.ts b/preset/login/utils/user.ts
index d364502..b7809ed 100755
--- a/preset/login/utils/user.ts
+++ b/preset/login/utils/user.ts
@@ -2,6 +2,8 @@ export const prasi_user = window as unknown as {
user: {
id: string;
username: string;
+ name: string;
+ fullname: string;
m_role: {
id: string;
name: string;
diff --git a/preset/menu/Layout.tsx b/preset/menu/Layout.tsx
index 2557514..3323a2f 100755
--- a/preset/menu/Layout.tsx
+++ b/preset/menu/Layout.tsx
@@ -62,12 +62,12 @@ export const Layout: FC = (props) => {
fn();
const path = getPathname();
const no_layout = props.exception;
+ loadSession("/auth/login");
if (Array.isArray(no_layout))
if (no_layout.length) {
if (no_layout.includes(path)) {
return <>{props.defaultLayout}>;
}
}
- loadSession("/dev/auth");
return <>{props.children}>;
};
diff --git a/utils/format-value.tsx b/utils/format-value.tsx
index c9b563e..08dfd13 100755
--- a/utils/format-value.tsx
+++ b/utils/format-value.tsx
@@ -22,13 +22,13 @@ export const FormatValue: FC<{
return {
...JSON.parse(e.value),
checked: e.checked.map((ex: any) => {
- if(typeof ex === "string"){
- return JSON.parse(e.value)
+ if (typeof ex === "string") {
+ return JSON.parse(e.value);
}
- try{
+ try {
return JSON.parse(ex["value"]);
- }catch(em){
- return null
+ } catch (em) {
+ return null;
}
}),
};
@@ -42,19 +42,20 @@ export const FormatValue: FC<{
if (typeof value === "object" && value) {
const rel = fields?.find((e) => e.name === name);
if (rel && rel.checked) {
- const result = rel.checked
- .filter((e) => !e.is_pk)
- .map((e) => {
- return value[e.name];
- })
- .join(" - ");
+
+ if (rel.type === "has-one") {
+ const result = [];
+ for (const [k,v] of Object.entries(value) as any ) {
+ if (!k.toLowerCase().includes('id')) result.push(v);
+ }
+ return result.join(' - ');
+ }
if (Array.isArray(value)) {
const len = value.length;
if (len === 0) return ` - `;
return `${len} item${len > 1 ? "s" : ""}`;
}
- return result;
}
return JSON.stringify(value);
diff --git a/utils/parse-gen-fields.ts b/utils/parse-gen-fields.ts
new file mode 100755
index 0000000..c9b5abb
--- /dev/null
+++ b/utils/parse-gen-fields.ts
@@ -0,0 +1,33 @@
+import { GFCol } from "lib/gen/utils";
+
+export const parseGenFields = (gen_fields: any) => {
+ const fields_map = new Map();
+ if (gen_fields) {
+ const gf = JSON.stringify(gen_fields);
+ if (!fields_map.has(gf)) {
+ fields_map.set(
+ gf,
+ gen_fields.map((e: any) => {
+ if (typeof e === "string") {
+ return JSON.parse(e);
+ } else {
+ return {
+ ...JSON.parse(e.value),
+ checked: e.checked.map((ex: any) => {
+ if (typeof ex === "string") {
+ return JSON.parse(e.value);
+ }
+ try {
+ return JSON.parse(ex["value"]);
+ } catch (em) {
+ return null;
+ }
+ }),
+ };
+ }
+ })
+ );
+ }
+ }
+ return fields_map;
+};