Merge pull request #1231 from pateljannat/refactor-batch-list
refactor: fetch minimal information for batch cards
This commit is contained in:
@@ -2,31 +2,32 @@
|
|||||||
<div v-if="badge.doc">
|
<div v-if="badge.doc">
|
||||||
<div class="p-5 flex flex-col items-center mt-40">
|
<div class="p-5 flex flex-col items-center mt-40">
|
||||||
<div class="text-3xl font-semibold">
|
<div class="text-3xl font-semibold">
|
||||||
{{ badge.doc.title }}
|
{{ badge.doc.badge }}
|
||||||
</div>
|
</div>
|
||||||
<img :src="badge.doc.image" :alt="badge.doc.title" class="h-60 mt-2" />
|
<img
|
||||||
|
:src="badge.doc.badge_image"
|
||||||
|
:alt="badge.doc.badge"
|
||||||
|
class="h-60 mt-2"
|
||||||
|
/>
|
||||||
<div class="text-lg">
|
<div class="text-lg">
|
||||||
{{
|
{{
|
||||||
__('This badge has been awarded to {0} on {1}.').format(
|
__('This badge has been awarded to {0} on {1}.').format(
|
||||||
userName,
|
badge.doc.member_name,
|
||||||
dayjs(issuedOn.data?.issued_on).format('DD MMM YYYY')
|
dayjs(badge.doc.issued_on).format('DD MMM YYYY')
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-lg mt-2">
|
<div class="text-lg mt-2">
|
||||||
{{ badge.doc.description }}
|
{{ badge.doc.badge_description }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup>
|
<script setup>
|
||||||
import { createDocumentResource, createResource, Breadcrumbs } from 'frappe-ui'
|
import { createDocumentResource } from 'frappe-ui'
|
||||||
import { computed, inject } from 'vue'
|
import { computed, inject } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
const allUsers = inject('$allUsers')
|
|
||||||
const dayjs = inject('$dayjs')
|
const dayjs = inject('$dayjs')
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
badgeName: {
|
badgeName: {
|
||||||
@@ -40,35 +41,11 @@ const props = defineProps({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const badge = createDocumentResource({
|
const badge = createDocumentResource({
|
||||||
doctype: 'LMS Badge',
|
|
||||||
name: props.badgeName,
|
|
||||||
})
|
|
||||||
|
|
||||||
const userName = computed(() => {
|
|
||||||
const user = Object.values(allUsers.data).find(
|
|
||||||
(user) => user.name === props.email
|
|
||||||
)
|
|
||||||
return user ? user.full_name : props.email
|
|
||||||
})
|
|
||||||
|
|
||||||
const issuedOn = createResource({
|
|
||||||
url: 'frappe.client.get_value',
|
|
||||||
makeParams(values) {
|
|
||||||
return {
|
|
||||||
doctype: 'LMS Badge Assignment',
|
doctype: 'LMS Badge Assignment',
|
||||||
filters: {
|
filters: {
|
||||||
member: props.email,
|
|
||||||
badge: props.badgeName,
|
badge: props.badgeName,
|
||||||
|
member: props.email,
|
||||||
},
|
},
|
||||||
fieldname: 'issued_on',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onSuccess(data) {
|
|
||||||
if (!data.issued_on) {
|
|
||||||
router.push({ name: 'Courses' })
|
|
||||||
}
|
|
||||||
},
|
|
||||||
auto: true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const breadcrumbs = computed(() => {
|
const breadcrumbs = computed(() => {
|
||||||
@@ -77,11 +54,11 @@ const breadcrumbs = computed(() => {
|
|||||||
label: 'Badges',
|
label: 'Badges',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: badge.doc.title,
|
label: badge.doc.badge,
|
||||||
route: {
|
route: {
|
||||||
name: 'Badge',
|
name: 'Badge',
|
||||||
params: {
|
params: {
|
||||||
badge: badge.doc.name,
|
badge: badge.doc.badge,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -228,8 +228,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
isLoggedIn &&
|
isLoggedIn &&
|
||||||
(to.name == 'Lesson' ||
|
(to.name == 'Lesson' ||
|
||||||
to.name == 'Batch' ||
|
to.name == 'Batch' ||
|
||||||
to.name == 'Notifications' ||
|
to.name == 'Notifications')
|
||||||
to.name == 'Badge')
|
|
||||||
) {
|
) {
|
||||||
await allUsers.promise
|
await allUsers.promise
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
"engine": "InnoDB",
|
"engine": "InnoDB",
|
||||||
"field_order": [
|
"field_order": [
|
||||||
"member",
|
"member",
|
||||||
|
"member_name",
|
||||||
"issued_on",
|
"issued_on",
|
||||||
"column_break_ugix",
|
"column_break_ugix",
|
||||||
"badge",
|
"badge",
|
||||||
@@ -57,11 +58,18 @@
|
|||||||
"label": "Badge Description",
|
"label": "Badge Description",
|
||||||
"read_only": 1,
|
"read_only": 1,
|
||||||
"reqd": 1
|
"reqd": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fetch_from": "member.full_name",
|
||||||
|
"fieldname": "member_name",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"label": "Member Name",
|
||||||
|
"read_only": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-05-13 20:16:00.191517",
|
"modified": "2025-01-06 12:32:28.450028",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "LMS",
|
"module": "LMS",
|
||||||
"name": "LMS Badge Assignment",
|
"name": "LMS Badge Assignment",
|
||||||
|
|||||||
@@ -1030,6 +1030,7 @@ def get_course_details(course):
|
|||||||
course_details.tags = course_details.tags.split(",") if course_details.tags else []
|
course_details.tags = course_details.tags.split(",") if course_details.tags else []
|
||||||
|
|
||||||
course_details.instructors = get_instructors(course_details.name)
|
course_details.instructors = get_instructors(course_details.name)
|
||||||
|
# course_details.is_instructor = is_instructor(course_details.name)
|
||||||
if course_details.paid_course:
|
if course_details.paid_course:
|
||||||
"""course_details.course_price, course_details.currency = check_multicurrency(
|
"""course_details.course_price, course_details.currency = check_multicurrency(
|
||||||
course_details.course_price, course_details.currency, None, course_details.amount_usd
|
course_details.course_price, course_details.currency, None, course_details.amount_usd
|
||||||
@@ -1048,7 +1049,6 @@ def get_course_details(course):
|
|||||||
["name", "course", "current_lesson", "progress", "member"],
|
["name", "course", "current_lesson", "progress", "member"],
|
||||||
as_dict=1,
|
as_dict=1,
|
||||||
)
|
)
|
||||||
course_details.is_instructor = is_instructor(course_details.name)
|
|
||||||
|
|
||||||
if course_details.membership and course_details.membership.current_lesson:
|
if course_details.membership and course_details.membership.current_lesson:
|
||||||
course_details.current_lesson = get_lesson_index(
|
course_details.current_lesson = get_lesson_index(
|
||||||
@@ -1219,12 +1219,49 @@ def get_batches():
|
|||||||
batch_list = frappe.get_all("LMS Batch", filters)
|
batch_list = frappe.get_all("LMS Batch", filters)
|
||||||
|
|
||||||
for batch in batch_list:
|
for batch in batch_list:
|
||||||
batches.append(get_batch_details(batch.name))
|
batches.append(get_batch_card_details(batch.name))
|
||||||
|
|
||||||
batches = categorize_batches(batches)
|
batches = categorize_batches(batches)
|
||||||
return batches
|
return batches
|
||||||
|
|
||||||
|
|
||||||
|
def get_batch_card_details(batchname):
|
||||||
|
batch = frappe.db.get_value(
|
||||||
|
"LMS Batch",
|
||||||
|
batchname,
|
||||||
|
[
|
||||||
|
"name",
|
||||||
|
"title",
|
||||||
|
"description",
|
||||||
|
"seat_count",
|
||||||
|
"paid_batch",
|
||||||
|
"amount",
|
||||||
|
"amount_usd",
|
||||||
|
"currency",
|
||||||
|
"start_date",
|
||||||
|
"start_time",
|
||||||
|
"end_time",
|
||||||
|
"timezone",
|
||||||
|
"published",
|
||||||
|
],
|
||||||
|
as_dict=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
batch.instructors = get_instructors(batchname)
|
||||||
|
students_count = frappe.db.count("Batch Student", {"parent": batchname})
|
||||||
|
|
||||||
|
if batch.seat_count:
|
||||||
|
batch.seats_left = batch.seat_count - students_count
|
||||||
|
|
||||||
|
if batch.paid_batch and batch.start_date >= getdate():
|
||||||
|
batch.amount, batch.currency = check_multicurrency(
|
||||||
|
batch.amount, batch.currency, None, batch.amount_usd
|
||||||
|
)
|
||||||
|
batch.price = fmt_money(batch.amount, 0, batch.currency)
|
||||||
|
|
||||||
|
return batch
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_batch_details(batch):
|
def get_batch_details(batch):
|
||||||
batch_details = frappe.db.get_value(
|
batch_details = frappe.db.get_value(
|
||||||
|
|||||||
Reference in New Issue
Block a user