feat: assessment tab in class

This commit is contained in:
Jannat Patel
2023-05-30 22:11:14 +05:30
parent 70a036e5a7
commit bb39999b84
41 changed files with 1157 additions and 263 deletions

View File

@@ -0,0 +1,72 @@
{% extends "lms/templates/lms_base.html" %}
{% block title %}
{{ assignment.title }}
{% endblock %}
{% block page_content %}
<main class="common-page-style">
{{ Header() }}
<div class="container form-width">
{{ SubmissionForm(assignment) }}
</div>
</main>
{% endblock %}
{% macro Header() %}
<header class="sticky mb-5">
<div class="container form-width">
<div class="edit-header">
<div class="vertically-center">
<div class="page-title">
{{ assignment.title }}
</div>
{% if submission.status %}
{% set color = "green" if submission.status == "Pass" else "red" if submission.status == "Fail" else "orange" %}
<div class="indicator-pill {{ color }} ml-2">
{{ submission.status }}
</div>
{% endif %}
</div>
{% if submission.status == "Not Graded" %}
<div class="align-self-center">
<button class="btn btn-primary btn-sm btn-save-assignment" {% if assignment.name %} data-assignment="{{ assignment.name }}" {% endif %}>
{{ _("Save") }}
</button>
</div>
{% endif %}
</div>
</div>
</header>
{% endmacro %}
{% macro SubmissionForm(assignment) %}
<article class="field-parent">
<div class="field-group">
<div class="field-label">
{{ _("Question")}}
</div>
{{ assignment.question }}
</div>
<div class="field-group">
<div class="field-label">
{{ _("Submit your assignment")}}
</div>
<div class="file-source-preview">
{% if submission.status == "Not Graded" %}
<span class="btn btn-default btn-sm btn-close">
{{ _("Clear") }}
</span>
{% endif %}
<div class="btn-upload clickable {% if submission.assignment_attachment %} hide {% endif %}" data-type="{{ assignment.type }}">
{{ _("Upload a {0}").format(assignment.type) }}
</div>
<iframe class="image-preview {% if not submission.assignment_attachment %} hide {% endif %}" {% if submission.assignment_attachment %} src="{{ submission.assignment_attachment }}" {% endif %}></iframe>
</div>
</div>
</article>
{% endmacro %}

View File

@@ -0,0 +1,74 @@
frappe.ready(() => {
$(".btn-upload").click((e) => {
upload_file(e);
});
$(".btn-save-assignment").click((e) => {
save_assignment(e);
});
$(".btn-close").click((e) => {
clear_preview(e);
});
});
const upload_file = (e) => {
let type = $(e.currentTarget).data("type");
let mapper = {
Image: "image/*",
Document:
".doc,.docx,.xml,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
PDF: ".pdf",
};
new frappe.ui.FileUploader({
disable_file_browser: true,
folder: "Home/Attachments",
make_attachments_public: true,
restrictions: {
allowed_file_types: [mapper[type]],
},
on_success: (file_doc) => {
$(e.currentTarget).addClass("hide");
$(".file-source-preview .btn-close").removeClass("hide");
$(".file-source-preview iframe")
.attr("src", file_doc.file_url)
.removeClass("hide");
},
});
};
const save_assignment = (e) => {
let file = $(".image-preview").attr("src");
if (!file) {
frappe.throw({
title: __("No File"),
message: __("Please upload a file."),
});
}
frappe.call({
method: "lms.lms.doctype.lms_assignment_submission.lms_assignment_submission.upload_assignment",
args: {
assignment: $(e.currentTarget).data("assignment"),
assignment_attachment: file,
},
callback: (data) => {
frappe.show_alert({
message: __("Saved"),
indicator: "green",
});
setTimeout(() => {
window.location.href = `/assignment-submission/${$(
e.currentTarget
).data("assignment")}/${data.message}`;
}, 2000);
},
});
};
const clear_preview = (e) => {
$(".file-source-preview .btn-upload").removeClass("hide");
$(".file-source-preview iframe").attr("src", "").addClass("hide");
$(".file-source-preview .btn-close").addClass("hide");
};

View File

@@ -0,0 +1,24 @@
import frappe
from frappe import _
def get_context(context):
context.no_cache = 1
submission = frappe.form_dict["submission"]
assignment = frappe.form_dict["assignment"]
context.assignment = frappe.db.get_value(
"LMS Assignment", assignment, ["title", "name", "type", "question"], as_dict=1
)
if submission == "new-submission":
context.submission = frappe._dict()
else:
context.submission = frappe.db.get_value(
"LMS Assignment Submission",
submission,
["name", "assignment_attachment", "comments", "status"],
as_dict=True,
)
if not context.assignment or not context.submission:
raise frappe.PermissionError(_("Invalid Submission URL"))