2019-02-04 13:54:17 -07:00
|
|
|
import moment from "moment";
|
2017-06-29 12:54:02 -06:00
|
|
|
import { CalendarOccurrence } from "../../interfaces";
|
|
|
|
import { FarmEventWithExecutable } from "./interfaces";
|
|
|
|
import { Calendar } from "./index";
|
2019-04-09 23:17:03 -06:00
|
|
|
import { TimeSettings } from "../../../interfaces";
|
|
|
|
import { timeFormatString } from "../../../util";
|
2017-06-29 12:54:02 -06:00
|
|
|
|
|
|
|
/** An occurrence is a single event on the calendar, usually rendered as a
|
|
|
|
* little white square on the farm event UI. This is the data representation for
|
|
|
|
* single calendar entries. */
|
2018-01-03 23:01:12 -07:00
|
|
|
export function occurrence(
|
|
|
|
m: moment.Moment,
|
2018-01-02 09:57:37 -07:00
|
|
|
fe: FarmEventWithExecutable,
|
2019-04-09 23:17:03 -06:00
|
|
|
timeSettings: TimeSettings,
|
2018-01-03 23:01:12 -07:00
|
|
|
modifiers?: { numHidden?: number, empty?: boolean }):
|
2017-06-29 12:54:02 -06:00
|
|
|
CalendarOccurrence {
|
2018-01-03 23:01:12 -07:00
|
|
|
const normalHeading = fe.executable.name || fe.executable_type;
|
|
|
|
const heading = () => {
|
2020-01-03 13:04:45 -07:00
|
|
|
if (modifiers?.empty) {
|
2018-01-03 23:01:12 -07:00
|
|
|
return "*Empty*";
|
|
|
|
}
|
2020-01-03 13:04:45 -07:00
|
|
|
if (modifiers?.numHidden) {
|
2018-01-03 23:01:12 -07:00
|
|
|
return `+ ${modifiers.numHidden} more: ` + normalHeading;
|
|
|
|
}
|
|
|
|
return normalHeading;
|
|
|
|
};
|
2019-04-09 23:17:03 -06:00
|
|
|
const { utcOffset } = timeSettings;
|
2017-06-29 12:54:02 -06:00
|
|
|
return {
|
2018-03-10 04:23:49 -07:00
|
|
|
mmddyy: m.utcOffset(utcOffset).format(Calendar.DATE_FORMAT),
|
2017-06-29 12:54:02 -06:00
|
|
|
sortKey: m.unix(),
|
2019-04-09 23:17:03 -06:00
|
|
|
timeStr: m.clone().utcOffset(utcOffset).format(timeFormatString(timeSettings)),
|
2018-01-03 23:01:12 -07:00
|
|
|
heading: heading(),
|
2017-06-29 12:54:02 -06:00
|
|
|
executableId: fe.executable_id || 0,
|
|
|
|
id: fe.id || 0,
|
|
|
|
};
|
|
|
|
}
|