feat: profile settings for roles
This commit is contained in:
@@ -116,7 +116,7 @@ const profile = createResource({
|
||||
|
||||
const setActiveTab = () => {
|
||||
let fragments = route.path.split('/')
|
||||
let sections = ['certificates', 'settings']
|
||||
let sections = ['certificates', 'settings', 'evaluator']
|
||||
sections.forEach((section) => {
|
||||
if (fragments.includes(section)) {
|
||||
activeTab.value = convertToTitleCase(section)
|
||||
@@ -131,6 +131,7 @@ watchEffect(() => {
|
||||
About: { name: 'ProfileAbout' },
|
||||
Certificates: { name: 'ProfileCertificates' },
|
||||
Settings: { name: 'ProfileSettings' },
|
||||
Evaluato: { name: 'ProfileEvaluator' },
|
||||
}[activeTab.value]
|
||||
router.push(route)
|
||||
}
|
||||
@@ -147,6 +148,8 @@ const isSessionUser = () => {
|
||||
const getTabButtons = () => {
|
||||
let buttons = [{ label: 'About' }, { label: 'Certificates' }]
|
||||
if ($user.data?.is_moderator) buttons.push({ label: 'Settings' })
|
||||
if (isSessionUser() && $user.data?.is_evaluator)
|
||||
buttons.push({ label: 'Evaluation Slots' })
|
||||
|
||||
return buttons
|
||||
}
|
||||
|
||||
2
frontend/src/pages/ProfileEvaluator.vue
Normal file
2
frontend/src/pages/ProfileEvaluator.vue
Normal file
@@ -0,0 +1,2 @@
|
||||
<template>Evaluator</template>
|
||||
<script setup></script>
|
||||
@@ -1 +1,96 @@
|
||||
<template></template>
|
||||
<template>
|
||||
<div class="mt-7">
|
||||
<h2 class="mb-3 text-lg font-semibold text-gray-900">
|
||||
{{ __('Settings') }}
|
||||
</h2>
|
||||
<div class="flex justify-between w-3/4 mt-5">
|
||||
<FormControl
|
||||
:label="__('Moderator')"
|
||||
v-model="moderator"
|
||||
type="checkbox"
|
||||
@change.stop="changeRole('moderator')"
|
||||
/>
|
||||
<FormControl
|
||||
:label="__('Course Creator')"
|
||||
v-model="course_creator"
|
||||
type="checkbox"
|
||||
@change.stop="changeRole('course_creator')"
|
||||
/>
|
||||
<FormControl
|
||||
:label="__('Evaluator')"
|
||||
v-model="batch_evaluator"
|
||||
type="checkbox"
|
||||
@change.stop="changeRole('batch_evaluator')"
|
||||
/>
|
||||
<FormControl
|
||||
:label="__('Student')"
|
||||
v-model="lms_student"
|
||||
type="checkbox"
|
||||
@change.stop="changeRole('lms_student')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { FormControl, createResource } from 'frappe-ui'
|
||||
import { ref } from 'vue'
|
||||
import { showToast, convertToTitleCase } from '@/utils'
|
||||
|
||||
const moderator = ref(false)
|
||||
const course_creator = ref(false)
|
||||
const batch_evaluator = ref(false)
|
||||
const lms_student = ref(false)
|
||||
|
||||
const props = defineProps({
|
||||
profile: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
|
||||
const roles = createResource({
|
||||
url: 'lms.lms.utils.get_roles',
|
||||
makeParams(values) {
|
||||
return {
|
||||
name: props.profile.data?.name,
|
||||
}
|
||||
},
|
||||
auto: true,
|
||||
onSuccess(data) {
|
||||
let roles = [
|
||||
'moderator',
|
||||
'course_creator',
|
||||
'batch_evaluator',
|
||||
'lms_student',
|
||||
]
|
||||
for (let role of roles) {
|
||||
if (data[role]) eval(role).value = true
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const updateRole = createResource({
|
||||
url: 'lms.overrides.user.save_role',
|
||||
makeParams(values) {
|
||||
return {
|
||||
user: props.profile.data?.name,
|
||||
role: values.role,
|
||||
value: values.value,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const changeRole = (role) => {
|
||||
updateRole.submit(
|
||||
{
|
||||
role: convertToTitleCase(role.split('_').join(' ')),
|
||||
value: eval(role).value,
|
||||
},
|
||||
{
|
||||
onSuccess(data) {
|
||||
showToast('Success', 'Role updated successfully', 'check')
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -77,6 +77,11 @@ const routes = [
|
||||
path: 'settings',
|
||||
component: () => import('@/pages/ProfileSettings.vue'),
|
||||
},
|
||||
{
|
||||
name: 'ProfileEvaluator',
|
||||
path: 'evaluator',
|
||||
component: () => import('@/pages/ProfileEvaluator.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user