Merge pull request #596 from thexqn/fix_order_bug

修复在继承模型的情况下,非继承属性与继承属性的排序以及其他分组的排序提示问题Fix order bug
This commit is contained in:
Leo Song 2024-08-26 11:20:15 +08:00 committed by GitHub
commit 55ab04dd28
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 24 deletions

View File

@ -130,6 +130,7 @@ const cmdb_en = {
selectAttribute: 'Select Attribute', selectAttribute: 'Select Attribute',
groupExisted: 'Group name already exists', groupExisted: 'Group name already exists',
attributeSortedTips: 'Attributes in other groups cannot be sorted. If you need to sort, please drag them to a custom group first!', attributeSortedTips: 'Attributes in other groups cannot be sorted. If you need to sort, please drag them to a custom group first!',
attributeSortedTips2: 'Non-inherited attributes cannot be inserted before inherited attributes!',
buildinAttribute: 'built-in attributes', buildinAttribute: 'built-in attributes',
expr: 'Expression', expr: 'Expression',
code: 'Code', code: 'Code',

View File

@ -130,6 +130,7 @@ const cmdb_zh = {
selectAttribute: '添加属性', selectAttribute: '添加属性',
groupExisted: '分组名称已存在', groupExisted: '分组名称已存在',
attributeSortedTips: '其他分组中的属性不能进行排序,如需排序请先拖至自定义的分组!', attributeSortedTips: '其他分组中的属性不能进行排序,如需排序请先拖至自定义的分组!',
attributeSortedTips2: '非继承属性不能插入到继承属性前!',
buildinAttribute: '内置字段', buildinAttribute: '内置字段',
expr: '表达式', expr: '表达式',
code: '代码', code: '代码',

View File

@ -233,6 +233,7 @@ export default {
attrTypeFilter: [], attrTypeFilter: [],
unique: '', unique: '',
show_id: null, show_id: null,
groupMaxCount: {},
} }
}, },
computed: { computed: {
@ -340,6 +341,7 @@ export default {
}) })
this.CITypeGroups = values[1] this.CITypeGroups = values[1]
this.CITypeGroups.forEach((g) => { this.CITypeGroups.forEach((g) => {
this.groupMaxCount[g.name] = g.attributes.filter(a => a.inherited).length
g.attributes.forEach((a) => { g.attributes.forEach((a) => {
a.is_required = (temp[a.id] && temp[a.id].is_required) || false a.is_required = (temp[a.id] && temp[a.id].is_required) || false
a.default_show = (temp[a.id] && temp[a.id].default_show) || false a.default_show = (temp[a.id] && temp[a.id].default_show) || false
@ -475,44 +477,43 @@ export default {
handleChange(e, group) { handleChange(e, group) {
console.log('changess', group) console.log('changess', group)
if (e.hasOwnProperty('moved') && e.moved.oldIndex !== e.moved.newIndex) { if (e.hasOwnProperty('moved') && e.moved.oldIndex !== e.moved.newIndex) {
if (group === -1) { if (group === -1 || group === null) {
this.$message.error(this.$t('cmdb.ciType.attributeSortedTips')) this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips'))
} else if (e.moved.newIndex < this.groupMaxCount[group]) {
this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips2'))
} else { } else {
transferCITypeAttrIndex(this.CITypeId, { transferCITypeAttrIndex(this.CITypeId, {
from: { attr_id: e.moved.element.id, group_name: group }, from: { attr_id: e.moved.element.id, group_name: group },
to: { order: e.moved.newIndex, group_name: group }, to: { order: e.moved.newIndex, group_name: group }
}) })
.then((res) => this.$message.success(this.$t('updateSuccess'))) .then(() => this.$message.success(this.$t('updateSuccess')))
.catch(() => { .catch(() => this.init())
this.abortDraggable()
})
} }
} }
if (e.hasOwnProperty('added')) { if (e.hasOwnProperty('added')) {
this.addRemoveGroupFlag = { to: { group_name: group, order: e.added.newIndex }, inited: true } this.addRemoveGroupFlag = { to: { group_name: group, order: e.added.newIndex }, inited: true }
} }
if (e.hasOwnProperty('removed')) { if (e.hasOwnProperty('removed')) {
this.$nextTick(() => { this.$nextTick(() => {
transferCITypeAttrIndex(this.CITypeId, { if (this.addRemoveGroupFlag.to.order < this.groupMaxCount[this.addRemoveGroupFlag.to.group_name]) {
from: { attr_id: e.removed.element.id, group_name: group }, this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips2'))
to: { group_name: this.addRemoveGroupFlag.to.group_name, order: this.addRemoveGroupFlag.to.order }, } else {
}) transferCITypeAttrIndex(this.CITypeId, {
.then((res) => this.$message.success(this.$t('saveSuccess'))) from: { attr_id: e.removed.element.id, group_name: group },
.catch(() => { to: { group_name: this.addRemoveGroupFlag.to.group_name, order: this.addRemoveGroupFlag.to.order }
this.abortDraggable()
})
.finally(() => {
this.addRemoveGroupFlag = {}
}) })
.then(() => this.$message.success(this.$t('saveSuccess')))
.catch(() => this.init())
.finally(() => {
this.addRemoveGroupFlag = {}
})
}
}) })
} }
}, },
abortDraggable() { refreshPage(errorMessage) {
this.$nextTick(() => { this.$message.error(errorMessage)
this.$router.push({ name: 'ci_type' }) this.init()
})
}, },
updatePropertyIndex() { updatePropertyIndex() {
const attributes = [] // All attributes const attributes = [] // All attributes
@ -594,7 +595,7 @@ export default {
return attrTypeFilter.includes(valueType) return attrTypeFilter.includes(valueType)
} }
}) })
}, }
}, },
} }
</script> </script>