@sprucelabs/spruce-calendar-components 19.1.2 → 20.0.0
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/esm/stores/RemoteEventStore.d.ts +2 -2
- package/build/esm/stores/RemoteEventStore.js +4 -4
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +1 -1
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +7 -7
- package/build/esm/types/calendar.types.d.ts +6 -1
- package/build/esm/viewControllers/Calendar.vc.d.ts +2 -1
- package/build/esm/viewControllers/Calendar.vc.js +26 -10
- package/build/esm/viewControllers/EventControlsCard.vc.d.ts +4 -2
- package/build/esm/viewControllers/EventControlsCard.vc.js +32 -2
- package/build/esm/viewControllers/RepeatingControlsList.vc.js +2 -2
- package/build/stores/RemoteEventStore.d.ts +2 -2
- package/build/stores/RemoteEventStore.js +4 -4
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +1 -1
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +7 -7
- package/build/types/calendar.types.d.ts +6 -1
- package/build/viewControllers/Calendar.vc.d.ts +2 -1
- package/build/viewControllers/Calendar.vc.js +23 -9
- package/build/viewControllers/EventControlsCard.vc.d.ts +4 -2
- package/build/viewControllers/EventControlsCard.vc.js +35 -2
- package/build/viewControllers/RepeatingControlsList.vc.js +2 -2
- package/package.json +1 -1
|
@@ -4,13 +4,13 @@ import { UpdateEvent } from '../types/calendar.types';
|
|
|
4
4
|
export interface RemoteEventStoreOptions {
|
|
5
5
|
client: MercuryClient;
|
|
6
6
|
calendarId?: string;
|
|
7
|
-
|
|
7
|
+
locationId: string;
|
|
8
8
|
}
|
|
9
9
|
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
10
10
|
export default class RemoteEventStore {
|
|
11
11
|
private client;
|
|
12
12
|
private calendarId?;
|
|
13
|
-
private
|
|
13
|
+
private locationId;
|
|
14
14
|
private pendingEvent?;
|
|
15
15
|
private draftIdMap;
|
|
16
16
|
private promises;
|
|
@@ -28,10 +28,10 @@ export default class RemoteEventStore {
|
|
|
28
28
|
this.queueByEventId = {};
|
|
29
29
|
this.busyByEvent = {};
|
|
30
30
|
this.lastSavedById = {};
|
|
31
|
-
assertOptions(options, ['client', '
|
|
31
|
+
assertOptions(options, ['client', 'locationId']);
|
|
32
32
|
this.client = options.client;
|
|
33
33
|
this.calendarId = options.calendarId;
|
|
34
|
-
this.
|
|
34
|
+
this.locationId = options.locationId;
|
|
35
35
|
}
|
|
36
36
|
persist(event) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -141,7 +141,7 @@ export default class RemoteEventStore {
|
|
|
141
141
|
payload = this.cleanPayload(payload);
|
|
142
142
|
return {
|
|
143
143
|
payload,
|
|
144
|
-
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId,
|
|
144
|
+
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId, locationId: this.locationId }),
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
cleanTarget(target) {
|
|
@@ -195,7 +195,7 @@ export default class RemoteEventStore {
|
|
|
195
195
|
else {
|
|
196
196
|
yield this.client.emitAndFlattenResponses('calendar.delete-calendar-event::v2021_05_19', {
|
|
197
197
|
target: {
|
|
198
|
-
|
|
198
|
+
locationId: this.locationId,
|
|
199
199
|
calendarEventId: id,
|
|
200
200
|
},
|
|
201
201
|
});
|
|
@@ -18,7 +18,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
18
18
|
private handleDidUpdateContext;
|
|
19
19
|
private getContext;
|
|
20
20
|
clearPendingContextChanges(): Promise<void>;
|
|
21
|
-
addTool(options: AddToolOptions): Promise<
|
|
21
|
+
addTool(options: AddToolOptions): Promise<CalendarTool>;
|
|
22
22
|
private buildVcConstructorOptions;
|
|
23
23
|
private addVc;
|
|
24
24
|
protected getPersonFromEvent(): ReturnType<GetPersonFromEventHandler>;
|
|
@@ -22,10 +22,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
22
22
|
this.sm = sm;
|
|
23
23
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
24
24
|
this._isLoaded = true;
|
|
25
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', {
|
|
26
|
-
onCancel: this.clearPendingContextChanges.bind(this),
|
|
27
|
-
onSave: this.handleClickSave.bind(this),
|
|
28
|
-
});
|
|
25
|
+
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
29
26
|
this.toolBeltVc.clearTools();
|
|
30
27
|
this.toolBeltVc.setStickyTool({
|
|
31
28
|
card: this.controlsVc.render(),
|
|
@@ -79,13 +76,15 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
79
76
|
const { cardVcId, lineIcon, id } = options;
|
|
80
77
|
const vc = this.sm.Controller(cardVcId, this.buildVcConstructorOptions(id));
|
|
81
78
|
yield this.addVc(id, lineIcon, vc);
|
|
79
|
+
return vc;
|
|
82
80
|
});
|
|
83
81
|
}
|
|
84
82
|
buildVcConstructorOptions(id) {
|
|
85
83
|
return {
|
|
86
|
-
updateContext: (updates) => this.handleUpdateContextFromTool(updates, id),
|
|
84
|
+
updateContext: (updates, options) => this.handleUpdateContextFromTool(updates, id, options),
|
|
87
85
|
getContext: () => this.getContext(),
|
|
88
86
|
getPersonFromEvent: () => this.getPersonFromEvent(),
|
|
87
|
+
getHasPendingContextChanges: () => Object.keys(this.pendingContextUpdates).length > 0,
|
|
89
88
|
};
|
|
90
89
|
}
|
|
91
90
|
addVc(toolId, lineIcon, vc) {
|
|
@@ -122,7 +121,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
122
121
|
return null;
|
|
123
122
|
});
|
|
124
123
|
}
|
|
125
|
-
handleUpdateContextFromTool(updates, fromToolId) {
|
|
124
|
+
handleUpdateContextFromTool(updates, fromToolId, options) {
|
|
126
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
127
126
|
const pendingUpdates = Object.assign(Object.assign({}, this.pendingContextUpdates), updates);
|
|
128
127
|
if (equalDeep(this.pendingContextUpdates, pendingUpdates)) {
|
|
@@ -131,7 +130,8 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
131
130
|
this.pendingContextUpdates = pendingUpdates;
|
|
132
131
|
yield this.handleDidUpdateContext(fromToolId);
|
|
133
132
|
const vc = this.getVcForTool(fromToolId);
|
|
134
|
-
if (vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately)
|
|
133
|
+
if ((vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately) ||
|
|
134
|
+
(options === null || options === void 0 ? void 0 : options.shouldPersistContextChangesImmediately)) {
|
|
135
135
|
yield this.sm.updateContext(Object.assign({}, updates));
|
|
136
136
|
}
|
|
137
137
|
});
|
|
@@ -28,13 +28,18 @@ export interface CalendarTool extends AbstractViewController<Card> {
|
|
|
28
28
|
handleUpdateContext(context: CalendarToolBeltContext): Promise<void> | void;
|
|
29
29
|
load?: () => Promise<void> | void;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export interface UpdateCalendarContextOptions {
|
|
32
|
+
shouldPersistContextChangesImmediately?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
32
35
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
33
36
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
|
+
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
34
38
|
export interface CalendarToolOptions {
|
|
35
39
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
36
40
|
getContext: GetCalendarToolBeltContextHandler;
|
|
37
41
|
getPersonFromEvent: GetPersonFromEventHandler;
|
|
42
|
+
getHasPendingContextChanges: GetHasPendingContextChangesHandler;
|
|
38
43
|
}
|
|
39
44
|
export interface EventWithToolBeltState {
|
|
40
45
|
getToolBeltState(): ToolBeltState;
|
|
@@ -38,7 +38,8 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
38
38
|
private handleClick;
|
|
39
39
|
private getDraftEvent;
|
|
40
40
|
private removeDraftEvent;
|
|
41
|
-
private
|
|
41
|
+
private addDraftEventFromClick;
|
|
42
|
+
addDraftEvent(event: Event): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | UpdateEvent | undefined>;
|
|
42
43
|
getIsSwappingEvent(): boolean;
|
|
43
44
|
private swapEvent;
|
|
44
45
|
updateEvent(id: string, updates: Partial<UpdateEvent>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
};
|
|
21
21
|
import { PeopleSorter } from '@sprucelabs/calendar-utils';
|
|
22
22
|
import { CalendarViewController as CoreCalendarViewController, } from '@sprucelabs/heartwood-view-controllers';
|
|
23
|
-
import { assertOptions } from '@sprucelabs/schema';
|
|
23
|
+
import { assertOptions, SchemaError } from '@sprucelabs/schema';
|
|
24
24
|
import draftEventGenerator from '../utilities/draftGenerator.js';
|
|
25
25
|
export default class CalendarViewController extends CoreCalendarViewController {
|
|
26
26
|
constructor(options) {
|
|
@@ -43,13 +43,13 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
43
43
|
handleDropEvent(options) {
|
|
44
44
|
var _a;
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const { event, blockUpdates,
|
|
46
|
+
const { event, blockUpdates, newPersonId, newStartDateTimeMs } = options;
|
|
47
47
|
const updates = {};
|
|
48
48
|
if (newStartDateTimeMs) {
|
|
49
49
|
updates.startDateTimeMs = newStartDateTimeMs;
|
|
50
50
|
}
|
|
51
|
-
if (
|
|
52
|
-
updates.target = Object.assign(Object.assign({}, event.target), { personId:
|
|
51
|
+
if (newPersonId) {
|
|
52
|
+
updates.target = Object.assign(Object.assign({}, event.target), { personId: newPersonId });
|
|
53
53
|
}
|
|
54
54
|
if (blockUpdates) {
|
|
55
55
|
updates.timeBlocks = [...event.timeBlocks];
|
|
@@ -84,7 +84,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
84
84
|
}
|
|
85
85
|
const draft = this.getDraftEvent();
|
|
86
86
|
if (!draft) {
|
|
87
|
-
yield this.
|
|
87
|
+
yield this.addDraftEventFromClick(options);
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
90
|
yield this.removeDraftEvent(draft.id);
|
|
@@ -108,16 +108,30 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
108
108
|
catch (_c) { }
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
addDraftEventFromClick(options) {
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const {
|
|
114
|
-
const
|
|
115
|
-
|
|
113
|
+
const { personId, dateTimeMs } = options;
|
|
114
|
+
const event = Object.assign({}, draftEventGenerator.generate(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : 0, personId !== null && personId !== void 0 ? personId : '**missing**'));
|
|
115
|
+
//@ts-ignore
|
|
116
|
+
delete event.id;
|
|
117
|
+
return yield this.addDraftEvent(event);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
addDraftEvent(event) {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
if (event.id) {
|
|
123
|
+
throw new SchemaError({
|
|
124
|
+
code: 'UNEXPECTED_PARAMETERS',
|
|
125
|
+
parameters: ['id'],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
event.id = draftEventGenerator.generateId();
|
|
116
129
|
this.addEvent(event);
|
|
117
130
|
this.selectEvent(event.id);
|
|
118
131
|
const draftAddedPromise = this.draftAddedHandler(event);
|
|
119
|
-
yield this.persist(event);
|
|
132
|
+
const saved = yield this.persist(event);
|
|
120
133
|
yield draftAddedPromise;
|
|
134
|
+
return saved;
|
|
121
135
|
});
|
|
122
136
|
}
|
|
123
137
|
getIsSwappingEvent() {
|
|
@@ -180,12 +194,14 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
180
194
|
else {
|
|
181
195
|
_super.updateEvent.call(this, saved.id, { isBusy, error: undefined });
|
|
182
196
|
}
|
|
197
|
+
return saved;
|
|
183
198
|
}
|
|
184
199
|
catch (err) {
|
|
185
200
|
if (this.hasEvent(id)) {
|
|
186
201
|
_super.updateEvent.call(this, id, { error: err, isBusy: false });
|
|
187
202
|
}
|
|
188
203
|
}
|
|
204
|
+
return event;
|
|
189
205
|
});
|
|
190
206
|
}
|
|
191
207
|
getPeople() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
-
export interface EventControlsCardOptions {
|
|
4
|
+
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
6
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
7
|
}
|
|
@@ -10,6 +10,8 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
10
10
|
private cardVc;
|
|
11
11
|
private saveHandler;
|
|
12
12
|
private cancelHandler;
|
|
13
|
+
private getHasPendingContextChangesHandler;
|
|
14
|
+
private getContext;
|
|
13
15
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
14
16
|
private handleClickCancel;
|
|
15
17
|
private handleClickSave;
|
|
@@ -9,12 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
|
|
11
11
|
import { assertOptions } from '@sprucelabs/schema';
|
|
12
|
+
import draftEventGenerator from '../utilities/draftGenerator.js';
|
|
12
13
|
export default class EventControlsCardViewController extends AbstractViewController {
|
|
13
14
|
constructor(options) {
|
|
14
15
|
super(options);
|
|
15
|
-
const { onSave, onCancel } = assertOptions(options, [
|
|
16
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext } = assertOptions(options, [
|
|
17
|
+
'onCancel',
|
|
18
|
+
'onSave',
|
|
19
|
+
'getHasPendingContextChanges',
|
|
20
|
+
'getContext',
|
|
21
|
+
]);
|
|
16
22
|
this.saveHandler = onSave;
|
|
17
23
|
this.cancelHandler = onCancel;
|
|
24
|
+
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
25
|
+
this.getContext = getContext;
|
|
18
26
|
this.cardVc = this.Controller('card', {
|
|
19
27
|
footer: {
|
|
20
28
|
isEnabled: false,
|
|
@@ -50,7 +58,29 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
50
58
|
});
|
|
51
59
|
}
|
|
52
60
|
handleUpdateContext() {
|
|
53
|
-
|
|
61
|
+
var _a;
|
|
62
|
+
if (this.getHasPendingContextChangesHandler()) {
|
|
63
|
+
this.cardVc.enableFooter();
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.cardVc.disableFooter();
|
|
67
|
+
}
|
|
68
|
+
const { event } = this.getContext();
|
|
69
|
+
if ((event === null || event === void 0 ? void 0 : event.id) && !draftEventGenerator.isDraftId(event.id)) {
|
|
70
|
+
this.cardVc.setBody({
|
|
71
|
+
sections: [
|
|
72
|
+
{
|
|
73
|
+
buttons: [
|
|
74
|
+
{
|
|
75
|
+
id: 'cancel-event',
|
|
76
|
+
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
77
|
+
type: 'destructive',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
54
84
|
}
|
|
55
85
|
render() {
|
|
56
86
|
return this.cardVc.render();
|
|
@@ -336,8 +336,8 @@ export default class RepeatingControlsListViewController extends AbstractViewCon
|
|
|
336
336
|
return this.Controller('calendar', {
|
|
337
337
|
onClick: (options) => __awaiter(this, void 0, void 0, function* () {
|
|
338
338
|
var _b;
|
|
339
|
-
if (options.
|
|
340
|
-
this.changeCalendarSelectedDate(options.
|
|
339
|
+
if (options.dateTimeMs) {
|
|
340
|
+
this.changeCalendarSelectedDate(options.dateTimeMs);
|
|
341
341
|
(_b = this.didChangeRepeating) === null || _b === void 0 ? void 0 : _b.call(this, this.repeating);
|
|
342
342
|
}
|
|
343
343
|
}),
|
|
@@ -4,13 +4,13 @@ import { UpdateEvent } from '../types/calendar.types';
|
|
|
4
4
|
export interface RemoteEventStoreOptions {
|
|
5
5
|
client: MercuryClient;
|
|
6
6
|
calendarId?: string;
|
|
7
|
-
|
|
7
|
+
locationId: string;
|
|
8
8
|
}
|
|
9
9
|
declare type FullEvent = SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent;
|
|
10
10
|
export default class RemoteEventStore {
|
|
11
11
|
private client;
|
|
12
12
|
private calendarId?;
|
|
13
|
-
private
|
|
13
|
+
private locationId;
|
|
14
14
|
private pendingEvent?;
|
|
15
15
|
private draftIdMap;
|
|
16
16
|
private promises;
|
|
@@ -24,10 +24,10 @@ class RemoteEventStore {
|
|
|
24
24
|
this.queueByEventId = {};
|
|
25
25
|
this.busyByEvent = {};
|
|
26
26
|
this.lastSavedById = {};
|
|
27
|
-
(0, schema_1.assertOptions)(options, ['client', '
|
|
27
|
+
(0, schema_1.assertOptions)(options, ['client', 'locationId']);
|
|
28
28
|
this.client = options.client;
|
|
29
29
|
this.calendarId = options.calendarId;
|
|
30
|
-
this.
|
|
30
|
+
this.locationId = options.locationId;
|
|
31
31
|
}
|
|
32
32
|
async persist(event) {
|
|
33
33
|
if (!this.resolveCalendarId(event)) {
|
|
@@ -127,7 +127,7 @@ class RemoteEventStore {
|
|
|
127
127
|
payload = this.cleanPayload(payload);
|
|
128
128
|
return {
|
|
129
129
|
payload,
|
|
130
|
-
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId,
|
|
130
|
+
target: Object.assign(Object.assign({}, target), { calendarEventPersonId: personId, locationId: this.locationId }),
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
cleanTarget(target) {
|
|
@@ -178,7 +178,7 @@ class RemoteEventStore {
|
|
|
178
178
|
else {
|
|
179
179
|
await this.client.emitAndFlattenResponses('calendar.delete-calendar-event::v2021_05_19', {
|
|
180
180
|
target: {
|
|
181
|
-
|
|
181
|
+
locationId: this.locationId,
|
|
182
182
|
calendarEventId: id,
|
|
183
183
|
},
|
|
184
184
|
});
|
|
@@ -18,7 +18,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
18
18
|
private handleDidUpdateContext;
|
|
19
19
|
private getContext;
|
|
20
20
|
clearPendingContextChanges(): Promise<void>;
|
|
21
|
-
addTool(options: AddToolOptions): Promise<
|
|
21
|
+
addTool(options: AddToolOptions): Promise<CalendarTool>;
|
|
22
22
|
private buildVcConstructorOptions;
|
|
23
23
|
private addVc;
|
|
24
24
|
protected getPersonFromEvent(): ReturnType<GetPersonFromEventHandler>;
|
|
@@ -17,10 +17,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
17
17
|
this.sm = sm;
|
|
18
18
|
this.toolBeltVc = sm.getToolBeltVc();
|
|
19
19
|
this._isLoaded = true;
|
|
20
|
-
this.controlsVc = sm.Controller('calendar.event-controls-card', {
|
|
21
|
-
onCancel: this.clearPendingContextChanges.bind(this),
|
|
22
|
-
onSave: this.handleClickSave.bind(this),
|
|
23
|
-
});
|
|
20
|
+
this.controlsVc = sm.Controller('calendar.event-controls-card', Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')));
|
|
24
21
|
this.toolBeltVc.clearTools();
|
|
25
22
|
this.toolBeltVc.setStickyTool({
|
|
26
23
|
card: this.controlsVc.render(),
|
|
@@ -64,12 +61,14 @@ class AbstractCalendarEventToolBeltState {
|
|
|
64
61
|
const { cardVcId, lineIcon, id } = options;
|
|
65
62
|
const vc = this.sm.Controller(cardVcId, this.buildVcConstructorOptions(id));
|
|
66
63
|
await this.addVc(id, lineIcon, vc);
|
|
64
|
+
return vc;
|
|
67
65
|
}
|
|
68
66
|
buildVcConstructorOptions(id) {
|
|
69
67
|
return {
|
|
70
|
-
updateContext: (updates) => this.handleUpdateContextFromTool(updates, id),
|
|
68
|
+
updateContext: (updates, options) => this.handleUpdateContextFromTool(updates, id, options),
|
|
71
69
|
getContext: () => this.getContext(),
|
|
72
70
|
getPersonFromEvent: () => this.getPersonFromEvent(),
|
|
71
|
+
getHasPendingContextChanges: () => Object.keys(this.pendingContextUpdates).length > 0,
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
74
|
async addVc(toolId, lineIcon, vc) {
|
|
@@ -102,7 +101,7 @@ class AbstractCalendarEventToolBeltState {
|
|
|
102
101
|
}
|
|
103
102
|
return null;
|
|
104
103
|
}
|
|
105
|
-
async handleUpdateContextFromTool(updates, fromToolId) {
|
|
104
|
+
async handleUpdateContextFromTool(updates, fromToolId, options) {
|
|
106
105
|
const pendingUpdates = Object.assign(Object.assign({}, this.pendingContextUpdates), updates);
|
|
107
106
|
if ((0, isEqual_1.default)(this.pendingContextUpdates, pendingUpdates)) {
|
|
108
107
|
return;
|
|
@@ -110,7 +109,8 @@ class AbstractCalendarEventToolBeltState {
|
|
|
110
109
|
this.pendingContextUpdates = pendingUpdates;
|
|
111
110
|
await this.handleDidUpdateContext(fromToolId);
|
|
112
111
|
const vc = this.getVcForTool(fromToolId);
|
|
113
|
-
if (vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately)
|
|
112
|
+
if ((vc === null || vc === void 0 ? void 0 : vc.shouldPersistContextChangesImmediately) ||
|
|
113
|
+
(options === null || options === void 0 ? void 0 : options.shouldPersistContextChangesImmediately)) {
|
|
114
114
|
await this.sm.updateContext(Object.assign({}, updates));
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -28,13 +28,18 @@ export interface CalendarTool extends AbstractViewController<Card> {
|
|
|
28
28
|
handleUpdateContext(context: CalendarToolBeltContext): Promise<void> | void;
|
|
29
29
|
load?: () => Promise<void> | void;
|
|
30
30
|
}
|
|
31
|
-
export
|
|
31
|
+
export interface UpdateCalendarContextOptions {
|
|
32
|
+
shouldPersistContextChangesImmediately?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
32
35
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
33
36
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
37
|
+
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
34
38
|
export interface CalendarToolOptions {
|
|
35
39
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
36
40
|
getContext: GetCalendarToolBeltContextHandler;
|
|
37
41
|
getPersonFromEvent: GetPersonFromEventHandler;
|
|
42
|
+
getHasPendingContextChanges: GetHasPendingContextChangesHandler;
|
|
38
43
|
}
|
|
39
44
|
export interface EventWithToolBeltState {
|
|
40
45
|
getToolBeltState(): ToolBeltState;
|
|
@@ -38,7 +38,8 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
38
38
|
private handleClick;
|
|
39
39
|
private getDraftEvent;
|
|
40
40
|
private removeDraftEvent;
|
|
41
|
-
private
|
|
41
|
+
private addDraftEventFromClick;
|
|
42
|
+
addDraftEvent(event: Event): Promise<SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEvent | UpdateEvent | undefined>;
|
|
42
43
|
getIsSwappingEvent(): boolean;
|
|
43
44
|
private swapEvent;
|
|
44
45
|
updateEvent(id: string, updates: Partial<UpdateEvent>): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarEvent;
|
|
@@ -38,13 +38,13 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
38
38
|
}
|
|
39
39
|
async handleDropEvent(options) {
|
|
40
40
|
var _a;
|
|
41
|
-
const { event, blockUpdates,
|
|
41
|
+
const { event, blockUpdates, newPersonId, newStartDateTimeMs } = options;
|
|
42
42
|
const updates = {};
|
|
43
43
|
if (newStartDateTimeMs) {
|
|
44
44
|
updates.startDateTimeMs = newStartDateTimeMs;
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
47
|
-
updates.target = Object.assign(Object.assign({}, event.target), { personId:
|
|
46
|
+
if (newPersonId) {
|
|
47
|
+
updates.target = Object.assign(Object.assign({}, event.target), { personId: newPersonId });
|
|
48
48
|
}
|
|
49
49
|
if (blockUpdates) {
|
|
50
50
|
updates.timeBlocks = [...event.timeBlocks];
|
|
@@ -77,7 +77,7 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
77
77
|
}
|
|
78
78
|
const draft = this.getDraftEvent();
|
|
79
79
|
if (!draft) {
|
|
80
|
-
await this.
|
|
80
|
+
await this.addDraftEventFromClick(options);
|
|
81
81
|
}
|
|
82
82
|
else {
|
|
83
83
|
await this.removeDraftEvent(draft.id);
|
|
@@ -98,15 +98,27 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
98
98
|
}
|
|
99
99
|
catch (_c) { }
|
|
100
100
|
}
|
|
101
|
-
async
|
|
102
|
-
const {
|
|
103
|
-
const
|
|
104
|
-
|
|
101
|
+
async addDraftEventFromClick(options) {
|
|
102
|
+
const { personId, dateTimeMs } = options;
|
|
103
|
+
const event = Object.assign({}, draftGenerator_1.default.generate(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : 0, personId !== null && personId !== void 0 ? personId : '**missing**'));
|
|
104
|
+
//@ts-ignore
|
|
105
|
+
delete event.id;
|
|
106
|
+
return await this.addDraftEvent(event);
|
|
107
|
+
}
|
|
108
|
+
async addDraftEvent(event) {
|
|
109
|
+
if (event.id) {
|
|
110
|
+
throw new schema_1.SchemaError({
|
|
111
|
+
code: 'UNEXPECTED_PARAMETERS',
|
|
112
|
+
parameters: ['id'],
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
event.id = draftGenerator_1.default.generateId();
|
|
105
116
|
this.addEvent(event);
|
|
106
117
|
this.selectEvent(event.id);
|
|
107
118
|
const draftAddedPromise = this.draftAddedHandler(event);
|
|
108
|
-
await this.persist(event);
|
|
119
|
+
const saved = await this.persist(event);
|
|
109
120
|
await draftAddedPromise;
|
|
121
|
+
return saved;
|
|
110
122
|
}
|
|
111
123
|
getIsSwappingEvent() {
|
|
112
124
|
return this.isSwapping;
|
|
@@ -159,12 +171,14 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
159
171
|
else {
|
|
160
172
|
super.updateEvent(saved.id, { isBusy, error: undefined });
|
|
161
173
|
}
|
|
174
|
+
return saved;
|
|
162
175
|
}
|
|
163
176
|
catch (err) {
|
|
164
177
|
if (this.hasEvent(id)) {
|
|
165
178
|
super.updateEvent(id, { error: err, isBusy: false });
|
|
166
179
|
}
|
|
167
180
|
}
|
|
181
|
+
return event;
|
|
168
182
|
}
|
|
169
183
|
getPeople() {
|
|
170
184
|
const people = super.getPeople();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions } from '../types/calendar.types';
|
|
3
3
|
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
-
export interface EventControlsCardOptions {
|
|
4
|
+
export interface EventControlsCardOptions extends CalendarToolOptions {
|
|
5
5
|
onCancel: () => Promise<void | boolean> | void | boolean;
|
|
6
6
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
7
|
}
|
|
@@ -10,6 +10,8 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
10
10
|
private cardVc;
|
|
11
11
|
private saveHandler;
|
|
12
12
|
private cancelHandler;
|
|
13
|
+
private getHasPendingContextChangesHandler;
|
|
14
|
+
private getContext;
|
|
13
15
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
14
16
|
private handleClickCancel;
|
|
15
17
|
private handleClickSave;
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const heartwood_view_controllers_1 = require("@sprucelabs/heartwood-view-controllers");
|
|
4
7
|
const schema_1 = require("@sprucelabs/schema");
|
|
8
|
+
const draftGenerator_1 = __importDefault(require("../utilities/draftGenerator"));
|
|
5
9
|
class EventControlsCardViewController extends heartwood_view_controllers_1.AbstractViewController {
|
|
6
10
|
constructor(options) {
|
|
7
11
|
super(options);
|
|
8
|
-
const { onSave, onCancel } = (0, schema_1.assertOptions)(options, [
|
|
12
|
+
const { onSave, onCancel, getHasPendingContextChanges, getContext } = (0, schema_1.assertOptions)(options, [
|
|
13
|
+
'onCancel',
|
|
14
|
+
'onSave',
|
|
15
|
+
'getHasPendingContextChanges',
|
|
16
|
+
'getContext',
|
|
17
|
+
]);
|
|
9
18
|
this.saveHandler = onSave;
|
|
10
19
|
this.cancelHandler = onCancel;
|
|
20
|
+
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
21
|
+
this.getContext = getContext;
|
|
11
22
|
this.cardVc = this.Controller('card', {
|
|
12
23
|
footer: {
|
|
13
24
|
isEnabled: false,
|
|
@@ -39,7 +50,29 @@ class EventControlsCardViewController extends heartwood_view_controllers_1.Abstr
|
|
|
39
50
|
this.cardVc.disableFooter();
|
|
40
51
|
}
|
|
41
52
|
handleUpdateContext() {
|
|
42
|
-
|
|
53
|
+
var _a;
|
|
54
|
+
if (this.getHasPendingContextChangesHandler()) {
|
|
55
|
+
this.cardVc.enableFooter();
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
this.cardVc.disableFooter();
|
|
59
|
+
}
|
|
60
|
+
const { event } = this.getContext();
|
|
61
|
+
if ((event === null || event === void 0 ? void 0 : event.id) && !draftGenerator_1.default.isDraftId(event.id)) {
|
|
62
|
+
this.cardVc.setBody({
|
|
63
|
+
sections: [
|
|
64
|
+
{
|
|
65
|
+
buttons: [
|
|
66
|
+
{
|
|
67
|
+
id: 'cancel-event',
|
|
68
|
+
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
69
|
+
type: 'destructive',
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
43
76
|
}
|
|
44
77
|
render() {
|
|
45
78
|
return this.cardVc.render();
|
|
@@ -329,8 +329,8 @@ class RepeatingControlsListViewController extends heartwood_view_controllers_1.A
|
|
|
329
329
|
return this.Controller('calendar', {
|
|
330
330
|
onClick: async (options) => {
|
|
331
331
|
var _a;
|
|
332
|
-
if (options.
|
|
333
|
-
this.changeCalendarSelectedDate(options.
|
|
332
|
+
if (options.dateTimeMs) {
|
|
333
|
+
this.changeCalendarSelectedDate(options.dateTimeMs);
|
|
334
334
|
(_a = this.didChangeRepeating) === null || _a === void 0 ? void 0 : _a.call(this, this.repeating);
|
|
335
335
|
}
|
|
336
336
|
},
|