feat(parser): parse "Задания для выполнения" column"
Now schedule can show the data in column "Задание для выполнения" under "Материалы" button
This commit is contained in:
@@ -991,20 +991,43 @@ const parseLesson = (row: Element, isTeacherSchedule: boolean = false): Lesson |
|
|||||||
lesson.topic = cells[4].textContent?.trim() || ''
|
lesson.topic = cells[4].textContent?.trim() || ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Колонка "Ресурс"
|
||||||
lesson.resources = []
|
lesson.resources = []
|
||||||
if (cells[5]) {
|
if (cells[5]) {
|
||||||
Array.from(cells[5].querySelectorAll('a'))
|
Array.from(cells[5].querySelectorAll('a')).forEach(a => {
|
||||||
.forEach(a => {
|
const title = a.textContent?.trim()
|
||||||
const title = a.textContent?.trim()
|
const url = a.getAttribute('href')
|
||||||
const url = a.getAttribute('href')
|
if (title && url) {
|
||||||
if (title && url) {
|
lesson.resources.push({
|
||||||
lesson.resources.push({
|
type: 'link',
|
||||||
type: 'link',
|
title,
|
||||||
title,
|
url,
|
||||||
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
|
return lesson
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ export function Lesson({ lesson, width = 350, animationDelay, hideTeacher = fals
|
|||||||
const hasSubject = 'subject' in lesson && lesson.subject
|
const hasSubject = 'subject' in lesson && lesson.subject
|
||||||
const hasContent = hasSubject || (isFallbackDiscipline && lesson.fallbackDiscipline) || (lesson.topic && lesson.topic.trim())
|
const hasContent = hasSubject || (isFallbackDiscipline && lesson.fallbackDiscipline) || (lesson.topic && lesson.topic.trim())
|
||||||
const isCancelled = lesson.isChange && !hasContent
|
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) => {
|
const getTeacherPhoto = (url?: string) => {
|
||||||
if(url) {
|
if(url) {
|
||||||
@@ -134,7 +137,7 @@ export function Lesson({ lesson, width = 350, animationDelay, hideTeacher = fals
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</CardContent>
|
</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">
|
<CardFooter className="flex flex-col sm:flex-row justify-between gap-2 mt-auto">
|
||||||
{('place' in lesson && lesson.place) ? (
|
{('place' in lesson && lesson.place) ? (
|
||||||
<div className='hidden md:flex flex-col text-muted-foreground text-xs break-words'>
|
<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>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
) : <span />}
|
) : <span />}
|
||||||
{Boolean(lesson.resources.length) && (
|
{hasAnyMaterials && (
|
||||||
<Button onClick={handleOpenResources} className="min-h-[44px] w-full sm:w-auto"><AiOutlineFolderView /> Материалы</Button>
|
<Button onClick={handleOpenResources} className="min-h-[44px] w-full sm:w-auto"><AiOutlineFolderView /> Материалы</Button>
|
||||||
)}
|
)}
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
@@ -154,7 +157,8 @@ export function Lesson({ lesson, width = 350, animationDelay, hideTeacher = fals
|
|||||||
open={resourcesDialogOpened}
|
open={resourcesDialogOpened}
|
||||||
onClose={() => setResourcesDialogOpened(false)}
|
onClose={() => setResourcesDialogOpened(false)}
|
||||||
teacherName={('teacher' in lesson && lesson.teacher) ? lesson.teacher : undefined}
|
teacherName={('teacher' in lesson && lesson.teacher) ? lesson.teacher : undefined}
|
||||||
resources={lesson.resources}
|
resources={lesson.resources}
|
||||||
|
homework={lesson.homework}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,11 +10,12 @@ import { Lesson } from '@/shared/model/lesson'
|
|||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { BiLink } from 'react-icons/bi'
|
import { BiLink } from 'react-icons/bi'
|
||||||
|
|
||||||
export function ResourcesDialog({ open, onClose, teacherName, resources }: {
|
export function ResourcesDialog({ open, onClose, teacherName, resources, homework }: {
|
||||||
open: boolean
|
open: boolean
|
||||||
onClose: () => any
|
onClose: () => any
|
||||||
teacherName?: string
|
teacherName?: string
|
||||||
resources: Lesson['resources']
|
resources: Lesson['resources']
|
||||||
|
homework?: string
|
||||||
}) {
|
}) {
|
||||||
const teacherPronouns = teachers.find(t => t.name === teacherName)?.pronouns
|
const teacherPronouns = teachers.find(t => t.name === teacherName)?.pronouns
|
||||||
|
|
||||||
@@ -38,6 +39,11 @@ export function ResourcesDialog({ open, onClose, teacherName, resources }: {
|
|||||||
)}
|
)}
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<div className="grid gap-4 py-4">
|
<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} />)}
|
{resources.map((resource, i) => <Resource resource={resource} key={i} />)}
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
|
|||||||
Reference in New Issue
Block a user