fix[filters]: Load filters from report doc & more(#6556)

* fix(Custom Report): Load filters from report doc

For Custom Report, load filters only from the report doc. For the report
builder, filters should load similar to listview.

* fix(Kanban): Explicit menu action to save filters

* fix: indent

* fix: Always route to the List view from dashboard
This commit is contained in:
Faris Ansari 2018-12-03 15:52:53 +05:30 committed by Suraj Shetty
parent 17e3e6f557
commit 9d13d3cd07
5 changed files with 70 additions and 6 deletions

View file

@ -301,7 +301,7 @@ frappe.ui.form.Dashboard = Class.extend({
}
}
frappe.set_route("List", doctype);
frappe.set_route("List", doctype, "List");
},
get_document_filter: function(doctype) {
// return the default filter for the given document

View file

@ -392,6 +392,10 @@ frappe.views.BaseList = class BaseList {
// for child classes
}
on_filter_change() {
// fired when filters are added or removed
}
toggle_result_area() {
this.$result.toggle(this.data.length > 0);
this.$paging_area.toggle(this.data.length > 0);
@ -480,6 +484,7 @@ class FilterArea {
if (this.trigger_refresh) {
this.list_view.start = 0;
this.list_view.refresh();
this.list_view.on_filter_change();
}
}

View file

@ -290,6 +290,15 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
return Promise.resolve();
}
parse_filters_from_settings() {
return (this.settings.filters || []).map(f => {
if (f.length === 3) {
f = [this.doctype, f[0], f[1], f[2]];
}
return f;
});
}
toggle_result_area() {
super.toggle_result_area();
this.toggle_actions_menu_button(

View file

@ -32,10 +32,14 @@ frappe.views.KanbanView = class KanbanView extends frappe.views.ListView {
this.page_title = this.board_name;
this.card_meta = this.get_card_meta();
return this.get_board()
.then(() => {
this.filters = this.board.filters_array;
});
this.menu_items.push({
label: __('Save filters'),
action: () => {
this.save_kanban_board_filters();
}
});
return this.get_board();
}
get_board() {
@ -43,9 +47,14 @@ frappe.views.KanbanView = class KanbanView extends frappe.views.ListView {
.then(board => {
this.board = board;
this.board.filters_array = JSON.parse(this.board.filters || '[]');
this.filters = this.board.filters_array;
});
}
before_refresh() {
}
setup_view() {
}
@ -60,13 +69,40 @@ frappe.views.KanbanView = class KanbanView extends frappe.views.ListView {
this.save_view_user_settings({
last_kanban_board: this.board_name
});
}
on_filter_change() {
if (JSON.stringify(this.board.filters_array) !== JSON.stringify(this.filter_area.get())) {
this.page.set_indicator(__('Not Saved'), 'orange');
} else {
this.page.clear_indicator();
}
}
save_kanban_board_filters() {
const filters = this.filter_area.get();
frappe.call({
method: 'frappe.desk.doctype.kanban_board.kanban_board.save_filters',
args: {
board_name: this.board_name,
filters: this.filter_area.get()
filters: filters
}
}).then(r => {
if (r.exc) {
frappe.show_alert({
indicator: 'red',
message: __('There was an error saving filters')
});
return;
}
frappe.show_alert({
indicator: 'green',
message: __('Filters saved')
});
this.board.filters_array = filters;
this.on_filter_change();
});
}

View file

@ -121,6 +121,16 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
}
}
on_filter_change() {
if (this.report_doc) {
if (JSON.stringify(this.filters) !== JSON.stringify(this.filter_area.get())) {
this.page.set_indicator(__('Not Saved'), 'orange');
} else {
this.page.clear_indicator();
}
}
}
update_row(doc, flash_row) {
const to_refresh = [];
@ -899,6 +909,10 @@ frappe.views.ReportView = class ReportView extends frappe.views.ListView {
if(r.message != this.report_name) {
frappe.set_route('List', this.doctype, 'Report', r.message);
}
// reset dirty state
this.filters = this.filter_area.get();
this.on_filter_change();
}
});