Skip to content

Commit

Permalink
feat: add http attr mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
LHRUN committed Jul 3, 2024
1 parent bc66d33 commit 0dc614f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 20 deletions.
10 changes: 10 additions & 0 deletions cmdb-ui/src/modules/cmdb/api/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ export function getSnmpAttributes(type, name) {
})
}

export function getHttpAttrMapping(name, resource) {
return axios({
url: `/v0.1/adr/http/${name}/mapping`,
method: 'GET',
params: {
resource
}
})
}

export function getCITypeDiscovery(type_id) {
return axios({
url: `/v0.1/adt/ci_types/${type_id}`,
Expand Down
55 changes: 36 additions & 19 deletions cmdb-ui/src/modules/cmdb/components/httpSnmpAD/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
</template>

<script>
import { getHttpCategories, getHttpAttributes, getSnmpAttributes } from '../../api/discovery'
import _ from 'lodash'
import { getHttpCategories, getHttpAttributes, getSnmpAttributes, getHttpAttrMapping } from '../../api/discovery'
import AttrMapTable from '@/modules/cmdb/components/attrMapTable/index.vue'
import ADPreviewTable from './adPreviewTable.vue'
import HttpADCategory from './httpADCategory.vue'
Expand Down Expand Up @@ -77,6 +78,7 @@ export default {
categoriesSelect: [],
currentCate: '',
tableData: [],
httpAttrMap: {}
}
},
computed: {
Expand All @@ -103,13 +105,7 @@ export default {
immediate: true,
handler(newVal) {
if (newVal) {
getHttpAttributes(this.ruleName, { resource: newVal }).then((res) => {
if (this.isEdit) {
this.formatTableData(res)
} else {
this.tableData = res
}
})
this.getHttpAttr(newVal)
}
},
},
Expand Down Expand Up @@ -158,28 +154,49 @@ export default {
},
formatTableData(list) {
const _findADT = this.adCITypeList.find((item) => Number(item.adr_id) === Number(this.currentTab))
this.tableData = (list || []).map((item) => {
if (_findADT.attributes) {
return {
...item,
attr: _findADT.attributes[`${item.name}`],
}
this.tableData = (list || []).map((val) => {
const item = _.cloneDeep(val)

if (_findADT?.attributes?.[item.name]) {
item.attr = _findADT.attributes[item.name]
} else {
const _find = this.ciTypeAttributes.find((ele) => ele.name === item.name)
if (_find) {
return {
...item,
attr: _find.name,
}
item.attr = _find.name
}
return item
}

if (
this.isEdit &&
!item.attr &&
this.httpAttrMap?.[item.name]
) {
item.attr = this.httpAttrMap[item.name]
}

return item
})
},
getTableData() {
const $table = this.$refs.attrMapTable
const { fullData } = $table.getTableData()
return fullData || []
},

async getHttpAttr(val) {
await this.getHttpAttrMapping(this.ruleName, val)
getHttpAttributes(this.ruleName, { resource: val }).then((res) => {
if (this.isEdit) {
this.formatTableData(res)
} else {
this.tableData = res
}
})
},

async getHttpAttrMapping(name, resource) {
const res = await getHttpAttrMapping(name, resource)
this.httpAttrMap = res || {}
}
},
}
Expand Down
22 changes: 21 additions & 1 deletion cmdb-ui/src/modules/cmdb/views/relation_views/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@
:data="instanceList"
@checkbox-change="onSelectChange"
@checkbox-all="onSelectChange"
:checkbox-config="{ reserve: true, trigger: 'cell' }"
@checkbox-range-start="checkboxRangeStart"
@checkbox-range-change="checkboxRangeChange"
@checkbox-range-end="checkboxRangeEnd"
:checkbox-config="{ reserve: true, range: true }"
@edit-closed="handleEditClose"
@edit-actived="handleEditActived"
:edit-config="{ trigger: 'dblclick', mode: 'row', showIcon: false }"
Expand Down Expand Up @@ -528,6 +531,8 @@ export default {
isFullSearch: false,
fullTreeData: [],
filterFullTreeData: [],

lastSelected: [], // checkbox range 记录
}
},
computed: {
Expand Down Expand Up @@ -1165,6 +1170,21 @@ export default {
onSelectChange({ records, reserves }) {
this.selectedRowKeys = [...records, ...reserves]
},
checkboxRangeStart(e) {
const xTable = this.$refs.xTable
const lastSelected = xTable.getCheckboxRecords()
const selectedReserve = xTable.getCheckboxReserveRecords()
this.lastSelected = [...lastSelected, ...selectedReserve]
},
checkboxRangeChange(e) {
const xTable = this.$refs.xTable
xTable.setCheckboxRow(this.lastSelected, true)
},
checkboxRangeEnd(e) {
const xTable = this.$refs.xTable
this.lastSelected = []
this.selectedRowKeys = [...xTable.getCheckboxRecords(), ...xTable.getCheckboxReserveRecords()]
},
batchDeleteCIRelation() {
const currentShowType = this.showTypes.find((item) => item.id === Number(this.currentTypeId[0]))
const that = this
Expand Down

0 comments on commit 0dc614f

Please sign in to comment.