diff --git a/wiki/public/js/render_wiki.js b/wiki/public/js/render_wiki.js index 01f8b1c7..fcd6cfeb 100644 --- a/wiki/public/js/render_wiki.js +++ b/wiki/public/js/render_wiki.js @@ -109,6 +109,7 @@ window.RenderWiki = class RenderWiki extends Wiki { this.set_revisions(); this.add_click_to_copy(); this.setup_feedback(); + this.setup_page_settings(); } }); } @@ -719,4 +720,38 @@ window.RenderWiki = class RenderWiki extends Wiki { }); }); } + + setup_page_settings() { + $(".update-page-settings-button").on("click", function () { + const name = $('[name="wiki-page-name"]').val(); + const hideOnSidebar = $('input[name="pageHideOnSidebar"]').prop( + "checked", + ); + const route = + $(".wiki-space-route-block").text().trim() + + $('input[name="pageRoute"]').val(); + + frappe + .call({ + method: "wiki.wiki.doctype.wiki_page.wiki_page.update_page_settings", + args: { + name, + settings: { + hide_on_sidebar: !!hideOnSidebar, + route, + }, + }, + }) + .then(() => { + frappe.show_alert({ + message: __("Page settings updated successfully"), + indicator: "green", + }); + + setTimeout(() => { + window.location.href = "/" + route; + }, 1000); + }); + }); + } }; diff --git a/wiki/public/scss/wiki.scss b/wiki/public/scss/wiki.scss index b84be465..92828f54 100644 --- a/wiki/public/scss/wiki.scss +++ b/wiki/public/scss/wiki.scss @@ -1233,6 +1233,25 @@ p { padding: 0.25rem 0.5rem; font-size: 13px; line-height: 1.25rem; + + &[type="checkbox"] { + color: #000; + padding: 0%; + border: 1px solid var(--gray-500); + border-radius: 4px; + accent-color: black; + + &:checked { + background-color: var(--primary); + background-image: url("data:image/svg+xml, "), + var(--checkbox-gradient); + background-size: 57%, 100%; + box-shadow: none; + border: none; + background-repeat: no-repeat; + background-position: center; + } + } } input, @@ -1334,3 +1353,11 @@ ins { letter-spacing: 0.02em; font-weight: 400; } + +.wiki-space-route-block { + padding: 0.4rem 0.5rem; + border-radius: 0.375rem; + background-color: var(--gray-300); + border-top-right-radius: 0; + border-bottom-right-radius: 0; +} \ No newline at end of file diff --git a/wiki/wiki/doctype/wiki_group_item/wiki_group_item.json b/wiki/wiki/doctype/wiki_group_item/wiki_group_item.json index 8b60dbc2..b0ec8262 100644 --- a/wiki/wiki/doctype/wiki_group_item/wiki_group_item.json +++ b/wiki/wiki/doctype/wiki_group_item/wiki_group_item.json @@ -8,7 +8,8 @@ "engine": "InnoDB", "field_order": [ "parent_label", - "wiki_page" + "wiki_page", + "hide_on_sidebar" ], "fields": [ { @@ -25,12 +26,18 @@ "label": "Wiki Page", "options": "Wiki Page", "reqd": 1 + }, + { + "default": "0", + "fieldname": "hide_on_sidebar", + "fieldtype": "Check", + "label": "Hide on sidebar" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-04-04 18:17:37.507102", + "modified": "2024-04-16 12:06:18.398870", "modified_by": "Administrator", "module": "Wiki", "name": "Wiki Group Item", diff --git a/wiki/wiki/doctype/wiki_page/templates/page_settings.html b/wiki/wiki/doctype/wiki_page/templates/page_settings.html new file mode 100644 index 00000000..129c7d39 --- /dev/null +++ b/wiki/wiki/doctype/wiki_page/templates/page_settings.html @@ -0,0 +1,43 @@ + \ No newline at end of file diff --git a/wiki/wiki/doctype/wiki_page/templates/show.html b/wiki/wiki/doctype/wiki_page/templates/show.html index f86f7c83..97c7a835 100644 --- a/wiki/wiki/doctype/wiki_page/templates/show.html +++ b/wiki/wiki/doctype/wiki_page/templates/show.html @@ -15,8 +15,13 @@

{{ title }}

@@ -25,6 +30,7 @@

{{ title }}

{% include "wiki/doctype/wiki_page/templates/revisions.html" %} + {% include "wiki/doctype/wiki_page/templates/page_settings.html" %}
{% include "wiki/doctype/wiki_page/templates/editor.html" %} @@ -116,5 +122,5 @@ {%- if script -%} - + {%- endif -%} \ No newline at end of file diff --git a/wiki/wiki/doctype/wiki_page/wiki_page.py b/wiki/wiki/doctype/wiki_page/wiki_page.py index 0b0fa95d..3fcebfba 100644 --- a/wiki/wiki/doctype/wiki_page/wiki_page.py +++ b/wiki/wiki/doctype/wiki_page/wiki_page.py @@ -245,6 +245,10 @@ def get_context(self, context): context.number_of_revisions = frappe.db.count( "Wiki Page Revision Item", {"wiki_page": self.name} ) + # TODO: group all context values + context.hide_on_sidebar = frappe.get_value( + "Wiki Group Item", {"wiki_page": self.name}, "hide_on_sidebar" + ) html = frappe.utils.md_to_html(self.content) context.content = html context.page_toc_html = ( @@ -313,6 +317,9 @@ def get_sidebar_items(self): sidebar = {} for sidebar_item in wiki_sidebar: + if sidebar_item.hide_on_sidebar: + continue + wiki_page = frappe.get_doc("Wiki Page", sidebar_item.wiki_page) if sidebar_item.parent_label not in sidebar: sidebar[sidebar_item.parent_label] = [ @@ -578,3 +585,17 @@ def delete_wiki_page(wiki_page_route): @frappe.whitelist(allow_guest=True) def has_edit_permission(): return frappe.has_permission(doctype="Wiki Page", ptype="write", throw=False) + + +@frappe.whitelist() +def update_page_settings(name, settings): + from frappe.utils import sbool + + frappe.has_permission(doctype="Wiki Page", ptype="write", doc=name, throw=True) + settings = frappe.parse_json(settings) + + frappe.db.set_value( + "Wiki Group Item", {"wiki_page": name}, "hide_on_sidebar", sbool(settings.hide_on_sidebar) + ) + + frappe.db.set_value("Wiki Page", name, "route", settings.route)