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():

View File

@@ -88,7 +88,7 @@
{% macro BatchSectionForStudents(course, upcoming_batches) %}
{% if upcoming_batches %}
<div class="mt-5">
<h3>Upcoming Batches</h3>
<h3 class="upcoming">Upcoming Batches</h3>
<div class="row">
{% for batch in upcoming_batches %}
<div class="col-lg-4 col-md-6">

View File

@@ -1,72 +1,92 @@
frappe.ready(() => {
if (frappe.session.user != "Guest") {
frappe.call({
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
'args': {
course: decodeURIComponent($("#course-title").attr("data-course")),
},
'callback': (data) => {
if (data.message > 0) {
$("#mentor-request").addClass("hide");
$("#already-applied").removeClass("hide")
}
}
})
}
if (frappe.session.user != "Guest") {
frappe.call({
'method': 'community.lms.doctype.lms_mentor_request.lms_mentor_request.has_requested',
'args': {
course: decodeURIComponent($("#course-title").attr("data-course")),
},
'callback': (data) => {
if (data.message > 0) {
$("#mentor-request").addClass("hide");
$("#already-applied").removeClass("hide")
}
}
})
}
$("#apply-now").click((e) => {
$("#apply-now").click((e) => {
e.preventDefault();
if (frappe.session.user == "Guest") {
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
return;
}
frappe.call({
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.create_request",
"args": {
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
},
"callback": (data) => {
if (data.message == "OK") {
$("#mentor-request").addClass("hide");
$("#already-applied").removeClass("hide")
}
}
})
})
if (frappe.session.user == "Guest") {
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
return;
}
frappe.call({
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.create_request",
"args": {
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
},
"callback": (data) => {
if (data.message == "OK") {
$("#mentor-request").addClass("hide");
$("#already-applied").removeClass("hide")
}
}
})
})
$("#cancel-request").click((e) => {
$("#cancel-request").click((e) => {
e.preventDefault()
frappe.call({
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
"args": {
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
},
"callback": (data) => {
if (data.message == "OK") {
$("#mentor-request").removeClass("hide");
$("#already-applied").addClass("hide")
}
}
})
})
frappe.call({
"method": "community.lms.doctype.lms_mentor_request.lms_mentor_request.cancel_request",
"args": {
"course": decodeURIComponent($(e.currentTarget).attr("data-course"))
},
"callback": (data) => {
if (data.message == "OK") {
$("#mentor-request").removeClass("hide");
$("#already-applied").addClass("hide")
}
}
})
})
$(".join-batch").click((e) => {
e.preventDefault()
if (frappe.session.user == "Guest") {
window.location.href = `/login?redirect-to=/courses/${$(e.currentTarget).attr("data-course")}`;
return;
}
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
frappe.call({
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
"args": {
"batch": batch
},
"callback": (data) => {
if (data.message == "OK") {
frappe.msgprint(__("You are now a student of this course."))
}
}
})
})
$(".join-batch").click((e) => {
e.preventDefault();
var course = $(e.currentTarget).attr("data-course")
if (frappe.session.user == "Guest") {
window.location.href = `/login?redirect-to=/courses/${course}`;
return;
}
batch = decodeURIComponent($(e.currentTarget).attr("data-batch"))
frappe.call({
"method": "community.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
"args": {
"batch": batch
},
"callback": (data) => {
if (data.message == "OK") {
frappe.msgprint(__("You are now a student of this course."));
setTimeout(function () {
window.location.href = `/courses/${course}/home`;
}, 2000);
}
}
})
})
$(".manage-batch").click((e) => {
e.preventDefault();
var batch = decodeURIComponent($(e.currentTarget).attr("data-batch"));
var course = decodeURIComponent($(e.currentTarget).attr("data-course"));
frappe.call({
method: "community.lms.doctype.lms_batch_membership.lms_batch_membership.update_current_membership",
args: {
batch: batch,
course: course
},
callback: (data) => {
window.location.href = `/courses/${course}/home`;
}
})
})
})

View File

@@ -19,6 +19,6 @@ def get_context(context):
batch = course.get_student_batch(frappe.session.user)
if batch:
frappe.local.flags.redirect_location = f"/courses/{course.name}/{batch.name}/learn"
frappe.local.flags.redirect_location = f"/courses/{course.name}/learn"
raise frappe.Redirect

View File

@@ -29,7 +29,7 @@
{% macro course_card(course) %}
<div class="col-sm-4 mb-4 text-left">
<a class="card-links" style="color: inherit;" href="/courses/{{course.name}}">
<a class="anchor_style" style="color: inherit;" href="/courses/{{course.name}}">
<div class="card h-100" style="box-shadow: 0px 5px 10px rgb(0 0 0 / 10%);">
<div class='card-body'>
<h5 class='card-title'>{{ course.title }}</h5>