Skip to content

Access Schedule

A list of time windows, each a day choice and a start and end time, with Add and Remove, like the access schedule in Jellyfin's parental control. The value is Jellyfin's own AccessSchedule shape, so a plugin can pass it straight through.

Decision

When Use
The times a user or a group may sign in or stream Access Schedule
Any list of weekly windows that Jellyfin stores as AccessSchedule Access Schedule
One run time on chosen days Schedule Picker
An interval, such as every 5 minutes Number Unit Field

Usage

import { createAccessSchedule } from './configurationpage?name=myplugin_stolon.js';

var schedule = createAccessSchedule({
    label: 'Access Schedule',
    value: group.AccessSchedules,
    onChange: function (windows) { group.AccessSchedules = windows; }
});
container.appendChild(schedule.element);
if (!schedule.isValid()) { return; }

Classes: stolon-access-schedule, stolon-access-schedule-head, stolon-access-schedule-row. The handle is { element, getValue, setValue, isValid, setHeight, destroy }.

Parts: stolon-access-schedule-label, stolon-access-schedule-description, stolon-access-schedule-rows, stolon-access-schedule-fields, stolon-access-schedule-day, stolon-access-schedule-range, stolon-access-schedule-start, stolon-access-schedule-end, stolon-access-schedule-remove, stolon-access-schedule-empty, stolon-access-schedule-add.

States and Modifiers

  • A window is { DayOfWeek, StartHour, EndHour }. DayOfWeek is "Sunday" to "Saturday", "Everyday", "Weekday", or "Weekend". The hours run from 0 to 24 in steps of step, which is 0.5 by default, so 0.5 is 12:30 AM and 24 is midnight at the end of the day.
  • label names the group through aria-labelledby, and description describes it through aria-describedby. Each hides while it is empty.
  • getValue() returns every row, valid or not. isValid() checks every row, shows its error, and returns true when every end is after its start.
  • The start and end are a Time Range Field, two time boxes with the clock icon. A typed time moves to the nearest step, an end of 00:00 is 24, and a loaded hour off the step reads back exactly until it is edited.
  • An end at or before its start marks the row with error and shows "The end must be after the start." under the times, with aria-invalid on both boxes.
  • The remove label names the hours as the user's locale time, such as "1:30 AM", and as "01:30" where the locale form is not available.
  • Add appends an Every day window from midnight to midnight and focuses its day.
  • The empty sentence is the List's, stolon-list-empty outside, under the rows.
  • maxRows disables Add at that count and shows limitText, "No more rows can be added.". height, maxHeight, and minHeight size the rows as a List takes them, 'auto' by default, and setHeight(height, maxHeight) changes them later.
  • The labels default to "Day", "Start", "End", "Add window", and "No windows. Access is allowed at any time.". The days default to "Sunday" to "Saturday", "Every day", "Weekdays", and "Weekends", and dayLabels replaces any of them by key, such as { Everyday: 'Daily' }.
  • removeText is "Remove {value}", where the value is the window from windowText, "{day} {start} to {end}".
  • At 600px and below the column labels hide, the day takes the first line, and the times share the second.
  • size is small, medium (default), or large, and sizes its fields on the size scale.

Gotchas

  • setValue reads an enum number from 0 for Sunday to 9 for Weekend and a day name in any case. An unknown day reads as "Everyday", and an hour outside 0 to 24 is clamped.
  • setValue does not call onChange.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createAccessSchedule

function createAccessSchedule(options?: AccessScheduleOptions): AccessScheduleHandle

A list of time windows, each a day choice and a start and end time, with Add and Remove, like Jellyfin's parental control access schedule. The value is Jellyfin's AccessSchedule shape, so a plugin can pass it straight through. The start and end are a Time Range Field, so each is a time box with its clock icon, and an end of 00:00 is midnight at the end of the day.

Option Type What it does
value AccessScheduleSource[] | null array of { DayOfWeek, StartHour, EndHour } [optional]
label string heading above the list [optional]
description string sentence under the heading, which describes the group [optional]
dayLabel string column label and aria-label of the day selects (default 'Day')
startLabel string column label and aria-label of the start boxes (default 'Start')
endLabel string column label and aria-label of the end boxes (default 'End')
addText string text of the add button (default 'Add window')
removeText string aria-label of a remove button, where {value} is the window from windowText (default 'Remove {value}')
windowText string name of a window, with {day}, {start}, and {end} (default '{day} {start} to {end}')
emptyText string sentence shown while there is no window (default 'No windows. Access is allowed at any time.')
endBeforeStartText string message for an end at or before the start (default 'The end must be after the start.')
dayLabels Partial<Record<AccessScheduleDay, string>> object that replaces day names by DayOfWeek key, such as { Everyday: 'Daily' } [optional]
step number hours between allowed times, where a typed time moves to the nearest one (default 0.5)
maxRows number most windows allowed, after which Add is disabled and the limit message shows [optional]
limitText string message when maxRows is reached (default 'No more rows can be added.')
height ListHeight height of the rows, as createList takes it (default 'auto')
maxHeight number | string | null height past which the rows scroll [optional]
minHeight number | string | null least height of a filling list [optional]
size 'small' | 'medium' | 'large' 'small', 'medium', or 'large' for its fields (default 'medium')
onChange (value: AccessScheduleWindow[]): void function(windows) [optional]
Handle member Type
getValue (): AccessScheduleWindow[]
setValue (next: AccessScheduleSource[] | null): void
isValid (): boolean
setHeight (height: ListHeight, maxHeight?: number | string | null): void
destroy (): void
Type What it is
AccessScheduleDay A day choice of a window, as Jellyfin's DynamicDayOfWeek names it.
AccessScheduleWindow One time window in Jellyfin's AccessSchedule shape. The hours run from 0 to 24, where 0.5 is 12:30 AM and 24 is midnight at the end of the day.
AccessScheduleSource A window to load. DayOfWeek may also be the enum number from 0 for Sunday to 9 for Weekend, and an hour may be a numeric string.
Class What it looks like
stolon-access-schedule List of time windows with a heading, column labels, rows of day, start, and end selects, and an add button
stolon-access-schedule-label Heading and the sentence under it
stolon-access-schedule-head Column labels over the day, start, and end columns
stolon-access-schedule-rows Rows of windows, each with its day select, its start and end time boxes, and its remove button, with the times' message under them

Example

Example Code

<!-- title: Access Schedule -->
<div id="mount"></div>
<script type="module">
const base = await window.__baseReady;
const view = document.getElementById('view');
const mount = document.getElementById('mount');
const note = document.createElement('div');
note.className = 'stolon-status-text';
const schedule = base.createAccessSchedule({
    label: 'Access Schedule',
    description: 'Times when the user may sign in.',
    value: [
        { DayOfWeek: 'Weekday', StartHour: 16, EndHour: 21.5 },
        { DayOfWeek: 'Weekend', StartHour: 9, EndHour: 23 },
        { DayOfWeek: 'Friday', StartHour: 22, EndHour: 20 }
    ],
    onChange: (windows) => { note.textContent = JSON.stringify(windows) + (schedule.isValid() ? '' : ' (not valid)'); }
});
mount.appendChild(schedule.element);
mount.appendChild(note);
</script>