@sprucelabs/spruce-calendar-components 21.0.3 → 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.
Files changed (71) hide show
  1. package/build/.spruce/errors/errors.types.d.ts +122 -0
  2. package/build/.spruce/errors/errors.types.js +4 -0
  3. package/build/.spruce/errors/options.types.d.ts +28 -0
  4. package/build/.spruce/errors/options.types.js +2 -0
  5. package/build/constants.d.ts +5 -0
  6. package/build/constants.js +9 -0
  7. package/build/errors/SpruceError.d.ts +5 -0
  8. package/build/errors/SpruceError.js +45 -0
  9. package/build/esm/.spruce/errors/errors.types.d.ts +122 -0
  10. package/build/esm/.spruce/errors/errors.types.js +3 -0
  11. package/build/esm/.spruce/errors/options.types.d.ts +28 -0
  12. package/build/esm/.spruce/errors/options.types.js +1 -0
  13. package/build/esm/constants.d.ts +5 -0
  14. package/build/esm/constants.js +6 -0
  15. package/build/esm/errors/SpruceError.d.ts +5 -0
  16. package/build/esm/errors/SpruceError.js +39 -0
  17. package/build/esm/index-module.d.ts +30 -0
  18. package/build/esm/index-module.js +7 -0
  19. package/build/esm/skillViewControllers/Root.svc.d.ts +73 -0
  20. package/build/esm/skillViewControllers/Root.svc.js +404 -0
  21. package/build/esm/toolBelt/CalendarToolTestFactory.d.ts +5 -0
  22. package/build/esm/toolBelt/CalendarToolTestFactory.js +28 -0
  23. package/build/esm/toolBelt/states/PrerequisitesToolBeltState.d.ts +37 -0
  24. package/build/esm/toolBelt/states/PrerequisitesToolBeltState.js +190 -0
  25. package/build/esm/toolBelt/states/RootToolBeltState.d.ts +37 -0
  26. package/build/esm/toolBelt/states/RootToolBeltState.js +122 -0
  27. package/build/esm/toolBelt/states/makeEventTyped.d.ts +2 -0
  28. package/build/esm/toolBelt/states/makeEventTyped.js +8 -0
  29. package/build/esm/types/calendar.types.d.ts +2 -0
  30. package/build/esm/utilities/CalendarEventManager.d.ts +72 -0
  31. package/build/esm/utilities/CalendarEventManager.js +321 -0
  32. package/build/esm/utilities/CalendarPeopleManager.d.ts +56 -0
  33. package/build/esm/utilities/CalendarPeopleManager.js +182 -0
  34. package/build/esm/utilities/calendarShiftGenerator.d.ts +8 -0
  35. package/build/esm/utilities/calendarShiftGenerator.js +24 -0
  36. package/build/esm/viewControllers/CalendarSelectTool.vc.d.ts +28 -0
  37. package/build/esm/viewControllers/CalendarSelectTool.vc.js +103 -0
  38. package/build/esm/viewControllers/DateSelectCard.vc.d.ts +29 -0
  39. package/build/esm/viewControllers/DateSelectCard.vc.js +77 -0
  40. package/build/esm/viewControllers/PersonSelectTool.vc.d.ts +36 -0
  41. package/build/esm/viewControllers/PersonSelectTool.vc.js +156 -0
  42. package/build/esm/viewControllers/SelectUpdateRepeatingStrategyCard.vc.d.ts +18 -0
  43. package/build/esm/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +85 -0
  44. package/build/index-module.d.ts +30 -0
  45. package/build/index-module.js +32 -0
  46. package/build/skillViewControllers/Root.svc.d.ts +73 -0
  47. package/build/skillViewControllers/Root.svc.js +359 -0
  48. package/build/toolBelt/CalendarToolTestFactory.d.ts +5 -0
  49. package/build/toolBelt/CalendarToolTestFactory.js +34 -0
  50. package/build/toolBelt/states/PrerequisitesToolBeltState.d.ts +37 -0
  51. package/build/toolBelt/states/PrerequisitesToolBeltState.js +172 -0
  52. package/build/toolBelt/states/RootToolBeltState.d.ts +37 -0
  53. package/build/toolBelt/states/RootToolBeltState.js +113 -0
  54. package/build/toolBelt/states/makeEventTyped.d.ts +2 -0
  55. package/build/toolBelt/states/makeEventTyped.js +14 -0
  56. package/build/types/calendar.types.d.ts +2 -0
  57. package/build/utilities/CalendarEventManager.d.ts +72 -0
  58. package/build/utilities/CalendarEventManager.js +279 -0
  59. package/build/utilities/CalendarPeopleManager.d.ts +56 -0
  60. package/build/utilities/CalendarPeopleManager.js +163 -0
  61. package/build/utilities/calendarShiftGenerator.d.ts +8 -0
  62. package/build/utilities/calendarShiftGenerator.js +26 -0
  63. package/build/viewControllers/CalendarSelectTool.vc.d.ts +28 -0
  64. package/build/viewControllers/CalendarSelectTool.vc.js +93 -0
  65. package/build/viewControllers/DateSelectCard.vc.d.ts +29 -0
  66. package/build/viewControllers/DateSelectCard.vc.js +69 -0
  67. package/build/viewControllers/PersonSelectTool.vc.d.ts +36 -0
  68. package/build/viewControllers/PersonSelectTool.vc.js +140 -0
  69. package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.d.ts +18 -0
  70. package/build/viewControllers/SelectUpdateRepeatingStrategyCard.vc.js +88 -0
  71. package/package.json +99 -30
@@ -0,0 +1,182 @@
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 { AbstractEventEmitter } from '@sprucelabs/mercury-event-emitter';
11
+ import { buildEventContract } from '@sprucelabs/mercury-types';
12
+ import { assertOptions } from '@sprucelabs/schema';
13
+ import { EMPLOYED_BASE_ROLES } from '@sprucelabs/spruce-core-schemas';
14
+ import SpruceError from '../errors/SpruceError.js';
15
+ export default class CalendarPeopleManager extends AbstractEventEmitter {
16
+ constructor(options) {
17
+ super(peopleContract);
18
+ this.team = [];
19
+ const { connectToApi, preferences, getVisibleEvents } = assertOptions(options, ['connectToApi', 'preferences', 'calendarVc', 'getVisibleEvents']);
20
+ this.connectToApi = connectToApi;
21
+ this.prefs = preferences;
22
+ this.getVisibleEvents = getVisibleEvents;
23
+ }
24
+ load(options) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const { loggedInPerson, organizationId, locationId } = options !== null && options !== void 0 ? options : {};
27
+ this.client = yield this.connectToApi();
28
+ this.loggedInPerson = loggedInPerson !== null && loggedInPerson !== void 0 ? loggedInPerson : undefined;
29
+ this.organizationId = organizationId;
30
+ this.locationId = locationId;
31
+ yield this.loadTeam();
32
+ if (this.getVisiblePeople().length === 0 && this.loggedInPerson) {
33
+ yield this.setVisiblePeopleIds([this.loggedInPerson.id]);
34
+ }
35
+ });
36
+ }
37
+ loadTeam() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ const [{ people }] = yield this.client.emitAndFlattenResponses('list-people::v2020_12_25', {
40
+ target: {
41
+ locationId: this.locationId,
42
+ organizationId: this.organizationId,
43
+ },
44
+ payload: {
45
+ roleBases: EMPLOYED_BASE_ROLES.map((r) => r.slug),
46
+ },
47
+ });
48
+ this.team = people;
49
+ });
50
+ }
51
+ getVisiblePeople() {
52
+ return this.getVisiblePeopleIds()
53
+ .map((i) => {
54
+ try {
55
+ return this.teammateById(i);
56
+ // eslint-disable-next-line no-empty
57
+ }
58
+ catch (_a) { }
59
+ return null;
60
+ })
61
+ .filter((t) => !!t);
62
+ }
63
+ teammateById(id) {
64
+ var _a;
65
+ const teammate = (_a = this.team) === null || _a === void 0 ? void 0 : _a.find((t) => t.id === id);
66
+ if (!teammate) {
67
+ throw new SpruceError({
68
+ code: 'PERSON_NOT_FOUND',
69
+ personId: id,
70
+ });
71
+ }
72
+ return teammate;
73
+ }
74
+ getTeam() {
75
+ return this.team;
76
+ }
77
+ getLoggedInPerson() {
78
+ return this.loggedInPerson;
79
+ }
80
+ getVisiblePeopleIds() {
81
+ var _a;
82
+ if (this.getVisibilityMode() === 'working') {
83
+ return this.getWorkingPeopleIds();
84
+ }
85
+ return (_a = this.getSavedVisiblePeopleIds()) !== null && _a !== void 0 ? _a : [];
86
+ }
87
+ getSavedVisiblePeopleIds() {
88
+ return this.prefs.getVisiblePeopleIds();
89
+ }
90
+ getVisibilityMode() {
91
+ var _a;
92
+ return (_a = this.prefs.getVisiblePeopleMode()) !== null && _a !== void 0 ? _a : 'me';
93
+ }
94
+ setVisibilityMode(mode) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ if (this.getVisibilityMode() === mode) {
97
+ return;
98
+ }
99
+ yield this.prefs.setVisiblePeopleMode(mode);
100
+ if (mode === 'me' && this.loggedInPerson) {
101
+ yield this.setVisibilityToMe();
102
+ }
103
+ else if (mode === 'working') {
104
+ yield this.setVisibleToWorking();
105
+ }
106
+ });
107
+ }
108
+ setVisibilityToMe() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ if (this.loggedInPerson) {
111
+ yield this.setVisiblePeopleIds([this.loggedInPerson.id], {
112
+ shouldForceEmitDidChange: true,
113
+ });
114
+ }
115
+ });
116
+ }
117
+ setVisibleToWorking() {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const ids = this.getWorkingPeopleIds();
120
+ yield this.setVisiblePeopleIds(ids);
121
+ });
122
+ }
123
+ getWorkingPeopleIds() {
124
+ return this.getWorkingPeople().map((i) => i.id);
125
+ }
126
+ getWorkingPeople() {
127
+ const events = this.getVisibleEvents();
128
+ let ids = events.map((e) => e.target.personId);
129
+ ids = ids.filter((id, idx) => ids.indexOf(id) === idx);
130
+ return ids
131
+ .map((id) => {
132
+ try {
133
+ return this.teammateById(id);
134
+ // eslint-disable-next-line no-empty
135
+ }
136
+ catch (_a) { }
137
+ return false;
138
+ })
139
+ .filter((p) => !!p);
140
+ }
141
+ setVisiblePeopleIds(visible, options) {
142
+ var _a;
143
+ return __awaiter(this, void 0, void 0, function* () {
144
+ const { shouldForceEmitDidChange } = options !== null && options !== void 0 ? options : {};
145
+ const newVisibile = visible.filter((id, idx) => visible.indexOf(id) === idx);
146
+ const oldVisible = (_a = this.getSavedVisiblePeopleIds()) !== null && _a !== void 0 ? _a : [];
147
+ const newKey = newVisibile.join('');
148
+ const oldKey = oldVisible.join('');
149
+ const didChange = newKey !== oldKey;
150
+ if (didChange) {
151
+ yield this.prefs.setVisiblePeopleIds(newVisibile);
152
+ }
153
+ if (didChange || shouldForceEmitDidChange) {
154
+ yield this.emitDidUpdate();
155
+ }
156
+ });
157
+ }
158
+ setPersonVisibility(id, shouldBeVisible) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ const person = this.teammateById(id);
161
+ let selected = [...this.getVisiblePeopleIds()];
162
+ if (shouldBeVisible) {
163
+ selected.push(person.id);
164
+ }
165
+ else {
166
+ selected = selected.filter((i) => i !== id);
167
+ }
168
+ yield this.setVisibilityMode('custom');
169
+ yield this.setVisiblePeopleIds(selected);
170
+ });
171
+ }
172
+ emitDidUpdate() {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ yield this.emit('did-update');
175
+ });
176
+ }
177
+ }
178
+ const peopleContract = buildEventContract({
179
+ eventSignatures: {
180
+ 'did-update': {},
181
+ },
182
+ });
@@ -0,0 +1,8 @@
1
+ import { SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
2
+ export declare type CalendarShift = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarShift;
3
+ import { EventForShift } from '../types/calendar.types';
4
+ declare const calendarShiftGenerator: {
5
+ generateFromEvent(event: EventForShift): CalendarShift[];
6
+ generateFromEvents(events: EventForShift[]): CalendarShift[];
7
+ };
8
+ export default calendarShiftGenerator;
@@ -0,0 +1,24 @@
1
+ const calendarShiftGenerator = {
2
+ generateFromEvent(event) {
3
+ let time = event.startDateTimeMs;
4
+ return event.timeBlocks.map((timeBlock, idx) => {
5
+ const end = time + timeBlock.durationMinutes * 60 * 1000;
6
+ const shift = {
7
+ id: event.id + '-' + idx,
8
+ startDateTimeMs: time,
9
+ endDateTimeMs: end,
10
+ personId: event.target.personId,
11
+ };
12
+ time = end;
13
+ return shift;
14
+ });
15
+ },
16
+ generateFromEvents(events) {
17
+ const shifts = events.reduce((shifts, event) => {
18
+ shifts.push(...this.generateFromEvent(event));
19
+ return shifts;
20
+ }, []);
21
+ return shifts;
22
+ },
23
+ };
24
+ export default calendarShiftGenerator;
@@ -0,0 +1,28 @@
1
+ import { AbstractViewController, ActiveRecordCardViewController, Scope, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ import { CalendarEventManager } from '../utilities/CalendarEventManager';
3
+ export default class CalendarSelectCardViewController extends AbstractViewController<Card> {
4
+ static id: string;
5
+ private isLoaded;
6
+ private activeVc;
7
+ private events;
8
+ private selectedCalendarIds;
9
+ private changePromise?;
10
+ constructor(options: ViewControllerOptions & CalendarSelectCardOptions);
11
+ private CalendarListVc;
12
+ private renderCalendarRow;
13
+ waitForChanges(): Promise<void>;
14
+ getActiveRecordCardVc(): ActiveRecordCardViewController;
15
+ getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
16
+ getIsLoaded(): boolean;
17
+ getSelectedCalendarIds(): string[];
18
+ load(options: {
19
+ scope: Scope;
20
+ }): Promise<void>;
21
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
22
+ }
23
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
24
+ export declare type CalendarVisibilityToggleHandler = (calendarId: string, isVisible: boolean) => any;
25
+ export interface CalendarSelectCardOptions {
26
+ events: CalendarEventManager;
27
+ }
28
+ export {};
@@ -0,0 +1,103 @@
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 { AbstractViewController, buildActiveRecordCard, } from '@sprucelabs/heartwood-view-controllers';
11
+ import { assertOptions } from '@sprucelabs/schema';
12
+ export default class CalendarSelectCardViewController extends AbstractViewController {
13
+ constructor(options) {
14
+ super(options);
15
+ this.isLoaded = false;
16
+ this.selectedCalendarIds = [];
17
+ const { events } = assertOptions(options, ['events']);
18
+ this.events = events;
19
+ this.selectedCalendarIds = this.events.getVisibleCalendarIds();
20
+ this.activeVc = this.CalendarListVc();
21
+ }
22
+ CalendarListVc() {
23
+ return this.Controller('activeRecordCard', buildActiveRecordCard({
24
+ shouldRenderRowDividers: true,
25
+ columnWidths: ['fill'],
26
+ header: {
27
+ title: 'Calendars',
28
+ },
29
+ noResultsRow: {
30
+ cells: [
31
+ {
32
+ text: { content: "You don't have any calendars yet!" },
33
+ },
34
+ ],
35
+ },
36
+ eventName: 'calendar.list-calendars::v2021_05_19',
37
+ rowTransformer: this.renderCalendarRow.bind(this),
38
+ responseKey: 'calendars',
39
+ }));
40
+ }
41
+ renderCalendarRow(calendar) {
42
+ return {
43
+ id: calendar.id,
44
+ cells: [
45
+ {
46
+ text: { content: calendar.title },
47
+ },
48
+ {
49
+ toggleInput: {
50
+ name: 'isVisible',
51
+ value: this.selectedCalendarIds.indexOf(calendar.id) > -1,
52
+ onChange: (isVisible) => __awaiter(this, void 0, void 0, function* () {
53
+ this.changePromise = this.events.setCalendarVisibility(calendar.id, isVisible);
54
+ return this.changePromise;
55
+ }),
56
+ },
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ waitForChanges() {
62
+ return __awaiter(this, void 0, void 0, function* () {
63
+ yield this.changePromise;
64
+ });
65
+ }
66
+ getActiveRecordCardVc() {
67
+ return this.activeVc;
68
+ }
69
+ getListVc() {
70
+ return this.activeVc.getListVc();
71
+ }
72
+ getIsLoaded() {
73
+ return this.isLoaded;
74
+ }
75
+ getSelectedCalendarIds() {
76
+ const records = this.activeVc.getRecords();
77
+ const ids = [];
78
+ for (const calendar of records) {
79
+ if (this.getListVc().getRowVc(calendar.id).getValue('isVisible')) {
80
+ ids.push(calendar.id);
81
+ }
82
+ }
83
+ return ids;
84
+ }
85
+ load(options) {
86
+ return __awaiter(this, void 0, void 0, function* () {
87
+ assertOptions(options, ['scope']);
88
+ const { scope } = options;
89
+ const org = yield scope.getCurrentOrganization();
90
+ if (org) {
91
+ this.activeVc.setTarget({
92
+ organizationId: org === null || org === void 0 ? void 0 : org.id,
93
+ });
94
+ }
95
+ yield this.activeVc.load();
96
+ this.isLoaded = true;
97
+ });
98
+ }
99
+ render() {
100
+ return this.activeVc.render();
101
+ }
102
+ }
103
+ CalendarSelectCardViewController.id = 'calendar-select-tool';
@@ -0,0 +1,29 @@
1
+ import { AbstractViewController, CalendarViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
3
+ declare type DateSelectHandler = (dateTimeMs: number) => void | Promise<void>;
4
+ export interface DateSelectOptions {
5
+ onSelectDate: DateSelectHandler;
6
+ startDate: number;
7
+ selectedDate?: {
8
+ year: number;
9
+ month: number;
10
+ day: number;
11
+ };
12
+ }
13
+ export default class DateSelectCardViewController extends AbstractViewController<Card> {
14
+ static id: string;
15
+ private cardVc;
16
+ private calendarVc;
17
+ private dateSelectHandler;
18
+ constructor(options: ViewControllerOptions & DateSelectOptions);
19
+ getStartDate(): number | null | undefined;
20
+ setStartDate(startDate: number): void;
21
+ private CalendarVc;
22
+ private handleDateSelect;
23
+ private CardVc;
24
+ setSelectedDate(year: number, month: number, day: number): void;
25
+ getSelectedDate(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.CalendarSelectedDate;
26
+ getCalendarVc(): CalendarViewController;
27
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
28
+ }
29
+ export {};
@@ -0,0 +1,77 @@
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 { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
12
+ import { assertOptions } from '@sprucelabs/schema';
13
+ export default class DateSelectCardViewController extends AbstractViewController {
14
+ constructor(options) {
15
+ super(options);
16
+ const { onSelectDate, startDate, selectedDate } = assertOptions(options, [
17
+ 'onSelectDate',
18
+ 'startDate',
19
+ ]);
20
+ this.dateSelectHandler = onSelectDate;
21
+ this.calendarVc = this.CalendarVc({
22
+ startDate,
23
+ selectedDates: selectedDate ? [selectedDate] : [],
24
+ });
25
+ this.cardVc = this.CardVc();
26
+ }
27
+ getStartDate() {
28
+ return this.calendarVc.getStartDate();
29
+ }
30
+ setStartDate(startDate) {
31
+ this.calendarVc.setStartDate(startDate);
32
+ }
33
+ CalendarVc(options) {
34
+ return this.Controller('calendar', Object.assign({ view: 'month', onClick: ({ dateTimeMs }) => this.handleDateSelect(dateTimeMs), selectedDates: [] }, options));
35
+ }
36
+ handleDateSelect(dateTimeMs) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ const { year, month, day } = dateUtil.splitDate(dateTimeMs);
39
+ yield this.calendarVc.renderOnce(() => {
40
+ this.calendarVc.setStartDate(dateTimeMs);
41
+ this.calendarVc.clearSelectedDates();
42
+ this.calendarVc.selectDate(year, month, day);
43
+ });
44
+ yield this.dateSelectHandler(dateTimeMs !== null && dateTimeMs !== void 0 ? dateTimeMs : 0);
45
+ });
46
+ }
47
+ CardVc() {
48
+ return this.Controller('card', {
49
+ body: {
50
+ sections: [
51
+ {
52
+ calendar: this.calendarVc.render(),
53
+ },
54
+ ],
55
+ },
56
+ });
57
+ }
58
+ setSelectedDate(year, month, day) {
59
+ this.calendarVc.setSelectedDates([
60
+ {
61
+ year,
62
+ month,
63
+ day,
64
+ },
65
+ ]);
66
+ }
67
+ getSelectedDate() {
68
+ return this.calendarVc.getSelectedDates()[0];
69
+ }
70
+ getCalendarVc() {
71
+ return this.calendarVc;
72
+ }
73
+ render() {
74
+ return this.cardVc.render();
75
+ }
76
+ }
77
+ DateSelectCardViewController.id = 'date-select-card';
@@ -0,0 +1,36 @@
1
+ import { AbstractViewController, SpruceSchemas, ViewControllerOptions, ButtonBarViewController, Card, ListViewController } from '@sprucelabs/heartwood-view-controllers';
2
+ import CalendarPeopleManager from '../utilities/CalendarPeopleManager';
3
+ export default class PersonSelectToolViewController extends AbstractViewController<Card> {
4
+ static id: string;
5
+ private shouldUpdateVisibilityOnToggleChange;
6
+ private updatePromise?;
7
+ private get visiblePeopleIds();
8
+ private isLoaded;
9
+ private get loggedInPersonId();
10
+ private cardVc;
11
+ private listVc;
12
+ private modeButtonBarVc;
13
+ private get mode();
14
+ private people;
15
+ constructor(options: ViewControllerOptions & PersonSelectCardOptions);
16
+ private CardVc;
17
+ private ModeButtonBarVc;
18
+ waitForSave(): Promise<void | undefined>;
19
+ private ListVc;
20
+ private renderRow;
21
+ private handleChangeMode;
22
+ getModeButtonBar(): ButtonBarViewController;
23
+ load(): Promise<void>;
24
+ private handlePeopleUpdated;
25
+ getListVc(): ListViewController;
26
+ getMode(): PersonMode;
27
+ setMode(mode: PersonMode): Promise<void>;
28
+ getIsLoaded(): boolean;
29
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
30
+ }
31
+ export declare type PersonVisibilityToggleHandler = (person: SpruceSchemas.Spruce.v2020_07_22.Person, isVisible: boolean) => void;
32
+ export declare type PersonVisibilytModeToggleHandler = (mode: PersonMode) => Promise<void> | void;
33
+ export declare type PersonMode = 'me' | 'custom' | 'working';
34
+ export interface PersonSelectCardOptions {
35
+ people: CalendarPeopleManager;
36
+ }
@@ -0,0 +1,156 @@
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 { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
11
+ import { assertOptions } from '@sprucelabs/schema';
12
+ export default class PersonSelectToolViewController extends AbstractViewController {
13
+ constructor(options) {
14
+ super(options);
15
+ this.shouldUpdateVisibilityOnToggleChange = true;
16
+ this.isLoaded = false;
17
+ const { people } = assertOptions(options, ['people']);
18
+ this.people = people;
19
+ this.listVc = this.ListVc();
20
+ this.modeButtonBarVc = this.ModeButtonBarVc();
21
+ this.cardVc = this.CardVc();
22
+ }
23
+ get visiblePeopleIds() {
24
+ return this.people.getVisiblePeople().map((p) => p.id);
25
+ }
26
+ get loggedInPersonId() {
27
+ var _a;
28
+ return (_a = this.people.getLoggedInPerson()) === null || _a === void 0 ? void 0 : _a.id;
29
+ }
30
+ get mode() {
31
+ return this.people.getVisibilityMode();
32
+ }
33
+ CardVc() {
34
+ return this.Controller('card', {
35
+ header: {
36
+ title: 'People',
37
+ },
38
+ body: {
39
+ sections: [
40
+ {
41
+ buttonBar: this.modeButtonBarVc.render(),
42
+ },
43
+ {
44
+ list: this.listVc.render(),
45
+ shouldBePadded: false,
46
+ },
47
+ ],
48
+ },
49
+ });
50
+ }
51
+ ModeButtonBarVc() {
52
+ return this.Controller('buttonBar', {
53
+ selected: [this.mode],
54
+ onSelectionChange: this.handleChangeMode.bind(this),
55
+ buttons: [
56
+ {
57
+ id: 'custom',
58
+ label: 'Custom',
59
+ lineIcon: 'users',
60
+ },
61
+ {
62
+ id: 'working',
63
+ label: 'Working',
64
+ lineIcon: 'clipboard',
65
+ },
66
+ {
67
+ id: 'me',
68
+ label: 'Me',
69
+ lineIcon: 'user',
70
+ },
71
+ ],
72
+ });
73
+ }
74
+ waitForSave() {
75
+ return __awaiter(this, void 0, void 0, function* () {
76
+ return this.updatePromise;
77
+ });
78
+ }
79
+ ListVc() {
80
+ return this.Controller('list', {
81
+ columnWidths: ['fill'],
82
+ rows: this.people.getTeam().map((p) => this.renderRow(p)),
83
+ });
84
+ }
85
+ renderRow(person) {
86
+ return {
87
+ id: person.id,
88
+ cells: [
89
+ {
90
+ text: {
91
+ content: person.id === this.loggedInPersonId ? 'You' : person.casualName,
92
+ },
93
+ },
94
+ {
95
+ toggleInput: {
96
+ name: 'isVisible',
97
+ value: !!this.visiblePeopleIds.find((id) => id === person.id),
98
+ onChange: (value) => __awaiter(this, void 0, void 0, function* () {
99
+ if (this.shouldUpdateVisibilityOnToggleChange) {
100
+ this.updatePromise = this.people.setPersonVisibility(person.id, value !== null && value !== void 0 ? value : false);
101
+ }
102
+ }),
103
+ },
104
+ },
105
+ ],
106
+ };
107
+ }
108
+ handleChangeMode() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ yield this.people.setVisibilityMode(this.getMode());
111
+ });
112
+ }
113
+ getModeButtonBar() {
114
+ return this.modeButtonBarVc;
115
+ }
116
+ load() {
117
+ return __awaiter(this, void 0, void 0, function* () {
118
+ this.isLoaded = true;
119
+ yield this.people.on('did-update', this.handlePeopleUpdated.bind(this));
120
+ });
121
+ }
122
+ handlePeopleUpdated() {
123
+ return __awaiter(this, void 0, void 0, function* () {
124
+ if (this.getMode() !== this.people.getVisibilityMode()) {
125
+ yield this.setMode(this.people.getVisibilityMode());
126
+ }
127
+ const rows = this.listVc.getRowVcs();
128
+ const visiblePeople = this.people.getVisiblePeople().map((p) => p.id);
129
+ this.shouldUpdateVisibilityOnToggleChange = false;
130
+ yield Promise.all(rows.map((row) => __awaiter(this, void 0, void 0, function* () {
131
+ const shouldBeSelected = visiblePeople.indexOf(row.getId()) > -1;
132
+ yield row.setValue('isVisible', shouldBeSelected);
133
+ })));
134
+ this.shouldUpdateVisibilityOnToggleChange = true;
135
+ });
136
+ }
137
+ getListVc() {
138
+ return this.listVc;
139
+ }
140
+ getMode() {
141
+ const [mode] = this.modeButtonBarVc.getSelectedButtons();
142
+ return mode;
143
+ }
144
+ setMode(mode) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ yield this.modeButtonBarVc.selectButtons([mode]);
147
+ });
148
+ }
149
+ getIsLoaded() {
150
+ return this.isLoaded;
151
+ }
152
+ render() {
153
+ return this.cardVc.render();
154
+ }
155
+ }
156
+ PersonSelectToolViewController.id = 'person-select-tool';
@@ -0,0 +1,18 @@
1
+ import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
2
+ import { CalendarEvent, UpdateRepeatingStrategyWithCancel } from '../types/calendar.types';
3
+ export default class SelectUpdateRepeatingStrategyCardViewController extends AbstractViewController<Card> {
4
+ static id: string;
5
+ private cardVc;
6
+ private event;
7
+ private onSelectStrategy;
8
+ constructor(options: ViewControllerOptions & SelectUpdateRepeatingStrategyOptions);
9
+ private CardVc;
10
+ getEvent(): CalendarEvent;
11
+ render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
12
+ }
13
+ declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
14
+ export interface SelectUpdateRepeatingStrategyOptions {
15
+ event: CalendarEvent;
16
+ onSelectStrategy: (strategy: UpdateRepeatingStrategyWithCancel) => Promise<void> | void;
17
+ }
18
+ export {};