mirror of https://github.com/veops/cmdb.git
perf(api): resource search supports recent searches and my favorites
This commit is contained in:
parent
02235d8cc0
commit
417e8fe349
|
@ -108,7 +108,8 @@ class AttributeManager(object):
|
||||||
return []
|
return []
|
||||||
choice_values = choice_table.get_by(fl=["value", "option"], attr_id=attr_id)
|
choice_values = choice_table.get_by(fl=["value", "option"], attr_id=attr_id)
|
||||||
|
|
||||||
return [[ValueTypeMap.serialize[value_type](choice_value['value']), choice_value['option']]
|
return [[ValueTypeMap.serialize[value_type](choice_value['value']), choice_value['option'] or
|
||||||
|
{"label": ValueTypeMap.serialize[value_type](choice_value['value'])}]
|
||||||
for choice_value in choice_values]
|
for choice_value in choice_values]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -140,7 +141,7 @@ class AttributeManager(object):
|
||||||
attr = AttributeCache.get(_attr_id) if _attr_id else _attr
|
attr = AttributeCache.get(_attr_id) if _attr_id else _attr
|
||||||
if attr and attr.is_choice:
|
if attr and attr.is_choice:
|
||||||
choice_values = cls.get_choice_values(attr.id, attr.value_type, None, None)
|
choice_values = cls.get_choice_values(attr.id, attr.value_type, None, None)
|
||||||
return {i[0]: i[1]['label'] for i in choice_values if i[1].get('label')}
|
return {i[0]: i[1]['label'] for i in choice_values if i[1] and i[1].get('label')}
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
|
@ -524,7 +524,14 @@ class CITypeAttributeManager(object):
|
||||||
for _type_id in parent_ids + [type_id]:
|
for _type_id in parent_ids + [type_id]:
|
||||||
result.extend(CITypeAttributesCache.get2(_type_id))
|
result.extend(CITypeAttributesCache.get2(_type_id))
|
||||||
|
|
||||||
return result
|
attr_ids = set()
|
||||||
|
result2 = []
|
||||||
|
for i in result:
|
||||||
|
if i[1].id not in attr_ids:
|
||||||
|
result2.append(i)
|
||||||
|
attr_ids.add(i[1].id)
|
||||||
|
|
||||||
|
return result2
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_attr_names_by_type_id(cls, type_id):
|
def get_attr_names_by_type_id(cls, type_id):
|
||||||
|
|
|
@ -384,6 +384,14 @@ class PreferenceManager(object):
|
||||||
def add_search_option(**kwargs):
|
def add_search_option(**kwargs):
|
||||||
kwargs['uid'] = current_user.uid
|
kwargs['uid'] = current_user.uid
|
||||||
|
|
||||||
|
if kwargs['name'] in ('__recent__', '__favor__'):
|
||||||
|
if kwargs['name'] == '__recent__':
|
||||||
|
for i in PreferenceSearchOption.get_by(
|
||||||
|
only_query=True, name=kwargs['name'], uid=current_user.uid).order_by(
|
||||||
|
PreferenceSearchOption.id.desc()).offset(20):
|
||||||
|
i.delete()
|
||||||
|
|
||||||
|
else:
|
||||||
existed = PreferenceSearchOption.get_by(uid=current_user.uid,
|
existed = PreferenceSearchOption.get_by(uid=current_user.uid,
|
||||||
name=kwargs.get('name'),
|
name=kwargs.get('name'),
|
||||||
prv_id=kwargs.get('prv_id'),
|
prv_id=kwargs.get('prv_id'),
|
||||||
|
|
Loading…
Reference in New Issue