wip fix
This commit is contained in:
parent
0a02fc3c0e
commit
4559a90ca1
|
|
@ -60,6 +60,11 @@ export const gen_form = (modify: (data: any) => void, data: any) => {
|
|||
}
|
||||
|
||||
const result: any = {};
|
||||
|
||||
if (!pk) {
|
||||
alert("Failed to generate! Primary Key not found. ");
|
||||
return;
|
||||
}
|
||||
if (pk) {
|
||||
if (mode.includes("on_load")) {
|
||||
result["on_load"] = data["on_load"];
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ export const on_load = ({
|
|||
pks: Record<string, string>;
|
||||
opt?: {
|
||||
before_load: string;
|
||||
after_load: string;
|
||||
};
|
||||
}) => {
|
||||
return `\
|
||||
|
|
@ -22,8 +23,9 @@ async (opt) => {
|
|||
let id = ${pk.type === "int" ? "parseInt(params.id)" : "params.id"};
|
||||
${opt?.before_load}
|
||||
|
||||
let item = {};
|
||||
if (id){
|
||||
const item = await db.${table}.findFirst({
|
||||
item = await db.${table}.findFirst({
|
||||
where: {
|
||||
${pk.name}: id,
|
||||
},
|
||||
|
|
@ -40,9 +42,12 @@ async (opt) => {
|
|||
}`;
|
||||
})
|
||||
.join("\n")}
|
||||
}
|
||||
|
||||
${opt?.after_load}
|
||||
|
||||
return item;
|
||||
} else {
|
||||
${opt?.after_load}
|
||||
}
|
||||
}`;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
export const form_before_load = (pk: string, title: string, name: string) => {
|
||||
export const form_before_load = (
|
||||
table: string,
|
||||
pk: string,
|
||||
title: string,
|
||||
label: string
|
||||
) => {
|
||||
return `
|
||||
const after_load = (item: any) => {
|
||||
const set_actions = () =>
|
||||
|
|
@ -11,7 +16,7 @@ export const form_before_load = (pk: string, title: string, name: string) => {
|
|||
md.ui.actions = [{ label: "Deleting...", type: "ghost" }];
|
||||
md.render();
|
||||
|
||||
await db.m_aset.delete({ where: { ${pk}: item.${pk} } });
|
||||
await db.${table}.delete({ where: { ${pk}: item.${pk} } });
|
||||
|
||||
setTimeout(() => {
|
||||
md.ui.actions = [...md.ui.default_actions];
|
||||
|
|
@ -39,8 +44,11 @@ export const form_before_load = (pk: string, title: string, name: string) => {
|
|||
},
|
||||
]);
|
||||
set_actions();
|
||||
md.ui.breadcrumb = [[${title}, ""], item?.nama_aset_komersial];
|
||||
md.ui.breadcrumb = [["${title}", ""]${label ? `, item?.["${label}"]` : ""}];
|
||||
md.render();
|
||||
};
|
||||
md.ui.breadcrumb = [["${title}", ""], "..."];
|
||||
md.render();
|
||||
|
||||
`;
|
||||
};
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -208,7 +208,6 @@ export const gen_master = () => {
|
|||
},
|
||||
typings:
|
||||
"const typings = {\n cell: `{ key: string, value: any }`,\n row: `any`,\n idx: `number`,\n rows: `any[]`,\n}",
|
||||
valueBuilt: ' "hello";\n',
|
||||
},
|
||||
columns: {
|
||||
idx: 0,
|
||||
|
|
@ -219,8 +218,6 @@ export const gen_master = () => {
|
|||
type: "string",
|
||||
value:
|
||||
'async (): Promise<\n { key: string; name: string; width?: number; frozen?: boolean }[]\n > => {\n return [\n { key: "id", name: "#", width: 60, frozen: true },\n {"key":"nama_aset_komersial","name":"Nama Aset Komersial"},\n {"key":"m_cabang","name":"Cabang"},\n {"key":"m_regional","name":"Regional"},\n {"key":"luas_setifikat","name":"Luas Setifikat"},\n {"key":"tanggal_sertifikat","name":"Tanggal Sertifikat"}\n ];\n }',
|
||||
valueBuilt:
|
||||
' async () => {\n return [\n { key: "id", name: "#", width: 60, frozen: true },\n { "key": "nama_aset_komersial", "name": "Nama Aset Komersial" },\n { "key": "m_cabang", "name": "Cabang" },\n { "key": "m_regional", "name": "Regional" },\n { "key": "luas_setifikat", "name": "Luas Setifikat" },\n { "key": "tanggal_sertifikat", "name": "Tanggal Sertifikat" }\n ];\n};\n',
|
||||
},
|
||||
on_load: {
|
||||
idx: 1,
|
||||
|
|
@ -230,9 +227,7 @@ export const gen_master = () => {
|
|||
name: "prop_1",
|
||||
type: "string",
|
||||
value:
|
||||
"async () => {\n if (isEditor)\n return [\n {\n id: createId(),\n },\n });\n\n return items;\n}",
|
||||
valueBuilt:
|
||||
' async () => {\n if (isEditor)\n return [\n {\n id: createId(),\n tanggal_sertifikat: "sample"\n }\n ];\n const items = await db.m_aset.findMany({\n select: {\n id: true,\n nama_aset_komersial: true,\n m_cabang: {\n select: {\n id: true,\n nama_cabang: true\n }\n },\n m_regional: {\n select: {\n regional: true,\n id: true\n }\n },\n luas_setifikat: true,\n tanggal_sertifikat: true\n },\n orderBy: {\n id: "desc"\n }\n });\n return items;\n};\n',
|
||||
"async () => {\n if (isEditor)\n return [\n {\n },\n });\n\n return items;\n}",
|
||||
},
|
||||
generate: {
|
||||
idx: 5,
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { gen_master } from "./gen_master";
|
|||
import { on_load as table_on_load } from "../gen_table/on_load";
|
||||
import { on_load as form_on_load } from "../gen_form/on_load";
|
||||
import { on_submit as form_on_submit } from "../gen_form/on_submit";
|
||||
import { newField as form_new_field } from "../gen_form/new_field";
|
||||
import { gen_columns } from "../gen_table/columns";
|
||||
import { newField as table_new_field } from "../gen_table/new_field";
|
||||
import { gen_detail } from "./gen_detail";
|
||||
|
|
@ -66,6 +67,10 @@ export const gen_md = (modify: (data: any) => void, data: any) => {
|
|||
}
|
||||
|
||||
const result: any = {};
|
||||
if (!pk) {
|
||||
alert("Failed to generate! Primary Key not found. ");
|
||||
return;
|
||||
}
|
||||
if (pk) {
|
||||
result["header"] = data["header"];
|
||||
result["header"].content = gen_header();
|
||||
|
|
@ -79,19 +84,48 @@ export const gen_md = (modify: (data: any) => void, data: any) => {
|
|||
|
||||
result["detail"] = data["detail"];
|
||||
const detail = gen_detail();
|
||||
const title = JSON.parse(get(data, "title.value"));
|
||||
const before_load = form_before_load(pk.name, title, "");
|
||||
const title = parse(get(data, "title.value"));
|
||||
const label = parse(get(data, "gen_label.value"));
|
||||
const before_load = form_before_load(table, pk.name, title, label);
|
||||
|
||||
detail.props["on_load"].value = form_on_load({ pk, pks, select, table });
|
||||
detail.props["on_load"].value = form_on_load({
|
||||
pk,
|
||||
pks,
|
||||
select,
|
||||
table,
|
||||
opt: { before_load, after_load: `after_load(item);` },
|
||||
});
|
||||
detail.props["on_submit"].value = form_on_submit({
|
||||
pk,
|
||||
table,
|
||||
select,
|
||||
pks,
|
||||
});
|
||||
|
||||
const childs = get(detail.props, "body.content.childs");
|
||||
if (Array.isArray(childs)) {
|
||||
detail.props.body.content.childs = new_fields.map(form_new_field) as any;
|
||||
console.log(detail.props.body.content.childs);
|
||||
}
|
||||
result["detail"].content = detail.content;
|
||||
}
|
||||
// modify(result);
|
||||
modify(result);
|
||||
|
||||
alert("Prop Generated!");
|
||||
alert("Prop Generated! ");
|
||||
};
|
||||
|
||||
const parse = (text: any) => {
|
||||
if (typeof text === "string") {
|
||||
let result = "";
|
||||
try {
|
||||
eval(`result = ${text}`);
|
||||
|
||||
if (typeof result === "function") {
|
||||
result = (result as any)();
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return result;
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,17 +38,24 @@ export const gen_table = (modify: (data: any) => void, data: any) => {
|
|||
}
|
||||
|
||||
const result = {} as any;
|
||||
if (data["columns"]) {
|
||||
result["columns"] = data["columns"];
|
||||
result["columns"].value = gen_columns(columns);
|
||||
|
||||
if (!pk) {
|
||||
alert("Failed to generate! Primary Key not found. ");
|
||||
return;
|
||||
}
|
||||
if (data["on_load"]) {
|
||||
result["on_load"] = data["on_load"];
|
||||
result["on_load"].value = on_load({ pk, table, select, pks });
|
||||
}
|
||||
if (data["child"]) {
|
||||
result["child"] = data["child"];
|
||||
result["child"].content.childs = newField(select, pks);
|
||||
if (pk) {
|
||||
if (data["columns"]) {
|
||||
result["columns"] = data["columns"];
|
||||
result["columns"].value = gen_columns(columns);
|
||||
}
|
||||
if (data["on_load"]) {
|
||||
result["on_load"] = data["on_load"];
|
||||
result["on_load"].value = on_load({ pk, table, select, pks });
|
||||
}
|
||||
if (data["child"]) {
|
||||
result["child"] = data["child"];
|
||||
result["child"].content.childs = newField(select, pks);
|
||||
}
|
||||
}
|
||||
modify(result);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue