Merge pull request #452 from pateljannat/search
This commit is contained in:
@@ -167,7 +167,6 @@ def reindex_exercises(doc):
|
|||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def search_course(text):
|
def search_course(text):
|
||||||
search_courses = []
|
|
||||||
courses = frappe.get_all(
|
courses = frappe.get_all(
|
||||||
"LMS Course",
|
"LMS Course",
|
||||||
filters={"published": True},
|
filters={"published": True},
|
||||||
@@ -177,17 +176,8 @@ def search_course(text):
|
|||||||
"short_introduction": ["like", f"%{text}%"],
|
"short_introduction": ["like", f"%{text}%"],
|
||||||
"description": ["like", f"%{text}%"],
|
"description": ["like", f"%{text}%"],
|
||||||
},
|
},
|
||||||
|
fields=["name", "title"],
|
||||||
)
|
)
|
||||||
|
|
||||||
""" for course in courses:
|
|
||||||
search_courses.append(frappe.get_doc("LMS Course", course)) """
|
|
||||||
|
|
||||||
""" template = frappe.render_template("lms/templates/course_list.html", {
|
|
||||||
"title": _("Search Results"),
|
|
||||||
"courses": search_courses,
|
|
||||||
"widgets": Widgets()
|
|
||||||
}) """
|
|
||||||
|
|
||||||
return courses
|
return courses
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -929,17 +929,29 @@ pre {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.search {
|
.search {
|
||||||
background-image: url(/assets/frappe/icons/timeless/search.svg);
|
background-image: url(/assets/frappe/icons/timeless/search.svg);
|
||||||
border: none;
|
border: none;
|
||||||
border-radius: var(--border-radius-md);
|
border-radius: var(--border-radius-md);
|
||||||
font-size: var(--text-sm);
|
font-size: var(--text-sm);
|
||||||
padding: 0.625rem 0.75rem;
|
padding: 0.625rem 0.75rem;
|
||||||
height: 36px;
|
height: 36px;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
text-indent: 1.5rem;
|
text-indent: 1.5rem;
|
||||||
background-position: 1rem 0.7rem;
|
background-position: 1rem 0.7rem;
|
||||||
width: 30%;
|
width: 30%;
|
||||||
box-shadow: var(--shadow-sm);
|
box-shadow: var(--shadow-sm);
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-course {
|
||||||
|
background-position: 1rem;
|
||||||
|
text-indent: 1rem;
|
||||||
|
font-size: var(--text-base);
|
||||||
|
padding: 1.5rem;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search:focus {
|
||||||
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.course-search-header {
|
.course-search-header {
|
||||||
@@ -1918,3 +1930,28 @@ select {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-right: 1rem;
|
margin-right: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.result-row {
|
||||||
|
display: block;
|
||||||
|
padding: 1rem;
|
||||||
|
border-top: 1px solid var(--gray-300);
|
||||||
|
font-weight: 500;
|
||||||
|
color: var(--gray-900);
|
||||||
|
font-size: var(--text-base);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-row:hover {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-modal .modal-dialog {
|
||||||
|
max-width: 70%;
|
||||||
|
margin: 15% auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-modal .modal-body {
|
||||||
|
padding: 0 !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
{% set search_placeholder = frappe.db.get_single_value("LMS Settings", "search_placeholder") %}
|
{% set search_placeholder = frappe.db.get_single_value("LMS Settings", "search_placeholder") %}
|
||||||
{% set portal_course_creation = frappe.db.get_single_value("LMS Settings", "portal_course_creation") %}
|
{% set portal_course_creation = frappe.db.get_single_value("LMS Settings", "portal_course_creation") %}
|
||||||
|
|
||||||
<input class="search" id="search-course" placeholder="{{ _(search_placeholder) or 'Search' }}">
|
|
||||||
<div class="empty-state alert alert-dismissible search-empty-state hide">
|
<div class="modal fade search-modal" id="search-modal" tabindex="-1" role="dialog">
|
||||||
<a href="#" class="close-search-empty-state" aria-label="close">×</a>
|
<div class="modal-dialog" role="document">
|
||||||
<div>
|
<div class="modal-content">
|
||||||
<img class="icon icon-xl" src="/assets/frappe/images/ui-states/search-empty-state.svg">
|
<div class="modal-body">
|
||||||
</div>
|
<input class="search search-course" id="search-course" placeholder="{{ _(search_placeholder) or 'Search for courses' }}">
|
||||||
<div class="empty-state-text">
|
</div>
|
||||||
<div class="empty-state-heading">{{ _("No results found") }}</div>
|
</div>
|
||||||
<div class="course-meta">{{ _("Try some other keyword or explore our list of courses.") }}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script> {% include "lms/templates/search_course/search_course.js" %} </script>
|
<script> {% include "lms/templates/search_course/search_course.js" %} </script>
|
||||||
|
|||||||
@@ -3,22 +3,22 @@ frappe.ready(() => {
|
|||||||
search_course(e);
|
search_course(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".close-search-empty-state").click((e) => {
|
$("#open-search").click((e) => {
|
||||||
close_search_empty_state(e);
|
show_search_bar(e);
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#search-modal").on("hidden.bs.modal", () => {
|
||||||
|
hide_search_bar();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const search_course = (e) => {
|
const search_course = (e) => {
|
||||||
let input = $(e.currentTarget).val();
|
let input = $(e.currentTarget).val();
|
||||||
|
|
||||||
if (input == window.input) return;
|
if (input == window.input) return;
|
||||||
|
|
||||||
window.input = input;
|
window.input = input;
|
||||||
|
|
||||||
if (input.length < 3 || input.trim() == "") {
|
if (input.length < 3 || input.trim() == "") {
|
||||||
$(".course-card").removeClass("hide");
|
$(".result-row").remove();
|
||||||
$(".search-empty-state").addClass("hide");
|
|
||||||
fix_heading_styles();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,47 +28,39 @@ const search_course = (e) => {
|
|||||||
text: input,
|
text: input,
|
||||||
},
|
},
|
||||||
callback: (data) => {
|
callback: (data) => {
|
||||||
render_course_list(data.message);
|
render_course_list(data);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const render_course_list = (courses) => {
|
const render_course_list = (data) => {
|
||||||
fix_heading_styles();
|
let courses = data.message;
|
||||||
$(".search-empty-state").addClass("hide");
|
$(".result-row").remove();
|
||||||
|
|
||||||
if (!courses.length) {
|
if (!courses.length) {
|
||||||
$(".course-card").removeClass("hide");
|
let element = `<a class="result-row">
|
||||||
$(".search-empty-state").removeClass("hide");
|
${__("No result found")}
|
||||||
|
</a>`;
|
||||||
|
$(element).insertAfter("#search-course");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".course-card").addClass("hide");
|
for (let i in courses) {
|
||||||
for (course in courses) {
|
let element = `<a class="result-row" href="/courses/${courses[i].name}">
|
||||||
$("[data-course=" + courses[course].name + "]").removeClass("hide");
|
${courses[i].title}
|
||||||
}
|
</a>`;
|
||||||
|
$(element).insertAfter("#search-course");
|
||||||
const visible_live_courses = $(".live-courses .course-card").not(".hide");
|
|
||||||
const visible_upcoming_courses = $(".upcoming-courses .course-card").not(
|
|
||||||
".hide"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!visible_live_courses.length) {
|
|
||||||
$(".live-courses .course-home-headings").addClass("hide");
|
|
||||||
$(".upcoming-courses").removeClass("mt-10");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!visible_upcoming_courses.length) {
|
|
||||||
$(".upcoming-courses .course-home-headings").addClass("hide");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fix_heading_styles = () => {
|
const show_search_bar = (e) => {
|
||||||
$(".course-home-headings").removeClass("hide");
|
$("#search-modal").modal("show");
|
||||||
$(".upcoming-courses").addClass("mt-10");
|
setTimeout(() => {
|
||||||
|
$("#search-course").focus();
|
||||||
|
}, 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
const close_search_empty_state = (e) => {
|
const hide_search_bar = (e) => {
|
||||||
$(".search-empty-state").addClass("hide");
|
|
||||||
$("#search-course").val("");
|
$("#search-course").val("");
|
||||||
|
$(".result-row").remove();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
||||||
<!-- {% include "lms/templates/search_course/search_course.html" %} -->
|
{% include "lms/templates/search_course/search_course.html" %}
|
||||||
|
|
||||||
<div class="course-list-cta">
|
<div class="course-list-cta">
|
||||||
{% if frappe.session.user != "Guest" %}
|
{% if frappe.session.user != "Guest" %}
|
||||||
@@ -36,6 +36,10 @@
|
|||||||
{{ _("Create a Course") }}
|
{{ _("Create a Course") }}
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<a class="btn btn-default btn-sm ml-2" id="open-search">
|
||||||
|
{{ _("Search") }}
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="course-home-headings">
|
<div class="course-home-headings">
|
||||||
|
|||||||
Reference in New Issue
Block a user