diff --git a/cypress/integration/list_view_settings.js b/cypress/integration/list_view_settings.js index 0c564d4aac..84131386f6 100644 --- a/cypress/integration/list_view_settings.js +++ b/cypress/integration/list_view_settings.js @@ -6,7 +6,7 @@ context('List View Settings', () => { it('Default settings', () => { cy.visit('/desk#List/DocType/List'); cy.get('.list-count').should('contain', "20 of"); - cy.get('.sidebar-stat').should('contain', "No Tags"); + cy.get('.sidebar-stat').should('contain', "Tags"); }); it('disable count and sidebar stats then verify', () => { cy.visit('/desk#List/DocType/List'); diff --git a/frappe/desk/listview.py b/frappe/desk/listview.py index f31aae401e..f4927dd098 100644 --- a/frappe/desk/listview.py +++ b/frappe/desk/listview.py @@ -3,8 +3,6 @@ from __future__ import unicode_literals import frappe -import json - @frappe.whitelist() def get_list_settings(doctype): @@ -22,31 +20,37 @@ def set_list_settings(doctype, values): doc = frappe.new_doc("List View Setting") doc.name = doctype frappe.clear_messages() - doc.update(json.loads(values)) + doc.update(frappe.parse_json(values)) doc.save() -@frappe.whitelist() -def get_user_assignments_and_count(doctype, current_filters): +@frappe.whitelist() +def get_group_by_count(doctype, current_filters, field): + current_filters = frappe.parse_json(current_filters) subquery_condition = '' - if current_filters: - # get the subquery - subquery = frappe.get_all(doctype, - filters=current_filters, return_query = True) + + subquery = frappe.get_all(doctype, filters=current_filters, return_query = True) + if field == 'assigned_to': subquery_condition = ' and `tabToDo`.reference_name in ({subquery})'.format(subquery = subquery) + return frappe.db.sql("""select `tabToDo`.owner as name, count(*) as count + from + `tabToDo`, `tabUser` + where + `tabToDo`.status='Open' and + `tabToDo`.owner = `tabUser`.name and + `tabUser`.user_type = 'System User' + {subquery_condition} + group by + `tabToDo`.owner + order by + count desc + limit 50""".format(subquery_condition = subquery_condition), as_dict=True) + else : + return frappe.db.get_list(doctype, + filters=current_filters, + group_by=field, + fields=['count(*) as count', field + ' as name'], + order_by='count desc', + limit=50, + ) - todo_list = frappe.db.sql("""select `tabToDo`.owner as name, count(*) as count - from - `tabToDo`, `tabUser` - where - `tabToDo`.status='Open' and - `tabToDo`.owner = `tabUser`.name and - `tabUser`.user_type = 'System User' - {subquery_condition} - group by - `tabToDo`.owner - order by - count desc - limit 50""".format(subquery_condition = subquery_condition), as_dict=True) - - return todo_list \ No newline at end of file diff --git a/frappe/public/build.json b/frappe/public/build.json index 203a642195..d4defadac7 100755 --- a/frappe/public/build.json +++ b/frappe/public/build.json @@ -276,6 +276,7 @@ "public/js/frappe/list/list_sidebar.js", "public/js/frappe/list/list_sidebar.html", "public/js/frappe/list/list_sidebar_stat.html", + "public/js/frappe/list/list_sidebar_group_by.js", "public/js/frappe/list/list_view_permission_restrictions.html", "public/js/frappe/views/gantt/gantt_view.js", diff --git a/frappe/public/js/frappe/list/list_sidebar.html b/frappe/public/js/frappe/list/list_sidebar.html index c8c2239b03..885b5f2dae 100644 --- a/frappe/public/js/frappe/list/list_sidebar.html +++ b/frappe/public/js/frappe/list/list_sidebar.html @@ -52,21 +52,31 @@ - {% if(frappe.help.has_help(doctype)) { %}
  • {{ __("Help") }}
  • {% } %} + + +