@sprucelabs/spruce-calendar-components 20.11.1 → 21.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/.spruce/errors/errors.types.d.ts +122 -0
- package/build/.spruce/errors/errors.types.js +4 -0
- package/build/.spruce/errors/options.types.d.ts +28 -0
- package/build/.spruce/errors/options.types.js +2 -0
- package/build/constants.d.ts +5 -0
- package/build/constants.js +9 -0
- package/build/errors/SpruceError.d.ts +5 -0
- package/build/errors/SpruceError.js +45 -0
- package/build/esm/.spruce/errors/errors.types.d.ts +122 -0
- package/build/esm/.spruce/errors/errors.types.js +3 -0
- package/build/esm/.spruce/errors/options.types.d.ts +28 -0
- package/build/esm/.spruce/errors/options.types.js +1 -0
- package/build/esm/constants.d.ts +5 -0
- package/build/esm/constants.js +6 -0
- package/build/esm/errors/SpruceError.d.ts +5 -0
- package/build/esm/errors/SpruceError.js +39 -0
- package/build/esm/index-module.d.ts +30 -0
- package/build/esm/index-module.js +7 -0
- package/build/esm/skillViewControllers/Root.svc.d.ts +73 -0
- package/build/esm/skillViewControllers/Root.svc.js +404 -0
- package/build/esm/stores/RemotePreferencesStore.d.ts +26 -0
- package/build/esm/stores/RemotePreferencesStore.js +85 -0
- package/build/esm/toolBelt/CalendarToolTestFactory.d.ts +5 -0
- package/build/esm/toolBelt/CalendarToolTestFactory.js +28 -0
- package/build/esm/toolBelt/states/PrerequisitesToolBeltState.d.ts +37 -0
- package/build/esm/toolBelt/states/PrerequisitesToolBeltState.js +190 -0
- package/build/esm/toolBelt/states/RootToolBeltState.d.ts +37 -0
- package/build/esm/toolBelt/states/RootToolBeltState.js +122 -0
- package/build/esm/toolBelt/states/makeEventTyped.d.ts +2 -0
- package/build/esm/toolBelt/states/makeEventTyped.js +8 -0
- package/build/esm/types/calendar.types.d.ts +10 -0
- package/build/esm/utilities/CalendarEventManager.d.ts +72 -0
- package/build/esm/utilities/CalendarEventManager.js +321 -0
- package/build/esm/utilities/CalendarPeopleManager.d.ts +56 -0
- package/build/esm/utilities/CalendarPeopleManager.js +182 -0
- package/build/esm/utilities/calendarShiftGenerator.d.ts +8 -0
- package/build/esm/utilities/calendarShiftGenerator.js +24 -0
- package/build/esm/viewControllers/CalendarSelectTool.vc.d.ts +28 -0
- package/build/esm/viewControllers/CalendarSelectTool.vc.js +103 -0
- package/build/esm/viewControllers/DateSelectCard.vc.d.ts +29 -0
- package/build/esm/viewControllers/DateSelectCard.vc.js +77 -0
- package/build/esm/viewControllers/PersonSelectTool.vc.d.ts +36 -0
- package/build/esm/viewControllers/PersonSelectTool.vc.js +156 -0
- package/build/esm/viewControllers/SelectUpdateRepeatingStrategyCard.vc.d.ts +18 -0
- package/build/esm/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +85 -0
- package/build/index-module.d.ts +30 -0
- package/build/index-module.js +32 -0
- package/build/skillViewControllers/Root.svc.d.ts +73 -0
- package/build/skillViewControllers/Root.svc.js +359 -0
- package/build/stores/RemotePreferencesStore.d.ts +26 -0
- package/build/stores/RemotePreferencesStore.js +67 -0
- package/build/toolBelt/CalendarToolTestFactory.d.ts +5 -0
- package/build/toolBelt/CalendarToolTestFactory.js +34 -0
- package/build/toolBelt/states/PrerequisitesToolBeltState.d.ts +37 -0
- package/build/toolBelt/states/PrerequisitesToolBeltState.js +172 -0
- package/build/toolBelt/states/RootToolBeltState.d.ts +37 -0
- package/build/toolBelt/states/RootToolBeltState.js +113 -0
- package/build/toolBelt/states/makeEventTyped.d.ts +2 -0
- package/build/toolBelt/states/makeEventTyped.js +14 -0
- package/build/types/calendar.types.d.ts +10 -0
- package/build/utilities/CalendarEventManager.d.ts +72 -0
- package/build/utilities/CalendarEventManager.js +279 -0
- package/build/utilities/CalendarPeopleManager.d.ts +56 -0
- package/build/utilities/CalendarPeopleManager.js +163 -0
- package/build/utilities/calendarShiftGenerator.d.ts +8 -0
- package/build/utilities/calendarShiftGenerator.js +26 -0
- package/build/viewControllers/CalendarSelectTool.vc.d.ts +28 -0
- package/build/viewControllers/CalendarSelectTool.vc.js +93 -0
- package/build/viewControllers/DateSelectCard.vc.d.ts +29 -0
- package/build/viewControllers/DateSelectCard.vc.js +69 -0
- package/build/viewControllers/PersonSelectTool.vc.d.ts +36 -0
- package/build/viewControllers/PersonSelectTool.vc.js +140 -0
- package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.d.ts +18 -0
- package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +88 -0
- package/package.json +99 -26
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import makeEventTyped from './makeEventTyped.js';
|
|
11
|
+
export class PrerequisitesToolBeltState {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.id = 'prerequisites';
|
|
14
|
+
this.selectCalendarHandler = options === null || options === void 0 ? void 0 : options.onSelectCalendar;
|
|
15
|
+
this.selectEventTypeHandler = options === null || options === void 0 ? void 0 : options.onSelectEventType;
|
|
16
|
+
}
|
|
17
|
+
load(stateMachine) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const toolBeltVc = stateMachine.getToolBeltVc();
|
|
20
|
+
this.toolBeltVc = toolBeltVc;
|
|
21
|
+
this.sm = stateMachine;
|
|
22
|
+
void this.toolBeltVc.renderOnce(() => {
|
|
23
|
+
this.toolBeltVc.clearTools();
|
|
24
|
+
this.toolBeltVc.clearStickyTools();
|
|
25
|
+
});
|
|
26
|
+
if (!this.calendars) {
|
|
27
|
+
this.calendars = yield this.listCalendars();
|
|
28
|
+
}
|
|
29
|
+
if (this.calendars.length === 1) {
|
|
30
|
+
yield this.handleSelectCalendar(this.calendars[0]);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.setupCalendarSelectCard(this.calendars);
|
|
34
|
+
yield this.sm.updateContext({
|
|
35
|
+
event: Object.assign(Object.assign({}, this.sm.getContext().event), { isBusy: false }),
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
destroy() { }
|
|
40
|
+
setupCalendarSelectCard(calendars) {
|
|
41
|
+
this.calendarSelectCardVc = this.SelectCalendarCardVc();
|
|
42
|
+
this.toolBeltVc.addTool({
|
|
43
|
+
id: 'calendars',
|
|
44
|
+
lineIcon: 'calendar-add',
|
|
45
|
+
card: this.calendarSelectCardVc.render(),
|
|
46
|
+
});
|
|
47
|
+
if (calendars.length > 0) {
|
|
48
|
+
this.calendarSelectCardVc.addSection({
|
|
49
|
+
buttons: calendars.map((c) => ({
|
|
50
|
+
id: c.id,
|
|
51
|
+
label: c.title,
|
|
52
|
+
onClick: () => this.handleSelectCalendar(c),
|
|
53
|
+
})),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.calendarSelectCardVc.addSection({
|
|
58
|
+
text: {
|
|
59
|
+
content: `You don't have any calendars. The only way to get one is to book an appointment or work at a place that uses Sprucebot! 🌲🤖`,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
this.calendarSelectCardVc.setIsBusy(false);
|
|
64
|
+
}
|
|
65
|
+
handleSelectCalendar(calendar) {
|
|
66
|
+
var _a, _b, _c, _d;
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
(_a = this.calendarSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
69
|
+
this.calendar = calendar;
|
|
70
|
+
yield ((_b = this.selectCalendarHandler) === null || _b === void 0 ? void 0 : _b.call(this, calendar));
|
|
71
|
+
const client = yield this.connectToApi();
|
|
72
|
+
let [{ calendarEventTypes }] = yield client.emitAndFlattenResponses('calendar.list-calendar-event-types::v2021_05_19');
|
|
73
|
+
const types = (_c = calendar.eventTypes) !== null && _c !== void 0 ? _c : [];
|
|
74
|
+
if (types.length > 0) {
|
|
75
|
+
calendarEventTypes = calendarEventTypes.filter((t) => types.indexOf(t.slug) > -1);
|
|
76
|
+
}
|
|
77
|
+
if (calendarEventTypes.length === 1) {
|
|
78
|
+
yield this.handleSelectType(calendarEventTypes[0]);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
yield this.updateEventInContext();
|
|
82
|
+
yield this.setupTypeSelectCard(calendarEventTypes);
|
|
83
|
+
}
|
|
84
|
+
(_d = this.calendarSelectCardVc) === null || _d === void 0 ? void 0 : _d.setIsBusy(false);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
setupTypeSelectCard(types) {
|
|
88
|
+
var _a, _b, _c, _d, _e, _f;
|
|
89
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
+
if (!this.toolBeltVc.getTool('types')) {
|
|
91
|
+
this.typeSelectCardVc = this.TypeSelectCardVc();
|
|
92
|
+
this.toolBeltVc.addTool({
|
|
93
|
+
id: 'types',
|
|
94
|
+
lineIcon: 'calendar-add',
|
|
95
|
+
card: this.typeSelectCardVc.render(),
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
(_a = this.typeSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
99
|
+
(_b = this.toolBeltVc) === null || _b === void 0 ? void 0 : _b.focusTool('types');
|
|
100
|
+
const section = yield this.renderTypeButtonsSection(types);
|
|
101
|
+
if (((_c = this.typeSelectCardVc) === null || _c === void 0 ? void 0 : _c.getTotalSections()) === 0) {
|
|
102
|
+
(_d = this.typeSelectCardVc) === null || _d === void 0 ? void 0 : _d.addSection(section);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
(_e = this.typeSelectCardVc) === null || _e === void 0 ? void 0 : _e.setSection(0, section);
|
|
106
|
+
}
|
|
107
|
+
(_f = this.typeSelectCardVc) === null || _f === void 0 ? void 0 : _f.setIsBusy(false);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
renderTypeButtonsSection(calendarEventTypes) {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
112
|
+
const section = {
|
|
113
|
+
buttons: calendarEventTypes.map((t) => ({
|
|
114
|
+
id: t.id,
|
|
115
|
+
label: t.name,
|
|
116
|
+
onClick: () => this.handleSelectType(t),
|
|
117
|
+
})),
|
|
118
|
+
};
|
|
119
|
+
return section;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
handleSelectType(type) {
|
|
123
|
+
var _a, _b, _c;
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
(_a = this.typeSelectCardVc) === null || _a === void 0 ? void 0 : _a.setIsBusy(true);
|
|
126
|
+
const { event } = this.sm.getContext();
|
|
127
|
+
const updated = makeEventTyped(event, type);
|
|
128
|
+
yield this.updateEventInContext({
|
|
129
|
+
eventTypeSlug: type.slug,
|
|
130
|
+
timeBlocks: updated.timeBlocks,
|
|
131
|
+
});
|
|
132
|
+
yield ((_b = this.selectEventTypeHandler) === null || _b === void 0 ? void 0 : _b.call(this, type));
|
|
133
|
+
(_c = this.typeSelectCardVc) === null || _c === void 0 ? void 0 : _c.setIsBusy(false);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
updateEventInContext(updates) {
|
|
137
|
+
var _a;
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
const { event } = this.sm.getContext();
|
|
140
|
+
if (event) {
|
|
141
|
+
yield this.sm.updateContext({
|
|
142
|
+
event: Object.assign(Object.assign(Object.assign({}, event), { calendarId: (_a = this.calendar) === null || _a === void 0 ? void 0 : _a.id }), updates),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
TypeSelectCardVc() {
|
|
148
|
+
return this.sm.Controller('card', {
|
|
149
|
+
header: {
|
|
150
|
+
title: 'What do you want to add?',
|
|
151
|
+
},
|
|
152
|
+
body: {
|
|
153
|
+
isBusy: true,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
getCalendarSelectCardVc() {
|
|
158
|
+
return this.calendarSelectCardVc;
|
|
159
|
+
}
|
|
160
|
+
getTypeSelectCardVc() {
|
|
161
|
+
return this.typeSelectCardVc;
|
|
162
|
+
}
|
|
163
|
+
SelectCalendarCardVc() {
|
|
164
|
+
return this.sm.Controller('card', {
|
|
165
|
+
header: {
|
|
166
|
+
title: 'Which calendar?',
|
|
167
|
+
},
|
|
168
|
+
body: {
|
|
169
|
+
isBusy: true,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
listCalendars() {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const org = yield this.sm.getContext().scope.getCurrentOrganization();
|
|
176
|
+
const client = yield this.connectToApi();
|
|
177
|
+
const [{ calendars }] = yield client.emitAndFlattenResponses('calendar.list-calendars::v2021_05_19', {
|
|
178
|
+
target: {
|
|
179
|
+
organizationId: org === null || org === void 0 ? void 0 : org.id,
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
return calendars;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
connectToApi() {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
return yield this.sm.connectToApi();
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SpruceSchemas, ToolBeltState } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { CalendarToolBeltStateMachine } from '../../types/calendar.types';
|
|
3
|
+
import { CalendarEventManager } from '../../utilities/CalendarEventManager';
|
|
4
|
+
import CalendarPeopleManager from '../../utilities/CalendarPeopleManager';
|
|
5
|
+
import CalendarSelectCardViewController from '../../viewControllers/CalendarSelectTool.vc';
|
|
6
|
+
import DateSelectCardViewController from '../../viewControllers/DateSelectCard.vc';
|
|
7
|
+
import PersonSelectToolViewController from '../../viewControllers/PersonSelectTool.vc';
|
|
8
|
+
export declare class RootToolBeltState implements ToolBeltState {
|
|
9
|
+
readonly id = "root";
|
|
10
|
+
private calendarSelectCardVc?;
|
|
11
|
+
private toolBeltVc;
|
|
12
|
+
private personSelectVc;
|
|
13
|
+
private sm;
|
|
14
|
+
private scopeSelectionTool?;
|
|
15
|
+
private dateSelectVc;
|
|
16
|
+
private lastSelectedDate?;
|
|
17
|
+
private people;
|
|
18
|
+
private events;
|
|
19
|
+
constructor(options: {
|
|
20
|
+
people: CalendarPeopleManager;
|
|
21
|
+
events: CalendarEventManager;
|
|
22
|
+
});
|
|
23
|
+
getCalendarSelectCardVc(): CalendarSelectCardViewController | undefined;
|
|
24
|
+
private CalendarSelectVc;
|
|
25
|
+
load(stateMachine: CalendarToolBeltStateMachine): Promise<void>;
|
|
26
|
+
private optionallyClearStickyTool;
|
|
27
|
+
private handleSelectDate;
|
|
28
|
+
private resetToolBelt;
|
|
29
|
+
private optionallyDropInScopeSelectionTool;
|
|
30
|
+
private setupCalendarSelectVc;
|
|
31
|
+
private optionallyAddPeopleCard;
|
|
32
|
+
getPersonSelectCardVc(): PersonSelectToolViewController;
|
|
33
|
+
getDateSelectVc(): DateSelectCardViewController;
|
|
34
|
+
getSelectedDate(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarSelectedDate;
|
|
35
|
+
setSelectedDate(year: number, month: number, day: number): void;
|
|
36
|
+
private PersonSelectVc;
|
|
37
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { dateUtil } from '@sprucelabs/calendar-utils';
|
|
11
|
+
import { assertOptions } from '@sprucelabs/schema';
|
|
12
|
+
export class RootToolBeltState {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.id = 'root';
|
|
15
|
+
const { people, events } = assertOptions(options, ['people', 'events']);
|
|
16
|
+
this.people = people;
|
|
17
|
+
this.events = events;
|
|
18
|
+
}
|
|
19
|
+
getCalendarSelectCardVc() {
|
|
20
|
+
return this.calendarSelectCardVc;
|
|
21
|
+
}
|
|
22
|
+
CalendarSelectVc() {
|
|
23
|
+
var _a;
|
|
24
|
+
return (_a = this.sm) === null || _a === void 0 ? void 0 : _a.Controller('calendar.calendar-select-tool', {
|
|
25
|
+
events: this.events,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
load(stateMachine) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
this.sm = stateMachine;
|
|
31
|
+
this.toolBeltVc = stateMachine.getToolBeltVc();
|
|
32
|
+
this.resetToolBelt();
|
|
33
|
+
this.dateSelectVc = this.sm.Controller('calendar.date-select-card', {
|
|
34
|
+
onSelectDate: (date) => this.handleSelectDate(date),
|
|
35
|
+
startDate: dateUtil.getStartOfDay(new Date().getTime()),
|
|
36
|
+
selectedDate: this.lastSelectedDate,
|
|
37
|
+
});
|
|
38
|
+
this.toolBeltVc.addTool({
|
|
39
|
+
id: 'date-selection',
|
|
40
|
+
lineIcon: 'calendar',
|
|
41
|
+
card: this.dateSelectVc.render(),
|
|
42
|
+
});
|
|
43
|
+
yield Promise.all([
|
|
44
|
+
this.setupCalendarSelectVc(stateMachine),
|
|
45
|
+
this.optionallyAddPeopleCard(stateMachine.getContext().scope),
|
|
46
|
+
]);
|
|
47
|
+
this.optionallyDropInScopeSelectionTool();
|
|
48
|
+
this.optionallyClearStickyTool();
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
optionallyClearStickyTool() {
|
|
52
|
+
if (this.toolBeltVc.getStickyTools().bottom) {
|
|
53
|
+
this.toolBeltVc.removeStickyTool('bottom');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
handleSelectDate(date) {
|
|
57
|
+
const { calendarVc } = this.sm.getContext();
|
|
58
|
+
calendarVc.setStartDate(date);
|
|
59
|
+
}
|
|
60
|
+
resetToolBelt() {
|
|
61
|
+
var _a;
|
|
62
|
+
if (!this.scopeSelectionTool) {
|
|
63
|
+
this.scopeSelectionTool = (_a = this.toolBeltVc) === null || _a === void 0 ? void 0 : _a.getTool('scope-selection');
|
|
64
|
+
}
|
|
65
|
+
this.toolBeltVc.clearTools();
|
|
66
|
+
}
|
|
67
|
+
optionallyDropInScopeSelectionTool() {
|
|
68
|
+
var _a;
|
|
69
|
+
if (this.scopeSelectionTool) {
|
|
70
|
+
(_a = this.toolBeltVc) === null || _a === void 0 ? void 0 : _a.addTool(this.scopeSelectionTool);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
setupCalendarSelectVc(stateMachine) {
|
|
74
|
+
var _a, _b, _c;
|
|
75
|
+
this.calendarSelectCardVc = this.CalendarSelectVc();
|
|
76
|
+
(_a = this.toolBeltVc) === null || _a === void 0 ? void 0 : _a.addTool({
|
|
77
|
+
lineIcon: 'calendar',
|
|
78
|
+
id: 'calendars',
|
|
79
|
+
card: (_b = this.calendarSelectCardVc) === null || _b === void 0 ? void 0 : _b.render(),
|
|
80
|
+
});
|
|
81
|
+
return (_c = this.calendarSelectCardVc) === null || _c === void 0 ? void 0 : _c.load(stateMachine.getContext());
|
|
82
|
+
}
|
|
83
|
+
optionallyAddPeopleCard(scope) {
|
|
84
|
+
var _a, _b;
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const location = yield scope.getCurrentLocation();
|
|
87
|
+
if (location && !((_a = this.toolBeltVc) === null || _a === void 0 ? void 0 : _a.getTool('people'))) {
|
|
88
|
+
this.personSelectVc = this.PersonSelectVc();
|
|
89
|
+
(_b = this.toolBeltVc) === null || _b === void 0 ? void 0 : _b.addTool({
|
|
90
|
+
lineIcon: 'user',
|
|
91
|
+
id: 'people',
|
|
92
|
+
card: this.personSelectVc.render(),
|
|
93
|
+
});
|
|
94
|
+
yield this.personSelectVc.load();
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getPersonSelectCardVc() {
|
|
99
|
+
return this.personSelectVc;
|
|
100
|
+
}
|
|
101
|
+
getDateSelectVc() {
|
|
102
|
+
return this.dateSelectVc;
|
|
103
|
+
}
|
|
104
|
+
getSelectedDate() {
|
|
105
|
+
return this.dateSelectVc.getSelectedDate();
|
|
106
|
+
}
|
|
107
|
+
setSelectedDate(year, month, day) {
|
|
108
|
+
var _a;
|
|
109
|
+
this.lastSelectedDate = {
|
|
110
|
+
year,
|
|
111
|
+
month,
|
|
112
|
+
day,
|
|
113
|
+
};
|
|
114
|
+
(_a = this.dateSelectVc) === null || _a === void 0 ? void 0 : _a.setSelectedDate(year, month, day);
|
|
115
|
+
}
|
|
116
|
+
PersonSelectVc() {
|
|
117
|
+
var _a;
|
|
118
|
+
return (_a = this.sm) === null || _a === void 0 ? void 0 : _a.Controller('calendar.person-select-tool', {
|
|
119
|
+
people: this.people,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
export default function makeEventTyped(event: SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent, type: SpruceSchemas.Calendar.v2021_05_19.CalendarEventType): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import draftEventGenerator from '../../utilities/draftGenerator.js';
|
|
2
|
+
export default function makeEventTyped(event, type) {
|
|
3
|
+
var _a;
|
|
4
|
+
const { timeBlocks } = event;
|
|
5
|
+
timeBlocks[0].title = draftEventGenerator.generateTitle(type.name);
|
|
6
|
+
timeBlocks[0].leftIcons = [{ icon: (_a = type.lineIcon) !== null && _a !== void 0 ? _a : 'coffee', hint: null }];
|
|
7
|
+
return event;
|
|
8
|
+
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { AbstractViewController, LineIcon, SkillViewControllerLoadOptions, ToolBeltState, ToolBeltStateMachine } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { SpruceSchemas } from '@sprucelabs/mercury-types';
|
|
3
3
|
import { EventTarget } from '@sprucelabs/spruce-event-utils';
|
|
4
|
+
import { UpdateRepeatingStrategy } from '../constants';
|
|
5
|
+
import { CalendarEventManager } from '../utilities/CalendarEventManager';
|
|
6
|
+
import CalendarPeopleManager from '../utilities/CalendarPeopleManager';
|
|
4
7
|
import CalendarViewController from '../viewControllers/Calendar.vc';
|
|
5
8
|
export interface Schedule {
|
|
6
9
|
target: EventTarget;
|
|
7
10
|
events: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent[];
|
|
8
11
|
}
|
|
12
|
+
export declare type EventForShift = Pick<CalendarEvent, 'id' | 'timeBlocks' | 'startDateTimeMs' | 'target'>;
|
|
9
13
|
export declare type DraftEvent = Pick<CalendarEvent, 'id' | 'startDateTimeMs' | 'style' | 'calendarId' | 'target' | 'timeBlocks' | 'isBusy'>;
|
|
10
14
|
export declare type CalendarEvent = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
11
15
|
export declare type UpdateEvent = SpruceSchemas.Calendar.v2021_05_19.UpdateCalendarEventEmitPayload & CalendarEvent;
|
|
@@ -17,8 +21,13 @@ export declare type SimpleCalendar = Pick<Calendar, 'id' | 'availableTimeSlotBeh
|
|
|
17
21
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
18
22
|
declare type ICalendarToolBeltContext = SkillViewControllerLoadOptions & {
|
|
19
23
|
event: CalendarEvent;
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated use events or people to control the state of the calendar
|
|
26
|
+
*/
|
|
20
27
|
calendarVc: CalendarViewController;
|
|
21
28
|
cancelEvent: CancelEventHandler;
|
|
29
|
+
events: CalendarEventManager;
|
|
30
|
+
people: CalendarPeopleManager;
|
|
22
31
|
};
|
|
23
32
|
export interface CalendarToolBeltContext extends ICalendarToolBeltContext {
|
|
24
33
|
}
|
|
@@ -41,6 +50,7 @@ export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltCo
|
|
|
41
50
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
42
51
|
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
43
52
|
export declare type CancelEventHandler = (eventId: string) => boolean | Promise<boolean | void> | void;
|
|
53
|
+
export declare type UpdateRepeatingStrategyWithCancel = UpdateRepeatingStrategy | 'cancel';
|
|
44
54
|
export interface CalendarToolOptions {
|
|
45
55
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
46
56
|
getContext: GetCalendarToolBeltContextHandler;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { DateUtils } from '@sprucelabs/calendar-utils';
|
|
2
|
+
import { CalendarEvent } from '@sprucelabs/heartwood-view-controllers';
|
|
3
|
+
import { RemoteViewControllerFactory } from '@sprucelabs/spruce-heartwood-utils';
|
|
4
|
+
import RemoteEventStore from '../stores/RemoteEventStore';
|
|
5
|
+
import RemotePreferencesStore from '../stores/RemotePreferencesStore';
|
|
6
|
+
import { CalendarToolBeltStateMachine, UpdateEvent, UpdateRepeatingStrategyWithCancel } from '../types/calendar.types';
|
|
7
|
+
import CalendarViewController from '../viewControllers/Calendar.vc';
|
|
8
|
+
export declare class CalendarEventManager {
|
|
9
|
+
private calendarVc;
|
|
10
|
+
protected allEvents: CalendarEvent[];
|
|
11
|
+
private inclusiveCalendarIds;
|
|
12
|
+
protected events: RemoteEventStore;
|
|
13
|
+
private eventTypes?;
|
|
14
|
+
private remoteVc;
|
|
15
|
+
private hasVcForEventTypeBeenLoaded;
|
|
16
|
+
private sm;
|
|
17
|
+
private shouldIgnoreNextContextUpdate;
|
|
18
|
+
private askForUpdateStrategy;
|
|
19
|
+
private dateToUpdate?;
|
|
20
|
+
private shouldUpdateAllEventsGoingForward?;
|
|
21
|
+
private dates;
|
|
22
|
+
protected prefs: RemotePreferencesStore;
|
|
23
|
+
private calendars;
|
|
24
|
+
private shouldUpdateContextOnNextSave;
|
|
25
|
+
protected get calendarIds(): string[];
|
|
26
|
+
protected get visibleCalendarIds(): string[];
|
|
27
|
+
constructor(options: CalendarEventManagerOptions);
|
|
28
|
+
replaceEventsInRange(events: CalendarEvent[], startMs: number, endMs: number): void;
|
|
29
|
+
private refreshShifts;
|
|
30
|
+
private isCalendarSelected;
|
|
31
|
+
private doesCalenderExist;
|
|
32
|
+
getAllEvents(): CalendarEvent[];
|
|
33
|
+
getCalendars(): import("@sprucelabs/calendar-utils").SpruceSchemas.Calendar.v2021_05_19.Calendar[];
|
|
34
|
+
addDraftEvent(event: CalendarEvent): Promise<void>;
|
|
35
|
+
silentlySwapEvent(oldId: string, event: CalendarEvent): Promise<void>;
|
|
36
|
+
handleDropEvent(id: string, updates: Partial<CalendarEvent>): Promise<boolean>;
|
|
37
|
+
reset(): Promise<void>;
|
|
38
|
+
restoreEventToDraftOnStateLoadError(): Promise<void>;
|
|
39
|
+
getVisibleCalendarIds(): string[];
|
|
40
|
+
removeEvent(id: string): Promise<void>;
|
|
41
|
+
makeCalendarVisible(calendarId: string): Promise<void>;
|
|
42
|
+
makeCalendarHidden(calendarId: string): Promise<void>;
|
|
43
|
+
updateEvent(id: string, updates: Partial<CalendarEvent> & {
|
|
44
|
+
dateToUpdate?: number;
|
|
45
|
+
shouldUpdateAllEventsGoingForward?: boolean;
|
|
46
|
+
}): void;
|
|
47
|
+
loadEvents(startDate: number, endDate: number, peopleIds: string[]): Promise<void>;
|
|
48
|
+
setCalendarVisibility(calendarId: string, shouldBeVisible: boolean): Promise<void>;
|
|
49
|
+
setupVcForEventType(vcId: string, typeSlug: string): Promise<void>;
|
|
50
|
+
private assertValidCalendarId;
|
|
51
|
+
private updateEventInContext;
|
|
52
|
+
private setEventInContext;
|
|
53
|
+
selectEvent(eventId: string): Promise<void>;
|
|
54
|
+
load(): Promise<void>;
|
|
55
|
+
private loadCalendars;
|
|
56
|
+
private handleWillUpdateContext;
|
|
57
|
+
private handleDidUpdateContext;
|
|
58
|
+
private saveEvent;
|
|
59
|
+
optionallyAskForUpdateRepeatingStrategy(event: UpdateEvent): Promise<boolean>;
|
|
60
|
+
}
|
|
61
|
+
export declare type EventManagerCalendarVc = Pick<CalendarViewController, 'replaceEventsInRange' | 'mixinEvents' | 'removeEvent' | 'addEvent' | 'hasEvent' | 'updateEvent' | 'setShifts' | 'getShifts' | 'getEvent' | 'getPeople' | 'setControllerForEventType' | 'setRemoteStore' | 'getSelectedEvent' | 'selectEvent'>;
|
|
62
|
+
declare type EventManagerRemoteViewControllerFactory = Pick<RemoteViewControllerFactory, 'fetchRemoteController'>;
|
|
63
|
+
export interface CalendarEventManagerOptions {
|
|
64
|
+
calendarVc: EventManagerCalendarVc;
|
|
65
|
+
events: RemoteEventStore;
|
|
66
|
+
remoteVc: EventManagerRemoteViewControllerFactory;
|
|
67
|
+
sm: CalendarToolBeltStateMachine;
|
|
68
|
+
dates: DateUtils;
|
|
69
|
+
preferences: RemotePreferencesStore;
|
|
70
|
+
askForUpdateStrategy: (event: UpdateEvent) => Promise<UpdateRepeatingStrategyWithCancel>;
|
|
71
|
+
}
|
|
72
|
+
export {};
|