incyclist-services 1.7.76 → 1.7.77

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 (64) hide show
  1. package/lib/cjs/activities/list/service.js +1 -1
  2. package/lib/cjs/activities/ride/service.js +2 -1
  3. package/lib/cjs/workouts/base/graph/index.js +18 -0
  4. package/lib/cjs/workouts/base/graph/series.js +162 -0
  5. package/lib/cjs/workouts/base/graph/types.js +2 -0
  6. package/lib/cjs/workouts/base/model/index.js +0 -1
  7. package/lib/cjs/workouts/calendar/service.js +14 -0
  8. package/lib/cjs/workouts/index.js +2 -0
  9. package/lib/cjs/workouts/list/cards/index.js +0 -1
  10. package/lib/cjs/workouts/list/index.js +0 -1
  11. package/lib/cjs/workouts/list/pageService.js +362 -5
  12. package/lib/cjs/workouts/list/service.js +39 -12
  13. package/lib/cjs/workouts/page/index.js +17 -0
  14. package/lib/cjs/workouts/page/service.js +455 -0
  15. package/lib/cjs/workouts/page/types.js +2 -0
  16. package/lib/cjs/workouts/ride/index.js +1 -0
  17. package/lib/cjs/workouts/ride/page/index.js +18 -0
  18. package/lib/cjs/workouts/ride/page/service.js +500 -0
  19. package/lib/cjs/workouts/ride/page/types.js +2 -0
  20. package/lib/cjs/workouts/types.js +2 -0
  21. package/lib/esm/activities/list/service.js +1 -1
  22. package/lib/esm/activities/ride/service.js +2 -1
  23. package/lib/esm/workouts/base/graph/index.js +2 -0
  24. package/lib/esm/workouts/base/graph/series.js +156 -0
  25. package/lib/esm/workouts/base/graph/types.js +1 -0
  26. package/lib/esm/workouts/base/model/index.js +0 -1
  27. package/lib/esm/workouts/calendar/service.js +14 -0
  28. package/lib/esm/workouts/index.js +2 -0
  29. package/lib/esm/workouts/list/cards/index.js +0 -1
  30. package/lib/esm/workouts/list/index.js +0 -1
  31. package/lib/esm/workouts/list/pageService.js +362 -5
  32. package/lib/esm/workouts/list/service.js +39 -12
  33. package/lib/esm/workouts/page/index.js +1 -0
  34. package/lib/esm/workouts/page/service.js +451 -0
  35. package/lib/esm/workouts/page/types.js +1 -0
  36. package/lib/esm/workouts/ride/index.js +1 -0
  37. package/lib/esm/workouts/ride/page/index.js +2 -0
  38. package/lib/esm/workouts/ride/page/service.js +496 -0
  39. package/lib/esm/workouts/ride/page/types.js +1 -0
  40. package/lib/esm/workouts/types.js +1 -0
  41. package/lib/types/types.d.ts +1 -0
  42. package/lib/types/workouts/base/graph/index.d.ts +2 -0
  43. package/lib/types/workouts/base/graph/series.d.ts +7 -0
  44. package/lib/types/workouts/base/graph/types.d.ts +11 -0
  45. package/lib/types/workouts/base/model/index.d.ts +0 -1
  46. package/lib/types/workouts/base/parsers/intervals/parser.d.ts +2 -1
  47. package/lib/types/workouts/calendar/service.d.ts +1 -0
  48. package/lib/types/workouts/index.d.ts +2 -0
  49. package/lib/types/workouts/list/cards/index.d.ts +0 -1
  50. package/lib/types/workouts/list/index.d.ts +0 -1
  51. package/lib/types/workouts/list/pageService.d.ts +136 -4
  52. package/lib/types/workouts/list/service.d.ts +4 -0
  53. package/lib/types/workouts/list/types.d.ts +1 -1
  54. package/lib/types/workouts/page/index.d.ts +1 -0
  55. package/lib/types/workouts/page/service.d.ts +57 -0
  56. package/lib/types/workouts/page/types.d.ts +95 -0
  57. package/lib/types/workouts/ride/index.d.ts +1 -0
  58. package/lib/types/workouts/ride/page/index.d.ts +2 -0
  59. package/lib/types/workouts/ride/page/service.d.ts +71 -0
  60. package/lib/types/workouts/ride/page/types.d.ts +72 -0
  61. package/lib/types/workouts/ride/service.d.ts +2 -1
  62. package/lib/types/workouts/ride/types.d.ts +1 -0
  63. package/lib/types/workouts/types.d.ts +8 -0
  64. package/package.json +1 -1
@@ -35,6 +35,7 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
35
35
  };
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.getWorkoutList = exports.useWorkoutList = exports.WorkoutListService = void 0;
38
+ const api_1 = require("../../api");
38
39
  const cardlist_1 = require("../../base/cardlist");
39
40
  const service_1 = require("../../base/service");
40
41
  const types_1 = require("../../base/types");
@@ -60,14 +61,17 @@ let WorkoutListService = (() => {
60
61
  let _instanceExtraInitializers = [];
61
62
  let _getWorkoutCalendar_decorators;
62
63
  let _getAppState_decorators;
64
+ let _getBindings_decorators;
63
65
  var WorkoutListService = class extends _classSuper {
64
66
  static { _classThis = this; }
65
67
  static {
66
68
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
67
69
  _getWorkoutCalendar_decorators = [decorators_1.Injectable];
68
70
  _getAppState_decorators = [decorators_1.Injectable];
71
+ _getBindings_decorators = [decorators_1.Injectable];
69
72
  __esDecorate(this, null, _getWorkoutCalendar_decorators, { kind: "method", name: "getWorkoutCalendar", static: false, private: false, access: { has: obj => "getWorkoutCalendar" in obj, get: obj => obj.getWorkoutCalendar }, metadata: _metadata }, null, _instanceExtraInitializers);
70
73
  __esDecorate(this, null, _getAppState_decorators, { kind: "method", name: "getAppState", static: false, private: false, access: { has: obj => "getAppState" in obj, get: obj => obj.getAppState }, metadata: _metadata }, null, _instanceExtraInitializers);
74
+ __esDecorate(this, null, _getBindings_decorators, { kind: "method", name: "getBindings", static: false, private: false, access: { has: obj => "getBindings" in obj, get: obj => obj.getBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
71
75
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
72
76
  WorkoutListService = _classThis = _classDescriptor.value;
73
77
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -84,6 +88,7 @@ let WorkoutListService = (() => {
84
88
  language;
85
89
  selectedWorkout;
86
90
  ftp;
91
+ useErgModeOverride;
87
92
  scheduledToday;
88
93
  scheduledList;
89
94
  selectedCard;
@@ -170,7 +175,8 @@ let WorkoutListService = (() => {
170
175
  let useErgMode = true;
171
176
  try {
172
177
  const userSettings = this.getUserSettings();
173
- useErgMode = userSettings.get('preferences.useErgMode', true);
178
+ const globalErgMode = userSettings.get('preferences.useErgMode', true);
179
+ useErgMode = this.useErgModeOverride ?? globalErgMode;
174
180
  const user = userSettings.get('user', undefined);
175
181
  ftp = this.ftp ?? user?.ftp ?? 200;
176
182
  }
@@ -181,8 +187,7 @@ let WorkoutListService = (() => {
181
187
  }
182
188
  setStartSettings(settings) {
183
189
  try {
184
- const userSettings = this.getUserSettings();
185
- userSettings.set('preferences.useErgMode', settings?.useErgMode);
190
+ this.useErgModeOverride = settings?.useErgMode;
186
191
  this.ftp = settings?.ftp;
187
192
  }
188
193
  catch (err) {
@@ -237,7 +242,9 @@ let WorkoutListService = (() => {
237
242
  this.getWorkoutCalendar().once('scheduled', (event) => {
238
243
  this.scheduledToday = event;
239
244
  this.getAppState().setState('scheduledToday', event.workout.id);
240
- this.getAppState().setPersistedState('page', 'workouts');
245
+ if (!this.isMobile()) {
246
+ this.getAppState().setPersistedState('page', 'workouts');
247
+ }
241
248
  });
242
249
  this.getWorkoutCalendar().init();
243
250
  this.preloadObserver.start()
@@ -339,13 +346,15 @@ let WorkoutListService = (() => {
339
346
  getScheduledWorkouts(scheduled) {
340
347
  const schedList = new cardlist_1.CardList('scheduled', 'Scheduled Workouts');
341
348
  scheduled.forEach(w => schedList.add(new ScheduledWorkoutCard_1.ScheduledWorkoutCard(w)));
342
- const today = this.getAppState().getState('scheduledToday');
343
- if (today) {
344
- schedList.getCards().forEach(c => {
345
- if (c.getId() === today) {
346
- c.select();
347
- }
348
- });
349
+ if (!this.isMobile()) {
350
+ const today = this.getAppState().getState('scheduledToday');
351
+ if (today) {
352
+ schedList.getCards().forEach(c => {
353
+ if (c.getId() === today) {
354
+ c.select();
355
+ }
356
+ });
357
+ }
349
358
  }
350
359
  const newList = (this.scheduledList === undefined || this.scheduledList === null);
351
360
  if (newList) {
@@ -430,7 +439,7 @@ let WorkoutListService = (() => {
430
439
  if (typeof target === 'string') {
431
440
  targetList = this.lists.find(l => l.getTitle() === target);
432
441
  if (!targetList)
433
- return;
442
+ targetList = this.addList(target);
434
443
  }
435
444
  else {
436
445
  targetList = target;
@@ -444,6 +453,18 @@ let WorkoutListService = (() => {
444
453
  this.logError(err, 'moveCard');
445
454
  }
446
455
  }
456
+ deleteWorkout(id) {
457
+ try {
458
+ const { card } = this.findCard(id) ?? {};
459
+ if (!card)
460
+ return observer_1.PromiseObserver.alwaysReturning(false);
461
+ return card.delete();
462
+ }
463
+ catch (err) {
464
+ this.logError(err, 'deleteWorkout');
465
+ return observer_1.PromiseObserver.alwaysReturning(false);
466
+ }
467
+ }
447
468
  canDisplayStart() {
448
469
  const routes = this.getRouteList();
449
470
  return (0, valid_1.valid)(routes.getSelected());
@@ -648,6 +669,12 @@ let WorkoutListService = (() => {
648
669
  getAppState() {
649
670
  return (0, appstate_1.useAppState)();
650
671
  }
672
+ isMobile() {
673
+ return this.getBindings()?.appInfo?.getChannel() === 'mobile';
674
+ }
675
+ getBindings() {
676
+ return (0, api_1.getBindings)();
677
+ }
651
678
  getRepo() {
652
679
  if (!this.db)
653
680
  this.db = new db_1.WorkoutsDbLoader();
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./service"), exports);
@@ -0,0 +1,455 @@
1
+ "use strict";
2
+ var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
3
+ var useValue = arguments.length > 2;
4
+ for (var i = 0; i < initializers.length; i++) {
5
+ value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
6
+ }
7
+ return useValue ? value : void 0;
8
+ };
9
+ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
10
+ function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
11
+ var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
12
+ var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
13
+ var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
14
+ var _, done = false;
15
+ for (var i = decorators.length - 1; i >= 0; i--) {
16
+ var context = {};
17
+ for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
18
+ for (var p in contextIn.access) context.access[p] = contextIn.access[p];
19
+ context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
20
+ var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
21
+ if (kind === "accessor") {
22
+ if (result === void 0) continue;
23
+ if (result === null || typeof result !== "object") throw new TypeError("Object expected");
24
+ if (_ = accept(result.get)) descriptor.get = _;
25
+ if (_ = accept(result.set)) descriptor.set = _;
26
+ if (_ = accept(result.init)) initializers.unshift(_);
27
+ }
28
+ else if (_ = accept(result)) {
29
+ if (kind === "field") initializers.unshift(_);
30
+ else descriptor[key] = _;
31
+ }
32
+ }
33
+ if (target) Object.defineProperty(target, contextIn.name, descriptor);
34
+ done = true;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.getWorkoutListPageService = exports.WorkoutListPageService = void 0;
38
+ const types_1 = require("../../base/types");
39
+ const pages_1 = require("../../base/pages");
40
+ const decorators_1 = require("../../base/decorators");
41
+ const appstate_1 = require("../../appstate");
42
+ const observer_1 = require("../../base/types/observer");
43
+ const settings_1 = require("../../settings");
44
+ const calendar_1 = require("../calendar");
45
+ const service_1 = require("../list/service");
46
+ const DEFAULT_IMPORT_GROUP = 'My Workouts';
47
+ const UPCOMING_COLLAPSED_COUNT = 3;
48
+ let WorkoutListPageService = (() => {
49
+ let _classDecorators = [types_1.Singleton];
50
+ let _classDescriptor;
51
+ let _classExtraInitializers = [];
52
+ let _classThis;
53
+ let _classSuper = pages_1.IncyclistPageService;
54
+ let _instanceExtraInitializers = [];
55
+ let _getWorkoutList_decorators;
56
+ let _getWorkoutCalendar_decorators;
57
+ let _getUserSettings_decorators;
58
+ let _getAppState_decorators;
59
+ var WorkoutListPageService = class extends _classSuper {
60
+ static { _classThis = this; }
61
+ static {
62
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
63
+ _getWorkoutList_decorators = [decorators_1.Injectable];
64
+ _getWorkoutCalendar_decorators = [decorators_1.Injectable];
65
+ _getUserSettings_decorators = [decorators_1.Injectable];
66
+ _getAppState_decorators = [decorators_1.Injectable];
67
+ __esDecorate(this, null, _getWorkoutList_decorators, { kind: "method", name: "getWorkoutList", static: false, private: false, access: { has: obj => "getWorkoutList" in obj, get: obj => obj.getWorkoutList }, metadata: _metadata }, null, _instanceExtraInitializers);
68
+ __esDecorate(this, null, _getWorkoutCalendar_decorators, { kind: "method", name: "getWorkoutCalendar", static: false, private: false, access: { has: obj => "getWorkoutCalendar" in obj, get: obj => obj.getWorkoutCalendar }, metadata: _metadata }, null, _instanceExtraInitializers);
69
+ __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
70
+ __esDecorate(this, null, _getAppState_decorators, { kind: "method", name: "getAppState", static: false, private: false, access: { has: obj => "getAppState" in obj, get: obj => obj.getAppState }, metadata: _metadata }, null, _instanceExtraInitializers);
71
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
72
+ WorkoutListPageService = _classThis = _classDescriptor.value;
73
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
74
+ __runInitializers(_classThis, _classExtraInitializers);
75
+ }
76
+ groupFilter = (__runInitializers(this, _instanceExtraInitializers), null);
77
+ importPhase;
78
+ importGroup;
79
+ importingFileName;
80
+ importResult;
81
+ importError;
82
+ listObserver;
83
+ listUpdateHandler = this.emitPageUpdate.bind(this);
84
+ calendarUpdateHandler = this.emitPageUpdate.bind(this);
85
+ constructor() {
86
+ super('WorkoutListPage');
87
+ }
88
+ openPage() {
89
+ try {
90
+ super.openPage();
91
+ this.logEvent({ message: 'page shown', page: 'Workouts' });
92
+ const { observer } = this.getWorkoutList().open();
93
+ this.listObserver = observer;
94
+ this.listObserver?.on('started', this.listUpdateHandler);
95
+ this.listObserver?.on('loading', this.listUpdateHandler);
96
+ this.listObserver?.on('loaded', this.listUpdateHandler);
97
+ this.listObserver?.on('updated', this.listUpdateHandler);
98
+ this.getWorkoutCalendar().on('updated', this.calendarUpdateHandler);
99
+ this.emitPageUpdate();
100
+ }
101
+ catch (err) {
102
+ this.logError(err, 'openPage');
103
+ }
104
+ return this.getPageObserver();
105
+ }
106
+ closePage() {
107
+ try {
108
+ this.getWorkoutList().close();
109
+ this.listObserver?.off('started', this.listUpdateHandler);
110
+ this.listObserver?.off('loading', this.listUpdateHandler);
111
+ this.listObserver?.off('loaded', this.listUpdateHandler);
112
+ this.listObserver?.off('updated', this.listUpdateHandler);
113
+ this.getWorkoutCalendar().off('updated', this.calendarUpdateHandler);
114
+ delete this.listObserver;
115
+ this.logEvent({ message: 'page closed', page: 'Workouts' });
116
+ super.closePage();
117
+ }
118
+ catch (err) {
119
+ this.logError(err, 'closePage');
120
+ }
121
+ }
122
+ getPageDisplayProps() {
123
+ try {
124
+ if (!this.getAppState().hasFeature('MOBILE_WORKOUTS')) {
125
+ return { pageType: 'placeholder' };
126
+ }
127
+ const service = this.getWorkoutList();
128
+ const loading = service.isStillLoading();
129
+ const upcoming = this.getUpcomingTrainingProps();
130
+ const allWorkouts = this.getAllWorkoutItems();
131
+ const groups = this.getGroupFilterProps();
132
+ const workouts = groups.selected ? allWorkouts.filter(w => w.group === groups.selected) : allWorkouts;
133
+ const selectedId = service.getSelected()?.id ?? null;
134
+ const isEmpty = allWorkouts.length === 0;
135
+ return { pageType: 'list', loading, upcoming, groups, workouts, selectedId, isEmpty };
136
+ }
137
+ catch (err) {
138
+ this.logError(err, 'getPageDisplayProps');
139
+ return {};
140
+ }
141
+ }
142
+ getWorkoutDetailsProps(id) {
143
+ try {
144
+ const card = this.findWorkoutCard(id);
145
+ if (!card)
146
+ return null;
147
+ const workout = card.getData();
148
+ const settingsProps = card.openSettings();
149
+ const isScheduled = card.getCardType() === 'ScheduledWorkout';
150
+ return {
151
+ id,
152
+ title: card.getTitle(),
153
+ description: workout?.description,
154
+ duration: settingsProps.duration,
155
+ workout,
156
+ ftp: settingsProps.settings?.ftp,
157
+ ftpRequired: settingsProps.ftpRequired,
158
+ useErgMode: settingsProps.settings?.useErgMode,
159
+ canStart: settingsProps.canStart,
160
+ canStartWorkoutOnly: settingsProps.canStartWorkoutOnly,
161
+ groups: settingsProps.categories,
162
+ group: settingsProps.category,
163
+ canDelete: card.canDelete(),
164
+ isScheduled,
165
+ date: isScheduled ? settingsProps.date : undefined
166
+ };
167
+ }
168
+ catch (err) {
169
+ this.logError(err, 'getWorkoutDetailsProps');
170
+ return null;
171
+ }
172
+ }
173
+ getImportDisplayProps() {
174
+ try {
175
+ const phase = this.importPhase ?? 'landing';
176
+ const knownGroups = this.getKnownGroups();
177
+ const group = this.importGroup ?? this.getLastUsedImportGroup();
178
+ const props = { phase, group, knownGroups };
179
+ if (phase === 'importing')
180
+ props.importing = { fileName: this.importingFileName };
181
+ if (phase === 'result')
182
+ props.result = this.importResult;
183
+ if (phase === 'error')
184
+ props.error = this.importError;
185
+ return props;
186
+ }
187
+ catch (err) {
188
+ this.logError(err, 'getImportDisplayProps');
189
+ return { phase: 'landing', group: DEFAULT_IMPORT_GROUP, knownGroups: [] };
190
+ }
191
+ }
192
+ onSelectGroup(group) {
193
+ try {
194
+ this.groupFilter = group;
195
+ this.emitPageUpdate();
196
+ }
197
+ catch (err) {
198
+ this.logError(err, 'onSelectGroup');
199
+ }
200
+ }
201
+ onOpenDetails(id) {
202
+ this.logEvent({ message: 'details opened', id });
203
+ }
204
+ onCloseDetails() {
205
+ this.logEvent({ message: 'details closed' });
206
+ }
207
+ onSetFtp(ftp) {
208
+ try {
209
+ const current = this.getWorkoutList().getStartSettings();
210
+ this.getWorkoutList().setStartSettings({ ...current, ftp });
211
+ this.emitPageUpdate();
212
+ }
213
+ catch (err) {
214
+ this.logError(err, 'onSetFtp');
215
+ }
216
+ }
217
+ onSetErgMode(enabled) {
218
+ try {
219
+ const current = this.getWorkoutList().getStartSettings();
220
+ this.getWorkoutList().setStartSettings({ ...current, useErgMode: enabled });
221
+ this.emitPageUpdate();
222
+ }
223
+ catch (err) {
224
+ this.logError(err, 'onSetErgMode');
225
+ }
226
+ }
227
+ onChangeGroup(id, group) {
228
+ try {
229
+ const card = this.findWorkoutCard(id);
230
+ card?.move(group);
231
+ this.emitPageUpdate();
232
+ }
233
+ catch (err) {
234
+ this.logError(err, 'onChangeGroup');
235
+ }
236
+ }
237
+ async onDelete(id) {
238
+ try {
239
+ const observer = this.getWorkoutList().deleteWorkout(id);
240
+ const deleted = await observer.wait();
241
+ this.emitPageUpdate();
242
+ return !!deleted;
243
+ }
244
+ catch (err) {
245
+ this.logError(err, 'onDelete');
246
+ return false;
247
+ }
248
+ }
249
+ onStart(id, opts) {
250
+ try {
251
+ const card = this.findWorkoutCard(id);
252
+ if (!card)
253
+ return;
254
+ const settings = this.getWorkoutList().getStartSettings();
255
+ card.select({ ...settings, noRoute: opts?.noRoute });
256
+ this.getPageObserver()?.emit('start-ride', { id, noRoute: opts?.noRoute });
257
+ }
258
+ catch (err) {
259
+ this.logError(err, 'onStart');
260
+ }
261
+ }
262
+ onMarkForRoute(id) {
263
+ try {
264
+ const card = this.findWorkoutCard(id);
265
+ if (!card)
266
+ return;
267
+ const settings = this.getWorkoutList().getStartSettings();
268
+ card.select({ ...settings, noRoute: false });
269
+ this.emitPageUpdate();
270
+ }
271
+ catch (err) {
272
+ this.logError(err, 'onMarkForRoute');
273
+ }
274
+ }
275
+ onClearSelection() {
276
+ try {
277
+ this.getWorkoutList().unselect();
278
+ this.emitPageUpdate();
279
+ }
280
+ catch (err) {
281
+ this.logError(err, 'onClearSelection');
282
+ }
283
+ }
284
+ onImportOpen() {
285
+ try {
286
+ this.importPhase = 'landing';
287
+ this.importGroup = this.getLastUsedImportGroup();
288
+ delete this.importError;
289
+ delete this.importResult;
290
+ this.emitImportUpdate();
291
+ }
292
+ catch (err) {
293
+ this.logError(err, 'onImportOpen');
294
+ }
295
+ }
296
+ onImportGroupChange(name) {
297
+ try {
298
+ this.importGroup = name;
299
+ this.emitImportUpdate();
300
+ }
301
+ catch (err) {
302
+ this.logError(err, 'onImportGroupChange');
303
+ }
304
+ }
305
+ onImportFile(file) {
306
+ const observer = new observer_1.Observer();
307
+ try {
308
+ const group = this.importGroup;
309
+ this.importPhase = 'importing';
310
+ this.importingFileName = file?.name;
311
+ this.emitImportUpdate();
312
+ this.getWorkoutList().import(file, { showImportCards: false })
313
+ .then(([card]) => {
314
+ if (group && group !== DEFAULT_IMPORT_GROUP)
315
+ card.move(group);
316
+ this.persistLastUsedImportGroup(group);
317
+ this.importPhase = 'result';
318
+ this.importResult = { workoutName: card.getTitle(), group };
319
+ observer.emit('success');
320
+ this.emitImportUpdate();
321
+ })
322
+ .catch((err) => {
323
+ this.importPhase = 'error';
324
+ this.importError = err?.message;
325
+ observer.emit('error', err);
326
+ this.emitImportUpdate();
327
+ });
328
+ }
329
+ catch (err) {
330
+ this.logError(err, 'onImportFile');
331
+ }
332
+ return observer;
333
+ }
334
+ onImportClose() {
335
+ try {
336
+ delete this.importPhase;
337
+ delete this.importingFileName;
338
+ delete this.importResult;
339
+ delete this.importError;
340
+ this.emitImportUpdate();
341
+ }
342
+ catch (err) {
343
+ this.logError(err, 'onImportClose');
344
+ }
345
+ }
346
+ getUpcomingTrainingProps() {
347
+ const calendar = this.getWorkoutCalendar();
348
+ const scheduled = calendar.getScheduledWorkouts();
349
+ if (!scheduled || scheduled.length === 0)
350
+ return null;
351
+ const todayId = calendar.getScheduledToday()?.id ?? null;
352
+ const selectedWorkout = this.getWorkoutList().getSelected();
353
+ const items = scheduled.map(w => ({
354
+ id: w.id,
355
+ title: w.workout?.name,
356
+ date: w.day,
357
+ duration: this.formatDuration(w.workout?.duration),
358
+ isToday: todayId !== null && w.id === todayId,
359
+ selected: selectedWorkout?.id !== undefined && selectedWorkout.id === w.workout?.id,
360
+ workout: w.workout
361
+ }));
362
+ return { items, collapsedCount: UPCOMING_COLLAPSED_COUNT, todayId };
363
+ }
364
+ getGroupFilterProps() {
365
+ const available = this.getKnownGroups();
366
+ return { available, selected: this.groupFilter };
367
+ }
368
+ getKnownGroups() {
369
+ const lists = this.getWorkoutList().getLists(false) ?? [];
370
+ return lists.filter(l => l.getId() !== 'scheduled').map(l => l.getTitle());
371
+ }
372
+ getAllWorkoutItems() {
373
+ const lists = this.getWorkoutList().getLists(false) ?? [];
374
+ const items = [];
375
+ lists.forEach(list => {
376
+ if (list.getId() === 'scheduled')
377
+ return;
378
+ list.getCards().forEach(card => {
379
+ if (card.getCardType() !== 'Workout')
380
+ return;
381
+ const workoutCard = card;
382
+ const props = workoutCard.getDisplayProperties();
383
+ items.push({
384
+ id: workoutCard.getId(),
385
+ title: props.title,
386
+ group: list.getTitle(),
387
+ duration: props.duration,
388
+ selected: props.selected,
389
+ canDelete: props.canDelete,
390
+ workout: props.workout
391
+ });
392
+ });
393
+ });
394
+ return items;
395
+ }
396
+ findWorkoutCard(id) {
397
+ const lists = this.getWorkoutList().getLists(false) ?? [];
398
+ for (const list of lists) {
399
+ const card = list.getCards().find(c => c.getId() === id);
400
+ if (card)
401
+ return card;
402
+ }
403
+ return undefined;
404
+ }
405
+ getLastUsedImportGroup() {
406
+ return this.getUserSettings().get('preferences.workouts.lastImportGroup', DEFAULT_IMPORT_GROUP);
407
+ }
408
+ persistLastUsedImportGroup(group) {
409
+ try {
410
+ this.getUserSettings().set('preferences.workouts.lastImportGroup', group);
411
+ }
412
+ catch (err) {
413
+ this.logError(err, 'persistLastUsedImportGroup');
414
+ }
415
+ }
416
+ formatDuration(duration) {
417
+ if (duration === undefined || duration === null)
418
+ return '';
419
+ if (duration < 120)
420
+ return `${duration.toFixed(0)}s`;
421
+ if (duration % 60 === 0)
422
+ return `${duration / 60}min`;
423
+ const secVal = duration % 60;
424
+ const minVal = (duration - secVal) / 60 % 60;
425
+ const h = Math.floor((duration - secVal - minVal * 60) / 3600);
426
+ const sec = secVal < 10 ? `0${secVal}` : secVal;
427
+ const min = minVal < 10 ? `0${minVal}` : minVal;
428
+ if (h > 0)
429
+ return `${h}:${min}:${sec}`;
430
+ return `${min}:${sec}`;
431
+ }
432
+ emitPageUpdate() {
433
+ this.getPageObserver()?.emit('page-update');
434
+ }
435
+ emitImportUpdate() {
436
+ this.getPageObserver()?.emit('import-update');
437
+ }
438
+ getWorkoutList() {
439
+ return (0, service_1.useWorkoutList)();
440
+ }
441
+ getWorkoutCalendar() {
442
+ return (0, calendar_1.useWorkoutCalendar)();
443
+ }
444
+ getUserSettings() {
445
+ return (0, settings_1.useUserSettings)();
446
+ }
447
+ getAppState() {
448
+ return (0, appstate_1.useAppState)();
449
+ }
450
+ };
451
+ return WorkoutListPageService = _classThis;
452
+ })();
453
+ exports.WorkoutListPageService = WorkoutListPageService;
454
+ const getWorkoutListPageService = () => new WorkoutListPageService();
455
+ exports.getWorkoutListPageService = getWorkoutListPageService;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./service"), exports);
18
18
  __exportStar(require("./types"), exports);
19
+ __exportStar(require("./page"), exports);
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./service"), exports);
18
+ __exportStar(require("./types"), exports);