diff --git a/lms/lms/doctype/class_course/class_course.json b/lms/lms/doctype/class_course/class_course.json index 6a614436..6412b74a 100644 --- a/lms/lms/doctype/class_course/class_course.json +++ b/lms/lms/doctype/class_course/class_course.json @@ -30,6 +30,7 @@ { "fieldname": "evaluator", "fieldtype": "Link", + "in_list_view": 1, "label": "Evaluator", "options": "Course Evaluator" } @@ -37,7 +38,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-07-13 14:21:49.953345", + "modified": "2023-07-13 17:51:36.278393", "modified_by": "Administrator", "module": "LMS", "name": "Class Course", diff --git a/lms/lms/doctype/course_evaluator/course_evaluator.py b/lms/lms/doctype/course_evaluator/course_evaluator.py index de3a6587..beff1c6e 100644 --- a/lms/lms/doctype/course_evaluator/course_evaluator.py +++ b/lms/lms/doctype/course_evaluator/course_evaluator.py @@ -36,14 +36,26 @@ class CourseEvaluator(Document): @frappe.whitelist() -def get_schedule(course, date): - evaluator = frappe.db.get_value("LMS Course", course, "evaluator") +def get_schedule(course, date, class_name=None): + evaluator = None + + if class_name: + evaluator = frappe.db.get_value( + "Class Course", + {"parent": class_name, "course": course}, + "evaluator", + ) + + if not evaluator: + evaluator = frappe.db.get_value("LMS Course", course, "evaluator") + all_slots = frappe.get_all( "Evaluator Schedule", filters={"parent": evaluator}, fields=["day", "start_time", "end_time"], order_by="start_time", ) + booked_slots = frappe.get_all( "LMS Certificate Request", filters={"evaluator": evaluator, "date": date}, diff --git a/lms/public/js/common_functions.js b/lms/public/js/common_functions.js index 2eeb43ae..62ad81f3 100644 --- a/lms/public/js/common_functions.js +++ b/lms/public/js/common_functions.js @@ -1,6 +1,7 @@ frappe.ready(() => { setup_file_size(); pin_header(); + setup_router(); $(".join-batch").click((e) => { join_course(e); @@ -42,6 +43,14 @@ frappe.ready(() => { }); }); +const setup_router = () => { + frappe.router = { + slug(name) { + return name.toLowerCase().replace(/ /g, "-"); + }, + }; +}; + const pin_header = () => { const el = document.querySelector(".sticky"); if (el) { diff --git a/lms/www/classes/progress.html b/lms/www/classes/progress.html index 84d030b9..f49e47cd 100644 --- a/lms/www/classes/progress.html +++ b/lms/www/classes/progress.html @@ -30,21 +30,27 @@ {{ class_info.name }} - {{ _("Student Progress").format(student.full_name) }} + + {{ _("Student Progress").format(student.full_name) }} + - {% if is_moderator %}
- + {{ _("View Profile") }} - + {% if student.name == frappe.session.user %} + + {% endif %} + {% if is_moderator %} + {{ _("Evaluate") }} + {% endif %}
- {% endif %} - @@ -107,4 +113,18 @@ {% else %}

{{ _("No Assessments") }}

{% endif %} -{% endmacro %} \ No newline at end of file +{% endmacro %} + +{%- block script %} + {{ super() }} + + {{ include_script('controls.bundle.js') }} +{% endblock %} \ No newline at end of file diff --git a/lms/www/classes/progress.js b/lms/www/classes/progress.js index 6c136c9a..5071da22 100644 --- a/lms/www/classes/progress.js +++ b/lms/www/classes/progress.js @@ -2,4 +2,134 @@ frappe.ready(() => { $(".clickable-row").click((e) => { window.location.href = $(e.currentTarget).data("href"); }); + + $(".btn-schedule-eval").click((e) => { + open_evaluation_form(e); + }); + + $(document).on("click", ".slot", (e) => { + mark_active_slot(e); + }); }); + +const open_evaluation_form = (e) => { + this.eval_form = new frappe.ui.Dialog({ + title: __("Schedule Evaluation"), + fields: [ + { + fieldtype: "Link", + fieldname: "course", + label: __("Course"), + options: "LMS Course", + reqd: 1, + get_query: () => { + return { + filters: { + name: ["in", courses], + }, + }; + }, + }, + { + fieldtype: "Date", + fieldname: "date", + label: __("Date"), + reqd: 1, + min_date: frappe.datetime.add_days( + frappe.datetime.get_today(), + 1 + ), + change: () => { + get_slots(); + }, + }, + { + fieldtype: "HTML", + fieldname: "slots", + label: __("Slots"), + }, + ], + primary_action: (values) => { + submit_evaluation_form(values); + }, + }); + this.eval_form.show(); + setTimeout(() => { + $(".modal-body").css("min-height", "300px"); + }, 1000); +}; + +const get_slots = () => { + frappe.call({ + method: "lms.lms.doctype.course_evaluator.course_evaluator.get_schedule", + args: { + course: this.eval_form.get_value("course"), + date: this.eval_form.get_value("date"), + class_name: class_name, + }, + callback: (r) => { + if (r.message) { + console.log(r.message); + display_slots(r.message); + } + }, + }); +}; + +const display_slots = (slots) => { + let slot_html = ""; + let day = moment(this.eval_form.get_value("date")).format("dddd"); + + slots.forEach((slot) => { + if (slot.day == day) { + slot_html += `
+ ${moment(slot.start_time, "hh:mm").format("hh:mm a")} - ${moment( + slot.end_time, + "hh:mm" + ).format("hh:mm a")} +
`; + } + }); + + if (!slot_html) { + slot_html = ``; + } + + $("[data-fieldname='slots']").html(slot_html); +}; + +const mark_active_slot = (e) => { + $(".slot").removeClass("btn-outline-primary"); + $(e.currentTarget).addClass("btn-outline-primary"); + this.current_slot = $(e.currentTarget); +}; + +const submit_evaluation_form = (values) => { + if (!this.current_slot) { + frappe.throw(__("Please select a slot")); + } + + frappe.call({ + method: "lms.lms.doctype.lms_certificate_request.lms_certificate_request.create_certificate_request", + args: { + course: values.course, + date: values.date, + start_time: this.current_slot.data("start"), + end_time: this.current_slot.data("end"), + day: this.current_slot.data("day"), + }, + callback: (r) => { + if (r.message) { + frappe.msgprint({ + title: __("Success"), + message: __("Evaluation scheduled successfully"), + }); + this.eval_form.hide(); + } + }, + }); +}; diff --git a/lms/www/classes/progress.py b/lms/www/classes/progress.py index be922dd1..b8a6e318 100644 --- a/lms/www/classes/progress.py +++ b/lms/www/classes/progress.py @@ -21,4 +21,8 @@ def get_context(context): "LMS Class", class_name, ["name"], as_dict=True ) + context.courses = frappe.get_all( + "Class Course", {"parent": class_name}, pluck="course" + ) + context.assessments = get_assessments(class_name, context.student.name)