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
@@ -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