fix relation
This commit is contained in:
parent
37cfd190d1
commit
c742e27887
|
|
@ -110,6 +110,7 @@ export const newField = async (
|
||||||
table: arg.relation.to.table,
|
table: arg.relation.to.table,
|
||||||
select: res.select,
|
select: res.select,
|
||||||
pks: {},
|
pks: {},
|
||||||
|
type: arg.type === "has-many" ? "typeahead" : "dropdown",
|
||||||
});
|
});
|
||||||
if (["has-one"].includes(arg.type)) {
|
if (["has-one"].includes(arg.type)) {
|
||||||
const rel__gen_fields = JSON.stringify(
|
const rel__gen_fields = JSON.stringify(
|
||||||
|
|
@ -171,7 +172,10 @@ export const newField = async (
|
||||||
result.on_load = `() => { return []; }`;
|
result.on_load = `() => { return []; }`;
|
||||||
}
|
}
|
||||||
let child: any = { childs: [] };
|
let child: any = { childs: [] };
|
||||||
const relation = arg.relation?.fields.filter((e) => get(e, "name") !== opt.parent_table) || [];
|
const relation =
|
||||||
|
arg.relation?.fields.filter(
|
||||||
|
(e) => get(e, "name") !== opt.parent_table
|
||||||
|
) || [];
|
||||||
let rel__gen_fields: any = JSON.stringify(
|
let rel__gen_fields: any = JSON.stringify(
|
||||||
relation.map((e) => {
|
relation.map((e) => {
|
||||||
const v = (e as any).value;
|
const v = (e as any).value;
|
||||||
|
|
|
||||||
|
|
@ -17,11 +17,13 @@ export const genRelMany = (prop: {
|
||||||
if (master) {
|
if (master) {
|
||||||
const select = generateSelect(master.relation.fields);
|
const select = generateSelect(master.relation.fields);
|
||||||
|
|
||||||
|
console.log(master);
|
||||||
result.on_load = on_load_rel({
|
result.on_load = on_load_rel({
|
||||||
pk: select.pk,
|
pk: select.pk,
|
||||||
table: master.name,
|
table: master.name,
|
||||||
select: select.select,
|
select: select.select,
|
||||||
pks: {},
|
pks: {},
|
||||||
|
type: "typeahead",
|
||||||
});
|
});
|
||||||
const pk_master = master.relation.fields.find((e: any) => get(e, "is_pk"));
|
const pk_master = master.relation.fields.find((e: any) => get(e, "is_pk"));
|
||||||
const get_value = `\
|
const get_value = `\
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ export const on_load_rel = ({
|
||||||
table,
|
table,
|
||||||
select,
|
select,
|
||||||
pks,
|
pks,
|
||||||
type
|
type,
|
||||||
}: {
|
}: {
|
||||||
pk: string;
|
pk: string;
|
||||||
table: string;
|
table: string;
|
||||||
|
|
@ -25,6 +25,11 @@ export const on_load_rel = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const skip_select =
|
||||||
|
!isEmptyString(type) &&
|
||||||
|
["checkbox", "typeahead", "button"].includes(type as any);
|
||||||
|
|
||||||
|
console.log(skip_select, type);
|
||||||
return `\
|
return `\
|
||||||
async (arg: {
|
async (arg: {
|
||||||
reload: () => Promise<void>;
|
reload: () => Promise<void>;
|
||||||
|
|
@ -38,9 +43,12 @@ async (arg: {
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise(async (done) => {
|
return new Promise(async (done) => {
|
||||||
${!isEmptyString(type) && ["checkbox", "typeahead", "button"].includes(type as any) ? `` : `const fields = parseGenField(rel__gen_fields);
|
${
|
||||||
const res = generateSelect(fields);`}
|
skip_select
|
||||||
|
? ``
|
||||||
|
: `
|
||||||
|
const fields = parseGenField(rel__gen_fields);
|
||||||
|
const res = generateSelect(fields);
|
||||||
|
|
||||||
const is_tree =
|
const is_tree =
|
||||||
typeof rel__feature !== "undefined" &&
|
typeof rel__feature !== "undefined" &&
|
||||||
|
|
@ -49,21 +57,28 @@ async (arg: {
|
||||||
|
|
||||||
if (is_tree && typeof rel__id_parent === "string" && rel__id_parent) {
|
if (is_tree && typeof rel__id_parent === "string" && rel__id_parent) {
|
||||||
res.select[rel__id_parent] = true;
|
res.select[rel__id_parent] = true;
|
||||||
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const items = await db.${table}.findMany({
|
|
||||||
${!isEmptyString(type) && ["checkbox", "typeahead", "button"].includes(type as any) ? `` : `select: {
|
let items = await db.${table}.findMany({
|
||||||
...${JSON.stringify(select)},
|
select: {
|
||||||
...(res?.select || {})
|
...${JSON.stringify(select)}
|
||||||
},`}
|
${skip_select ? `` : `,...(res?.select || {})`}
|
||||||
|
},
|
||||||
orderBy: arg.orderBy || {
|
orderBy: arg.orderBy || {
|
||||||
${pk}: "desc"
|
${pk}: "desc"
|
||||||
},
|
},
|
||||||
...arg.paging,
|
...arg.paging,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
${
|
||||||
|
skip_select
|
||||||
|
? ""
|
||||||
|
: `\
|
||||||
if (is_tree && typeof rel__id_parent === "string" && rel__id_parent) {
|
if (is_tree && typeof rel__id_parent === "string" && rel__id_parent) {
|
||||||
items = sortTree(items, rel__id_parent, "${pk}");
|
items = sortTree(items, rel__id_parent, "${pk}");
|
||||||
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
if(items.length){
|
if(items.length){
|
||||||
|
|
@ -79,9 +94,10 @@ async (arg: {
|
||||||
}
|
}
|
||||||
|
|
||||||
let blank: any = undefined;
|
let blank: any = undefined;
|
||||||
if (ext__required !== "y") {
|
if ((ext__required as any) !== "y" && (sub_type as any) === 'dropdown') {
|
||||||
blank = { value: undefined, label: "", data: {} };
|
blank = { value: undefined, label: "", data: {} };
|
||||||
}
|
}
|
||||||
|
|
||||||
done(
|
done(
|
||||||
[
|
[
|
||||||
blank,
|
blank,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
.rdg-dark {
|
|
||||||
--rdg-color-scheme: light !important;
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue