Merge pull request #1996 from pateljannat/issues-170

fix: misc issues
This commit is contained in:
Jannat Patel
2026-01-16 11:34:29 +05:30
committed by GitHub
7 changed files with 296 additions and 102 deletions

View File

@@ -3,55 +3,56 @@
<div class="text-xs text-ink-gray-5 mb-2"> <div class="text-xs text-ink-gray-5 mb-2">
{{ label }} {{ label }}
</div> </div>
<div class="overflow-x-auto overflow-y-visible border rounded-md"> <div class="overflow-visible border rounded-md">
<div <div class="overflow-x-auto">
class="grid items-center space-x-4 p-2 border-b"
:style="{ gridTemplateColumns: getGridTemplateColumns() }"
>
<div <div
v-for="(column, index) in columns" class="grid items-center space-x-4 p-2 border-b"
:key="index" :style="{ gridTemplateColumns: getGridTemplateColumns() }"
class="text-sm text-ink-gray-5"
> >
{{ column }} <div
</div> v-for="(column, index) in columns"
<div></div> :key="index"
</div> class="text-sm text-ink-gray-5"
<div
v-for="(row, rowIndex) in rows"
:key="rowIndex"
class="grid items-center space-x-4 p-2"
:style="{ gridTemplateColumns: getGridTemplateColumns() }"
>
<template v-for="key in Object.keys(row)" :key="key">
<input
v-if="showKey(key)"
v-model="row[key]"
class="py-1.5 px-2 border-none focus:ring-0 focus:border focus:border-gray-300 focus:bg-surface-gray-2 rounded-md text-sm focus:outline-none"
/>
</template>
<div class="relative" ref="menuRef">
<Button
variant="ghost"
@click="(event: MouseEvent) => toggleMenu(rowIndex, event)"
> >
<template #icon> {{ column }}
<Ellipsis </div>
class="size-4 text-ink-gray-7 stroke-1.5 cursor-pointer" <div></div>
/> </div>
</template> <div
</Button> v-for="(row, rowIndex) in rows"
:key="rowIndex"
class="grid items-center space-x-4 p-2"
:style="{ gridTemplateColumns: getGridTemplateColumns() }"
>
<template v-for="key in Object.keys(row)" :key="key">
<input
v-if="showKey(key)"
v-model="row[key]"
class="py-1.5 px-2 border-none focus:ring-0 focus:border focus:border-gray-300 focus:bg-surface-gray-2 rounded-md text-sm focus:outline-none"
/>
</template>
<div class="relative">
<Button
variant="ghost"
@click="(event: MouseEvent) => toggleMenu(rowIndex, event)"
>
<template #icon>
<Ellipsis
class="size-4 text-ink-gray-7 stroke-1.5 cursor-pointer"
/>
</template>
</Button>
<Teleport to="body">
<div <div
v-if="menuOpenIndex === rowIndex" v-if="menuOpenIndex === rowIndex"
:style="{ ref="menuRef"
position: 'absolute', class="absolute right-0 w-32 z-50 bg-surface-white border border-outline-gray-1 rounded-md shadow-sm"
top: menuTopPosition, :class="
left: menuLeftPosition, rowIndex == (rows?.length ?? 0) - 1
}" ? 'bottom-full mb-1'
class="top-5 mt-1 w-32 bg-surface-white border border-outline-gray-1 rounded-md shadow-sm" : 'top-full mt-1'
"
> >
<button <button
@click="deleteRow(rowIndex)" @click="deleteRow(rowIndex)"
@@ -63,7 +64,7 @@
</span> </span>
</button> </button>
</div> </div>
</Teleport> </div>
</div> </div>
</div> </div>
</div> </div>
@@ -154,10 +155,7 @@ const getGridTemplateColumns = () => {
} }
const toggleMenu = (index: number, event: MouseEvent) => { const toggleMenu = (index: number, event: MouseEvent) => {
const rect = (event.target as HTMLElement).getBoundingClientRect() menuOpenIndex.value = menuOpenIndex.value === index ? null : index
menuOpenIndex.value = index
menuTopPosition.value = rect.bottom + 'px'
menuLeftPosition.value = rect.right + 'px'
} }
onClickOutside(menuRef, () => { onClickOutside(menuRef, () => {

View File

@@ -1,12 +1,17 @@
<template> <template>
<Dialog v-model="show" :options="{ size: '5xl' }"> <Dialog v-model="show" :options="{ size: '4xl' }">
<template #body-title> <template #body-title>
<div class="text-xl font-semibold text-ink-gray-9"> <div class="flex items-center space-x-2">
{{ <div class="text-xl font-semibold text-ink-gray-9">
props.exerciseID === 'new' {{
? __('Create Programming Exercise') props.exerciseID === 'new'
: __('Edit Programming Exercise') ? __('Create Programming Exercise')
}} : __('Edit Programming Exercise')
}}
</div>
<Badge v-if="isDirty" theme="orange">
{{ __('Not Saved') }}
</Badge>
</div> </div>
</template> </template>
<template #body-content> <template #body-content>
@@ -59,7 +64,6 @@
@click="deleteExercise(close)" @click="deleteExercise(close)"
variant="outline" variant="outline"
theme="red" theme="red"
class="invisible group-hover:visible"
> >
<template #prefix> <template #prefix>
<Trash2 class="size-4 stroke-1.5" /> <Trash2 class="size-4 stroke-1.5" />
@@ -108,6 +112,7 @@
import { computed, ref, watch } from 'vue' import { computed, ref, watch } from 'vue'
import { escapeHTML } from '@/utils' import { escapeHTML } from '@/utils'
import { import {
Badge,
Button, Button,
createListResource, createListResource,
Dialog, Dialog,
@@ -125,6 +130,8 @@ import ChildTable from '@/components/Controls/ChildTable.vue'
const show = defineModel() const show = defineModel()
const exercises = defineModel<ProgrammingExercises>('exercises') const exercises = defineModel<ProgrammingExercises>('exercises')
const isDirty = ref(false)
const originalTestCaseCount = ref(0)
const exercise = ref<ProgrammingExercise>({ const exercise = ref<ProgrammingExercise>({
title: '', title: '',
@@ -172,6 +179,7 @@ const setExerciseData = () => {
test_cases: [], test_cases: [],
} }
} }
isDirty.value = false
} }
const testCases = createListResource({ const testCases = createListResource({
@@ -180,6 +188,14 @@ const testCases = createListResource({
cache: ['testCases', props.exerciseID], cache: ['testCases', props.exerciseID],
parent: 'LMS Programming Exercise', parent: 'LMS Programming Exercise',
orderBy: 'idx', orderBy: 'idx',
onSuccess(data: TestCase[]) {
isDirty.value = false
originalTestCaseCount.value = data.length
},
onError(err: any) {
toast.error(__(err.messages?.[0] || err))
console.error('Error loading testCases:', err)
},
}) })
const fetchTestCases = () => { const fetchTestCases = () => {
@@ -191,13 +207,28 @@ const fetchTestCases = () => {
}, },
}) })
testCases.reload() testCases.reload()
originalTestCaseCount.value = testCases.data.length
} }
const validateTitle = () => { const validateTitle = () => {
exercise.value.title = escapeHTML(exercise.value.title.trim()) exercise.value.title = escapeHTML(exercise.value.title.trim())
} }
const saveExercise = (close: () => void) => { watch(
exercise,
() => {
isDirty.value = true
},
{ deep: true }
)
watch(testCases, () => {
if (testCases.data.length !== originalTestCaseCount.value) {
isDirty.value = true
}
})
const updateTestCasesInExercise = () => {
exercise.value.test_cases = testCases.data.map( exercise.value.test_cases = testCases.data.map(
(tc: TestCase, index: number) => ({ (tc: TestCase, index: number) => ({
input: tc.input, input: tc.input,
@@ -205,7 +236,11 @@ const saveExercise = (close: () => void) => {
idx: index + 1, idx: index + 1,
}) })
) )
}
const saveExercise = (close: () => void) => {
validateTitle() validateTitle()
updateTestCasesInExercise()
if (props.exerciseID == 'new') createNewExercise(close) if (props.exerciseID == 'new') createNewExercise(close)
else updateExercise(close) else updateExercise(close)
} }
@@ -218,6 +253,7 @@ const createNewExercise = (close: () => void) => {
{ {
onSuccess() { onSuccess() {
close() close()
isDirty.value = false
exercises.value?.reload() exercises.value?.reload()
toast.success(__('Programming Exercise created successfully')) toast.success(__('Programming Exercise created successfully'))
}, },
@@ -237,6 +273,7 @@ const updateExercise = (close: () => void) => {
{ {
onSuccess() { onSuccess() {
close() close()
isDirty.value = false
exercises.value?.reload() exercises.value?.reload()
toast.success(__('Programming Exercise updated successfully')) toast.success(__('Programming Exercise updated successfully'))
}, },

View File

@@ -6,27 +6,26 @@
</header> </header>
<div class="p-6"> <div class="p-6">
<div class="flex items-center justify-between space-x-32 mb-5"> <div class="flex items-center justify-between space-x-32 mb-5">
<div class="text-xl font-semibold text-ink-gray-7"> <div class="text-lg font-semibold text-ink-gray-9">
{{ {{
submissions.data?.length submissions.data?.length
? __('{0} Submissions').format(submissions.data.length) ? __('{0} Submissions').format(submissions.data.length)
: __('No Submissions') : __('No Submissions')
}} }}
</div> </div>
<div <div v-if="submissions.data?.length" class="grid grid-cols-3 gap-5">
v-if="submissions.data?.length"
class="grid grid-cols-3 gap-5 flex-1"
>
<Link <Link
doctype="LMS Programming Exercise" doctype="LMS Programming Exercise"
v-model="filters.exercise" v-model="filters.exercise"
:placeholder="__('Filter by Exercise')" :placeholder="__('Filter by Exercise')"
class="w-40"
/> />
<Link <Link
doctype="User" doctype="User"
v-model="filters.member" v-model="filters.member"
:placeholder="__('Filter by Member')" :placeholder="__('Filter by Member')"
:readonly="isStudent" :readonly="isStudent"
class="w-40"
/> />
<FormControl <FormControl
v-model="filters.status" v-model="filters.status"
@@ -37,6 +36,7 @@
{ label: __('Failed'), value: 'Failed' }, { label: __('Failed'), value: 'Failed' },
]" ]"
:placeholder="__('Filter by Status')" :placeholder="__('Filter by Status')"
class="w-40"
/> />
</div> </div>
</div> </div>
@@ -47,6 +47,7 @@
rowKey="name" rowKey="name"
:options="{ :options="{
selectable: true, selectable: true,
showTooltip: false,
}" }"
> >
<ListHeader <ListHeader
@@ -73,7 +74,7 @@
}, },
}" }"
> >
<ListRow :row="row"> <ListRow :row="row" class="hover:bg-surface-gray-1">
<template #default="{ column, item }"> <template #default="{ column, item }">
<ListRowItem :item="row[column.key]" :align="column.align"> <ListRowItem :item="row[column.key]" :align="column.align">
<template #prefix> <template #prefix>

View File

@@ -33,50 +33,80 @@
</Button> </Button>
</div> </div>
</header> </header>
<div class="md:w-4/5 md:mx-auto p-5"> <div class="p-5">
<div class="flex items-center justify-between mb-5"> <div class="flex items-center justify-between mb-5">
<div v-if="exerciseCount" class="text-lg font-semibold text-ink-gray-9"> <div class="text-lg font-semibold text-ink-gray-9">
{{ __('{0} Exercises').format(exerciseCount) }} {{ __('{0} Exercises').format(exerciseCount) }}
</div> </div>
<div <div class="grid grid-cols-2 gap-5">
v-if="exercises.data?.length || exerciseCount > 0" <FormControl
class="grid grid-cols-2 gap-5" v-model="titleFilter"
> :placeholder="__('Search by Title')"
<!-- <FormControl @input="updateList"
v-model="titleFilter" />
:placeholder="__('Search by title')" <FormControl
/> v-model="languageFilter"
<FormControl type="select"
v-model="typeFilter" :options="languages"
type="select" :placeholder="__('Type')"
:options="assignmentTypes" @update:modelValue="updateList"
:placeholder="__('Type')" />
/> -->
</div> </div>
</div> </div>
<div <div v-if="exercises.data?.length">
v-if="exercises.data?.length" <ListView
class="grid grid-cols-1 md:grid-cols-3 gap-4" :columns="columns"
> :rows="exercises.data"
<div row-key="name"
v-for="exercise in exercises.data" :options="{
:key="exercise.name" showTooltip: false,
@click=" selectable: true,
() => { onRowClick: (row: any) => {
exerciseID = exercise.name if (readOnlyMode) return
exerciseID = row.name
showForm = true showForm = true
} },
" }"
class="flex flex-col border rounded-md p-3 h-full hover:border-outline-gray-3 space-y-2 cursor-pointer"
> >
<div class="text-lg font-semibold text-ink-gray-9"> <ListHeader
{{ exercise.title }} class="mb-2 grid items-center space-x-4 rounded bg-surface-gray-2 p-2"
</div> >
<div class="text-sm text-ink-gray-7"> </ListHeader>
{{ exercise.language }} <ListRows>
</div> <ListRow
</div> :row="row"
v-for="row in exercises.data"
class="hover:bg-surface-gray-1"
>
<template #default="{ column, item }">
<ListRowItem :item="row[column.key]" :align="column.align">
<div
v-if="column.key == 'modified'"
class="text-sm text-ink-gray-5"
>
{{ dayjs(row[column.key]).format('MMM D, YYYY') }}
</div>
<div v-else>
{{ row[column.key] }}
</div>
</ListRowItem>
</template>
</ListRow>
</ListRows>
<ListSelectBanner>
<template #actions="{ unselectAll, selections }">
<div class="flex gap-2">
<Button
variant="ghost"
@click="showDeleteConfirmation(selections, unselectAll)"
>
<FeatherIcon name="trash-2" class="h-4 w-4 stroke-1.5" />
</Button>
</div>
</template>
</ListSelectBanner>
</ListView>
</div> </div>
<EmptyState v-else type="Programming Exercises" /> <EmptyState v-else type="Programming Exercises" />
<div <div
@@ -95,12 +125,22 @@
/> />
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed, inject, onMounted, ref } from 'vue' import { computed, getCurrentInstance, inject, onMounted, ref } from 'vue'
import { import {
Breadcrumbs, Breadcrumbs,
Button, Button,
call, call,
createListResource, createListResource,
dayjs,
FormControl,
ListView,
ListHeader,
ListRows,
ListRow,
ListRowItem,
FeatherIcon,
ListSelectBanner,
toast,
usePageMeta, usePageMeta,
} from 'frappe-ui' } from 'frappe-ui'
import { ClipboardList, Plus } from 'lucide-vue-next' import { ClipboardList, Plus } from 'lucide-vue-next'
@@ -114,7 +154,11 @@ const { brand } = sessionStore()
const showForm = ref<boolean>(false) const showForm = ref<boolean>(false)
const exerciseID = ref<string | null>('new') const exerciseID = ref<string | null>('new')
const user = inject<any>('$user') const user = inject<any>('$user')
const titleFilter = ref<string>('')
const languageFilter = ref<string>('')
const router = useRouter() const router = useRouter()
const app = getCurrentInstance()
const { $dialog } = app?.appContext.config.globalProperties
onMounted(() => { onMounted(() => {
validatePermissions() validatePermissions()
@@ -133,9 +177,10 @@ const validatePermissions = () => {
} }
} }
const getExerciseCount = () => { const getExerciseCount = (filters: any = {}) => {
call('frappe.client.get_count', { call('frappe.client.get_count', {
doctype: 'LMS Programming Exercise', doctype: 'LMS Programming Exercise',
filters: filters,
}) })
.then((count: number) => { .then((count: number) => {
exerciseCount.value = count exerciseCount.value = count
@@ -148,11 +193,98 @@ const getExerciseCount = () => {
const exercises = createListResource({ const exercises = createListResource({
doctype: 'LMS Programming Exercise', doctype: 'LMS Programming Exercise',
cache: ['programmingExercises'], cache: ['programmingExercises'],
fields: ['name', 'title', 'language', 'problem_statement'], fields: ['name', 'title', 'language', 'problem_statement', 'modified'],
auto: true, auto: true,
orderBy: 'modified desc', orderBy: 'modified desc',
}) })
const updateList = () => {
let filters = getFilters()
exercises.update({
filters: filters,
})
exercises.reload()
getExerciseCount(filters)
}
const getFilters = () => {
let filters: any = {}
if (titleFilter.value) {
filters['title'] = ['like', `%${titleFilter.value}%`]
}
if (languageFilter.value && languageFilter.value.trim() !== '') {
filters['language'] = languageFilter.value
}
return filters
}
const showDeleteConfirmation = (
selections: Set<string>,
unselectAll: () => void
) => {
$dialog({
title: __('Confirm Your Action'),
message: __(
'Deleting these exercises will permanently remove them from the system, along with all associated submissions. This action is irreversible. Are you sure you want to proceed?'
),
actions: [
{
label: __('Delete'),
theme: 'red',
variant: 'solid',
onClick(close: () => void) {
deleteExercises(selections, unselectAll)
close()
},
},
],
})
}
const deleteExercises = (selections: Set<string>, unselectAll: () => void) => {
Array.from(selections).forEach(async (exerciseName) => {
call('lms.lms.api.delete_programming_exercise', {
exercise: exerciseName,
})
.then(() => {
toast.success(__('Exercise deleted successfully'))
updateList()
})
.catch((error: any) => {
toast.error(__(error.message || error))
console.error('Error deleting exercise:', error)
})
})
unselectAll()
}
const languages = [
{ label: ' ', value: ' ' },
{ label: 'Python', value: 'Python' },
{ label: 'JavaScript', value: 'JavaScript' },
]
const columns = computed(() => {
return [
{
label: __('Title'),
key: 'title',
width: 3,
},
{
label: __('Language'),
key: 'language',
width: 2,
align: 'left',
},
{
label: __('Updated On'),
key: 'modified',
width: 1,
},
]
})
usePageMeta(() => { usePageMeta(() => {
return { return {
title: __('Programming Exercises'), title: __('Programming Exercises'),

View File

@@ -529,6 +529,13 @@ const getSidebarItems = () => {
condition: () => { condition: () => {
return isAdmin() return isAdmin()
}, },
activeFor: [
'Quizzes',
'QuizForm',
'QuizPage',
'QuizSubmissionList',
'QuizSubmission',
],
}, },
{ {
label: 'Assignments', label: 'Assignments',
@@ -537,6 +544,11 @@ const getSidebarItems = () => {
condition: () => { condition: () => {
return isAdmin() return isAdmin()
}, },
activeFor: [
'Assignments',
'AssignmentSubmissionList',
'AssignmentSubmission',
],
}, },
{ {
label: 'Programming Exercises', label: 'Programming Exercises',
@@ -545,6 +557,11 @@ const getSidebarItems = () => {
condition: () => { condition: () => {
return isAdmin() return isAdmin()
}, },
activeFor: [
'ProgrammingExercises',
'ProgrammingExerciseSubmissions',
'ProgrammingExerciseSubmission',
],
}, },
], ],
}, },

View File

@@ -2050,3 +2050,9 @@ def get_upcoming_batches():
limit=4, limit=4,
pluck="name", pluck="name",
) )
@frappe.whitelist()
def delete_programming_exercise(exercise):
frappe.db.delete("LMS Programming Exercise Submission", {"exercise": exercise})
frappe.db.delete("LMS Programming Exercise", exercise)

View File

@@ -33,6 +33,9 @@ class LMSQuiz(Document):
frappe.throw(_("Rows {0} have the duplicate questions.").format(frappe.bold(comma_and(rows)))) frappe.throw(_("Rows {0} have the duplicate questions.").format(frappe.bold(comma_and(rows))))
def validate_limit(self): def validate_limit(self):
if not self.shuffle_questions and self.limit_questions_to:
self.limit_questions_to = 0
if self.limit_questions_to and cint(self.limit_questions_to) >= len(self.questions): if self.limit_questions_to and cint(self.limit_questions_to) >= len(self.questions):
frappe.throw(_("Limit cannot be greater than or equal to the number of questions in the quiz.")) frappe.throw(_("Limit cannot be greater than or equal to the number of questions in the quiz."))