remove form
This commit is contained in:
parent
01b7efbbd5
commit
b4d6609892
|
|
@ -37,7 +37,6 @@ export const generateForm = async (
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pk) {
|
if (pk) {
|
||||||
|
|
||||||
if (data["on_load"]) {
|
if (data["on_load"]) {
|
||||||
result.on_load = {
|
result.on_load = {
|
||||||
mode: "raw",
|
mode: "raw",
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
import { MDLocal } from "@/comps/md/utils/typings";
|
|
||||||
import { codeBuild } from "../master_detail/utils";
|
|
||||||
import { GenFn } from "../utils";
|
|
||||||
export const gen_action: GenFn<{ name: string; on_load: () => MDLocal }> = async (
|
|
||||||
modify,
|
|
||||||
data,
|
|
||||||
arg: { name: string, on_load: () => MDLocal }
|
|
||||||
) => {
|
|
||||||
const md = arg.on_load
|
|
||||||
console.log("halo gen")
|
|
||||||
console.log({modify, data, arg, md: md()})
|
|
||||||
// const res = await codeBuild({
|
|
||||||
// div: `\
|
|
||||||
// <>
|
|
||||||
// {md.tab.active === "${arg.name}" && (
|
|
||||||
// <div {...props} className={cx(props.className, "")}>
|
|
||||||
// {children}
|
|
||||||
// </div>
|
|
||||||
// )}
|
|
||||||
// </>
|
|
||||||
// `,
|
|
||||||
// });
|
|
||||||
};
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
import { on_load } from "lib/comps/form/gen/on_load";
|
|
||||||
import { codeBuild } from "../master_detail/utils";
|
|
||||||
import { GFCol, parseGenField } from "../utils";
|
|
||||||
import { newField } from "./new_field";
|
|
||||||
import { on_submit } from "./on_submit";
|
|
||||||
|
|
||||||
export const gen_form = async (
|
|
||||||
modify: (data: any) => void,
|
|
||||||
data: any,
|
|
||||||
is_md?: boolean
|
|
||||||
) => {
|
|
||||||
console.error("FAILED TO GENERATE: OBSOLETE FUNCTION");
|
|
||||||
// const table = JSON.parse(data.gen_table.value);
|
|
||||||
// const raw_fields = JSON.parse(data.gen_fields.value) as (
|
|
||||||
// | string
|
|
||||||
// | { value: string; checked: string[] }
|
|
||||||
// )[];
|
|
||||||
// const select = {} as any;
|
|
||||||
// let pk: null | GFCol = null;
|
|
||||||
// let pks: Record<string, string> = {};
|
|
||||||
|
|
||||||
// const fields = parseGenField(raw_fields);
|
|
||||||
// const result = {} as any;
|
|
||||||
// for (const f of fields) {
|
|
||||||
// select[f.name] = true;
|
|
||||||
// if (f.relation) {
|
|
||||||
// select[f.name] = {
|
|
||||||
// select: {},
|
|
||||||
// };
|
|
||||||
// for (const r of f.relation.fields) {
|
|
||||||
// select[f.name].select[r.name] = true;
|
|
||||||
// if (r.is_pk) {
|
|
||||||
// pks[f.name] = r.name;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (f.is_pk) {
|
|
||||||
// pk = f;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!pk) {
|
|
||||||
// alert("Failed to generate! Primary Key not found. ");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (pk) {
|
|
||||||
// const code = {} as any;
|
|
||||||
// if (data["on_load"]) {
|
|
||||||
// result["on_load"] = data["on_load"];
|
|
||||||
// result["on_load"].value = on_load({
|
|
||||||
// pk: pk.name,
|
|
||||||
// pks,
|
|
||||||
// select,
|
|
||||||
// table,
|
|
||||||
// opt: is_md ? { is_md: true } : undefined,
|
|
||||||
// });
|
|
||||||
// code.on_load = result["on_load"].value;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (data["on_submit"]) {
|
|
||||||
// result["on_submit"] = data["on_submit"];
|
|
||||||
// result["on_submit"].value = on_submit({ pk, table, select, pks });
|
|
||||||
// code.on_submit = result["on_submit"].value;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const res = await codeBuild(code);
|
|
||||||
// for (const [k, v] of Object.entries(res)) {
|
|
||||||
// result[k].valueBuilt = v[1];
|
|
||||||
// }
|
|
||||||
|
|
||||||
// result["body"] = data["body"];
|
|
||||||
// result.body.content.childs = [];
|
|
||||||
// for (const item of fields.filter((e) => !e.is_pk)) {
|
|
||||||
// result.body.content.childs.push(
|
|
||||||
// await newField(item, { parent_table: table })
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// modify(result);
|
|
||||||
};
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
import { createId } from "@paralleldrive/cuid2";
|
|
||||||
import { gen_relation } from "../gen_relation/gen_relation";
|
|
||||||
import { GFCol, createItem, formatName } from "../utils";
|
|
||||||
|
|
||||||
export const newItem = (component: {
|
|
||||||
id: string;
|
|
||||||
props: Record<string, string>;
|
|
||||||
}) => {
|
|
||||||
return {
|
|
||||||
id: createId(),
|
|
||||||
name: "new_item",
|
|
||||||
type: "item",
|
|
||||||
dim: { w: "full", h: "full" },
|
|
||||||
childs: [],
|
|
||||||
adv: {
|
|
||||||
css: "",
|
|
||||||
},
|
|
||||||
component: component,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export type NewFieldArg = {
|
|
||||||
name: string;
|
|
||||||
label: string;
|
|
||||||
type: "relation" | "text";
|
|
||||||
required: boolean;
|
|
||||||
relation?: {
|
|
||||||
table: string;
|
|
||||||
fields: string[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const newField = async (arg: GFCol, opt: { parent_table: string }) => {
|
|
||||||
const childs = [];
|
|
||||||
|
|
||||||
let type = "text";
|
|
||||||
if (["int", "string", "text"].includes(arg.type)) {
|
|
||||||
childs.push(
|
|
||||||
createItem({
|
|
||||||
component: {
|
|
||||||
id: "ca7ac237-8f22-4492-bb9d-4b715b1f5c25",
|
|
||||||
props: {
|
|
||||||
type: arg.type === "int" ? "number" : "text",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else if (["has-many", "has-one"].includes(arg.type) && arg.relation) {
|
|
||||||
type = "relation";
|
|
||||||
const value = JSON.stringify(
|
|
||||||
arg.relation.fields.map((e) => {
|
|
||||||
if (e.relation) {
|
|
||||||
const rel = { ...e };
|
|
||||||
const fields = e.relation.fields;
|
|
||||||
delete (e as any).relation.fields;
|
|
||||||
return {
|
|
||||||
value: JSON.stringify(e),
|
|
||||||
checked: fields.map((e) => JSON.stringify(e)),
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return JSON.stringify(e);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const item = createItem({
|
|
||||||
component: {
|
|
||||||
id: "69263ca0-61a1-4899-ad5f-059ac12b94d1",
|
|
||||||
props: {
|
|
||||||
type: arg.type,
|
|
||||||
on_load: [
|
|
||||||
`async () => {
|
|
||||||
return { items: [], pk: "" };
|
|
||||||
}`,
|
|
||||||
],
|
|
||||||
label: [`() => {}`],
|
|
||||||
gen_table: arg.relation.to.table,
|
|
||||||
gen_fields: [value, value],
|
|
||||||
has_many_from:
|
|
||||||
arg.type === "has-many" ? arg.relation.from.table : undefined,
|
|
||||||
has_many_list: arg.type === "has-many" ? [`null`] : undefined,
|
|
||||||
child: {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
await gen_relation(() => {}, item.component.props, {
|
|
||||||
id_parent: "",
|
|
||||||
type: arg.type as any,
|
|
||||||
parent_table: opt.parent_table,
|
|
||||||
});
|
|
||||||
childs.push(item);
|
|
||||||
} else {
|
|
||||||
// type not found,
|
|
||||||
console.warn("Type not found", type);
|
|
||||||
type = "text";
|
|
||||||
childs.push(
|
|
||||||
createItem({
|
|
||||||
component: {
|
|
||||||
id: "ca7ac237-8f22-4492-bb9d-4b715b1f5c25",
|
|
||||||
props: {
|
|
||||||
type: "text",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const item = createItem({
|
|
||||||
component: {
|
|
||||||
id: "32550d01-42a3-4b15-a04a-2c2d5c3c8e67",
|
|
||||||
props: {
|
|
||||||
name: arg.name,
|
|
||||||
label: formatName(arg.name),
|
|
||||||
type,
|
|
||||||
child: {
|
|
||||||
childs,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return item;
|
|
||||||
};
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
import { GFCol } from "../utils";
|
|
||||||
|
|
||||||
export const on_submit = ({
|
|
||||||
pk,
|
|
||||||
table,
|
|
||||||
select,
|
|
||||||
pks,
|
|
||||||
}: {
|
|
||||||
pk: GFCol;
|
|
||||||
table: string;
|
|
||||||
select: any;
|
|
||||||
pks: Record<string, string>;
|
|
||||||
}) => {
|
|
||||||
const id = pk.name;
|
|
||||||
|
|
||||||
return `\
|
|
||||||
async ({ form, error }: IForm) => {
|
|
||||||
if (isEditor) return false;
|
|
||||||
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<string, string> }`;
|
|
||||||
};
|
|
||||||
|
|
@ -1,225 +0,0 @@
|
||||||
import { codeBuild } from "../master_detail/utils";
|
|
||||||
import { gen_prop_fields } from "../prop/gen_prop_fields";
|
|
||||||
import { GFCol, parseGenField } from "../utils";
|
|
||||||
import { newField } from "./new_field";
|
|
||||||
import { on_load } from "./on_load";
|
|
||||||
|
|
||||||
export const gen_relation = async (
|
|
||||||
modify: (data: any) => void,
|
|
||||||
data: any,
|
|
||||||
arg: { id_parent: string; type: "has-many" | "has-one"; parent_table: string }
|
|
||||||
) => {
|
|
||||||
const table = JSON.parse(data.gen_table.value);
|
|
||||||
const raw_fields = JSON.parse(data.gen_fields.value) as (
|
|
||||||
| string
|
|
||||||
| { value: string; checked: string[] }
|
|
||||||
)[];
|
|
||||||
|
|
||||||
const fields = parseGenField(raw_fields);
|
|
||||||
if (arg.type === "has-one") {
|
|
||||||
await genHasOne(modify, data, arg, { table, fields });
|
|
||||||
} else {
|
|
||||||
await genHasMany(modify, data, arg, { table, fields });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const genHasMany = async (
|
|
||||||
modify: (data: any) => void,
|
|
||||||
data: any,
|
|
||||||
arg: {
|
|
||||||
id_parent: string;
|
|
||||||
type: "has-many" | "has-one";
|
|
||||||
parent_table: string;
|
|
||||||
},
|
|
||||||
pass: {
|
|
||||||
table: string;
|
|
||||||
fields: GFCol[];
|
|
||||||
}
|
|
||||||
) => {
|
|
||||||
const { table, fields } = pass;
|
|
||||||
|
|
||||||
let pk: null | GFCol = null;
|
|
||||||
let pks: Record<string, string> = {};
|
|
||||||
const select = {} as any;
|
|
||||||
const result = {} as any;
|
|
||||||
|
|
||||||
for (const f of fields) {
|
|
||||||
select[f.name] = true;
|
|
||||||
if (f.relation) {
|
|
||||||
select[f.name] = {
|
|
||||||
select: {},
|
|
||||||
};
|
|
||||||
for (const r of f.relation.fields) {
|
|
||||||
select[f.name].select[r.name] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f.is_pk) {
|
|
||||||
pk = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg && arg.id_parent) {
|
|
||||||
select[arg.id_parent] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pk) {
|
|
||||||
alert("Failed to generate! Primary Key not found. ");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pk) {
|
|
||||||
const code = {} as any;
|
|
||||||
if (data["on_load"]) {
|
|
||||||
result["on_load"] = data["on_load"];
|
|
||||||
result["on_load"].value = on_load({
|
|
||||||
pk,
|
|
||||||
pks,
|
|
||||||
select,
|
|
||||||
table,
|
|
||||||
id_parent: arg.id_parent,
|
|
||||||
});
|
|
||||||
code.on_load = result["on_load"].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data["has_many_from"] && arg.parent_table) {
|
|
||||||
result["has_many_from"] = data["has_many_from"];
|
|
||||||
result["has_many_from"].value = `"${arg.parent_table}"`;
|
|
||||||
result["has_many_from"].valueBuilt = `"${arg.parent_table}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data["has_many_list"] && arg.parent_table) {
|
|
||||||
const defs = parseGenField(
|
|
||||||
(await gen_prop_fields(arg.parent_table)).map((e: any) => e.value)
|
|
||||||
);
|
|
||||||
const pk = defs.find((e) => e.is_pk);
|
|
||||||
if (pk) {
|
|
||||||
result["has_many_list"] = data["has_many_list"];
|
|
||||||
result["has_many_list"].value = `\
|
|
||||||
async () => {
|
|
||||||
const result: { value: string; label: string }[] = [];
|
|
||||||
const list = await db.${arg.parent_table}.findMany({
|
|
||||||
select: {
|
|
||||||
${pk?.name}: true,
|
|
||||||
},
|
|
||||||
where: { },
|
|
||||||
});
|
|
||||||
return result;
|
|
||||||
}`;
|
|
||||||
code.has_many_list = result["has_many_list"].value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data["label"]) {
|
|
||||||
result["label"] = data["label"];
|
|
||||||
result["label"].value = `\
|
|
||||||
(item:any, pk:string) => {
|
|
||||||
return \`${Object.entries(select)
|
|
||||||
.filter(([k, v]) => {
|
|
||||||
if (typeof v !== "object" && k !== pk?.name && k !== arg.id_parent) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(([name]) => {
|
|
||||||
return `\${item.${name}}`;
|
|
||||||
})
|
|
||||||
.join(" ")}\`
|
|
||||||
}`;
|
|
||||||
code.on_load = result["on_load"].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await codeBuild(code);
|
|
||||||
for (const [k, v] of Object.entries(res)) {
|
|
||||||
result[k].valueBuilt = v[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
result["child"] = data["child"];
|
|
||||||
result.child.content.childs = fields.filter((e) => !e.is_pk).map(newField);
|
|
||||||
}
|
|
||||||
|
|
||||||
modify(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
const genHasOne = async (
|
|
||||||
modify: (data: any) => void,
|
|
||||||
data: any,
|
|
||||||
arg: { id_parent: string; type: "has-many" | "has-one" },
|
|
||||||
pass: {
|
|
||||||
table: string;
|
|
||||||
fields: GFCol[];
|
|
||||||
}
|
|
||||||
) => {
|
|
||||||
const { table, fields } = pass;
|
|
||||||
|
|
||||||
let pk: null | GFCol = null;
|
|
||||||
let pks: Record<string, string> = {};
|
|
||||||
const select = {} as any;
|
|
||||||
const result = {} as any;
|
|
||||||
|
|
||||||
for (const f of fields) {
|
|
||||||
select[f.name] = true;
|
|
||||||
if (f.relation) {
|
|
||||||
select[f.name] = {
|
|
||||||
select: {},
|
|
||||||
};
|
|
||||||
for (const r of f.relation.fields) {
|
|
||||||
select[f.name].select[r.name] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f.is_pk) {
|
|
||||||
pk = f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg && arg.id_parent) {
|
|
||||||
select[arg.id_parent] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pk) {
|
|
||||||
alert("Failed to generate! Primary Key not found. ");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pk) {
|
|
||||||
const code = {} as any;
|
|
||||||
if (data["on_load"]) {
|
|
||||||
result["on_load"] = data["on_load"];
|
|
||||||
result["on_load"].value = on_load({
|
|
||||||
pk,
|
|
||||||
pks,
|
|
||||||
select,
|
|
||||||
table,
|
|
||||||
id_parent: arg.id_parent,
|
|
||||||
});
|
|
||||||
code.on_load = result["on_load"].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data["label"]) {
|
|
||||||
result["label"] = data["label"];
|
|
||||||
result["label"].value = `\
|
|
||||||
(item:any, pk:string) => {
|
|
||||||
return \`${Object.entries(select)
|
|
||||||
.filter(([k, v]) => {
|
|
||||||
if (typeof v !== "object" && k !== pk?.name && k !== arg.id_parent) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(([name]) => {
|
|
||||||
return `\${item.${name}}`;
|
|
||||||
})
|
|
||||||
.join(" ")}\`
|
|
||||||
}`;
|
|
||||||
code.on_load = result["on_load"].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await codeBuild(code);
|
|
||||||
for (const [k, v] of Object.entries(res)) {
|
|
||||||
result[k].valueBuilt = v[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
result["child"] = data["child"];
|
|
||||||
result.child.content.childs = fields.filter((e) => !e.is_pk).map(newField);
|
|
||||||
}
|
|
||||||
modify(result);
|
|
||||||
};
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
import { createId } from "@paralleldrive/cuid2";
|
|
||||||
import { GFCol, createItem, formatName } from "../utils";
|
|
||||||
export const newItem = (component: {
|
|
||||||
id: string;
|
|
||||||
props: Record<string, string>;
|
|
||||||
}) => {
|
|
||||||
return {
|
|
||||||
id: createId(),
|
|
||||||
name: "new_item",
|
|
||||||
type: "item",
|
|
||||||
dim: { w: "full", h: "full" },
|
|
||||||
childs: [],
|
|
||||||
adv: {
|
|
||||||
css: "",
|
|
||||||
},
|
|
||||||
component: component,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export type NewFieldArg = {
|
|
||||||
name: string;
|
|
||||||
label: string;
|
|
||||||
type: "relation" | "text";
|
|
||||||
required: boolean;
|
|
||||||
relation?: {
|
|
||||||
table: string;
|
|
||||||
fields: string[];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const newField = (arg: GFCol, idx: number) => {
|
|
||||||
let result = `{item["${arg.name}"]}`;
|
|
||||||
let result_built = `render(React.createElement("div", Object.assign({}, props, { className: cx(props.className, "") }), item["${arg.name}"]));`;
|
|
||||||
if (idx === 0) {
|
|
||||||
result = `<FormatValue value={item["${arg.name}"]} tree_depth={item.__depth} />`;
|
|
||||||
result_built = `render(React.createElement("div", Object.assign({}, props, { className: cx(props.className, "") }),
|
|
||||||
React.createElement(FormatValue, { value: item["${arg.name}"], tree_depth: item.__depth })));`;
|
|
||||||
}
|
|
||||||
return createItem({
|
|
||||||
name: arg.name,
|
|
||||||
adv: {
|
|
||||||
js: `\
|
|
||||||
<div {...props} className={cx(props.className, "")}>
|
|
||||||
${result}
|
|
||||||
</div>`,
|
|
||||||
jsBuilt: result_built,
|
|
||||||
},
|
|
||||||
dim: {
|
|
||||||
h: "full",
|
|
||||||
w: "fit",
|
|
||||||
},
|
|
||||||
padding: {
|
|
||||||
l: 0,
|
|
||||||
b: 0,
|
|
||||||
t: 0,
|
|
||||||
r: 5,
|
|
||||||
},
|
|
||||||
layout: {
|
|
||||||
dir: "row",
|
|
||||||
align: "left",
|
|
||||||
gap: 0,
|
|
||||||
wrap: "flex-nowrap",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
import { GFCol } from "../utils";
|
|
||||||
|
|
||||||
export const on_load = ({
|
|
||||||
pk,
|
|
||||||
table,
|
|
||||||
select,
|
|
||||||
pks,
|
|
||||||
opt,
|
|
||||||
id_parent,
|
|
||||||
}: {
|
|
||||||
pk: GFCol;
|
|
||||||
table: string;
|
|
||||||
select: any;
|
|
||||||
pks: Record<string, string>;
|
|
||||||
opt?: {
|
|
||||||
before_load: string;
|
|
||||||
after_load: string;
|
|
||||||
};
|
|
||||||
id_parent: 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: { value: any }) => {
|
|
||||||
if (isEditor) return { items: [${JSON.stringify(sample)}], pk: "${pk.name}" };
|
|
||||||
|
|
||||||
let raw_id = opt.value;
|
|
||||||
${
|
|
||||||
opt?.before_load
|
|
||||||
? opt.before_load
|
|
||||||
: `let id = ${pk.type === "int" ? "parseInt(raw_id)" : "raw_id"};`
|
|
||||||
}
|
|
||||||
|
|
||||||
let items = await db.${table}.findMany({
|
|
||||||
select: ${JSON.stringify(select, null, 2).split("\n").join("\n ")},
|
|
||||||
});
|
|
||||||
|
|
||||||
return { items, pk: "${pk.name}" };
|
|
||||||
}`;
|
|
||||||
};
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
import capitalize from "lodash.capitalize";
|
|
||||||
import { GFCol, createItem, parseGenField } from "../utils";
|
|
||||||
import { on_load } from "./on_load";
|
|
||||||
import { codeBuild, codeBuildTest } from "../master_detail/utils";
|
|
||||||
// import * as Excel from "exceljs";
|
|
||||||
// import ExcelJS from "exceljs";
|
|
||||||
|
|
||||||
export const gen_export = async (
|
|
||||||
modify: (data: any) => void,
|
|
||||||
data: any,
|
|
||||||
arg: { mode: "table" | "list" | "grid" | "auto"; id_parent?: string }
|
|
||||||
) => {
|
|
||||||
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[] }
|
|
||||||
)[];
|
|
||||||
const select = {} as any;
|
|
||||||
let pk = "";
|
|
||||||
let pks: Record<string, string> = {};
|
|
||||||
|
|
||||||
const fields = parseGenField(raw_fields);
|
|
||||||
for (const f of fields) {
|
|
||||||
select[f.name] = true;
|
|
||||||
if (f.relation) {
|
|
||||||
select[f.name] = {
|
|
||||||
select: {},
|
|
||||||
};
|
|
||||||
for (const r of f.relation.fields) {
|
|
||||||
select[f.name].select[r.name] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (f.is_pk) {
|
|
||||||
pk = f.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.id_parent) {
|
|
||||||
select[arg.id_parent] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pk) {
|
|
||||||
alert("Failed to generate! Primary Key not found. ");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const keys = Object.keys(select);
|
|
||||||
const tableName = data.gen_table.value;
|
|
||||||
const selectFields = keys.join(", ");
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result: any[] = await db.$queryRawUnsafe(
|
|
||||||
`SELECT ${selectFields} FROM ${tableName};`
|
|
||||||
);
|
|
||||||
|
|
||||||
// const workbook = new ExcelJS.Workbook();
|
|
||||||
// const worksheet = workbook.addWorksheet("Sheet 1");
|
|
||||||
|
|
||||||
// const columns = Object.keys(result[0]);
|
|
||||||
// worksheet.addRow(columns);
|
|
||||||
|
|
||||||
// result.forEach((row) => {
|
|
||||||
// const values = columns.map((col) => row[col]);
|
|
||||||
// worksheet.addRow(values);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// const buffer = await workbook.xlsx.writeBuffer();
|
|
||||||
|
|
||||||
// const blob = new Blob([buffer], {
|
|
||||||
// type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
||||||
// });
|
|
||||||
|
|
||||||
// FileSaver.saveAs(blob, "exported_data.xlsx");
|
|
||||||
|
|
||||||
console.log("Data exported");
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error exporting data:", error);
|
|
||||||
} finally {
|
|
||||||
await db.$disconnect();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,176 +0,0 @@
|
||||||
import capitalize from "lodash.capitalize";
|
|
||||||
import { GFCol, createItem, parseGenField } from "../utils";
|
|
||||||
import { on_load } from "./on_load";
|
|
||||||
import { codeBuild } from "../master_detail/utils";
|
|
||||||
|
|
||||||
export const gen_table_list = async (
|
|
||||||
modify: (data: any) => void,
|
|
||||||
data: any,
|
|
||||||
arg: { mode: "table" | "list" | "grid" | "auto"; id_parent?: string }
|
|
||||||
) => {
|
|
||||||
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[] }
|
|
||||||
)[];
|
|
||||||
const select = {} as any;
|
|
||||||
let pk = "";
|
|
||||||
let pks: Record<string, string> = {};
|
|
||||||
|
|
||||||
const fields = parseGenField(raw_fields);
|
|
||||||
const result = {} as any;
|
|
||||||
for (const f of fields) {
|
|
||||||
select[f.name] = true;
|
|
||||||
if (f.relation) {
|
|
||||||
select[f.name] = {
|
|
||||||
select: {},
|
|
||||||
};
|
|
||||||
for (const r of f.relation.fields) {
|
|
||||||
select[f.name].select[r.name] = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (f.is_pk) {
|
|
||||||
pk = f.name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg.id_parent) {
|
|
||||||
select[arg.id_parent] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pk) {
|
|
||||||
alert("Failed to generate! Primary Key not found. ");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data["child"]) {
|
|
||||||
result["child"] = data["child"];
|
|
||||||
let sub_name = "fields";
|
|
||||||
switch (arg.mode) {
|
|
||||||
case "table":
|
|
||||||
case "auto":
|
|
||||||
sub_name = "tbl-col";
|
|
||||||
break;
|
|
||||||
case "list":
|
|
||||||
sub_name = "list-row";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
result["child"].content.childs = result["child"].content.childs.filter(
|
|
||||||
(e: any) => {
|
|
||||||
return e.name !== sub_name;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let first = true;
|
|
||||||
const child = createItem({
|
|
||||||
name: sub_name,
|
|
||||||
childs: fields
|
|
||||||
.map((e, idx) => {
|
|
||||||
if (idx >= 1 && arg.mode === "list") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (e.is_pk && (arg.mode === "table" || arg.mode === "auto"))
|
|
||||||
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: `\
|
|
||||||
<div {...props} className={cx(props.className, "")}>
|
|
||||||
<FormatValue value={col.value} name={col.name} gen_fields={gen_fields} ${tree_depth} />
|
|
||||||
</div>`,
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
result["child"].content.childs = [
|
|
||||||
child,
|
|
||||||
...result["child"].content.childs,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
// detect row yang aktif
|
|
||||||
if (data["selected"]) {
|
|
||||||
result["selected"] = data["selected"];
|
|
||||||
result["selected"].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;
|
|
||||||
}`;
|
|
||||||
delete result["selected"].valueBuilt;
|
|
||||||
code.selected = result["selected"].value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await codeBuild(code);
|
|
||||||
for (const [k, v] of Object.entries(res)) {
|
|
||||||
result[k].valueBuilt = v[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modify(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
const formatName = (name: string) => {
|
|
||||||
return name
|
|
||||||
.split("_")
|
|
||||||
.filter((e) => e.length > 1)
|
|
||||||
.map((e) => capitalize(e))
|
|
||||||
.join(" ");
|
|
||||||
};
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
export const on_load = ({
|
|
||||||
pk,
|
|
||||||
table,
|
|
||||||
select,
|
|
||||||
pks,
|
|
||||||
}: {
|
|
||||||
pk: string;
|
|
||||||
table: string;
|
|
||||||
select: any;
|
|
||||||
pks: Record<string, string>;
|
|
||||||
}) => {
|
|
||||||
const sample = {} as any;
|
|
||||||
|
|
||||||
for (const [k, v] of Object.entries(select) as any) {
|
|
||||||
if (typeof v === "object") {
|
|
||||||
sample[k] = {};
|
|
||||||
|
|
||||||
Object.keys(v.select)
|
|
||||||
.filter((e) => e !== pks[k])
|
|
||||||
.map((e) => {
|
|
||||||
sample[k][e] = "sample";
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
sample[k] = "sample";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return `\
|
|
||||||
async (arg: TableOnLoad) => {
|
|
||||||
if (isEditor) return [${JSON.stringify(sample)}];
|
|
||||||
|
|
||||||
if (arg.mode === 'count') {
|
|
||||||
return await db.${table}.count();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise(async (done) => {
|
|
||||||
const items = await db.${table}.findMany({
|
|
||||||
select: ${JSON.stringify(select, null, 2).split("\n").join("\n ")},
|
|
||||||
orderBy: arg.orderBy || {
|
|
||||||
${pk}: "desc"
|
|
||||||
},
|
|
||||||
...arg.paging,
|
|
||||||
});
|
|
||||||
|
|
||||||
done(items);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
type TableOnLoad = {
|
|
||||||
reload: () => Promise<void>;
|
|
||||||
orderBy?: Record<string, "asc" | "desc">;
|
|
||||||
paging: { take: number; skip: number };
|
|
||||||
mode: 'count' | 'query';
|
|
||||||
where?: Record<string, any>;
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
import get from "lodash.get";
|
|
||||||
import { GenMasterDetailArg, codeBuild } from "./utils";
|
|
||||||
import { createItem, formatName } from "../utils";
|
|
||||||
import { gen_form } from "../gen_form/gen_form";
|
|
||||||
|
|
||||||
export const genAtions = async (arg: GenMasterDetailArg, data: any) => {
|
|
||||||
console.log({ arg, data });
|
|
||||||
const header = get(data, "header");
|
|
||||||
const action_right = header.content.childs.find(
|
|
||||||
(e: any) => e.name === "right"
|
|
||||||
);
|
|
||||||
|
|
||||||
const list_action_right =
|
|
||||||
typeof action_right === "object" ? action_right.childs : [];
|
|
||||||
for (const c of get(data, "child.content.childs") || []) {
|
|
||||||
if (c.component?.id === "cb52075a-14ab-455a-9847-6f1d929a2a73") {
|
|
||||||
const name_tab = c.component.props.name.value.replaceAll('"', "");
|
|
||||||
const is_already = list_action_right.length
|
|
||||||
? list_action_right.some(
|
|
||||||
(action: any) =>
|
|
||||||
action.component.props.name.value.replaceAll(/`/g, "") ===
|
|
||||||
name_tab
|
|
||||||
)
|
|
||||||
: false;
|
|
||||||
if (!is_already) {
|
|
||||||
const res = await codeBuild({
|
|
||||||
show: `\
|
|
||||||
() => {
|
|
||||||
if (typeof md === "object") {
|
|
||||||
const tab_active = md.tab.active;
|
|
||||||
if (name === "master") {
|
|
||||||
if (tab_active === "" || tab_active === "master") return true;
|
|
||||||
} else {
|
|
||||||
if (tab_active === name) return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
});
|
|
||||||
// const childs = get(action_right, "childs") || [];
|
|
||||||
// childs.push(
|
|
||||||
// createItem({
|
|
||||||
// name: "action"
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// const childs = get(data, "child.content.childs[3].childs") || [];
|
|
||||||
// console.log(childs)
|
|
||||||
// childs.push(
|
|
||||||
// createItem({
|
|
||||||
// name: "action",
|
|
||||||
// // component: {
|
|
||||||
// // id: "83a2859d-2f72-4e7d-a0c6-9d3368e1ed85",
|
|
||||||
// // props: {
|
|
||||||
// // show: res.show,
|
|
||||||
// // name: name_tab,
|
|
||||||
// // },
|
|
||||||
// // },
|
|
||||||
// })
|
|
||||||
// );
|
|
||||||
// console.log({action_right})
|
|
||||||
}
|
|
||||||
console.log(is_already);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
import get from "lodash.get";
|
|
||||||
import { GenMasterDetailArg, codeBuild } from "./utils";
|
|
||||||
import { createItem, formatName } from "../utils";
|
|
||||||
import { gen_form } from "../gen_form/gen_form";
|
|
||||||
|
|
||||||
export const genForm = async (arg: GenMasterDetailArg, data: any) => {
|
|
||||||
// tambahi kondisi, jika gk nemu component tab detail maka update tab detail atau bikin baru
|
|
||||||
const childs_form = data.child.content.childs || [];
|
|
||||||
const tab_form = childs_form.filter((c: any) => c.component?.id === "cb52075a-14ab-455a-9847-6f1d929a2a73" && c.component.props.name.value.replaceAll("\"","") === "detail")
|
|
||||||
for (const c of get(data, "child.content.childs") || []) {
|
|
||||||
if (c.component?.id === "cb52075a-14ab-455a-9847-6f1d929a2a73") {
|
|
||||||
// passing khusus tab detail, biar tab lain gk di rewrite.
|
|
||||||
let passing = false;
|
|
||||||
if(!tab_form.length){
|
|
||||||
passing = true;
|
|
||||||
}else{
|
|
||||||
const name_tab = c.component.props.name.value.replaceAll("\"","");
|
|
||||||
passing = name_tab === "detail"
|
|
||||||
}
|
|
||||||
if(passing){
|
|
||||||
|
|
||||||
const res = await codeBuild({
|
|
||||||
breadcrumb: `\
|
|
||||||
async () => {
|
|
||||||
const breads: BreadItem[] = [
|
|
||||||
{
|
|
||||||
label: "List ${formatName(arg.gen_table)}",
|
|
||||||
onClick: () => {
|
|
||||||
md.selected = null;
|
|
||||||
md.tab.active = "";
|
|
||||||
md.internal.action_should_refresh = true;
|
|
||||||
md.params.apply();
|
|
||||||
md.render();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isEditor) {
|
|
||||||
breads.push({ label: "Add New" });
|
|
||||||
} else {
|
|
||||||
if (
|
|
||||||
md.selected &&
|
|
||||||
typeof md.selected === "object"
|
|
||||||
) {
|
|
||||||
if (Object.keys(md.selected).length === 0){
|
|
||||||
breads.push({ label: "Add New" });
|
|
||||||
} else {
|
|
||||||
breads.push({ label: "Edit" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return breads;
|
|
||||||
};
|
|
||||||
|
|
||||||
type BreadItem = {
|
|
||||||
label: React.ReactNode;
|
|
||||||
url?: string;
|
|
||||||
onClick?: () => void;
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
actions: `\
|
|
||||||
async () => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
action: "delete",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: "Save",
|
|
||||||
action: "save",
|
|
||||||
},
|
|
||||||
] as ActionItem[];
|
|
||||||
};
|
|
||||||
|
|
||||||
type ActionItem =
|
|
||||||
| {
|
|
||||||
action?: string;
|
|
||||||
label: React.ReactNode;
|
|
||||||
onClick?: (e: any) => Promise<void>;
|
|
||||||
}
|
|
||||||
| React.ReactNode`,
|
|
||||||
// on_init: `\
|
|
||||||
// async ({ submit, reload }: Init) => {
|
|
||||||
// const tab = md.childs[md.tab.active];
|
|
||||||
// if (tab) {
|
|
||||||
// const actions = await getProp(tab.internal, "actions", { md });
|
|
||||||
// if (Array.isArray(actions)) {
|
|
||||||
// const save_btn = actions
|
|
||||||
// .filter((e) => e)
|
|
||||||
// .find((e) => e.action === "save");
|
|
||||||
// if (save_btn) {
|
|
||||||
// save_btn.onClick = async () => {
|
|
||||||
// await submit();
|
|
||||||
// };
|
|
||||||
// md.actions = actions;
|
|
||||||
// md.render();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// type Init = { submit: () => Promise<boolean>; reload: () => void }
|
|
||||||
// `,
|
|
||||||
on_init: `\
|
|
||||||
async ({ submit, reload, fm }: Init) => {
|
|
||||||
if (typeof md === "object") {
|
|
||||||
md.childs["form"] = {} as any;
|
|
||||||
md.childs["form"]["fm"] = fm;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
type Init = { submit: () => Promise<boolean>; reload: () => void; fm:any }
|
|
||||||
`,
|
|
||||||
});
|
|
||||||
const comp = createItem({
|
|
||||||
component: {
|
|
||||||
id: "cb52075a-14ab-455a-9847-6f1d929a2a73",
|
|
||||||
props: {
|
|
||||||
breadcrumb: res.breadcrumb,
|
|
||||||
actions: res.actions,
|
|
||||||
name: "detail",
|
|
||||||
label: "Detail",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
for (const [k, v] of Object.entries(comp.component.props)) {
|
|
||||||
c.component.props[k] = v;
|
|
||||||
}
|
|
||||||
const childs = get(c, "component.props.child.content.childs") || [];
|
|
||||||
childs.length = 0;
|
|
||||||
childs.push(
|
|
||||||
createItem({
|
|
||||||
component: {
|
|
||||||
id: "c4e65c26-4f36-48aa-a5b3-0771feac082e",
|
|
||||||
props: {
|
|
||||||
name: arg.gen_table,
|
|
||||||
label: formatName(arg.gen_table),
|
|
||||||
gen_table: arg.gen_table,
|
|
||||||
gen_fields: [JSON.stringify(arg.gen_fields)],
|
|
||||||
on_init: res.on_init,
|
|
||||||
on_load: "",
|
|
||||||
on_submit: "",
|
|
||||||
generate: "y",
|
|
||||||
body: {
|
|
||||||
childs: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const data = childs[0].component.props;
|
|
||||||
const modify = async (props: any) => {};
|
|
||||||
await gen_form(modify, data, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,121 +0,0 @@
|
||||||
import get from "lodash.get";
|
|
||||||
import { gen_table_list } from "../gen_table_list/gen_table_list";
|
|
||||||
import { createItem, formatName } from "../utils";
|
|
||||||
import { GenMasterDetailArg, codeBuild } from "./utils";
|
|
||||||
export const genList = async (arg: GenMasterDetailArg, data: any) => {
|
|
||||||
for (const c of get(data, "child.content.childs") || []) {
|
|
||||||
if (c.component?.id === "c68415ca-dac5-44fe-aeb6-936caf8cc491") {
|
|
||||||
const res = await codeBuild({
|
|
||||||
row_click: `\
|
|
||||||
({ 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<HTMLDivElement, MouseEvent>;
|
|
||||||
}
|
|
||||||
`,
|
|
||||||
selected: `\
|
|
||||||
({ 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;
|
|
||||||
}`,
|
|
||||||
breadcrumb: `\
|
|
||||||
async () => {
|
|
||||||
return [{ label: "List ${formatName(arg.gen_table)}" }] as BreadItem[];
|
|
||||||
};
|
|
||||||
|
|
||||||
type BreadItem = {
|
|
||||||
label: React.ReactNode;
|
|
||||||
url?: string;
|
|
||||||
onClick?: () => void;
|
|
||||||
}`,
|
|
||||||
actions: `\
|
|
||||||
async () => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
label: "Add ${formatName(arg.gen_table)}",
|
|
||||||
onClick: async () => {
|
|
||||||
md.selected = {};
|
|
||||||
md.render();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
] as ActionItem[];
|
|
||||||
};
|
|
||||||
|
|
||||||
type ActionItem =
|
|
||||||
| {
|
|
||||||
action?: string;
|
|
||||||
label: React.ReactNode;
|
|
||||||
onClick?: (e: any) => Promise<void>;
|
|
||||||
}
|
|
||||||
| React.ReactNode`,
|
|
||||||
});
|
|
||||||
const comp = createItem({
|
|
||||||
component: {
|
|
||||||
id: "c68415ca-dac5-44fe-aeb6-936caf8cc491",
|
|
||||||
props: {
|
|
||||||
breadcrumb: res.breadcrumb,
|
|
||||||
actions: res.actions,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
for (const [k, v] of Object.entries(comp.component.props)) {
|
|
||||||
c.component.props[k] = v;
|
|
||||||
}
|
|
||||||
|
|
||||||
const childs = get(c, "component.props.child.content.childs") || [];
|
|
||||||
childs.length = 0;
|
|
||||||
childs.push(
|
|
||||||
createItem({
|
|
||||||
component: {
|
|
||||||
id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
|
|
||||||
props: {
|
|
||||||
name: arg.gen_table,
|
|
||||||
gen__table: arg.gen_table,
|
|
||||||
generate: "y",
|
|
||||||
on_load: "",
|
|
||||||
row_click: res.row_click,
|
|
||||||
selected: res.selected,
|
|
||||||
gen__fields: [JSON.stringify(arg.gen_fields)],
|
|
||||||
child: {
|
|
||||||
childs: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const data = childs[0].component.props;
|
|
||||||
const modify = async (props: any) => {};
|
|
||||||
gen_table_list(modify, data, { mode: "auto" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
import { PropOptRaw, GenFn, parseGenField, parseOpt } from "../utils";
|
|
||||||
import { genAtions } from "./gen-action";
|
|
||||||
import { genForm } from "./gen-form";
|
|
||||||
import { genList } from "./gen-list";
|
|
||||||
import { GenMasterDetailArg } from "./utils";
|
|
||||||
|
|
||||||
const w = window as unknown as {
|
|
||||||
generating_prasi_md: Record<string, true>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const gen_master_detail: GenFn<GenMasterDetailArg> = async (
|
|
||||||
modify,
|
|
||||||
data,
|
|
||||||
arg
|
|
||||||
) => {
|
|
||||||
w.generating_prasi_md = {
|
|
||||||
"master_detail": true
|
|
||||||
};
|
|
||||||
const result: any = {};
|
|
||||||
const fields = parseGenField(arg.gen_fields);
|
|
||||||
modify(result);
|
|
||||||
const should_gen = parseOpt<{
|
|
||||||
list: { number: boolean; actions: boolean };
|
|
||||||
form: boolean;
|
|
||||||
view: boolean;
|
|
||||||
}>(arg.gen_feature);
|
|
||||||
|
|
||||||
if (should_gen.list) {
|
|
||||||
await genList(arg, data);
|
|
||||||
}
|
|
||||||
if (should_gen.form) {
|
|
||||||
await genForm(arg, data);
|
|
||||||
}
|
|
||||||
result.child = data.child;
|
|
||||||
|
|
||||||
delete w.generating_prasi_md["master_detail"];
|
|
||||||
modify(result);
|
|
||||||
};
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
import { PropOptRaw } from "../utils";
|
|
||||||
|
|
||||||
export type GenMasterDetailArg = {
|
|
||||||
mode: "full" | "h-split" | "v-split";
|
|
||||||
show_head: "always" | "only-master" | "only-child" | "hidden";
|
|
||||||
tab_mode: "h-tab" | "v-tab" | "hidden";
|
|
||||||
gen_feature: PropOptRaw;
|
|
||||||
gen_table: string;
|
|
||||||
gen_fields: PropOptRaw;
|
|
||||||
child:any
|
|
||||||
};
|
|
||||||
|
|
||||||
export const codeBuild = async <K extends Record<string, string>>(input: K) => {
|
|
||||||
const result = {} as any;
|
|
||||||
|
|
||||||
//@ts-ignore
|
|
||||||
const res = await _api.code_build(input);
|
|
||||||
if (res) {
|
|
||||||
for (const [k, v] of Object.entries(res) as any) {
|
|
||||||
result[k] = [input[k], v];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result as Record<keyof K, [string, string]>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const codeBuildTest = async (input: string) => {
|
|
||||||
const result = {} as any;
|
|
||||||
|
|
||||||
//@ts-ignore
|
|
||||||
const res = await _api.code_build(input);
|
|
||||||
return res;
|
|
||||||
// if (res) {
|
|
||||||
// for (const [k, v] of Object.entries(res) as any) {
|
|
||||||
// result[k] = [input[k], v];
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return result as Record<keyof K, [string, string]>;
|
|
||||||
};
|
|
||||||
|
|
@ -1,18 +1,8 @@
|
||||||
import { gen_action } from "./gen_action/gen_action";
|
import { gen_object_rel } from "./prop/gen_object_rel";
|
||||||
import { gen_form } from "./gen_form/gen_form";
|
|
||||||
import { gen_relation } from "./gen_relation/gen_relation";
|
|
||||||
import { gen_table_list } from "./gen_table_list/gen_table_list";
|
|
||||||
import { gen_master_detail } from "./master_detail/gen";
|
|
||||||
import { gen_prop_fields } from "./prop/gen_prop_fields";
|
import { gen_prop_fields } from "./prop/gen_prop_fields";
|
||||||
import { gen_props_table } from "./prop/gen_prop_table";
|
import { gen_props_table } from "./prop/gen_prop_table";
|
||||||
import { gen_object_rel } from "./prop/gen_object_rel";
|
|
||||||
|
|
||||||
export const prasi_gen = {
|
export const prasi_gen = {
|
||||||
actions_tab: gen_action,
|
|
||||||
// master_detail: gen_master_detail,
|
|
||||||
// table_list: gen_table_list,
|
|
||||||
// form: gen_form,
|
|
||||||
// relation: gen_relation,
|
|
||||||
prop: {
|
prop: {
|
||||||
fields: gen_prop_fields,
|
fields: gen_prop_fields,
|
||||||
table: gen_props_table,
|
table: gen_props_table,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue