mirror of https://github.com/veops/cmdb.git
feat(ui): Resources and Preference support grouping
This commit is contained in:
parent
6955714951
commit
0a13ca82c6
|
@ -182,8 +182,8 @@ export default {
|
||||||
<tag {...{ props, attrs }}>
|
<tag {...{ props, attrs }}>
|
||||||
{this.renderIcon({ icon: menu.meta.icon, customIcon: menu.meta.customIcon, name: menu.meta.name, typeId: menu.meta.typeId, routeName: menu.name, selectedIcon: menu.meta.selectedIcon, })}
|
{this.renderIcon({ icon: menu.meta.icon, customIcon: menu.meta.customIcon, name: menu.meta.name, typeId: menu.meta.typeId, routeName: menu.name, selectedIcon: menu.meta.selectedIcon, })}
|
||||||
<span>
|
<span>
|
||||||
<span class={this.renderI18n(menu.meta.title).length > 10 ? 'scroll' : ''}>{this.renderI18n(menu.meta.title)}</span>
|
<span style={menu.meta.style} class={this.renderI18n(menu.meta.title).length > 10 ? 'scroll' : ''}>{this.renderI18n(menu.meta.title)}</span>
|
||||||
{isShowDot &&
|
{isShowDot && !menu.meta.disabled &&
|
||||||
<a-popover
|
<a-popover
|
||||||
overlayClassName="custom-menu-extra-submenu"
|
overlayClassName="custom-menu-extra-submenu"
|
||||||
placement="rightTop"
|
placement="rightTop"
|
||||||
|
|
|
@ -81,7 +81,7 @@ export default {
|
||||||
if (route.name === 'cmdb') {
|
if (route.name === 'cmdb') {
|
||||||
const preference = await getPreference()
|
const preference = await getPreference()
|
||||||
const lastTypeId = window.localStorage.getItem('ops_ci_typeid') || undefined
|
const lastTypeId = window.localStorage.getItem('ops_ci_typeid') || undefined
|
||||||
if (lastTypeId && preference.some((item) => item.id === Number(lastTypeId))) {
|
if (lastTypeId && preference.type_ids.some((item) => item === Number(lastTypeId))) {
|
||||||
this.$router.push(`/cmdb/instances/types/${lastTypeId}`)
|
this.$router.push(`/cmdb/instances/types/${lastTypeId}`)
|
||||||
} else {
|
} else {
|
||||||
this.$router.push('/cmdb/dashboard')
|
this.$router.push('/cmdb/dashboard')
|
||||||
|
|
|
@ -144,7 +144,15 @@ const genCmdbRoutes = async () => {
|
||||||
// Dynamically add subscription items and business relationships
|
// Dynamically add subscription items and business relationships
|
||||||
const [preference, relation] = await Promise.all([getPreference(), getRelationView()])
|
const [preference, relation] = await Promise.all([getPreference(), getRelationView()])
|
||||||
|
|
||||||
preference.forEach(item => {
|
preference.group_types.forEach(group => {
|
||||||
|
if (preference.group_types.length > 1) {
|
||||||
|
routes.children[2].children.push({
|
||||||
|
path: `/cmdb/instances/types/group${group.id}`,
|
||||||
|
name: `cmdb_instances_group_${group.id}`,
|
||||||
|
meta: { title: group.name || 'other', disabled: true, style: 'margin-left: 12px' },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
group.ci_types.forEach(item => {
|
||||||
routes.children[2].children.push({
|
routes.children[2].children.push({
|
||||||
path: `/cmdb/instances/types/${item.id}`,
|
path: `/cmdb/instances/types/${item.id}`,
|
||||||
component: () => import(`../views/ci/index`),
|
component: () => import(`../views/ci/index`),
|
||||||
|
@ -153,8 +161,9 @@ const genCmdbRoutes = async () => {
|
||||||
// hideChildrenInMenu: true // Force display of MenuItem instead of SubMenu
|
// hideChildrenInMenu: true // Force display of MenuItem instead of SubMenu
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
const lastTypeId = window.localStorage.getItem('ops_ci_typeid') || undefined
|
const lastTypeId = window.localStorage.getItem('ops_ci_typeid') || undefined
|
||||||
if (lastTypeId && preference.some(item => item.id === Number(lastTypeId))) {
|
if (lastTypeId && preference.type_ids.some(item => item === Number(lastTypeId))) {
|
||||||
routes.redirect = `/cmdb/instances/types/${lastTypeId}`
|
routes.redirect = `/cmdb/instances/types/${lastTypeId}`
|
||||||
} else if (routes.children[2]?.children?.length > 0) {
|
} else if (routes.children[2]?.children?.length > 0) {
|
||||||
routes.redirect = routes.children[2].children.find(item => !item.hidden)?.path
|
routes.redirect = routes.children[2].children.find(item => !item.hidden)?.path
|
||||||
|
|
|
@ -32,16 +32,29 @@
|
||||||
}"
|
}"
|
||||||
/></span>
|
/></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="cmdb-preference-group" v-for="(group, index) in myPreferences" :key="group.name">
|
<div class="cmdb-preference-group" v-for="(subType, index) in myPreferences" :key="subType.name">
|
||||||
<div class="cmdb-preference-group-title">
|
<div class="cmdb-preference-group-title">
|
||||||
<span> <ops-icon :style="{ marginRight: '10px' }" :type="group.icon" />{{ group.name }} </span>
|
<span> <ops-icon :style="{ marginRight: '10px' }" :type="subType.icon" />{{ subType.name }} </span>
|
||||||
|
</div>
|
||||||
|
<draggable class="ci-types-left-content" :list="subType.groups" @end="handleChangeGroups" filter=".undraggable">
|
||||||
|
<div v-for="group in subType.groups" :key="group.id || group.name">
|
||||||
|
<div
|
||||||
|
:class="
|
||||||
|
`${group.id === undefined ? 'undraggable' : ''}`
|
||||||
|
"
|
||||||
|
>
|
||||||
|
<div v-if="index === 0 && subType.groups.length > 1" class="cmdb-preference-group-content">
|
||||||
|
<OpsMoveIcon class="cmdb-preference-move-icon" v-if="group.name || index === 1"/>
|
||||||
|
<span style="font-weight: 500; color: #a5a9bc">{{ group.name || $t('other') }}</span>
|
||||||
|
<span :style="{ color: '#c3cdd7' }">({{ group.ci_types.length }})</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<draggable
|
<draggable
|
||||||
v-model="group.ci_types"
|
v-model="group.ci_types"
|
||||||
:animation="300"
|
:animation="300"
|
||||||
@change="
|
@change="
|
||||||
(e) => {
|
(e) => {
|
||||||
orderChange(e, group)
|
orderChange(e, group, index === 1)
|
||||||
}
|
}
|
||||||
"
|
"
|
||||||
>
|
>
|
||||||
|
@ -91,6 +104,8 @@
|
||||||
</div>
|
</div>
|
||||||
</draggable>
|
</draggable>
|
||||||
</div>
|
</div>
|
||||||
|
</draggable>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="cmdb-preference-right">
|
<div class="cmdb-preference-right">
|
||||||
<a-input-search
|
<a-input-search
|
||||||
|
@ -261,7 +276,7 @@ export default {
|
||||||
ciTypeGroup.forEach((group) => {
|
ciTypeGroup.forEach((group) => {
|
||||||
if (group.ci_types && group.ci_types.length) {
|
if (group.ci_types && group.ci_types.length) {
|
||||||
group.ci_types.forEach((type) => {
|
group.ci_types.forEach((type) => {
|
||||||
const idx = pref.findIndex((p) => p.id === type.id)
|
const idx = pref.type_ids.findIndex((p) => p === type.id)
|
||||||
if (idx > -1) {
|
if (idx > -1) {
|
||||||
type.is_subscribed = true
|
type.is_subscribed = true
|
||||||
}
|
}
|
||||||
|
@ -283,19 +298,18 @@ export default {
|
||||||
const _myPreferences = [
|
const _myPreferences = [
|
||||||
{
|
{
|
||||||
name: this.$t('cmdb.menu.ciTable'),
|
name: this.$t('cmdb.menu.ciTable'),
|
||||||
ci_types: self.instance.map((item) => {
|
groups: pref.group_types,
|
||||||
const _find = pref.find((ci) => ci.id === item)
|
|
||||||
return _find
|
|
||||||
}),
|
|
||||||
icon: 'cmdb-ci',
|
icon: 'cmdb-ci',
|
||||||
type: 'ci',
|
type: 'ci',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: this.$t('cmdb.menu.ciTree'),
|
name: this.$t('cmdb.menu.ciTree'),
|
||||||
ci_types: self.tree.map((item) => {
|
groups: [
|
||||||
const _find = pref.find((ci) => ci.id === item)
|
{
|
||||||
return _find
|
ci_types: pref.tree_types,
|
||||||
}),
|
name: null,
|
||||||
|
}
|
||||||
|
],
|
||||||
icon: 'cmdb-tree',
|
icon: 'cmdb-tree',
|
||||||
type: 'tree',
|
type: 'tree',
|
||||||
},
|
},
|
||||||
|
@ -377,10 +391,41 @@ export default {
|
||||||
this.expandKeys.push(group.id)
|
this.expandKeys.push(group.id)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
orderChange(e, group) {
|
async handleChangeGroups() {
|
||||||
preferenceCitypeOrder({ type_ids: group.ci_types.map((type) => type.id), is_tree: group.type !== 'ci' })
|
const typeIds = []
|
||||||
|
this.myPreferences[0].groups.forEach(groupTypes => {
|
||||||
|
groupTypes.ci_types.forEach(ciType => {
|
||||||
|
typeIds.push(ciType.id)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
preferenceCitypeOrder({ type_ids: typeIds, is_tree: false })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (group.type === 'ci') {
|
this.resetRoute()
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
this.getCITypes(false)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
orderChange(e, group, isTree) {
|
||||||
|
let typeIds = []
|
||||||
|
if (!isTree) {
|
||||||
|
this.myPreferences[0].groups.forEach(groupTypes => {
|
||||||
|
if (group.id === groupTypes.id) {
|
||||||
|
group.ci_types.forEach(ciType => {
|
||||||
|
typeIds.push(ciType.id)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
groupTypes.ci_types.forEach(ciType => {
|
||||||
|
typeIds.push(ciType.id)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
typeIds = group.ci_types.map(item => item.id)
|
||||||
|
}
|
||||||
|
preferenceCitypeOrder({ type_ids: typeIds, is_tree: isTree })
|
||||||
|
.then(() => {
|
||||||
|
if (!isTree) {
|
||||||
this.resetRoute()
|
this.resetRoute()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -442,6 +487,18 @@ export default {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
.cmdb-preference-group {
|
.cmdb-preference-group {
|
||||||
|
.ci-types-left-content {
|
||||||
|
max-height: calc(100% - 45px);
|
||||||
|
overflow: hidden;
|
||||||
|
&:hover {
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
.undraggable{
|
||||||
|
.cmdb-preference-group-content {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
.cmdb-preference-group-title {
|
.cmdb-preference-group-title {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
|
|
Loading…
Reference in New Issue