Skip to content

Commit

Permalink
feat(wiki-space): space specific logo and navbar settings (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
BreadGenie authored Apr 5, 2024
1 parent 3899e78 commit 4a52a28
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
10 changes: 7 additions & 3 deletions wiki/wiki/doctype/wiki_page/wiki_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,15 @@ def calculate_toc_html(self, html):
def get_context(self, context):
self.verify_permission("read")
self.set_breadcrumbs(context)

wiki_settings = frappe.get_single("Wiki Settings")
wiki_space_name = frappe.get_value("Wiki Group Item", {"wiki_page": self.name}, "parent")
wiki_space = frappe.get_doc("Wiki Space", wiki_space_name)

context.navbar_search = wiki_settings.add_search_bar
context.add_dark_mode = wiki_settings.add_dark_mode
context.light_mode_logo = wiki_settings.logo
context.dark_mode_logo = wiki_settings.dark_mode_logo
context.light_mode_logo = wiki_space.wiki_space_logo or wiki_settings.logo
context.dark_mode_logo = wiki_space.wiki_space_logo or wiki_settings.dark_mode_logo
context.script = wiki_settings.javascript
context.show_feedback = wiki_settings.enable_feedback
context.ask_for_contact_details = wiki_settings.ask_for_contact_details
Expand Down Expand Up @@ -265,7 +269,7 @@ def get_context(self, context):
)
context = context.update(
{
"navbar_items": modify_header_footer_items(wiki_settings.navbar),
"navbar_items": modify_header_footer_items(wiki_space.navbar_items or wiki_settings.navbar),
"post_login": [
{"label": _("My Account"), "url": "/me"},
{"label": _("Logout"), "url": "/?cmd=web_logout"},
Expand Down
46 changes: 46 additions & 0 deletions wiki/wiki/doctype/wiki_space/wiki_space.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,50 @@ frappe.ui.form.on("Wiki Space", {
});
});
},

onload_post_render: function (frm) {
frm.trigger("set_parent_label_options");
},

set_parent_label_options: function (frm) {
frm.fields_dict.navbar_items.grid.update_docfield_property(
"parent_label",
"options",
frm.events.get_parent_options(frm, "navbar_items"),
);
},

get_parent_options: function (frm, table_field) {
var items = frm.doc[table_field] || [];
var main_items = [""];
for (var i in items) {
var d = items[i];
if (!d.url && d.label) {
main_items.push(d.label);
}
}
return main_items.join("\n");
},
});

frappe.ui.form.on("Top Bar Item", {
navbar_delete(frm) {
frm.events.set_parent_label_options(frm);
},

navbar_add(frm, cdt, cdn) {
frm.events.set_parent_label_options(frm);
},

parent_label: function (frm, doctype, name) {
frm.events.set_parent_label_options(frm);
},

url: function (frm, doctype, name) {
frm.events.set_parent_label_options(frm);
},

label: function (frm, doctype, name) {
frm.events.set_parent_label_options(frm);
},
});
29 changes: 27 additions & 2 deletions wiki/wiki/doctype/wiki_space/wiki_space.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"general_tab",
"route",
"wiki_sidebars"
"wiki_sidebars",
"navbar_tab",
"wiki_space_logo",
"navbar_items"
],
"fields": [
{
Expand All @@ -25,11 +29,32 @@
"fieldtype": "Table",
"label": "Wiki Sidebars",
"options": "Wiki Group Item"
},
{
"fieldname": "general_tab",
"fieldtype": "Tab Break",
"label": "General"
},
{
"fieldname": "navbar_tab",
"fieldtype": "Tab Break",
"label": "Navbar"
},
{
"fieldname": "wiki_space_logo",
"fieldtype": "Attach Image",
"label": "Wiki Space Logo"
},
{
"fieldname": "navbar_items",
"fieldtype": "Table",
"label": "Navbar Items",
"options": "Top Bar Item"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-04-11 17:49:56.612594",
"modified": "2024-04-05 13:36:07.517135",
"modified_by": "Administrator",
"module": "Wiki",
"name": "Wiki Space",
Expand Down

0 comments on commit 4a52a28

Please sign in to comment.