Enhance template and scheduling functionalities: add PlanningRules to template endpoints and commands, implement repeat limits and audience filtering in scheduling logic, and update related data structures. Refactor frontend components to support new rules and improve user experience in channel management.

This commit is contained in:
Leonid Pershin
2026-07-26 14:25:32 +03:00
parent 7b12a06d1b
commit 8494eb5e6a
30 changed files with 3400 additions and 438 deletions
@@ -0,0 +1,45 @@
import type { LayerApplicability } from '@/shared/api/types'
/**
* Действует ли слой в эту дату вещательных суток. Зеркало серверного `LayerApplicability.Covers`
* (`TeleWave.Application/Programming/Templates/LayerApplicability.cs`) — источник правды там,
* здесь только подсветка сетки. Меняя одно, правьте второе.
*/
export function coversDate(applicability: LayerApplicability | null, date: Date): boolean {
if (!applicability || isEmpty(applicability)) return true
const weekday = date.getDay()
if (applicability.weekdays?.includes(weekday)) return true
const iso = toIsoDate(date)
if (applicability.specificDates?.includes(iso)) return true
if (applicability.dateRanges?.some((r) => iso >= r.from && iso <= r.to)) return true
// Ежегодный период может пересекать Новый год — сравниваем по паре (месяц, день).
const value = (date.getMonth() + 1) * 100 + date.getDate()
return (
applicability.annualRanges?.some((r) => {
const from = r.fromMonth * 100 + r.fromDay
const to = r.toMonth * 100 + r.toDay
return from <= to ? value >= from && value <= to : value >= from || value <= to
}) ?? false
)
}
export function isEmpty(applicability: LayerApplicability | null): boolean {
if (!applicability) return true
return (
!applicability.weekdays?.length &&
!applicability.dateRanges?.length &&
!applicability.annualRanges?.length &&
!applicability.specificDates?.length
)
}
/** «2026-12-25» из локальной даты — без ухода в UTC, иначе вечер уезжает на день назад. */
export function toIsoDate(date: Date): string {
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(
date.getDate(),
).padStart(2, '0')}`
}
@@ -10,6 +10,12 @@ export function formatTime(iso: string | null) {
})
}
/** Минуты суток → «HH:MM:00» — формат `TimeOnly` на сервере. */
export function toTime(minutes: number): string {
const m = ((minutes % (24 * 60)) + 24 * 60) % (24 * 60)
return `${String(Math.floor(m / 60)).padStart(2, '0')}:${String(m % 60).padStart(2, '0')}:00`
}
/** Минуты суток → «HH:MM». */
export function formatMinute(minute: number | null) {
if (minute == null) return '—'