This commit is contained in:
+14
-9
@@ -18,6 +18,7 @@ import parseTeachers from "../utils/parseTeachers.js"
|
||||
import ExcelJS, { Worksheet, Cell, Row, Workbook } from "exceljs"
|
||||
import JSZip from "jszip";
|
||||
import { parseStringPromise } from "xml2js";
|
||||
import getAnnouncements, { Flag } from "../api/annoucements.js";
|
||||
|
||||
interface ThemeColors {
|
||||
[key: number]: string | null;
|
||||
@@ -123,11 +124,13 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
|
||||
|
||||
const upcoming = getUpcomingSheets(workbook);
|
||||
const resolvedDays = groupSheetsByDate(upcoming);
|
||||
const getDates = resolvedDays.map((d) => d.dateKey);
|
||||
const annoucements = await getAnnouncements(getDates);
|
||||
|
||||
const schedule: any = {};
|
||||
|
||||
for (const { dateKey, sheet } of resolvedDays) {
|
||||
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors);
|
||||
const { changes, absence, inWork, takesPlace, reservedRooms } = extractDaySchedule(sheet, teacherMap, themeColors, annoucements[dateKey].map(a => a.flags).flat());
|
||||
|
||||
schedule[dateKey] = {
|
||||
info: { inWork },
|
||||
@@ -140,6 +143,7 @@ export default async function parseV3(workbook: Workbook, downloadedFilePath: st
|
||||
|
||||
const data = {
|
||||
status: { lastUpdated: formatNowTime() },
|
||||
annoucements,
|
||||
schedule,
|
||||
};
|
||||
|
||||
@@ -202,9 +206,9 @@ function groupSheetsByDate(items: ResolvedDay[]) {
|
||||
// ────────────────────────────────────────────────────────────
|
||||
//
|
||||
|
||||
function extractDaySchedule(sheet: Worksheet, teacherMap: Record<string, string>, themeColors: ThemeColors | null) {
|
||||
function extractDaySchedule(sheet: Worksheet, teacherMap: Record<string, string>, themeColors: ThemeColors | null, flags: Flag[]) {
|
||||
return {
|
||||
changes: extractClassChanges(sheet, themeColors),
|
||||
changes: extractClassChanges(sheet, themeColors, flags),
|
||||
absence: extractAbsence(sheet, teacherMap),
|
||||
inWork: isPripravaSheet(sheet.name.toLowerCase()),
|
||||
takesPlace: extractTakesPlace(sheet),
|
||||
@@ -226,7 +230,8 @@ function isPripravaSheet(name: string) {
|
||||
// ────────────────────────────────────────────────────────────
|
||||
//
|
||||
|
||||
function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null) {
|
||||
function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null, flags: Flag[]) {
|
||||
const ignoreColors = flags.includes(Flag.SHOW_ALL_ENTRIES)
|
||||
const classRegex = /[AEC][0-4][a-c]?\s*\/.*/s;
|
||||
const prefixRegex = /[AEC][0-4][a-c]?/;
|
||||
|
||||
@@ -248,20 +253,20 @@ function extractClassChanges(sheet: Worksheet, themeColors: ThemeColors | null)
|
||||
|
||||
classCells.forEach((address, index) => {
|
||||
const row = sheet.getRow(Number(sheet.getCell(address).row));
|
||||
changes[classes[index]] = buildLessonArray(row, address, themeColors);
|
||||
changes[classes[index]] = buildLessonArray(row, address, themeColors, ignoreColors);
|
||||
});
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
function buildLessonArray(row: Row, ignoreAddress: string, themeColors: ThemeColors | null) {
|
||||
function buildLessonArray(row: Row, ignoreAddress: string, themeColors: ThemeColors | null, ignoreColors: boolean) {
|
||||
const lessons: (Lesson | null)[] = [];
|
||||
|
||||
row.eachCell((cell) => {
|
||||
if (cell.address === ignoreAddress) return;
|
||||
|
||||
const colIndex = letterToNumber(cell.address.replace(/[0-9]/g, ""));
|
||||
lessons[colIndex] = parseLessonCell(cell, themeColors);
|
||||
lessons[colIndex] = parseLessonCell(cell, themeColors, ignoreColors);
|
||||
});
|
||||
|
||||
const normalized = Array.from(lessons, (x) => (x === undefined ? null : x));
|
||||
@@ -270,13 +275,13 @@ function buildLessonArray(row: Row, ignoreAddress: string, themeColors: ThemeCol
|
||||
return normalized.slice(1, 11);
|
||||
}
|
||||
|
||||
function parseLessonCell(cell: Cell, themeColors: ThemeColors | null): Lesson | null {
|
||||
function parseLessonCell(cell: Cell, themeColors: ThemeColors | null, ignoreColors: boolean): Lesson | null {
|
||||
try {
|
||||
const text = (cell.text || "").trim();
|
||||
const cleanupRegex = /^úklid\s+(?:\d+\s+)?[A-Za-z]{2}$/;
|
||||
|
||||
// @ts-ignore
|
||||
if (!text || cleanupRegex.test(text) || !cell.fill?.fgColor) return null;
|
||||
if (!text || cleanupRegex.test(text) || (!cell.fill?.fgColor && !ignoreColors)) return null;
|
||||
|
||||
const backgroundColor = resolveCellColor(cell, themeColors);
|
||||
const foregroundColor = !backgroundColor ? undefined : (
|
||||
|
||||
Reference in New Issue
Block a user