feat(dashboard): Add dropdown menu to set filters

This commit is contained in:
Aditya Hase 2019-01-16 15:55:16 +05:30
parent 21ae89e721
commit cc0ea4f5ef
3 changed files with 83 additions and 2 deletions

View file

@ -3,4 +3,14 @@
border-radius: 4px;
margin: 15px 0;
padding: 15px;
}
.chart-actions {
position: absolute;
right: 30px;
top: 30px;
}
.chart-column-container {
position: relative;
}

View file

@ -65,12 +65,49 @@ class Dashboard {
}
render_chart(chart, data) {
chart.filter_fields = JSON.parse(chart.filter_fields || '[]')
chart.filters_json = JSON.parse(chart.filters_json || '{}')
const column_width_map = {
"Half": "6",
"Full": "12",
};
let columns = column_width_map[chart.width];
let chart_container = $(`<div class="col-sm-${columns}"><div class="chart-wrapper"></div></div>`);
let actions = [
{
label: __("More"),
action: "more",
handler() {
const d = new frappe.ui.Dialog({
title: __('Set Filters'),
fields: chart.filter_fields
})
d.set_values(chart.filters_json)
d.show();
}
}
]
let chart_action = $(`<div class="chart-actions btn-group dropdown pull-right">
<a class="dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false"> <button class="btn btn-default btn-xs"><span class="caret"></span></button>
</a>
<ul class="dropdown-menu" style="max-height: 300px; overflow-y: auto;">
${actions.map(action => `<li><a data-action="${action.action}">${action.label}</a></li>`).join('')}
</ul>
</div>
`);
chart_action.find("a[data-action]").each((i, o) => {
const action = o.dataset.action
$(o).click(actions.find(a => a.action === action))
})
let chart_container = $(`<div class="col-sm-${columns} chart-column-container">
<div class="chart-wrapper"></div>
</div>`);
chart_action.prependTo(chart_container)
chart_container.appendTo(this.container);

View file

@ -129,6 +129,7 @@
"label": "Filters JSON",
"length": 0,
"no_copy": 0,
"options": "JSON",
"permlevel": 0,
"precision": "",
"print_hide": 0,
@ -206,6 +207,39 @@
"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": "filter_fields",
"fieldtype": "Code",
"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": "Filter Fields",
"length": 0,
"no_copy": 0,
"options": "JSON",
"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,
@ -218,7 +252,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-01-16 14:33:08.565174",
"modified": "2019-01-16 15:22:10.760396",
"modified_by": "Administrator",
"module": "Desk",
"name": "Dashboard Chart",