Skip to content

Commit

Permalink
Merge pull request #38 from ONE-F-M/186240224
Browse files Browse the repository at this point in the history
Fix wiki page patch approval error due to duplicate route
  • Loading branch information
Talleyrand333 authored Oct 12, 2023
2 parents 458839e + dee2dbe commit d0d5d8b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
14 changes: 9 additions & 5 deletions one_wiki/overrides/overrides.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import frappe
import frappe,random
import re
import os
from frappe.website.utils import is_binary_file
Expand Down Expand Up @@ -103,13 +103,17 @@ def update_old_page_(self):

def create_new_wiki_page_(self):
self.new_wiki_page = frappe.new_doc("Wiki Page")

#Check for existing routes and update the route value with _ with one
route ="/".join(self.wiki_page_doc.route.split("/")[:-1] + [cleanup_page_name(self.new_title)])
existing_routes = frappe.get_all("Wiki Page",{'route':route})
if existing_routes:
str_index = random.choice(range(len(route)-1))
route = route.replace(route[str_index],"_")

wiki_page_dict = {
"title": self.new_title,
"content": self.new_code,
"route": "/".join(
self.wiki_page_doc.route.split("/")[:-1] + [cleanup_page_name(self.new_title)]
),
"route": route,
"published": 1,
"language":'عربي' if frappe.cache().get_value(f'wiki_language_{frappe.session.user}') =='ar' else 'English',
"allow_guest": self.wiki_page_doc.allow_guest,
Expand Down
19 changes: 15 additions & 4 deletions one_wiki/public/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,22 @@ const getContent = () => {
};

const saveWikiPage = (draft = false) => {
console.log("INSIDE FUNC")


const urlParams = new URLSearchParams(window.location.search);
const isEmptyEditor = !!urlParams.get("newWiki");

const title = $(`.wiki-editor .ProseMirror h1`).html();
if (!title){
if(window.wiki_language == "English"){
$(`.wiki-editor .ProseMirror h1`).focus();
frappe.throw("Please set a Title")
}
else{
$(`.wiki-editor .ProseMirror h1`).focus();
frappe.throw("يرجى تحديد عنوان لهذه الوثيقة")
}
}
// markdown=1 tag is needed for older wiki content to properly render
// TODO: use editor.getHTML() instead of this when ueberdosis/tiptap#4044 is fixed
const content = `<div markdown="1">${$(".editor-space .ProseMirror")
Expand Down Expand Up @@ -388,12 +399,12 @@ buttons.deleteTable.addEventListener("click", () => {
buttons.saveWikiPage.addEventListener("click", () => {

if(window.is_wiki_manager){
console.log("CALLED HERE11111")

saveWikiPage(draft = true);
}
else{
console.log("CALLED HERE222222")
console.log(window.is_wiki_manager)


saveWikiPage();
}

Expand Down
21 changes: 14 additions & 7 deletions one_wiki/templates/wiki_page/templates/wiki_doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ <h5>On this page</h5>

<script>
frappe.ready(() => {

set_wiki_language('{{name}}')

frappe.setup_search('#search-container', '{{ docs_search_scope or "" }}');

$('.web-footer .container')
Expand Down Expand Up @@ -101,15 +101,16 @@ <h5>On this page</h5>

//$('[data-tiptap-button="draftWikiPage"]').hide()
//$('[data-tiptap-button="saveWikiPage"]').hide()
window.is_wiki_manager = '{{is_wiki_manager}}'
$('.btn.btn-primary.save-wiki-page-btn.btn-sm').html("Save Draft")

window.wiki_language == "English" ? $('.btn.btn-primary.save-wiki-page-btn.btn-sm').html("Save Draft") : $('.btn.btn-primary.save-wiki-page-btn.btn-sm').html("حفظ المسودة")

$('.btn.btn-primary.save-wiki-page-btn.btn-sm').off('click', 'saveWikiPage');
$('.btn.btn-primary.save-wiki-page-btn.btn-sm').attr('data-tiptap-button', 'draftWikiPage')
$('.btn.btn-primary.btn-sm.dropdown-toggle.dropdown-toggle-split').hide()
}
if(('{{is_wiki_manager}}'=='1')&& '{{can_approve}}' != "True"){
$('.btn.btn-primary.save-wiki-page-btn.btn-sm').html("Submit")

window.wiki_language == "English" ? $('.btn.btn-primary.save-wiki-page-btn.btn-sm').html("Submit") : $('.btn.btn-primary.save-wiki-page-btn.btn-sm').html("إرسال")
$('.btn.btn-primary.save-wiki-page-btn.btn-sm').attr('data-tiptap-button', 'draftWikiPage');
$('.btn.btn-primary.save-wiki-page-btn.btn-sm').off('click', 'saveWikiPage');
$('[data-tiptap-button="saveWikiPage"]').hide()
Expand Down Expand Up @@ -177,9 +178,7 @@ <h5>On this page</h5>

}
const saveWikiPage = (draft = false,rejected = false) => {
console.log("CLICKED OOO")
console.log(draft)
console.log(rejected)

const urlParams = new URLSearchParams(window.location.search);
const isEmptyEditor = !!urlParams.get("newWiki");

Expand Down Expand Up @@ -267,6 +266,7 @@ <h5>On this page</h5>
window.existing_page_patch_url = r.message.url
window.existing_page_patch_approver = r.message.owner
window.existing_page_patch_title = r.message.title
window.wiki_language = r.message.language
set_edit_control()
}
});
Expand All @@ -290,6 +290,8 @@ <h5>On this page</h5>
$(this).html(dict[$(this).html().trim()])

})


}
function switch_to_ar(val){
if(val){
Expand All @@ -308,6 +310,11 @@ <h5>On this page</h5>
$('.dropdown-item.show-revisions').html('التنقيحات')
$('.dropdown-item.show-revisions').css('text-align','right')
$('[data-tiptap-button="draftWikiPage"]').html('مسودة')


$('.btn.btn-primary.save-wiki-page-btn.btn-sm').html("يُقدِّم")


$('#lang_icon').html('عربي')
change_navbar_lang('ar')

Expand Down

0 comments on commit d0d5d8b

Please sign in to comment.