fix: ui, preview, progress, batches

This commit is contained in:
pateljannat
2021-06-14 18:45:46 +05:30
parent f5f3c808d4
commit 7840512a13
31 changed files with 275 additions and 425 deletions

View File

@@ -25,9 +25,16 @@
{{ widgets.BatchTabs(course=course, batch=batch) }}
<div class="lesson-page">
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-name="{{ lesson.name }}" data-batch="{{ batch.name }}">{{ lesson.title }}</h2>
<h2 class="title {% if course.is_mentor(frappe.session.user) %} is_mentor {% endif %}" data-name="{{ lesson.name }}" {% if batch %} data-batch="{{ batch.name }}" {% endif %}>{{ lesson.title }}</h2>
{% if batch or lesson.include_in_preview %}
{{ lesson.render_html() }}
{% else %}
<div class="no-preview-message">
<span>This lesson is not available for Preview. Please join a batch to access the complete course.</span>
<a href="/courses/{{ course.name }}">Checkout Upcoming Batches</a>
</div>
{% endif %}
{{ pagination(prev_chap, prev_url, next_chap, next_url) }}
</div>
@@ -53,18 +60,6 @@
{%- block script %}
{{ super() }}
<script type="text/javascript">
$(function() {
var batch_name = "{{ batch.name }}";
var lesson_name = "{{ lesson.name }}";
frappe.call("community.lms.api.save_current_lesson", {
"batch_name": batch_name,
"lesson_name": lesson_name
})
})
</script>
{% for ext in page_extensions %}
{{ ext.render_footer() }}
{% endfor %}

View File

@@ -1,5 +1,5 @@
frappe.ready(() => {
if (!$(".title").hasClass("is_mentor")) {
if ($(".title").attr("data-batch") && !$(".title").hasClass("is_mentor")) {
frappe.call({
method: "community.lms.doctype.lesson.lesson.save_progress",
args: {
@@ -8,4 +8,10 @@ frappe.ready(() => {
}
})
}
if ($(".title").attr("data-batch")) {
frappe.call("community.lms.api.save_current_lesson", {
"batch_name": $(".title").attr("data-batch"),
"lesson_name": $(".title").attr("data-name")
})
}
})

View File

@@ -3,6 +3,8 @@ import frappe
from . import utils
from frappe.utils import cstr
from community.www import batch
def get_context(context):
utils.get_common_context(context)
@@ -11,11 +13,12 @@ def get_context(context):
lesson_number = f"{chapter_index}.{lesson_index}"
course_name = context.course.name
print(chapter_index, lesson_index)
if not chapter_index or not lesson_index:
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
print(index_)
frappe.local.flags.redirect_location = context.batch.get_learn_url(index_)
if context.batch:
index_ = get_lesson_index(context.course, context.batch, frappe.session.user) or "1.1"
else:
index_ = "1.1"
frappe.local.flags.redirect_location = context.course.get_learn_url(index_)
raise frappe.Redirect
context.lesson = context.course.get_lesson(chapter_index, lesson_index)
@@ -27,8 +30,8 @@ def get_context(context):
next_ = outline.get_next(lesson_number)
context.prev_chap = get_chapter_title(course_name, prev_)
context.next_chap = get_chapter_title(course_name, next_)
context.next_url = context.batch.get_learn_url(next_)
context.prev_url = context.batch.get_learn_url(prev_)
context.next_url = context.course.get_learn_url(next_)
context.prev_url = context.course.get_learn_url(prev_)
context.page_extensions = get_page_extensions()

View File

@@ -1,5 +1,5 @@
import frappe
from community.lms.models import Course, Membership
from community.lms.models import Course
def get_common_context(context):
context.no_cache = 1
@@ -10,16 +10,16 @@ def get_common_context(context):
if not course:
context.template = "www/404.html"
return
batch_name = Membership.get_user_batch(course_name)
batch_name = course.get_current_batch()
batch = course.get_batch(batch_name)
""" if not batch or not batch.is_member(frappe.session.user):
frappe.local.flags.redirect_location = "/courses/" + course_name
raise frappe.Redirect """
context.batch = batch
if batch_name:
context.members = batch.get_mentors() + batch.get_students()
context.member_count = len(context.members)
context.course = course
context.batch = batch
context.members = batch.get_mentors() + batch.get_students()
context.member_count = len(context.members)
context.livecode_url = get_livecode_url()
def get_livecode_url():