feat: my class tab

This commit is contained in:
Jannat Patel
2023-06-01 22:44:32 +05:30
parent fe80ef9b85
commit 85903d5385
9 changed files with 183 additions and 62 deletions

View File

@@ -16,25 +16,32 @@
<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>
<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 %}
{% 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 class="vertically-center small">
<a class="dark-links" href="/classes">
{{ _("All Classes") }}
</a>
</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 %}>
<button class="btn btn-primary btn-sm btn-save-assignment" {% if assignment.name %} data-assignment="{{ assignment.name }}" {% endif %}
{% if submission.name %} data-submission="{{ submission.name }}" {% endif %}>
{{ _("Save") }}
</button>
</div>
{% endif %}
</div>
</div>
</header>
@@ -42,17 +49,19 @@
{% macro SubmissionForm(assignment) %}
<article class="field-parent">
{% if submission.name and is_moderator %}
<div class="field-group">
<div class="field-label">
{{ _("Student") }}
{{ _("Student Name") }}
</div>
{{ submission.member_name }}
</div>
{% endif %}
<div class="field-group">
<!-- <div class="field-label">
<div class="field-label">
{{ _("Question")}}
</div> -->
</div>
{{ assignment.question }}
</div>
@@ -64,18 +73,61 @@
{{ _("Upload assignment as {0}").format(assignment.type) }}
</div>
<div class="file-source-preview">
{% if submission.status == "Not Graded" and submission.member == frappe.session.user %}
<span class="btn btn-default btn-sm btn-close">
{{ _("Clear") }}
<div class="btn btn-default btn-sm btn-upload mt-2 {% if submission.assignment_attachment %} hide {% endif %}" data-type="{{ assignment.type }}">
{{ _("Browse").format(assignment.type) }}
</div>
<div class="field-input flex justify-between align-center {% if not submission.assignment_attachment %} hide {% endif %}" id="assignment-preview">
<a class="clickable" {% if submission.assignment_attachment %} href="{{ submission.assignment_attachment }}" {% endif %}>
{% if submission.assignment_attachment %} {{ submission.assignment_attachment }} {% endif %}
</a>
<span class="btn btn-default btn-sm btn-close {% if not submission %} hide {% endif %}">
{{ _("Clear") }}
</span>
{% endif %}
<div class="btn-upload clickable {% if submission.assignment_attachment %} hide {% endif %}" data-type="{{ assignment.type }}">
{{ _("Browse").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>
{% if is_moderator %}
<div class="field-group">
<div class="field-label">
{{ _("Status") }}
</div>
<div class="field-input flex align-center">
<select class="form-control" id="status">
{% set statuses = ["Not Graded", "Pass", "Fail"] %}
{% for status in statuses %}
<option value="{{ status }}" {% if submission.status == status %} selected {% endif %}>
{{ status }}
</option>
{% endfor %}
</select>
<div class="select-icon">
<svg class="icon icon-sm">
<use class="" href="#icon-select"></use>
</svg>
</div>
</div>
</div>
<div class="field-group">
<div class="field-label">
{{ _("Comments by Mentor") }}
</div>
<textarea id="comments" type="text" class="field-input" height="300px"
>{% if submission.comments %}{{ submission.comments }}{% endif %}</textarea>
</div>
{% endif %}
{% if submission and submission.member == frappe.session.user and submission.comments %}
<div class="field-group">
<div class="field-label">
{{ _("Comments by Mentor") }}
</div>
<div>
{{ submission.comments }}
</div>
</div>
{% endif %}
</article>
{% endmacro %}

View File

@@ -15,10 +15,15 @@ frappe.ready(() => {
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",
Image: ["image/*"],
Document: [
".doc",
".docx",
".xml",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
],
PDF: [".pdf"],
};
new frappe.ui.FileUploader({
@@ -26,20 +31,23 @@ const upload_file = (e) => {
folder: "Home/Attachments",
make_attachments_public: true,
restrictions: {
allowed_file_types: [mapper[type]],
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");
$("#assignment-preview").removeClass("hide");
$("#assignment-preview .btn-close").removeClass("hide");
$("#assignment-preview a").attr(
"href",
encodeURI(file_doc.file_url)
);
$("#assignment-preview a").text(file_doc.file_url);
},
});
};
const save_assignment = (e) => {
let file = $(".image-preview").attr("src");
let file = $("#assignment-preview a").attr("href");
if (!file) {
frappe.throw({
title: __("No File"),
@@ -51,7 +59,10 @@ const save_assignment = (e) => {
method: "lms.lms.doctype.lms_assignment_submission.lms_assignment_submission.upload_assignment",
args: {
assignment: $(e.currentTarget).data("assignment"),
submission: $(e.currentTarget).data("submission") || "",
assignment_attachment: file,
status: $("#status").val(),
comments: $("#comments").val(),
},
callback: (data) => {
frappe.show_alert({
@@ -68,7 +79,8 @@ const save_assignment = (e) => {
};
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");
$(".btn-upload").removeClass("hide");
$("#assignment-preview").addClass("hide");
$("#assignment-preview a").attr("href", "");
$("#assignment-preview .btn-close").addClass("hide");
};

View File

@@ -25,5 +25,5 @@ def get_context(context):
if not context.is_moderator and frappe.session.user != context.submission.member:
raise frappe.PermissionError(_("You don't have permission to access this page."))
if not context.assignment or not context.submission:
raise frappe.PermissionError(_("Invalid Submission URL"))
if not context.assignment or not context.submission:
raise frappe.PermissionError(_("Invalid Submission URL"))