From cc2cdbcc9f07c33980f167f6ec93a623782912e1 Mon Sep 17 00:00:00 2001 From: pycook Date: Tue, 3 Dec 2019 21:57:44 +0800 Subject: [PATCH] fix delete ci relation --- api/lib/cmdb/ci.py | 2 +- api/lib/cmdb/preference.py | 17 +++++++++++++++++ ui/src/views/cmdb/relation_views/index.vue | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/api/lib/cmdb/ci.py b/api/lib/cmdb/ci.py index f55ac47..ef51902 100644 --- a/api/lib/cmdb/ci.py +++ b/api/lib/cmdb/ci.py @@ -548,7 +548,7 @@ class CIRelationManager(object): @staticmethod def delete(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.add(cr, operate_type=OperateType.DELETE) diff --git a/api/lib/cmdb/preference.py b/api/lib/cmdb/preference.py index f519ae1..f4a1fac 100644 --- a/api/lib/cmdb/preference.py +++ b/api/lib/cmdb/preference.py @@ -1,5 +1,7 @@ # -*- coding:utf-8 -*- + +import copy import json 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])) 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))), topo_flatten=list(toposort.toposort_flatten(topo)), leaf=leaf, leaf2show_types=leaf2show_types, + node2show_types=node2show_types, show_types=[CITypeCache.get(j).to_dict() for i in leaf2show_types.values() for j in i]) diff --git a/ui/src/views/cmdb/relation_views/index.vue b/ui/src/views/cmdb/relation_views/index.vue index ad47cdd..cf2fe57 100644 --- a/ui/src/views/cmdb/relation_views/index.vue +++ b/ui/src/views/cmdb/relation_views/index.vue @@ -64,6 +64,7 @@ export default { showTypeIds: [], showTypes: [], leaf2showTypes: {}, + node2ShowTypes: {}, leaf: [], typeId: null, viewId: null, @@ -131,6 +132,14 @@ export default { q += `&root_id=${this.treeKeys[this.treeKeys.length - 1].split('_')[0]}` 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 = [] if (!this.leaf.includes(typeId)) { let startIdx = 0 @@ -333,6 +342,7 @@ export default { }) this.showTypeIds = showTypeIds 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.currentView = [this.viewId] this.currentTypeId = [this.showTypeIds[0]]