feat: chapter creation

This commit is contained in:
Jannat Patel
2024-03-04 22:10:51 +05:30
parent e863abe37c
commit 9ae96bd1fa
16 changed files with 4703 additions and 52 deletions

View File

@@ -0,0 +1,164 @@
<template>
<Dialog
v-model="show"
:options="{
title: __('Create a Batch'),
size: 'xl',
actions: [
{
label: __('Save'),
variant: 'solid',
onClick: (close) => createBatch(close),
},
],
}"
>
<template #body-content>
<div>
<FormControl v-model="batch.title" :label="__('Title')" class="mb-4" />
<FormControl
v-model="batch.published"
type="checkbox"
:label="__('Published')"
class="mb-4"
/>
<div class="grid grid-cols-2 gap-4">
<div>
<FormControl
v-model="batch.start_date"
:label="__('Start Date')"
type="date"
class="mb-4"
/>
<FormControl
v-model="batch.end_date"
:label="__('End Date')"
type="date"
class="mb-4"
/>
</div>
<div>
<FormControl
v-model="batch.start_time"
:label="__('Start Time')"
type="time"
class="mb-4"
/>
<FormControl
v-model="batch.end_time"
:label="__('End Time')"
type="time"
class="mb-4"
/>
</div>
</div>
<div class="grid grid-cols-2">
<div>
<FormControl
v-model="batch.medium"
:label="__('Medium')"
class="mb-4"
/>
<FormControl
v-model="batch.category"
:label="__('Category')"
class="mb-4"
/>
</div>
<div>
<FormControl
v-model="batch.seat_count"
:label="__('Seat Count')"
type="number"
class="mb-4"
/>
<FormControl
v-model="batch.evaluation_end_date"
:label="__('Evaluation End Date')"
type="date"
class="mb-4"
/>
</div>
</div>
<FormControl
v-model="batch.description"
:label="__('Description')"
type="textarea"
class="mb-4"
/>
<TextEditor
v-model="batch.batch_details"
:label="__('Batch Details')"
class="mb-4"
/>
<FormControl
v-model="batch_details.raw"
:label="__('Batch Details')"
type="textarea"
class="mb-4"
/>
<FileUploader
v-if="!image"
:fileTypes="['image/*']"
:validateFile="validateFile"
@success="
(file) => {
image = file
}
"
>
<template v-slot="{ file, progress, uploading, openFileSelector }">
<div class="mb-4">
<Button @click="openFileSelector" :loading="uploading">
{{ uploading ? `Uploading ${progress}%` : 'Upload an image' }}
</Button>
</div>
</template>
</FileUploader>
<div>
<FormControl
v-model="batch.paid_batch"
type="checkbox"
:label="__('Paid Batch')"
class="mb-4"
/>
<FormControl
v-model="batch.amount"
:label="__('Amount')"
type="number"
class="mb-4"
/>
<Link
doctype="Currency"
v-model="course.currency"
:filters="{ enabled: 1 }"
:label="__('Currency')"
/>
</div>
</div>
</template>
</Dialog>
</template>
<script setup>
import { Dialog, FormControl, TextEditor, FileUploader, Link } from 'frappe-ui'
const batch = reactive({
title: '',
published: false,
start_date: '',
end_date: '',
start_time: '',
end_time: '',
medium: '',
category: '',
seat_count: 0,
evaluation_end_date: '',
description: '',
batch_details: '',
batch_details_raw: '',
meta_image: '',
paid_batch: false,
amount: 0,
currency: '',
})
</script>

View File

@@ -0,0 +1,161 @@
<template>
<Dialog
v-model="show"
:options="{
title: __('Add Chapter'),
size: 'lg',
actions: [
{
label: chapterDetail ? __('Edit Chapter') : __('Add Chapter'),
variant: 'solid',
onClick: (close) =>
chapterDetail ? editChapter(close) : addChapter(close),
},
],
}"
>
<template #body-content>
<FormControl label="Title" v-model="chapter.title" class="mb-4" />
</template>
</Dialog>
</template>
<script setup>
import { Dialog, FormControl, createResource } from 'frappe-ui'
import { defineModel, reactive, watch, inject } from 'vue'
import { createToast, formatTime } from '@/utils/'
const show = defineModel()
const outline = defineModel('outline')
const props = defineProps({
course: {
type: String,
required: true,
},
chapterDetail: {
type: Object,
},
})
const chapter = reactive({
title: '',
})
const chapterResource = createResource({
url: 'frappe.client.insert',
makeParams(values) {
return {
doc: {
doctype: 'Course Chapter',
title: chapter.title,
description: chapter.description,
course: props.course,
},
}
},
})
const chapterEditResource = createResource({
url: 'frappe.client.set_value',
makeParams(values) {
return {
doctype: 'Course Chapter',
name: props.chapterDetail?.name,
fieldname: 'title',
value: chapter.title,
}
},
})
const chapterReference = createResource({
url: 'frappe.client.insert',
makeParams(values) {
return {
doc: {
doctype: 'Chapter Reference',
chapter: values.name,
parent: props.course,
parenttype: 'LMS Course',
parentfield: 'chapters',
},
}
},
})
const addChapter = (close) => {
chapterResource.submit(
{},
{
validate() {
if (!chapter.title) {
return 'Title is required'
}
},
onSuccess: (data) => {
chapterReference.submit(
{ name: data.name },
{
onSuccess(data) {
outline.value.reload()
createToast({
text: 'Chapter added successfully',
icon: 'check',
iconClasses: 'bg-green-600 text-white rounded-md p-px',
})
},
onError(err) {
showError(err)
},
}
)
close()
},
onError(err) {
showError(err)
},
}
)
}
const editChapter = (close) => {
chapterEditResource.submit(
{},
{
validate() {
if (!chapter.title) {
return 'Title is required'
}
},
onSuccess() {
outline.value.reload()
createToast({
text: 'Chapter updated successfully',
icon: 'check',
iconClasses: 'bg-green-600 text-white rounded-md p-px',
})
close()
},
onError(err) {
showError(err)
},
}
)
}
const showError = (err) => {
createToast({
title: 'Error',
text: err.messages?.[0] || err,
icon: 'x',
iconClasses: 'bg-red-600 text-white rounded-md p-px',
position: 'top-center',
timeout: 10,
})
}
watch(
() => props.chapterDetail,
(newChapter) => {
chapter.title = newChapter?.title
}
)
</script>

View File

@@ -6,7 +6,7 @@
size: 'xl',
actions: [
{
label: 'Submit',
label: __('Submit'),
variant: 'solid',
onClick: (close) => submitEvaluation(close),
},