mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-29 04:50:20 +00:00
Extracted component and util logic
This commit is contained in:
parent
dd75b5b21a
commit
36ec2fb1b0
2 changed files with 157 additions and 108 deletions
66
frontend/src/utils/forms/RecurringRuleModalUtils.js
Normal file
66
frontend/src/utils/forms/RecurringRuleModalUtils.js
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import API from '../../api.js';
|
||||
import { toTimeString } from '../dateTimeUtils.js';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export const getChannelOptions = (channels) => {
|
||||
return Object.values(channels || {})
|
||||
.sort((a, b) => {
|
||||
const aNum = Number(a.channel_number) || 0;
|
||||
const bNum = Number(b.channel_number) || 0;
|
||||
if (aNum === bNum) {
|
||||
return (a.name || '').localeCompare(b.name || '');
|
||||
}
|
||||
return aNum - bNum;
|
||||
})
|
||||
.map((item) => ({
|
||||
value: `${item.id}`,
|
||||
label: item.name || `Channel ${item.id}`,
|
||||
}));
|
||||
};
|
||||
|
||||
export const getUpcomingOccurrences = (
|
||||
recordings,
|
||||
userNow,
|
||||
ruleId,
|
||||
toUserTime
|
||||
) => {
|
||||
const list = Array.isArray(recordings)
|
||||
? recordings
|
||||
: Object.values(recordings || {});
|
||||
const now = userNow();
|
||||
return list
|
||||
.filter(
|
||||
(rec) =>
|
||||
rec?.custom_properties?.rule?.id === ruleId &&
|
||||
toUserTime(rec.start_time).isAfter(now)
|
||||
)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
toUserTime(a.start_time).valueOf() - toUserTime(b.start_time).valueOf()
|
||||
);
|
||||
};
|
||||
|
||||
export const updateRecurringRule = async (ruleId, values) => {
|
||||
await API.updateRecurringRule(ruleId, {
|
||||
channel: values.channel_id,
|
||||
days_of_week: (values.days_of_week || []).map((d) => Number(d)),
|
||||
start_time: toTimeString(values.start_time),
|
||||
end_time: toTimeString(values.end_time),
|
||||
start_date: values.start_date
|
||||
? dayjs(values.start_date).format('YYYY-MM-DD')
|
||||
: null,
|
||||
end_date: values.end_date
|
||||
? dayjs(values.end_date).format('YYYY-MM-DD')
|
||||
: null,
|
||||
name: values.rule_name?.trim() || '',
|
||||
enabled: Boolean(values.enabled),
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteRecurringRuleById = async (ruleId) => {
|
||||
await API.deleteRecurringRule(ruleId);
|
||||
};
|
||||
|
||||
export const updateRecurringRuleEnabled = async (ruleId, checked) => {
|
||||
await API.updateRecurringRule(ruleId, { enabled: checked });
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue