feat: hide/unhide workspace from sidebar

This commit is contained in:
Shariq Ansari 2023-01-09 17:51:25 +05:30
parent 32ea734e9c
commit 97a57f7105
6 changed files with 178 additions and 25 deletions

View file

@ -379,7 +379,17 @@ def get_workspace_sidebar_items():
# pages sorted based on sequence id
order_by = "sequence_id asc"
fields = ["name", "title", "for_user", "parent_page", "content", "public", "module", "icon"]
fields = [
"name",
"title",
"for_user",
"parent_page",
"content",
"public",
"module",
"icon",
"is_hidden",
]
all_pages = frappe.get_all(
"Workspace", fields=fields, filters=filters, order_by=order_by, ignore_permissions=True
)
@ -391,7 +401,7 @@ def get_workspace_sidebar_items():
try:
workspace = Workspace(page, True)
if has_access or workspace.is_permitted():
if page.public:
if page.public and (has_access or not page.is_hidden):
pages.append(page)
elif page.for_user == frappe.session.user:
private_pages.append(page)

View file

@ -19,6 +19,7 @@
"restrict_to_domain",
"hide_custom",
"public",
"is_hidden",
"content",
"tab_break_2",
"charts",
@ -174,11 +175,17 @@
"fieldtype": "Table",
"label": "Quick Lists",
"options": "Workspace Quick List"
},
{
"default": "0",
"fieldname": "is_hidden",
"fieldtype": "Check",
"label": "Is Hidden"
}
],
"in_create": 1,
"links": [],
"modified": "2023-01-07 17:02:48.278025",
"modified": "2023-01-07 19:37:39.512482",
"modified_by": "Administrator",
"module": "Desk",
"name": "Workspace",

View file

@ -247,6 +247,32 @@ def update_page(name, title, icon, parent, public):
return {"name": title, "public": public, "label": new_name}
def hide_unhide_page(page_name: str, is_hidden: int):
page = frappe.get_doc("Workspace", page_name)
if page.get("public") and not is_workspace_manager():
frappe.throw(
_("Need Workspace Manager role to hide/unhide public workspaces"), frappe.PermissionError
)
if not page.get("public") and page.get("for_user") != frappe.session.user:
frappe.throw(_("Cannot update private workspace of other users"), frappe.PermissionError)
page.is_hidden = is_hidden
page.save(ignore_permissions=True)
return True
@frappe.whitelist()
def hide_page(page_name: str):
return hide_unhide_page(page_name, 1)
@frappe.whitelist()
def unhide_page(page_name: str):
return hide_unhide_page(page_name, 0)
@frappe.whitelist()
def duplicate_page(page_name, new_page):
if not loads(new_page):

View file

@ -48,6 +48,16 @@
<path d="M9 3L13 5.99999L9 9" stroke="var(--icon-stroke)" stroke-linecap="round" stroke-linejoin="round"/>
</symbol>
<symbol viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" id="icon-unhide">
<path stroke="none" fill-rule="evenodd" clip-rule="evenodd" d="M2.10756 9.53547C1.93501 9.82126 1.93501 10.1787 2.10756 10.4645C3.75635 13.1955 6.60531 15 9.84351 15C13.0817 15 15.9307 13.1955 17.5795 10.4645C17.752 10.1787 17.752 9.82127 17.5795 9.53548C15.9307 6.80451 13.0817 5 9.84351 5C6.60531 5 3.75635 6.8045 2.10756 9.53547ZM10 13C11.6569 13 13 11.6569 13 10C13 8.34315 11.6569 7 10 7C8.34315 7 7 8.34315 7 10C7 11.6569 8.34315 13 10 13Z" fill="var(--icon-stroke)"/>
<circle cx="10" cy="10" r="1" stroke="none" fill="var(--icon-stroke)"/>
</symbol>
<symbol viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg" id="icon-hide">
<rect stroke="none" x="3.02185" y="3.89151" width="1.26078" height="18.4481" rx="0.630391" transform="rotate(-45 3.02185 3.89151)" fill="var(--icon-stroke)"/>
<path stroke="none" fill-rule="evenodd" clip-rule="evenodd" d="M5.02016 6.99831C4.84611 6.82426 4.57032 6.80165 4.37821 6.95554C3.49472 7.66323 2.73193 8.53749 2.12941 9.53547C1.95686 9.82126 1.95686 10.1787 2.12941 10.4645C3.7782 13.1955 6.62716 15 9.86536 15C10.5301 15 11.1784 14.924 11.8032 14.7795C12.1655 14.6957 12.2727 14.2508 12.0098 13.9879L11.1052 13.0833C10.9747 12.9529 10.7837 12.9083 10.6027 12.9438C10.4148 12.9807 10.2206 13 10.0219 13C8.365 13 7.02185 11.6569 7.02185 10C7.02185 9.80128 7.04117 9.60707 7.07804 9.41915C7.11355 9.23815 7.06896 9.04711 6.93853 8.91668L5.02016 6.99831ZM12.1967 12.8433C11.9793 12.6259 12.011 12.2666 12.2202 12.0414C12.7176 11.506 13.0219 10.7885 13.0219 10C13.0219 8.34315 11.6787 7 10.0219 7C9.23334 7 8.51587 7.30421 7.98043 7.80167C7.75522 8.0109 7.3959 8.04255 7.17854 7.82518L5.98518 6.63183C5.75274 6.39939 5.80413 6.00935 6.10001 5.86613C7.24996 5.3095 8.52428 5 9.86536 5C13.1036 5 15.9525 6.80451 17.6013 9.53548C17.7739 9.82127 17.7739 10.1787 17.6013 10.4645C16.6787 11.9927 15.3803 13.2307 13.8482 14.0249C13.6613 14.1218 13.4343 14.0809 13.2854 13.932L12.1967 12.8433Z" fill="var(--icon-stroke)"/>
</symbol>
<symbol viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" id="icon-sidebar-collapse">
<path d="M12 6L6 12L12 18" stroke="var(--icon-stroke)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M18 6L12 12L18 18" stroke="var(--icon-stroke)" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 111 KiB

View file

@ -78,9 +78,13 @@ frappe.views.Workspace = class Workspace {
sidebar_item_container(item) {
return $(`
<div class="sidebar-item-container ${item.is_editable ? "is-draggable" : ""}" item-parent="${
item.parent_page
}" item-name="${item.title}" item-public="${item.public || 0}">
<div
class="sidebar-item-container ${item.is_editable ? "is-draggable" : ""}"
item-parent="${item.parent_page}"
item-name="${item.title}"
item-public="${item.public || 0}"
item-is-hidden="${item.is_hidden || 0}"
>
<div class="desk-sidebar-item standard-sidebar-item ${item.selected ? "selected" : ""}">
<a
href="/app/${
@ -393,6 +397,7 @@ frappe.views.Workspace = class Workspace {
this.page.set_secondary_action(__("Edit"), async () => {
if (!this.editor || !this.editor.readOnly) return;
this.is_read_only = false;
this.toggle_hidden_workspaces(true);
await this.editor.readOnly.toggle();
this.editor.isReady.then(() => {
this.initialize_editorjs_undo();
@ -441,6 +446,7 @@ frappe.views.Workspace = class Workspace {
this.page.set_secondary_action(__("Discard"), async () => {
this.discard = true;
this.clear_page_actions();
this.toggle_hidden_workspaces(false);
await this.editor.readOnly.toggle();
this.is_read_only = true;
this.sidebar_pages = this.cached_pages;
@ -455,6 +461,10 @@ frappe.views.Workspace = class Workspace {
}
}
toggle_hidden_workspaces(show) {
$(".desk-sidebar").toggleClass("show-hidden-workspaces", show);
}
show_sidebar_actions() {
this.sidebar.find(".standard-sidebar-section").addClass("show-control");
this.make_sidebar_sortable();
@ -481,6 +491,15 @@ frappe.views.Workspace = class Workspace {
null,
sidebar_control
);
} else if (item.is_hidden) {
frappe.utils.add_custom_button(
frappe.utils.icon("unhide", "sm"),
(e) => this.unhide_workspace(item, e),
"unhide-workspace-btn",
__("Unhide Workspace"),
null,
sidebar_control
);
} else {
frappe.utils.add_custom_button(
frappe.utils.icon("drag", "xs"),
@ -720,6 +739,12 @@ frappe.views.Workspace = class Workspace {
icon: frappe.utils.icon("duplicate", "sm"),
action: () => this.duplicate_page(item),
},
{
label: __("Hide"),
title: __("Hide Workspace"),
icon: frappe.utils.icon("hide", "sm"),
action: (e) => this.hide_workspace(item, e),
},
];
if (this.is_item_deletable(item)) {
@ -748,7 +773,7 @@ frappe.views.Workspace = class Workspace {
html.click((event) => {
event.stopPropagation();
action && action();
action && action(event);
});
return html;
@ -910,6 +935,45 @@ frappe.views.Workspace = class Workspace {
d.show();
}
hide_unhide_workspace(page, event, hide) {
page.is_hidden = hide;
let sidebar_control = event.target.closest(".sidebar-item-control");
let sidebar_item_container = sidebar_control.closest(".sidebar-item-container");
$(sidebar_item_container).attr("item-is-hidden", hide);
$(sidebar_control).empty();
this.add_sidebar_actions(page, $(sidebar_control));
let cached_page = this.cached_pages.pages.findIndex((p) => p.name === page.name);
if (cached_page !== -1) {
this.cached_pages.pages[cached_page].is_hidden = hide;
}
let method = hide ? "hide_page" : "unhide_page";
frappe.call({
method: "frappe.desk.doctype.workspace.workspace." + method,
args: {
page_name: page.name,
},
callback: (r) => {
if (!r.message) return;
let message = hide ? "{0} is hidden successfully" : "{0} is unhidden successfully";
message = __(message, [page.title.bold()]);
frappe.show_alert({ message: message, indicator: "green" });
},
});
}
hide_workspace(page, event) {
this.hide_unhide_workspace(page, event, 1);
}
unhide_workspace(page, event) {
this.hide_unhide_workspace(page, event, 0);
}
make_sidebar_sortable() {
let me = this;
$(".nested-container").each(function () {

View file

@ -1017,6 +1017,16 @@ body {
.sidebar-item-container {
position: relative;
&[item-is-hidden="1"] {
display: none;
opacity: 0.4;
&:hover {
opacity: 1;
}
}
.sidebar-item-container{
margin-left: 10px;
@ -1026,31 +1036,57 @@ body {
}
}
.standard-sidebar-section.show-control {
.desk-sidebar-item.standard-sidebar-item {
.desk-sidebar {
&.show-hidden-workspaces {
&:hover, &.selected {
.drag-handle {
display: inline-block;
}
.setting-btn, .duplicate-page {
display: inline-block;
margin-right: 8px;
}
.drop-icon {
padding: 10px 8px 10px 2px;
margin-left: -8px;
}
.unhide-page-btn {
display: none;
}
.block-click {
pointer-events:none;
.standard-sidebar-section {
display: block;
.sidebar-item-container[item-is-hidden="1"] {
display: block;
}
}
}
.standard-sidebar-section {
display: none;
&:has(> [item-is-hidden="0"]) {
display: block;
}
}
.standard-sidebar-section.show-control {
.desk-sidebar-item.standard-sidebar-item {
&:hover, &.selected {
.drag-handle {
display: inline-block;
}
.setting-btn, .duplicate-page, .unhide-workspace-btn {
display: inline-block;
margin-right: 8px;
}
.drop-icon {
padding: 10px 8px 10px 2px;
margin-left: -8px;
}
}
.block-click {
pointer-events:none;
}
}
}
}
.codex-editor__loader {
display: none !important;
}