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 = {};
|
const result: any = {};
|
||||||
|
|
||||||
|
if (!pk) {
|
||||||
|
alert("Failed to generate! Primary Key not found. ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (pk) {
|
if (pk) {
|
||||||
if (mode.includes("on_load")) {
|
if (mode.includes("on_load")) {
|
||||||
result["on_load"] = data["on_load"];
|
result["on_load"] = data["on_load"];
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ export const on_load = ({
|
||||||
pks: Record<string, string>;
|
pks: Record<string, string>;
|
||||||
opt?: {
|
opt?: {
|
||||||
before_load: string;
|
before_load: string;
|
||||||
|
after_load: string;
|
||||||
};
|
};
|
||||||
}) => {
|
}) => {
|
||||||
return `\
|
return `\
|
||||||
|
|
@ -22,8 +23,9 @@ async (opt) => {
|
||||||
let id = ${pk.type === "int" ? "parseInt(params.id)" : "params.id"};
|
let id = ${pk.type === "int" ? "parseInt(params.id)" : "params.id"};
|
||||||
${opt?.before_load}
|
${opt?.before_load}
|
||||||
|
|
||||||
|
let item = {};
|
||||||
if (id){
|
if (id){
|
||||||
const item = await db.${table}.findFirst({
|
item = await db.${table}.findFirst({
|
||||||
where: {
|
where: {
|
||||||
${pk.name}: id,
|
${pk.name}: id,
|
||||||
},
|
},
|
||||||
|
|
@ -40,9 +42,12 @@ async (opt) => {
|
||||||
}`;
|
}`;
|
||||||
})
|
})
|
||||||
.join("\n")}
|
.join("\n")}
|
||||||
}
|
|
||||||
|
${opt?.after_load}
|
||||||
|
|
||||||
return item;
|
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 `
|
return `
|
||||||
const after_load = (item: any) => {
|
const after_load = (item: any) => {
|
||||||
const set_actions = () =>
|
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.ui.actions = [{ label: "Deleting...", type: "ghost" }];
|
||||||
md.render();
|
md.render();
|
||||||
|
|
||||||
await db.m_aset.delete({ where: { ${pk}: item.${pk} } });
|
await db.${table}.delete({ where: { ${pk}: item.${pk} } });
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
md.ui.actions = [...md.ui.default_actions];
|
md.ui.actions = [...md.ui.default_actions];
|
||||||
|
|
@ -39,8 +44,11 @@ export const form_before_load = (pk: string, title: string, name: string) => {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
set_actions();
|
set_actions();
|
||||||
md.ui.breadcrumb = [[${title}, ""], item?.nama_aset_komersial];
|
md.ui.breadcrumb = [["${title}", ""]${label ? `, item?.["${label}"]` : ""}];
|
||||||
md.render();
|
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:
|
typings:
|
||||||
"const typings = {\n cell: `{ key: string, value: any }`,\n row: `any`,\n idx: `number`,\n rows: `any[]`,\n}",
|
"const typings = {\n cell: `{ key: string, value: any }`,\n row: `any`,\n idx: `number`,\n rows: `any[]`,\n}",
|
||||||
valueBuilt: ' "hello";\n',
|
|
||||||
},
|
},
|
||||||
columns: {
|
columns: {
|
||||||
idx: 0,
|
idx: 0,
|
||||||
|
|
@ -219,8 +218,6 @@ export const gen_master = () => {
|
||||||
type: "string",
|
type: "string",
|
||||||
value:
|
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 }',
|
'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: {
|
on_load: {
|
||||||
idx: 1,
|
idx: 1,
|
||||||
|
|
@ -230,9 +227,7 @@ export const gen_master = () => {
|
||||||
name: "prop_1",
|
name: "prop_1",
|
||||||
type: "string",
|
type: "string",
|
||||||
value:
|
value:
|
||||||
"async () => {\n if (isEditor)\n return [\n {\n id: createId(),\n },\n });\n\n return items;\n}",
|
"async () => {\n if (isEditor)\n return [\n {\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',
|
|
||||||
},
|
},
|
||||||
generate: {
|
generate: {
|
||||||
idx: 5,
|
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 table_on_load } from "../gen_table/on_load";
|
||||||
import { on_load as form_on_load } from "../gen_form/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 { 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 { gen_columns } from "../gen_table/columns";
|
||||||
import { newField as table_new_field } from "../gen_table/new_field";
|
import { newField as table_new_field } from "../gen_table/new_field";
|
||||||
import { gen_detail } from "./gen_detail";
|
import { gen_detail } from "./gen_detail";
|
||||||
|
|
@ -66,6 +67,10 @@ export const gen_md = (modify: (data: any) => void, data: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: any = {};
|
const result: any = {};
|
||||||
|
if (!pk) {
|
||||||
|
alert("Failed to generate! Primary Key not found. ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (pk) {
|
if (pk) {
|
||||||
result["header"] = data["header"];
|
result["header"] = data["header"];
|
||||||
result["header"].content = gen_header();
|
result["header"].content = gen_header();
|
||||||
|
|
@ -79,19 +84,48 @@ export const gen_md = (modify: (data: any) => void, data: any) => {
|
||||||
|
|
||||||
result["detail"] = data["detail"];
|
result["detail"] = data["detail"];
|
||||||
const detail = gen_detail();
|
const detail = gen_detail();
|
||||||
const title = JSON.parse(get(data, "title.value"));
|
const title = parse(get(data, "title.value"));
|
||||||
const before_load = form_before_load(pk.name, title, "");
|
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({
|
detail.props["on_submit"].value = form_on_submit({
|
||||||
pk,
|
pk,
|
||||||
table,
|
table,
|
||||||
select,
|
select,
|
||||||
pks,
|
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;
|
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,6 +38,12 @@ export const gen_table = (modify: (data: any) => void, data: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = {} as any;
|
const result = {} as any;
|
||||||
|
|
||||||
|
if (!pk) {
|
||||||
|
alert("Failed to generate! Primary Key not found. ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pk) {
|
||||||
if (data["columns"]) {
|
if (data["columns"]) {
|
||||||
result["columns"] = data["columns"];
|
result["columns"] = data["columns"];
|
||||||
result["columns"].value = gen_columns(columns);
|
result["columns"].value = gen_columns(columns);
|
||||||
|
|
@ -50,6 +56,7 @@ export const gen_table = (modify: (data: any) => void, data: any) => {
|
||||||
result["child"] = data["child"];
|
result["child"] = data["child"];
|
||||||
result["child"].content.childs = newField(select, pks);
|
result["child"].content.childs = newField(select, pks);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
modify(result);
|
modify(result);
|
||||||
|
|
||||||
alert("Prop Generated!");
|
alert("Prop Generated!");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue