Create Moodle courses from teaching tasks

This commit is contained in:
biss committed 2026-11-21 15:52:35 +08:00
1 parent c7786f7c16
commit d010af26b5
8 files changed
+242 -2

No files matched your search

+22 -1
View File
@@ -33,6 +33,7 @@ const hasMore = ref(false);
const dialogVisible = ref(false);
const moodleDialog = ref(false);
const moodleSaving = ref(false);
const moodleAvailable = ref(false);
const moodleTask = ref<any>(null);
const moodleUrl = ref("");
const generationDialog = ref(false);
@@ -267,10 +268,29 @@ function canManageRow(row: any) {
);
}
function editMoodle(row: any) {
async function editMoodle(row: any) {
moodleTask.value = row;
moodleUrl.value = row.moodleCourseUrl ?? "";
moodleDialog.value = true;
moodleAvailable.value = false;
try {
moodleAvailable.value = (await http.get('/moodle-courses/availability')).data.available;
} catch { /* Manual linking remains available. */ }
}
async function createMoodle() {
try {
await ElMessageBox.confirm(t('moodle.createConfirm'), t('moodle.create'), { type: 'warning' });
moodleSaving.value = true;
await http.post(`/moodle-courses/teaching-tasks/${moodleTask.value.id}`);
moodleDialog.value = false;
ElMessage.success(t('moodle.created'));
await load();
} catch (error) {
if (error !== 'cancel' && error !== 'close') ElMessage.error(apiErrorMessage(error));
} finally {
moodleSaving.value = false;
}
}
async function saveMoodle() {
@@ -810,6 +830,7 @@ 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="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>
</template>