Skip to content

Commit

Permalink
feat(wiki-page): page settings (#228)
Browse files Browse the repository at this point in the history
* feat(wiki-page): page settings

* chore: add template

* fix: perm check and reload once settings changed

* feat: update route from page settings
  • Loading branch information
BreadGenie authored Apr 16, 2024
1 parent fc1fc53 commit 3f12cdd
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 5 deletions.
35 changes: 35 additions & 0 deletions wiki/public/js/render_wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
}
Expand Down Expand Up @@ -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);
});
});
}
};
27 changes: 27 additions & 0 deletions wiki/public/scss/wiki.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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, <svg viewBox='0 0 8 7' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M1 4.00001L2.66667 5.80001L7 1.20001' stroke='white' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/></svg>"),
var(--checkbox-gradient);
background-size: 57%, 100%;
box-shadow: none;
border: none;
background-repeat: no-repeat;
background-position: center;
}
}
}

input,
Expand Down Expand Up @@ -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;
}
11 changes: 9 additions & 2 deletions wiki/wiki/doctype/wiki_group_item/wiki_group_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"engine": "InnoDB",
"field_order": [
"parent_label",
"wiki_page"
"wiki_page",
"hide_on_sidebar"
],
"fields": [
{
Expand All @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions wiki/wiki/doctype/wiki_page/templates/page_settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<div class="modal page-settings-modal fade" id="pageSettingsModal" tabindex="-1" role="dialog"
aria-labelledby="pageSettingsModalTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title page-settings-title">Page Settings</h5>
<button type="button" class="d-block d-sm-none close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form class="page-settings-form">
<div class="form-group">
<div>
<label class="text-muted text-xs" for="pageRoute">Route</label>
<div class="flex align-items-center">
<div class="text-sm wiki-space-route-block"
title="Wiki Space route (can't be modified)">
{{ route.split('/')[0] }}/
</div>
<input type="text" id="pageRoute" name="pageRoute" class="form-control"
style="border-top-left-radius: 0; border-bottom-left-radius: 0;" value="{{ "
/".join(route.split('/')[1:]) }}">
</div>
</div>
<div class="mt-4 flex align-content-center">
<input type="checkbox" id="pageHideOnSidebar" {{ 'checked' if bool(hide_on_sidebar) else ''
}} name="pageHideOnSidebar">
<label class="text-muted text-xs" for="pageHideOnSidebar" class="mt-2">
Hide on Sidebar
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" data-modal-button="update"
class="btn btn-primary btn-sm update-page-settings-button">
Update
</button>
</div>
</div>
</div>
</div>
12 changes: 9 additions & 3 deletions wiki/wiki/doctype/wiki_page/templates/show.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ <h1 class="wiki-title">{{ title }}</h1>
<div class="dropdown-menu d-print-none" aria-labelledby="wikiOptionsButton">
<a class="dropdown-item edit-wiki-btn" href="#">Edit Page</a>
<a class="dropdown-item add-wiki-btn" href="#">New Page</a>
<a class="dropdown-item show-revisions" href="#" data-toggle="modal"
data-target="#revisionsModal">Revisions</a>
<a class="dropdown-item show-revisions" href="#" data-toggle="modal" data-target="#revisionsModal">
Revisions
</a>
<a class="dropdown-item show-page-settings" href="#" data-toggle="modal"
data-target="#pageSettingsModal">
Page Settings
</a>
</div>
</div>
</div>
Expand All @@ -25,6 +30,7 @@ <h1 class="wiki-title">{{ title }}</h1>
</div>
<input value={{ name }} class="d-none" name="wiki-page-name"></input>
{% include "wiki/doctype/wiki_page/templates/revisions.html" %}
{% include "wiki/doctype/wiki_page/templates/page_settings.html" %}
</div>
<div class="wiki-editor {% if not edit_wiki_page and not new_wiki_page %}hide{% endif %}">
{% include "wiki/doctype/wiki_page/templates/editor.html" %}
Expand Down Expand Up @@ -116,5 +122,5 @@ <h5 class="modal-title" id="addGroupModalTitle">Title</h5>
</script>

{%- if script -%}
<script>{{ script }}</script>
<script>{ { script } }</script>
{%- endif -%}
21 changes: 21 additions & 0 deletions wiki/wiki/doctype/wiki_page/wiki_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -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] = [
Expand Down Expand Up @@ -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)

0 comments on commit 3f12cdd

Please sign in to comment.