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); const errors = fm.error.get(name);
let type_field: any = typeof arg.type === "function" ? arg.type() : arg.type; // tipe field 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 = <></>; let custom = <></>;
if (field.type === "custom") { if (field.type === "custom") {
let res = arg.custom?.() || <></>; let res = arg.custom?.() || <></>;

View File

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

View File

@ -37,10 +37,6 @@ export const generateForm = async (
return; return;
} }
if (pk) { 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"]) { if (data["on_load"]) {
result.on_load = { result.on_load = {

View File

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

View File

@ -320,8 +320,13 @@ export const Typeahead: FC<{
let inputval = local.search.input; let inputval = local.search.input;
if (!local.open && local.mode === "single" && local.value?.length > 0) { 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]; inputval = local.value[0];
} }
}
return ( return (
<div <div

View File

@ -4,73 +4,79 @@ import { GFCol, parseGenField } from "../utils";
import { newField } from "./new_field"; import { newField } from "./new_field";
import { on_submit } from "./on_submit"; import { on_submit } from "./on_submit";
export const gen_form = async (modify: (data: any) => void, data: any, is_md?: boolean) => { export const gen_form = async (
const table = JSON.parse(data.gen_table.value); modify: (data: any) => void,
const raw_fields = JSON.parse(data.gen_fields.value) as ( data: any,
| string is_md?: boolean
| { value: string; checked: string[] } ) => {
)[]; console.error("FAILED TO GENERATE: OBSOLETE FUNCTION");
const select = {} as any; // const table = JSON.parse(data.gen_table.value);
let pk: null | GFCol = null; // const raw_fields = JSON.parse(data.gen_fields.value) as (
let pks: Record<string, string> = {}; // | 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 fields = parseGenField(raw_fields);
const result = {} as any; // const result = {} as any;
for (const f of fields) { // for (const f of fields) {
select[f.name] = true; // select[f.name] = true;
if (f.relation) { // if (f.relation) {
select[f.name] = { // select[f.name] = {
select: {}, // select: {},
}; // };
for (const r of f.relation.fields) { // for (const r of f.relation.fields) {
select[f.name].select[r.name] = true; // select[f.name].select[r.name] = true;
if (r.is_pk) { // if (r.is_pk) {
pks[f.name] = r.name; // pks[f.name] = r.name;
} // }
} // }
} // }
if (f.is_pk) { // if (f.is_pk) {
pk = f; // pk = f;
} // }
} // }
if (!pk) { // if (!pk) {
alert("Failed to generate! Primary Key not found. "); // alert("Failed to generate! Primary Key not found. ");
return; // return;
} // }
if (pk) {
const code = {} as any; // if (pk) {
if (data["on_load"]) { // const code = {} as any;
result["on_load"] = data["on_load"]; // if (data["on_load"]) {
result["on_load"].value = on_load({ // result["on_load"] = data["on_load"];
pk: pk.name, // result["on_load"].value = on_load({
pks, // pk: pk.name,
select, // pks,
table, // select,
opt: is_md ? { is_md: true } : undefined, // table,
}); // opt: is_md ? { is_md: true } : undefined,
code.on_load = result["on_load"].value; // });
} // code.on_load = result["on_load"].value;
// }
if (data["on_submit"]) {
result["on_submit"] = data["on_submit"]; // if (data["on_submit"]) {
result["on_submit"].value = on_submit({ pk, table, select, pks }); // result["on_submit"] = data["on_submit"];
code.on_submit = result["on_submit"].value; // 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)) { // const res = await codeBuild(code);
result[k].valueBuilt = v[1]; // for (const [k, v] of Object.entries(res)) {
} // result[k].valueBuilt = v[1];
// }
result["body"] = data["body"];
result.body.content.childs = []; // result["body"] = data["body"];
for (const item of fields.filter((e) => !e.is_pk)) { // result.body.content.childs = [];
result.body.content.childs.push( // for (const item of fields.filter((e) => !e.is_pk)) {
await newField(item, { parent_table: table }) // result.body.content.childs.push(
); // await newField(item, { parent_table: table })
} // );
} // }
modify(result); // }
// modify(result);
}; };