Procházet zdrojové kódy

Show record count in list header

version-14
Faris Ansari před 7 roky
rodič
revize
bc45beb868
3 změnil soubory, kde provedl 43 přidání a 0 odebrání
  1. +10
    -0
      frappe/model/db_query.py
  2. +23
    -0
      frappe/public/js/frappe/list/list_renderer.js
  3. +10
    -0
      frappe/utils/data.py

+ 10
- 0
frappe/model/db_query.py Zobrazit soubor

@@ -578,3 +578,13 @@ def get_list(doctype, *args, **kwargs):
'''wrapper for DatabaseQuery'''
kwargs.pop('cmd', None)
return DatabaseQuery(doctype).execute(None, *args, **kwargs)

@frappe.whitelist()
def get_count(doctype, filters=None):
if filters:
filters = json.loads(filters)

if isinstance(filters, list):
filters = frappe.utils.make_filter_dict(filters)

return frappe.db.count(doctype, filters=filters)

+ 23
- 0
frappe/public/js/frappe/list/list_renderer.js Zobrazit soubor

@@ -355,6 +355,29 @@ frappe.views.ListRenderer = Class.extend({
this.render_tags($item_container, value);
});

this.render_count(values.length);
},

render_count: function(current_count) {
console.log(this)
const $header_right = this.list_view.list_header.find('.list-item__content--activity');

frappe.call({
method: 'frappe.model.db_query.get_count',
args: {
doctype: this.doctype,
filters: this.list_view.get_filters_args()
}
}).then(r => {
const count = r.message;
const $html = $(`<span>${current_count} of ${count}</span>`);

$html.css({
marginRight: '10px'
})
$header_right.addClass('text-muted');
$header_right.html($html);
})
},

// returns html for a data item,


+ 10
- 0
frappe/utils/data.py Zobrazit soubor

@@ -781,6 +781,16 @@ def make_filter_tuple(doctype, key, value):
else:
return [doctype, key, "=", value]

def make_filter_dict(filters):
'''convert this [[doctype, key, operator, value], ..]
to this { key: (operator, value), .. }
'''
_filter = frappe._dict()
for f in filters:
_filter[f[1]] = (f[2], f[3])

return _filter

def scrub_urls(html):
html = expand_relative_urls(html)
# encoding should be responsibility of the composer


Načítá se…
Zrušit
Uložit