refactor: hide_sidebar on Page
This commit is contained in:
parent
dff85c9993
commit
2f3e44cb77
6 changed files with 26 additions and 43 deletions
|
|
@ -18,9 +18,6 @@ frappe.ui.form.on("Workspace Settings", {
|
|||
frm.docfields.push({
|
||||
fieldtype: "Check",
|
||||
fieldname: page.name,
|
||||
hidden: !frappe.boot.app_data_map[frappe.current_app].workspaces.includes(
|
||||
page.title
|
||||
),
|
||||
label: page.title + (page.parent_page ? ` (${page.parent_page})` : ""),
|
||||
initial_value: workspace_visibilty[page.name] !== 0, // not set is also visible
|
||||
});
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ frappe.Application = class Application {
|
|||
this.add_browser_class();
|
||||
this.setup_copy_doc_listener();
|
||||
this.setup_broadcast_listeners();
|
||||
this.setup_sidebar();
|
||||
|
||||
frappe.ui.keys.setup();
|
||||
|
||||
|
|
@ -137,13 +136,7 @@ frappe.Application = class Application {
|
|||
}
|
||||
}
|
||||
}
|
||||
setup_sidebar() {
|
||||
$(document).on("page-change", function () {
|
||||
if (!frappe.app.sidebar.hide_sidebar) {
|
||||
frappe.app.sidebar.set_workspace_sidebar();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
show_notices() {
|
||||
if (frappe.boot.messages) {
|
||||
frappe.msgprint(frappe.boot.messages);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ frappe.ui.Page = class Page {
|
|||
this.views = {};
|
||||
|
||||
this.make();
|
||||
if (!Object.keys(opts).includes("hide_sidebar")) this.hide_sidebar = false;
|
||||
frappe.ui.pages[frappe.get_route_str()] = this;
|
||||
}
|
||||
|
||||
|
|
@ -188,14 +189,8 @@ frappe.ui.Page = class Page {
|
|||
);
|
||||
})
|
||||
.appendTo(this.sidebar);
|
||||
this.hide_main_sidebar();
|
||||
}
|
||||
hide_main_sidebar() {
|
||||
if (this.hide_sidebar) {
|
||||
frappe.app.sidebar.hide_sidebar = true;
|
||||
frappe.app.sidebar.hide();
|
||||
}
|
||||
}
|
||||
|
||||
setup_sidebar_toggle() {
|
||||
let sidebar_toggle = $(".page-head").find(".sidebar-toggle-btn");
|
||||
let sidebar_wrapper = this.wrapper.find(".layout-side-section");
|
||||
|
|
|
|||
|
|
@ -9,9 +9,8 @@ frappe.ui.Sidebar = class Sidebar {
|
|||
// no sidebar if setup is not complete
|
||||
return;
|
||||
}
|
||||
|
||||
this.make_dom();
|
||||
this.set_all_pages();
|
||||
// this.make_dom();
|
||||
this.sidebar_items = {
|
||||
public: {},
|
||||
private: {},
|
||||
|
|
@ -30,21 +29,38 @@ frappe.ui.Sidebar = class Sidebar {
|
|||
"purple",
|
||||
"light-blue",
|
||||
];
|
||||
|
||||
this.setup_pages();
|
||||
this.handle_outside_click();
|
||||
this.hide_sidebar = false;
|
||||
this.setup_events();
|
||||
}
|
||||
|
||||
setup(workspace_title) {
|
||||
if (!this.setup_complete) {
|
||||
this.workspace_title = workspace_title;
|
||||
this.make_dom();
|
||||
this.apps_switcher = new frappe.ui.SidebarHeader(this, workspace_title);
|
||||
this.make_sidebar(workspace_title.toLowerCase());
|
||||
this.setup_complete = true;
|
||||
}
|
||||
}
|
||||
setup_events() {
|
||||
const me = this;
|
||||
$(document).on("page-change", function () {
|
||||
frappe.app.sidebar.toggle();
|
||||
});
|
||||
$(document).on("form-refresh", function () {
|
||||
frappe.app.sidebar.toggle();
|
||||
});
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (!frappe.container.page.page) return;
|
||||
if (frappe.container.page.page.hide_sidebar) {
|
||||
this.wrapper.hide();
|
||||
} else {
|
||||
frappe.app.sidebar.set_workspace_sidebar();
|
||||
this.wrapper.show();
|
||||
}
|
||||
}
|
||||
make_dom() {
|
||||
this.wrapper = $(frappe.render_template("sidebar")).prependTo("body");
|
||||
|
||||
|
|
@ -73,18 +89,7 @@ frappe.ui.Sidebar = class Sidebar {
|
|||
set_all_pages() {
|
||||
this.sidebar_items = frappe.boot.workspace_sidebar_item;
|
||||
}
|
||||
async set_report_items() {
|
||||
for (let f of this.workspace_sidebar_items) {
|
||||
if (f.link_type === "Report") {
|
||||
const { message } = await frappe.db.get_value("Report", f.link_to, [
|
||||
"report_type",
|
||||
"ref_doctype",
|
||||
]);
|
||||
f.report = message;
|
||||
}
|
||||
}
|
||||
console.log(this.workspace_sidebar_items);
|
||||
}
|
||||
|
||||
set_default_app() {
|
||||
// sort apps based on # of workspaces
|
||||
frappe.boot.app_data.sort((a, b) => (a.workspaces.length < b.workspaces.length ? 1 : -1));
|
||||
|
|
@ -205,7 +210,6 @@ frappe.ui.Sidebar = class Sidebar {
|
|||
route: `/app/${workspace_title}`,
|
||||
};
|
||||
}
|
||||
this.set_report_items();
|
||||
// this.build_sidebar_section("All", parent_pages);
|
||||
this.create_sidebar();
|
||||
|
||||
|
|
@ -220,7 +224,6 @@ frappe.ui.Sidebar = class Sidebar {
|
|||
this.set_sidebar_state();
|
||||
}
|
||||
create_sidebar() {
|
||||
this.set_report_items();
|
||||
if (this.workspace_sidebar_items && this.workspace_sidebar_items.length > 0) {
|
||||
let parent_links = this.workspace_sidebar_items.filter((f) => f.child !== 1);
|
||||
parent_links.forEach((w) => {
|
||||
|
|
@ -521,9 +524,4 @@ frappe.ui.Sidebar = class Sidebar {
|
|||
}
|
||||
this.set_active_workspace_item();
|
||||
}
|
||||
hide() {
|
||||
if (this.wrapper) {
|
||||
this.wrapper.hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ frappe.ui.SidebarHeader = class SidebarHeader {
|
|||
this.add_desktop();
|
||||
this.add_edit_sidebar();
|
||||
this.add_website_select();
|
||||
this.add_settings_select();
|
||||
}
|
||||
|
||||
add_app_item(app) {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ frappe.standard_pages["Workspaces"] = function () {
|
|||
name: "Workspaces",
|
||||
title: __("Workspace"),
|
||||
single_column: true,
|
||||
hide_sidebar: false,
|
||||
});
|
||||
|
||||
frappe.workspace = new frappe.views.Workspace(wrapper);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue