Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frappe Search Integration #215

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions wiki/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
page_renderer = "wiki.wiki.doctype.wiki_page.wiki_renderer.WikiPageRenderer"

website_route_rules = [
{"from_route": "/<path:wiki_page>/edit-wiki", "to_route": "/edit"},
{"from_route": "/<path:wiki_page>/new-wiki", "to_route": "/new"},
{"from_route": "/<path:wiki_page>/revisions", "to_route": "/revisions"},
{"from_route": "/<path:wiki_page>/edit-wiki", "to_route": "/edit"},
{"from_route": "/<path:wiki_page>/new-wiki", "to_route": "/new"},
{"from_route": "/<path:wiki_page>/revisions", "to_route": "/revisions"},
]

# Includes in <head>
Expand Down Expand Up @@ -109,7 +109,7 @@
# ---------------

scheduler_events = {
"cron": {"*/15 * * * *": ["wiki.wiki.doctype.wiki_page.search.rebuild_index_in_background"]}
"cron": {"*/15 * * * *": ["wiki.wiki.doctype.wiki_page.search.rebuild_index_in_background"]}
}

# scheduler_events = {
Expand Down Expand Up @@ -159,3 +159,19 @@
# exempt linked doctypes from being automatically cancelled
#
# auto_cancel_exempted_doctypes = ["Auto Repeat"]

frappe_search_doctypes = {
"Wiki Page": {
"title": "title",
"content": ["content"],
"extras": ["route"],
},
}

frappe_search_doctypes = {
"Wiki Page": {
"title": "title",
"content": ["content"],
"fields": ["route"],
},
}
62 changes: 31 additions & 31 deletions wiki/public/js/render_wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,26 +126,26 @@ window.RenderWiki = class RenderWiki extends Wiki {
if (
!$(
`.doc-sidebar .sidebar-group[data-title="${urlParams.get(
"newWiki",
)}"] .add-sidebar-page`,
"newWiki"
)}"] .add-sidebar-page`
).length
) {
this.add_wiki_sidebar(urlParams.get("newWiki"));

$(
$(
`.sidebar-items > .list-unstyled .h6:contains(${urlParams.get(
"newWiki",
)}) + .add-sidebar-page`,
)[0],
"newWiki"
)}) + .add-sidebar-page`
)[0]
).trigger("click");
} else
$(
$(
`.sidebar-items > .list-unstyled .h6:contains(${urlParams.get(
"newWiki",
)}) + .add-sidebar-page`,
)[1],
"newWiki"
)}) + .add-sidebar-page`
)[1]
).trigger("click");
}
$(".wiki-footer, .wiki-page-meta").toggleClass("hide");
Expand All @@ -168,7 +168,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
{
scrollTop: offset,
},
500,
500
);
});
});
Expand Down Expand Up @@ -257,7 +257,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".edit-wiki-btn, .sidebar-edit-mode-btn").on("click", function () {
if (frappe.session.user === "Guest")
window.location.assign(
`/login?redirect-to=${window.location.pathname}`,
`/login?redirect-to=${window.location.pathname}`
);
else {
const urlParams = new URLSearchParams(window.location.search);
Expand All @@ -283,7 +283,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
const groupName = $(".sidebar-item.active").data("group-name");
$(".edit-wiki-btn").trigger("click");
$(
`.doc-sidebar .add-sidebar-page[data-group-name="${groupName}"]`,
`.doc-sidebar .add-sidebar-page[data-group-name="${groupName}"]`
).trigger("click");
});

Expand All @@ -308,7 +308,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
if (newWikiPage.data("group-name") !== groupName) {
// when new item is created in a different group as earlier
newSidebarItem.appendTo(
$(this).parent().parent().children(".list-unstyled"),
$(this).parent().parent().children(".list-unstyled")
);
if (urlParams.get("newWiki") !== groupName)
set_search_params("newWiki", groupName);
Expand All @@ -325,11 +325,11 @@ window.RenderWiki = class RenderWiki extends Wiki {
} else {
// fresh new item
active_items = $(
".sidebar-item.active, .sidebar-item.active .active",
".sidebar-item.active, .sidebar-item.active .active"
).removeClass("active");

newSidebarItem.appendTo(
$(this).parent().parent().children(".list-unstyled"),
$(this).parent().parent().children(".list-unstyled")
);
if (!$(".wiki-editor").is(":visible")) toggleEditor();
if (urlParams.get("newWiki") !== groupName)
Expand All @@ -338,7 +338,7 @@ window.RenderWiki = class RenderWiki extends Wiki {

$(this).parent().parent().each(setSortable);
e.stopPropagation();
},
}
);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
title: __("Delete Wiki Page"),
indicator: "red",
message: __(
`Are you sure you want to <b>delete</b> the Wiki Page <b>${title}</b>?`,
`Are you sure you want to <b>delete</b> the Wiki Page <b>${title}</b>?`
),
primary_action: {
label: "Yes",
Expand All @@ -393,7 +393,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
},
},
});
},
}
);
}

Expand All @@ -408,7 +408,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".revision-content").html(),
$(".from-markdown .wiki-content")
.html()
.replaceAll(/<br class="ProseMirror-trailingBreak">/g, ""),
.replaceAll(/<br class="ProseMirror-trailingBreak">/g, "")
);
$(".previous-revision").removeClass("hide");
} else {
Expand Down Expand Up @@ -450,11 +450,11 @@ window.RenderWiki = class RenderWiki extends Wiki {
if (previousRevision.content)
$(".revision-content")[0].innerHTML = HtmlDiff.execute(
previousRevision.content,
currentRevision.content,
currentRevision.content
);
else $(".revision-content")[0].innerHTML = currentRevision.content;
$(
".revision-time",
".revision-time"
)[0].innerHTML = `${currentRevision.author} edited ${currentRevision.revision_time}`;
currentRevisionIndex++;
addHljsClass();
Expand All @@ -472,10 +472,10 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".previous-revision").removeClass("hide");
$(".revision-content")[0].innerHTML = HtmlDiff.execute(
nextRevision.content,
currentRevision.content,
currentRevision.content
);
$(
".revision-time",
".revision-time"
)[0].innerHTML = `${currentRevision.author} edited ${currentRevision.revision_time}`;
currentRevisionIndex--;
addHljsClass();
Expand Down Expand Up @@ -505,7 +505,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(".doc-sidebar .sidebar-items")
.children(".list-unstyled")
.not(".hidden")
.first(),
.first()
);

$(".web-sidebar ul").each(setSortable);
Expand Down Expand Up @@ -537,7 +537,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$(this)
.parent()
.append(
$(`<ul class="list-unstyled" style="min-height:20px;"> </ul`),
$(`<ul class="list-unstyled" style="min-height:20px;"> </ul`)
);
}
});
Expand Down Expand Up @@ -568,7 +568,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
// fixes html tags when they are sliced
return new DOMParser().parseFromString(
content.slice(start, end),
"text/html",
"text/html"
).body.innerHTML;
}

Expand Down Expand Up @@ -599,27 +599,27 @@ window.RenderWiki = class RenderWiki extends Wiki {

frappe
.call({
method: "wiki.wiki.doctype.wiki_page.search.search",
method: "frappe_search.api.search",
args: {
query: searchInput.val(),
path: window.location.pathname,
space: search_scope,
},
})
.then((res) => {
let results = res.message.docs || [];
let results = res.message.results || [];
let dropdown_html;
if (results.length === 0) {
dropdown_html = `<div style="margin: 1.5rem 9rem;">No results found</div>`;
} else {
dropdown_html = results
.map((r) => {
return `<a class="dropdown-item" href="/${r.route}">
<h6>${r.title}</h6>
return `<a class="dropdown-item" href="/${r.fields.route}">
<h6>${r.highlighted_title || r.title}</h6>
<div>${
res.message.search_engine === "frappe_web_search"
? r.content
: trimContent(r.content)
: trimContent(r.highlighted_content || r.content)
}</div>
</a>
<div class='dropdown-border'></div>`;
Expand All @@ -630,7 +630,7 @@ window.RenderWiki = class RenderWiki extends Wiki {
$dropdown_menu.addClass("show");
dropdownItems = $dropdown_menu.find(".dropdown-item");
});
}, 500),
}, 500)
);

$("#dropdownMenuSearch, .mobile-search-icon").on("click", () => {
Expand Down
Loading