mirror of
https://github.com/veops/cmdb.git
synced 2025-08-26 04:44:43 +08:00
feat(ui): CI - relation table by subscribed attr
This commit is contained in:
@@ -100,6 +100,7 @@ import _ from 'lodash'
|
|||||||
import { getCanEditByParentIdChildId } from '@/modules/cmdb/api/CITypeRelation'
|
import { getCanEditByParentIdChildId } from '@/modules/cmdb/api/CITypeRelation'
|
||||||
import { deleteCIRelationView } from '@/modules/cmdb/api/CIRelation'
|
import { deleteCIRelationView } from '@/modules/cmdb/api/CIRelation'
|
||||||
import { searchCI } from '@/modules/cmdb/api/ci'
|
import { searchCI } from '@/modules/cmdb/api/ci'
|
||||||
|
import { getSubscribeAttributes } from '@/modules/cmdb/api/preference'
|
||||||
|
|
||||||
import CIDetailTableTitle from './ciDetailTableTitle.vue'
|
import CIDetailTableTitle from './ciDetailTableTitle.vue'
|
||||||
import AddTableModal from '@/modules/cmdb/views/relation_views/modules/AddTableModal.vue'
|
import AddTableModal from '@/modules/cmdb/views/relation_views/modules/AddTableModal.vue'
|
||||||
@@ -194,28 +195,22 @@ export default {
|
|||||||
|
|
||||||
const cloneRelationData = _.cloneDeep(relationData)
|
const cloneRelationData = _.cloneDeep(relationData)
|
||||||
|
|
||||||
const [
|
const allCITypes = [
|
||||||
{
|
...cloneRelationData.parentCITypeList,
|
||||||
ciTypes: parentCITypes,
|
...cloneRelationData.childCITypeList
|
||||||
|
]
|
||||||
|
await this.handleSubscribeAttributes(allCITypes)
|
||||||
|
|
||||||
|
const {
|
||||||
columns: parentColumns,
|
columns: parentColumns,
|
||||||
jsonAttr: parentJSONAttr,
|
jsonAttr: parentJSONAttr,
|
||||||
canEdit: parentCanEdit
|
} = this.handleCITypeList(cloneRelationData.parentCITypeList, true)
|
||||||
},
|
const {
|
||||||
{
|
|
||||||
ciTypes: childCITypes,
|
|
||||||
columns: childColumns,
|
columns: childColumns,
|
||||||
jsonAttr: childJSONAttr,
|
jsonAttr: childJSONAttr,
|
||||||
canEdit: childCanEdit
|
} = this.handleCITypeList(cloneRelationData.childCITypeList, false)
|
||||||
},
|
|
||||||
] = await Promise.all([
|
|
||||||
this.getParentCITypes(cloneRelationData.parentCITypeList),
|
|
||||||
this.getChildCITypes(cloneRelationData.childCITypeList)
|
|
||||||
])
|
|
||||||
|
|
||||||
this.allCITypes = [
|
this.allCITypes = allCITypes
|
||||||
...parentCITypes,
|
|
||||||
...childCITypes
|
|
||||||
]
|
|
||||||
this.allColumns = {
|
this.allColumns = {
|
||||||
...parentColumns,
|
...parentColumns,
|
||||||
...childColumns
|
...childColumns
|
||||||
@@ -224,14 +219,12 @@ export default {
|
|||||||
...parentJSONAttr,
|
...parentJSONAttr,
|
||||||
...childJSONAttr
|
...childJSONAttr
|
||||||
}
|
}
|
||||||
this.allCanEdit = {
|
|
||||||
...parentCanEdit,
|
await this.getCanEditList(this.allCITypes)
|
||||||
...childCanEdit
|
|
||||||
}
|
|
||||||
|
|
||||||
const [parentCIs, childCIs] = await Promise.all([
|
const [parentCIs, childCIs] = await Promise.all([
|
||||||
this.getParentCIs(cloneRelationData.parentCIList),
|
this.handleCIList(cloneRelationData.parentCIList, true),
|
||||||
this.getChildCIs(cloneRelationData.childCIList)
|
this.handleCIList(cloneRelationData.childCIList, false)
|
||||||
])
|
])
|
||||||
this.allCIList = {
|
this.allCIList = {
|
||||||
...parentCIs,
|
...parentCIs,
|
||||||
@@ -257,50 +250,15 @@ export default {
|
|||||||
this.handleReferenceCINameMap()
|
this.handleReferenceCINameMap()
|
||||||
},
|
},
|
||||||
|
|
||||||
async getParentCITypes(ciTypes) {
|
handleCITypeList(list, isParent) {
|
||||||
const canEdit = {}
|
|
||||||
for (let i = 0; i < ciTypes.length; i++) {
|
|
||||||
ciTypes[i].isParent = true
|
|
||||||
await getCanEditByParentIdChildId(ciTypes[i].id, this.typeId).then((p_res) => {
|
|
||||||
canEdit[ciTypes[i].id] = p_res.result
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const { columns, jsonAttr } = this.handleCITypeList(ciTypes || [])
|
|
||||||
|
|
||||||
return {
|
|
||||||
ciTypes,
|
|
||||||
columns,
|
|
||||||
jsonAttr,
|
|
||||||
canEdit
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async getChildCITypes(ciTypes) {
|
|
||||||
const canEdit = {}
|
|
||||||
for (let i = 0; i < ciTypes.length; i++) {
|
|
||||||
ciTypes[i].isParent = false
|
|
||||||
await getCanEditByParentIdChildId(this.typeId, ciTypes[i].id).then((c_res) => {
|
|
||||||
canEdit[ciTypes[i].id] = c_res.result
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const { columns, jsonAttr } = this.handleCITypeList(ciTypes)
|
|
||||||
return {
|
|
||||||
ciTypes,
|
|
||||||
columns,
|
|
||||||
jsonAttr,
|
|
||||||
canEdit
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
handleCITypeList(list) {
|
|
||||||
const CIColumns = {}
|
const CIColumns = {}
|
||||||
const CIJSONAttr = {}
|
const CIJSONAttr = {}
|
||||||
|
|
||||||
list.forEach((item) => {
|
list.forEach((item) => {
|
||||||
const columns = []
|
const columns = []
|
||||||
const jsonAttr = []
|
const jsonAttr = []
|
||||||
|
|
||||||
|
item.isParent = isParent
|
||||||
item.attributes.forEach((attr) => {
|
item.attributes.forEach((attr) => {
|
||||||
const column = {
|
const column = {
|
||||||
key: 'p_' + attr.id,
|
key: 'p_' + attr.id,
|
||||||
@@ -343,33 +301,67 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getParentCIs(ciList) {
|
async getCanEditList(allCITypes) {
|
||||||
const cis = {}
|
const promises = allCITypes.map((ciType) => {
|
||||||
ciList.forEach((item) => {
|
let parentId = ciType.id
|
||||||
this.allJSONAttr[item._type].forEach((attr) => {
|
let childId = this.typeId
|
||||||
item[`${attr}`] = item[`${attr}`] ? JSON.stringify(item[`${attr}`]) : ''
|
|
||||||
})
|
|
||||||
this.formatCI(item)
|
|
||||||
item.isParent = true
|
|
||||||
|
|
||||||
if (item._type in cis) {
|
if (!ciType.isParent) {
|
||||||
cis[item._type].push(item)
|
parentId = this.typeId
|
||||||
} else {
|
childId = ciType.id
|
||||||
cis[item._type] = [item]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return getCanEditByParentIdChildId(parentId, childId).then((res) => {
|
||||||
|
return { id: ciType.id, canEdit: res.result }
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return cis
|
const allCanEdit = {}
|
||||||
|
|
||||||
|
const res = await Promise.all(promises)
|
||||||
|
if (res?.length) {
|
||||||
|
res.map((item) => {
|
||||||
|
allCanEdit[item.id] = item.canEdit
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
this.allCanEdit = allCanEdit
|
||||||
},
|
},
|
||||||
|
|
||||||
async getChildCIs(ciList) {
|
async handleSubscribeAttributes(allCITypes) {
|
||||||
|
const promises = allCITypes.map((ciType, index) => {
|
||||||
|
return getSubscribeAttributes(ciType.id).then((res) => {
|
||||||
|
return {
|
||||||
|
...(res || {}),
|
||||||
|
id: ciType.id,
|
||||||
|
indexInAll: index
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const res = await Promise.all(promises)
|
||||||
|
|
||||||
|
if (res?.length) {
|
||||||
|
res.forEach((item) => {
|
||||||
|
if (
|
||||||
|
allCITypes?.[item.indexInAll]?.attributes &&
|
||||||
|
item?.is_subscribed
|
||||||
|
) {
|
||||||
|
allCITypes[item.indexInAll].attributes = item.attributes
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return allCITypes
|
||||||
|
},
|
||||||
|
|
||||||
|
async handleCIList(ciList, isParent) {
|
||||||
const cis = {}
|
const cis = {}
|
||||||
ciList.forEach((item) => {
|
ciList.forEach((item) => {
|
||||||
this.allJSONAttr[item._type].forEach((attr) => {
|
this.allJSONAttr[item._type].forEach((attr) => {
|
||||||
item[`${attr}`] = item[`${attr}`] ? JSON.stringify(item[`${attr}`]) : ''
|
item[`${attr}`] = item[`${attr}`] ? JSON.stringify(item[`${attr}`]) : ''
|
||||||
})
|
})
|
||||||
this.formatCI(item)
|
this.formatCI(item)
|
||||||
item.isParent = false
|
item.isParent = isParent
|
||||||
|
|
||||||
if (item._type in cis) {
|
if (item._type in cis) {
|
||||||
cis[item._type].push(item)
|
cis[item._type].push(item)
|
||||||
@@ -590,6 +582,7 @@ export default {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 15px 17px;
|
padding: 15px 17px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
min-height: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-item {
|
&-item {
|
||||||
|
Reference in New Issue
Block a user