From 8f504a8043a4499313cf171c5f7318e7e0bf2aa7 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 28 Feb 2024 23:42:17 +0530 Subject: [PATCH] fix: course creation form validations --- .../components/Modals/JobApplicationModal.vue | 14 +- frontend/src/components/UserDropdown.vue | 15 +- frontend/src/pages/CreateCourse.vue | 130 +++++++++++++++--- frontend/src/utils/index.js | 23 ++++ lms/lms/doctype/lms_course/lms_course.json | 8 +- 5 files changed, 139 insertions(+), 51 deletions(-) diff --git a/frontend/src/components/Modals/JobApplicationModal.vue b/frontend/src/components/Modals/JobApplicationModal.vue index 035e8d040..decaf5e79 100644 --- a/frontend/src/components/Modals/JobApplicationModal.vue +++ b/frontend/src/components/Modals/JobApplicationModal.vue @@ -55,7 +55,7 @@ {{ resume.file_name }} - {{ getFileSize() }} + {{ getFileSize(resume.file_size) }} @@ -67,7 +67,7 @@ import { Dialog, FileUploader, Button, createResource } from 'frappe-ui' import { FileText } from 'lucide-vue-next' import { ref, inject, defineModel } from 'vue' -import { createToast } from '@/utils/' +import { createToast, getFileSize } from '@/utils/' const resume = ref(null) const show = defineModel() @@ -87,16 +87,6 @@ const validateFile = (file) => { } } -const getFileSize = () => { - let value = parseInt(resume.value.file_size) - if (value > 1048576) { - return (value / 1048576).toFixed(2) + 'M' - } else if (value > 1024) { - return (value / 1024).toFixed(2) + 'K' - } - return value -} - const jobApplication = createResource({ url: 'frappe.client.insert', makeParams(values) { diff --git a/frontend/src/components/UserDropdown.vue b/frontend/src/components/UserDropdown.vue index d71ea7da5..af3759b8c 100644 --- a/frontend/src/components/UserDropdown.vue +++ b/frontend/src/components/UserDropdown.vue @@ -48,6 +48,7 @@ import { sessionStore } from '@/stores/session' import { Dropdown } from 'frappe-ui' import { ChevronDown, LogIn, LogOut, User } from 'lucide-vue-next' import { useRouter } from 'vue-router' +import { convertToTitleCase } from '../utils' const router = useRouter() const props = defineProps({ @@ -94,18 +95,4 @@ const userDropdownOptions = [ }, }, ] - -function convertToTitleCase(str) { - if (!str) { - return '' - } - - return str - .toLowerCase() - .split(' ') - .map(function (word) { - return word.charAt(0).toUpperCase().concat(word.substr(1)) - }) - .join(' ') -} diff --git a/frontend/src/pages/CreateCourse.vue b/frontend/src/pages/CreateCourse.vue index 671224e5b..9d34b7261 100644 --- a/frontend/src/pages/CreateCourse.vue +++ b/frontend/src/pages/CreateCourse.vue @@ -25,11 +25,15 @@
- - +
@@ -37,35 +41,81 @@
- - + + + +
+
+ +
+
+ + {{ course.image }} + + + {{ getFileSize(course.image) }} + +
+
+
- - +
- - + +
+ + @@ -76,14 +126,16 @@ diff --git a/frontend/src/utils/index.js b/frontend/src/utils/index.js index 6632e712a..35fccadd1 100644 --- a/frontend/src/utils/index.js +++ b/frontend/src/utils/index.js @@ -41,6 +41,29 @@ export function formatNumberIntoCurrency(number, currency) { return '' } +export function convertToTitleCase(str) { + if (!str) { + return '' + } + + return str + .toLowerCase() + .split(' ') + .map(function (word) { + return word.charAt(0).toUpperCase().concat(word.substr(1)) + }) + .join(' ') +} +export function getFileSize(file_size) { + let value = parseInt(file_size) + if (value > 1048576) { + return (value / 1048576).toFixed(2) + 'M' + } else if (value > 1024) { + return (value / 1024).toFixed(2) + 'K' + } + return value +} + export function getTimezones() { return [ 'Pacific/Midway', diff --git a/lms/lms/doctype/lms_course/lms_course.json b/lms/lms/doctype/lms_course/lms_course.json index f26e382da..58f2275ac 100644 --- a/lms/lms/doctype/lms_course/lms_course.json +++ b/lms/lms/doctype/lms_course/lms_course.json @@ -75,7 +75,8 @@ { "fieldname": "video_link", "fieldtype": "Data", - "label": "Video Embed Link" + "label": "Video Embed Link", + "reqd": 1 }, { "fieldname": "short_introduction", @@ -92,7 +93,8 @@ { "fieldname": "image", "fieldtype": "Attach Image", - "label": "Preview Image" + "label": "Preview Image", + "reqd": 1 }, { "fieldname": "tags", @@ -266,7 +268,7 @@ } ], "make_attachments_public": 1, - "modified": "2023-12-21 12:27:32.559901", + "modified": "2024-02-28 11:20:47.700649", "modified_by": "Administrator", "module": "LMS", "name": "LMS Course",