Files
Academic-Affairs-System/web/src/views/SchedulesView.vue
T
2026-11-13 19:09:49 +08:00

2794 lines
94 KiB
Vue

<script setup lang="ts">
import { useI18n } from "vue-i18n";
const { t } = useI18n();
import { computed, onBeforeUnmount, onMounted, reactive, ref } from "vue";
import {
CopyDocument,
EditPen,
Plus,
Promotion,
Refresh,
Search,
Setting,
} from "@element-plus/icons-vue";
import http, { apiErrorMessage } from "../api/http";
import {
academicTermLabel,
academicTermOptionClass,
defaultAcademicTermId,
} from "../utils/academicTerms";
const plans = ref<any[]>([]);
const selected = ref<any | null>(null);
const terms = ref<any[]>([]);
const tasks = ref<any[]>([]);
const classrooms = ref<any[]>([]);
const campuses = ref<any[]>([]);
const buildings = ref<any[]>([]);
const timeSlots = ref<any[]>([]);
const constraints = ref<any[]>([]);
const loading = ref(false);
const detailLoading = ref(false);
const autoJob = ref<any | null>(null);
const publishJob = ref<any | null>(null);
const planDialog = ref(false);
const cloneDialog = ref(false);
const entryDialog = ref(false);
const settingsDrawer = ref(false);
const settingsTab = ref("time");
const constraintDialog = ref(false);
const constraintBatchDialog = ref(false);
const constraintBatchSaving = ref(false);
const editingPlanId = ref("");
const editingEntryId = ref("");
const keyword = ref("");
const termId = ref<string | undefined>();
const planForm = reactive<Record<string, any>>({});
const cloneForm = reactive<Record<string, any>>({});
const revisingPublishedPlan = ref(false);
const entryForm = reactive<Record<string, any>>({});
const constraintForm = reactive<Record<string, any>>({});
const constraintBatchForm = reactive<Record<string, any>>({});
const optimizationSettings = reactive({
teacherSameDayWeight: 120,
classSameDayWeight: 100,
classGapWeight: 240,
consecutiveClassWeight: 60,
earlyPeriodPenalty: 30,
latePeriodPenalty: 30,
roomCapacityWasteWeight: 1,
coursePreferenceWeight: 180,
geneticPopulationSize: 32,
geneticGenerationCount: 80,
geneticMutationRatePercent: 12,
});
const optimizationSaving = ref(false);
const constraintFilters = reactive({
keyword: "",
collegeId: undefined as string | undefined,
schedulingMode: undefined as string | undefined,
classroomMode: undefined as string | undefined,
constraintState: undefined as string | undefined,
});
let autoPollTimer: ReturnType<typeof setTimeout> | undefined;
let publishPollTimer: ReturnType<typeof setTimeout> | undefined;
const weekdays = computed(() => [
{ value: 1, label: t("schedulesScript.monday") },
{ value: 2, label: t("schedulesScript.tuesday") },
{ value: 3, label: t("schedulesScript.wednesday") },
{ value: 4, label: t("schedulesScript.thursday") },
{ value: 5, label: t("schedulesScript.friday") },
{ value: 6, label: t("schedulesScript.saturday") },
{ value: 7, label: t("schedulesScript.sunday") },
]);
const experimentVenueNatures = computed(() => [
{ value: 1, label: t("schedulesScript.generalClassroom") },
{ value: 2, label: t("schedulesScript.laboratory") },
{ value: 4, label: t("schedulesScript.trainingRoom") },
{ value: 8, label: t("schedulesScript.computerLab") },
{ value: 16, label: t("schedulesScript.languageLab") },
{ value: 32, label: t("schedulesScript.sportsVenue") },
{ value: 64, label: t("schedulesScript.artsVenue") },
]);
const venueNatureValue = (value: unknown) => {
if (typeof value === "number") return value;
if (typeof value !== "string") return 0;
const names: Record<string, number> = {
GeneralClassroom: 1,
Laboratory: 2,
TrainingRoom: 4,
ComputerLab: 8,
LanguageLab: 16,
SportsVenue: 32,
ArtsVenue: 64,
};
return value
.split(",")
.reduce((sum, name) => sum | (names[name.trim()] ?? 0), 0);
};
const periods = computed(() => {
const configured = timeSlots.value
.filter((item) => item.isEnabled)
.map((item) => item.periodNumber);
return configured.length
? configured
: Array.from({ length: 12 }, (_, index) => index + 1);
});
const statusLabels = computed<Record<string, string>>(() => ({
Draft: t("schedulesScript.draft"),
Published: t("schedulesScript.published"),
Archived: t("schedulesScript.archived"),
}));
const patternLabels = computed<Record<string, string>>(() => ({
All: t("schedulesScript.everyWeek"),
Odd: t("schedulesScript.oddWeeks"),
Even: t("schedulesScript.evenWeeks"),
}));
const isDraft = computed(() => selected.value?.status === "Draft");
const autoLoading = computed(
() =>
autoJob.value?.status === "Queued" || autoJob.value?.status === "Running",
);
const publishLoading = computed(
() =>
publishJob.value?.status === "Queued" ||
publishJob.value?.status === "Running",
);
const scheduleJobLoading = computed(
() => autoLoading.value || publishLoading.value,
);
const autoProgress = computed(() => {
if (!autoJob.value?.totalTasks) return 0;
return Math.min(
100,
Math.round((autoJob.value.processedTasks / autoJob.value.totalTasks) * 100),
);
});
const autoProgressStatus = computed(() => {
if (autoJob.value?.status === "Succeeded") return "success";
if (autoJob.value?.status === "Failed") return "exception";
return undefined;
});
const autoStatusText = computed(() => {
if (!autoJob.value) return "";
if (autoJob.value.status === "Queued")
return t("schedulesScript.jobQueuedForBackgroundProcessing");
if (autoJob.value.status === "Running") {
if (autoJob.value.totalGenerations) {
return t("schedulesScript.generation", {
current: autoJob.value.currentGeneration,
total: autoJob.value.totalGenerations,
});
}
return t("schedulesScript.processing", {
processed: autoJob.value.processedTasks,
total: autoJob.value.totalTasks,
entries: autoJob.value.createdEntries,
});
}
if (autoJob.value.status === "Succeeded") {
return t("schedulesScript.complete", {
entries: autoJob.value.createdEntries,
});
}
return (
autoJob.value.errorMessage ||
t("schedulesScript.backgroundSchedulingFailedTryAgainLater")
);
});
const publishProgress = computed(() => {
if (!publishJob.value?.totalSteps) return 0;
return Math.min(
100,
Math.round(
(publishJob.value.completedSteps / publishJob.value.totalSteps) * 100,
),
);
});
const publishProgressStatus = computed(() => {
if (publishJob.value?.status === "Succeeded") return "success";
if (publishJob.value?.status === "Failed") return "exception";
return undefined;
});
const publishStatusText = computed(() => {
if (!publishJob.value) return "";
if (publishJob.value.status === "Queued")
return t("schedulesScript.publicationQueuedForBackgroundChecks");
if (publishJob.value.status === "Running") {
return (
publishJob.value.currentStep ||
t("schedulesScript.checkingAndPublishingTheTimetable")
);
}
if (publishJob.value.status === "Succeeded")
return t("schedulesScript.checksPassedTimetablePublished");
return (
publishJob.value.errorMessage || t("schedulesScript.timetableCheckFailed")
);
});
const selectedTaskConstraint = computed(() =>
constraints.value.find((item) => item.id === entryForm.teachingTaskId),
);
const entryClassrooms = computed(() =>
classrooms.value.filter(
(room) =>
(entryForm.kind === "Experiment" ||
!selectedTaskConstraint.value?.requiredCampusId ||
room.campusId === selectedTaskConstraint.value.requiredCampusId) &&
(entryForm.kind === "Experiment" ||
!selectedTaskConstraint.value?.requiredBuildingId ||
room.buildingId === selectedTaskConstraint.value.requiredBuildingId) &&
(entryForm.kind === "Experiment" ||
!selectedTaskConstraint.value?.allowedClassroomIds?.length ||
selectedTaskConstraint.value.allowedClassroomIds.includes(room.id)) &&
(entryForm.kind !== "Experiment" ||
!selectedTaskConstraint.value?.experimentRequiredCampusId ||
room.campusId ===
selectedTaskConstraint.value.experimentRequiredCampusId) &&
(entryForm.kind !== "Experiment" ||
!selectedTaskConstraint.value?.experimentRequiredBuildingId ||
room.buildingId ===
selectedTaskConstraint.value.experimentRequiredBuildingId) &&
(entryForm.kind !== "Experiment" ||
!selectedTaskConstraint.value?.allowedExperimentClassroomIds?.length ||
selectedTaskConstraint.value.allowedExperimentClassroomIds.includes(
room.id,
)),
),
);
const entryWeekdays = computed(() => {
const allowedDays = selectedTaskConstraint.value?.allowedDayOfWeeks ?? [];
return allowedDays.length
? weekdays.value.filter((day) => allowedDays.includes(day.value))
: weekdays.value;
});
const constraintColleges = computed(() => {
const result = new Map<string, string>();
constraints.value.forEach((item) =>
result.set(item.collegeId, item.collegeName),
);
return [...result]
.map(([id, name]) => ({ id, name }))
.sort((a, b) => a.name.localeCompare(b.name, "zh-CN"));
});
const filteredConstraints = computed(() => {
const text = constraintFilters.keyword.trim().toLowerCase();
return constraints.value.filter((item) => {
const matchesKeyword =
!text ||
[
item.taskNumber,
item.name,
item.courseCode,
item.courseName,
...item.teacherNames,
].some((value) => String(value).toLowerCase().includes(text));
const matchesCollege =
!constraintFilters.collegeId ||
item.collegeId === constraintFilters.collegeId;
const matchesMode =
!constraintFilters.schedulingMode ||
item.schedulingMode === constraintFilters.schedulingMode;
const matchesClassroom =
!constraintFilters.classroomMode ||
(constraintFilters.classroomMode === "required"
? item.requiresClassroom
: !item.requiresClassroom);
const matchesState =
!constraintFilters.constraintState ||
(constraintFilters.constraintState === "custom"
? item.hasCustomConstraint
: !item.hasCustomConstraint);
return (
matchesKeyword &&
matchesCollege &&
matchesMode &&
matchesClassroom &&
matchesState
);
});
});
const filteredBuildings = computed(() =>
constraintForm.requiredCampusId
? buildings.value.filter(
(item) => item.campusId === constraintForm.requiredCampusId,
)
: buildings.value,
);
const filteredClassrooms = computed(() =>
classrooms.value.filter(
(item) =>
(!constraintForm.requiredCampusId ||
item.campusId === constraintForm.requiredCampusId) &&
(!constraintForm.requiredBuildingId ||
item.buildingId === constraintForm.requiredBuildingId),
),
);
const filteredExperimentBuildings = computed(() =>
constraintForm.experimentRequiredCampusId
? buildings.value.filter(
(item) => item.campusId === constraintForm.experimentRequiredCampusId,
)
: buildings.value,
);
const filteredExperimentClassrooms = computed(() =>
classrooms.value.filter(
(item) =>
(!constraintForm.experimentRequiredCampusId ||
item.campusId === constraintForm.experimentRequiredCampusId) &&
(!constraintForm.experimentRequiredBuildingId ||
item.buildingId === constraintForm.experimentRequiredBuildingId) &&
(!(constraintForm.allowedExperimentVenueNatures ?? []).length ||
(venueNatureValue(item.teachingVenueNature) &
(constraintForm.allowedExperimentVenueNatures ?? []).reduce(
(value: number, nature: number) => value | nature,
0,
)) !==
0),
),
);
const batchFilteredBuildings = computed(() =>
constraintBatchForm.requiredCampusId
? buildings.value.filter(
(item) => item.campusId === constraintBatchForm.requiredCampusId,
)
: buildings.value,
);
const batchFilteredClassrooms = computed(() =>
classrooms.value.filter(
(item) =>
(!constraintBatchForm.requiredCampusId ||
item.campusId === constraintBatchForm.requiredCampusId) &&
(!constraintBatchForm.requiredBuildingId ||
item.buildingId === constraintBatchForm.requiredBuildingId),
),
);
const batchFilteredExperimentBuildings = computed(() =>
constraintBatchForm.experimentRequiredCampusId
? buildings.value.filter(
(item) =>
item.campusId === constraintBatchForm.experimentRequiredCampusId,
)
: buildings.value,
);
const batchFilteredExperimentClassrooms = computed(() =>
classrooms.value.filter(
(item) =>
(!constraintBatchForm.experimentRequiredCampusId ||
item.campusId === constraintBatchForm.experimentRequiredCampusId) &&
(!constraintBatchForm.experimentRequiredBuildingId ||
item.buildingId === constraintBatchForm.experimentRequiredBuildingId) &&
(!(constraintBatchForm.allowedExperimentVenueNatures ?? []).length ||
(venueNatureValue(item.teachingVenueNature) &
(constraintBatchForm.allowedExperimentVenueNatures ?? []).reduce(
(value: number, nature: number) => value | nature,
0,
)) !==
0),
),
);
const filteredEntries = computed(() => {
const text = keyword.value.trim().toLowerCase();
if (!text) return selected.value?.entries ?? [];
return (selected.value?.entries ?? []).filter((entry: any) =>
[
entry.taskNumber,
entry.taskName,
entry.courseCode,
entry.courseName,
entry.classroomName,
...entry.teacherNames,
...entry.classNames,
].some((value) => String(value).toLowerCase().includes(text)),
);
});
function entriesAt(day: number, period: number) {
return filteredEntries.value.filter(
(entry: any) => entry.dayOfWeek === day && entry.startPeriod === period,
);
}
function timeLabel(period: number) {
const slot = timeSlots.value.find((item) => item.periodNumber === period);
return slot
? `${slot.startsAt}—${slot.endsAt}`
: t("schedulesScript.period", { period });
}
async function loadSchedulingSettings() {
if (!termId.value) return;
try {
const [timeRes, constraintRes, optimizationRes] = await Promise.all([
http.get("/schedules/time-slots", {
params: { academicTermId: termId.value },
}),
http.get("/schedules/constraints", {
params: { academicTermId: termId.value },
}),
http.get("/schedules/optimization-settings", {
params: { academicTermId: termId.value },
}),
]);
timeSlots.value = timeRes.data;
constraints.value = constraintRes.data;
tasks.value = constraintRes.data.filter(
(item: any) => item.schedulingMode === "Standard",
);
Object.assign(optimizationSettings, optimizationRes.data);
} catch (error) {
ElMessage.error(apiErrorMessage(error));
}
}
async function saveOptimizationSettings() {
if (!termId.value) return;
try {
optimizationSaving.value = true;
const { data } = await http.put(
`/schedules/optimization-settings/${termId.value}`,
optimizationSettings,
);
Object.assign(optimizationSettings, data);
ElMessage.success(t("schedulesScript.automaticSchedulingStrategySaved"));
} catch (error) {
ElMessage.error(apiErrorMessage(error));
} finally {
optimizationSaving.value = false;
}
}
async function changeTerm() {
await Promise.all([loadPlans(false), loadSchedulingSettings()]);
}
function initializeTimeSlots() {
const defaults = [
["08:00", "08:45"],
["08:55", "09:40"],
["10:00", "10:45"],
["10:55", "11:40"],
["14:00", "14:45"],
["14:55", "15:40"],
["16:00", "16:45"],
["16:55", "17:40"],
["19:00", "19:45"],
["19:55", "20:40"],
];
timeSlots.value = defaults.map(([startsAt, endsAt], index) => ({
periodNumber: index + 1,
name: `第 ${index + 1} 节`,
startsAt,
endsAt,
isEnabled: true,
}));
}
function addTimeSlot() {
const last = timeSlots.value.at(-1);
timeSlots.value.push({
periodNumber: (last?.periodNumber ?? 0) + 1,
name: `第 ${(last?.periodNumber ?? 0) + 1} 节`,
startsAt: "08:00",
endsAt: "08:45",
isEnabled: true,
});
}
async function saveTimeSlots() {
try {
await http.put(`/schedules/time-slots/${termId.value}`, timeSlots.value);
ElMessage.success(t("schedulesScript.teachingTimeSlotsSaved"));
await loadSchedulingSettings();
} catch (error) {
ElMessage.error(apiErrorMessage(error));
}
}
function openConstraint(item: any) {
Object.assign(constraintForm, {
teachingTaskId: item.id,
title: `${item.taskNumber} · ${item.name}`,
coursePracticeHours: item.coursePracticeHours,
schedulingMode: item.schedulingMode,
requiresClassroom: item.requiresClassroom,
requiredCampusId: item.requiredCampusId,
requiredBuildingId: item.requiredBuildingId,
experimentRequiredCampusId: item.experimentRequiredCampusId,
experimentRequiredBuildingId: item.experimentRequiredBuildingId,
allowedClassroomIds: [...item.allowedClassroomIds],
allowedExperimentClassroomIds: [...item.allowedExperimentClassroomIds],
allowedExperimentVenueNatures: experimentVenueNatures.value
.filter(
(nature) =>
(Number(item.allowedExperimentVenueNatures) & nature.value) !== 0,
)
.map((nature) => nature.value),
allowedDayOfWeeks: item.allowedDayOfWeeks.length
? [...item.allowedDayOfWeeks]
: [1, 2, 3, 4, 5],
earliestPeriod: item.earliestPeriod,
latestPeriod: item.latestPeriod,
preferredDayOfWeeks: [...(item.preferredDayOfWeeks ?? [])],
preferredEarliestPeriod: item.preferredEarliestPeriod,
preferredLatestPeriod: item.preferredLatestPeriod,
});
constraintDialog.value = true;
}
async function saveConstraint() {
try {
const payload = {
schedulingMode: constraintForm.schedulingMode,
requiresClassroom: constraintForm.requiresClassroom,
requiredCampusId: constraintForm.requiredCampusId || null,
requiredBuildingId: constraintForm.requiredBuildingId || null,
experimentRequiredCampusId:
constraintForm.experimentRequiredCampusId || null,
experimentRequiredBuildingId:
constraintForm.experimentRequiredBuildingId || null,
allowedClassroomIds: constraintForm.allowedClassroomIds ?? [],
allowedExperimentClassroomIds:
constraintForm.allowedExperimentClassroomIds ?? [],
allowedExperimentVenueNatures: (
constraintForm.allowedExperimentVenueNatures ?? []
).reduce((value: number, nature: number) => value | nature, 0),
allowedDayOfWeeks: constraintForm.allowedDayOfWeeks ?? [],
earliestPeriod: constraintForm.earliestPeriod || null,
latestPeriod: constraintForm.latestPeriod || null,
preferredDayOfWeeks: constraintForm.preferredDayOfWeeks ?? [],
preferredEarliestPeriod: constraintForm.preferredEarliestPeriod || null,
preferredLatestPeriod: constraintForm.preferredLatestPeriod || null,
};
await http.put(
`/schedules/constraints/${constraintForm.teachingTaskId}`,
payload,
);
constraintDialog.value = false;
ElMessage.success(t("schedulesScript.schedulingConstraintsSaved"));
await loadSchedulingSettings();
} catch (error) {
ElMessage.error(apiErrorMessage(error));
}
}
function resetConstraintFilters() {
Object.assign(constraintFilters, {
keyword: "",
collegeId: undefined,
schedulingMode: undefined,
classroomMode: undefined,
constraintState: undefined,
});
}
function openConstraintBatch() {
if (!filteredConstraints.value.length) {
ElMessage.warning(
t("schedulesScript.noEditableTeachingTasksMatchTheCurrentFilters"),
);
return;
}
Object.keys(constraintBatchForm).forEach(
(key) => delete constraintBatchForm[key],
);
Object.assign(constraintBatchForm, {
updateSchedulingMode: false,
schedulingMode: "Standard",
updateRequiresClassroom: false,
requiresClassroom: true,
updateClassroomScope: false,
requiredCampusId: undefined,
requiredBuildingId: undefined,
allowedClassroomIds: [],
updateExperimentClassroomScope: false,
experimentRequiredCampusId: undefined,
experimentRequiredBuildingId: undefined,
allowedExperimentVenueNatures: [],
allowedExperimentClassroomIds: [],
updateDays: false,
allowedDayOfWeeks: [1, 2, 3, 4, 5],
updatePeriodRange: false,
earliestPeriod: undefined,
latestPeriod: undefined,
});
constraintBatchDialog.value = true;
}
async function saveConstraintBatch() {
if (
!constraintBatchForm.updateSchedulingMode &&
!constraintBatchForm.updateRequiresClassroom &&
!constraintBatchForm.updateClassroomScope &&
!constraintBatchForm.updateExperimentClassroomScope &&
!constraintBatchForm.updateDays &&
!constraintBatchForm.updatePeriodRange
) {
ElMessage.warning(t("schedulesScript.selectAtLeastOneSettingToChange"));
return;
}
const targets = [...filteredConstraints.value];
try {
await ElMessageBox.confirm(
t("schedulesScript.confirmBulk", { count: targets.length }),
t("schedulesScript.changeSchedulingConstraintsInBulk"),
{
type: "warning",
confirmButtonText: t("schedulesScript.updateFilteredResults"),
cancelButtonText: t("schedulesScript.cancel"),
},
);
constraintBatchSaving.value = true;
const flexible =
constraintBatchForm.updateSchedulingMode &&
constraintBatchForm.schedulingMode === "Flexible";
const updateClassroomScope =
!flexible &&
!(
constraintBatchForm.updateRequiresClassroom &&
!constraintBatchForm.requiresClassroom
) &&
constraintBatchForm.updateClassroomScope;
const updateExperimentClassroomScope =
!flexible &&
!(
constraintBatchForm.updateRequiresClassroom &&
!constraintBatchForm.requiresClassroom
) &&
constraintBatchForm.updateExperimentClassroomScope;
const { data } = await http.put("/schedules/constraints/batch", {
academicTermId: termId.value,
teachingTaskIds: targets.map((item) => item.id),
schedulingMode: constraintBatchForm.updateSchedulingMode
? constraintBatchForm.schedulingMode
: null,
requiresClassroom:
!flexible && constraintBatchForm.updateRequiresClassroom
? constraintBatchForm.requiresClassroom
: null,
updateClassroomScope,
requiredCampusId: updateClassroomScope
? constraintBatchForm.requiredCampusId || null
: null,
requiredBuildingId: updateClassroomScope
? constraintBatchForm.requiredBuildingId || null
: null,
allowedClassroomIds: updateClassroomScope
? constraintBatchForm.allowedClassroomIds
: null,
updateExperimentClassroomScope,
experimentRequiredCampusId: updateExperimentClassroomScope
? constraintBatchForm.experimentRequiredCampusId || null
: null,
experimentRequiredBuildingId: updateExperimentClassroomScope
? constraintBatchForm.experimentRequiredBuildingId || null
: null,
allowedExperimentVenueNatures: updateExperimentClassroomScope
? (constraintBatchForm.allowedExperimentVenueNatures ?? []).reduce(
(value: number, nature: number) => value | nature,
0,
)
: null,
allowedExperimentClassroomIds: updateExperimentClassroomScope
? constraintBatchForm.allowedExperimentClassroomIds
: null,
allowedDayOfWeeks:
!flexible && constraintBatchForm.updateDays
? constraintBatchForm.allowedDayOfWeeks
: null,
updatePeriodRange: !flexible && constraintBatchForm.updatePeriodRange,
earliestPeriod:
!flexible && constraintBatchForm.updatePeriodRange
? constraintBatchForm.earliestPeriod || null
: null,
latestPeriod:
!flexible && constraintBatchForm.updatePeriodRange
? constraintBatchForm.latestPeriod || null
: null,
});
constraintBatchDialog.value = false;
ElMessage.success(
t("schedulesScript.updated", { count: data.affectedCount }),
);
await loadSchedulingSettings();
} catch (error: any) {
if (error !== "cancel" && error !== "close")
ElMessage.error(apiErrorMessage(error));
} finally {
constraintBatchSaving.value = false;
}
}
function openManualHandling() {
settingsTab.value = "constraints";
settingsDrawer.value = true;
}
async function autoSchedule() {
try {
await ElMessageBox.confirm(
t(
"schedulesScript.existingManualAssignmentsArePreservedWhileTheoryAndLabClassesAreFilledInLabsUseSuitableVenuesGeneratedEntriesRemainEditable",
),
t("schedulesScript.startAutomaticScheduling"),
{
type: "warning",
confirmButtonText: t("schedulesScript.generateSchedule"),
cancelButtonText: t("schedulesScript.cancel"),
},
);
const planId = selected.value.id;
const { data } = await http.post(
`/schedules/plans/${planId}/auto-schedule`,
);
autoJob.value = data;
ElMessage.success(
t("schedulesScript.schedulingJobSubmittedProgressIsAvailableOnThisPage"),
);
scheduleAutoSchedulePoll(data.id, planId);
} catch (error: any) {
if (error !== "cancel" && error !== "close")
ElMessage.error(apiErrorMessage(error));
}
}
function clearPublishPoll() {
if (publishPollTimer) clearTimeout(publishPollTimer);
publishPollTimer = undefined;
}
function schedulePublishPoll(jobId: string, planId: string) {
clearPublishPoll();
publishPollTimer = setTimeout(() => pollPublishJob(jobId, planId), 1000);
}
async function pollPublishJob(jobId: string, planId: string) {
try {
const { data } = await http.get(`/schedules/publish-jobs/${jobId}`);
if (selected.value?.id !== planId) return;
publishJob.value = data;
if (data.status === "Queued" || data.status === "Running") {
schedulePublishPoll(jobId, planId);
return;
}
clearPublishPoll();
if (data.status === "Succeeded") {
ElMessage.success(
t("schedulesScript.timetableChecksPassedAndItWasPublished"),
);
await loadPlans();
} else {
ElMessage.error(
data.errorMessage ||
t(
"schedulesScript.timetableChecksFailedAdjustTheScheduleAndTryAgain",
),
);
}
} catch {
if (selected.value?.id === planId) {
schedulePublishPoll(jobId, planId);
}
}
}
async function resumePublish(planId: string) {
clearPublishPoll();
publishJob.value = null;
const { data } = await http.get(`/schedules/plans/${planId}/publish-job`);
if (selected.value?.id !== planId || !data) return;
publishJob.value = data;
if (data.status === "Queued" || data.status === "Running") {
schedulePublishPoll(data.id, planId);
}
}
function clearAutoSchedulePoll() {
if (autoPollTimer) clearTimeout(autoPollTimer);
autoPollTimer = undefined;
}
function scheduleAutoSchedulePoll(jobId: string, planId: string) {
clearAutoSchedulePoll();
autoPollTimer = setTimeout(() => pollAutoScheduleJob(jobId, planId), 1000);
}
async function pollAutoScheduleJob(jobId: string, planId: string) {
try {
const { data } = await http.get(`/schedules/auto-schedule-jobs/${jobId}`);
if (selected.value?.id !== planId) return;
autoJob.value = data;
if (data.status === "Queued" || data.status === "Running") {
scheduleAutoSchedulePoll(jobId, planId);
return;
}
clearAutoSchedulePoll();
if (data.status === "Succeeded") {
await loadDetail(planId, false);
const summary = plans.value.find((item) => item.id === planId);
if (summary) summary.entryCount = selected.value.entries.length;
if (data.messages.length) {
ElMessage.warning(
t("schedulesScript.completeManual", {
entries: data.createdEntries,
tasks: data.messages.length,
}),
);
} else {
ElMessage.success(
t("schedulesScript.complete", { entries: data.createdEntries }),
);
}
} else {
ElMessage.error(
data.errorMessage ||
t("schedulesScript.backgroundSchedulingFailedTryAgainLater"),
);
}
} catch {
if (selected.value?.id === planId) {
scheduleAutoSchedulePoll(jobId, planId);
}
}
}
async function resumeAutoSchedule(planId: string) {
clearAutoSchedulePoll();
autoJob.value = null;
const { data } = await http.get(
`/schedules/plans/${planId}/auto-schedule-job`,
);
if (selected.value?.id !== planId || !data) return;
autoJob.value = data;
scheduleAutoSchedulePoll(data.id, planId);
}
async function loadPlans(keepSelection = true) {
loading.value = true;
try {
plans.value = (
await http.get("/schedules/plans", {
params: { academicTermId: termId.value },
})
).data;
const id =
keepSelection && selected.value ? selected.value.id : plans.value[0]?.id;
if (id && plans.value.some((item) => item.id === id)) {
await loadDetail(id);
} else {
selected.value = null;
clearAutoSchedulePoll();
autoJob.value = null;
clearPublishPoll();
publishJob.value = null;
}
} catch (error) {
ElMessage.error(apiErrorMessage(error));
} finally {
loading.value = false;
}
}
async function loadDetail(id: string, resumeJob = true) {
detailLoading.value = true;
try {
selected.value = (await http.get(`/schedules/plans/${id}`)).data;
if (resumeJob && selected.value.status === "Draft") {
await Promise.all([resumeAutoSchedule(id), resumePublish(id)]);
} else if (resumeJob) {
clearAutoSchedulePoll();
autoJob.value = null;
await resumePublish(id);
}
} catch (error) {
ElMessage.error(apiErrorMessage(error));
} finally {
detailLoading.value = false;
}
}
function openPlan(plan?: any) {
editingPlanId.value = plan?.id ?? "";
Object.assign(planForm, {
academicTermId: plan?.academicTermId ?? termId.value,
name: plan?.name ?? "",
version: plan?.version ?? `V${plans.value.length + 1}`,
notes: plan?.notes ?? "",
});
planDialog.value = true;
}
async function savePlan() {
if (
!planForm.academicTermId ||
!planForm.name?.trim() ||
!planForm.version?.trim()
) {
ElMessage.warning(
t("schedulesScript.enterTheTermVersionNameAndVersionNumber"),
);
return;
}
try {
if (editingPlanId.value) {
await http.put(`/schedules/plans/${editingPlanId.value}`, planForm);
} else {
await http.post("/schedules/plans", planForm);
}
planDialog.value = false;
await loadPlans(false);
} catch (error) {
ElMessage.error(apiErrorMessage(error));
}
}
function openClone() {
revisingPublishedPlan.value = selected.value.status === "Published";
Object.assign(cloneForm, {
name: `${selected.value.name}(修订版)`,
version: `V${plans.value.length + 1}`,
});
cloneDialog.value = true;
}
async function clonePlan() {
try {
const { data } = await http.post(
`/schedules/plans/${selected.value.id}/clone`,
cloneForm,
);
cloneDialog.value = false;
ElMessage.success(
revisingPublishedPlan.value
? t(
"schedulesScript.revisionDraftCreatedThePublishedTimetableRemainsActive",
)
: t("schedulesScript.copiedToAnEditableDraft"),
);
await loadPlans(false);
if (data.id && selected.value?.id !== data.id) await loadDetail(data.id);
} catch (error) {
ElMessage.error(apiErrorMessage(error));
}
}
async function publishPlan() {
try {
await ElMessageBox.confirm(
t(
"schedulesScript.allInstructorClassAndRoomConflictsWillBeCheckedPublishingLocksThisVersionAndReplacesThePreviousTimetableARevisionCanBeCreatedAfterward",
),
t("schedulesScript.publishTimetable"),
{
type: "warning",
confirmButtonText: t("schedulesScript.checkAndPublish"),
cancelButtonText: t("schedulesScript.cancel"),
},
);
const planId = selected.value.id;
const { data } = await http.post(`/schedules/plans/${planId}/publish`);
publishJob.value = data;
ElMessage.success(
t(
"schedulesScript.checkAndPublicationJobSubmittedProgressIsAvailableHere",
),
);
schedulePublishPoll(data.id, planId);
} catch (error: any) {
if (error !== "cancel" && error !== "close")
ElMessage.error(apiErrorMessage(error));
}
}
async function deletePlan() {
try {
await ElMessageBox.confirm(
t("schedulesScript.deleteThisDraftAndAllSchedulingEntries"),
t("schedulesScript.deleteSchedulingDraft"),
{
type: "warning",
},
);
await http.delete(`/schedules/plans/${selected.value.id}`);
await loadPlans(false);
} catch (error: any) {
if (error !== "cancel" && error !== "close")
ElMessage.error(apiErrorMessage(error));
}
}
function openEntry(entry?: any, day?: number, period?: number) {
editingEntryId.value = entry?.id ?? "";
Object.assign(entryForm, {
teachingTaskId: entry?.teachingTaskId,
kind: entry?.kind ?? "Lecture",
classroomId: entry?.classroomId,
dayOfWeek: entry?.dayOfWeek ?? day ?? 1,
startPeriod: entry?.startPeriod ?? period ?? 1,
periodCount: entry?.periodCount ?? 2,
startWeek: entry?.startWeek ?? 1,
endWeek: entry?.endWeek ?? 16,
weekPattern: entry?.weekPattern ?? "All",
notes: entry?.notes ?? "",
});
entryDialog.value = true;
}
function changeEntryTask() {
if (editingEntryId.value) return;
const task = selectedTaskConstraint.value;
if (!task) return;
entryForm.startWeek = task.startWeek;
entryForm.endWeek = task.endWeek;
if (
task.allowedDayOfWeeks?.length &&
!task.allowedDayOfWeeks.includes(entryForm.dayOfWeek)
) {
entryForm.dayOfWeek = task.allowedDayOfWeeks[0];
}
if (task.requiresClassroom === false && entryForm.kind !== "Experiment") {
entryForm.classroomId = null;
return;
}
const room = classrooms.value.find(
(item) => item.id === entryForm.classroomId,
);
if (
room &&
((entryForm.kind !== "Experiment" &&
task.requiredCampusId &&
room.campusId !== task.requiredCampusId) ||
(entryForm.kind !== "Experiment" &&
task.requiredBuildingId &&
room.buildingId !== task.requiredBuildingId) ||
(entryForm.kind !== "Experiment" &&
task.allowedClassroomIds?.length &&
!task.allowedClassroomIds.includes(room.id)) ||
(entryForm.kind === "Experiment" &&
task.experimentRequiredCampusId &&
room.campusId !== task.experimentRequiredCampusId) ||
(entryForm.kind === "Experiment" &&
task.experimentRequiredBuildingId &&
room.buildingId !== task.experimentRequiredBuildingId) ||
(entryForm.kind === "Experiment" &&
task.allowedExperimentClassroomIds?.length &&
!task.allowedExperimentClassroomIds.includes(room.id)))
) {
entryForm.classroomId = null;
}
}
function changeEntryKind() {
const room = classrooms.value.find(
(item) => item.id === entryForm.classroomId,
);
const task = selectedTaskConstraint.value;
if (
entryForm.kind === "Experiment" &&
room &&
task?.allowedExperimentClassroomIds?.length &&
!task.allowedExperimentClassroomIds.includes(room.id)
) {
entryForm.classroomId = null;
}
}
async function preflightSchedule() {
try {
const { data } = await http.get(
`/schedules/plans/${selected.value.id}/preflight`,
);
const message = data.unscheduledTasks
? t("schedulesScript.unscheduled", {
count: data.unscheduledTasks,
messages: data.messages.join("\n"),
})
: t(
"schedulesScript.theDraftCoversAllTeachingClassesRequiringScheduling",
);
await ElMessageBox.alert(
message,
t("schedulesScript.checkTitle", {
scheduled: data.scheduledTasks,
total: data.totalTasks,
}),
{ confirmButtonText: t("schedulesScript.ok") },
);
} catch (error) {
ElMessage.error(apiErrorMessage(error));
}
}
async function saveEntry() {
if (
!entryForm.teachingTaskId ||
((entryForm.kind === "Experiment" ||
selectedTaskConstraint.value?.requiresClassroom !== false) &&
!entryForm.classroomId)
) {
ElMessage.warning(
t("schedulesScript.selectATeachingTaskAndAClassroomIfRequired"),
);
return;
}
const task = selectedTaskConstraint.value;
if (
task &&
(entryForm.startWeek < task.startWeek || entryForm.endWeek > task.endWeek)
) {
ElMessage.warning(
t("schedulesScript.weekRange", {
start: task.startWeek,
end: task.endWeek,
}),
);
return;
}
if (
task?.allowedDayOfWeeks?.length &&
!task.allowedDayOfWeeks.includes(entryForm.dayOfWeek)
) {
ElMessage.warning(
t("schedulesScript.theSelectedDayIsNotAllowedForThisTeachingTask"),
);
return;
}
if (
entryForm.kind !== "Experiment" &&
selectedTaskConstraint.value?.requiresClassroom === false
)
entryForm.classroomId = null;
try {
const base = `/schedules/plans/${selected.value.id}/entries`;
if (editingEntryId.value)
await http.put(`${base}/${editingEntryId.value}`, entryForm);
else await http.post(base, entryForm);
entryDialog.value = false;
ElMessage.success(
editingEntryId.value
? t("schedulesScript.scheduleEntryUpdated")
: t("schedulesScript.scheduleEntryAdded"),
);
await loadDetail(selected.value.id);
} catch (error) {
ElMessage.error(apiErrorMessage(error));
}
}
async function deleteEntry(entry: any) {
try {
await ElMessageBox.confirm(
t("schedulesScript.remove", { name: entry.taskName }),
t("schedulesScript.removeScheduleEntry"),
{
type: "warning",
},
);
await http.delete(
`/schedules/plans/${selected.value.id}/entries/${entry.id}`,
);
await loadDetail(selected.value.id);
} catch (error: any) {
if (error !== "cancel" && error !== "close")
ElMessage.error(apiErrorMessage(error));
}
}
onMounted(async () => {
const [termRes, classroomRes, campusRes, buildingRes] = await Promise.all([
http.get("/base-data/terms"),
http.get("/base-data/classrooms"),
http.get("/base-data/campuses"),
http.get("/base-data/buildings"),
]);
terms.value = termRes.data;
classrooms.value = classroomRes.data.filter((item: any) => item.isEnabled);
campuses.value = campusRes.data.filter((item: any) => item.isEnabled);
buildings.value = buildingRes.data.filter((item: any) => item.isEnabled);
termId.value = defaultAcademicTermId(terms.value);
await Promise.all([loadPlans(false), loadSchedulingSettings()]);
});
onBeforeUnmount(() => {
clearAutoSchedulePoll();
clearPublishPoll();
});
</script>
<template>
<div class="page-stack">
<section class="page-intro">
<div>
<span class="section-kicker">TIMETABLE BOARD</span>
<h2>{{ t("dashboard.admin.actions.schedules.label") }}</h2>
<p>
{{
t(
"schedulesTemplate.automaticallyAssignInstructorsClassesAndVenuesUsingPeriodTimesAndCourseConstraintsThenFineTuneIndividualEntries",
)
}}
</p>
</div>
<div class="page-actions">
<el-button :icon="Setting" @click="settingsDrawer = true">{{
t("schedulesTemplate.schedulingRulesAndPeriods")
}}</el-button>
<el-button type="primary" :icon="Plus" @click="openPlan()">{{
t("schedulesTemplate.newTimetableVersion2")
}}</el-button>
</div>
</section>
<section class="schedule-toolbar">
<el-select
v-model="termId"
:placeholder="t('batchBusiness.selectTerm')"
@change="changeTerm"
>
<el-option
v-for="item in terms"
:key="item.id"
:label="academicTermLabel(item)"
:value="item.id"
:class="academicTermOptionClass(item)"
/>
</el-select>
<div class="schedule-version-strip">
<button
v-for="plan in plans"
:key="plan.id"
type="button"
:class="{ active: selected?.id === plan.id }"
@click="loadDetail(plan.id)"
>
<b>{{ plan.version }}</b>
<span>{{ statusLabels[plan.status] }}</span>
<small>{{
t("schedulesDynamic.entries", { count: plan.entryCount })
}}</small>
</button>
<span v-if="plans.length === 0">{{
t("schedulesTemplate.noTimetableVersionsForThisTerm")
}}</span>
</div>
</section>
<section v-if="selected" v-loading="detailLoading" class="schedule-sheet">
<header class="schedule-sheet-head">
<div>
<span>{{ selected.termName }} · {{ selected.version }}</span>
<h3>{{ selected.name }}</h3>
<p>
{{
t("schedulesDynamic.entriesStatus", {
count: selected.entries.length,
status: statusLabels[selected.status],
})
}}
</p>
</div>
<div class="plan-actions">
<el-button
v-if="isDraft"
:disabled="scheduleJobLoading"
@click="openPlan(selected)"
>{{ t("schedulesTemplate.editVersion") }}</el-button
>
<el-button
v-if="selected.status === 'Published'"
type="warning"
plain
:icon="EditPen"
@click="openClone"
>
{{ t("schedulesTemplate.reviseAfterPublication") }}
</el-button>
<el-button
v-else
:icon="CopyDocument"
:disabled="scheduleJobLoading"
@click="openClone"
>
{{ t("schedulesTemplate.copyAndRevise") }}
</el-button>
<el-button
v-if="isDraft"
:disabled="scheduleJobLoading"
@click="preflightSchedule"
>
{{ t("schedulesTemplate.checkBeforeScheduling") }}
</el-button>
<el-button
v-if="isDraft"
type="warning"
plain
:icon="Promotion"
:loading="autoLoading"
:disabled="publishLoading"
@click="autoSchedule"
>
{{ t("operationsBatch.automaticScheduling") }}
</el-button>
<el-button
v-if="isDraft"
type="primary"
:icon="Plus"
:disabled="scheduleJobLoading"
@click="openEntry()"
>{{ t("schedulesTemplate.addScheduleEntry") }}</el-button
>
<el-button
v-if="isDraft"
type="success"
:icon="Promotion"
:loading="publishLoading"
:disabled="autoLoading"
@click="publishPlan"
>
{{
publishLoading
? t("schedulesTemplate.checkingAndPublishing")
: t("schedulesTemplate.publishTimetable")
}}
</el-button>
<el-button
v-if="isDraft"
type="danger"
plain
:disabled="scheduleJobLoading"
@click="deletePlan"
>{{ t("workflowBatch.deleteDraft") }}</el-button
>
</div>
</header>
<div
v-if="autoJob"
class="auto-schedule-progress"
:class="`is-${String(autoJob.status).toLowerCase()}`"
>
<div>
<b>{{ autoStatusText }}</b>
<span v-if="autoJob.status === 'Running'">
{{
t("schedulesTemplate.theBackgroundJobContinuesIfYouLeaveThisPage")
}}
</span>
<span
v-else-if="
autoJob.status === 'Succeeded' && autoJob.messages.length
"
>
{{
t("schedulesDynamic.manual", { count: autoJob.messages.length })
}}
</span>
</div>
<el-progress
:percentage="autoProgress"
:status="autoProgressStatus"
:indeterminate="autoJob.status === 'Queued'"
:duration="2"
/>
<div
v-if="autoJob.status === 'Succeeded' && autoJob.messages.length"
class="auto-schedule-issues"
>
<div class="auto-schedule-issues-head">
<b>{{
t("schedulesTemplate.unscheduledTasksAndRecommendations")
}}</b>
<el-button
size="small"
type="warning"
plain
@click="openManualHandling"
>
{{ t("schedulesTemplate.checkSchedulingConstraints") }}
</el-button>
</div>
<ol>
<li v-for="message in autoJob.messages" :key="message">
{{ message }}
</li>
</ol>
</div>
</div>
<div
v-if="publishJob"
class="auto-schedule-progress"
:class="`is-${String(publishJob.status).toLowerCase()}`"
>
<div>
<b>{{ publishStatusText }}</b>
<span v-if="publishLoading">{{
t("schedulesTemplate.theBackgroundJobContinuesIfYouLeaveThisPage")
}}</span>
<span v-else-if="publishJob.status === 'Failed'">
{{
t(
"schedulesTemplate.theDraftWasNotPublishedAddressTheReasonsAboveAndTryAgain",
)
}}
</span>
</div>
<el-progress
:percentage="publishProgress"
:status="publishProgressStatus"
:indeterminate="publishJob.status === 'Queued'"
:duration="2"
/>
</div>
<div class="schedule-search">
<el-input
v-model="keyword"
:prefix-icon="Search"
clearable
:placeholder="
t(
'schedulesTemplate.filterByCourseInstructorAdministrativeClassOrClassroom',
)
"
/>
<el-button :icon="Refresh" @click="keyword = ''">{{
t("schedulesTemplate.clearFilters")
}}</el-button>
<span>{{
t("schedulesTemplate.oddEvenWeeksAndWeekRangesAppearOnCourseCards")
}}</span>
</div>
<div class="timetable-scroll">
<div class="timetable-grid">
<div class="timetable-corner">{{ t("attendanceBatch.period") }}</div>
<div v-for="day in weekdays" :key="day.value" class="timetable-day">
{{ day.label }}
</div>
<template v-for="period in periods" :key="period">
<div class="timetable-period">
<b>{{ period }}</b>
<span>{{ timeLabel(period) }}</span>
</div>
<div
v-for="day in weekdays"
:key="`${day.value}-${period}`"
class="timetable-cell"
:class="{ editable: isDraft }"
@dblclick="isDraft && openEntry(undefined, day.value, period)"
>
<article
v-for="entry in entriesAt(day.value, period)"
:key="entry.id"
class="schedule-card"
:class="{
readonly: !isDraft,
experiment: entry.kind === 'Experiment',
}"
@click="isDraft && openEntry(entry)"
>
<span>
{{
entry.kind === "Experiment"
? t("attendanceBatch.labClass")
: t("schedulesTemplate.lecture")
}}
· {{ entry.courseCode }} ·
{{ patternLabels[entry.weekPattern] }}
</span>
<b>{{ entry.courseName }}</b>
<small
>{{ entry.teacherNames.join("、") }} ·
{{
entry.classroomName ||
t("schedulesTemplate.noClassroomRequired")
}}</small
>
<i>{{
t("schedulesDynamic.weekPeriods", {
start: entry.startWeek,
end: entry.endWeek,
count: entry.periodCount,
})
}}</i>
<button
v-if="isDraft"
type="button"
@click.stop="deleteEntry(entry)"
>
×
</button>
</article>
<span
v-if="isDraft && entriesAt(day.value, period).length === 0"
class="cell-add"
>{{ t("schedulesTemplate.doubleClickToAdd") }}</span
>
</div>
</template>
</div>
</div>
</section>
<el-empty
v-else
:description="t('schedulesTemplate.selectOrCreateATimetableVersion')"
/>
<el-dialog
v-model="planDialog"
:title="
editingPlanId
? t('schedulesTemplate.editTimetableVersion')
: t('schedulesTemplate.newTimetableVersion2')
"
width="560px"
>
<el-form label-position="top">
<el-form-item :label="t('businessLabels.term')" required
><el-select v-model="planForm.academicTermId"
><el-option
v-for="item in terms"
:key="item.id"
:label="academicTermLabel(item)"
:value="item.id"
:class="academicTermOptionClass(item)" /></el-select
></el-form-item>
<el-form-item :label="t('schedulesTemplate.versionName')" required
><el-input
v-model="planForm.name"
:placeholder="
t('schedulesTemplate.forExampleFirstPublishedTimetable')
"
/></el-form-item>
<el-form-item :label="t('batchBusiness.version')" required
><el-input
v-model="planForm.version"
:placeholder="t('schedulesDynamic.versionExample')"
/></el-form-item>
<el-form-item :label="t('businessLabels.notes')"
><el-input v-model="planForm.notes" type="textarea" :rows="2"
/></el-form-item>
</el-form>
<template #footer
><el-button @click="planDialog = false">{{
t("businessLabels.cancel")
}}</el-button
><el-button type="primary" @click="savePlan">{{
t("businessLabels.save")
}}</el-button></template
>
</el-dialog>
<el-dialog
v-model="cloneDialog"
:title="
revisingPublishedPlan
? t('schedulesTemplate.revisePublishedTimetable')
: t('schedulesTemplate.copyTimetableVersion')
"
width="520px"
>
<el-alert
v-if="revisingPublishedPlan"
:title="
t(
'schedulesTemplate.anEditableRevisionDraftIsCreatedTheOriginalTimetableRemainsInEffectForTeachersAndStudentsUntilTheRevisionIsPublished',
)
"
type="info"
:closable="false"
show-icon
/>
<el-form label-position="top">
<el-form-item :label="t('schedulesTemplate.newVersionName')" required
><el-input v-model="cloneForm.name"
/></el-form-item>
<el-form-item :label="t('batchBusiness.newVersion')" required
><el-input v-model="cloneForm.version"
/></el-form-item>
</el-form>
<template #footer>
<el-button @click="cloneDialog = false">{{
t("businessLabels.cancel")
}}</el-button>
<el-button type="primary" @click="clonePlan">
{{
revisingPublishedPlan
? t("schedulesTemplate.createRevisionDraft")
: t("venueManager.copy")
}}
</el-button>
</template>
</el-dialog>
<el-dialog
v-model="entryDialog"
:title="
editingEntryId
? t('schedulesTemplate.editScheduleEntry')
: t('schedulesTemplate.addScheduleEntry')
"
width="680px"
>
<el-form label-position="top">
<el-form-item :label="t('dashboard.teacher.teachingTasks')" required>
<el-select
v-model="entryForm.teachingTaskId"
filterable
@change="changeEntryTask"
>
<el-option
v-for="item in tasks"
:key="item.id"
:label="`${item.taskNumber} · ${item.name}`"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.sessionType')" required>
<el-radio-group v-model="entryForm.kind" @change="changeEntryKind">
<el-radio-button value="Lecture">{{
t("schedulesTemplate.lecture")
}}</el-radio-button>
<el-radio-button
value="Experiment"
:disabled="!selectedTaskConstraint?.coursePracticeHours"
>
{{ t("attendanceBatch.labClass") }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-alert
v-if="selectedTaskConstraint"
:title="
t('schedulesDynamic.constraint', {
total: selectedTaskConstraint.courseTotalHours,
theory:
selectedTaskConstraint.courseTotalHours -
selectedTaskConstraint.coursePracticeHours,
practice: selectedTaskConstraint.coursePracticeHours,
start: selectedTaskConstraint.startWeek,
end: selectedTaskConstraint.endWeek,
days: entryWeekdays.map((day) => day.label).join(', '),
})
"
type="info"
:closable="false"
show-icon
/>
<el-alert
v-if="
selectedTaskConstraint?.requiresClassroom === false &&
entryForm.kind !== 'Experiment'
"
:title="
t(
'schedulesTemplate.thisCourseDoesNotUseAClassroomInstructorAndAdministrativeClassConflictsAreStillChecked',
)
"
type="info"
:closable="false"
show-icon
/>
<el-form-item
v-else
:label="
entryForm.kind === 'Experiment'
? t('classroomReservation.kicker')
: t('baseData.classroom')
"
required
:hint="
selectedTaskConstraint?.requiredBuildingId
? t('schedulesTemplate.showOnlyClassroomsAllowedByConstraints')
: ''
"
>
<el-select v-model="entryForm.classroomId" filterable>
<el-option
v-for="item in entryClassrooms"
:key="item.id"
:label="
t('schedulesDynamic.roomFull', {
campus: item.campusName,
building: item.buildingName,
name: item.name,
type: item.roomType,
capacity: item.capacity,
})
"
:value="item.id"
/>
</el-select>
</el-form-item>
<div class="form-grid three">
<el-form-item :label="t('freeClassrooms.weekday')"
><el-select v-model="entryForm.dayOfWeek"
><el-option
v-for="day in entryWeekdays"
:key="day.value"
:label="day.label"
:value="day.value" /></el-select
></el-form-item>
<el-form-item :label="t('freeClassrooms.startPeriod')">
<el-select v-model="entryForm.startPeriod">
<el-option
v-for="period in periods"
:key="period"
:label="
t('schedulesDynamic.periodTime', {
period,
time: timeLabel(period),
})
"
:value="period"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('freeClassrooms.periodCount')"
><el-input-number v-model="entryForm.periodCount" :min="1" :max="6"
/></el-form-item>
</div>
<div class="form-grid three">
<el-form-item :label="t('batchBusiness.startWeek')"
><el-input-number v-model="entryForm.startWeek" :min="1" :max="30"
/></el-form-item>
<el-form-item :label="t('batchBusiness.endWeek')"
><el-input-number v-model="entryForm.endWeek" :min="1" :max="30"
/></el-form-item>
<el-form-item :label="t('schedulesTemplate.oddEvenWeeks')"
><el-select v-model="entryForm.weekPattern"
><el-option
v-for="(label, value) in patternLabels"
:key="value"
:label="label"
:value="value" /></el-select
></el-form-item>
</div>
<el-form-item :label="t('businessLabels.notes')"
><el-input v-model="entryForm.notes" type="textarea" :rows="2"
/></el-form-item>
</el-form>
<template #footer
><el-button @click="entryDialog = false">{{
t("businessLabels.cancel")
}}</el-button
><el-button type="primary" @click="saveEntry">{{
t("schedulesTemplate.checkConflictsAndSave")
}}</el-button></template
>
</el-dialog>
<el-drawer
v-model="settingsDrawer"
:title="t('schedulesTemplate.schedulingRulesAndPeriods')"
size="760px"
class="schedule-settings-drawer"
>
<el-tabs v-model="settingsTab">
<el-tab-pane
:label="t('schedulesTemplate.periodTimetable')"
name="time"
>
<div class="settings-lead">
<div>
<b>{{ t("schedulesTemplate.periodTimetable") }}</b>
<span>{{
t(
"schedulesTemplate.periodStartAndEndTimesAndAvailabilityForThisTermAutomaticSchedulingUsesEnabledPeriodsOnly",
)
}}</span>
</div>
<div>
<el-button
v-if="!timeSlots.length"
@click="initializeTimeSlots"
>{{ t("schedulesTemplate.loadStandardPeriods") }}</el-button
>
<el-button @click="addTimeSlot">{{
t("schedulesTemplate.addPeriod")
}}</el-button>
<el-button type="primary" @click="saveTimeSlots">{{
t("schedulesTemplate.saveTimetable")
}}</el-button>
</div>
</div>
<el-table :data="timeSlots" class="settings-table">
<el-table-column :label="t('attendanceBatch.period')" width="100">
<template #default="{ row }"
><el-input-number
v-model="row.periodNumber"
:min="1"
:max="30"
controls-position="right"
/></template>
</el-table-column>
<el-table-column :label="t('baseData.name')" min-width="130">
<template #default="{ row }"
><el-input v-model="row.name"
/></template>
</el-table-column>
<el-table-column :label="t('schedulesTemplate.start')" width="130">
<template #default="{ row }"
><el-time-select
v-model="row.startsAt"
start="06:00"
step="00:05"
end="23:00"
/></template>
</el-table-column>
<el-table-column :label="t('schedulesTemplate.end')" width="130">
<template #default="{ row }"
><el-time-select
v-model="row.endsAt"
start="06:00"
step="00:05"
end="23:00"
/></template>
</el-table-column>
<el-table-column
:label="t('schedulesTemplate.availableForScheduling')"
width="90"
>
<template #default="{ row }"
><el-switch v-model="row.isEnabled"
/></template>
</el-table-column>
<el-table-column width="60">
<template #default="{ $index }"
><el-button
link
type="danger"
@click="timeSlots.splice($index, 1)"
>{{ t("businessLabels.remove") }}</el-button
></template
>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane
:label="t('schedulesTemplate.automaticSchedulingOptimization')"
name="optimization"
>
<div class="settings-lead">
<div>
<b>{{ t("schedulesTemplate.geneticAlgorithmStrategy") }}</b>
<span>{{
t(
"schedulesTemplate.theGeneticAlgorithmSearchesForAGlobalScheduleWhileHonoringHardConstraintsHigherWeightsDiscourageTheCorrespondingSituationSetTo0ToDisableAPreference",
)
}}</span>
</div>
<el-button
type="primary"
:loading="optimizationSaving"
@click="saveOptimizationSettings"
>
{{ t("schedulesTemplate.saveOptimizationSettings") }}
</el-button>
</div>
<el-alert
:title="
t(
'schedulesTemplate.theseSettingsApplyOnlyToFutureAutomaticSchedulingJobsAndDoNotChangeGeneratedOrPublishedSchedules',
)
"
type="info"
:closable="false"
show-icon
/>
<el-form label-position="top" class="optimization-form">
<div class="form-grid">
<el-form-item
:label="t('schedulesTemplate.instructorSameDayPenalty')"
>
<el-input-number
v-model="optimizationSettings.teacherSameDayWeight"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.preferSpreadingAnInstructorSClassesAcrossDays",
)
}}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.classSameDayPenalty')">
<el-input-number
v-model="optimizationSettings.classSameDayWeight"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.avoidConcentratingAnAdministrativeClassSCoursesOnOneDay",
)
}}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.classGapPenalty')">
<el-input-number
v-model="optimizationSettings.classGapWeight"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.preferPeriodsAdjacentToExistingSameDayClassesToReduceGaps",
)
}}</small>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.classConsecutiveCoursePenalty')"
>
<el-input-number
v-model="optimizationSettings.consecutiveClassWeight"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.avoidBackToBackDifferentCoursesACourseSOwnDoublePeriodsAreUnaffected",
)
}}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.firstPeriodPenalty')">
<el-input-number
v-model="optimizationSettings.earlyPeriodPenalty"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.reduceTheLikelihoodOfUsingTheFirstPeriodWhenAlternativesExist",
)
}}</small>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.lastPeriodPenalty')">
<el-input-number
v-model="optimizationSettings.latePeriodPenalty"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.reduceTheLikelihoodOfUsingTheLastPeriodWhenAlternativesExist",
)
}}</small>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.classroomCapacitySurplusWeight')"
>
<el-input-number
v-model="optimizationSettings.roomCapacityWasteWeight"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.preferAvailableClassroomsWhoseCapacityBetterFitsTheClassSize",
)
}}</small>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.coursePreferenceWeight')"
>
<el-input-number
v-model="optimizationSettings.coursePreferenceWeight"
:min="0"
:max="10000"
/>
<small class="field-hint">{{
t("schedulesTemplate.preferConfiguredCourseDaysAndPeriods")
}}</small>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.geneticAlgorithmPopulationSize')"
>
<el-input-number
v-model="optimizationSettings.geneticPopulationSize"
:min="12"
:max="64"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.numberOfCandidatesPerGenerationHigherValuesBroadenTheSearchAndIncreaseRuntime",
)
}}</small>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.geneticAlgorithmGenerations')"
>
<el-input-number
v-model="optimizationSettings.geneticGenerationCount"
:min="12"
:max="160"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.moreGenerationsCanImproveTheScheduleButIncreaseRuntime",
)
}}</small>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.geneticAlgorithmMutationRate')"
>
<el-input-number
v-model="optimizationSettings.geneticMutationRatePercent"
:min="1"
:max="50"
/>
<small class="field-hint">{{
t(
"schedulesTemplate.percentageOfSessionsRandomlyChangedPerGenerationToEscapeLocalOptima",
)
}}</small>
</el-form-item>
</div>
</el-form>
</el-tab-pane>
<el-tab-pane
:label="t('schedulesTemplate.courseSchedulingConstraints')"
name="constraints"
>
<div class="settings-lead">
<div>
<b>{{ t("schedulesTemplate.courseSchedulingConstraints") }}</b>
<span>{{
t(
"schedulesTemplate.bulkEditFilteredResultsFlexibleCoursesDoNotOccupyRegularTimesOrVenues",
)
}}</span>
</div>
<div>
<el-button @click="resetConstraintFilters">{{
t("schedulesTemplate.resetFilters")
}}</el-button>
<el-button
type="primary"
:disabled="!filteredConstraints.length"
@click="openConstraintBatch"
>{{
t("schedulesDynamic.bulkTitle", {
count: filteredConstraints.length,
})
}}</el-button
>
</div>
</div>
<div class="constraint-filter-grid">
<el-input
v-model="constraintFilters.keyword"
clearable
:placeholder="t('schedulesTemplate.taskCourseOrInstructor')"
:prefix-icon="Search"
/>
<el-select
v-model="constraintFilters.collegeId"
clearable
:placeholder="t('batchBusiness.allOfferingDepartments')"
>
<el-option
v-for="item in constraintColleges"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
<el-select
v-model="constraintFilters.schedulingMode"
clearable
:placeholder="t('schedulesTemplate.allTeachingModes')"
>
<el-option
:label="t('workflowBatch.regularScheduling')"
value="Standard"
/>
<el-option
:label="t('workflowBatch.flexibleCourse')"
value="Flexible"
/>
</el-select>
<el-select
v-model="constraintFilters.classroomMode"
clearable
:placeholder="t('schedulesTemplate.allVenueRequirements')"
>
<el-option
:label="t('schedulesTemplate.classroomRequired')"
value="required"
/>
<el-option
:label="t('schedulesTemplate.noClassroomRequired2')"
value="not-required"
/>
</el-select>
<el-select
v-model="constraintFilters.constraintState"
clearable
:placeholder="t('schedulesTemplate.allConstraintStatuses')"
>
<el-option
:label="t('schedulesTemplate.customConstraints')"
value="custom"
/>
<el-option
:label="t('schedulesTemplate.defaultConstraints')"
value="default"
/>
</el-select>
</div>
<div class="constraint-result-summary">
{{
t("schedulesDynamic.taskCounts", {
total: constraints.length,
shown: filteredConstraints.length,
})
}}
</div>
<div class="constraint-list">
<article v-for="item in filteredConstraints" :key="item.id">
<div>
<span>{{
t("schedulesDynamic.weeklyHours", {
number: item.taskNumber,
hours: item.weeklyHours,
})
}}</span>
<b>{{ item.name }} · {{ item.courseName }}</b>
<small
>{{ item.collegeName }} ·
{{
item.teacherNames.join("、") ||
t("schedulesTemplate.noInstructorAssigned")
}}
· {{ item.capacity }}
{{ t("graduationAudits.people") }}</small
>
</div>
<div class="constraint-badges">
<el-tag
v-if="item.schedulingMode === 'Flexible'"
type="success"
>{{ t("workflowBatch.flexibleCourse") }}</el-tag
>
<el-tag :type="item.requiresClassroom ? 'primary' : 'info'">
{{
item.requiresClassroom
? t("schedulesTemplate.usesClassroom")
: t("schedulesTemplate.noClassroomRequired2")
}}
</el-tag>
<el-tag v-if="item.requiredBuildingId" type="warning">{{
t("schedulesTemplate.restrictBuilding")
}}</el-tag>
<el-tag v-if="item.allowedClassroomIds.length" type="warning">
{{
t("schedulesDynamic.specifiedRooms", {
count: item.allowedClassroomIds.length,
})
}}
</el-tag>
</div>
<el-button @click="openConstraint(item)">{{
t("schedulesTemplate.setConstraints")
}}</el-button>
</article>
<el-empty
v-if="!filteredConstraints.length"
:description="
t('schedulesTemplate.noTeachingTasksMatchTheFilters')
"
/>
</div>
</el-tab-pane>
</el-tabs>
</el-drawer>
<el-dialog
v-model="constraintDialog"
:title="t('schedulesTemplate.setCourseSchedulingConstraints')"
width="720px"
>
<div class="constraint-title">{{ constraintForm.title }}</div>
<el-form label-position="top">
<el-form-item :label="t('batchBusiness.teachingMode')">
<el-radio-group v-model="constraintForm.schedulingMode">
<el-radio-button value="Standard">{{
t("workflowBatch.regularScheduling")
}}</el-radio-button>
<el-radio-button value="Flexible">{{
t("workflowBatch.flexibleCourse")
}}</el-radio-button>
</el-radio-group>
<small class="field-hint">{{
t(
"schedulesTemplate.flexibleCoursesAreExcludedFromAutomaticSchedulingAndShownSeparatelyOnClassAndPersonalTimetables",
)
}}</small>
</el-form-item>
<template v-if="constraintForm.schedulingMode === 'Standard'">
<el-form-item>
<el-switch
v-model="constraintForm.requiresClassroom"
:active-text="t('schedulesTemplate.classroomRequired2')"
in:active-text="t('schedulesTemplate.noClassroomRequired')"
/>
</el-form-item>
<template v-if="constraintForm.requiresClassroom">
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.restrictCampus')">
<el-select
v-model="constraintForm.requiredCampusId"
clearable
@change="
constraintForm.requiredBuildingId = undefined;
constraintForm.allowedClassroomIds = [];
"
>
<el-option
v-for="item in campuses"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.restrictBuilding')">
<el-select
v-model="constraintForm.requiredBuildingId"
clearable
@change="constraintForm.allowedClassroomIds = []"
>
<el-option
v-for="item in filteredBuildings"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
<el-form-item
:label="t('schedulesTemplate.selectAvailableClassrooms')"
>
<el-select
v-model="constraintForm.allowedClassroomIds"
multiple
filterable
collapse-tags
>
<el-option
v-for="item in filteredClassrooms"
:key="item.id"
:label="
t('schedulesDynamic.room', {
building: item.buildingName,
name: item.name,
capacity: item.capacity,
})
"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.allowedLabVenueTypes')">
<el-checkbox-group
v-model="constraintForm.allowedExperimentVenueNatures"
>
<el-checkbox
v-for="nature in experimentVenueNatures"
:key="nature.value"
:value="nature.value"
>{{ nature.label }}</el-checkbox
>
</el-checkbox-group>
<small class="field-hint">{{
t(
"schedulesTemplate.appliesOnlyToLabSessionsIfNoneAreSelectedAllLabTeachingVenuesAreAllowed",
)
}}</small>
</el-form-item>
<section
v-if="constraintForm.coursePracticeHours"
class="experiment-classroom-scope"
>
<div class="experiment-classroom-scope__title">
{{ t("schedulesTemplate.selectAvailableLabVenues") }}
</div>
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.restrictLabCampus')">
<el-select
v-model="constraintForm.experimentRequiredCampusId"
clearable
@change="
constraintForm.experimentRequiredBuildingId = undefined;
constraintForm.allowedExperimentClassroomIds = [];
"
>
<el-option
v-for="item in campuses"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.restrictLabBuilding')"
>
<el-select
v-model="constraintForm.experimentRequiredBuildingId"
clearable
@change="constraintForm.allowedExperimentClassroomIds = []"
>
<el-option
v-for="item in filteredExperimentBuildings"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
<el-form-item
:label="t('schedulesTemplate.selectAvailableLabVenues')"
>
<el-select
v-model="constraintForm.allowedExperimentClassroomIds"
multiple
filterable
collapse-tags
>
<el-option
v-for="item in filteredExperimentClassrooms"
:key="item.id"
:label="
t('schedulesDynamic.roomType', {
building: item.buildingName,
name: item.name,
type: item.roomType,
capacity: item.capacity,
})
"
:value="item.id"
/>
</el-select>
<small class="field-hint">{{
t(
"schedulesTemplate.chooseLabsWithinTheAllowedVenueTypesLeaveEmptyToFilterAutomaticallyByType",
)
}}</small>
</el-form-item>
</section>
</template>
<el-form-item :label="t('schedulesTemplate.allowedTeachingDays')">
<el-checkbox-group v-model="constraintForm.allowedDayOfWeeks">
<el-checkbox
v-for="day in weekdays"
:key="day.value"
:value="day.value"
>{{ day.label }}</el-checkbox
>
</el-checkbox-group>
</el-form-item>
<div class="form-grid">
<el-form-item :label="t('schedulesTemplate.earliestStartPeriod')">
<el-select v-model="constraintForm.earliestPeriod" clearable>
<el-option
v-for="period in periods"
:key="period"
:label="
t('schedulesDynamic.periodTime', {
period,
time: timeLabel(period),
})
"
:value="period"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.latestEndPeriod')">
<el-select v-model="constraintForm.latestPeriod" clearable>
<el-option
v-for="period in periods"
:key="period"
:label="
t('schedulesDynamic.periodTime', {
period,
time: timeLabel(period),
})
"
:value="period"
/>
</el-select>
</el-form-item>
</div>
<el-divider content-position="left">{{
t("schedulesTemplate.schedulingPreferencesOptional")
}}</el-divider>
<el-form-item :label="t('schedulesTemplate.preferredDays')">
<el-checkbox-group v-model="constraintForm.preferredDayOfWeeks">
<el-checkbox
v-for="day in weekdays"
:key="day.value"
:value="day.value"
>{{ day.label }}</el-checkbox
>
</el-checkbox-group>
<small class="field-hint">{{
t(
"schedulesTemplate.notAHardConstraintTheAlgorithmPrefersTheseDaysWhenConflictFree",
)
}}</small>
</el-form-item>
<div class="form-grid">
<el-form-item
:label="t('schedulesTemplate.preferredEarliestStart')"
>
<el-select
v-model="constraintForm.preferredEarliestPeriod"
clearable
>
<el-option
v-for="period in periods"
:key="period"
:label="
t('schedulesDynamic.periodTime', {
period,
time: timeLabel(period),
})
"
:value="period"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.preferredLatestEnd')">
<el-select
v-model="constraintForm.preferredLatestPeriod"
clearable
>
<el-option
v-for="period in periods"
:key="period"
:label="
t('schedulesDynamic.periodTime', {
period,
time: timeLabel(period),
})
"
:value="period"
/>
</el-select>
</el-form-item>
</div>
</template>
</el-form>
<template #footer>
<el-button @click="constraintDialog = false">{{
t("businessLabels.cancel")
}}</el-button>
<el-button type="primary" @click="saveConstraint">{{
t("schedulesTemplate.saveConstraints")
}}</el-button>
</template>
</el-dialog>
<el-dialog
v-model="constraintBatchDialog"
:title="t('schedulesTemplate.bulkEditFilteredResults')"
width="720px"
>
<div class="constraint-title">
{{
t("schedulesDynamic.affects", { count: filteredConstraints.length })
}}
</div>
<el-alert
:title="
t(
'schedulesTemplate.selectOnlySettingsToChangeUnselectedSettingsKeepTheirValues',
)
"
type="info"
:closable="false"
show-icon
/>
<el-form label-position="top" class="constraint-batch-form">
<el-checkbox v-model="constraintBatchForm.updateSchedulingMode">{{
t("schedulesTemplate.changeTeachingMode")
}}</el-checkbox>
<el-form-item
v-if="constraintBatchForm.updateSchedulingMode"
:label="t('schedulesTemplate.setTeachingMode')"
>
<el-radio-group v-model="constraintBatchForm.schedulingMode">
<el-radio-button value="Standard">{{
t("workflowBatch.regularScheduling")
}}</el-radio-button>
<el-radio-button value="Flexible">{{
t("workflowBatch.flexibleCourse")
}}</el-radio-button>
</el-radio-group>
</el-form-item>
<template
v-if="
!(
constraintBatchForm.updateSchedulingMode &&
constraintBatchForm.schedulingMode === 'Flexible'
)
"
>
<el-checkbox v-model="constraintBatchForm.updateRequiresClassroom">{{
t("schedulesTemplate.changeVenueRequirement")
}}</el-checkbox>
<el-form-item
v-if="constraintBatchForm.updateRequiresClassroom"
:label="t('schedulesTemplate.setVenueRequirement')"
>
<el-switch
v-model="constraintBatchForm.requiresClassroom"
:active-text="t('schedulesTemplate.classroomRequired2')"
in:active-text="t('schedulesTemplate.noClassroomRequired')"
@change="
!constraintBatchForm.requiresClassroom &&
(constraintBatchForm.updateClassroomScope = false)
"
/>
</el-form-item>
<template
v-if="
!(
constraintBatchForm.updateRequiresClassroom &&
!constraintBatchForm.requiresClassroom
)
"
>
<el-checkbox v-model="constraintBatchForm.updateClassroomScope">
{{ t("schedulesTemplate.setClassroomScopeInBulk") }}
</el-checkbox>
<div
v-if="constraintBatchForm.updateClassroomScope"
class="batch-classroom-scope"
>
<el-alert
:title="
t(
'schedulesTemplate.setsClassroomRequiredLeavingCampusBuildingAndClassroomsEmptyClearsExistingRestrictionsAndPermitsAutomaticAssignment',
)
"
type="warning"
:closable="false"
show-icon
/>
<div class="form-grid">
<el-form-item
:label="t('schedulesTemplate.setCampusRestriction')"
>
<el-select
v-model="constraintBatchForm.requiredCampusId"
clearable
@change="
constraintBatchForm.requiredBuildingId = undefined;
constraintBatchForm.allowedClassroomIds = [];
"
>
<el-option
v-for="item in campuses"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.setBuildingRestriction')"
>
<el-select
v-model="constraintBatchForm.requiredBuildingId"
clearable
@change="constraintBatchForm.allowedClassroomIds = []"
>
<el-option
v-for="item in batchFilteredBuildings"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
<el-form-item
:label="t('schedulesTemplate.setAvailableClassrooms')"
>
<el-select
v-model="constraintBatchForm.allowedClassroomIds"
multiple
filterable
collapse-tags
collapse-tags-tooltip
:placeholder="
t('schedulesTemplate.leaveEmptyToAllowAnyClassroomInScope')
"
>
<el-option
v-for="item in batchFilteredClassrooms"
:key="item.id"
:label="
t('schedulesDynamic.room', {
building: item.buildingName,
name: item.name,
capacity: item.capacity,
})
"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
</template>
<el-checkbox
v-model="constraintBatchForm.updateExperimentClassroomScope"
>
{{ t("schedulesTemplate.setLabVenuesInBulk") }}
</el-checkbox>
<div
v-if="constraintBatchForm.updateExperimentClassroomScope"
class="batch-classroom-scope"
>
<el-alert
:title="
t(
'schedulesTemplate.appliesOnlyToTasksWithLabHoursWithoutSpecificVenuesAssignmentUsesVenueTypes',
)
"
type="warning"
:closable="false"
show-icon
/>
<el-form-item
:label="t('schedulesTemplate.setAllowedLabVenueTypes')"
>
<el-checkbox-group
v-model="constraintBatchForm.allowedExperimentVenueNatures"
>
<el-checkbox
v-for="nature in experimentVenueNatures"
:key="nature.value"
:value="nature.value"
>{{ nature.label }}</el-checkbox
>
</el-checkbox-group>
</el-form-item>
<div class="form-grid">
<el-form-item
:label="t('schedulesTemplate.setLabCampusRestriction')"
>
<el-select
v-model="constraintBatchForm.experimentRequiredCampusId"
clearable
@change="
constraintBatchForm.experimentRequiredBuildingId =
undefined;
constraintBatchForm.allowedExperimentClassroomIds = [];
"
>
<el-option
v-for="item in campuses"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item
:label="t('schedulesTemplate.setLabBuildingRestriction')"
>
<el-select
v-model="constraintBatchForm.experimentRequiredBuildingId"
clearable
@change="
constraintBatchForm.allowedExperimentClassroomIds = []
"
>
<el-option
v-for="item in batchFilteredExperimentBuildings"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
<el-form-item :label="t('schedulesTemplate.setAvailableLabVenues')">
<el-select
v-model="constraintBatchForm.allowedExperimentClassroomIds"
multiple
filterable
collapse-tags
:placeholder="
t(
'schedulesTemplate.leaveEmptyToAllowAnyLabVenueOfAnAllowedType',
)
"
>
<el-option
v-for="item in batchFilteredExperimentClassrooms"
:key="item.id"
:label="
t('schedulesDynamic.roomType', {
building: item.buildingName,
name: item.name,
type: item.roomType,
capacity: item.capacity,
})
"
:value="item.id"
/>
</el-select>
</el-form-item>
</div>
<el-checkbox v-model="constraintBatchForm.updateDays">{{
t("schedulesTemplate.changeAllowedDays")
}}</el-checkbox>
<el-form-item
v-if="constraintBatchForm.updateDays"
:label="t('schedulesTemplate.setAllowedTeachingDays')"
>
<el-checkbox-group v-model="constraintBatchForm.allowedDayOfWeeks">
<el-checkbox
v-for="day in weekdays"
:key="day.value"
:value="day.value"
>{{ day.label }}</el-checkbox
>
</el-checkbox-group>
</el-form-item>
<el-checkbox v-model="constraintBatchForm.updatePeriodRange">{{
t("schedulesTemplate.changePeriodRange")
}}</el-checkbox>
<div v-if="constraintBatchForm.updatePeriodRange" class="form-grid">
<el-form-item
:label="t('schedulesTemplate.setEarliestStartPeriod')"
>
<el-select v-model="constraintBatchForm.earliestPeriod" clearable>
<el-option
v-for="period in periods"
:key="period"
:label="t('schedulesDynamic.period', { period })"
:value="period"
/>
</el-select>
</el-form-item>
<el-form-item :label="t('schedulesTemplate.setLatestEndPeriod')">
<el-select v-model="constraintBatchForm.latestPeriod" clearable>
<el-option
v-for="period in periods"
:key="period"
:label="t('schedulesDynamic.period', { period })"
:value="period"
/>
</el-select>
</el-form-item>
</div>
</template>
</el-form>
<template #footer>
<el-button @click="constraintBatchDialog = false">{{
t("businessLabels.cancel")
}}</el-button>
<el-button
type="primary"
:loading="constraintBatchSaving"
@click="saveConstraintBatch"
>
{{ t("schedulesTemplate.updateFilteredResults") }}
</el-button>
</template>
</el-dialog>
</div>
</template>