feat(parser): parse "Задания для выполнения" column"

Now schedule can show the data in column "Задание для выполнения" under "Материалы" button
This commit is contained in:
kilyabin
2026-03-02 14:43:16 +04:00
parent da7b4fe812
commit e6ba2e0334
3 changed files with 49 additions and 16 deletions

View File

@@ -991,20 +991,43 @@ const parseLesson = (row: Element, isTeacherSchedule: boolean = false): Lesson |
lesson.topic = cells[4].textContent?.trim() || ''
}
// Колонка "Ресурс"
lesson.resources = []
if (cells[5]) {
Array.from(cells[5].querySelectorAll('a'))
.forEach(a => {
const title = a.textContent?.trim()
const url = a.getAttribute('href')
if (title && url) {
lesson.resources.push({
type: 'link',
title,
url
})
}
})
Array.from(cells[5].querySelectorAll('a')).forEach(a => {
const title = a.textContent?.trim()
const url = a.getAttribute('href')
if (title && url) {
lesson.resources.push({
type: 'link',
title,
url,
})
}
})
}
// Колонка "Задание для выполнения"
lesson.homework = ''
if (cells[6]) {
const hwCell = cells[6]
const rawText = hwCell.textContent?.replace(/\s+/g, ' ').trim() || ''
if (rawText) {
lesson.homework = rawText
}
// Добавляем ссылки из задания тоже в список материалов
Array.from(hwCell.querySelectorAll('a')).forEach(a => {
const title = a.textContent?.trim()
const url = a.getAttribute('href')
if (title && url) {
lesson.resources.push({
type: 'link',
title,
url,
})
}
})
}
return lesson

View File

@@ -39,6 +39,9 @@ export function Lesson({ lesson, width = 350, animationDelay, hideTeacher = fals
const hasSubject = 'subject' in lesson && lesson.subject
const hasContent = hasSubject || (isFallbackDiscipline && lesson.fallbackDiscipline) || (lesson.topic && lesson.topic.trim())
const isCancelled = lesson.isChange && !hasContent
const hasHomework = Boolean(lesson.homework && lesson.homework.trim())
const hasResources = Boolean(lesson.resources.length)
const hasAnyMaterials = hasResources || hasHomework
const getTeacherPhoto = (url?: string) => {
if(url) {
@@ -134,7 +137,7 @@ export function Lesson({ lesson, width = 350, animationDelay, hideTeacher = fals
</div>
)}
</CardContent>
{!isCancelled && (Boolean(lesson.resources.length) || ('place' in lesson && lesson.place)) && (
{!isCancelled && (hasAnyMaterials || ('place' in lesson && lesson.place)) && (
<CardFooter className="flex flex-col sm:flex-row justify-between gap-2 mt-auto">
{('place' in lesson && lesson.place) ? (
<div className='hidden md:flex flex-col text-muted-foreground text-xs break-words'>
@@ -145,7 +148,7 @@ export function Lesson({ lesson, width = 350, animationDelay, hideTeacher = fals
</span>
</div>
) : <span />}
{Boolean(lesson.resources.length) && (
{hasAnyMaterials && (
<Button onClick={handleOpenResources} className="min-h-[44px] w-full sm:w-auto"><AiOutlineFolderView />&nbsp;Материалы</Button>
)}
</CardFooter>
@@ -154,7 +157,8 @@ export function Lesson({ lesson, width = 350, animationDelay, hideTeacher = fals
open={resourcesDialogOpened}
onClose={() => setResourcesDialogOpened(false)}
teacherName={('teacher' in lesson && lesson.teacher) ? lesson.teacher : undefined}
resources={lesson.resources}
resources={lesson.resources}
homework={lesson.homework}
/>
</Card>
)

View File

@@ -10,11 +10,12 @@ import { Lesson } from '@/shared/model/lesson'
import Link from 'next/link'
import { BiLink } from 'react-icons/bi'
export function ResourcesDialog({ open, onClose, teacherName, resources }: {
export function ResourcesDialog({ open, onClose, teacherName, resources, homework }: {
open: boolean
onClose: () => any
teacherName?: string
resources: Lesson['resources']
homework?: string
}) {
const teacherPronouns = teachers.find(t => t.name === teacherName)?.pronouns
@@ -38,6 +39,11 @@ export function ResourcesDialog({ open, onClose, teacherName, resources }: {
)}
</DialogHeader>
<div className="grid gap-4 py-4">
{homework && homework.trim() && (
<div className="text-sm whitespace-pre-wrap break-words">
{homework}
</div>
)}
{resources.map((resource, i) => <Resource resource={resource} key={i} />)}
</div>
</DialogContent>