fix delete ci relation

This commit is contained in:
pycook 2019-12-03 21:57:44 +08:00
parent 81fe850627
commit cc2cdbcc9f
3 changed files with 28 additions and 1 deletions

View File

@ -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)

View File

@ -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])

View File

@ -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]]