fix: tags should consider list filters

This commit is contained in:
Himanshu Warekar 2019-11-20 16:09:01 +05:30
parent de2064a9a6
commit c3f68142db
2 changed files with 18 additions and 11 deletions

View file

@ -261,17 +261,24 @@ def delete_bulk(doctype, items):
@frappe.whitelist()
@frappe.read_only()
def get_sidebar_stats(stats, doctype, filters=[]):
_user_tags = []
data = frappe._dict(frappe.local.form_dict)
filters = json.loads(data["filters"])
if not frappe.cache().hget("tags_count", doctype):
tags = [tag.name for tag in frappe.get_list("Tag")]
_user_tags = []
for tag in tags:
count = frappe.db.count("Tag Link", filters={"document_type": doctype, "tag": tag})
if count > 0:
_user_tags.append([tag, count])
frappe.cache().hset("tags_count", doctype, _user_tags)
if not frappe.cache().hget("Tags", doctype):
tags = set([tag.tag for tag in frappe.get_list("Tag Link", filters={"document_type": doctype}, fields=["tag"])])
frappe.cache().hset("Tags", doctype, tags)
return {"stats": {"_user_tags": frappe.cache().hget("tags_count", doctype)}}
for tag in list(frappe.cache().hget("Tags", doctype)):
tag_filters = []
tag_filters.extend(filters)
tag_filters.extend([['Tag Link', 'tag', '=', tag]])
count = frappe.get_all(doctype, filters=tag_filters, fields=["count(*)"])
if count[0].get("count(*)") > 0:
_user_tags.append([tag, count[0].get("count(*)")])
return {"stats": {"_user_tags": _user_tags}}
@frappe.whitelist()
@frappe.read_only()

View file

@ -386,8 +386,8 @@ frappe.views.ListSidebar = class ListSidebar {
}
reload_stats() {
this.sidebar.find(".sidebar-stat").remove();
this.sidebar.find(".list-tag-preview").remove();
this.sidebar.find(".stat-link").remove();
this.sidebar.find(".stat-no-records").remove();
this.get_stats();
}