From 0a563deb11623486ae12a97a06c9b23f0390f047 Mon Sep 17 00:00:00 2001 From: pycook Date: Mon, 25 Nov 2019 19:23:51 +0800 Subject: [PATCH] UI: relation type define [done] --- api/lib/cmdb/preference.py | 7 +- ui/src/api/cmdb/CITypeRelation.js | 8 - ui/src/api/cmdb/relationType.js | 31 ++ ui/src/config/router.config.js | 60 +++- .../{ => model_config}/attributes/index.vue | 0 .../attributes/module/attributeForm.vue | 0 .../attributes/module/const.js | 0 .../ci_type/attributesTable.vue | 4 +- .../{ => model_config}/ci_type/checkTable.vue | 0 .../ci_type/defaultShowTable.vue | 0 .../{ => model_config}/ci_type/detail.vue | 0 .../cmdb/{ => model_config}/ci_type/group.vue | 0 .../cmdb/{ => model_config}/ci_type/list.vue | 0 .../ci_type/relationTable.vue | 3 +- .../preference_relation/index.vue | 6 + .../cmdb/model_config/relation_type/index.vue | 280 ++++++++++++++++++ .../relation_type/module/relationTypeForm.vue | 196 ++++++++++++ ui/src/views/cmdb/relation_views/index.vue | 248 ++++++++++++++++ 18 files changed, 814 insertions(+), 29 deletions(-) create mode 100644 ui/src/api/cmdb/relationType.js rename ui/src/views/cmdb/{ => model_config}/attributes/index.vue (100%) rename ui/src/views/cmdb/{ => model_config}/attributes/module/attributeForm.vue (100%) rename ui/src/views/cmdb/{ => model_config}/attributes/module/const.js (100%) rename ui/src/views/cmdb/{ => model_config}/ci_type/attributesTable.vue (98%) rename ui/src/views/cmdb/{ => model_config}/ci_type/checkTable.vue (100%) rename ui/src/views/cmdb/{ => model_config}/ci_type/defaultShowTable.vue (100%) rename ui/src/views/cmdb/{ => model_config}/ci_type/detail.vue (100%) rename ui/src/views/cmdb/{ => model_config}/ci_type/group.vue (100%) rename ui/src/views/cmdb/{ => model_config}/ci_type/list.vue (100%) rename ui/src/views/cmdb/{ => model_config}/ci_type/relationTable.vue (98%) create mode 100644 ui/src/views/cmdb/model_config/preference_relation/index.vue create mode 100644 ui/src/views/cmdb/model_config/relation_type/index.vue create mode 100644 ui/src/views/cmdb/model_config/relation_type/module/relationTypeForm.vue create mode 100644 ui/src/views/cmdb/relation_views/index.vue diff --git a/api/lib/cmdb/preference.py b/api/lib/cmdb/preference.py index a897252..91d0970 100644 --- a/api/lib/cmdb/preference.py +++ b/api/lib/cmdb/preference.py @@ -119,11 +119,12 @@ class PreferenceManager(object): id2type = dict() for view_name in result: - result[view_name] = toposort.toposort_flatten( - {i['child_id']: {i['parent_id']} for i in result[view_name]}) for i in result[view_name]: id2type[i['parent_id']] = None - id2type[i['child']] = None + id2type[i['child_id']] = None + + result[view_name] = toposort.toposort_flatten( + {i['child_id']: {i['parent_id']} for i in result[view_name]}) for type_id in id2type: id2type[type_id] = CITypeCache.get(type_id).to_dict() diff --git a/ui/src/api/cmdb/CITypeRelation.js b/ui/src/api/cmdb/CITypeRelation.js index 8305c6a..8bb934c 100644 --- a/ui/src/api/cmdb/CITypeRelation.js +++ b/ui/src/api/cmdb/CITypeRelation.js @@ -15,14 +15,6 @@ export function getCITypeParent (CITypeID) { }) } -export function getRelationTypes (CITypeID, parameter) { - return axios({ - url: '/v0.1/relation_types', - method: 'get', - params: parameter - }) -} - export function createRelation (parentId, childrenId, relationTypeId) { return axios({ url: `/v0.1/ci_type_relations/${parentId}/${childrenId}`, diff --git a/ui/src/api/cmdb/relationType.js b/ui/src/api/cmdb/relationType.js new file mode 100644 index 0000000..831b0ae --- /dev/null +++ b/ui/src/api/cmdb/relationType.js @@ -0,0 +1,31 @@ +import { axios } from '@/utils/request' + +export function getRelationTypes () { + return axios({ + url: '/v0.1/relation_types', + method: 'GET' + }) +} + +export function addRelationType (payload) { + return axios({ + url: `/v0.1/relation_types`, + method: 'POST', + data: payload + }) +} + +export function updateRelationType (rtId, payload) { + return axios({ + url: `/v0.1/relation_types/${rtId}`, + method: 'PUT', + data: payload + }) +} + +export function deleteRelationType (rtId) { + return axios({ + url: `/v0.1/relation_types/${rtId}`, + method: 'DELETE' + }) +} diff --git a/ui/src/config/router.config.js b/ui/src/config/router.config.js index b41bf9b..72a8829 100644 --- a/ui/src/config/router.config.js +++ b/ui/src/config/router.config.js @@ -12,7 +12,23 @@ const cmdbRouter = [ name: 'cmdb_preference', meta: { title: '我的订阅', icon: 'book', keepAlive: true } }, - // views + // relation views + { + path: '/relation_views', + component: () => import('@/views/cmdb/relation_views'), + name: 'cmdb_relation_views', + meta: { title: '关系视图', icon: 'link', keepAlive: true }, + hideChildrenInMenu: true, + children: [ + { + path: '/relation_views/:id', + name: 'cmdb_relation_views_item', + component: () => import('@/views/cmdb/relation_views'), + meta: { title: '关系视图', keepAlive: true }, + hidden: true + }] + }, + // tree views { path: '/tree_views', component: () => import('@/views/cmdb/tree_views'), @@ -36,33 +52,47 @@ const cmdbRouter = [ meta: { 'title': '批量导入', icon: 'upload', keepAlive: true } }, { - path: '/ci_types', + path: '/config//ci_types', name: 'cmdb_ci_type', component: RouteView, - redirect: '/ci_type', + redirect: '/ci_types', meta: { title: '模型配置', icon: 'setting', permission: ['admin'] }, children: [ { - path: '/ci_types', + path: '/config/ci_types', name: 'ci_type', - hideChildrenInMenu: true, // 强制显示 MenuItem 而不是 SubMenu - component: () => import('@/views/cmdb/ci_type/list'), - meta: { title: '模型定义', keepAlive: true } + hideChildrenInMenu: true, + component: () => import('@/views/cmdb/model_config/ci_type/list'), + meta: { title: '模型管理', keepAlive: true } }, { - path: '/ci_types/:CITypeName/detail/:CITypeId', + path: '/config/ci_types/:CITypeName/detail/:CITypeId', name: 'ci_type_detail', - hideChildrenInMenu: true, // 强制显示 MenuItem 而不是 SubMenu - component: () => import('@/views/cmdb/ci_type/detail'), - meta: { title: '模型配置', keepAlive: true, hidden: true }, + hideChildrenInMenu: true, + component: () => import('@/views/cmdb/model_config/ci_type/detail'), + meta: { title: '模型管理', keepAlive: true, hidden: true }, hidden: true }, { - path: '/attributes', + path: '/config/attributes', name: 'attributes', - hideChildrenInMenu: true, // 强制显示 MenuItem 而不是 SubMenu - component: () => import('@/views/cmdb/attributes/index'), + hideChildrenInMenu: true, + component: () => import('@/views/cmdb/model_config/attributes/index'), meta: { title: '属性库', keepAlive: true } + }, + { + path: '/config/relation_type', + name: 'relation_type', + hideChildrenInMenu: true, + component: () => import('@/views/cmdb/model_config/relation_type/index'), + meta: { title: '关系类型', keepAlive: true } + }, + { + path: '/config/preference_relation', + name: 'preference_relation', + hideChildrenInMenu: true, + component: () => import('@/views/cmdb/model_config/preference_relation/index'), + meta: { title: '关系视图配置', keepAlive: true } } ] }, @@ -128,7 +158,7 @@ export const generatorDynamicRouter = () => { component: () => import(`@/views/cmdb/ci/index`), name: `cmdb_${item.id}`, meta: { title: item.alias, icon: 'table', keepAlive: true, typeId: item.id }, - hideChildrenInMenu: true // 强制显示 MenuItem 而不是 SubMenu + hideChildrenInMenu: true }) } diff --git a/ui/src/views/cmdb/attributes/index.vue b/ui/src/views/cmdb/model_config/attributes/index.vue similarity index 100% rename from ui/src/views/cmdb/attributes/index.vue rename to ui/src/views/cmdb/model_config/attributes/index.vue diff --git a/ui/src/views/cmdb/attributes/module/attributeForm.vue b/ui/src/views/cmdb/model_config/attributes/module/attributeForm.vue similarity index 100% rename from ui/src/views/cmdb/attributes/module/attributeForm.vue rename to ui/src/views/cmdb/model_config/attributes/module/attributeForm.vue diff --git a/ui/src/views/cmdb/attributes/module/const.js b/ui/src/views/cmdb/model_config/attributes/module/const.js similarity index 100% rename from ui/src/views/cmdb/attributes/module/const.js rename to ui/src/views/cmdb/model_config/attributes/module/const.js diff --git a/ui/src/views/cmdb/ci_type/attributesTable.vue b/ui/src/views/cmdb/model_config/ci_type/attributesTable.vue similarity index 98% rename from ui/src/views/cmdb/ci_type/attributesTable.vue rename to ui/src/views/cmdb/model_config/ci_type/attributesTable.vue index f0c4e5c..2e484f3 100644 --- a/ui/src/views/cmdb/ci_type/attributesTable.vue +++ b/ui/src/views/cmdb/model_config/ci_type/attributesTable.vue @@ -143,8 +143,8 @@ import { } from '@/api/cmdb/CITypeAttr' import { STable } from '@/components' import { mixin, mixinDevice } from '@/utils/mixin' -import AttributeForm from '@/views/cmdb/attributes/module/attributeForm' -import { valueTypeMap } from '@/views/cmdb/attributes/module/const' +import AttributeForm from '@/views/cmdb/model_config/attributes/module/attributeForm' +import { valueTypeMap } from '@/views/cmdb/model_config/attributes/module/const' export default { name: 'AttributesTable', diff --git a/ui/src/views/cmdb/ci_type/checkTable.vue b/ui/src/views/cmdb/model_config/ci_type/checkTable.vue similarity index 100% rename from ui/src/views/cmdb/ci_type/checkTable.vue rename to ui/src/views/cmdb/model_config/ci_type/checkTable.vue diff --git a/ui/src/views/cmdb/ci_type/defaultShowTable.vue b/ui/src/views/cmdb/model_config/ci_type/defaultShowTable.vue similarity index 100% rename from ui/src/views/cmdb/ci_type/defaultShowTable.vue rename to ui/src/views/cmdb/model_config/ci_type/defaultShowTable.vue diff --git a/ui/src/views/cmdb/ci_type/detail.vue b/ui/src/views/cmdb/model_config/ci_type/detail.vue similarity index 100% rename from ui/src/views/cmdb/ci_type/detail.vue rename to ui/src/views/cmdb/model_config/ci_type/detail.vue diff --git a/ui/src/views/cmdb/ci_type/group.vue b/ui/src/views/cmdb/model_config/ci_type/group.vue similarity index 100% rename from ui/src/views/cmdb/ci_type/group.vue rename to ui/src/views/cmdb/model_config/ci_type/group.vue diff --git a/ui/src/views/cmdb/ci_type/list.vue b/ui/src/views/cmdb/model_config/ci_type/list.vue similarity index 100% rename from ui/src/views/cmdb/ci_type/list.vue rename to ui/src/views/cmdb/model_config/ci_type/list.vue diff --git a/ui/src/views/cmdb/ci_type/relationTable.vue b/ui/src/views/cmdb/model_config/ci_type/relationTable.vue similarity index 98% rename from ui/src/views/cmdb/ci_type/relationTable.vue rename to ui/src/views/cmdb/model_config/ci_type/relationTable.vue index da5835a..451593f 100644 --- a/ui/src/views/cmdb/ci_type/relationTable.vue +++ b/ui/src/views/cmdb/model_config/ci_type/relationTable.vue @@ -103,7 +103,8 @@ diff --git a/ui/src/views/cmdb/model_config/relation_type/index.vue b/ui/src/views/cmdb/model_config/relation_type/index.vue new file mode 100644 index 0000000..5e2681b --- /dev/null +++ b/ui/src/views/cmdb/model_config/relation_type/index.vue @@ -0,0 +1,280 @@ + + + + + diff --git a/ui/src/views/cmdb/model_config/relation_type/module/relationTypeForm.vue b/ui/src/views/cmdb/model_config/relation_type/module/relationTypeForm.vue new file mode 100644 index 0000000..9c3f479 --- /dev/null +++ b/ui/src/views/cmdb/model_config/relation_type/module/relationTypeForm.vue @@ -0,0 +1,196 @@ + + + + + diff --git a/ui/src/views/cmdb/relation_views/index.vue b/ui/src/views/cmdb/relation_views/index.vue new file mode 100644 index 0000000..69c92c6 --- /dev/null +++ b/ui/src/views/cmdb/relation_views/index.vue @@ -0,0 +1,248 @@ + + + + +