Skip to content

Commit

Permalink
Merge pull request #616 from thexqn/optimize_history
Browse files Browse the repository at this point in the history
feat: Add show_attr value column to operation history table
  • Loading branch information
pycook authored Sep 14, 2024
2 parents bb7157e + 131d213 commit f32339b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ cmdb-ui/npm-debug.log*
cmdb-ui/yarn-debug.log*
cmdb-ui/yarn-error.log*
cmdb-ui/package-lock.json
start.sh
18 changes: 18 additions & 0 deletions cmdb-api/api/lib/cmdb/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from api.lib.cmdb.cache import AttributeCache
from api.lib.cmdb.cache import RelationTypeCache
from api.lib.cmdb.const import OperateType
from api.lib.cmdb.cache import CITypeCache
from api.lib.cmdb.perms import CIFilterPermsCRUD
from api.lib.cmdb.resp_format import ErrFormat
from api.lib.perm.acl.cache import UserCache
Expand All @@ -22,6 +23,7 @@
from api.models.cmdb import CITypeTrigger
from api.models.cmdb import CITypeUniqueConstraint
from api.models.cmdb import OperationRecord
from api.lib.cmdb.utils import TableMap


class AttributeHistoryManger(object):
Expand Down Expand Up @@ -59,8 +61,23 @@ def get_records_for_attributes(start, end, username, page, page_size, operate_ty
total = len(records)

res = {}
show_attr_set = {}
show_attr_cache = {}
for record in records:
record_id = record.OperationRecord.id
type_id = record.OperationRecord.type_id
ci_id = record.AttributeHistory.ci_id
show_attr_set[ci_id] = None
show_attr = show_attr_cache.setdefault(
type_id,
AttributeCache.get(
CITypeCache.get(type_id).show_id or CITypeCache.get(type_id).unique_id) if CITypeCache.get(type_id) else None
)
if show_attr:
attr_table = TableMap(attr=show_attr).table
attr_record = attr_table.get_by(attr_id=show_attr.id, ci_id=ci_id, first=True, to_dict=False)
show_attr_set[ci_id] = attr_record.value if attr_record else None

attr_hist = record.AttributeHistory.to_dict()
attr_hist['attr'] = AttributeCache.get(attr_hist['attr_id'])
if attr_hist['attr']:
Expand All @@ -76,6 +93,7 @@ def get_records_for_attributes(start, end, username, page, page_size, operate_ty

if record_id not in res:
record_dict = record.OperationRecord.to_dict()
record_dict['show_attr_value'] = show_attr_set.get(ci_id)
record_dict["user"] = UserCache.get(record_dict.get("uid"))
if record_dict["user"]:
record_dict['user'] = record_dict['user'].nickname
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</template>
</vxe-column>
<vxe-column field="type_id" width="100px" :title="$t('cmdb.ciType.ciType')"></vxe-column>
<vxe-column field="show_attr_value" width="100px" :title="$t('cmdb.ciType.show')"></vxe-column>
<vxe-column field="operate_type" width="89px" :title="$t('operation')">
<template #header="{ column }">
<span>{{ column.title }}</span>
Expand Down Expand Up @@ -314,7 +315,7 @@ export default {
}
},
mergeRowMethod({ row, _rowIndex, column, visibleData }) {
const fields = ['created_at', 'user', 'type_id']
const fields = ['created_at', 'user', 'type_id', 'show_attr_value']
const cellValue = row[column.property]
const created_at = row['created_at']
if (column.property === 'created_at') {
Expand Down Expand Up @@ -365,6 +366,22 @@ export default {
}
}
}
} else if (column.property === 'show_attr_value') {
if (cellValue && fields.includes(column.property)) {
const prevRow = visibleData[_rowIndex - 1]
let nextRow = visibleData[_rowIndex + 1]
if (prevRow && prevRow[column.property] === cellValue && prevRow['created_at'] === created_at) {
return { rowspan: 0, colspan: 0 }
} else {
let countRowspan = 1
while (nextRow && nextRow[column.property] === cellValue && nextRow['created_at'] === created_at) {
nextRow = visibleData[++countRowspan + _rowIndex]
}
if (countRowspan > 1) {
return { rowspan: countRowspan, colspan: 1 }
}
}
}
}
},
filterUser() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
@change="onChange"
format="YYYY-MM-DD HH:mm"
:placeholder="[$t('cmdb.history.startTime'), $t('cmdb.history.endTime')]"
v-else-if="attr.value_type === '3'"
v-else-if="valueTypeMap[item.value_type] == 'date' || valueTypeMap[item.value_type] == 'datetime'"
:show-time="{
hideDisabledOptions: true,
defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
Expand Down

0 comments on commit f32339b

Please sign in to comment.