Skip to content

Commit

Permalink
cmdb.sql update
Browse files Browse the repository at this point in the history
  • Loading branch information
pycook committed Nov 29, 2019
1 parent 8522244 commit 882b158
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
19 changes: 19 additions & 0 deletions api/lib/cmdb/ci_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
from api.lib.cmdb.cache import CITypeAttributeCache
from api.lib.cmdb.cache import CITypeCache
from api.lib.decorator import kwargs_required
from api.models.cmdb import CI
from api.models.cmdb import CIType
from api.models.cmdb import CITypeAttribute
from api.models.cmdb import CITypeAttributeGroup
from api.models.cmdb import CITypeAttributeGroupItem
from api.models.cmdb import CITypeGroup
from api.models.cmdb import CITypeGroupItem
from api.models.cmdb import CITypeRelation
from api.models.cmdb import PreferenceTreeView
from api.models.cmdb import PreferenceShowAttributes


class CITypeManager(object):
Expand Down Expand Up @@ -99,6 +102,22 @@ def set_enabled(cls, type_id, enabled=True):
@classmethod
def delete(cls, type_id):
ci_type = cls.check_is_existed(type_id)

if CI.get_by(type_id=type_id, first=True, to_dict=False) is not False:
return abort(400, "cannot delete, because CI instance exists")

for item in CITypeRelation.get_by(parent_id=type_id, to_dict=False):
item.soft_delete()

for item in CITypeRelation.get_by(child_id=type_id, to_dict=False):
item.soft_delete()

for item in PreferenceTreeView.get_by(type_id=type_id, to_dict=False):
item.soft_delete()

for item in PreferenceShowAttributes.get_by(type_id=type_id, to_dict=False):
item.soft_delete()

ci_type.soft_delete()

CITypeCache.clean(type_id)
Expand Down
2 changes: 1 addition & 1 deletion api/lib/cmdb/preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def get_relation_view():
def create_or_update_relation_view(cls, name, cr_ids):
existed = PreferenceRelationView.get_by(name=name, to_dict=False, first=True)
if existed is None:
return PreferenceRelationView.create(name=name, cr_ids=json.dumps(cr_ids))
PreferenceRelationView.create(name=name, cr_ids=json.dumps(cr_ids))

return cls.get_relation_view()

Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/cmdb/ci/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export default {
that.$refs.table.clearSelected()
setTimeout(() => {
that.$refs.table.refresh(true)
}, 1000)
}, 1500)
})
.catch(e => {
console.log(e)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/cmdb/modeling/preference_relation/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
:key="view"
v-for="view in Object.keys(relationViews.views)">
<a-card :bordered="true" :title="view">
<a slot="extra"><a-icon type='close' @click="deleteView(view)"></a-icon></a>
<a slot="extra"><a-icon type="close" @click="deleteView(view)"></a-icon></a>
<div :id="&quot;view-&quot; + (relationViews.views[view] || []).join(&quot;&quot;)" style="height:200px"></div>
</a-card>
</a-col>
Expand Down

0 comments on commit 882b158

Please sign in to comment.