mirror of https://github.com/veops/cmdb.git
fix delete ci relation
This commit is contained in:
parent
81fe850627
commit
cc2cdbcc9f
|
@ -548,7 +548,7 @@ class CIRelationManager(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def delete(cr_id):
|
def delete(cr_id):
|
||||||
cr = CIRelation.get_by_id(cr_id) or abort(404, "CIRelation <{0}> is not existed".format(cr_id))
|
cr = CIRelation.get_by_id(cr_id) or abort(404, "CIRelation <{0}> is not existed".format(cr_id))
|
||||||
cr.soft_delete()
|
cr.delete()
|
||||||
|
|
||||||
his_manager = CIRelationHistoryManager()
|
his_manager = CIRelationHistoryManager()
|
||||||
his_manager.add(cr, operate_type=OperateType.DELETE)
|
his_manager.add(cr, operate_type=OperateType.DELETE)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
@ -129,11 +131,26 @@ class PreferenceManager(object):
|
||||||
leaf = list(set(toposort.toposort_flatten(topo)) - set([j for i in topo.values() for j in i]))
|
leaf = list(set(toposort.toposort_flatten(topo)) - set([j for i in topo.values() for j in i]))
|
||||||
|
|
||||||
leaf2show_types = {i: [t['child_id'] for t in CITypeRelation.get_by(parent_id=i)] for i in leaf}
|
leaf2show_types = {i: [t['child_id'] for t in CITypeRelation.get_by(parent_id=i)] for i in leaf}
|
||||||
|
node2show_types = copy.deepcopy(leaf2show_types)
|
||||||
|
|
||||||
|
def _find_parent(node_id):
|
||||||
|
parents = topo.get(node_id, {})
|
||||||
|
for parent in parents:
|
||||||
|
node2show_types.setdefault(parent, []).extend(node2show_types.get(node_id, []))
|
||||||
|
_find_parent(parent)
|
||||||
|
if not parents:
|
||||||
|
return
|
||||||
|
for l in leaf:
|
||||||
|
_find_parent(l)
|
||||||
|
|
||||||
|
for node_id in node2show_types:
|
||||||
|
node2show_types[node_id] = [CITypeCache.get(i).to_dict() for i in set(node2show_types[node_id])]
|
||||||
|
|
||||||
result[view_name] = dict(topo=list(map(list, toposort.toposort(topo))),
|
result[view_name] = dict(topo=list(map(list, toposort.toposort(topo))),
|
||||||
topo_flatten=list(toposort.toposort_flatten(topo)),
|
topo_flatten=list(toposort.toposort_flatten(topo)),
|
||||||
leaf=leaf,
|
leaf=leaf,
|
||||||
leaf2show_types=leaf2show_types,
|
leaf2show_types=leaf2show_types,
|
||||||
|
node2show_types=node2show_types,
|
||||||
show_types=[CITypeCache.get(j).to_dict()
|
show_types=[CITypeCache.get(j).to_dict()
|
||||||
for i in leaf2show_types.values() for j in i])
|
for i in leaf2show_types.values() for j in i])
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ export default {
|
||||||
showTypeIds: [],
|
showTypeIds: [],
|
||||||
showTypes: [],
|
showTypes: [],
|
||||||
leaf2showTypes: {},
|
leaf2showTypes: {},
|
||||||
|
node2ShowTypes: {},
|
||||||
leaf: [],
|
leaf: [],
|
||||||
typeId: null,
|
typeId: null,
|
||||||
viewId: null,
|
viewId: null,
|
||||||
|
@ -131,6 +132,14 @@ export default {
|
||||||
|
|
||||||
q += `&root_id=${this.treeKeys[this.treeKeys.length - 1].split('_')[0]}`
|
q += `&root_id=${this.treeKeys[this.treeKeys.length - 1].split('_')[0]}`
|
||||||
const typeId = parseInt(this.treeKeys[this.treeKeys.length - 1].split('_')[1])
|
const typeId = parseInt(this.treeKeys[this.treeKeys.length - 1].split('_')[1])
|
||||||
|
|
||||||
|
this.showTypes = this.node2ShowTypes[typeId + '']
|
||||||
|
const showTypeIds = []
|
||||||
|
this.showTypes.forEach(item => {
|
||||||
|
showTypeIds.push(item.id)
|
||||||
|
})
|
||||||
|
this.showTypeIds = showTypeIds
|
||||||
|
|
||||||
let level = []
|
let level = []
|
||||||
if (!this.leaf.includes(typeId)) {
|
if (!this.leaf.includes(typeId)) {
|
||||||
let startIdx = 0
|
let startIdx = 0
|
||||||
|
@ -333,6 +342,7 @@ export default {
|
||||||
})
|
})
|
||||||
this.showTypeIds = showTypeIds
|
this.showTypeIds = showTypeIds
|
||||||
this.leaf2showTypes = this.relationViews.views[this.viewName].leaf2show_types
|
this.leaf2showTypes = this.relationViews.views[this.viewName].leaf2show_types
|
||||||
|
this.node2ShowTypes = this.relationViews.views[this.viewName].node2show_types
|
||||||
this.leaf = this.relationViews.views[this.viewName].leaf
|
this.leaf = this.relationViews.views[this.viewName].leaf
|
||||||
this.currentView = [this.viewId]
|
this.currentView = [this.viewId]
|
||||||
this.currentTypeId = [this.showTypeIds[0]]
|
this.currentTypeId = [this.showTypeIds[0]]
|
||||||
|
|
Loading…
Reference in New Issue