Farmbot-Web-App/frontend/farm_designer/farm_events/calendar/occurrence.ts

37 lines
1.2 KiB
TypeScript
Raw Normal View History

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. */
export function occurrence(
m: moment.Moment,
fe: FarmEventWithExecutable,
2019-04-09 23:17:03 -06:00
timeSettings: TimeSettings,
modifiers?: { numHidden?: number, empty?: boolean }):
2017-06-29 12:54:02 -06:00
CalendarOccurrence {
const normalHeading = fe.executable.name || fe.executable_type;
const heading = () => {
2020-01-03 13:04:45 -07:00
if (modifiers?.empty) {
return "*Empty*";
}
2020-01-03 13:04:45 -07:00
if (modifiers?.numHidden) {
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)),
heading: heading(),
2017-06-29 12:54:02 -06:00
executableId: fe.executable_id || 0,
id: fe.id || 0,
};
}