mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-07 16:33:51 +00:00
2fa397548a
* feat/navigate upgrade react router * feat/navigate migrate to react router 6 * feat/navigate style modal * feat/navigate create endpoints for app settings * feat/navigate protect editor with pin * feat/navigate apply dynamic routing draft * feat/navigate upgrade relevant packages * feat/navigate restructure directory and add tests * feat/navigate test aliases validation * feat/navigate validate aliases before sending * feat/navigate create data endpoint * feat/navigate config: prettier * feat/navigate invalidate empty strings * feat/navigate create endpoints * feat/navigate parse on import * feat/navigate navigate to alias * feat/navigate user help and sample data * feat/navigate refact aliases modal * feat/navigate refact settings style * feat/navigate update sample db * feat/navigate link is relative to hostname * feat/navigate navigate to first match * feat/navigate update readme and version bump * feat/navigate config: create shared module * feat/navigate config: cheat module install * feat/navigate fix tests * feat/navigate run tests in pull request * Update ontime_cy.yml
85 lines
2.4 KiB
JavaScript
85 lines
2.4 KiB
JavaScript
import { stringFromMillis } from 'ontime-utils/time';
|
|
|
|
/**
|
|
* @description From a list of events, returns only events of type event with calculated delays
|
|
* @param {Object[]} events - given events
|
|
* @returns {Object[]} Filtered events with calculated delays
|
|
*/
|
|
export const getEventsWithDelay = (events) => {
|
|
|
|
if (events == null) return [];
|
|
|
|
const unfilteredEvents = [...events];
|
|
|
|
// Add running delay
|
|
let delay = 0;
|
|
for (const e of unfilteredEvents) {
|
|
if (e.type === 'block') delay = 0;
|
|
else if (e.type === 'delay') delay = delay + e.duration;
|
|
else if (e.type === 'event' && delay > 0) {
|
|
e.timeStart += delay;
|
|
e.timeEnd += delay;
|
|
}
|
|
}
|
|
|
|
// filter just events
|
|
return unfilteredEvents.filter((e) => e.type === 'event');
|
|
};
|
|
|
|
/**
|
|
* @description Returns trimmed event list array
|
|
* @param {Object[]} events - given events
|
|
* @param {string} selectedId - id of currently selected event
|
|
* @param {number} limit - max number of events to return
|
|
* @returns {Object[]} Event list with maximum <limit> objects
|
|
*/
|
|
export const trimEventlist = (events, selectedId, limit) => {
|
|
if (events == null) return [];
|
|
|
|
const BEFORE = 2;
|
|
const trimmedEvents = [...events];
|
|
|
|
// limit events length if necessary
|
|
if (limit != null) {
|
|
while (trimmedEvents.length > limit) {
|
|
const idx = trimmedEvents.findIndex((e) => e.id === selectedId);
|
|
if (idx <= BEFORE) { trimmedEvents.pop(); }
|
|
else { trimmedEvents.shift(); }
|
|
}
|
|
}
|
|
return trimmedEvents;
|
|
};
|
|
|
|
/**
|
|
* @description Returns list of events formatted to be displayed
|
|
* @param {Object[]} events - given events
|
|
* @param {string} selectedId - id of currently selected event
|
|
* @param {string} nextId - id of next event
|
|
* @param {boolean} [showEnd] - whether to show the end time
|
|
* @returns {Object[]} Formatted list of events [{time: -, title: -, isNow, isNext}]
|
|
*/
|
|
export const formatEventList = (events, selectedId, nextId, showEnd = false) => {
|
|
if (events == null) return [];
|
|
|
|
const givenEvents = [...events];
|
|
|
|
// format list
|
|
let formattedEvents = [];
|
|
for (const g of givenEvents) {
|
|
const start = stringFromMillis(g.timeStart, false);
|
|
const end = stringFromMillis(g.timeEnd, false);
|
|
|
|
formattedEvents.push({
|
|
id: g.id,
|
|
time: showEnd ? `${start} - ${end}` : start,
|
|
title: g.title,
|
|
isNow: g.id === selectedId,
|
|
isNext: g.id === nextId,
|
|
});
|
|
}
|
|
|
|
return formattedEvents;
|
|
};
|
|
|
|
|