mirror of https://github.com/veops/cmdb.git
support JSON type
This commit is contained in:
parent
3a8d4ecebc
commit
317a16aa21
|
@ -11,6 +11,7 @@ class ValueTypeEnum(BaseEnum):
|
||||||
DATETIME = "3"
|
DATETIME = "3"
|
||||||
DATE = "4"
|
DATE = "4"
|
||||||
TIME = "5"
|
TIME = "5"
|
||||||
|
JSON = "6"
|
||||||
|
|
||||||
|
|
||||||
class CIStatusEnum(BaseEnum):
|
class CIStatusEnum(BaseEnum):
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
from flask import abort
|
from flask import abort
|
||||||
from flask import g
|
from flask import g
|
||||||
|
|
||||||
|
@ -105,8 +107,8 @@ class AttributeHistoryManger(object):
|
||||||
for attr_id, operate_type, old, new in history_list or []:
|
for attr_id, operate_type, old, new in history_list or []:
|
||||||
AttributeHistory.create(attr_id=attr_id,
|
AttributeHistory.create(attr_id=attr_id,
|
||||||
operate_type=operate_type,
|
operate_type=operate_type,
|
||||||
old=old,
|
old=json.dumps(old) if isinstance(old, (dict, list)) else old,
|
||||||
new=new,
|
new=json.dumps(new) if isinstance(new, (dict, list)) else new,
|
||||||
ci_id=ci_id,
|
ci_id=ci_id,
|
||||||
record_id=record.id)
|
record_id=record.id)
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
import json
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
|
@ -33,15 +34,17 @@ class ValueTypeMap(object):
|
||||||
ValueTypeEnum.TIME: lambda x: escape(x).encode('utf-8').decode('utf-8'),
|
ValueTypeEnum.TIME: lambda x: escape(x).encode('utf-8').decode('utf-8'),
|
||||||
ValueTypeEnum.DATETIME: str2datetime,
|
ValueTypeEnum.DATETIME: str2datetime,
|
||||||
ValueTypeEnum.DATE: str2datetime,
|
ValueTypeEnum.DATE: str2datetime,
|
||||||
|
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) else x,
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize = {
|
serialize = {
|
||||||
ValueTypeEnum.INT: int,
|
ValueTypeEnum.INT: int,
|
||||||
ValueTypeEnum.FLOAT: float,
|
ValueTypeEnum.FLOAT: float,
|
||||||
ValueTypeEnum.TEXT: lambda x: x if isinstance(x, six.text_type) else str(x),
|
ValueTypeEnum.TEXT: lambda x: x if isinstance(x, six.string_types) else str(x),
|
||||||
ValueTypeEnum.TIME: lambda x: x if isinstance(x, six.text_type) else str(x),
|
ValueTypeEnum.TIME: lambda x: x if isinstance(x, six.string_types) else str(x),
|
||||||
ValueTypeEnum.DATE: lambda x: x.strftime("%Y-%m-%d"),
|
ValueTypeEnum.DATE: lambda x: x.strftime("%Y-%m-%d"),
|
||||||
ValueTypeEnum.DATETIME: lambda x: x.strftime("%Y-%m-%d %H:%M:%S"),
|
ValueTypeEnum.DATETIME: lambda x: x.strftime("%Y-%m-%d %H:%M:%S"),
|
||||||
|
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) else x,
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize2 = {
|
serialize2 = {
|
||||||
|
@ -51,6 +54,7 @@ class ValueTypeMap(object):
|
||||||
ValueTypeEnum.TIME: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
ValueTypeEnum.TIME: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
||||||
ValueTypeEnum.DATE: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
ValueTypeEnum.DATE: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
||||||
ValueTypeEnum.DATETIME: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
ValueTypeEnum.DATETIME: lambda x: x.decode() if not isinstance(x, six.string_types) else x,
|
||||||
|
ValueTypeEnum.JSON: lambda x: json.loads(x) if isinstance(x, six.string_types) else x,
|
||||||
}
|
}
|
||||||
|
|
||||||
choice = {
|
choice = {
|
||||||
|
@ -66,12 +70,14 @@ class ValueTypeMap(object):
|
||||||
ValueTypeEnum.DATE: model.CIValueDateTime,
|
ValueTypeEnum.DATE: model.CIValueDateTime,
|
||||||
ValueTypeEnum.TIME: model.CIValueText,
|
ValueTypeEnum.TIME: model.CIValueText,
|
||||||
ValueTypeEnum.FLOAT: model.CIValueFloat,
|
ValueTypeEnum.FLOAT: model.CIValueFloat,
|
||||||
|
ValueTypeEnum.JSON: model.CIValueJson,
|
||||||
'index_{0}'.format(ValueTypeEnum.INT): model.CIIndexValueInteger,
|
'index_{0}'.format(ValueTypeEnum.INT): model.CIIndexValueInteger,
|
||||||
'index_{0}'.format(ValueTypeEnum.TEXT): model.CIIndexValueText,
|
'index_{0}'.format(ValueTypeEnum.TEXT): model.CIIndexValueText,
|
||||||
'index_{0}'.format(ValueTypeEnum.DATETIME): model.CIIndexValueDateTime,
|
'index_{0}'.format(ValueTypeEnum.DATETIME): model.CIIndexValueDateTime,
|
||||||
'index_{0}'.format(ValueTypeEnum.DATE): model.CIIndexValueDateTime,
|
'index_{0}'.format(ValueTypeEnum.DATE): model.CIIndexValueDateTime,
|
||||||
'index_{0}'.format(ValueTypeEnum.TIME): model.CIIndexValueText,
|
'index_{0}'.format(ValueTypeEnum.TIME): model.CIIndexValueText,
|
||||||
'index_{0}'.format(ValueTypeEnum.FLOAT): model.CIIndexValueFloat,
|
'index_{0}'.format(ValueTypeEnum.FLOAT): model.CIIndexValueFloat,
|
||||||
|
'index_{0}'.format(ValueTypeEnum.JSON): model.CIValueJson,
|
||||||
}
|
}
|
||||||
|
|
||||||
table_name = {
|
table_name = {
|
||||||
|
@ -81,12 +87,14 @@ class ValueTypeMap(object):
|
||||||
ValueTypeEnum.DATE: 'c_value_datetime',
|
ValueTypeEnum.DATE: 'c_value_datetime',
|
||||||
ValueTypeEnum.TIME: 'c_value_texts',
|
ValueTypeEnum.TIME: 'c_value_texts',
|
||||||
ValueTypeEnum.FLOAT: 'c_value_floats',
|
ValueTypeEnum.FLOAT: 'c_value_floats',
|
||||||
|
ValueTypeEnum.JSON: 'c_value_json',
|
||||||
'index_{0}'.format(ValueTypeEnum.INT): 'c_value_index_integers',
|
'index_{0}'.format(ValueTypeEnum.INT): 'c_value_index_integers',
|
||||||
'index_{0}'.format(ValueTypeEnum.TEXT): 'c_value_index_texts',
|
'index_{0}'.format(ValueTypeEnum.TEXT): 'c_value_index_texts',
|
||||||
'index_{0}'.format(ValueTypeEnum.DATETIME): 'c_value_index_datetime',
|
'index_{0}'.format(ValueTypeEnum.DATETIME): 'c_value_index_datetime',
|
||||||
'index_{0}'.format(ValueTypeEnum.DATE): 'c_value_index_datetime',
|
'index_{0}'.format(ValueTypeEnum.DATE): 'c_value_index_datetime',
|
||||||
'index_{0}'.format(ValueTypeEnum.TIME): 'c_value_index_texts',
|
'index_{0}'.format(ValueTypeEnum.TIME): 'c_value_index_texts',
|
||||||
'index_{0}'.format(ValueTypeEnum.FLOAT): 'c_value_index_floats',
|
'index_{0}'.format(ValueTypeEnum.FLOAT): 'c_value_index_floats',
|
||||||
|
'index_{0}'.format(ValueTypeEnum.JSON): 'c_value_json',
|
||||||
}
|
}
|
||||||
|
|
||||||
es_type = {
|
es_type = {
|
||||||
|
@ -95,7 +103,8 @@ class ValueTypeMap(object):
|
||||||
ValueTypeEnum.DATETIME: 'text',
|
ValueTypeEnum.DATETIME: 'text',
|
||||||
ValueTypeEnum.DATE: 'text',
|
ValueTypeEnum.DATE: 'text',
|
||||||
ValueTypeEnum.TIME: 'text',
|
ValueTypeEnum.TIME: 'text',
|
||||||
ValueTypeEnum.FLOAT: 'float'
|
ValueTypeEnum.FLOAT: 'float',
|
||||||
|
ValueTypeEnum.JSON: 'object'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
import redis
|
import redis
|
||||||
import six
|
import six
|
||||||
from elasticsearch import Elasticsearch
|
from elasticsearch import Elasticsearch
|
||||||
|
@ -26,6 +28,9 @@ def get_page_size(page_size):
|
||||||
|
|
||||||
|
|
||||||
def handle_arg_list(arg):
|
def handle_arg_list(arg):
|
||||||
|
if isinstance(arg, six.string_types) and arg.startswith('['):
|
||||||
|
return json.loads(arg)
|
||||||
|
|
||||||
return list(filter(lambda x: x != "", arg.strip().split(","))) if isinstance(arg, six.string_types) else arg
|
return list(filter(lambda x: x != "", arg.strip().split(","))) if isinstance(arg, six.string_types) else arg
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -250,6 +250,17 @@ class CIValueDateTime(Model):
|
||||||
attr = db.relationship("Attribute", backref="c_value_datetime.attr_id")
|
attr = db.relationship("Attribute", backref="c_value_datetime.attr_id")
|
||||||
|
|
||||||
|
|
||||||
|
class CIValueJson(Model):
|
||||||
|
__tablename__ = "c_value_json"
|
||||||
|
|
||||||
|
ci_id = db.Column(db.Integer, db.ForeignKey('c_cis.id'), nullable=False)
|
||||||
|
attr_id = db.Column(db.Integer, db.ForeignKey('c_attributes.id'), nullable=False)
|
||||||
|
value = db.Column(db.JSON, nullable=False)
|
||||||
|
|
||||||
|
ci = db.relationship("CI", backref="c_value_json.ci_id")
|
||||||
|
attr = db.relationship("Attribute", backref="c_value_json.attr_id")
|
||||||
|
|
||||||
|
|
||||||
# history
|
# history
|
||||||
class OperationRecord(Model):
|
class OperationRecord(Model):
|
||||||
__tablename__ = "c_records"
|
__tablename__ = "c_records"
|
||||||
|
|
|
@ -73,7 +73,7 @@ class CIView(APIView):
|
||||||
ci_dict[k] = v.strip() if isinstance(v, six.string_types) else v
|
ci_dict[k] = v.strip() if isinstance(v, six.string_types) else v
|
||||||
return ci_dict
|
return ci_dict
|
||||||
|
|
||||||
@has_perm_from_args("ci_type", ResourceTypeEnum.CI, PermEnum.ADD)
|
@has_perm_from_args("ci_type", ResourceTypeEnum.CI, PermEnum.ADD, lambda x: CITypeCache.get(x).name)
|
||||||
def post(self):
|
def post(self):
|
||||||
ci_type = request.values.get("ci_type")
|
ci_type = request.values.get("ci_type")
|
||||||
_no_attribute_policy = request.values.get("_no_attribute_policy", ExistPolicy.IGNORE)
|
_no_attribute_policy = request.values.get("_no_attribute_policy", ExistPolicy.IGNORE)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
NODE_ENV=production
|
NODE_ENV=production
|
||||||
VUE_APP_PREVIEW=false
|
VUE_APP_PREVIEW=false
|
||||||
VUE_APP_API_BASE_URL=http://127.0.0.1:5000/api
|
VUE_APP_API_BASE_URL=http://127.0.0.1:5001/api
|
||||||
|
|
|
@ -94,7 +94,8 @@ var valueTypeMap = {
|
||||||
'2': 'text',
|
'2': 'text',
|
||||||
'3': 'datetime',
|
'3': 'datetime',
|
||||||
'4': 'date',
|
'4': 'date',
|
||||||
'5': 'time'
|
'5': 'time',
|
||||||
|
'6': 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -270,6 +271,7 @@ export default {
|
||||||
const col = {}
|
const col = {}
|
||||||
col.title = item.alias
|
col.title = item.alias
|
||||||
col.dataIndex = item.name
|
col.dataIndex = item.name
|
||||||
|
col.value_type = item.value_type
|
||||||
if (index !== prefAttrList.length - 1) {
|
if (index !== prefAttrList.length - 1) {
|
||||||
col.width = 100
|
col.width = 100
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ var valueTypeMap = {
|
||||||
'2': 'text',
|
'2': 'text',
|
||||||
'3': 'datetime',
|
'3': 'datetime',
|
||||||
'4': 'date',
|
'4': 'date',
|
||||||
'5': 'time'
|
'5': 'time',
|
||||||
|
'6': 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="editable-cell">
|
<div class="editable-cell">
|
||||||
<div v-if="editable.x" class="editable-cell-input-wrapper">
|
<div v-if="editable.x" class="editable-cell-input-wrapper">
|
||||||
<a-input :value="value" @change="handleChange" @pressEnter="check" />
|
<a-input :value="value | joinList" @change="handleChange" @pressEnter="check" />
|
||||||
<a-icon type="check" class="editable-cell-icon-check" @click="check" />
|
<a-icon type="check" class="editable-cell-icon-check" @click="check" />
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="editable-cell-text-wrapper">
|
<div v-else class="editable-cell-text-wrapper">
|
||||||
|
@ -37,10 +37,25 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filters: {
|
filters: {
|
||||||
|
jsonDump: function (v) {
|
||||||
|
if (typeof v === 'object') {
|
||||||
|
return JSON.stringify(v)
|
||||||
|
} else {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
},
|
||||||
joinList: function (itemValue) {
|
joinList: function (itemValue) {
|
||||||
if (typeof itemValue === 'object' && itemValue) {
|
if (typeof itemValue === 'object' && itemValue) {
|
||||||
|
try {
|
||||||
|
if (typeof itemValue[0] !== 'object') {
|
||||||
return itemValue.join(',')
|
return itemValue.join(',')
|
||||||
} else if (itemValue !== null && itemValue !== 'undefined') {
|
} else {
|
||||||
|
return JSON.stringify(itemValue)
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return JSON.stringify(itemValue)
|
||||||
|
}
|
||||||
|
} else if (itemValue !== null && itemValue !== 'undefined' && itemValue !== undefined && itemValue !== 'null') {
|
||||||
return itemValue + ''
|
return itemValue + ''
|
||||||
} else {
|
} else {
|
||||||
return ''
|
return ''
|
||||||
|
|
|
@ -97,7 +97,8 @@ var valueTypeMap = {
|
||||||
'2': 'text',
|
'2': 'text',
|
||||||
'3': 'datetime',
|
'3': 'datetime',
|
||||||
'4': 'date',
|
'4': 'date',
|
||||||
'5': 'time'
|
'5': 'time',
|
||||||
|
'6': 'json'
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -4,5 +4,6 @@ export const valueTypeMap = {
|
||||||
'2': '文本',
|
'2': '文本',
|
||||||
'3': 'datetime',
|
'3': 'datetime',
|
||||||
'4': 'date',
|
'4': 'date',
|
||||||
'5': 'time'
|
'5': 'time',
|
||||||
|
'6': 'json'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue