@sprucelabs/spruce-calendar-components 19.2.0 → 20.1.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/index-components.d.ts +1 -0
- package/build/esm/index-components.js +1 -0
- 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 +3 -1
- package/build/esm/toolBelt/states/AbstractCalendarEventToolBeltState.js +6 -4
- package/build/esm/types/calendar.types.d.ts +4 -0
- package/build/esm/viewControllers/Calendar.vc.d.ts +1 -0
- package/build/esm/viewControllers/Calendar.vc.js +9 -4
- package/build/esm/viewControllers/EventControlsCard.vc.d.ts +8 -2
- package/build/esm/viewControllers/EventControlsCard.vc.js +43 -3
- package/build/index-components.d.ts +1 -0
- package/build/index-components.js +3 -1
- package/build/stores/RemoteEventStore.d.ts +2 -2
- package/build/stores/RemoteEventStore.js +4 -4
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.d.ts +3 -1
- package/build/toolBelt/states/AbstractCalendarEventToolBeltState.js +6 -4
- package/build/types/calendar.types.d.ts +4 -0
- package/build/viewControllers/Calendar.vc.d.ts +1 -0
- package/build/viewControllers/Calendar.vc.js +9 -4
- package/build/viewControllers/EventControlsCard.vc.d.ts +8 -2
- package/build/viewControllers/EventControlsCard.vc.js +46 -3
- package/package.json +1 -1
|
@@ -15,5 +15,6 @@ export { default as CalendarToolRegistrar } from './toolBelt/CalendarToolRegistr
|
|
|
15
15
|
export * from './toolBelt/CalendarToolRegistrar';
|
|
16
16
|
export { default as AbstractCalendarEventToolBeltState } from './toolBelt/states/AbstractCalendarEventToolBeltState';
|
|
17
17
|
export * from './toolBelt/states/AbstractCalendarEventToolBeltState';
|
|
18
|
+
export { default as draftEventGenerator } from './utilities/draftGenerator';
|
|
18
19
|
/** TYPES */
|
|
19
20
|
export * from './types/calendar.types';
|
|
@@ -15,5 +15,6 @@ export { default as CalendarToolRegistrar } from './toolBelt/CalendarToolRegistr
|
|
|
15
15
|
export * from './toolBelt/CalendarToolRegistrar.js';
|
|
16
16
|
export { default as AbstractCalendarEventToolBeltState } from './toolBelt/states/AbstractCalendarEventToolBeltState.js';
|
|
17
17
|
export * from './toolBelt/states/AbstractCalendarEventToolBeltState.js';
|
|
18
|
+
export { default as draftEventGenerator } from './utilities/draftGenerator.js';
|
|
18
19
|
/** TYPES */
|
|
19
20
|
export * from './types/calendar.types.js';
|
|
@@ -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
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpruceSchemas, ToolBeltState, ViewControllerId } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolBeltStateMachine, GetPersonFromEventHandler } from '../../types/calendar.types';
|
|
3
|
+
import EventControlsCardViewController from '../../viewControllers/EventControlsCard.vc';
|
|
3
4
|
declare type Tool = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool;
|
|
4
5
|
export declare type AddToolOptions = Omit<Tool, 'card'> & {
|
|
5
6
|
cardVcId: ViewControllerId;
|
|
@@ -18,7 +19,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
18
19
|
private handleDidUpdateContext;
|
|
19
20
|
private getContext;
|
|
20
21
|
clearPendingContextChanges(): Promise<void>;
|
|
21
|
-
addTool(options: AddToolOptions): Promise<
|
|
22
|
+
addTool(options: AddToolOptions): Promise<CalendarTool>;
|
|
22
23
|
private buildVcConstructorOptions;
|
|
23
24
|
private addVc;
|
|
24
25
|
protected getPersonFromEvent(): ReturnType<GetPersonFromEventHandler>;
|
|
@@ -26,6 +27,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
26
27
|
removeTool(id: string): void;
|
|
27
28
|
getPendingContextChanges(): Partial<CalendarToolBeltContext>;
|
|
28
29
|
getVcForTool(toolId: string): CalendarTool | undefined;
|
|
30
|
+
getControlsVc(): EventControlsCardViewController;
|
|
29
31
|
destroy(): Promise<void>;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -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(Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')), { onCancelEvent: this.sm.getContext().cancelEvent }));
|
|
29
26
|
this.toolBeltVc.clearTools();
|
|
30
27
|
this.toolBeltVc.setStickyTool({
|
|
31
28
|
card: this.controlsVc.render(),
|
|
@@ -79,6 +76,7 @@ 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) {
|
|
@@ -86,6 +84,7 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
86
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) {
|
|
@@ -153,6 +152,9 @@ export default class AbstractCalendarEventToolBeltState {
|
|
|
153
152
|
var _a;
|
|
154
153
|
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
155
154
|
}
|
|
155
|
+
getControlsVc() {
|
|
156
|
+
return this.controlsVc;
|
|
157
|
+
}
|
|
156
158
|
destroy() {
|
|
157
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
160
|
yield this.sm.off('did-update-context', this.handleDidUpdateContext);
|
|
@@ -18,6 +18,7 @@ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
|
18
18
|
export declare type CalendarToolBeltContext = SkillViewControllerLoadOptions & {
|
|
19
19
|
event: CalendarEvent;
|
|
20
20
|
calendarVc: CalendarViewController;
|
|
21
|
+
cancelEvent: CancelEventHandler;
|
|
21
22
|
};
|
|
22
23
|
export declare type CalendarToolBeltStateMachine = ToolBeltStateMachine<CalendarToolBeltContext>;
|
|
23
24
|
export interface RemoteCalendarTool extends CalendarTool {
|
|
@@ -34,10 +35,13 @@ export interface UpdateCalendarContextOptions {
|
|
|
34
35
|
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
35
36
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
37
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
38
|
+
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
39
|
+
export declare type CancelEventHandler = (eventId: string) => boolean | Promise<boolean | void> | void;
|
|
37
40
|
export interface CalendarToolOptions {
|
|
38
41
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
39
42
|
getContext: GetCalendarToolBeltContextHandler;
|
|
40
43
|
getPersonFromEvent: GetPersonFromEventHandler;
|
|
44
|
+
getHasPendingContextChanges: GetHasPendingContextChangesHandler;
|
|
41
45
|
}
|
|
42
46
|
export interface EventWithToolBeltState {
|
|
43
47
|
getToolBeltState(): ToolBeltState;
|
|
@@ -30,6 +30,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
30
30
|
private eventSwappedHandler?;
|
|
31
31
|
private dropEventHandler?;
|
|
32
32
|
private isSwapping;
|
|
33
|
+
private lastSwappedId?;
|
|
33
34
|
constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
|
|
34
35
|
private handleDropEvent;
|
|
35
36
|
getCalendarVc(): this;
|
|
@@ -186,10 +186,15 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
186
186
|
if (!saved) {
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
if (id !== saved.id) {
|
|
190
|
+
if (this.lastSwappedId === id) {
|
|
191
|
+
this.updateEvent(saved.id, saved);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
this.lastSwappedId = id;
|
|
195
|
+
yield this.swapEvent(event, saved);
|
|
196
|
+
yield ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
|
|
197
|
+
}
|
|
193
198
|
}
|
|
194
199
|
else {
|
|
195
200
|
_super.updateEvent.call(this, saved.id, { isBusy, error: undefined });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions, CancelEventHandler } 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
|
+
onCancelEvent: CancelEventHandler;
|
|
6
7
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
8
|
}
|
|
8
9
|
export default class EventControlsCardViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -10,10 +11,15 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
10
11
|
private cardVc;
|
|
11
12
|
private saveHandler;
|
|
12
13
|
private cancelHandler;
|
|
14
|
+
private getHasPendingContextChangesHandler;
|
|
15
|
+
private getContext;
|
|
16
|
+
private cancelEventHandler;
|
|
13
17
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
18
|
+
private CardVc;
|
|
14
19
|
private handleClickCancel;
|
|
15
20
|
private handleClickSave;
|
|
16
21
|
handleUpdateContext(): void;
|
|
22
|
+
private optionallyDropInCancelButton;
|
|
17
23
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
18
24
|
}
|
|
19
25
|
export {};
|
|
@@ -9,13 +9,27 @@ 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, onCancelEvent, } = assertOptions(options, [
|
|
17
|
+
'onCancel',
|
|
18
|
+
'onSave',
|
|
19
|
+
'onCancelEvent',
|
|
20
|
+
'getHasPendingContextChanges',
|
|
21
|
+
'getContext',
|
|
22
|
+
]);
|
|
16
23
|
this.saveHandler = onSave;
|
|
17
24
|
this.cancelHandler = onCancel;
|
|
18
|
-
this.
|
|
25
|
+
this.cancelEventHandler = onCancelEvent;
|
|
26
|
+
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
27
|
+
this.getContext = getContext;
|
|
28
|
+
this.cardVc = this.CardVc();
|
|
29
|
+
this.optionallyDropInCancelButton();
|
|
30
|
+
}
|
|
31
|
+
CardVc() {
|
|
32
|
+
return this.Controller('card', {
|
|
19
33
|
footer: {
|
|
20
34
|
isEnabled: false,
|
|
21
35
|
isBusy: false,
|
|
@@ -50,7 +64,33 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
50
64
|
});
|
|
51
65
|
}
|
|
52
66
|
handleUpdateContext() {
|
|
53
|
-
this.
|
|
67
|
+
if (this.getHasPendingContextChangesHandler()) {
|
|
68
|
+
this.cardVc.enableFooter();
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.cardVc.disableFooter();
|
|
72
|
+
}
|
|
73
|
+
this.optionallyDropInCancelButton();
|
|
74
|
+
}
|
|
75
|
+
optionallyDropInCancelButton() {
|
|
76
|
+
var _a;
|
|
77
|
+
const { event } = this.getContext();
|
|
78
|
+
if ((event === null || event === void 0 ? void 0 : event.id) && !draftEventGenerator.isDraftId(event.id)) {
|
|
79
|
+
this.cardVc.setBody({
|
|
80
|
+
sections: [
|
|
81
|
+
{
|
|
82
|
+
buttons: [
|
|
83
|
+
{
|
|
84
|
+
id: 'cancel-event',
|
|
85
|
+
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
86
|
+
type: 'destructive',
|
|
87
|
+
onClick: () => this.cancelEventHandler(this.getContext().event.id),
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
}
|
|
54
94
|
}
|
|
55
95
|
render() {
|
|
56
96
|
return this.cardVc.render();
|
|
@@ -15,5 +15,6 @@ export { default as CalendarToolRegistrar } from './toolBelt/CalendarToolRegistr
|
|
|
15
15
|
export * from './toolBelt/CalendarToolRegistrar';
|
|
16
16
|
export { default as AbstractCalendarEventToolBeltState } from './toolBelt/states/AbstractCalendarEventToolBeltState';
|
|
17
17
|
export * from './toolBelt/states/AbstractCalendarEventToolBeltState';
|
|
18
|
+
export { default as draftEventGenerator } from './utilities/draftGenerator';
|
|
18
19
|
/** TYPES */
|
|
19
20
|
export * from './types/calendar.types';
|
|
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.AbstractCalendarEventToolBeltState = exports.CalendarToolRegistrar = exports.EventRepeatingToolViewController = exports.EventDateTimeToolViewController = exports.EventControlsCardViewController = exports.CalendarViewController = exports.RepeatingControlsListViewController = exports.RepeatingCardViewController = void 0;
|
|
16
|
+
exports.draftEventGenerator = exports.AbstractCalendarEventToolBeltState = exports.CalendarToolRegistrar = exports.EventRepeatingToolViewController = exports.EventDateTimeToolViewController = exports.EventControlsCardViewController = exports.CalendarViewController = exports.RepeatingControlsListViewController = exports.RepeatingCardViewController = void 0;
|
|
17
17
|
/** COMPONENTS */
|
|
18
18
|
var EventRepeatingTool_vc_1 = require("./viewControllers/EventRepeatingTool.vc");
|
|
19
19
|
Object.defineProperty(exports, "RepeatingCardViewController", { enumerable: true, get: function () { return __importDefault(EventRepeatingTool_vc_1).default; } });
|
|
@@ -39,5 +39,7 @@ __exportStar(require("./toolBelt/CalendarToolRegistrar"), exports);
|
|
|
39
39
|
var AbstractCalendarEventToolBeltState_1 = require("./toolBelt/states/AbstractCalendarEventToolBeltState");
|
|
40
40
|
Object.defineProperty(exports, "AbstractCalendarEventToolBeltState", { enumerable: true, get: function () { return __importDefault(AbstractCalendarEventToolBeltState_1).default; } });
|
|
41
41
|
__exportStar(require("./toolBelt/states/AbstractCalendarEventToolBeltState"), exports);
|
|
42
|
+
var draftGenerator_1 = require("./utilities/draftGenerator");
|
|
43
|
+
Object.defineProperty(exports, "draftEventGenerator", { enumerable: true, get: function () { return __importDefault(draftGenerator_1).default; } });
|
|
42
44
|
/** TYPES */
|
|
43
45
|
__exportStar(require("./types/calendar.types"), exports);
|
|
@@ -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
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SpruceSchemas, ToolBeltState, ViewControllerId } from '@sprucelabs/heartwood-view-controllers';
|
|
2
2
|
import { CalendarTool, CalendarToolBeltContext, CalendarToolBeltStateMachine, GetPersonFromEventHandler } from '../../types/calendar.types';
|
|
3
|
+
import EventControlsCardViewController from '../../viewControllers/EventControlsCard.vc';
|
|
3
4
|
declare type Tool = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.ToolBeltTool;
|
|
4
5
|
export declare type AddToolOptions = Omit<Tool, 'card'> & {
|
|
5
6
|
cardVcId: ViewControllerId;
|
|
@@ -18,7 +19,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
18
19
|
private handleDidUpdateContext;
|
|
19
20
|
private getContext;
|
|
20
21
|
clearPendingContextChanges(): Promise<void>;
|
|
21
|
-
addTool(options: AddToolOptions): Promise<
|
|
22
|
+
addTool(options: AddToolOptions): Promise<CalendarTool>;
|
|
22
23
|
private buildVcConstructorOptions;
|
|
23
24
|
private addVc;
|
|
24
25
|
protected getPersonFromEvent(): ReturnType<GetPersonFromEventHandler>;
|
|
@@ -26,6 +27,7 @@ export default abstract class AbstractCalendarEventToolBeltState implements Tool
|
|
|
26
27
|
removeTool(id: string): void;
|
|
27
28
|
getPendingContextChanges(): Partial<CalendarToolBeltContext>;
|
|
28
29
|
getVcForTool(toolId: string): CalendarTool | undefined;
|
|
30
|
+
getControlsVc(): EventControlsCardViewController;
|
|
29
31
|
destroy(): Promise<void>;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -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(Object.assign({ onCancel: this.clearPendingContextChanges.bind(this), onSave: this.handleClickSave.bind(this) }, this.buildVcConstructorOptions('controls')), { onCancelEvent: this.sm.getContext().cancelEvent }));
|
|
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
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) {
|
|
@@ -131,6 +130,9 @@ class AbstractCalendarEventToolBeltState {
|
|
|
131
130
|
var _a;
|
|
132
131
|
return (_a = this.vcs.find((v) => v.toolId === toolId)) === null || _a === void 0 ? void 0 : _a.vc;
|
|
133
132
|
}
|
|
133
|
+
getControlsVc() {
|
|
134
|
+
return this.controlsVc;
|
|
135
|
+
}
|
|
134
136
|
async destroy() {
|
|
135
137
|
await this.sm.off('did-update-context', this.handleDidUpdateContext);
|
|
136
138
|
}
|
|
@@ -18,6 +18,7 @@ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
|
18
18
|
export declare type CalendarToolBeltContext = SkillViewControllerLoadOptions & {
|
|
19
19
|
event: CalendarEvent;
|
|
20
20
|
calendarVc: CalendarViewController;
|
|
21
|
+
cancelEvent: CancelEventHandler;
|
|
21
22
|
};
|
|
22
23
|
export declare type CalendarToolBeltStateMachine = ToolBeltStateMachine<CalendarToolBeltContext>;
|
|
23
24
|
export interface RemoteCalendarTool extends CalendarTool {
|
|
@@ -34,10 +35,13 @@ export interface UpdateCalendarContextOptions {
|
|
|
34
35
|
export declare type UpdateCalendarToolBeltContextHandler = (context: Partial<CalendarToolBeltContext>, options?: UpdateCalendarContextOptions) => Promise<void>;
|
|
35
36
|
export declare type GetCalendarToolBeltContextHandler = () => CalendarToolBeltContext;
|
|
36
37
|
export declare type GetPersonFromEventHandler = () => Promise<Person | null>;
|
|
38
|
+
export declare type GetHasPendingContextChangesHandler = () => boolean;
|
|
39
|
+
export declare type CancelEventHandler = (eventId: string) => boolean | Promise<boolean | void> | void;
|
|
37
40
|
export interface CalendarToolOptions {
|
|
38
41
|
updateContext: UpdateCalendarToolBeltContextHandler;
|
|
39
42
|
getContext: GetCalendarToolBeltContextHandler;
|
|
40
43
|
getPersonFromEvent: GetPersonFromEventHandler;
|
|
44
|
+
getHasPendingContextChanges: GetHasPendingContextChangesHandler;
|
|
41
45
|
}
|
|
42
46
|
export interface EventWithToolBeltState {
|
|
43
47
|
getToolBeltState(): ToolBeltState;
|
|
@@ -30,6 +30,7 @@ export default class CalendarViewController extends CoreCalendarViewController {
|
|
|
30
30
|
private eventSwappedHandler?;
|
|
31
31
|
private dropEventHandler?;
|
|
32
32
|
private isSwapping;
|
|
33
|
+
private lastSwappedId?;
|
|
33
34
|
constructor(options: ViewControllerOptions & CalendarViewControllerOptions);
|
|
34
35
|
private handleDropEvent;
|
|
35
36
|
getCalendarVc(): this;
|
|
@@ -163,10 +163,15 @@ class CalendarViewController extends heartwood_view_controllers_1.CalendarViewCo
|
|
|
163
163
|
if (!saved) {
|
|
164
164
|
return;
|
|
165
165
|
}
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
166
|
+
if (id !== saved.id) {
|
|
167
|
+
if (this.lastSwappedId === id) {
|
|
168
|
+
this.updateEvent(saved.id, saved);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
this.lastSwappedId = id;
|
|
172
|
+
await this.swapEvent(event, saved);
|
|
173
|
+
await ((_b = this.eventSwappedHandler) === null || _b === void 0 ? void 0 : _b.call(this, saved));
|
|
174
|
+
}
|
|
170
175
|
}
|
|
171
176
|
else {
|
|
172
177
|
super.updateEvent(saved.id, { isBusy, error: undefined });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
-
import { CalendarTool } from '../types/calendar.types';
|
|
2
|
+
import { CalendarTool, CalendarToolOptions, CancelEventHandler } 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
|
+
onCancelEvent: CancelEventHandler;
|
|
6
7
|
onSave: () => Promise<void | boolean> | void | boolean;
|
|
7
8
|
}
|
|
8
9
|
export default class EventControlsCardViewController extends AbstractViewController<Card> implements CalendarTool {
|
|
@@ -10,10 +11,15 @@ export default class EventControlsCardViewController extends AbstractViewControl
|
|
|
10
11
|
private cardVc;
|
|
11
12
|
private saveHandler;
|
|
12
13
|
private cancelHandler;
|
|
14
|
+
private getHasPendingContextChangesHandler;
|
|
15
|
+
private getContext;
|
|
16
|
+
private cancelEventHandler;
|
|
13
17
|
constructor(options: ViewControllerOptions & EventControlsCardOptions);
|
|
18
|
+
private CardVc;
|
|
14
19
|
private handleClickCancel;
|
|
15
20
|
private handleClickSave;
|
|
16
21
|
handleUpdateContext(): void;
|
|
22
|
+
private optionallyDropInCancelButton;
|
|
17
23
|
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
18
24
|
}
|
|
19
25
|
export {};
|
|
@@ -1,14 +1,31 @@
|
|
|
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, onCancelEvent, } = (0, schema_1.assertOptions)(options, [
|
|
13
|
+
'onCancel',
|
|
14
|
+
'onSave',
|
|
15
|
+
'onCancelEvent',
|
|
16
|
+
'getHasPendingContextChanges',
|
|
17
|
+
'getContext',
|
|
18
|
+
]);
|
|
9
19
|
this.saveHandler = onSave;
|
|
10
20
|
this.cancelHandler = onCancel;
|
|
11
|
-
this.
|
|
21
|
+
this.cancelEventHandler = onCancelEvent;
|
|
22
|
+
this.getHasPendingContextChangesHandler = getHasPendingContextChanges;
|
|
23
|
+
this.getContext = getContext;
|
|
24
|
+
this.cardVc = this.CardVc();
|
|
25
|
+
this.optionallyDropInCancelButton();
|
|
26
|
+
}
|
|
27
|
+
CardVc() {
|
|
28
|
+
return this.Controller('card', {
|
|
12
29
|
footer: {
|
|
13
30
|
isEnabled: false,
|
|
14
31
|
isBusy: false,
|
|
@@ -39,7 +56,33 @@ class EventControlsCardViewController extends heartwood_view_controllers_1.Abstr
|
|
|
39
56
|
this.cardVc.disableFooter();
|
|
40
57
|
}
|
|
41
58
|
handleUpdateContext() {
|
|
42
|
-
this.
|
|
59
|
+
if (this.getHasPendingContextChangesHandler()) {
|
|
60
|
+
this.cardVc.enableFooter();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.cardVc.disableFooter();
|
|
64
|
+
}
|
|
65
|
+
this.optionallyDropInCancelButton();
|
|
66
|
+
}
|
|
67
|
+
optionallyDropInCancelButton() {
|
|
68
|
+
var _a;
|
|
69
|
+
const { event } = this.getContext();
|
|
70
|
+
if ((event === null || event === void 0 ? void 0 : event.id) && !draftGenerator_1.default.isDraftId(event.id)) {
|
|
71
|
+
this.cardVc.setBody({
|
|
72
|
+
sections: [
|
|
73
|
+
{
|
|
74
|
+
buttons: [
|
|
75
|
+
{
|
|
76
|
+
id: 'cancel-event',
|
|
77
|
+
label: `Cancel ${(_a = event.eventTypeSlug) !== null && _a !== void 0 ? _a : 'event'}`,
|
|
78
|
+
type: 'destructive',
|
|
79
|
+
onClick: () => this.cancelEventHandler(this.getContext().event.id),
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
}
|
|
43
86
|
}
|
|
44
87
|
render() {
|
|
45
88
|
return this.cardVc.render();
|