feat: access for course creation

This commit is contained in:
Jannat Patel
2022-08-22 12:58:54 +05:30
parent 5aba690318
commit 668130d443
17 changed files with 123 additions and 92 deletions
+2
View File
@@ -185,7 +185,9 @@
<div class="mt-4">
<button class="btn btn-primary btn-sm btn-lesson pull-right ml-2"> {{ _("Save") }} </button>
{% if lesson.name %}
<button class="btn btn-secondary btn-sm pull-right btn-back ml-2"> {{ _("Back to Lesson") }} </button>
{% endif %}
<a class="btn btn-secondary btn-sm pull-right" href="/quizzes"> {{ _("Create a Quiz") }} </a>
<div class="attachments-parent">
+8 -5
View File
@@ -1,6 +1,6 @@
frappe.ready(() => {
localStorage.removeItem($("#quiz-title").text());
localStorage.removeItem($("#quiz-title").data("name"));
fetch_assignments();
@@ -200,8 +200,9 @@ const move_to_next_lesson = (status, e) => {
const quiz_summary = (e=undefined) => {
e && e.preventDefault();
let quiz_name = $("#quiz-title").text();
let quiz_name = $("#quiz-title").data("name");
let total_questions = $(".question").length;
frappe.call({
method: "lms.lms.doctype.lms_quiz.lms_quiz.quiz_summary",
args: {
@@ -230,7 +231,6 @@ const check_answer = (e=undefined) => {
e && e.preventDefault();
clearInterval(self.timer);
$(".timer").addClass("hide");
let quiz_name = $("#quiz-title").text();
let total_questions = $(".question").length;
let current_index = $(".active-question").attr("data-qt-index");
@@ -249,7 +249,7 @@ const check_answer = (e=undefined) => {
$("#next").removeClass("hide");
}
let [answer, is_correct] = parse_options();
add_to_local_storage(quiz_name, current_index, answer, is_correct);
add_to_local_storage(current_index, answer, is_correct);
};
@@ -285,13 +285,16 @@ const add_icon = (element, icon) => {
};
const add_to_local_storage = (quiz_name, current_index, answer, is_correct) => {
const add_to_local_storage = (current_index, answer, is_correct) => {
let quiz_name = $("#quiz-title").data("name")
let quiz_stored = JSON.parse(localStorage.getItem(quiz_name));
let quiz_obj = {
"question_index": current_index,
"answer": answer.join(),
"is_correct": is_correct
}
quiz_stored ? quiz_stored.push(quiz_obj) : quiz_stored = [quiz_obj]
localStorage.setItem(quiz_name, JSON.stringify(quiz_stored))
};
+11 -5
View File
@@ -24,16 +24,17 @@ def get_context(context):
context.lesson = get_current_lesson_details(lesson_number, context)
if not context.lesson:
context.lessom = frappe._dict()
context.lesson = frappe._dict()
if frappe.form_dict.get("edit"):
if not is_instructor(context.course.name):
redirect_to_courses_list()
context.lesson.edit_mode = True
else:
neighbours = get_neighbours(lesson_number, context.lessons)
context.next_url = get_url(neighbours["next"], context.course)
context.prev_url = get_url(neighbours["prev"], context.course)
neighbours = get_neighbours(lesson_number, context.lessons)
context.next_url = get_url(neighbours["next"], context.course)
context.prev_url = get_url(neighbours["prev"], context.course)
meta_info = context.lesson.title + " - " + context.course.title if context.lesson.title else "New Lesson"
context.metatags = {
"title": meta_info,
@@ -52,8 +53,13 @@ def get_context(context):
def get_current_lesson_details(lesson_number, context):
details_list = list(filter(lambda x: cstr(x.number) == lesson_number, context.lessons))
if not len(details_list):
redirect_to_lesson(context.course)
if frappe.form_dict.get("edit"):
return None
else:
redirect_to_lesson(context.course)
lesson_info = details_list[0]
lesson_info.body = lesson_info.body.replace("\"", "'")
return lesson_info