feat(desk): List View Settings
This commit is contained in:
parent
ca09a38187
commit
ad65471d06
9 changed files with 307 additions and 3 deletions
0
frappe/desk/doctype/list_view_setting/__init__.py
Normal file
0
frappe/desk/doctype/list_view_setting/__init__.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// Copyright (c) 2019, Frappe Technologies and contributors
|
||||
// For license information, please see license.txt
|
||||
|
||||
frappe.ui.form.on('List View Setting', {
|
||||
// refresh: function(frm) {
|
||||
|
||||
// }
|
||||
});
|
||||
160
frappe/desk/doctype/list_view_setting/list_view_setting.json
Normal file
160
frappe/desk/doctype/list_view_setting/list_view_setting.json
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
{
|
||||
"allow_copy": 0,
|
||||
"allow_events_in_timeline": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"autoname": "Prompt",
|
||||
"beta": 0,
|
||||
"creation": "2019-03-06 13:29:21.101860",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "disable_count",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Disable Count",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "disable_sidebar_stats",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Disable Sidebar Stats",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "disable_auto_refresh",
|
||||
"fieldtype": "Check",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Disable Auto Refresh",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 0,
|
||||
"max_attachments": 0,
|
||||
"modified": "2019-03-06 13:40:59.533586",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Desk",
|
||||
"name": "List View Setting",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
"permissions": [
|
||||
{
|
||||
"amend": 0,
|
||||
"cancel": 0,
|
||||
"create": 1,
|
||||
"delete": 1,
|
||||
"email": 1,
|
||||
"export": 0,
|
||||
"if_owner": 0,
|
||||
"import": 0,
|
||||
"permlevel": 0,
|
||||
"print": 1,
|
||||
"read": 1,
|
||||
"report": 0,
|
||||
"role": "System Manager",
|
||||
"set_user_permissions": 0,
|
||||
"share": 1,
|
||||
"submit": 0,
|
||||
"write": 1
|
||||
}
|
||||
],
|
||||
"quick_entry": 0,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1,
|
||||
"track_seen": 0,
|
||||
"track_views": 0
|
||||
}
|
||||
10
frappe/desk/doctype/list_view_setting/list_view_setting.py
Normal file
10
frappe/desk/doctype/list_view_setting/list_view_setting.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class ListViewSetting(Document):
|
||||
pass
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2019, Frappe Technologies and Contributors
|
||||
# See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
|
||||
class TestListViewSetting(unittest.TestCase):
|
||||
pass
|
||||
26
frappe/desk/listview.py
Normal file
26
frappe/desk/listview.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import frappe
|
||||
import json
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_list_settings(doctype):
|
||||
try:
|
||||
return frappe.get_cached_doc("List View Setting", doctype)
|
||||
except frappe.DoesNotExistError:
|
||||
frappe.clear_messages()
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_list_settings(doctype, values):
|
||||
try:
|
||||
doc = frappe.get_doc("List View Setting", doctype)
|
||||
except frappe.DoesNotExistError:
|
||||
doc = frappe.new_doc("List View Setting")
|
||||
doc.name = doctype
|
||||
frappe.clear_messages()
|
||||
doc.update(json.loads(values))
|
||||
doc.save()
|
||||
|
|
@ -258,6 +258,9 @@ frappe.views.ListSidebar = class ListSidebar {
|
|||
|
||||
get_stats() {
|
||||
var me = this;
|
||||
if (this.list_view.list_view_settings.disable_sidebar_stats) {
|
||||
return;
|
||||
}
|
||||
frappe.call({
|
||||
method: 'frappe.desk.reportview.get_sidebar_stats',
|
||||
type: 'GET',
|
||||
|
|
|
|||
|
|
@ -87,6 +87,11 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
}
|
||||
|
||||
this.patch_refresh_and_load_lib();
|
||||
return this.get_list_view_settings();
|
||||
}
|
||||
|
||||
get_list_view_settings() {
|
||||
return frappe.call("frappe.desk.listview.get_list_settings", {doctype: this.doctype}).then(doc => this.list_view_settings = doc.message || {});
|
||||
}
|
||||
|
||||
on_sort_change(sort_by, sort_order) {
|
||||
|
|
@ -289,7 +294,9 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
}
|
||||
|
||||
freeze() {
|
||||
this.$result.find('.list-count').html(`<span>${__('Refreshing')}...</span>`);
|
||||
if (!this.list_view_settings.disable_count) {
|
||||
this.$result.find('.list-count').html(`<span>${__('Refreshing')}...</span>`);
|
||||
}
|
||||
}
|
||||
|
||||
get_args() {
|
||||
|
|
@ -375,10 +382,11 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
}
|
||||
|
||||
render_count() {
|
||||
this.get_count_str()
|
||||
.then(str => {
|
||||
if (!this.list_view_settings.disable_count) {
|
||||
this.get_count_str().then(str => {
|
||||
this.$result.find('.list-count').html(`<span>${str}</span>`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
render_tags() {
|
||||
|
|
@ -824,6 +832,9 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
}
|
||||
|
||||
setup_realtime_updates() {
|
||||
if (this.list_view_settings.disable_auto_refresh) {
|
||||
return;
|
||||
}
|
||||
frappe.realtime.on('list_update', data => {
|
||||
if (this.filter_area.is_being_edited()) {
|
||||
return;
|
||||
|
|
@ -1026,9 +1037,33 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
|
|||
});
|
||||
}
|
||||
|
||||
if (frappe.user.has_role('System Manager')) {
|
||||
items.push({
|
||||
label: __('Settings'),
|
||||
action: () => this.show_list_settings(),
|
||||
standard: true
|
||||
});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
show_list_settings() {
|
||||
frappe.model.with_doctype("List View Setting", () => {
|
||||
let d = new frappe.ui.Dialog({
|
||||
title: __("Settings"),
|
||||
fields: frappe.get_meta("List View Setting").fields
|
||||
});
|
||||
d.set_values(this.list_view_settings);
|
||||
d.show();
|
||||
d.set_primary_action(__('Save'), () => {
|
||||
let values = d.get_values();
|
||||
frappe.call("frappe.desk.listview.set_list_settings", {doctype: this.doctype, values: values});
|
||||
Object.assign(this.list_view_settings, values);
|
||||
d.hide();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
get_actions_menu_items() {
|
||||
const doctype = this.doctype;
|
||||
const actions_menu_items = [];
|
||||
|
|
|
|||
53
frappe/tests/test_listview.py
Normal file
53
frappe/tests/test_listview.py
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# MIT License. See license.txt
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import unittest
|
||||
import frappe
|
||||
import json
|
||||
|
||||
from frappe.desk.listview import get_list_settings, set_list_settings
|
||||
|
||||
class TestListView(unittest.TestCase):
|
||||
def setUp(self):
|
||||
if frappe.db.exists("List View Setting", "DocType"):
|
||||
frappe.delete_doc("List View Setting", "DocType")
|
||||
|
||||
def test_get_list_settings_without_settings(self):
|
||||
self.assertIsNone(get_list_settings("DocType"), None)
|
||||
|
||||
def test_get_list_settings_with_default_settings(self):
|
||||
frappe.get_doc({"doctype": "List View Setting", "name": "DocType"}).insert()
|
||||
settings = get_list_settings("DocType")
|
||||
self.assertIsNotNone(settings)
|
||||
|
||||
self.assertEqual(settings.disable_auto_refresh, 0)
|
||||
self.assertEqual(settings.disable_count, 0)
|
||||
self.assertEqual(settings.disable_sidebar_stats, 0)
|
||||
|
||||
def test_get_list_settings_with_non_default_settings(self):
|
||||
frappe.get_doc({"doctype": "List View Setting", "name": "DocType", "disable_count": 1}).insert()
|
||||
settings = get_list_settings("DocType")
|
||||
self.assertIsNotNone(settings)
|
||||
|
||||
self.assertEqual(settings.disable_auto_refresh, 0)
|
||||
self.assertEqual(settings.disable_count, 1)
|
||||
self.assertEqual(settings.disable_sidebar_stats, 0)
|
||||
|
||||
def test_set_list_settings_without_settings(self):
|
||||
set_list_settings("DocType", json.dumps({}))
|
||||
settings = frappe.get_doc("List View Setting","DocType")
|
||||
|
||||
self.assertEqual(settings.disable_auto_refresh, 0)
|
||||
self.assertEqual(settings.disable_count, 0)
|
||||
self.assertEqual(settings.disable_sidebar_stats, 0)
|
||||
|
||||
def test_set_list_settings_with_existing_settings(self):
|
||||
frappe.get_doc({"doctype": "List View Setting", "name": "DocType", "disable_count": 1}).insert()
|
||||
set_list_settings("DocType", json.dumps({"disable_count": 0, "disable_auto_refresh": 1}))
|
||||
settings = frappe.get_doc("List View Setting","DocType")
|
||||
|
||||
self.assertEqual(settings.disable_auto_refresh, 1)
|
||||
self.assertEqual(settings.disable_count, 0)
|
||||
self.assertEqual(settings.disable_sidebar_stats, 0)
|
||||
|
||||
Loading…
Add table
Reference in a new issue