@jsb188/mday 1.1.10 → 1.1.11
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/package.json +105 -54
- package/src/constants/agentDoc.ts +12 -0
- package/src/constants/agentMemory.ts +154 -0
- package/src/constants/aiChat.ts +5 -0
- package/src/constants/campaign.ts +127 -0
- package/src/constants/dataTable.ts +35 -9
- package/src/constants/dataTableFieldTypes.generated.ts +63 -0
- package/src/constants/docAccess.ts +32 -0
- package/src/constants/email.ts +20 -4
- package/src/constants/fieldDoc.ts +34 -0
- package/src/constants/graphqlReactivity.ts +113 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +7 -410
- package/src/constants/logActivityGroupColors.generated.ts +19 -0
- package/src/constants/logTaxonomy.generated.ts +1103 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +13 -15
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/schedule.ts +220 -0
- package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
- package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
- package/src/constants/sheet.ts +154 -6
- package/src/constants/sheetRegionSources.generated.ts +578 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +56 -7
- package/src/constants/usage.ts +79 -0
- package/src/schemas/editLogEntry.ts +1010 -777
- package/src/schemas/fieldDocsQuery.ts +12 -0
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/schemas/organization.ts +49 -46
- package/src/types/account.d.ts +4 -1
- package/src/types/agentDoc.d.ts +64 -0
- package/src/types/agentMemory.d.ts +74 -0
- package/src/types/campaign.d.ts +683 -0
- package/src/types/dataTable.d.ts +175 -256
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/email.d.ts +83 -12
- package/src/types/fieldDoc.d.ts +273 -0
- package/src/types/inboundContact.d.ts +2 -1
- package/src/types/log.d.ts +209 -341
- package/src/types/noteDoc.d.ts +86 -0
- package/src/types/organization.d.ts +83 -40
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/schedule.d.ts +391 -0
- package/src/types/sheet.d.ts +862 -30
- package/src/types/storage.d.ts +206 -125
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +149 -18
- package/src/utils/agentDoc.ts +109 -0
- package/src/utils/aiChat.ts +26 -0
- package/src/utils/campaign.ts +741 -0
- package/src/utils/campaignFormEditor.ts +871 -0
- package/src/utils/dataTable.ts +425 -410
- package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
- package/src/utils/dataTableRealtimeAuthority.ts +209 -0
- package/src/utils/dataTableRealtimeSelection.ts +134 -0
- package/src/utils/dataTableRowDocument.ts +508 -0
- package/src/utils/dataTableSource.ts +230 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +112 -53
- package/src/utils/fieldDoc.ts +113 -0
- package/src/utils/log.ts +169 -176
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +266 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +439 -0
- package/src/utils/noteDoc.ts +827 -0
- package/src/utils/organization.ts +510 -91
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/schedule.ts +799 -0
- package/src/utils/scheduleEvaluation.ts +1994 -0
- package/src/utils/scheduleICS.ts +246 -0
- package/src/utils/scheduleRuleTemplates.ts +188 -0
- package/src/utils/sheet.ts +4842 -39
- package/src/utils/sheetAxisMove.ts +830 -0
- package/src/utils/sheetBootstrap.ts +1769 -0
- package/src/utils/sheetCommand.ts +423 -0
- package/src/utils/sheetExport.ts +238 -0
- package/src/utils/sheetFormulaEvaluation.ts +914 -0
- package/src/utils/sheetFormulaEvaluator.ts +852 -0
- package/src/utils/sheetJournal.ts +78 -0
- package/src/utils/sheetNumberFormat.ts +1211 -0
- package/src/utils/sheetRegion.ts +374 -0
- package/src/utils/sheetRegionFilter.ts +1259 -0
- package/src/utils/sheetRegionSourceRegistry.ts +594 -0
- package/src/utils/sheetSequence.ts +148 -0
- package/src/utils/sheetSnapshot.ts +992 -0
- package/src/utils/sheetStructureEdit.ts +1284 -0
- package/src/utils/square.ts +22 -12
- package/src/utils/storage.ts +152 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/workflow.ts +191 -23
- package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/noteDoc.test.ts +669 -0
- package/tests/schedule.test.ts +693 -0
- package/tests/scheduleEvaluation.test.ts +1970 -0
- package/tests/scheduleICS.test.ts +208 -0
- package/tests/scheduleRuleTemplates.test.ts +176 -0
- package/tests/scheduleSweepInvariants.test.ts +428 -0
- package/tests/sheetAxisMove.test.ts +343 -0
- package/tests/sheetFormulaEvaluator.test.ts +575 -0
- package/tests/sheetRegionFilter.test.ts +1135 -0
- package/tests/sheetSequence.test.ts +41 -0
- package/tests/sheetStructureEdit.test.ts +82 -0
- package/tsconfig.json +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
|
@@ -1,455 +0,0 @@
|
|
|
1
|
-
import i18n from '@jsb188/app/i18n/index.ts';
|
|
2
|
-
import type { AddressObj, ScheduleObj } from '@jsb188/app/types/other.d.ts';
|
|
3
|
-
import { getFullDate } from '@jsb188/app/utils/datetime.ts';
|
|
4
|
-
import { convertToMilitaryTime } from '@jsb188/app/utils/number.ts';
|
|
5
|
-
import { DEFAULT_TIMEZONE, formatCalDateInTimeZone, getDayOfWeekInTimeZone, hhmmFromDateOrTime, parseBoundaryDateInTimezone } from '@jsb188/app/utils/timeZone.ts';
|
|
6
|
-
import { DateTime } from 'luxon';
|
|
7
|
-
import type { ProductCalEventData, ProductCalEventGQL } from '../types/product.d.ts';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Get the address in a single line text format
|
|
11
|
-
* @param address - Address data object
|
|
12
|
-
* @param multiline - Whether to format in multiple lines
|
|
13
|
-
* @returns Address in a single line text format
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
export function getAddressText(
|
|
17
|
-
address: AddressObj | null,
|
|
18
|
-
multiline = false,
|
|
19
|
-
): string {
|
|
20
|
-
if (!address) {
|
|
21
|
-
return i18n.t('form.not_specified');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const { line1, line2, city, state, postalCode, country } = address;
|
|
25
|
-
if (multiline) {
|
|
26
|
-
return [
|
|
27
|
-
[line1, line2].filter(Boolean).join(', '),
|
|
28
|
-
[city, state, postalCode, country].filter(Boolean).join(', '),
|
|
29
|
-
].filter(Boolean).join('\n');
|
|
30
|
-
}
|
|
31
|
-
return [line1, line2, city, state, postalCode, country].filter(Boolean).join(', ');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Check if organization event is upcoming
|
|
36
|
-
* Upcoming is defined by: "recurring and not ended" or "date is in the future"
|
|
37
|
-
* @param eventProduct - Calendar Event product GQL data
|
|
38
|
-
* @returns boolean value to indicate if event is upcoming
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
export function checkIfEventIsUpcoming(eventDetails: ProductCalEventGQL): boolean {
|
|
42
|
-
const now = new Date();
|
|
43
|
-
|
|
44
|
-
const once = !eventDetails.schedule?.frequency || eventDetails.schedule.frequency === 'ONCE';
|
|
45
|
-
if (once) {
|
|
46
|
-
const startAt = new Date(eventDetails.startAt);
|
|
47
|
-
return startAt > now;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// End date only applies to recurring events
|
|
51
|
-
const endAt = eventDetails.endAt ? new Date(eventDetails.endAt) : null;
|
|
52
|
-
const finished = endAt && (endAt < now);
|
|
53
|
-
if (finished) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// If it's not "once" event, then it's recurring until end date, so it will default to true
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Get icon for event based on time (finished, upcoming, today, etc)
|
|
63
|
-
* @param startAt - Event start date/time in ISO format
|
|
64
|
-
* @param endAt - Event end date/time in ISO format
|
|
65
|
-
* @param schedule - Event schedule object
|
|
66
|
-
* @param showRecurringSchedule - Whether recurring schedule should be shown
|
|
67
|
-
* @returns Icon name as string
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
export function getEventIconName(
|
|
71
|
-
startAt_: string | Date,
|
|
72
|
-
endAt_: string | Date | null,
|
|
73
|
-
schedule: ScheduleObj | null,
|
|
74
|
-
): string {
|
|
75
|
-
const startAt = new Date(startAt_);
|
|
76
|
-
const endAt = endAt_ ? new Date(endAt_) : null;
|
|
77
|
-
const once = !schedule?.frequency || schedule?.frequency === 'ONCE';
|
|
78
|
-
const isUpcoming = checkIfEventIsUpcoming({ startAt, endAt, schedule } as ProductCalEventGQL);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (isUpcoming && !once) {
|
|
83
|
-
return 'calendar-3'; // Upcoming & not-finished recurring event
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const now = new Date();
|
|
87
|
-
if (startAt < now) {
|
|
88
|
-
return 'calendar-check'; // Finished event
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const startDate = new Date(startAt.getFullYear(), startAt.getMonth(), startAt.getDate());
|
|
92
|
-
const nowDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
|
|
93
|
-
|
|
94
|
-
if (startDate.getTime() === nowDate.getTime()) {
|
|
95
|
-
return 'clock-3'; // Today's event
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return 'calendar-3'; // Upcoming one-time event
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Get the icon labels for Organization event data
|
|
103
|
-
* @param eventProduct - Calendar Event product GQL data
|
|
104
|
-
* @returns Array of icon label objects with icon name and tooltip text
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
export function getEventLabelIcons(eventDetails: ProductCalEventGQL) {
|
|
108
|
-
const { schedule, address } = eventDetails;
|
|
109
|
-
const addressText = address && getAddressText(address);
|
|
110
|
-
const labelIcons = [];
|
|
111
|
-
|
|
112
|
-
if (addressText) {
|
|
113
|
-
labelIcons.push({
|
|
114
|
-
iconName: 'style-two-pin-marker',
|
|
115
|
-
color: 'darker_2', // should really be "lt" but because the icon is "filled", it looks more like texts written in "lt"
|
|
116
|
-
tooltipText: addressText,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// if (status === 'CANCELED') {
|
|
121
|
-
// labelIcons.push({
|
|
122
|
-
// text: 'Canceled',
|
|
123
|
-
// color: 'red_light',
|
|
124
|
-
// // tooltipText: i18n.t('org.event_canceled'),
|
|
125
|
-
// });
|
|
126
|
-
// }
|
|
127
|
-
|
|
128
|
-
// if (recurring) {
|
|
129
|
-
// labelIcons.push({
|
|
130
|
-
// iconName: 'library-filled',
|
|
131
|
-
// color: 'darker_2', // should really be "lt" but because the icon is "filled", it looks more like texts written in "lt"
|
|
132
|
-
// tooltipText: recurringSchedule || i18n.t('org.no_recurring_schedule'),
|
|
133
|
-
// });
|
|
134
|
-
// } else {
|
|
135
|
-
// labelIcons.push({
|
|
136
|
-
// iconName: 'circle-number-1-filled',
|
|
137
|
-
// color: 'emerald',
|
|
138
|
-
// tooltipText: i18n.t('org.single_event_msg'),
|
|
139
|
-
// });
|
|
140
|
-
// }
|
|
141
|
-
|
|
142
|
-
return labelIcons;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Get schedule info and icons
|
|
147
|
-
* @param eventDetails - Calendar Event details object
|
|
148
|
-
* @param alwaysFillIcon - Whether to always use filled icons
|
|
149
|
-
* @returns Array of icon label objects with icon name and tooltip text
|
|
150
|
-
*/
|
|
151
|
-
|
|
152
|
-
export function getScheduleIcons(eventDetails: ProductCalEventGQL, alwaysFillIcon = false) {
|
|
153
|
-
const { schedule } = eventDetails;
|
|
154
|
-
const once = !schedule?.frequency || schedule.frequency === 'ONCE';
|
|
155
|
-
|
|
156
|
-
if (once) {
|
|
157
|
-
return [{
|
|
158
|
-
iconName: 'number-1-circle-filled',
|
|
159
|
-
color: 'amber',
|
|
160
|
-
tooltipText: i18n.t('org.single_event_msg'),
|
|
161
|
-
}];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const { daysOfWeek } = schedule;
|
|
165
|
-
const [startTime, endTime] = schedule.time || [];
|
|
166
|
-
|
|
167
|
-
const labelIcons = [[0,'S'], [1, 'M'], [2, 'T'], [3, 'W'], [4, 'T'], [5, 'F'], [6, 'S']].map((d) => {
|
|
168
|
-
const [dayInt, dayLetter] = d as [0 | 1 | 2 | 3 | 4 | 5 | 6, string];
|
|
169
|
-
const isScheduled = daysOfWeek?.includes(dayInt);
|
|
170
|
-
|
|
171
|
-
let timeText = '';
|
|
172
|
-
if (startTime) {
|
|
173
|
-
timeText = ` ${convertToMilitaryTime(startTime)}${endTime ? ' - ' + convertToMilitaryTime(endTime) : ''}`;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
iconName: `circle-letter-${dayLetter.toLowerCase()}${isScheduled || alwaysFillIcon ? '-filled' : ''}`,
|
|
178
|
-
color: !isScheduled ? 'darker_2' : dayLetter === 's' ? 'sky' : 'lime',
|
|
179
|
-
tooltipText: isScheduled ? (i18n.t(`datetime.daysOfWeek.${dayInt}`) + timeText) : undefined,
|
|
180
|
-
};
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
return labelIcons;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get next date from schedule
|
|
188
|
-
* @param schedule - Event schedule object
|
|
189
|
-
* @param startAt - Start date/time of when this schedule goes in effect
|
|
190
|
-
* @param timeZone - Time zone string
|
|
191
|
-
* @returns Next date in string format
|
|
192
|
-
*/
|
|
193
|
-
|
|
194
|
-
export function getNextDateFromSchedule(
|
|
195
|
-
schedule: ScheduleObj | null,
|
|
196
|
-
startAt: string | Date | null,
|
|
197
|
-
timeZone_: string | null,
|
|
198
|
-
) {
|
|
199
|
-
const timeZone = timeZone_ || DEFAULT_TIMEZONE;
|
|
200
|
-
const once = !schedule?.frequency || schedule.frequency === 'ONCE';
|
|
201
|
-
if (once) {
|
|
202
|
-
let onceDate, onceCalDate;
|
|
203
|
-
if (startAt) {
|
|
204
|
-
const dt = DateTime.fromISO(startAt.toString()).setZone(timeZone);
|
|
205
|
-
onceDate = dt.toJSDate();
|
|
206
|
-
onceCalDate = dt.toFormat('yyyy-MM-dd');
|
|
207
|
-
} else {
|
|
208
|
-
onceDate = null;
|
|
209
|
-
onceCalDate = null;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
date: onceDate,
|
|
214
|
-
calDate: onceCalDate,
|
|
215
|
-
text: getFullDate(startAt, 'DATE_ONLY_SHORT', timeZone),
|
|
216
|
-
numericText: getFullDate(startAt, 'TOMORROW_OR_NUMERIC', timeZone),
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
// Get date in time zone using Luxon package
|
|
221
|
-
let now = DateTime.now().setZone(timeZone).toJSDate();
|
|
222
|
-
if (startAt) {
|
|
223
|
-
const scheduleStartDate = DateTime.fromISO(startAt.toString()).setZone(timeZone).toJSDate();
|
|
224
|
-
// If scheduleStartDate is after "now", use that as the base date
|
|
225
|
-
if (scheduleStartDate > now) {
|
|
226
|
-
now = scheduleStartDate;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const daySchedTime = (schedule.time || []).map(Number);
|
|
231
|
-
// const startTime = (daySchedTime[0] || daySchedTime[0] === 0) && convertToMilitaryTime(daySchedTime[0]);
|
|
232
|
-
const hours = Math.floor((daySchedTime[0] || 0) / 100);
|
|
233
|
-
const minutes = (daySchedTime[0] || 0) % 100;
|
|
234
|
-
const { daysOfWeek } = schedule;
|
|
235
|
-
|
|
236
|
-
let nextDate;
|
|
237
|
-
if (daysOfWeek && daysOfWeek.length > 0) {
|
|
238
|
-
const today = now.getDay();
|
|
239
|
-
|
|
240
|
-
let minDiff = Infinity;
|
|
241
|
-
for (const num of daysOfWeek) {
|
|
242
|
-
if (num < 0 || num > 6) {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
let diff = (num - today + 7) % 7;
|
|
247
|
-
// if it's today, check the time
|
|
248
|
-
if (diff === 0) {
|
|
249
|
-
const candidate = DateTime.fromJSDate(now).setZone(timeZone)
|
|
250
|
-
.set({ hour: hours, minute: minutes, second: 0, millisecond: 0 })
|
|
251
|
-
.toJSDate();
|
|
252
|
-
|
|
253
|
-
// if the time hasn't passed yet → pick today
|
|
254
|
-
if (candidate > now) {
|
|
255
|
-
minDiff = 0;
|
|
256
|
-
break; // earliest possible, no need to check others
|
|
257
|
-
} else {
|
|
258
|
-
diff = 7; // skip to next week
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (diff < minDiff) {
|
|
263
|
-
minDiff = diff;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
if (minDiff !== Infinity) {
|
|
268
|
-
nextDate = DateTime.fromJSDate(now).setZone(timeZone)
|
|
269
|
-
.plus({ days: minDiff })
|
|
270
|
-
.set({ hour: hours, minute: minutes, second: 0, millisecond: 0 })
|
|
271
|
-
.toJSDate();
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (nextDate) {
|
|
276
|
-
const calDate = DateTime.fromJSDate(nextDate, { zone: timeZone }).toFormat('yyyy-MM-dd');
|
|
277
|
-
return {
|
|
278
|
-
date: nextDate,
|
|
279
|
-
calDate,
|
|
280
|
-
text: getFullDate(nextDate, 'DATE_ONLY_SHORT', timeZone),
|
|
281
|
-
numericText: getFullDate(nextDate, 'TOMORROW_OR_NUMERIC', timeZone),
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return {
|
|
286
|
-
date: null,
|
|
287
|
-
calDate: null,
|
|
288
|
-
numericText: '',
|
|
289
|
-
text: '',
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Check if date is a scheduled date
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
export function isScheduledDate(
|
|
298
|
-
eventDetails: ProductCalEventData['metadata'] | ProductCalEventGQL | null,
|
|
299
|
-
calDateInt_: number | string,
|
|
300
|
-
startAt: string | Date | null,
|
|
301
|
-
endAt: string | Date | null,
|
|
302
|
-
) {
|
|
303
|
-
// @ts-ignore - For server + client usage
|
|
304
|
-
const schedule = (eventDetails?.schedule || eventDetails?.metadata?.schedule || {}) as ScheduleObj;
|
|
305
|
-
const { frequency, daysOfWeek } = schedule;
|
|
306
|
-
const startCalDateInt = startAt ? Number(DateTime.fromJSDate(new Date(startAt)).toFormat('yyyyMMdd')) : 0;
|
|
307
|
-
const endCalDateInt = endAt ? Number(DateTime.fromJSDate(new Date(endAt)).toFormat('yyyyMMdd')) : 0;
|
|
308
|
-
const calDateInt = typeof calDateInt_ === 'string' ? Number(calDateInt_.replace(/-/g, '')) : calDateInt_;
|
|
309
|
-
|
|
310
|
-
if (calDateInt < startCalDateInt || (endCalDateInt && calDateInt > endCalDateInt)) {
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
switch (frequency) {
|
|
315
|
-
case 'ONCE':
|
|
316
|
-
return calDateInt == startCalDateInt;
|
|
317
|
-
case 'WEEKLY': {
|
|
318
|
-
const hasWeeklyNth = schedule.weeksOfMonth && schedule.weeksOfMonth.length > 0;
|
|
319
|
-
if (hasWeeklyNth) {
|
|
320
|
-
const dt = DateTime.fromFormat(String(calDateInt), 'yyyyMMdd');
|
|
321
|
-
const weekOfMonth = Math.ceil(dt.day / 7);
|
|
322
|
-
if (!schedule.weeksOfMonth?.includes(weekOfMonth)) {
|
|
323
|
-
return false;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// Convert yyyyMMdd to day of week (0-6)
|
|
328
|
-
const dateDay = DateTime.fromFormat(String(calDateInt), 'yyyyMMdd').weekday % 7;
|
|
329
|
-
return !!daysOfWeek?.includes(dateDay as any);
|
|
330
|
-
}
|
|
331
|
-
default:
|
|
332
|
-
if (frequency) {
|
|
333
|
-
console.warn(`isScheduledDate(): ${frequency} frequency is not implemented yet`);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
return false;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Get time from schedule
|
|
342
|
-
* @param schedule - Event schedule object
|
|
343
|
-
* @returns Next date in string format
|
|
344
|
-
*/
|
|
345
|
-
|
|
346
|
-
export function getTimeFromSchedule(
|
|
347
|
-
schedule: ScheduleObj | null,
|
|
348
|
-
date: Date | null,
|
|
349
|
-
endAt: Date | null,
|
|
350
|
-
timeZone: string | null
|
|
351
|
-
) {
|
|
352
|
-
if ((!schedule?.frequency || schedule.frequency === 'ONCE') && date) {
|
|
353
|
-
|
|
354
|
-
const endAtDate = endAt ? new Date(endAt) : null;
|
|
355
|
-
if (endAtDate) {
|
|
356
|
-
|
|
357
|
-
const dayDiff = Math.floor((endAtDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24));
|
|
358
|
-
if (dayDiff > 0) {
|
|
359
|
-
return [
|
|
360
|
-
hhmmFromDateOrTime(null, date, true, timeZone),
|
|
361
|
-
getFullDate(endAtDate, 'DATE_ONLY_SHORT', timeZone)
|
|
362
|
-
];
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
return [
|
|
366
|
-
hhmmFromDateOrTime(null, date, true, timeZone),
|
|
367
|
-
endAtDate > date ? hhmmFromDateOrTime(null, endAtDate, true, timeZone) : null
|
|
368
|
-
];
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return [hhmmFromDateOrTime(null, date, true, timeZone)];
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
const timeSched = schedule?.time;
|
|
375
|
-
if (
|
|
376
|
-
!Array.isArray(timeSched) ||
|
|
377
|
-
!timeSched[0]
|
|
378
|
-
) {
|
|
379
|
-
return [i18n.t('form.not_specified')];
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
const [startTime, endTime] = timeSched;
|
|
383
|
-
return [
|
|
384
|
-
hhmmFromDateOrTime(startTime, null, true, timeZone),
|
|
385
|
-
endTime && hhmmFromDateOrTime(endTime, null, true, timeZone)
|
|
386
|
-
];
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
/**
|
|
390
|
-
* Get all date this event happens between 2 calendar dates
|
|
391
|
-
* @param calEvent
|
|
392
|
-
* @param fromDate
|
|
393
|
-
* @param toDate
|
|
394
|
-
* @returns
|
|
395
|
-
*/
|
|
396
|
-
|
|
397
|
-
export function getAllEventDates(
|
|
398
|
-
calEvent: ProductCalEventData,
|
|
399
|
-
fromDate: string, // "YYYY-MM-DD"
|
|
400
|
-
toDate: string, // "YYYY-MM-DD"
|
|
401
|
-
timeZone: string | null = null,
|
|
402
|
-
): string[] {
|
|
403
|
-
const results: string[] = [];
|
|
404
|
-
|
|
405
|
-
const from = parseBoundaryDateInTimezone(fromDate, timeZone);
|
|
406
|
-
const to = parseBoundaryDateInTimezone(toDate, timeZone, true);
|
|
407
|
-
|
|
408
|
-
const eventStart = new Date(calEvent.startAt);
|
|
409
|
-
const eventEnd = calEvent.endAt ? new Date(calEvent.endAt) : null;
|
|
410
|
-
|
|
411
|
-
const rangeStart = new Date(Math.max(from.getTime(), eventStart.getTime()));
|
|
412
|
-
const rangeEnd = eventEnd
|
|
413
|
-
? new Date(Math.min(to.getTime(), eventEnd.getTime()))
|
|
414
|
-
: to;
|
|
415
|
-
|
|
416
|
-
// @ts-ignore – product events only
|
|
417
|
-
const { frequency, daysOfWeek } = calEvent.metadata?.schedule || {};
|
|
418
|
-
|
|
419
|
-
switch (frequency) {
|
|
420
|
-
case 'ONCE': {
|
|
421
|
-
if (eventStart >= from && eventStart <= to) {
|
|
422
|
-
results.push(formatCalDateInTimeZone(eventStart, timeZone));
|
|
423
|
-
}
|
|
424
|
-
return results;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
case 'WEEKLY': {
|
|
428
|
-
if (!Array.isArray(daysOfWeek) || !daysOfWeek.length) {
|
|
429
|
-
return results;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
const allowedDays = new Set<number>(daysOfWeek);
|
|
433
|
-
const cursor = new Date(rangeStart);
|
|
434
|
-
|
|
435
|
-
while (cursor <= rangeEnd) {
|
|
436
|
-
const dow = getDayOfWeekInTimeZone(cursor, timeZone);
|
|
437
|
-
|
|
438
|
-
if (allowedDays.has(dow)) {
|
|
439
|
-
const dateStr = formatCalDateInTimeZone(cursor, timeZone);
|
|
440
|
-
|
|
441
|
-
// Final safety clamp (prevents Jan 1 bleed)
|
|
442
|
-
if (dateStr >= fromDate && dateStr <= toDate) {
|
|
443
|
-
results.push(dateStr);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// Move forward ONE LOCAL DAY safely
|
|
448
|
-
cursor.setDate(cursor.getDate() + 1);
|
|
449
|
-
}
|
|
450
|
-
break;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
return results;
|
|
455
|
-
}
|
package/src/utils/report.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import type { LogEntryGQL } from '@jsb188/mday/types/log.d.ts';
|
|
2
|
-
import type { ReportFieldsRow, ReportSectionGQL } from '@jsb188/mday/types/report.d.ts';
|
|
3
|
-
import type { StorageGQL } from '@jsb188/mday/types/storage.d.ts';
|
|
4
|
-
import { REPORT_NUMBERED_PRESETS } from '../constants/report.ts';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get report sections file status
|
|
8
|
-
* Returns whether a report has any finished files, if all sections have files, and if all sections are empty
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export interface ReportSectionsFileStatus {
|
|
12
|
-
hasValidFile: boolean;
|
|
13
|
-
isComplete: boolean;
|
|
14
|
-
isEmpty: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface ReportSectionsFilesCount {
|
|
18
|
-
required: number;
|
|
19
|
-
hasFile: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
* Check whether one report row should contribute to automated line numbering.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
export function isReportNumberedRow(row?: Pick<ReportFieldsRow, 'preset' | '__notAutomated'> | null): boolean {
|
|
27
|
-
return !!row && !row.__notAutomated && !!row.preset && REPORT_NUMBERED_PRESETS.includes(row.preset);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/*
|
|
31
|
-
* Build one report line number using the numbered row index and column index.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
export function getReportLineNumber(lineIndex?: number | null, colIndex?: number | null): string | null {
|
|
35
|
-
if (!lineIndex || colIndex == null) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return `${lineIndex}.${colIndex + 1}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/*
|
|
43
|
-
* Build the stable row identifier used by report answers and column fragment keys.
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
export function getReportRowIdentifier(answerKey?: string | null, rowKey?: string | null): string {
|
|
47
|
-
return `${answerKey || '__'}.${rowKey || 'ERROR'}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/*
|
|
51
|
-
* Build the stable column identifier used inside one report row.
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
export function getReportColumnIdentifier(rowIdentifier: string, columnKey: string): string {
|
|
55
|
-
return `${rowIdentifier}.${columnKey}`;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/*
|
|
59
|
-
* Build the realtime fragment data ID for one report submission question column.
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
export function getReportColumnFragmentDataId(
|
|
63
|
-
reportSubmissionIdKey: string | number | bigint,
|
|
64
|
-
rowIdentifier: string,
|
|
65
|
-
columnKey: string,
|
|
66
|
-
): string {
|
|
67
|
-
return `${reportSubmissionIdKey}:${getReportColumnIdentifier(rowIdentifier, columnKey)}`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/*
|
|
71
|
-
* Check whether a report file can render as an image preview.
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
export function isReportReferenceImageFile(file?: StorageGQL | null) {
|
|
75
|
-
return !file?.__deleted
|
|
76
|
-
&& !file?.uploadStatus
|
|
77
|
-
&& !!file?.uri
|
|
78
|
-
&& file.contentType?.startsWith('image/');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/*
|
|
82
|
-
* Resolve the logs and files referenced by one report row.
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
export function getReportReferenceContent(
|
|
86
|
-
logEntriesForReport?: LogEntryGQL[] | null,
|
|
87
|
-
referenceIds?: (string | null | undefined)[] | null,
|
|
88
|
-
) {
|
|
89
|
-
if (!logEntriesForReport?.length || !referenceIds?.length) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const referenceIdSet = new Set(referenceIds.filter((referenceId): referenceId is string => !!referenceId));
|
|
94
|
-
if (!referenceIdSet.size) {
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const logs = logEntriesForReport.filter((log) => referenceIdSet.has(log.id));
|
|
99
|
-
if (!logs.length) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return {
|
|
104
|
-
files: logs.flatMap((log) => log.files || []),
|
|
105
|
-
logs,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function getReportFilesCount(sections?: ReportSectionGQL[]): ReportSectionsFilesCount {
|
|
110
|
-
return (sections || []).reduce((acc, section) => {
|
|
111
|
-
if (section.requireFileUploads) {
|
|
112
|
-
acc.required++;
|
|
113
|
-
if (section.files?.filter((file) => !file.__deleted)?.length) {
|
|
114
|
-
acc.hasFile++;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return acc;
|
|
118
|
-
}, {
|
|
119
|
-
required: 0,
|
|
120
|
-
hasFile: 0,
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function getReportFileStatus(sections: ReportSectionGQL[] | undefined): ReportSectionsFileStatus {
|
|
125
|
-
let hasValidFile = false;
|
|
126
|
-
let totalRequiring = 0;
|
|
127
|
-
let totalWithFile = 0;
|
|
128
|
-
|
|
129
|
-
for (const section of sections || []) {
|
|
130
|
-
if (!section.requireFileUploads) continue;
|
|
131
|
-
|
|
132
|
-
totalRequiring++;
|
|
133
|
-
|
|
134
|
-
let hasNonDeleted = false;
|
|
135
|
-
let hasCompleted = false;
|
|
136
|
-
|
|
137
|
-
if (section.files) {
|
|
138
|
-
for (const file of section.files) {
|
|
139
|
-
if (!file.__deleted) {
|
|
140
|
-
hasNonDeleted = true;
|
|
141
|
-
if (!file.uploadStatus) {
|
|
142
|
-
hasCompleted = true;
|
|
143
|
-
break; // Found completed file, no need to check more
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (hasNonDeleted) totalWithFile++;
|
|
150
|
-
if (!hasCompleted) hasValidFile = true;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
hasValidFile,
|
|
155
|
-
isComplete: totalRequiring > 0 && totalWithFile === totalRequiring,
|
|
156
|
-
isEmpty: totalWithFile === 0,
|
|
157
|
-
};
|
|
158
|
-
}
|