mirror of https://github.com/veops/cmdb.git
relation view [doing]
This commit is contained in:
parent
73b92ff533
commit
1696ecf49d
|
@ -114,8 +114,10 @@ class PreferenceManager(object):
|
||||||
def get_relation_view():
|
def get_relation_view():
|
||||||
views = PreferenceRelationView.get_by(to_dict=True)
|
views = PreferenceRelationView.get_by(to_dict=True)
|
||||||
result = dict()
|
result = dict()
|
||||||
|
name2id = list()
|
||||||
for view in views:
|
for view in views:
|
||||||
result.setdefault(view['name'], []).extend(json.loads(view['cr_ids']))
|
result.setdefault(view['name'], []).extend(json.loads(view['cr_ids']))
|
||||||
|
name2id.append([view['name'], view['id']])
|
||||||
|
|
||||||
id2type = dict()
|
id2type = dict()
|
||||||
for view_name in result:
|
for view_name in result:
|
||||||
|
@ -129,7 +131,7 @@ class PreferenceManager(object):
|
||||||
for type_id in id2type:
|
for type_id in id2type:
|
||||||
id2type[type_id] = CITypeCache.get(type_id).to_dict()
|
id2type[type_id] = CITypeCache.get(type_id).to_dict()
|
||||||
|
|
||||||
return result, id2type
|
return result, id2type, sorted(name2id, key=lambda x: x[1])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_or_update_relation_view(cls, name, cr_ids):
|
def create_or_update_relation_view(cls, name, cr_ids):
|
||||||
|
|
|
@ -71,18 +71,18 @@ class PreferenceRelationApiView(APIView):
|
||||||
url_prefix = "/preference/relation/view"
|
url_prefix = "/preference/relation/view"
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
views, id2type = PreferenceManager.get_relation_view()
|
views, id2type, name2id = PreferenceManager.get_relation_view()
|
||||||
|
|
||||||
return self.jsonify(views=views, id2type=id2type)
|
return self.jsonify(views=views, id2type=id2type, name2id=name2id)
|
||||||
|
|
||||||
@role_required(RoleEnum.CONFIG)
|
@role_required(RoleEnum.CONFIG)
|
||||||
@args_required("name")
|
@args_required("name")
|
||||||
def post(self):
|
def post(self):
|
||||||
name = request.values.get("name")
|
name = request.values.get("name")
|
||||||
cr_ids = request.values.get("cr_ids")
|
cr_ids = request.values.get("cr_ids")
|
||||||
views, id2type = PreferenceManager.create_or_update_relation_view(name, cr_ids)
|
views, id2type, name2id = PreferenceManager.create_or_update_relation_view(name, cr_ids)
|
||||||
|
|
||||||
return self.jsonify(views, id2type)
|
return self.jsonify(views=views, id2type=id2type, name2id=name2id)
|
||||||
|
|
||||||
def put(self):
|
def put(self):
|
||||||
return self.post()
|
return self.post()
|
||||||
|
|
|
@ -21,7 +21,7 @@ const cmdbRouter = [
|
||||||
hideChildrenInMenu: true,
|
hideChildrenInMenu: true,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '/relation_views/:id',
|
path: '/relation_views/:viewId',
|
||||||
name: 'cmdb_relation_views_item',
|
name: 'cmdb_relation_views_item',
|
||||||
component: () => import('@/views/cmdb/relation_views'),
|
component: () => import('@/views/cmdb/relation_views'),
|
||||||
meta: { title: '关系视图', keepAlive: true },
|
meta: { title: '关系视图', keepAlive: true },
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<a-card :bordered="false">
|
<a-card :bordered="false">
|
||||||
<a-menu v-model="current" mode="horizontal" v-if="ciTypes.length">
|
<a-menu v-model="current" mode="horizontal" v-if="relationViews.name2id && relationViews.name2id.length">
|
||||||
<a-menu-item :key="ciType.id" v-for="ciType in ciTypes">
|
<a-menu-item :key="item[1]" v-for="item in relationViews.name2id">
|
||||||
<router-link
|
<router-link
|
||||||
:to="{name: 'cmdb_tree_views_item', params: {typeId: ciType.id}}"
|
:to="{name: 'cmdb_relation_views_item', params: { viewId: item[1]} }"
|
||||||
>{{ ciType.alias || ciTypes.name }}</router-link>
|
>{{ item[0] }}</router-link>
|
||||||
</a-menu-item>
|
</a-menu-item>
|
||||||
</a-menu>
|
</a-menu>
|
||||||
<a-alert message="请先到 我的订阅 页面完成订阅!" banner v-else></a-alert>
|
<a-alert message="管理员 还未配置关系视图!" banner v-else></a-alert>
|
||||||
<div style="clear: both; margin-top: 20px"></div>
|
<div style="clear: both; margin-top: 20px"></div>
|
||||||
<template>
|
<template>
|
||||||
<a-row :gutter="8">
|
<a-row :gutter="8">
|
||||||
|
@ -37,7 +37,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { STable } from '@/components'
|
import { STable } from '@/components'
|
||||||
|
|
||||||
import { getSubscribeTreeView, getSubscribeAttributes } from '@/api/cmdb/preference'
|
import { getRelationView, getSubscribeAttributes } from '@/api/cmdb/preference'
|
||||||
import { searchCI } from '@/api/cmdb/ci'
|
import { searchCI } from '@/api/cmdb/ci'
|
||||||
export default {
|
export default {
|
||||||
components: { STable },
|
components: { STable },
|
||||||
|
@ -47,8 +47,11 @@ export default {
|
||||||
triggerSelect: false,
|
triggerSelect: false,
|
||||||
treeNode: null,
|
treeNode: null,
|
||||||
ciTypes: [],
|
ciTypes: [],
|
||||||
|
relationViews: {},
|
||||||
levels: [],
|
levels: [],
|
||||||
typeId: null,
|
typeId: null,
|
||||||
|
viewId: null,
|
||||||
|
viewName: null,
|
||||||
current: [],
|
current: [],
|
||||||
instanceList: [],
|
instanceList: [],
|
||||||
treeKeys: [],
|
treeKeys: [],
|
||||||
|
@ -59,9 +62,11 @@ export default {
|
||||||
scrollY: 0,
|
scrollY: 0,
|
||||||
|
|
||||||
loadInstances: parameter => {
|
loadInstances: parameter => {
|
||||||
|
console.log(parameter, 'load instances')
|
||||||
const params = parameter || {}
|
const params = parameter || {}
|
||||||
// const params = Object.assign(parameter, this.$refs.search.queryParam)
|
// const params = Object.assign(parameter, this.$refs.search.queryParam)
|
||||||
let q = `q=_type:${this.typeId}`
|
let q = `q=_type:${this.typeId}`
|
||||||
|
console.log(params, 'params')
|
||||||
Object.keys(params).forEach(key => {
|
Object.keys(params).forEach(key => {
|
||||||
if (!['pageNo', 'pageSize', 'sortField', 'sortOrder'].includes(key) && params[key] + '' !== '') {
|
if (!['pageNo', 'pageSize', 'sortField', 'sortOrder'].includes(key) && params[key] + '' !== '') {
|
||||||
if (typeof params[key] === 'object' && params[key].length > 1) {
|
if (typeof params[key] === 'object' && params[key].length > 1) {
|
||||||
|
@ -121,20 +126,21 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
created () {
|
created () {
|
||||||
this.getCITypes()
|
this.getRelationViews()
|
||||||
},
|
},
|
||||||
|
|
||||||
inject: ['reload'],
|
inject: ['reload'],
|
||||||
watch: {
|
watch: {
|
||||||
'$route.path': function (newPath, oldPath) {
|
'$route.path': function (newPath, oldPath) {
|
||||||
this.typeId = this.$route.params.typeId
|
this.viewId = this.$route.params.viewId
|
||||||
this.getCITypes()
|
this.getRelationViews()
|
||||||
this.reload()
|
this.reload()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onSelect (keys) {
|
onSelect (keys) {
|
||||||
|
console.log('onSelect')
|
||||||
this.triggerSelect = true
|
this.triggerSelect = true
|
||||||
if (keys.length) {
|
if (keys.length) {
|
||||||
this.treeKeys = keys[0].split('-').filter(item => item !== '')
|
this.treeKeys = keys[0].split('-').filter(item => item !== '')
|
||||||
|
@ -143,6 +149,7 @@ export default {
|
||||||
this.$refs.table.refresh(true)
|
this.$refs.table.refresh(true)
|
||||||
},
|
},
|
||||||
wrapTreeData (facet) {
|
wrapTreeData (facet) {
|
||||||
|
console.log('wrapTreeData')
|
||||||
if (this.triggerSelect) {
|
if (this.triggerSelect) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -169,7 +176,7 @@ export default {
|
||||||
rows = document.querySelector('.ant-table-body').childNodes[0].childNodes[1].childNodes[0].childNodes
|
rows = document.querySelector('.ant-table-body').childNodes[0].childNodes[1].childNodes[0].childNodes
|
||||||
}
|
}
|
||||||
let scrollX = 0
|
let scrollX = 0
|
||||||
|
console.log(rows, 'rows')
|
||||||
const columns = Object.assign([], this.columns)
|
const columns = Object.assign([], this.columns)
|
||||||
for (let i = 0; i < rows.length; i++) {
|
for (let i = 0; i < rows.length; i++) {
|
||||||
columns[i].width = rows[i].offsetWidth < 80 ? 80 : rows[i].offsetWidth
|
columns[i].width = rows[i].offsetWidth < 80 ? 80 : rows[i].offsetWidth
|
||||||
|
@ -182,6 +189,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoadData (treeNode) {
|
onLoadData (treeNode) {
|
||||||
|
console.log(treeNode, 'load data')
|
||||||
this.triggerSelect = false
|
this.triggerSelect = false
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
if (treeNode.dataRef.children) {
|
if (treeNode.dataRef.children) {
|
||||||
|
@ -195,20 +203,28 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
getCITypes () {
|
getRelationViews () {
|
||||||
getSubscribeTreeView().then(res => {
|
getRelationView().then(res => {
|
||||||
this.ciTypes = res
|
this.relationViews = res
|
||||||
if (this.ciTypes.length) {
|
|
||||||
this.typeId = this.$route.params.typeId || this.ciTypes[0].id
|
if ((Object.keys(this.relationViews.views) || []).length) {
|
||||||
this.current = [this.typeId]
|
this.viewId = parseInt(this.$route.params.viewId) || this.relationViews.name2id[0][1]
|
||||||
this.loadColumns()
|
this.relationViews.name2id.forEach(item => {
|
||||||
this.levels = res.find(item => item.id === this.typeId).levels
|
if (item[1] === this.viewId) {
|
||||||
this.$refs.table && this.$refs.table.refresh(true)
|
this.viewName = item[0]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
this.levels = this.relationViews.views[this.viewName]
|
||||||
|
this.current = [this.levels[0]]
|
||||||
|
this.typeId = this.levels[0]
|
||||||
|
console.log(this.levels, 'levels')
|
||||||
|
// this.loadColumns()
|
||||||
|
// this.$refs.table && this.$refs.table.refresh(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
loadColumns () {
|
loadColumns () {
|
||||||
getSubscribeAttributes(this.typeId).then(res => {
|
getSubscribeAttributes(this.levels[this.levels.length - 1]).then(res => {
|
||||||
const prefAttrList = res.attributes
|
const prefAttrList = res.attributes
|
||||||
|
|
||||||
const columns = []
|
const columns = []
|
||||||
|
|
Loading…
Reference in New Issue