Add Moodle course reuse and teacher synchronization
This commit is contained in:
1 parent
d010af26b5
commit
6faf00a68f
7 files changed
+246
-8
No files matched your search
@@ -3,6 +3,9 @@ export default {
|
||||
manage: "Link Moodle", hint: "Paste the HTTPS address of an existing Moodle course. Clear it to unlink. Teachers need access to the course in Moodle.",
|
||||
placeholder: "https://moodle.example.edu/course/view.php?id=123", save: "Save", cancel: "Cancel", saved: "Moodle course link saved", open: "Open Moodle course", linked: "Moodle linked",
|
||||
create: "Create empty course", createConfirm: "Create a hidden, empty Moodle course for this teaching task? Teachers and students will not be enrolled automatically.", created: "Moodle course created and linked",
|
||||
batchCreate: "Create Moodle courses", batchConfirm: "Create hidden, empty courses for {count} selected tasks? Teachers and students will not be enrolled automatically.", batchResult: "Course creation results", batchSuccess: "Created or recovered {count} courses.", unavailable: "Configure the Moodle service first.",
|
||||
syncTeachers: "Sync teachers", syncConfirm: "Match teacher numbers to Moodle usernames and enrol teachers. Existing teachers will not be removed. Continue?", syncSuccess: "Teachers synced to Moodle",
|
||||
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",
|
||||
},
|
||||
selectionTemplate: {
|
||||
courseSelection: "Course selection",
|
||||
|
||||
@@ -3,6 +3,9 @@ export default {
|
||||
manage: "关联 Moodle", hint: "粘贴已有 Moodle 课程的 HTTPS 地址;留空可解除关联。教师需要具备 Moodle 课程访问权限。",
|
||||
placeholder: "https://moodle.example.edu/course/view.php?id=123", save: "保存", cancel: "取消", saved: "Moodle 课程关联已保存", open: "进入 Moodle 课程", linked: "已关联 Moodle",
|
||||
create: "创建空课程", createConfirm: "将在 Moodle 创建隐藏的空课程并关联当前教学任务。教师和学生尚不会自动加入,确认继续?", created: "Moodle 课程已创建并关联",
|
||||
batchCreate: "批量创建 Moodle 课程", batchConfirm: "将为选中的 {count} 个未关联教学任务创建隐藏的空课程,不会自动加入教师或学生。确认继续?", batchResult: "批量创建结果", batchSuccess: "已创建或恢复关联 {count} 门课程。", unavailable: "请先配置 Moodle 服务。",
|
||||
syncTeachers: "同步授课教师", syncConfirm: "按工号匹配 Moodle 用户名并加入授课教师;不会移除 Moodle 中已有的教师。确认继续?", syncSuccess: "授课教师已同步至 Moodle",
|
||||
copy: "复制历史课程", copyHint: "请输入 Moodle 历史课程的数字 ID。复制不包含旧用户及其记录;如复制超时,请先在 Moodle 检查结果。", invalidTemplate: "请输入正整数课程 ID", copied: "Moodle 历史课程已复制并关联",
|
||||
},
|
||||
selectionTemplate: {
|
||||
courseSelection: "学生选课",
|
||||
|
||||
@@ -34,6 +34,7 @@ const dialogVisible = ref(false);
|
||||
const moodleDialog = ref(false);
|
||||
const moodleSaving = ref(false);
|
||||
const moodleAvailable = ref(false);
|
||||
const moodleTeacherSync = ref(false);
|
||||
const moodleTask = ref<any>(null);
|
||||
const moodleUrl = ref("");
|
||||
const generationDialog = ref(false);
|
||||
@@ -230,6 +231,27 @@ const selectedDraftRows = computed(() =>
|
||||
const selectedPublishedRows = computed(() =>
|
||||
selectedRows.value.filter((item) => item.status === "Published"),
|
||||
);
|
||||
const moodleBatchLoading = ref(false);
|
||||
const moodleBatchTargets = computed(() => selectedPublishedRows.value.filter((item) => !item.moodleCourseUrl && canManageRow(item)));
|
||||
|
||||
async function createMoodleBatch() {
|
||||
try {
|
||||
const availability = await http.get('/moodle-courses/availability');
|
||||
if (!availability.data.available) { ElMessage.error(t('moodle.unavailable')); return; }
|
||||
await ElMessageBox.confirm(t('moodle.batchConfirm', { count: moodleBatchTargets.value.length }), t('moodle.batchCreate'), { type: 'warning' });
|
||||
moodleBatchLoading.value = true;
|
||||
const failures: string[] = [];
|
||||
const targets = [...moodleBatchTargets.value];
|
||||
for (const task of targets) {
|
||||
try { await http.post(`/moodle-courses/teaching-tasks/${task.id}`); }
|
||||
catch (error) { failures.push(`${task.taskNumber}: ${apiErrorMessage(error)}`); }
|
||||
}
|
||||
await load();
|
||||
await ElMessageBox.alert(failures.length ? failures.join('\n') : t('moodle.batchSuccess', { count: targets.length }), t('moodle.batchResult'), { customClass: 'moodle-batch-result' });
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error));
|
||||
} finally { moodleBatchLoading.value = false; }
|
||||
}
|
||||
const selectedClosedRows = computed(() =>
|
||||
selectedRows.value.filter((item) => item.status === "Closed"),
|
||||
);
|
||||
@@ -273,11 +295,25 @@ async function editMoodle(row: any) {
|
||||
moodleUrl.value = row.moodleCourseUrl ?? "";
|
||||
moodleDialog.value = true;
|
||||
moodleAvailable.value = false;
|
||||
moodleTeacherSync.value = false;
|
||||
try {
|
||||
moodleAvailable.value = (await http.get('/moodle-courses/availability')).data.available;
|
||||
const settings = (await http.get('/moodle-courses/availability')).data;
|
||||
moodleAvailable.value = settings.available;
|
||||
moodleTeacherSync.value = settings.teacherSync;
|
||||
} catch { /* Manual linking remains available. */ }
|
||||
}
|
||||
|
||||
async function syncMoodleTeachers() {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('moodle.syncConfirm'), t('moodle.syncTeachers'), { type: 'warning' });
|
||||
moodleSaving.value = true;
|
||||
await http.post(`/moodle-courses/teaching-tasks/${moodleTask.value.id}/teachers`);
|
||||
ElMessage.success(t('moodle.syncSuccess'));
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error));
|
||||
} finally { moodleSaving.value = false; }
|
||||
}
|
||||
|
||||
async function createMoodle() {
|
||||
try {
|
||||
await ElMessageBox.confirm(t('moodle.createConfirm'), t('moodle.create'), { type: 'warning' });
|
||||
@@ -293,6 +329,21 @@ async function createMoodle() {
|
||||
}
|
||||
}
|
||||
|
||||
async function copyMoodle() {
|
||||
try {
|
||||
const result = await ElMessageBox.prompt(t('moodle.copyHint'), t('moodle.copy'), {
|
||||
inputPattern: /^[1-9]\d*$/, inputErrorMessage: t('moodle.invalidTemplate'),
|
||||
});
|
||||
moodleSaving.value = true;
|
||||
await http.post(`/moodle-courses/teaching-tasks/${moodleTask.value.id}/copy`, { templateId: Number(result.value) });
|
||||
moodleDialog.value = false;
|
||||
ElMessage.success(t('moodle.copied'));
|
||||
await load();
|
||||
} catch (error) {
|
||||
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error));
|
||||
} finally { moodleSaving.value = false; }
|
||||
}
|
||||
|
||||
async function saveMoodle() {
|
||||
moodleSaving.value = true;
|
||||
try {
|
||||
@@ -830,6 +881,8 @@ onMounted(async () => {
|
||||
<p>{{ t('moodle.hint') }}</p>
|
||||
<el-input v-model="moodleUrl" maxlength="2048" :placeholder="t('moodle.placeholder')" clearable />
|
||||
<template #footer>
|
||||
<el-button v-if="moodleAvailable && moodleTask?.status === 'Published' && !moodleTask?.moodleCourseUrl" :loading="moodleSaving" @click="copyMoodle">{{ t('moodle.copy') }}</el-button>
|
||||
<el-button v-if="moodleTeacherSync && moodleTask?.status === 'Published' && moodleTask?.moodleCourseUrl" :loading="moodleSaving" @click="syncMoodleTeachers">{{ t('moodle.syncTeachers') }}</el-button>
|
||||
<el-button v-if="moodleAvailable && moodleTask?.status === 'Published' && !moodleTask?.moodleCourseUrl" :loading="moodleSaving" @click="createMoodle">{{ t('moodle.create') }}</el-button>
|
||||
<el-button @click="moodleDialog = false">{{ t('moodle.cancel') }}</el-button>
|
||||
<el-button type="primary" :loading="moodleSaving" @click="saveMoodle">{{ t('moodle.save') }}</el-button>
|
||||
@@ -975,6 +1028,7 @@ onMounted(async () => {
|
||||
}}</span>
|
||||
</div>
|
||||
<div>
|
||||
<el-button :disabled="!moodleBatchTargets.length" :loading="moodleBatchLoading" @click="createMoodleBatch">{{ t('moodle.batchCreate') }}</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
|
||||
Reference in new issue
Block a user