|
|
@ -4,11 +4,16 @@ |
|
|
|
|
|
|
|
|
|
|
|
<div class="d-flex align-center img-container flex-grow-1 hm-items"> |
|
|
|
<div class="d-flex align-center img-container flex-grow-1 hm-items"> |
|
|
|
<template v-if="value"> |
|
|
|
<template v-if="value"> |
|
|
|
<v-chip small v-for="(v,j) in value.map(v=>Object.values(v)[2])" |
|
|
|
<item-chip v-for="(v,j) in value" |
|
|
|
:color="colors[j%colors.length]" :key="j">{{ |
|
|
|
:active="active" |
|
|
|
v |
|
|
|
:item="v" |
|
|
|
}} |
|
|
|
:color="colors[j%colors.length]" |
|
|
|
</v-chip> |
|
|
|
:value="Object.values(v)[2]" |
|
|
|
|
|
|
|
:key="j" |
|
|
|
|
|
|
|
@edit="editChild" |
|
|
|
|
|
|
|
@unlink="unlinkChild" |
|
|
|
|
|
|
|
></item-chip> |
|
|
|
|
|
|
|
|
|
|
|
</template> |
|
|
|
</template> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div class=" align-center justify-center px-1 flex-shrink-1" :class="{'d-none': !active, 'd-flex':active }"> |
|
|
|
<div class=" align-center justify-center px-1 flex-shrink-1" :class="{'d-none': !active, 'd-flex':active }"> |
|
|
@ -17,45 +22,18 @@ |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<v-dialog v-if="newRecordModal" v-model="newRecordModal" width="600"> |
|
|
|
<list-items |
|
|
|
<v-card width="600" color="backgroundColor"> |
|
|
|
v-if="newRecordModal" |
|
|
|
<v-card-title class="textColor--text mx-2">Add Record</v-card-title> |
|
|
|
:hm="true" |
|
|
|
<v-card-text> |
|
|
|
:size="10" |
|
|
|
<v-text-field |
|
|
|
:meta="childMeta" |
|
|
|
hide-details |
|
|
|
:primary-col="childPrimaryCol" |
|
|
|
dense |
|
|
|
:primary-key="childPrimaryKey" |
|
|
|
outlined |
|
|
|
v-model="newRecordModal" |
|
|
|
placeholder="Search record" |
|
|
|
:api="childApi" |
|
|
|
class="mb-2 mx-2 caption" |
|
|
|
@add-new-record="insertAndAddNewChildRecord" |
|
|
|
/> |
|
|
|
@add="addChildToParent" |
|
|
|
|
|
|
|
:query-params="{...childQueryParams, conditionGraph }"/> |
|
|
|
<div class="items-container"> |
|
|
|
|
|
|
|
<template v-if="list"> |
|
|
|
|
|
|
|
<v-card |
|
|
|
|
|
|
|
v-for="(p,i) in list.list" |
|
|
|
|
|
|
|
class="ma-2 child-card" |
|
|
|
|
|
|
|
outlined |
|
|
|
|
|
|
|
v-ripple |
|
|
|
|
|
|
|
@click="addChildToParent(p)" |
|
|
|
|
|
|
|
:key="i" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<v-card-title class="primary-value textColor--text text--lighten-2">{{ p[childPrimaryCol] }} |
|
|
|
|
|
|
|
<span class="grey--text caption primary-key" |
|
|
|
|
|
|
|
v-if="childPrimaryKey">(Primary Key : {{ p[childPrimaryKey] }})</span> |
|
|
|
|
|
|
|
</v-card-title> |
|
|
|
|
|
|
|
</v-card> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</v-card-text> |
|
|
|
|
|
|
|
<v-card-actions class="justify-center pb-6 "> |
|
|
|
|
|
|
|
<v-btn small outlined class="caption" color="primary"> |
|
|
|
|
|
|
|
<v-icon>mdi-plus</v-icon> |
|
|
|
|
|
|
|
Add New Record |
|
|
|
|
|
|
|
</v-btn> |
|
|
|
|
|
|
|
</v-card-actions> |
|
|
|
|
|
|
|
</v-card> |
|
|
|
|
|
|
|
</v-dialog> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<v-dialog v-if="childListModal" v-model="childListModal" width="600"> |
|
|
|
<v-dialog v-if="childListModal" v-model="childListModal" width="600"> |
|
|
|
<v-card width="600" color="backgroundColor"> |
|
|
|
<v-card width="600" color="backgroundColor"> |
|
|
@ -130,6 +108,41 @@ |
|
|
|
:heading="confirmMessage" |
|
|
|
:heading="confirmMessage" |
|
|
|
> |
|
|
|
> |
|
|
|
</dlg-label-submit-cancel> |
|
|
|
</dlg-label-submit-cancel> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- todo : move to listitem component --> |
|
|
|
|
|
|
|
<v-dialog |
|
|
|
|
|
|
|
:overlay-opacity="0.8" |
|
|
|
|
|
|
|
v-if="selectedChild" |
|
|
|
|
|
|
|
width="1000px" |
|
|
|
|
|
|
|
max-width="100%" |
|
|
|
|
|
|
|
class=" mx-auto" |
|
|
|
|
|
|
|
v-model="expandFormModal"> |
|
|
|
|
|
|
|
<component |
|
|
|
|
|
|
|
v-if="selectedChild" |
|
|
|
|
|
|
|
:is="form" |
|
|
|
|
|
|
|
:db-alias="nodes.dbAlias" |
|
|
|
|
|
|
|
:has-many="childMeta.hasMany" |
|
|
|
|
|
|
|
:belongs-to="childMeta.belongsTo" |
|
|
|
|
|
|
|
:table="childMeta.tn" |
|
|
|
|
|
|
|
v-model="selectedChild" |
|
|
|
|
|
|
|
:old-row="{...selectedChild}" |
|
|
|
|
|
|
|
:meta="childMeta" |
|
|
|
|
|
|
|
:sql-ui="sqlUi" |
|
|
|
|
|
|
|
:primary-value-column="childPrimaryCol" |
|
|
|
|
|
|
|
:api="childApi" |
|
|
|
|
|
|
|
:available-columns="childAvailableColumns" |
|
|
|
|
|
|
|
icon-color="warning" |
|
|
|
|
|
|
|
:nodes="nodes" |
|
|
|
|
|
|
|
:query-params="childQueryParams" |
|
|
|
|
|
|
|
ref="expandedForm" |
|
|
|
|
|
|
|
:is-new="isNewChild" |
|
|
|
|
|
|
|
@cancel="selectedChild = null" |
|
|
|
|
|
|
|
@input="onChildSave" |
|
|
|
|
|
|
|
></component> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</v-dialog> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
|
@ -137,11 +150,13 @@ |
|
|
|
import colors from "@/mixins/colors"; |
|
|
|
import colors from "@/mixins/colors"; |
|
|
|
import ApiFactory from "@/components/project/spreadsheet/apis/apiFactory"; |
|
|
|
import ApiFactory from "@/components/project/spreadsheet/apis/apiFactory"; |
|
|
|
import DlgLabelSubmitCancel from "@/components/utils/dlgLabelSubmitCancel"; |
|
|
|
import DlgLabelSubmitCancel from "@/components/utils/dlgLabelSubmitCancel"; |
|
|
|
|
|
|
|
import ListItems from "@/components/project/spreadsheet/components/virtualCell/components/listItems"; |
|
|
|
|
|
|
|
import ItemChip from "@/components/project/spreadsheet/components/virtualCell/components/item-chip"; |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
export default { |
|
|
|
name: "many-to-many-cell", |
|
|
|
name: "many-to-many-cell", |
|
|
|
mixins: [colors], |
|
|
|
mixins: [colors], |
|
|
|
components: {DlgLabelSubmitCancel}, |
|
|
|
components: {ItemChip, ListItems, DlgLabelSubmitCancel}, |
|
|
|
props: { |
|
|
|
props: { |
|
|
|
value: [Object, Array], |
|
|
|
value: [Object, Array], |
|
|
|
meta: [Object], |
|
|
|
meta: [Object], |
|
|
@ -151,30 +166,51 @@ export default { |
|
|
|
api: [Object, Function], |
|
|
|
api: [Object, Function], |
|
|
|
sqlUi: [Object, Function], |
|
|
|
sqlUi: [Object, Function], |
|
|
|
active: Boolean, |
|
|
|
active: Boolean, |
|
|
|
isNew: Boolean |
|
|
|
isNew: Boolean, |
|
|
|
}, |
|
|
|
}, |
|
|
|
data: () => ({ |
|
|
|
data: () => ({ |
|
|
|
|
|
|
|
isNewChild: false, |
|
|
|
newRecordModal: false, |
|
|
|
newRecordModal: false, |
|
|
|
childListModal: false, |
|
|
|
childListModal: false, |
|
|
|
childMeta: null, |
|
|
|
childMeta: null, |
|
|
|
assocMeta: null, |
|
|
|
assocMeta: null, |
|
|
|
list: null, |
|
|
|
// list: null, |
|
|
|
childList: null, |
|
|
|
childList: null, |
|
|
|
dialogShow: false, |
|
|
|
dialogShow: false, |
|
|
|
confirmAction: null, |
|
|
|
confirmAction: null, |
|
|
|
confirmMessage: '', |
|
|
|
confirmMessage: '', |
|
|
|
selectedChild:null |
|
|
|
selectedChild: null, |
|
|
|
|
|
|
|
expandFormModal: false |
|
|
|
}), |
|
|
|
}), |
|
|
|
|
|
|
|
|
|
|
|
methods: { |
|
|
|
methods: { |
|
|
|
|
|
|
|
async onChildSave(child) { |
|
|
|
|
|
|
|
if (this.isNewChild) { |
|
|
|
|
|
|
|
await this.addChildToParent(child) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.$emit('loadTableData') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
async showChildListModal() { |
|
|
|
async showChildListModal() { |
|
|
|
this.childListModal = true; |
|
|
|
this.childListModal = true; |
|
|
|
await this.getChildMeta(); |
|
|
|
await this.loadChildMeta(); |
|
|
|
const pid = this.meta.columns.filter((c) => c.pk).map(c => this.row[c._cn]).join('___'); |
|
|
|
const pid = this.meta.columns.filter((c) => c.pk).map(c => this.row[c._cn]).join('___'); |
|
|
|
const _cn = this.childMeta.columns.find(c => c.cn === this.hm.cn)._cn; |
|
|
|
const _cn = this.childMeta.columns.find(c => c.cn === this.hm.cn)._cn; |
|
|
|
this.childList = await this.childApi.paginatedList({ |
|
|
|
this.childList = await this.childApi.paginatedList({ |
|
|
|
where: `(${_cn},eq,${pid})` |
|
|
|
where: `(${_cn},eq,${pid})` |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
}, async unlinkChild(child) { |
|
|
|
|
|
|
|
await Promise.all([this.loadChildMeta(), this.loadAssociateTableMeta()]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const _pcn = this.meta.columns.find(c => c.cn === this.mm.cn)._cn; |
|
|
|
|
|
|
|
const _ccn = this.childMeta.columns.find(c => c.cn === this.mm.rcn)._cn; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const apcn = this.assocMeta.columns.find(c => c.cn === this.mm.vcn).cn; |
|
|
|
|
|
|
|
const accn = this.assocMeta.columns.find(c => c.cn === this.mm.vrcn).cn; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const id = this.assocMeta.columns.filter((c) => c.cn === apcn || c.cn === accn).map(c => c.cn === apcn ? this.row[_pcn] : child[_ccn]).join('___'); |
|
|
|
|
|
|
|
await this.assocApi.delete(id) |
|
|
|
|
|
|
|
this.$emit('loadTableData') |
|
|
|
}, |
|
|
|
}, |
|
|
|
async removeChild(child) { |
|
|
|
async removeChild(child) { |
|
|
|
this.dialogShow = true; |
|
|
|
this.dialogShow = true; |
|
|
@ -192,7 +228,7 @@ export default { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
async getChildMeta() { |
|
|
|
async loadChildMeta() { |
|
|
|
// todo: optimize |
|
|
|
// todo: optimize |
|
|
|
if (!this.childMeta) { |
|
|
|
if (!this.childMeta) { |
|
|
|
const parentTableData = await this.$store.dispatch('sqlMgr/ActSqlOp', [{ |
|
|
|
const parentTableData = await this.$store.dispatch('sqlMgr/ActSqlOp', [{ |
|
|
@ -204,7 +240,7 @@ export default { |
|
|
|
this.childMeta = JSON.parse(parentTableData.meta) |
|
|
|
this.childMeta = JSON.parse(parentTableData.meta) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
async getAssociateTableMeta() { |
|
|
|
async loadAssociateTableMeta() { |
|
|
|
// todo: optimize |
|
|
|
// todo: optimize |
|
|
|
if (!this.childMeta) { |
|
|
|
if (!this.childMeta) { |
|
|
|
const assocTableData = await this.$store.dispatch('sqlMgr/ActSqlOp', [{ |
|
|
|
const assocTableData = await this.$store.dispatch('sqlMgr/ActSqlOp', [{ |
|
|
@ -217,9 +253,9 @@ export default { |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
async showNewRecordModal() { |
|
|
|
async showNewRecordModal() { |
|
|
|
|
|
|
|
await Promise.all([this.loadChildMeta(), this.loadAssociateTableMeta()]); |
|
|
|
this.newRecordModal = true; |
|
|
|
this.newRecordModal = true; |
|
|
|
await Promise.all([this.getChildMeta(), this.getAssociateTableMeta()]); |
|
|
|
// this.list = await this.childApi.paginatedList({}) |
|
|
|
this.list = await this.childApi.paginatedList({}) |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
async addChildToParent(child) { |
|
|
|
async addChildToParent(child) { |
|
|
|
const cid = this.childMeta.columns.filter((c) => c.pk).map(c => child[c._cn]).join('___'); |
|
|
|
const cid = this.childMeta.columns.filter((c) => c.pk).map(c => child[c._cn]).join('___'); |
|
|
@ -227,15 +263,42 @@ export default { |
|
|
|
|
|
|
|
|
|
|
|
const vcidCol = this.assocMeta.columns.find(c => c.cn === this.mm.vrcn)._cn; |
|
|
|
const vcidCol = this.assocMeta.columns.find(c => c.cn === this.mm.vrcn)._cn; |
|
|
|
const vpidCol = this.assocMeta.columns.find(c => c.cn === this.mm.vcn)._cn; |
|
|
|
const vpidCol = this.assocMeta.columns.find(c => c.cn === this.mm.vcn)._cn; |
|
|
|
|
|
|
|
try { |
|
|
|
await this.assocApi.insert({ |
|
|
|
await this.assocApi.insert({ |
|
|
|
[vcidCol]: cid, |
|
|
|
[vcidCol]: cid, |
|
|
|
[vpidCol]: pid |
|
|
|
[vpidCol]: pid |
|
|
|
}); |
|
|
|
}); |
|
|
|
this.newRecordModal = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.$emit('loadTableData') |
|
|
|
this.$emit('loadTableData') |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
// todo: handle |
|
|
|
|
|
|
|
console.log(e) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
this.newRecordModal = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async insertAndAddNewChildRecord() { |
|
|
|
|
|
|
|
this.newRecordModal = false; |
|
|
|
|
|
|
|
await this.loadChildMeta(); |
|
|
|
|
|
|
|
this.isNewChild = true; |
|
|
|
|
|
|
|
this.selectedChild = { |
|
|
|
|
|
|
|
[this.childForeignKey]: this.parentId |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
this.expandFormModal = true; |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
this.$refs.expandedForm && this.$refs.expandedForm.$set(this.$refs.expandedForm.changedColumns, this.childForeignKey, true) |
|
|
|
|
|
|
|
}, 500) |
|
|
|
|
|
|
|
}, async editChild(child) { |
|
|
|
|
|
|
|
await this.loadChildMeta(); |
|
|
|
|
|
|
|
this.isNewChild = false; |
|
|
|
|
|
|
|
this.selectedChild = child; |
|
|
|
|
|
|
|
this.expandFormModal = true; |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
|
|
|
|
this.$refs.expandedForm && this.$refs.expandedForm.reload() |
|
|
|
|
|
|
|
}, 500) |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
computed: { |
|
|
|
childApi() { |
|
|
|
childApi() { |
|
|
@ -264,7 +327,43 @@ export default { |
|
|
|
}, |
|
|
|
}, |
|
|
|
parentPrimaryKey() { |
|
|
|
parentPrimaryKey() { |
|
|
|
return this.meta && (this.meta.columns.find(c => c.pk) || {})._cn |
|
|
|
return this.meta && (this.meta.columns.find(c => c.pk) || {})._cn |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
childQueryParams() { |
|
|
|
|
|
|
|
if (!this.childMeta) return {} |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
childs: (this.childMeta && this.childMeta.hasMany && this.childMeta.hasMany.map(hm => hm.tn).join()) || '', |
|
|
|
|
|
|
|
parents: (this.childMeta && this.childMeta.belongsTo && this.childMeta.belongsTo.map(hm => hm.rtn).join()) || '', |
|
|
|
|
|
|
|
many: (this.childMeta && this.childMeta.manyToMany && this.childMeta.manyToMany.map(mm => mm.rtn).join()) || '' |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
conditionGraph() { |
|
|
|
|
|
|
|
// if (!this.childMeta || !this.assocMeta) return null; |
|
|
|
|
|
|
|
// return { |
|
|
|
|
|
|
|
// [this.assocMeta.tn]: { |
|
|
|
|
|
|
|
// "relationType": "hm", |
|
|
|
|
|
|
|
// [this.assocMeta.columns.find(c => c.cn === this.mm.vcn).cn]: { |
|
|
|
|
|
|
|
// "eq": this.row[this.parentPrimaryKey] |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
childAvailableColumns() { |
|
|
|
|
|
|
|
const hideCols = ['created_at', 'updated_at']; |
|
|
|
|
|
|
|
if (!this.childMeta) return []; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const columns = []; |
|
|
|
|
|
|
|
if (this.childMeta.columns) { |
|
|
|
|
|
|
|
columns.push(...this.childMeta.columns.filter(c => !(c.pk && c.ai) && !hideCols.includes(c.cn))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.childMeta.v) { |
|
|
|
|
|
|
|
columns.push(...this.childMeta.v.map(v => ({...v, virtual: 1}))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return columns; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// todo: |
|
|
|
|
|
|
|
form() { |
|
|
|
|
|
|
|
return this.selectedChild ? () => import("@/components/project/spreadsheet/components/expandedForm") : 'span'; |
|
|
|
|
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|