@sprucelabs/spruce-appointment-utils 5.1.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/README.md +5 -0
- package/build/esm/index-module.d.ts +7 -0
- package/build/esm/index-module.js +7 -0
- package/build/esm/types-module.d.ts +21 -0
- package/build/esm/types-module.js +1 -0
- package/build/esm/viewControllers/AbstractCapabilityCardViewController.d.ts +32 -0
- package/build/esm/viewControllers/AbstractCapabilityCardViewController.js +143 -0
- package/build/esm/viewControllers/DurationCard.vc.d.ts +33 -0
- package/build/esm/viewControllers/DurationCard.vc.js +75 -0
- package/build/esm/viewControllers/DurationList.vc.d.ts +37 -0
- package/build/esm/viewControllers/DurationList.vc.js +188 -0
- package/build/esm/viewControllers/EditOverrideDetailsCard.vc.d.ts +44 -0
- package/build/esm/viewControllers/EditOverrideDetailsCard.vc.js +98 -0
- package/build/esm/viewControllers/EditTimeBlockTitleCard.vc.d.ts +33 -0
- package/build/esm/viewControllers/EditTimeBlockTitleCard.vc.js +69 -0
- package/build/esm/viewControllers/RolesCard.vc.d.ts +22 -0
- package/build/esm/viewControllers/RolesCard.vc.js +75 -0
- package/build/index-module.d.ts +7 -0
- package/build/index-module.js +29 -0
- package/build/types-module.d.ts +21 -0
- package/build/types-module.js +2 -0
- package/build/viewControllers/AbstractCapabilityCardViewController.d.ts +32 -0
- package/build/viewControllers/AbstractCapabilityCardViewController.js +131 -0
- package/build/viewControllers/DurationCard.vc.d.ts +33 -0
- package/build/viewControllers/DurationCard.vc.js +69 -0
- package/build/viewControllers/DurationList.vc.d.ts +37 -0
- package/build/viewControllers/DurationList.vc.js +178 -0
- package/build/viewControllers/EditOverrideDetailsCard.vc.d.ts +44 -0
- package/build/viewControllers/EditOverrideDetailsCard.vc.js +92 -0
- package/build/viewControllers/EditTimeBlockTitleCard.vc.d.ts +33 -0
- package/build/viewControllers/EditTimeBlockTitleCard.vc.js +72 -0
- package/build/viewControllers/RolesCard.vc.d.ts +22 -0
- package/build/viewControllers/RolesCard.vc.js +66 -0
- package/package.json +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as AbstractCapabilityCardViewController } from './viewControllers/AbstractCapabilityCardViewController';
|
|
2
|
+
export { default as DurationCardViewController } from './viewControllers/DurationCard.vc';
|
|
3
|
+
export { default as DurationListViewController } from './viewControllers/DurationList.vc';
|
|
4
|
+
export { default as EditOverrideDetailsCardViewController } from './viewControllers/EditOverrideDetailsCard.vc';
|
|
5
|
+
export { default as EditTimeBlockTitleCardViewController } from './viewControllers/EditTimeBlockTitleCard.vc';
|
|
6
|
+
export { default as RolesCardViewController } from './viewControllers/RolesCard.vc';
|
|
7
|
+
export * from './types-module';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as AbstractCapabilityCardViewController } from './viewControllers/AbstractCapabilityCardViewController.js';
|
|
2
|
+
export { default as DurationCardViewController } from './viewControllers/DurationCard.vc.js';
|
|
3
|
+
export { default as DurationListViewController } from './viewControllers/DurationList.vc.js';
|
|
4
|
+
export { default as EditOverrideDetailsCardViewController } from './viewControllers/EditOverrideDetailsCard.vc.js';
|
|
5
|
+
export { default as EditTimeBlockTitleCardViewController } from './viewControllers/EditTimeBlockTitleCard.vc.js';
|
|
6
|
+
export { default as RolesCardViewController } from './viewControllers/RolesCard.vc.js';
|
|
7
|
+
export * from './types-module.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import DurationCardViewController, { DurationCardViewControllerOptions } from './viewControllers/DurationCard.vc';
|
|
2
|
+
import DurationListViewController, { DurationListViewControllerOptions } from './viewControllers/DurationList.vc';
|
|
3
|
+
import EditOverrideDetailsCardViewController, { EditOverrideDetailsCardViewControllerOptions } from './viewControllers/EditOverrideDetailsCard.vc';
|
|
4
|
+
import EditTimeBlockTitleCardViewController, { EditTimeBlockTitleCardViewControllerOptions } from './viewControllers/EditTimeBlockTitleCard.vc';
|
|
5
|
+
import RolesCardViewController, { RolesCardViewControllerOptions } from './viewControllers/RolesCard.vc';
|
|
6
|
+
declare module '@sprucelabs/heartwood-view-controllers/build/types/heartwood.types' {
|
|
7
|
+
interface ViewControllerMap {
|
|
8
|
+
durationCard: DurationCardViewController;
|
|
9
|
+
durationList: DurationListViewController;
|
|
10
|
+
editOverrideDetailsCard: EditOverrideDetailsCardViewController;
|
|
11
|
+
editTimeBlockTitleCard: EditTimeBlockTitleCardViewController;
|
|
12
|
+
rolesCard: RolesCardViewController;
|
|
13
|
+
}
|
|
14
|
+
interface ViewControllerOptionsMap {
|
|
15
|
+
durationCard: DurationCardViewControllerOptions;
|
|
16
|
+
durationList: DurationListViewControllerOptions;
|
|
17
|
+
editOverrideDetailsCard: EditOverrideDetailsCardViewControllerOptions;
|
|
18
|
+
editTimeBlockTitleCard: EditTimeBlockTitleCardViewControllerOptions;
|
|
19
|
+
rolesCard: RolesCardViewControllerOptions;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { AbstractViewController, ActiveRecordCardViewController, SpruceSchemas } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import EditOverrideDetailsCardViewController from './EditOverrideDetailsCard.vc';
|
|
3
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
4
|
+
declare type ToggleHandler = (serviceId: string, isSelected: boolean) => void;
|
|
5
|
+
declare type Service = SpruceSchemas.Appointments.v2021_06_23.ListService;
|
|
6
|
+
export default abstract class AbstractCapabilityCardViewController extends AbstractViewController<Card> {
|
|
7
|
+
protected activeRecordCardVc: ActiveRecordCardViewController;
|
|
8
|
+
protected onUpdateHasCapability?: ToggleHandler;
|
|
9
|
+
protected onEdit?: (row: any) => void;
|
|
10
|
+
protected capabilities: any[];
|
|
11
|
+
protected locationId?: string;
|
|
12
|
+
protected organizationId?: string;
|
|
13
|
+
protected editVc?: EditOverrideDetailsCardViewController;
|
|
14
|
+
protected abstract insertOrUpdateCapability(serviceId: string, values: any, capability: SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined): Promise<SpruceSchemas.Appointments.v2021_06_23.ListRoleCapability | undefined>;
|
|
15
|
+
protected abstract loadCapabilities(): Promise<any>;
|
|
16
|
+
ActiveRecordCard(row: any): ActiveRecordCardViewController;
|
|
17
|
+
protected buildRow(service: Service): any;
|
|
18
|
+
private handleEdit;
|
|
19
|
+
private upsertCapabilities;
|
|
20
|
+
private handleToggleChange;
|
|
21
|
+
protected loadVc(organizationId: string): Promise<void>;
|
|
22
|
+
private calculateDuration;
|
|
23
|
+
getCardVc(): import("@sprucelabs/heartwood-view-controllers").CardViewController;
|
|
24
|
+
getActiveRecordVc(): ActiveRecordCardViewController;
|
|
25
|
+
getListVc(): import("@sprucelabs/heartwood-view-controllers").ListViewController;
|
|
26
|
+
getEditVc(): EditOverrideDetailsCardViewController | undefined;
|
|
27
|
+
getOrganizationId(): string | undefined;
|
|
28
|
+
getCapabilities(): any[];
|
|
29
|
+
getLocationId(): string;
|
|
30
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,143 @@
|
|
|
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 { durationUtil } from '@sprucelabs/calendar-utils';
|
|
11
|
+
import { AbstractViewController, buildActiveRecordCard, } from '@sprucelabs/heartwood-view-controllers';
|
|
12
|
+
export default class AbstractCapabilityCardViewController extends AbstractViewController {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.capabilities = [];
|
|
16
|
+
}
|
|
17
|
+
ActiveRecordCard(row) {
|
|
18
|
+
return this.Controller('activeRecordCard', buildActiveRecordCard({
|
|
19
|
+
id: row.id,
|
|
20
|
+
columnWidths: ['fill'],
|
|
21
|
+
shouldRenderRowDividers: true,
|
|
22
|
+
header: {
|
|
23
|
+
title: row.name,
|
|
24
|
+
},
|
|
25
|
+
eventName: 'appointments.list-services::v2021_06_23',
|
|
26
|
+
responseKey: 'services',
|
|
27
|
+
footer: {},
|
|
28
|
+
rowTransformer: this.buildRow.bind(this),
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
buildRow(service) {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
const serviceCapability = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.find((r) => r.serviceId === service.id);
|
|
34
|
+
return {
|
|
35
|
+
id: service.id,
|
|
36
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
yield this.handleEdit(service, serviceCapability);
|
|
38
|
+
}),
|
|
39
|
+
cells: [
|
|
40
|
+
{
|
|
41
|
+
text: {
|
|
42
|
+
content: service.name,
|
|
43
|
+
},
|
|
44
|
+
subText: {
|
|
45
|
+
content: `$${(_b = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.price) !== null && _b !== void 0 ? _b : service.price} - ${this.calculateDuration((_c = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.timeBlocks) !== null && _c !== void 0 ? _c : service.timeBlocks)}`,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
toggleInput: {
|
|
50
|
+
name: 'isEnabled',
|
|
51
|
+
value: (_d = serviceCapability === null || serviceCapability === void 0 ? void 0 : serviceCapability.isEnabled) !== null && _d !== void 0 ? _d : false,
|
|
52
|
+
onChange: (value) => __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
yield this.handleToggleChange(service, value !== null && value !== void 0 ? value : false, serviceCapability);
|
|
54
|
+
}),
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
].filter((c) => !!c),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
handleEdit(serviceRow, serviceRoleCapability) {
|
|
61
|
+
var _a;
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
this.editVc = this.Controller('appointments.edit-override-details-card', {
|
|
64
|
+
onCancel: () => { },
|
|
65
|
+
onSubmit: (price, timeBlocks, serviceRow, serviceRoleCapability) => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
yield dlgVc.hide();
|
|
67
|
+
const newServiceCapability = yield this.insertOrUpdateCapability(serviceRow.id, { price, timeBlocks, isEnabled: true }, serviceRoleCapability);
|
|
68
|
+
if (newServiceCapability) {
|
|
69
|
+
this.upsertCapabilities(newServiceCapability, serviceRow);
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
service: serviceRow,
|
|
73
|
+
serviceRoleCapability,
|
|
74
|
+
});
|
|
75
|
+
const dlgVc = this.renderInDialog(Object.assign({}, this.editVc.render()));
|
|
76
|
+
return (_a = this.onEdit) === null || _a === void 0 ? void 0 : _a.call(this, serviceRow);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
upsertCapabilities(newServiceCapability, service) {
|
|
80
|
+
var _a;
|
|
81
|
+
const listVc = this.getListVc();
|
|
82
|
+
if (newServiceCapability) {
|
|
83
|
+
this.capabilities = (_a = this.capabilities) === null || _a === void 0 ? void 0 : _a.filter((r) => r.id !== newServiceCapability.id);
|
|
84
|
+
this.capabilities.push(newServiceCapability);
|
|
85
|
+
listVc.upsertRow(service.id, Object.assign({}, this.buildRow(service)));
|
|
86
|
+
listVc.triggerRender();
|
|
87
|
+
this.getActiveRecordVc().triggerRender();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
handleToggleChange(service, value, capability) {
|
|
91
|
+
var _a;
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
(_a = this.onUpdateHasCapability) === null || _a === void 0 ? void 0 : _a.call(this, service, value);
|
|
94
|
+
const newCapability = yield this.insertOrUpdateCapability(service.id, { isEnabled: value }, capability);
|
|
95
|
+
if (newCapability) {
|
|
96
|
+
this.upsertCapabilities(newCapability, service);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
loadVc(organizationId) {
|
|
101
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
this.organizationId = organizationId;
|
|
103
|
+
this.activeRecordCardVc.setTarget({ organizationId });
|
|
104
|
+
this.activeRecordCardVc.getCardVc().setIsBusy(false);
|
|
105
|
+
yield this.loadCapabilities();
|
|
106
|
+
yield this.activeRecordCardVc.load();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
calculateDuration(timeblocks) {
|
|
110
|
+
const duration = timeblocks
|
|
111
|
+
.map((a) => a.durationMinutes)
|
|
112
|
+
.reduce(function (a, b) {
|
|
113
|
+
return a + b;
|
|
114
|
+
});
|
|
115
|
+
const r = durationUtil.msToFriendly(duration * 60000);
|
|
116
|
+
return r;
|
|
117
|
+
}
|
|
118
|
+
getCardVc() {
|
|
119
|
+
return this.activeRecordCardVc.getCardVc();
|
|
120
|
+
}
|
|
121
|
+
getActiveRecordVc() {
|
|
122
|
+
return this.activeRecordCardVc;
|
|
123
|
+
}
|
|
124
|
+
getListVc() {
|
|
125
|
+
return this.activeRecordCardVc.getListVc();
|
|
126
|
+
}
|
|
127
|
+
getEditVc() {
|
|
128
|
+
return this.editVc;
|
|
129
|
+
}
|
|
130
|
+
getOrganizationId() {
|
|
131
|
+
return this.organizationId;
|
|
132
|
+
}
|
|
133
|
+
getCapabilities() {
|
|
134
|
+
return this.capabilities;
|
|
135
|
+
}
|
|
136
|
+
getLocationId() {
|
|
137
|
+
var _a;
|
|
138
|
+
return (_a = this.locationId) !== null && _a !== void 0 ? _a : 'no location id';
|
|
139
|
+
}
|
|
140
|
+
render() {
|
|
141
|
+
return this.activeRecordCardVc.render();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SpruceSchemas as SpruceSchemasCalendarUtils } from '@sprucelabs/calendar-utils';
|
|
2
|
+
import { AbstractViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
3
|
+
import DurationListViewController from './DurationList.vc';
|
|
4
|
+
export declare type EventTimeBlock = Omit<SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.EventTimeBlock, 'durationMinutes'> & {
|
|
5
|
+
durationMinutes?: number;
|
|
6
|
+
};
|
|
7
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
8
|
+
export declare type DurationCardViewControllerOptions = ViewControllerOptions;
|
|
9
|
+
export default class DurationCardViewController extends AbstractViewController<Card> {
|
|
10
|
+
static id: string;
|
|
11
|
+
private listVc;
|
|
12
|
+
private cardVc;
|
|
13
|
+
constructor(options: DurationCardViewControllerOptions);
|
|
14
|
+
private CardVc;
|
|
15
|
+
load(timeBlocks?: EventTimeBlock[]): void;
|
|
16
|
+
setValues(timeBlocks?: EventTimeBlock[]): void;
|
|
17
|
+
private handleClickAddTimeBlock;
|
|
18
|
+
private ListVc;
|
|
19
|
+
getEditTitleFormVc(): import("./EditTimeBlockTitleCard.vc").FormVc | undefined;
|
|
20
|
+
payAttentionToMe(): void;
|
|
21
|
+
getDurationListVc(): DurationListViewController;
|
|
22
|
+
getTimeBlocks(): {
|
|
23
|
+
title?: string | null | undefined;
|
|
24
|
+
subtitle?: string | null | undefined;
|
|
25
|
+
isBusy: boolean;
|
|
26
|
+
rightIcons?: SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.CalendarEventLineIcon[] | null | undefined;
|
|
27
|
+
leftIcons?: SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.CalendarEventLineIcon[] | null | undefined;
|
|
28
|
+
durationMinutes?: number | undefined;
|
|
29
|
+
id: string;
|
|
30
|
+
}[];
|
|
31
|
+
render(): SpruceSchemasCalendarUtils.HeartwoodViewControllers.v2021_02_11.Card;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
export default class DurationCardViewController extends AbstractViewController {
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options);
|
|
14
|
+
this.listVc = this.ListVc();
|
|
15
|
+
this.cardVc = this.CardVc();
|
|
16
|
+
}
|
|
17
|
+
CardVc() {
|
|
18
|
+
return this.Controller('card', {
|
|
19
|
+
id: 'durations',
|
|
20
|
+
header: {
|
|
21
|
+
title: 'Durations',
|
|
22
|
+
subtitle: 'You can set how long a services going to take. You can even break a service up into distinct blocks of time to handle things like setup, teardown, breaks, or whenever!',
|
|
23
|
+
},
|
|
24
|
+
body: {
|
|
25
|
+
isBusy: true,
|
|
26
|
+
sections: [
|
|
27
|
+
{
|
|
28
|
+
list: this.listVc.render(),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
footer: {
|
|
33
|
+
buttons: [
|
|
34
|
+
{
|
|
35
|
+
label: 'Add block of time',
|
|
36
|
+
id: 'addDuration',
|
|
37
|
+
type: 'primary',
|
|
38
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
this.handleClickAddTimeBlock();
|
|
40
|
+
}),
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
load(timeBlocks) {
|
|
47
|
+
this.setValues(timeBlocks);
|
|
48
|
+
this.cardVc.setIsBusy(false);
|
|
49
|
+
}
|
|
50
|
+
setValues(timeBlocks) {
|
|
51
|
+
this.listVc.setValues(timeBlocks);
|
|
52
|
+
}
|
|
53
|
+
handleClickAddTimeBlock() {
|
|
54
|
+
this.listVc.addNewTimeBlock();
|
|
55
|
+
}
|
|
56
|
+
ListVc() {
|
|
57
|
+
return this.Controller('appointments.duration-list', {});
|
|
58
|
+
}
|
|
59
|
+
getEditTitleFormVc() {
|
|
60
|
+
return this.listVc.getEditTitleFormVc();
|
|
61
|
+
}
|
|
62
|
+
payAttentionToMe() {
|
|
63
|
+
this.cardVc.payAttentionToMe();
|
|
64
|
+
}
|
|
65
|
+
getDurationListVc() {
|
|
66
|
+
return this.listVc;
|
|
67
|
+
}
|
|
68
|
+
getTimeBlocks() {
|
|
69
|
+
return this.listVc.getTimeBlocks();
|
|
70
|
+
}
|
|
71
|
+
render() {
|
|
72
|
+
return this.cardVc.render();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
DurationCardViewController.id = 'duration-card';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { AbstractViewController, ListViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
2
|
+
import { EventTimeBlock } from './DurationCard.vc';
|
|
3
|
+
import { FormVc } from './EditTimeBlockTitleCard.vc';
|
|
4
|
+
declare type List = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.List;
|
|
5
|
+
declare type TimeBlockWithId = EventTimeBlock & {
|
|
6
|
+
id: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type DurationListViewControllerOptions = ViewControllerOptions;
|
|
9
|
+
export default class DurationListViewController extends AbstractViewController<List> {
|
|
10
|
+
static id: string;
|
|
11
|
+
private listVc;
|
|
12
|
+
private timeBlocksWithId;
|
|
13
|
+
private timeBlockRowIdx;
|
|
14
|
+
private editTitleFormVc?;
|
|
15
|
+
constructor(options: DurationListViewControllerOptions);
|
|
16
|
+
private ListVc;
|
|
17
|
+
setValues(timeBlocks: EventTimeBlock[] | undefined): void;
|
|
18
|
+
private generateBlockId;
|
|
19
|
+
private addRow;
|
|
20
|
+
getListVc(): ListViewController;
|
|
21
|
+
getTimeBlocks(): {
|
|
22
|
+
title?: string | null | undefined;
|
|
23
|
+
subtitle?: string | null | undefined;
|
|
24
|
+
isBusy: boolean;
|
|
25
|
+
rightIcons?: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventLineIcon[] | null | undefined;
|
|
26
|
+
leftIcons?: SpruceSchemas.CalendarUtils.v2021_05_19.CalendarEventLineIcon[] | null | undefined;
|
|
27
|
+
durationMinutes?: number | undefined;
|
|
28
|
+
id: string;
|
|
29
|
+
}[];
|
|
30
|
+
private buildRow;
|
|
31
|
+
addNewTimeBlock(): void;
|
|
32
|
+
handleClickEditTitle(timeBlock: TimeBlockWithId): Promise<void>;
|
|
33
|
+
private handleClickDelete;
|
|
34
|
+
getEditTitleFormVc(): FormVc | undefined;
|
|
35
|
+
render(): SpruceSchemas.HeartwoodViewControllers.v2021_02_11.List;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,188 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { AbstractViewController, } from '@sprucelabs/heartwood-view-controllers';
|
|
22
|
+
export default class DurationListViewController extends AbstractViewController {
|
|
23
|
+
constructor(options) {
|
|
24
|
+
super(options);
|
|
25
|
+
this.timeBlocksWithId = [];
|
|
26
|
+
this.timeBlockRowIdx = 0;
|
|
27
|
+
this.listVc = this.ListVc();
|
|
28
|
+
}
|
|
29
|
+
ListVc() {
|
|
30
|
+
return this.Controller('list', {
|
|
31
|
+
columnWidths: ['content', 'content', 'fill'],
|
|
32
|
+
rows: [],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
setValues(timeBlocks) {
|
|
36
|
+
if (!timeBlocks || timeBlocks.length === 0) {
|
|
37
|
+
timeBlocks = [
|
|
38
|
+
{ title: 'Duration', isBusy: true, durationMinutes: undefined },
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
this.timeBlocksWithId = timeBlocks.map((tb) => (Object.assign({ id: this.generateBlockId() }, tb)));
|
|
42
|
+
for (const timeBlock of this.timeBlocksWithId) {
|
|
43
|
+
this.addRow(timeBlock);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
generateBlockId() {
|
|
47
|
+
return `timeblock-${this.timeBlockRowIdx++}`;
|
|
48
|
+
}
|
|
49
|
+
addRow(timeBlock) {
|
|
50
|
+
this.listVc.addRow(this.buildRow(timeBlock));
|
|
51
|
+
}
|
|
52
|
+
getListVc() {
|
|
53
|
+
return this.listVc;
|
|
54
|
+
}
|
|
55
|
+
getTimeBlocks() {
|
|
56
|
+
return this.timeBlocksWithId.map((tb) => {
|
|
57
|
+
const values = __rest(tb
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
, []);
|
|
60
|
+
//@ts-ignore
|
|
61
|
+
delete values.id;
|
|
62
|
+
return values;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
buildRow(timeBlockWithId) {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
const { id: rowId } = timeBlockWithId, timeBlock = __rest(timeBlockWithId, ["id"]);
|
|
68
|
+
return {
|
|
69
|
+
id: rowId,
|
|
70
|
+
height: 'content',
|
|
71
|
+
cells: [
|
|
72
|
+
{
|
|
73
|
+
button: {
|
|
74
|
+
id: 'edit-title',
|
|
75
|
+
lineIcon: 'edit-line',
|
|
76
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
yield this.handleClickEditTitle(timeBlockWithId);
|
|
78
|
+
}),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
text: {
|
|
83
|
+
content: (_a = timeBlock.title) !== null && _a !== void 0 ? _a : 'Duration',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
textInput: {
|
|
88
|
+
name: 'durationMinutes',
|
|
89
|
+
label: 'Minutes',
|
|
90
|
+
value: (timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.durationMinutes)
|
|
91
|
+
? `${timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.durationMinutes}`
|
|
92
|
+
: undefined,
|
|
93
|
+
onChange: (value) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
if (value) {
|
|
95
|
+
const cleaned = value.replace(/[^0-9]/, '');
|
|
96
|
+
if (cleaned !== value) {
|
|
97
|
+
yield this.listVc
|
|
98
|
+
.getRowVc(rowId)
|
|
99
|
+
.setValue('durationMinutes', cleaned);
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
timeBlockWithId.durationMinutes = parseInt(value, 10);
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}),
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
toggleInput: {
|
|
110
|
+
name: 'isBusy',
|
|
111
|
+
value: (_b = timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.isBusy) !== null && _b !== void 0 ? _b : true,
|
|
112
|
+
onChange: (value) => {
|
|
113
|
+
timeBlockWithId.isBusy = value !== null && value !== void 0 ? value : false;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
button: {
|
|
119
|
+
lineIcon: 'help-circle',
|
|
120
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
yield this.alert({
|
|
122
|
+
style: 'info',
|
|
123
|
+
title: 'Mark time as busy?',
|
|
124
|
+
message: `This toggle is how you set this time to be marked as busy or not. If the time is busy, nobody can book the provider during this time. If the time is not busy, people can book over this time.`,
|
|
125
|
+
});
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
button: {
|
|
131
|
+
id: 'delete',
|
|
132
|
+
lineIcon: 'delete',
|
|
133
|
+
type: 'destructive',
|
|
134
|
+
onClick: () => {
|
|
135
|
+
return this.handleClickDelete(timeBlockWithId);
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
addNewTimeBlock() {
|
|
143
|
+
const timeBlock = {
|
|
144
|
+
id: this.generateBlockId(),
|
|
145
|
+
isBusy: true,
|
|
146
|
+
};
|
|
147
|
+
this.timeBlocksWithId.push(timeBlock);
|
|
148
|
+
this.addRow(timeBlock);
|
|
149
|
+
}
|
|
150
|
+
handleClickEditTitle(timeBlock) {
|
|
151
|
+
var _a;
|
|
152
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
153
|
+
const editVc = this.Controller('appointments.edit-time-block-title-card', {
|
|
154
|
+
onCancel: () => { },
|
|
155
|
+
onSubmit: (title) => __awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
timeBlock.title = title;
|
|
157
|
+
this.listVc.upsertRow(timeBlock.id, Object.assign({}, this.buildRow(timeBlock)));
|
|
158
|
+
this.listVc.triggerRender();
|
|
159
|
+
yield dlgVc.hide();
|
|
160
|
+
}),
|
|
161
|
+
title: (_a = timeBlock === null || timeBlock === void 0 ? void 0 : timeBlock.title) !== null && _a !== void 0 ? _a : '',
|
|
162
|
+
});
|
|
163
|
+
this.editTitleFormVc = editVc.getFormVc();
|
|
164
|
+
const dlgVc = this.renderInDialog(Object.assign({}, editVc.render()));
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
handleClickDelete(timeBlock) {
|
|
168
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
169
|
+
const shouldDelete = yield this.confirm({
|
|
170
|
+
title: `You sure?`,
|
|
171
|
+
isDestructive: true,
|
|
172
|
+
});
|
|
173
|
+
if (!shouldDelete) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
this.listVc.deleteRow(timeBlock.id);
|
|
177
|
+
const idx = this.timeBlocksWithId.indexOf(timeBlock);
|
|
178
|
+
this.timeBlocksWithId.splice(idx, 1);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
getEditTitleFormVc() {
|
|
182
|
+
return this.editTitleFormVc;
|
|
183
|
+
}
|
|
184
|
+
render() {
|
|
185
|
+
return this.listVc.render();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
DurationListViewController.id = 'duration-list';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SpruceSchemas as SpruceSchemasCalendarUtils } from '@sprucelabs/calendar-utils';
|
|
2
|
+
import { AbstractViewController, FormViewController, SpruceSchemas, ViewControllerOptions } from '@sprucelabs/heartwood-view-controllers';
|
|
3
|
+
import DurationCardViewController from './DurationCard.vc';
|
|
4
|
+
declare type Card = SpruceSchemas.HeartwoodViewControllers.v2021_02_11.Card;
|
|
5
|
+
declare type EventTimeBlock = Omit<SpruceSchemasCalendarUtils.CalendarUtils.v2021_05_19.EventTimeBlock, 'durationMinutes'> & {
|
|
6
|
+
durationMinutes?: number;
|
|
7
|
+
};
|
|
8
|
+
declare const schema: {
|
|
9
|
+
id: string;
|
|
10
|
+
fields: {
|
|
11
|
+
price: {
|
|
12
|
+
type: "text";
|
|
13
|
+
label: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
declare type Schema = typeof schema;
|
|
18
|
+
export declare type FormVc = FormViewController<Schema>;
|
|
19
|
+
interface EditOverrideDetailsOptions {
|
|
20
|
+
service?: any;
|
|
21
|
+
serviceRoleCapability?: any;
|
|
22
|
+
onCancel: () => void;
|
|
23
|
+
onSubmit: (price: string | undefined, timeBlocks: EventTimeBlock[] | undefined, service: any | undefined, serviceRoleCapability: any | undefined) => void;
|
|
24
|
+
}
|
|
25
|
+
export declare type EditOverrideDetailsCardViewControllerOptions = ViewControllerOptions & EditOverrideDetailsOptions;
|
|
26
|
+
export default class EditOverrideDetailsCardViewController extends AbstractViewController<Card> {
|
|
27
|
+
static id: string;
|
|
28
|
+
private cardVc;
|
|
29
|
+
private formVc;
|
|
30
|
+
private durationVc;
|
|
31
|
+
private durationListVc;
|
|
32
|
+
private onSubmitHandler;
|
|
33
|
+
private onCancelHandler;
|
|
34
|
+
private service;
|
|
35
|
+
private serviceRoleCapability;
|
|
36
|
+
constructor(options: EditOverrideDetailsCardViewControllerOptions);
|
|
37
|
+
private FormVc;
|
|
38
|
+
private handleClickAddTimeBlock;
|
|
39
|
+
private CardVc;
|
|
40
|
+
getFormVc(): FormVc;
|
|
41
|
+
getDurationVc(): DurationCardViewController;
|
|
42
|
+
render(): SpruceSchemasCalendarUtils.HeartwoodViewControllers.v2021_02_11.Card;
|
|
43
|
+
}
|
|
44
|
+
export {};
|