fix: enhance the sidebar which is generated
This commit is contained in:
parent
d9d231feb8
commit
e2ff41dc89
3 changed files with 48 additions and 14 deletions
|
|
@ -18,7 +18,6 @@ def execute():
|
|||
sidebar.header_icon = "hammer"
|
||||
sidebars.append(sidebar)
|
||||
sidebar.save()
|
||||
return sidebars
|
||||
|
||||
|
||||
def get_module_info(module_name):
|
||||
|
|
@ -32,30 +31,63 @@ def get_module_info(module_name):
|
|||
filters.append({"istable": 0})
|
||||
module_info[entity] = frappe.get_all(entity, filters=filters, pluck="name")
|
||||
|
||||
# if module info has no workspaces, then move doctypes to the front
|
||||
if not module_info.get("Workspace"):
|
||||
module_info = {
|
||||
"DocType": module_info.get("DocType"),
|
||||
"Workspace": module_info.get("Workspace"),
|
||||
"Report": module_info.get("Report"),
|
||||
"Dashboard": module_info.get("Dashboard"),
|
||||
"Page": module_info.get("Page"),
|
||||
}
|
||||
return module_info
|
||||
|
||||
|
||||
def create_sidebar_items(module_info):
|
||||
sidebar_items = []
|
||||
idx = 1
|
||||
|
||||
section_entities = {"report": "Reports", "dashboard": "Dashboards", "page": "Pages"}
|
||||
|
||||
for entity, items in module_info.items():
|
||||
if entity.lower() == "report":
|
||||
section_break = frappe.new_doc("Workspace Sidebar Item")
|
||||
section_break.update(
|
||||
{
|
||||
"type": "Section Break",
|
||||
}
|
||||
)
|
||||
section_break_added = False
|
||||
entity_lower = entity.lower()
|
||||
|
||||
if entity_lower in section_entities:
|
||||
if entity_lower == "report":
|
||||
section_break = add_section_breaks("Reports", idx)
|
||||
elif entity_lower in ("dashboard", "page") and len(items) > 1:
|
||||
section_break = add_section_breaks(section_entities[entity_lower], idx)
|
||||
section_break_added = True
|
||||
sidebar_items.append(section_break)
|
||||
idx += 1
|
||||
|
||||
for item in items:
|
||||
item_info = {"label": item, "type": "Link", "link_type": entity, "link_to": item}
|
||||
if entity.lower() == "workspace":
|
||||
print(entity, item)
|
||||
item_info = {"label": item, "type": "Link", "link_type": entity, "link_to": item, "idx": idx}
|
||||
|
||||
if entity_lower == "report":
|
||||
item_info["child"] = 1
|
||||
|
||||
if entity_lower == "workspace":
|
||||
item_info["icon"] = "home"
|
||||
|
||||
if entity.lower() == "doctype" and "settings" in item.lower():
|
||||
if entity_lower == "doctype" and "settings" in item.lower():
|
||||
item_info["icon"] = "settings"
|
||||
|
||||
if section_break_added:
|
||||
item_info["child"] = 1
|
||||
|
||||
sidebar_item = frappe.new_doc("Workspace Sidebar Item")
|
||||
sidebar_item.update(item_info)
|
||||
sidebar_items.append(sidebar_item)
|
||||
|
||||
idx += 1
|
||||
|
||||
return sidebar_items
|
||||
|
||||
|
||||
def add_section_breaks(label, idx):
|
||||
section_break = frappe.new_doc("Workspace Sidebar Item")
|
||||
section_break.update({"label": label, "type": "Section Break", "idx": idx})
|
||||
return section_break
|
||||
|
|
|
|||
|
|
@ -161,11 +161,11 @@ frappe.ui.Sidebar = class Sidebar {
|
|||
let match = false;
|
||||
const that = this;
|
||||
$(".item-anchor").each(function () {
|
||||
let href = $(this).attr("href")?.split("?")[0];
|
||||
let href = decodeURIComponent($(this).attr("href")?.split("?")[0]);
|
||||
const path = decodeURIComponent(window.location.pathname);
|
||||
|
||||
// Match only if path equals href or starts with it followed by "/" or end of string
|
||||
const isActive = new RegExp(`^${href}(?:/|$)`).test(path);
|
||||
const isActive = href === path;
|
||||
if (href && isActive) {
|
||||
match = true;
|
||||
if (that.active_item) that.active_item.removeClass("active-sidebar");
|
||||
|
|
|
|||
|
|
@ -54,7 +54,9 @@ frappe.ui.sidebar_item.TypeLink = class SidebarItem {
|
|||
});
|
||||
}
|
||||
}
|
||||
return path;
|
||||
if (path) {
|
||||
return encodeURI(path);
|
||||
}
|
||||
}
|
||||
prepare() {}
|
||||
make() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue