fix: program title rename and program overlay
This commit is contained in:
@@ -176,6 +176,7 @@
|
||||
import {
|
||||
Breadcrumbs,
|
||||
Button,
|
||||
call,
|
||||
createDocumentResource,
|
||||
Dialog,
|
||||
FormControl,
|
||||
@@ -305,25 +306,14 @@ const updateOrder = (e) => {
|
||||
}
|
||||
|
||||
const saveProgram = () => {
|
||||
program.setValue.submit(
|
||||
{
|
||||
title: program.doc.title,
|
||||
program_courses: program.doc.program_courses,
|
||||
program_members: program.doc.program_members,
|
||||
},
|
||||
{
|
||||
onSuccess(data) {
|
||||
router.push({
|
||||
name: 'ProgramsForm',
|
||||
params: { programName: data.name },
|
||||
})
|
||||
showToast(__('Success'), __('Program saved successfully'), 'check')
|
||||
},
|
||||
onError(err) {
|
||||
showToast('Error', err.messages?.[0] || err, 'x')
|
||||
},
|
||||
}
|
||||
)
|
||||
call('frappe.model.rename_doc.update_document_title', {
|
||||
doctype: 'LMS Program',
|
||||
docname: program.doc.name,
|
||||
name: program.doc.title,
|
||||
}).then((data) => {
|
||||
console.log(data)
|
||||
router.push({ name: 'ProgramForm', params: { programName: data } })
|
||||
})
|
||||
}
|
||||
|
||||
const courseColumns = computed(() => {
|
||||
|
||||
@@ -61,12 +61,23 @@
|
||||
v-if="program.courses?.length"
|
||||
class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-5 mt-5"
|
||||
>
|
||||
<CourseCard
|
||||
v-for="course in program.courses"
|
||||
:course="course"
|
||||
@click="enrollMember(program.name, course.name)"
|
||||
class="cursor-pointer"
|
||||
/>
|
||||
<div v-for="course in program.courses" class="relative group">
|
||||
<CourseCard
|
||||
:course="course"
|
||||
@click="enrollMember(program.name, course.name)"
|
||||
class="cursor-pointer"
|
||||
/>
|
||||
<div
|
||||
v-if="lockCourse(course)"
|
||||
class="absolute inset-0 bg-black-overlay-500 opacity-60 rounded-md"
|
||||
></div>
|
||||
<div
|
||||
v-if="lockCourse(course)"
|
||||
class="absolute inset-0 flex items-center justify-center"
|
||||
>
|
||||
<LockKeyhole class="size-10 text-white" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="text-sm italic text-gray-600 mt-4">
|
||||
{{ __('No courses in this program') }}
|
||||
@@ -119,7 +130,7 @@ import {
|
||||
FormControl,
|
||||
} from 'frappe-ui'
|
||||
import { computed, inject, onMounted, ref } from 'vue'
|
||||
import { BookOpen, Edit, Plus } from 'lucide-vue-next'
|
||||
import { BookOpen, Edit, Plus, LockKeyhole } from 'lucide-vue-next'
|
||||
import CourseCard from '@/components/CourseCard.vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { showToast, singularize } from '@/utils'
|
||||
@@ -189,6 +200,13 @@ const enrollMember = (program, course) => {
|
||||
})
|
||||
}
|
||||
|
||||
const lockCourse = (course) => {
|
||||
if (user.data?.is_moderator || user.data?.is_instructor) return false
|
||||
if (course.membership) return false
|
||||
if (course.eligible) return false
|
||||
return true
|
||||
}
|
||||
|
||||
const breadbrumbs = computed(() => [
|
||||
{
|
||||
label: 'Programs',
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.model.document import Document
|
||||
from frappe.model.rename_doc import update_document_title
|
||||
|
||||
|
||||
class LMSProgram(Document):
|
||||
def validate(self):
|
||||
self.validate_program_courses()
|
||||
self.validate_program_members()
|
||||
self.validate_title()
|
||||
|
||||
def validate_program_courses(self):
|
||||
courses = [row.course for row in self.program_courses]
|
||||
@@ -31,7 +31,3 @@ class LMSProgram(Document):
|
||||
frappe.bold(next(iter(duplicates)))
|
||||
)
|
||||
)
|
||||
|
||||
def validate_title(self):
|
||||
if self.has_value_changed("title"):
|
||||
frappe.rename_doc(self.doctype, self.name, self.title)
|
||||
|
||||
@@ -1771,8 +1771,18 @@ def get_programs():
|
||||
"LMS Program Course", {"parent": program.name}, ["course"], order_by="idx"
|
||||
)
|
||||
program.courses = []
|
||||
for course in program_courses:
|
||||
program.courses.append(get_course_details(course.course))
|
||||
previous_progress = 0
|
||||
for i, course in enumerate(program_courses):
|
||||
details = get_course_details(course.course)
|
||||
if i == 0:
|
||||
details.eligible = True
|
||||
elif previous_progress == 100:
|
||||
details.eligible = True
|
||||
else:
|
||||
details.eligible = False
|
||||
|
||||
previous_progress = details.membership.progress if details.membership else 0
|
||||
program.courses.append(details)
|
||||
|
||||
program.members = frappe.db.count("LMS Program Member", {"parent": program.name})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user