From d80c1d7ad25692e2658ad266401ddc90daf5df86 Mon Sep 17 00:00:00 2001
From: kinyXu <13030514+kinyXu@user.noreply.gitee.com>
Date: Tue, 20 Aug 2024 11:48:44 +0800
Subject: [PATCH 1/4] feat: add attribute sorted tips for non-inherited
 attributes

---
 cmdb-ui/src/modules/cmdb/lang/en.js           |  1 +
 cmdb-ui/src/modules/cmdb/lang/zh.js           |  1 +
 .../cmdb/views/ci_types/attributesTable.vue   | 26 ++++++++++++++++---
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/cmdb-ui/src/modules/cmdb/lang/en.js b/cmdb-ui/src/modules/cmdb/lang/en.js
index e5fbb69..20d882e 100644
--- a/cmdb-ui/src/modules/cmdb/lang/en.js
+++ b/cmdb-ui/src/modules/cmdb/lang/en.js
@@ -130,6 +130,7 @@ const cmdb_en = {
         selectAttribute: 'Select Attribute',
         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!',
+        attributeSortedTips2: 'Non-inherited attributes cannot be inserted before inherited attributes!',
         buildinAttribute: 'built-in attributes',
         expr: 'Expression',
         code: 'Code',
diff --git a/cmdb-ui/src/modules/cmdb/lang/zh.js b/cmdb-ui/src/modules/cmdb/lang/zh.js
index 40fdc00..60f44f8 100644
--- a/cmdb-ui/src/modules/cmdb/lang/zh.js
+++ b/cmdb-ui/src/modules/cmdb/lang/zh.js
@@ -130,6 +130,7 @@ const cmdb_zh = {
         selectAttribute: '添加属性',
         groupExisted: '分组名称已存在',
         attributeSortedTips: '其他分组中的属性不能进行排序,如需排序请先拖至自定义的分组!',
+        attributeSortedTips2: '非继承属性不能插入到继承属性前!',
         buildinAttribute: '内置字段',
         expr: '表达式',
         code: '代码',
diff --git a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
index 6e28ac1..f9fa995 100644
--- a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
+++ b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
@@ -1,5 +1,6 @@
 <template>
   <div>
+    <router-view :key="$route.fullPath"></router-view>
     <a-modal
       v-model="addGroupModal"
       :title="$t('cmdb.ciType.addGroup')"
@@ -233,6 +234,7 @@ export default {
       attrTypeFilter: [],
       unique: '',
       show_id: null,
+      groupMaxCount: {},
     }
   },
   computed: {
@@ -335,6 +337,7 @@ export default {
         })
         this.CITypeGroups = values[1]
         this.CITypeGroups.forEach((g) => {
+          this.groupMaxCount[g.name] = g.attributes.filter(a => a.inherited).length
           g.attributes.forEach((a) => {
             a.is_required = (temp[a.id] && temp[a.id].is_required) || false
             a.default_show = (temp[a.id] && temp[a.id].default_show) || false
@@ -470,8 +473,12 @@ export default {
     handleChange(e, group) {
       console.log('changess', group)
       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()
+        } else if (e.moved.newIndex < this.groupMaxCount[group]) {
+          this.$message.error(this.$t('cmdb.ciType.attributeSortedTips2'))
+          this.refreshPage()
         } else {
           transferCITypeAttrIndex(this.CITypeId, {
             from: { attr_id: e.moved.element.id, group_name: group },
@@ -479,7 +486,7 @@ export default {
           })
             .then((res) => this.$message.success(this.$t('updateSuccess')))
             .catch(() => {
-              this.abortDraggable()
+              this.refreshPage()
             })
         }
       }
@@ -490,17 +497,23 @@ export default {
 
       if (e.hasOwnProperty('removed')) {
         this.$nextTick(() => {
+          if (this.addRemoveGroupFlag.to.order < this.groupMaxCount[this.addRemoveGroupFlag.to.group_name]) {
+            this.$message.error(this.$t('cmdb.ciType.attributeSortedTips2'))
+            this.refreshPage()
+            this.addRemoveGroupFlag = {}
+          } else {
           transferCITypeAttrIndex(this.CITypeId, {
             from: { attr_id: e.removed.element.id, group_name: group },
             to: { group_name: this.addRemoveGroupFlag.to.group_name, order: this.addRemoveGroupFlag.to.order },
           })
             .then((res) => this.$message.success(this.$t('saveSuccess')))
             .catch(() => {
-              this.abortDraggable()
+              this.refreshPage()
             })
             .finally(() => {
               this.addRemoveGroupFlag = {}
             })
+          }
         })
       }
     },
@@ -605,6 +618,13 @@ export default {
         }
       })
     },
+    refreshPage() {
+      const path = this.$route.path
+      const query = { ...this.$route.query, refresh: new Date().getTime() }
+      this.$router.replace({ path: '/cmdb/dashboard' }).then(() => {
+        this.$router.replace({ path, query })
+      })
+    },
   },
 }
 </script>

From 2a38401f5a23d546890cf9193101f5faf3735ffa Mon Sep 17 00:00:00 2001
From: thexqn <thexqn@gmail.com>
Date: Fri, 23 Aug 2024 16:29:29 +0800
Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8?=
 =?UTF-8?q?=E7=BB=A7=E6=89=BF=E6=A8=A1=E5=9E=8B=E7=9A=84=E6=83=85=E5=86=B5?=
 =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E9=9D=9E=E7=BB=A7=E6=89=BF=E5=B1=9E=E6=80=A7?=
 =?UTF-8?q?=E4=B8=8E=E7=BB=A7=E6=89=BF=E5=B1=9E=E6=80=A7=E7=9A=84=E6=8E=92?=
 =?UTF-8?q?=E5=BA=8F=E4=BB=A5=E5=8F=8A=E5=85=B6=E4=BB=96=E5=88=86=E7=BB=84?=
 =?UTF-8?q?=E7=9A=84=E6=8E=92=E5=BA=8F=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../cmdb/views/ci_types/attributesTable.vue   | 45 +++++++------------
 1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
index 18855b5..c01a402 100644
--- a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
+++ b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
@@ -479,53 +479,42 @@ export default {
       console.log('changess', group)
       if (e.hasOwnProperty('moved') && e.moved.oldIndex !== e.moved.newIndex) {
         if (group === -1 || group === null) {
-          this.$message.error(this.$t('cmdb.ciType.attributeSortedTips'))
-          this.refreshPage()
+          this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips'))
         } else if (e.moved.newIndex < this.groupMaxCount[group]) {
-          this.$message.error(this.$t('cmdb.ciType.attributeSortedTips2'))
-          this.refreshPage()
+          this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips2'))
         } else {
           transferCITypeAttrIndex(this.CITypeId, {
             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')))
-            .catch(() => {
-              this.refreshPage()
-            })
+            .then(() => this.$message.success(this.$t('updateSuccess')))
+            .catch(() => this.init())
         }
       }
-
       if (e.hasOwnProperty('added')) {
         this.addRemoveGroupFlag = { to: { group_name: group, order: e.added.newIndex }, inited: true }
       }
-
       if (e.hasOwnProperty('removed')) {
         this.$nextTick(() => {
           if (this.addRemoveGroupFlag.to.order < this.groupMaxCount[this.addRemoveGroupFlag.to.group_name]) {
-            this.$message.error(this.$t('cmdb.ciType.attributeSortedTips2'))
-            this.refreshPage()
-            this.addRemoveGroupFlag = {}
+            this.refreshPage(this.$t('cmdb.ciType.attributeSortedTips2'))
           } else {
-          transferCITypeAttrIndex(this.CITypeId, {
-            from: { attr_id: e.removed.element.id, group_name: group },
-            to: { group_name: this.addRemoveGroupFlag.to.group_name, order: this.addRemoveGroupFlag.to.order },
-          })
-            .then((res) => this.$message.success(this.$t('saveSuccess')))
-            .catch(() => {
-              this.refreshPage()
-            })
-            .finally(() => {
-              this.addRemoveGroupFlag = {}
+            transferCITypeAttrIndex(this.CITypeId, {
+              from: { attr_id: e.removed.element.id, group_name: group },
+              to: { group_name: this.addRemoveGroupFlag.to.group_name, order: this.addRemoveGroupFlag.to.order }
             })
+              .then(() => this.$message.success(this.$t('saveSuccess')))
+              .catch(() => this.init())
+              .finally(() => {
+                this.addRemoveGroupFlag = {}
+              })
           }
         })
       }
     },
-    abortDraggable() {
-      this.$nextTick(() => {
-        this.$router.push({ name: 'ci_type' })
-      })
+    refreshPage(errorMessage) {
+      this.$message.error(errorMessage)
+      this.init()
     },
     updatePropertyIndex() {
       const attributes = [] // All attributes

From 0679fb96e9ab4249682b290439e7c48eb9952f96 Mon Sep 17 00:00:00 2001
From: thexqn <thexqn@gmail.com>
Date: Fri, 23 Aug 2024 16:50:37 +0800
Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8?=
 =?UTF-8?q?=E7=BB=A7=E6=89=BF=E6=A8=A1=E5=9E=8B=E7=9A=84=E6=83=85=E5=86=B5?=
 =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E9=9D=9E=E7=BB=A7=E6=89=BF=E5=B1=9E=E6=80=A7?=
 =?UTF-8?q?=E4=B8=8E=E7=BB=A7=E6=89=BF=E5=B1=9E=E6=80=A7=E7=9A=84=E6=8E=92?=
 =?UTF-8?q?=E5=BA=8F=E4=BB=A5=E5=8F=8A=E5=85=B6=E4=BB=96=E5=88=86=E7=BB=84?=
 =?UTF-8?q?=E7=9A=84=E6=8E=92=E5=BA=8F=E7=9A=84=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../src/modules/cmdb/views/ci_types/attributesTable.vue  | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
index c01a402..cf1702c 100644
--- a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
+++ b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
@@ -596,14 +596,7 @@ export default {
           return attrTypeFilter.includes(valueType)
         }
       })
-    },
-    refreshPage() {
-      const path = this.$route.path
-      const query = { ...this.$route.query, refresh: new Date().getTime() }
-      this.$router.replace({ path: '/cmdb/dashboard' }).then(() => {
-        this.$router.replace({ path, query })
-      })
-    },
+    }
   },
 }
 </script>

From 0a087df03fb3098a8b438f47abb9d5a48e4dccef Mon Sep 17 00:00:00 2001
From: thexqn <thexqn@gmail.com>
Date: Fri, 23 Aug 2024 16:55:21 +0800
Subject: [PATCH 4/4] =?UTF-8?q?=E6=B8=85=E7=90=86=E5=A4=9A=E4=BD=99?=
 =?UTF-8?q?=E7=9A=84router-view?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue | 1 -
 1 file changed, 1 deletion(-)

diff --git a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
index cf1702c..74d67e6 100644
--- a/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
+++ b/cmdb-ui/src/modules/cmdb/views/ci_types/attributesTable.vue
@@ -1,6 +1,5 @@
 <template>
   <div>
-    <router-view :key="$route.fullPath"></router-view>
     <a-modal
       v-model="addGroupModal"
       :title="$t('cmdb.ciType.addGroup')"