This commit is contained in:
rizrmd 2024-06-20 14:34:47 -07:00
parent 18d24c37b8
commit afed8e9d40
5 changed files with 23 additions and 26 deletions

View File

@ -26,18 +26,18 @@ export const on_load_rel = ({
}
return `\
(arg: {
async (arg: {
reload: () => Promise<void>;
orderBy?: Record<string, "asc" | "desc">;
paging: { take: number; skip: number };
mode: 'count' | 'query'
}) => {
if (isEditor) return [${JSON.stringify(sample)}];
if (arg.mode === 'count') {
return await db.${table}.count();
}
return new Promise(async (done) => {
if (arg.mode === 'count') {
return await db.${table}.count();
}
${!isEmptyString(type) && ["checkbox", "typeahead", "button"].includes(type as any) ? `` : `const fields = parseGenField(rel__gen_fields);
const res = generateSelect(fields);`}

View File

@ -265,10 +265,7 @@ export const TableList: FC<TableListProp> = ({
);
let childs: any[] = [];
let checkedBox: any[] = [];
let sub_name = "fields";
// if (mode === "table") sub_name = "columns";
switch (mode) {
case "table":

View File

@ -34,20 +34,20 @@ export const on_load = ({
}
return `\
(arg: TableOnLoad) => {
async (arg: TableOnLoad) => {
if (isEditor)
return [${JSON.stringify(sample)}];
let where = arg.where;
if (arg.mode === "count") {
return await db.${table}.count({
where: {
...where,
},
});
}
return new Promise(async (done) => {
let where = arg.where;
if (arg.mode === "count") {
return await db.${table}.count({
where: {
...where,
},
});
}
const items = await db.${table}.findMany({
select: ${JSON.stringify(select, null, 2).split("\n").join("\n ")},
orderBy: arg.orderBy || {

View File

@ -26,14 +26,14 @@ export const on_load = ({
}
return `\
(arg: TableOnLoad) => {
async (arg: TableOnLoad) => {
if (isEditor) return [${JSON.stringify(sample)}];
return new Promise(async (done) => {
if (arg.mode === 'count') {
return await db.${table}.count();
}
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 || {

View File

@ -1,7 +1,7 @@
import { GFCol, PropOptRaw, createItem, formatName } from "../utils";
import get from "lodash.get";
import { GenMasterDetailArg, codeBuild } from "./utils";
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") {
@ -99,12 +99,12 @@ type ActionItem =
id: "567d5362-2cc8-4ca5-a531-f771a5c866c2",
props: {
name: arg.gen_table,
gen_table: 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)],
gen__fields: [JSON.stringify(arg.gen_fields)],
child: {
childs: [],
},