feat: assignment as text
This commit is contained in:
@@ -21,7 +21,7 @@
|
||||
<div class="page-title">
|
||||
{{ assignment.title }}
|
||||
</div>
|
||||
{% if submission.status %}
|
||||
{% if assignment.grade_assignment and 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 }}
|
||||
@@ -37,7 +37,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% if not assignment.show_answer or (assignment.show_answer and not submission) %}
|
||||
<div class="align-self-center">
|
||||
<button class="btn btn-primary btn-sm btn-save-assignment"
|
||||
data-assignment="{{ assignment.name }}" data-type="{{ assignment.type }}"
|
||||
@@ -45,6 +45,7 @@
|
||||
{{ _("Save") }}
|
||||
</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
@@ -52,7 +53,7 @@
|
||||
|
||||
{% macro SubmissionForm(assignment) %}
|
||||
<article class="field-parent">
|
||||
{% if submission.name %}
|
||||
{% if assignment.grade_assignment and submission.name %}
|
||||
<div class="alert alert-info">
|
||||
{{ _("You've successfully submitted the assignment. Once the moderator grades your submission, you'll find the details here. Feel free to make edits to your submission if needed.") }}
|
||||
</div>
|
||||
@@ -73,7 +74,7 @@
|
||||
{{ assignment.question }}
|
||||
</div>
|
||||
|
||||
{% if assignment.type != "URL" %}
|
||||
{% if assignment.type not in ["URL", "Text"] %}
|
||||
<div class="field-group">
|
||||
<div class="bold-heading">
|
||||
{{ _("Submit")}}
|
||||
@@ -100,17 +101,41 @@
|
||||
|
||||
<div class="field-group">
|
||||
<div class="bold-heading">
|
||||
{{ _("Submit")}}
|
||||
{{ _("Submission")}}
|
||||
</div>
|
||||
<div class="field-description">
|
||||
{{ _("Enter a URL") }}
|
||||
{% if assignment.type == "URL" %}
|
||||
{{ _("Enter a {0}").format(assignment.type) }}
|
||||
{% else %}
|
||||
{{ _("Enter your response") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
<input id="assignment-url" type="text" class="field-input" placeholder="https://"
|
||||
{% if submission.answer %} value="{{ submission.answer }}" {% endif %}>
|
||||
{% if assignment.type == "URL" %}
|
||||
<input type="text" class="field-input assignment-answer" placeholder="https://"
|
||||
{% if submission.answer %} value="{{ submission.answer }}" {% endif %}>
|
||||
{% else %}
|
||||
<div class="assignment-text"></div>
|
||||
{% if submission.answer %}
|
||||
<div class="assignment-text-data hide">
|
||||
{{ submission.answer }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if is_moderator %}
|
||||
{% if assignment.show_answer and submission %}
|
||||
<div class="field-group">
|
||||
<div class="bold-heading">
|
||||
{{ _("Response by Instructor:") }}
|
||||
</div>
|
||||
<div>
|
||||
{{ assignment.answer }}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if assignment.grade_assignment and is_moderator %}
|
||||
<div class="field-group">
|
||||
<div class="field-label">
|
||||
{{ _("Status") }}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
frappe.ready(() => {
|
||||
if ($(".assignment-text").length) {
|
||||
frappe.require("controls.bundle.js", () => {
|
||||
make_text_editor();
|
||||
});
|
||||
}
|
||||
|
||||
$(".btn-upload").click((e) => {
|
||||
upload_file(e);
|
||||
});
|
||||
@@ -52,11 +58,19 @@ const save_assignment = (e) => {
|
||||
file = "";
|
||||
|
||||
if (data == "URL") {
|
||||
answer = $("#assignment-url").val();
|
||||
answer = $(".assignment-answer").val();
|
||||
if (!answer) {
|
||||
frappe.throw({
|
||||
title: __("No URL"),
|
||||
message: __("Please enter a URL."),
|
||||
title: __("No Submission"),
|
||||
message: __("Please enter a response."),
|
||||
});
|
||||
}
|
||||
} else if (data == "Text") {
|
||||
answer = this.text_editor.get_value("assignment_text");
|
||||
if (!answer) {
|
||||
frappe.throw({
|
||||
title: __("No Submission"),
|
||||
message: __("Please enter a response."),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -99,3 +113,20 @@ const clear_preview = (e) => {
|
||||
$("#assignment-preview a").attr("href", "");
|
||||
$("#assignment-preview .btn-close").addClass("hide");
|
||||
};
|
||||
|
||||
const make_text_editor = () => {
|
||||
this.text_editor = new frappe.ui.FieldGroup({
|
||||
fields: [
|
||||
{
|
||||
fieldname: "assignment_text",
|
||||
fieldtype: "Text Editor",
|
||||
default: $(".assignment-text-data").html(),
|
||||
},
|
||||
],
|
||||
body: $(".assignment-text").get(0),
|
||||
});
|
||||
this.text_editor.make();
|
||||
$(".assignment-text .form-section:last").removeClass("empty-section");
|
||||
$(".assignment-text .frappe-control").removeClass("hide-control");
|
||||
$(".assignment-text .form-column").addClass("p-0");
|
||||
};
|
||||
|
||||
@@ -14,7 +14,10 @@ def get_context(context):
|
||||
assignment = frappe.form_dict["assignment"]
|
||||
|
||||
context.assignment = frappe.db.get_value(
|
||||
"LMS Assignment", assignment, ["title", "name", "type", "question"], as_dict=1
|
||||
"LMS Assignment",
|
||||
assignment,
|
||||
["title", "name", "type", "question", "show_answer", "answer", "grade_assignment"],
|
||||
as_dict=1,
|
||||
)
|
||||
|
||||
if submission == "new-submission":
|
||||
@@ -34,6 +37,10 @@ def get_context(context):
|
||||
],
|
||||
as_dict=True,
|
||||
)
|
||||
|
||||
if not context.submission:
|
||||
raise frappe.PermissionError(_("Invalid Submission URL"))
|
||||
|
||||
if not context.is_moderator and frappe.session.user != context.submission.member:
|
||||
raise frappe.PermissionError(_("You don't have permission to access this page."))
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
{% block content %}
|
||||
<main class="common-page-style">
|
||||
<div class="container form-width">
|
||||
<div class="container">
|
||||
{{ Header() }}
|
||||
{% if assignments | length %}
|
||||
{{ AssignmentList(assignments) }}
|
||||
@@ -32,7 +32,33 @@
|
||||
|
||||
{% macro AssignmentList(assignments) %}
|
||||
<div class="mt-5">
|
||||
<ul class="list-unstyled">
|
||||
<div class="form-grid">
|
||||
<div class="grid-heading-row">
|
||||
<div class="grid-row">
|
||||
<div class="data-row row">
|
||||
<div class="col grid-static-col">
|
||||
{{ _("Title") }}
|
||||
</div>
|
||||
<div class="col grid-static-col col-xs-3">
|
||||
{{ _("Type") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% for assignment in assignments %}
|
||||
<div class="grid-row">
|
||||
<div class="data-row row">
|
||||
<a class="col grid-static-col button-links clickable" href="/assignments/{{ assignment.name }}">
|
||||
{{ assignment.title }}
|
||||
</a>
|
||||
<div class="col grid-static-col col-xs-3">
|
||||
{{ assignment.type }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<!-- <ul class="list-unstyled">
|
||||
{% for assignment in assignments %}
|
||||
<li class="list-row">
|
||||
<a class="clickable" href="/assignments/{{ assignment.name }}">
|
||||
@@ -45,7 +71,7 @@
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</ul> -->
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import frappe
|
||||
from lms.lms.utils import has_course_moderator_role
|
||||
|
||||
|
||||
def get_context(context):
|
||||
context.no_cache = 1
|
||||
|
||||
filters = {"owner": frappe.session.user}
|
||||
|
||||
if has_course_moderator_role():
|
||||
filters = {}
|
||||
|
||||
context.assignments = frappe.get_all(
|
||||
"LMS Assignment",
|
||||
{"owner": frappe.session.user},
|
||||
filters,
|
||||
["title", "name", "type", "question"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user