This commit is contained in:
Rizky 2024-07-08 02:29:40 -07:00
parent c7641e154d
commit b1f410758d
6 changed files with 84 additions and 69 deletions

View File

@ -36,7 +36,8 @@ export const FieldInput: FC<{
const errors = fm.error.get(name);
let type_field: any = typeof arg.type === "function" ? arg.type() : arg.type; // tipe field
const disabled = typeof field.disabled === "function" ? field.disabled() : field.disabled;
const disabled =
typeof field.disabled === "function" ? field.disabled() : field.disabled;
let custom = <></>;
if (field.type === "custom") {
let res = arg.custom?.() || <></>;

View File

@ -74,6 +74,11 @@ export const FieldTypeInput: FC<{
} else {
value = null;
}
if (type_field === "datetime-local" && date instanceof Date) {
date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
value = date.toISOString().slice(0, 16);
}
} else {
try {
let date = parse(value);
@ -98,6 +103,7 @@ export const FieldTypeInput: FC<{
const disabled =
typeof field.disabled === "function" ? field.disabled() : field.disabled;
switch (type_field) {
case "toggle":
return (

View File

@ -37,10 +37,6 @@ export const generateForm = async (
return;
}
if (pk) {
let is_md: boolean | string =
item.edit?.parent?.item?.component?.id ===
"cb52075a-14ab-455a-9847-6f1d929a2a73";
if (!is_md) is_md = "";
if (data["on_load"]) {
result.on_load = {

View File

@ -50,6 +50,7 @@ export const generateMDForm = async (
},
};
generateForm(async (props: any) => {}, props, tablelist, false, true);
tab_detail?.edit.setProp("breadcrumb", {
mode: "raw",
value: `\

View File

@ -320,8 +320,13 @@ export const Typeahead: FC<{
let inputval = local.search.input;
if (!local.open && local.mode === "single" && local.value?.length > 0) {
const found = options.find((e) => e.value === local.value[0]);
if (found) {
inputval = found.label;
} else {
inputval = local.value[0];
}
}
return (
<div

View File

@ -4,73 +4,79 @@ 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) => {
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> = {};
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;
}
}
}
// 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 (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 (!pk) {
// alert("Failed to generate! Primary Key not found. ");
// return;
// }
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;
}
// 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;
// }
const res = await codeBuild(code);
for (const [k, v] of Object.entries(res)) {
result[k].valueBuilt = v[1];
}
// 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;
// }
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);
// 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);
};