feat: assignment submission and ui
This commit is contained in:
0
lms/www/assignments/__init__.py
Normal file
0
lms/www/assignments/__init__.py
Normal file
@@ -8,26 +8,53 @@
|
||||
<div class="common-page-style">
|
||||
<div class="container">
|
||||
<div class="common-card-style column-card">
|
||||
<div class="btn btn-primary btn-sm pull-right" id="save-assignment"> {{ _("Save") }} </div>
|
||||
<div class="course-home-headings"> {{ _("Assignments") }} </div>
|
||||
<div class="row medium">
|
||||
<div class="col">
|
||||
<div>
|
||||
<a href="{{ assignment.assignment }}" target="_blank">
|
||||
{{ _("Click to open assignment") }}
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<select class="btn btn-default ml-2" id="file-type" data-type="{{ assignment.status }}">
|
||||
<option selected> {{ _("Result") }} </option>
|
||||
<option value="Image"> {{ _("Pass") }} </option>
|
||||
<option value="Document"> {{ _("Fail") }} </option>
|
||||
</select>
|
||||
<div class="course-home-headings"> {{ _("Assignment Grading") }} </div>
|
||||
<div class="medium w-50 mt-3">
|
||||
<a class="btn btn-secondary btn-sm" href="{{ assignment.assignment }}" target="_blank">
|
||||
{{ _("Open Attachment") }}
|
||||
</a>
|
||||
<select class="btn btn-secondary btn-sm ml-2 lms-menu" id="result" data-type="{{ assignment.status }}">
|
||||
<option selected> {{ _("Not Graded") }} </option>
|
||||
<option value="Pass"> {{ _("Pass") }} </option>
|
||||
<option value="Fail"> {{ _("Fail") }} </option>
|
||||
</select>
|
||||
|
||||
<div class="mt-3">
|
||||
<span class="subheading">
|
||||
{{ _("Member") }}:
|
||||
</span>
|
||||
<span>
|
||||
{{ assignment.member_name }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{% set course_title = frappe.db.get_value("LMS Course", assignment.course, "title") %}
|
||||
<span class="subheading">
|
||||
{{ _("Course") }}:
|
||||
</span>
|
||||
<span>
|
||||
{{ course_title }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-3">
|
||||
{% set lesson_title = frappe.db.get_value("Course Lesson", assignment.lesson, "title") %}
|
||||
<span class="subheading"> {{ _("Lesson") }}: </span>
|
||||
<span>
|
||||
{{ lesson_title }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div class="subheading mt-3"> {{ _("Comments") }}: </div>
|
||||
<div class="control-input-wrapper">
|
||||
<div class="control-input">
|
||||
<textarea type="text" class="input-with-feedback form-control" id="comments" spellcheck="false"
|
||||
autocomplete="off" placeholder="Comments">{% if assignment.comments %}{{ assignment.comments }}{% endif %}
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col">
|
||||
<div contenteditable="true" data-placeholder="{{ _('Comments') }}"
|
||||
style="height: 100px;" >{% if assignment.comments %}{{ assignment.comments }}{% endif %}</div>
|
||||
|
||||
<div class="btn btn-primary btn-sm mt-3" id="save-assignment" data-assignment="{{ assignment.name }}">
|
||||
{{ _("Save") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
50
lms/www/assignments/assignment.js
Normal file
50
lms/www/assignments/assignment.js
Normal file
@@ -0,0 +1,50 @@
|
||||
frappe.ready(() => {
|
||||
|
||||
this.result;
|
||||
let self = this;
|
||||
|
||||
set_result();
|
||||
|
||||
$("#save-assignment").click((e) => {
|
||||
save_assignment(e);
|
||||
});
|
||||
|
||||
$("#result").change((e) => {
|
||||
$("#result option:selected").each(function () {
|
||||
self.result = $(this).val();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
const set_result = () => {
|
||||
let self = this;
|
||||
let result = $("#result").data("type");
|
||||
if (result) {
|
||||
$("#result option").each((i, elem) => {
|
||||
if ($(elem).val() == result) {
|
||||
$(elem).attr("selected", true);
|
||||
self.result = result;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const save_assignment = (e) => {
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lesson_assignment.lesson_assignment.grade_assignment",
|
||||
args: {
|
||||
"name": $(e.currentTarget).data("assignment"),
|
||||
"result": self.result,
|
||||
"comments": $("#comments").val(),
|
||||
},
|
||||
callback: (data) => {
|
||||
frappe.show_alert({
|
||||
message: __("Saved"),
|
||||
indicator: "green",
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import frappe
|
||||
from lms.lms.utils import has_course_moderator_role
|
||||
from frappe import _
|
||||
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
assignment = frappe.form_dict["assignment"]
|
||||
@@ -13,4 +14,9 @@ def get_context(context):
|
||||
|
||||
raise frappe.PermissionError(_(message))
|
||||
|
||||
context.assignment = frappe.db.get_value("Lesson Assignment", assignment, ["assignment", "comments", "status", "name"], as_dict=True)
|
||||
context.assignment = frappe.db.get_value(
|
||||
"Lesson Assignment",
|
||||
assignment,
|
||||
["assignment", "comments", "status", "name", "member_name", "course", "lesson"],
|
||||
as_dict=True,
|
||||
)
|
||||
|
||||
@@ -33,9 +33,11 @@
|
||||
<div class="course-home-headings">
|
||||
{{ class_info.title }}
|
||||
</div>
|
||||
{% if class_info.description %}
|
||||
<div class="medium">
|
||||
{{ class_info.description }}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="medium">
|
||||
{% if class_info.start_date %}
|
||||
<span>
|
||||
@@ -108,18 +110,19 @@
|
||||
{% if class_students | length %}
|
||||
<div class="mt-10">
|
||||
{% for student in class_students %}
|
||||
<div class="" style="position: relative;">
|
||||
<span>{{ student.student_name }}</span>
|
||||
<div class="d-flex" style="position: relative;">
|
||||
<a class="button-links flex-grow-1" href="/classes/{{ class_info.name }}/students/{{ student.username }}">
|
||||
{{ student.student_name }}
|
||||
</a>
|
||||
<svg class="icon icon-md pull-right remove-student" data-student="{{ student.student }}">
|
||||
<use href="#icon-delete"></use>
|
||||
</svg>
|
||||
<a class="stretched-link" href="/classes/{{ class_info.name }}/students/{{ student.username }}"></a>
|
||||
</div>
|
||||
{% if not loop.last %} <hr> {% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="text-muted"> {{ _("No Students are added to this class.") }} </p>
|
||||
<p class="text-muted mt-3"> {{ _("No Students are added to this class.") }} </p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
frappe.ready(() => {
|
||||
|
||||
$("#submit-student").click((e) => {
|
||||
submit_student(e);
|
||||
});
|
||||
@@ -11,57 +10,61 @@ frappe.ready(() => {
|
||||
$(".class-course").click((e) => {
|
||||
update_course(e);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
const submit_student = (e) => {
|
||||
e.preventDefault();
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_class.lms_class.add_student",
|
||||
args: {
|
||||
"email": $("#student-email").val(),
|
||||
"class_name": $(".class-details").data("class")
|
||||
email: $("#student-email").val(),
|
||||
class_name: $(".class-details").data("class"),
|
||||
},
|
||||
callback: (data) => {
|
||||
frappe.show_alert({
|
||||
frappe.show_alert(
|
||||
{
|
||||
message: __("Student added successfully"),
|
||||
indicator: "green",
|
||||
} ,3);
|
||||
},
|
||||
3
|
||||
);
|
||||
window.location.reload();
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const remove_student = (e) => {
|
||||
frappe.confirm("Are you sure you want to remove this student from the class?",
|
||||
() => {
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_class.lms_class.remove_student",
|
||||
args: {
|
||||
"student": $(e.currentTarget).data("student"),
|
||||
"class_name": $(".class-details").data("class")
|
||||
},
|
||||
callback: (data) => {
|
||||
frappe.show_alert({
|
||||
message: __("Student removed successfully"),
|
||||
indicator: "green",
|
||||
}, 3);
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
frappe.confirm(
|
||||
"Are you sure you want to remove this student from the class?",
|
||||
() => {
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_class.lms_class.remove_student",
|
||||
args: {
|
||||
student: $(e.currentTarget).data("student"),
|
||||
class_name: $(".class-details").data("class"),
|
||||
},
|
||||
callback: (data) => {
|
||||
frappe.show_alert(
|
||||
{
|
||||
message: __("Student removed successfully"),
|
||||
indicator: "green",
|
||||
},
|
||||
3
|
||||
);
|
||||
window.location.reload();
|
||||
},
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const update_course = (e) => {
|
||||
frappe.call({
|
||||
method: "lms.lms.doctype.lms_class.lms_class.update_course",
|
||||
args: {
|
||||
"course": $(e.currentTarget).data("course"),
|
||||
"value": $(e.currentTarget).children("input").prop("checked") ? 1 : 0,
|
||||
"class_name": $(".class-details").data("class")
|
||||
}
|
||||
})
|
||||
course: $(e.currentTarget).data("course"),
|
||||
value: $(e.currentTarget).children("input").prop("checked") ? 1 : 0,
|
||||
class_name: $(".class-details").data("class"),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import frappe
|
||||
from lms.lms.utils import has_course_moderator_role
|
||||
from frappe import _
|
||||
from lms.lms.utils import has_course_moderator_role
|
||||
|
||||
|
||||
def get_context(context):
|
||||
@@ -16,13 +15,20 @@ def get_context(context):
|
||||
|
||||
class_name = frappe.form_dict["classname"]
|
||||
|
||||
context.class_info = frappe.db.get_value("LMS Class", class_name, ["name", "title", "start_date", "end_date", "description"], as_dict=True)
|
||||
context.published_courses = frappe.get_all("LMS Course", {"published": 1}, ["name", "title"])
|
||||
context.class_info = frappe.db.get_value(
|
||||
"LMS Class",
|
||||
class_name,
|
||||
["name", "title", "start_date", "end_date", "description"],
|
||||
as_dict=True,
|
||||
)
|
||||
context.published_courses = frappe.get_all(
|
||||
"LMS Course", {"published": 1}, ["name", "title"]
|
||||
)
|
||||
|
||||
context.class_courses = frappe.get_all("Class Course", {
|
||||
"parent": class_name
|
||||
}, pluck="course")
|
||||
context.class_courses = frappe.get_all(
|
||||
"Class Course", {"parent": class_name}, pluck="course"
|
||||
)
|
||||
|
||||
context.class_students = frappe.get_all("Class Student", {
|
||||
"parent": class_name
|
||||
}, ["student", "student_name", "username"])
|
||||
context.class_students = frappe.get_all(
|
||||
"Class Student", {"parent": class_name}, ["student", "student_name", "username"]
|
||||
)
|
||||
|
||||
@@ -13,4 +13,6 @@ def get_context(context):
|
||||
|
||||
raise frappe.PermissionError(_(message))
|
||||
|
||||
context.classes = frappe.get_all("LMS Class", fields=["name", "title", "start_date", "end_date"])
|
||||
context.classes = frappe.get_all(
|
||||
"LMS Class", fields=["name", "title", "start_date", "end_date"]
|
||||
)
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
{% macro Progress(class_info, student) %}
|
||||
<div>
|
||||
{% for course in class_courses %}
|
||||
{% set progress = course.membership.progress %}
|
||||
<div class="medium">
|
||||
<div class="progress-course-header">
|
||||
<div class="section-heading"> {{ course.title }} </div>
|
||||
@@ -56,11 +57,12 @@
|
||||
{{ _("Last Attempt Date") }}
|
||||
</th>
|
||||
</tr>
|
||||
{% for quiz in course.quizzes %}
|
||||
|
||||
{% for quiz in course.quizzes %}
|
||||
{% set filters = { "member": student.name, "course": course.course } %}
|
||||
{% set has_submitted = frappe.db.exists("LMS Quiz Submission", filters) %}
|
||||
{% set submission = frappe.db.get_value("LMS Quiz Submission", filters, ["score", "creation"], as_dict=True) %}
|
||||
{% set total_questions = frappe.db.count("LMS Quiz Question", {"parent": quiz.name}) %}
|
||||
|
||||
<tr class="">
|
||||
<td>
|
||||
@@ -71,7 +73,7 @@
|
||||
</td>
|
||||
{% if has_submitted %}
|
||||
<td>
|
||||
{{ submission.score }}
|
||||
{{ submission.score }}/{{ total_questions }}
|
||||
</td>
|
||||
<td>
|
||||
{{ frappe.utils.format_date(submission.creation, "medium") }}
|
||||
|
||||
@@ -2,6 +2,7 @@ import frappe
|
||||
from lms.lms.utils import has_course_moderator_role
|
||||
from frappe import _
|
||||
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
|
||||
@@ -15,19 +16,31 @@ def get_context(context):
|
||||
student = frappe.form_dict["username"]
|
||||
classname = frappe.form_dict["classname"]
|
||||
|
||||
context.student = frappe.db.get_value("User", {"username": student}, ["first_name", "full_name", "name"], as_dict=True)
|
||||
context.class_info = frappe.db.get_value("LMS Class", classname, ["name"], as_dict=True)
|
||||
context.student = frappe.db.get_value(
|
||||
"User", {"username": student}, ["first_name", "full_name", "name"], as_dict=True
|
||||
)
|
||||
context.class_info = frappe.db.get_value(
|
||||
"LMS Class", classname, ["name"], as_dict=True
|
||||
)
|
||||
|
||||
class_courses = frappe.get_all("Class Course", {
|
||||
"parent": classname
|
||||
}, ["course", "title"])
|
||||
class_courses = frappe.get_all(
|
||||
"Class Course", {"parent": classname}, ["course", "title"]
|
||||
)
|
||||
|
||||
for course in class_courses:
|
||||
course.membership = frappe.db.get_value("LMS Batch Membership", {
|
||||
"member": context.student.name,
|
||||
"course": course.course
|
||||
}, ["progress"], as_dict=True)
|
||||
course.quizzes = frappe.get_all("LMS Quiz", {"course": course.course}, ["name", "title"])
|
||||
course.assignments = frappe.get_all("Course Lesson", {"course": course.course, "question": ["is", "set"]}, ["name", "title"])
|
||||
course.membership = frappe.db.get_value(
|
||||
"LMS Batch Membership",
|
||||
{"member": context.student.name, "course": course.course},
|
||||
["progress"],
|
||||
as_dict=True,
|
||||
)
|
||||
course.quizzes = frappe.get_all(
|
||||
"LMS Quiz", {"course": course.course}, ["name", "title"]
|
||||
)
|
||||
course.assignments = frappe.get_all(
|
||||
"Course Lesson",
|
||||
{"course": course.course, "question": ["is", "set"]},
|
||||
["name", "title"],
|
||||
)
|
||||
|
||||
context.class_courses = class_courses
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
frappe.ready(() => {
|
||||
|
||||
});
|
||||
frappe.ready(() => {});
|
||||
|
||||
const change_hash = (e) => {
|
||||
window.location.hash = $(e.currentTarget).attr("href");
|
||||
|
||||
Reference in New Issue
Block a user