From 52ad39c899e4f7bc4bbc35a40ff62461ea51678d Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Fri, 29 Dec 2017 09:14:35 +0530 Subject: [PATCH] [awesome-bar] handle report route via list --- .../js/frappe/ui/toolbar/awesome_bar.js | 4 ++-- .../js/frappe/ui/toolbar/search_utils.js | 19 ++++++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/frappe/public/js/frappe/ui/toolbar/awesome_bar.js b/frappe/public/js/frappe/ui/toolbar/awesome_bar.js index cd1b743735..20f3c7198e 100644 --- a/frappe/public/js/frappe/ui/toolbar/awesome_bar.js +++ b/frappe/public/js/frappe/ui/toolbar/awesome_bar.js @@ -180,7 +180,7 @@ frappe.search.AwesomeBar = Class.extend({ var out = [], routes = []; options.forEach(function(option) { if(option.route) { - if(option.route[0] === "List" && option.route[2]) { + if(option.route[0] === "List" && option.route[2] !== 'Report') { option.route.splice(2); } var str_route = (typeof option.route==='string') ? @@ -190,7 +190,7 @@ frappe.search.AwesomeBar = Class.extend({ routes.push(str_route); } else { var old = routes.indexOf(str_route); - if(out[old].index < option.index) { + if(out[old].index < option.index && !option.recent) { out[old] = option; } } diff --git a/frappe/public/js/frappe/ui/toolbar/search_utils.js b/frappe/public/js/frappe/ui/toolbar/search_utils.js index c434bef88f..5f7a8ae298 100644 --- a/frappe/public/js/frappe/ui/toolbar/search_utils.js +++ b/frappe/public/js/frappe/ui/toolbar/search_utils.js @@ -20,7 +20,8 @@ frappe.search.utils = { if($.isPlainObject(option)) { option = [option]; } - option.forEach(function(o) { o.match = item; }); + option.forEach(function(o) { o.match = item; o.recent = true;}); + options = option.concat(options); } } @@ -37,7 +38,7 @@ frappe.search.utils = { if(route[0]==='Form') { values.push([route[2], route]); } - else if(in_list(['List', 'Report', 'Tree', 'modules', 'query-report'], route[0])) { + else if(['List', 'Tree', 'modules', 'query-report'].includes(route[0]) || route[2]==='Report') { if(route[1]) { values.push([route[1], route]); } @@ -59,10 +60,10 @@ frappe.search.utils = { out.label = __(match[1][1]).bold(); out.value = __(match[1][1]); } - } else if (in_list(['List', 'Report', 'Tree', 'modules', 'query-report'], match[1][0]) && (match[1].length > 1)) { + } else if (['List', 'Tree', 'modules', 'query-report'].includes(match[1][0]) && (match[1].length > 1)) { var type = match[1][0], label = type; if(type==='modules') label = 'Module'; - else if(type==='query-report') label = 'Report'; + else if(type==='query-report' || match[1][2] ==='Report') label = 'Report'; out.label = __(match[1][1]).bold() + " " + __(label); out.value = __(match[1][1]) + " " + __(label); } else if (match[0]) { @@ -134,7 +135,7 @@ frappe.search.utils = { return { type: type, label: me.bolden_match_part(__(target), keywords) + " " + __(type), - value: __(target) + " " + __(type), + value: __(target + " " + type), index: level + order, match: target, route: route, @@ -166,11 +167,7 @@ frappe.search.utils = { } else { out.push(option("List", ["List", item], 0.05)); if (frappe.model.can_get_report(item)) { - out.push(option("Report", ["Report", item], 0.04)); - } - if (frappe.boot.calendars.indexOf(item) !== -1) { - out.push(option("Calendar", ["List", item, "Calendar"], 0.03)); - out.push(option("Gantt", ["List", item, "Gantt"], 0.02)); + out.push(option("Report", ["List", item, "Report"], 0.04)); } } } @@ -188,7 +185,7 @@ frappe.search.utils = { if(level > 0) { var report = frappe.boot.user.all_reports[item]; if(report.report_type == "Report Builder") - route = ["Report", report.ref_doctype, item]; + route = [report.ref_doctype, item, "Report"]; else route = ["query-report", item]; out.push({