feat: settings
This commit is contained in:
@@ -266,7 +266,9 @@ def get_chart_details():
|
||||
"upcoming": 0,
|
||||
},
|
||||
)
|
||||
details.users = frappe.db.count("User", {"enabled": 1})
|
||||
details.users = frappe.db.count(
|
||||
"User", {"enabled": 1, "name": ["not in", ("Administrator", "Guest")]}
|
||||
)
|
||||
details.completions = frappe.db.count(
|
||||
"LMS Enrollment", {"progress": ["like", "%100%"]}
|
||||
)
|
||||
@@ -560,3 +562,29 @@ def get_categories(doctype, filters):
|
||||
categoryOptions.append({"label": category, "value": category})
|
||||
|
||||
return categoryOptions
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_fields(doctype: str, allow_all_fieldtypes: bool = False):
|
||||
not_allowed_fieldtypes = list(frappe.model.no_value_fields) + ["Read Only"]
|
||||
if allow_all_fieldtypes:
|
||||
not_allowed_fieldtypes = []
|
||||
fields = frappe.get_meta(doctype).fields
|
||||
|
||||
_fields = []
|
||||
|
||||
for field in fields:
|
||||
if field.fieldtype not in not_allowed_fieldtypes and field.fieldname:
|
||||
_fields.append(
|
||||
{
|
||||
"label": field.label,
|
||||
"type": field.fieldtype,
|
||||
"value": field.fieldname,
|
||||
"options": field.options,
|
||||
"mandatory": field.reqd,
|
||||
"read_only": field.read_only,
|
||||
"hidden": field.hidden,
|
||||
}
|
||||
)
|
||||
|
||||
return _fields
|
||||
|
||||
@@ -517,13 +517,6 @@ def can_create_courses(course, member=None):
|
||||
if has_course_instructor_role(member) and member in instructors:
|
||||
return True
|
||||
|
||||
portal_course_creation = frappe.db.get_single_value(
|
||||
"LMS Settings", "portal_course_creation"
|
||||
)
|
||||
|
||||
if portal_course_creation == "Anyone" and member in instructors:
|
||||
return True
|
||||
|
||||
if not course and has_course_instructor_role(member):
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
{% 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") %}
|
||||
|
||||
|
||||
<div class="modal fade search-modal" id="search-modal" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-body">
|
||||
<input class="search search-course" id="search-course" placeholder="{{ _(search_placeholder) or 'Search for courses' }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script> {% include "lms/templates/search_course/search_course.js" %} </script>
|
||||
@@ -1,72 +0,0 @@
|
||||
frappe.ready(() => {
|
||||
$("#search-course").keyup((e) => {
|
||||
search_course(e);
|
||||
});
|
||||
|
||||
$("#open-search").click((e) => {
|
||||
show_search_bar(e);
|
||||
});
|
||||
|
||||
$("#search-modal").on("hidden.bs.modal", () => {
|
||||
hide_search_bar();
|
||||
});
|
||||
|
||||
$(document).keydown(function (e) {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key == "k") {
|
||||
show_search_bar(e);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const search_course = (e) => {
|
||||
let input = $(e.currentTarget).val();
|
||||
if (input == window.input) return;
|
||||
window.input = input;
|
||||
|
||||
if (input.length < 3 || input.trim() == "") {
|
||||
$(".result-row").remove();
|
||||
return;
|
||||
}
|
||||
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_course.lms_course.search_course",
|
||||
args: {
|
||||
text: input,
|
||||
},
|
||||
callback: (data) => {
|
||||
render_course_list(data);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const render_course_list = (data) => {
|
||||
let courses = data.message;
|
||||
$(".result-row").remove();
|
||||
|
||||
if (!courses.length) {
|
||||
let element = `<a class="result-row">
|
||||
${__("No result found")}
|
||||
</a>`;
|
||||
$(element).insertAfter("#search-course");
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i in courses) {
|
||||
let element = `<a class="result-row" href="/courses/${courses[i].name}">
|
||||
${courses[i].title}
|
||||
</a>`;
|
||||
$(element).insertAfter("#search-course");
|
||||
}
|
||||
};
|
||||
|
||||
const show_search_bar = (e) => {
|
||||
$("#search-modal").modal("show");
|
||||
setTimeout(() => {
|
||||
$("#search-course").focus();
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
const hide_search_bar = (e) => {
|
||||
$("#search-course").val("");
|
||||
$(".result-row").remove();
|
||||
};
|
||||
Reference in New Issue
Block a user