Allow teachers to provision Moodle courses

This commit is contained in:
biss committed 2026-11-21 19:23:04 +08:00
1 parent d5573ee4cb
commit 6d70f6a385
8 files changed
+102 -11

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ export default {
students: "Import Moodle students", studentsConfirm: "Enrol the current class roster by matching student numbers to Moodle usernames. Existing students will not be removed. Continue?", studentsDone: "Processed {count} students",
studentsBatch: "Import Moodle students in bulk", studentsBatchConfirm: "Import current student rosters for {count} linked classes? Existing students will not be removed.", studentsBatchDone: "Processed {count} classes.",
copy: "Copy existing course", copyHint: "Enter the numeric ID of the Moodle course to copy. Users and their records are excluded. If the copy times out, check Moodle before retrying.", invalidTemplate: "Enter a positive numeric course ID", copied: "Moodle course copied and linked",
teacherCopyHint: "Enter the numeric Moodle course ID of a previously assigned class linked in this system. Users and their records are excluded; check Moodle if copying times out.",
},
selectionTemplate: {
courseSelection: "Course selection",
+1
View File
@@ -9,6 +9,7 @@ export default {
students: "导入 Moodle 学生", studentsConfirm: "按当前教学班名单和学号匹配 Moodle 用户名并加入课程;已有学生不会被移除。确认继续?", studentsDone: "已处理 {count} 名学生",
studentsBatch: "批量导入 Moodle 学生", studentsBatchConfirm: "为选中的 {count} 个已关联教学班导入当前学生名单;不会移除已有学生。确认继续?", studentsBatchDone: "已处理 {count} 个教学班。",
copy: "复制历史课程", copyHint: "请输入 Moodle 历史课程的数字 ID。复制不包含旧用户及其记录;如复制超时,请先在 Moodle 检查结果。", invalidTemplate: "请输入正整数课程 ID", copied: "Moodle 历史课程已复制并关联",
teacherCopyHint: "请输入本人曾任教且已在教务系统关联的 Moodle 课程数字 ID。复制不包含旧用户及其记录;如复制超时,请先在 Moodle 检查结果。",
},
selectionTemplate: {
courseSelection: "学生选课",
+56 -2
View File
@@ -15,14 +15,58 @@ const roster = ref<any>(null)
const termId = ref<string>()
const { locale, t } = useI18n()
const moodleStudentSync = ref(false)
const moodleAvailable = ref(false)
const moodleTeacherSync = ref(false)
const syncingMoodle = ref(false)
async function createMoodleCourse() {
if (!selectedTask.value) return
const taskId = selectedTask.value.id
try {
await ElMessageBox.confirm(t('moodle.createConfirm'), t('moodle.create'), { type: 'warning' })
syncingMoodle.value = true
await http.post(`/moodle-courses/teaching-tasks/${taskId}`)
ElMessage.success(t('moodle.created'))
await loadTasks()
} catch (error) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
} finally { syncingMoodle.value = false }
}
async function syncMoodleTeachers() {
if (!selectedTask.value) return
const taskId = selectedTask.value.id
try {
await ElMessageBox.confirm(t('moodle.syncConfirm'), t('moodle.syncTeachers'), { type: 'warning' })
syncingMoodle.value = true
await http.post(`/moodle-courses/teaching-tasks/${taskId}/teachers`)
ElMessage.success(t('moodle.syncSuccess'))
} catch (error) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
} finally { syncingMoodle.value = false }
}
async function copyMoodleCourse() {
if (!selectedTask.value) return
const taskId = selectedTask.value.id
try {
const answer = await ElMessageBox.prompt(t('moodle.teacherCopyHint'), t('moodle.copy'), { inputPattern: /^[1-9]\d*$/, inputErrorMessage: t('moodle.invalidTemplate') })
syncingMoodle.value = true
await http.post(`/moodle-courses/teaching-tasks/${taskId}/copy`, { templateId: Number(answer.value) })
ElMessage.success(t('moodle.copied'))
await loadTasks()
} catch (error) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
} finally { syncingMoodle.value = false }
}
async function syncMoodleStudents() {
if (!selectedTask.value) return
const taskId = selectedTask.value.id
try {
await ElMessageBox.confirm(t('moodle.studentsConfirm'), t('moodle.students'), { type: 'warning' })
syncingMoodle.value = true
const result = await http.post(`/moodle-courses/teaching-tasks/${selectedTask.value.id}/students`)
const result = await http.post(`/moodle-courses/teaching-tasks/${taskId}/students`)
ElMessage.success(t('moodle.studentsDone', { count: result.data.count }))
} catch (error) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error))
@@ -80,7 +124,12 @@ async function exportRoster() {
}
onMounted(async () => {
try { moodleStudentSync.value = (await http.get('/moodle-courses/availability')).data.studentSync } catch { moodleStudentSync.value = false }
try {
const settings = (await http.get('/moodle-courses/availability')).data
moodleAvailable.value = settings.available
moodleTeacherSync.value = settings.teacherSync
moodleStudentSync.value = settings.studentSync
} catch { moodleStudentSync.value = false }
terms.value = (await http.get('/base-data/terms')).data
termId.value = defaultAcademicTermId(terms.value)
await loadTasks()
@@ -124,8 +173,13 @@ onMounted(async () => {
<main class="roster-detail" v-loading="detailLoading">
<el-empty v-if="!selectedTask" :description="t('teacherRoster.selectTask')" />
<div v-if="selectedTask?.status === 'Published' && moodleAvailable && !selectedTask?.moodleCourseUrl" class="moodle-course-link">
<el-button type="primary" :loading="syncingMoodle" @click="createMoodleCourse">{{ t('moodle.create') }}</el-button>
<el-button :loading="syncingMoodle" @click="copyMoodleCourse">{{ t('moodle.copy') }}</el-button>
</div>
<div v-if="selectedTask?.moodleCourseUrl" class="moodle-course-link">
<a :href="selectedTask.moodleCourseUrl" target="_blank" rel="noopener noreferrer">{{ t('moodle.open') }} ↗</a>
<el-button v-if="moodleTeacherSync && selectedTask.status === 'Published'" link type="primary" :loading="syncingMoodle" @click="syncMoodleTeachers">{{ t('moodle.syncTeachers') }}</el-button>
<el-button v-if="moodleStudentSync" link type="primary" :loading="syncingMoodle" @click="syncMoodleStudents">{{ t('moodle.students') }}</el-button>
</div>
<template v-if="selectedTask && roster">