incyclist-services 1.7.79 → 1.7.81
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/lib/cjs/workouts/base/model/Workout.js +12 -2
- package/lib/cjs/workouts/list/service.js +5 -5
- package/lib/cjs/workouts/page/service.js +25 -20
- package/lib/esm/workouts/base/model/Workout.js +12 -2
- package/lib/esm/workouts/list/service.js +5 -5
- package/lib/esm/workouts/page/service.js +25 -20
- package/lib/types/workouts/base/model/Workout.d.ts +2 -0
- package/lib/types/workouts/page/service.d.ts +2 -2
- package/lib/types/workouts/page/types.d.ts +2 -2
- package/package.json +1 -1
|
@@ -11,11 +11,12 @@ class Workout extends Segment_1.Segment {
|
|
|
11
11
|
name;
|
|
12
12
|
description;
|
|
13
13
|
category;
|
|
14
|
+
explicitId;
|
|
14
15
|
constructor(opts) {
|
|
15
16
|
super(opts, true);
|
|
16
17
|
this.name = opts.name || '';
|
|
17
18
|
this._hash = opts.hash;
|
|
18
|
-
this.
|
|
19
|
+
this.explicitId = !!(opts.id || opts.hash);
|
|
19
20
|
this.description = opts.description || undefined;
|
|
20
21
|
this.repeat = 1;
|
|
21
22
|
this.type = 'workout';
|
|
@@ -32,6 +33,7 @@ class Workout extends Segment_1.Segment {
|
|
|
32
33
|
catch {
|
|
33
34
|
}
|
|
34
35
|
});
|
|
36
|
+
this.id = opts.id || this.hash;
|
|
35
37
|
}
|
|
36
38
|
get hash() {
|
|
37
39
|
if (this._hash)
|
|
@@ -41,6 +43,12 @@ class Workout extends Segment_1.Segment {
|
|
|
41
43
|
this._hash = crypto.createHash('md5').update(JSON.stringify({ name, description, steps, repeat })).digest('hex');
|
|
42
44
|
return this._hash;
|
|
43
45
|
}
|
|
46
|
+
refreshHash() {
|
|
47
|
+
if (this.explicitId)
|
|
48
|
+
return;
|
|
49
|
+
this._hash = undefined;
|
|
50
|
+
this.id = this.hash;
|
|
51
|
+
}
|
|
44
52
|
getSegment(time) {
|
|
45
53
|
const s = this.steps.find(s => s.getStart() <= time && s.getEnd() > time);
|
|
46
54
|
if (s?.type === 'segment')
|
|
@@ -57,6 +65,7 @@ class Workout extends Segment_1.Segment {
|
|
|
57
65
|
const s = new Step_1.Step(step);
|
|
58
66
|
this.push(s);
|
|
59
67
|
}
|
|
68
|
+
this.refreshHash();
|
|
60
69
|
}
|
|
61
70
|
}
|
|
62
71
|
addSegment(segment) {
|
|
@@ -68,6 +77,7 @@ class Workout extends Segment_1.Segment {
|
|
|
68
77
|
const s = new Segment_1.Segment(segment);
|
|
69
78
|
this.push(s);
|
|
70
79
|
}
|
|
80
|
+
this.refreshHash();
|
|
71
81
|
}
|
|
72
82
|
}
|
|
73
83
|
}
|
|
@@ -84,10 +94,10 @@ class Plan {
|
|
|
84
94
|
this.type = 'plan';
|
|
85
95
|
const { id, name, description, workouts, hash } = plan;
|
|
86
96
|
this._hash = hash;
|
|
87
|
-
this.id = id || this.hash;
|
|
88
97
|
this.name = name;
|
|
89
98
|
this.description = description;
|
|
90
99
|
this.workouts = workouts;
|
|
100
|
+
this.id = id || this.hash;
|
|
91
101
|
}
|
|
92
102
|
get hash() {
|
|
93
103
|
if (this._hash)
|
|
@@ -575,7 +575,7 @@ let WorkoutListService = (() => {
|
|
|
575
575
|
return;
|
|
576
576
|
const card = list.getCards().find(c => c.getData()?.id === id);
|
|
577
577
|
if (card)
|
|
578
|
-
res = { card, list
|
|
578
|
+
res = { card, list };
|
|
579
579
|
});
|
|
580
580
|
return res;
|
|
581
581
|
}
|
|
@@ -596,11 +596,11 @@ let WorkoutListService = (() => {
|
|
|
596
596
|
const workout = await this.parse(info);
|
|
597
597
|
const existing = this.findCard(workout);
|
|
598
598
|
if (existing) {
|
|
599
|
-
existing.
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
this.items.push(workout);
|
|
599
|
+
const card = existing.card;
|
|
600
|
+
card.update(workout);
|
|
601
|
+
return card;
|
|
603
602
|
}
|
|
603
|
+
this.items.push(workout);
|
|
604
604
|
const card = new WorkoutCard_1.WorkoutCard(workout, { list: this.myWorkouts });
|
|
605
605
|
card.save();
|
|
606
606
|
card.enableDelete(true);
|
|
@@ -76,7 +76,6 @@ let WorkoutListPageService = (() => {
|
|
|
76
76
|
groupFilter = (__runInitializers(this, _instanceExtraInitializers), null);
|
|
77
77
|
detailWorkoutId = null;
|
|
78
78
|
importPhase;
|
|
79
|
-
importGroup;
|
|
80
79
|
importingFileName;
|
|
81
80
|
importResult;
|
|
82
81
|
importError;
|
|
@@ -175,8 +174,7 @@ let WorkoutListPageService = (() => {
|
|
|
175
174
|
try {
|
|
176
175
|
const phase = this.importPhase ?? 'landing';
|
|
177
176
|
const knownGroups = this.getKnownGroups();
|
|
178
|
-
const
|
|
179
|
-
const props = { phase, group, knownGroups };
|
|
177
|
+
const props = { phase, knownGroups };
|
|
180
178
|
if (phase === 'importing')
|
|
181
179
|
props.importing = { fileName: this.importingFileName };
|
|
182
180
|
if (phase === 'result')
|
|
@@ -187,7 +185,7 @@ let WorkoutListPageService = (() => {
|
|
|
187
185
|
}
|
|
188
186
|
catch (err) {
|
|
189
187
|
this.logError(err, 'getImportDisplayProps');
|
|
190
|
-
return { phase: 'landing',
|
|
188
|
+
return { phase: 'landing', knownGroups: [] };
|
|
191
189
|
}
|
|
192
190
|
}
|
|
193
191
|
onSelectGroup(group) {
|
|
@@ -299,7 +297,6 @@ let WorkoutListPageService = (() => {
|
|
|
299
297
|
onImportOpen() {
|
|
300
298
|
try {
|
|
301
299
|
this.importPhase = 'landing';
|
|
302
|
-
this.importGroup = this.getLastUsedImportGroup();
|
|
303
300
|
delete this.importError;
|
|
304
301
|
delete this.importResult;
|
|
305
302
|
this.emitImportUpdate();
|
|
@@ -308,29 +305,19 @@ let WorkoutListPageService = (() => {
|
|
|
308
305
|
this.logError(err, 'onImportOpen');
|
|
309
306
|
}
|
|
310
307
|
}
|
|
311
|
-
onImportGroupChange(name) {
|
|
312
|
-
try {
|
|
313
|
-
this.importGroup = name;
|
|
314
|
-
this.emitImportUpdate();
|
|
315
|
-
}
|
|
316
|
-
catch (err) {
|
|
317
|
-
this.logError(err, 'onImportGroupChange');
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
308
|
onImportFile(file) {
|
|
321
309
|
const observer = new observer_1.Observer();
|
|
322
310
|
try {
|
|
323
|
-
const group = this.importGroup;
|
|
324
311
|
this.importPhase = 'importing';
|
|
325
312
|
this.importingFileName = file?.name;
|
|
326
313
|
this.emitImportUpdate();
|
|
327
314
|
this.getWorkoutList().import(file, { showImportCards: false })
|
|
328
315
|
.then(([card]) => {
|
|
329
|
-
|
|
316
|
+
const group = this.getLastUsedImportGroup();
|
|
317
|
+
if (group !== DEFAULT_IMPORT_GROUP)
|
|
330
318
|
card.move(group);
|
|
331
|
-
this.persistLastUsedImportGroup(group);
|
|
332
319
|
this.importPhase = 'result';
|
|
333
|
-
this.importResult = { workoutName: card.getTitle(), group };
|
|
320
|
+
this.importResult = { id: card.getId(), workoutName: card.getTitle(), group };
|
|
334
321
|
observer.emit('success');
|
|
335
322
|
this.emitImportUpdate();
|
|
336
323
|
})
|
|
@@ -346,6 +333,19 @@ let WorkoutListPageService = (() => {
|
|
|
346
333
|
}
|
|
347
334
|
return observer;
|
|
348
335
|
}
|
|
336
|
+
onImportSetGroup(id, group) {
|
|
337
|
+
try {
|
|
338
|
+
const card = this.findWorkoutCard(id);
|
|
339
|
+
card?.move(group);
|
|
340
|
+
this.persistLastUsedImportGroup(group);
|
|
341
|
+
if (this.importResult)
|
|
342
|
+
this.importResult = { ...this.importResult, group };
|
|
343
|
+
this.emitImportUpdate();
|
|
344
|
+
}
|
|
345
|
+
catch (err) {
|
|
346
|
+
this.logError(err, 'onImportSetGroup');
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
349
|
onImportClose() {
|
|
350
350
|
try {
|
|
351
351
|
delete this.importPhase;
|
|
@@ -366,7 +366,7 @@ let WorkoutListPageService = (() => {
|
|
|
366
366
|
const todayId = calendar.getScheduledToday()?.id ?? null;
|
|
367
367
|
const selectedWorkout = this.getWorkoutList().getSelected();
|
|
368
368
|
const items = scheduled.map(w => ({
|
|
369
|
-
id: w.id,
|
|
369
|
+
id: w.workout?.id,
|
|
370
370
|
title: w.workout?.name,
|
|
371
371
|
date: w.day,
|
|
372
372
|
duration: this.formatDuration(w.workout?.duration),
|
|
@@ -448,7 +448,12 @@ let WorkoutListPageService = (() => {
|
|
|
448
448
|
this.getPageObserver()?.emit('page-update');
|
|
449
449
|
}
|
|
450
450
|
emitImportUpdate() {
|
|
451
|
-
|
|
451
|
+
try {
|
|
452
|
+
this.getPageObserver()?.emit('import-update');
|
|
453
|
+
}
|
|
454
|
+
catch (err) {
|
|
455
|
+
this.logError(err, 'emitImportUpdate');
|
|
456
|
+
}
|
|
452
457
|
}
|
|
453
458
|
getWorkoutList() {
|
|
454
459
|
return (0, service_1.useWorkoutList)();
|
|
@@ -8,11 +8,12 @@ export class Workout extends Segment {
|
|
|
8
8
|
name;
|
|
9
9
|
description;
|
|
10
10
|
category;
|
|
11
|
+
explicitId;
|
|
11
12
|
constructor(opts) {
|
|
12
13
|
super(opts, true);
|
|
13
14
|
this.name = opts.name || '';
|
|
14
15
|
this._hash = opts.hash;
|
|
15
|
-
this.
|
|
16
|
+
this.explicitId = !!(opts.id || opts.hash);
|
|
16
17
|
this.description = opts.description || undefined;
|
|
17
18
|
this.repeat = 1;
|
|
18
19
|
this.type = 'workout';
|
|
@@ -29,6 +30,7 @@ export class Workout extends Segment {
|
|
|
29
30
|
catch {
|
|
30
31
|
}
|
|
31
32
|
});
|
|
33
|
+
this.id = opts.id || this.hash;
|
|
32
34
|
}
|
|
33
35
|
get hash() {
|
|
34
36
|
if (this._hash)
|
|
@@ -38,6 +40,12 @@ export class Workout extends Segment {
|
|
|
38
40
|
this._hash = crypto.createHash('md5').update(JSON.stringify({ name, description, steps, repeat })).digest('hex');
|
|
39
41
|
return this._hash;
|
|
40
42
|
}
|
|
43
|
+
refreshHash() {
|
|
44
|
+
if (this.explicitId)
|
|
45
|
+
return;
|
|
46
|
+
this._hash = undefined;
|
|
47
|
+
this.id = this.hash;
|
|
48
|
+
}
|
|
41
49
|
getSegment(time) {
|
|
42
50
|
const s = this.steps.find(s => s.getStart() <= time && s.getEnd() > time);
|
|
43
51
|
if (s?.type === 'segment')
|
|
@@ -54,6 +62,7 @@ export class Workout extends Segment {
|
|
|
54
62
|
const s = new Step(step);
|
|
55
63
|
this.push(s);
|
|
56
64
|
}
|
|
65
|
+
this.refreshHash();
|
|
57
66
|
}
|
|
58
67
|
}
|
|
59
68
|
addSegment(segment) {
|
|
@@ -65,6 +74,7 @@ export class Workout extends Segment {
|
|
|
65
74
|
const s = new Segment(segment);
|
|
66
75
|
this.push(s);
|
|
67
76
|
}
|
|
77
|
+
this.refreshHash();
|
|
68
78
|
}
|
|
69
79
|
}
|
|
70
80
|
}
|
|
@@ -80,10 +90,10 @@ export class Plan {
|
|
|
80
90
|
this.type = 'plan';
|
|
81
91
|
const { id, name, description, workouts, hash } = plan;
|
|
82
92
|
this._hash = hash;
|
|
83
|
-
this.id = id || this.hash;
|
|
84
93
|
this.name = name;
|
|
85
94
|
this.description = description;
|
|
86
95
|
this.workouts = workouts;
|
|
96
|
+
this.id = id || this.hash;
|
|
87
97
|
}
|
|
88
98
|
get hash() {
|
|
89
99
|
if (this._hash)
|
|
@@ -572,7 +572,7 @@ let WorkoutListService = (() => {
|
|
|
572
572
|
return;
|
|
573
573
|
const card = list.getCards().find(c => c.getData()?.id === id);
|
|
574
574
|
if (card)
|
|
575
|
-
res = { card, list
|
|
575
|
+
res = { card, list };
|
|
576
576
|
});
|
|
577
577
|
return res;
|
|
578
578
|
}
|
|
@@ -593,11 +593,11 @@ let WorkoutListService = (() => {
|
|
|
593
593
|
const workout = await this.parse(info);
|
|
594
594
|
const existing = this.findCard(workout);
|
|
595
595
|
if (existing) {
|
|
596
|
-
existing.
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
this.items.push(workout);
|
|
596
|
+
const card = existing.card;
|
|
597
|
+
card.update(workout);
|
|
598
|
+
return card;
|
|
600
599
|
}
|
|
600
|
+
this.items.push(workout);
|
|
601
601
|
const card = new WorkoutCard(workout, { list: this.myWorkouts });
|
|
602
602
|
card.save();
|
|
603
603
|
card.enableDelete(true);
|
|
@@ -73,7 +73,6 @@ let WorkoutListPageService = (() => {
|
|
|
73
73
|
groupFilter = (__runInitializers(this, _instanceExtraInitializers), null);
|
|
74
74
|
detailWorkoutId = null;
|
|
75
75
|
importPhase;
|
|
76
|
-
importGroup;
|
|
77
76
|
importingFileName;
|
|
78
77
|
importResult;
|
|
79
78
|
importError;
|
|
@@ -172,8 +171,7 @@ let WorkoutListPageService = (() => {
|
|
|
172
171
|
try {
|
|
173
172
|
const phase = this.importPhase ?? 'landing';
|
|
174
173
|
const knownGroups = this.getKnownGroups();
|
|
175
|
-
const
|
|
176
|
-
const props = { phase, group, knownGroups };
|
|
174
|
+
const props = { phase, knownGroups };
|
|
177
175
|
if (phase === 'importing')
|
|
178
176
|
props.importing = { fileName: this.importingFileName };
|
|
179
177
|
if (phase === 'result')
|
|
@@ -184,7 +182,7 @@ let WorkoutListPageService = (() => {
|
|
|
184
182
|
}
|
|
185
183
|
catch (err) {
|
|
186
184
|
this.logError(err, 'getImportDisplayProps');
|
|
187
|
-
return { phase: 'landing',
|
|
185
|
+
return { phase: 'landing', knownGroups: [] };
|
|
188
186
|
}
|
|
189
187
|
}
|
|
190
188
|
onSelectGroup(group) {
|
|
@@ -296,7 +294,6 @@ let WorkoutListPageService = (() => {
|
|
|
296
294
|
onImportOpen() {
|
|
297
295
|
try {
|
|
298
296
|
this.importPhase = 'landing';
|
|
299
|
-
this.importGroup = this.getLastUsedImportGroup();
|
|
300
297
|
delete this.importError;
|
|
301
298
|
delete this.importResult;
|
|
302
299
|
this.emitImportUpdate();
|
|
@@ -305,29 +302,19 @@ let WorkoutListPageService = (() => {
|
|
|
305
302
|
this.logError(err, 'onImportOpen');
|
|
306
303
|
}
|
|
307
304
|
}
|
|
308
|
-
onImportGroupChange(name) {
|
|
309
|
-
try {
|
|
310
|
-
this.importGroup = name;
|
|
311
|
-
this.emitImportUpdate();
|
|
312
|
-
}
|
|
313
|
-
catch (err) {
|
|
314
|
-
this.logError(err, 'onImportGroupChange');
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
305
|
onImportFile(file) {
|
|
318
306
|
const observer = new Observer();
|
|
319
307
|
try {
|
|
320
|
-
const group = this.importGroup;
|
|
321
308
|
this.importPhase = 'importing';
|
|
322
309
|
this.importingFileName = file?.name;
|
|
323
310
|
this.emitImportUpdate();
|
|
324
311
|
this.getWorkoutList().import(file, { showImportCards: false })
|
|
325
312
|
.then(([card]) => {
|
|
326
|
-
|
|
313
|
+
const group = this.getLastUsedImportGroup();
|
|
314
|
+
if (group !== DEFAULT_IMPORT_GROUP)
|
|
327
315
|
card.move(group);
|
|
328
|
-
this.persistLastUsedImportGroup(group);
|
|
329
316
|
this.importPhase = 'result';
|
|
330
|
-
this.importResult = { workoutName: card.getTitle(), group };
|
|
317
|
+
this.importResult = { id: card.getId(), workoutName: card.getTitle(), group };
|
|
331
318
|
observer.emit('success');
|
|
332
319
|
this.emitImportUpdate();
|
|
333
320
|
})
|
|
@@ -343,6 +330,19 @@ let WorkoutListPageService = (() => {
|
|
|
343
330
|
}
|
|
344
331
|
return observer;
|
|
345
332
|
}
|
|
333
|
+
onImportSetGroup(id, group) {
|
|
334
|
+
try {
|
|
335
|
+
const card = this.findWorkoutCard(id);
|
|
336
|
+
card?.move(group);
|
|
337
|
+
this.persistLastUsedImportGroup(group);
|
|
338
|
+
if (this.importResult)
|
|
339
|
+
this.importResult = { ...this.importResult, group };
|
|
340
|
+
this.emitImportUpdate();
|
|
341
|
+
}
|
|
342
|
+
catch (err) {
|
|
343
|
+
this.logError(err, 'onImportSetGroup');
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
346
|
onImportClose() {
|
|
347
347
|
try {
|
|
348
348
|
delete this.importPhase;
|
|
@@ -363,7 +363,7 @@ let WorkoutListPageService = (() => {
|
|
|
363
363
|
const todayId = calendar.getScheduledToday()?.id ?? null;
|
|
364
364
|
const selectedWorkout = this.getWorkoutList().getSelected();
|
|
365
365
|
const items = scheduled.map(w => ({
|
|
366
|
-
id: w.id,
|
|
366
|
+
id: w.workout?.id,
|
|
367
367
|
title: w.workout?.name,
|
|
368
368
|
date: w.day,
|
|
369
369
|
duration: this.formatDuration(w.workout?.duration),
|
|
@@ -445,7 +445,12 @@ let WorkoutListPageService = (() => {
|
|
|
445
445
|
this.getPageObserver()?.emit('page-update');
|
|
446
446
|
}
|
|
447
447
|
emitImportUpdate() {
|
|
448
|
-
|
|
448
|
+
try {
|
|
449
|
+
this.getPageObserver()?.emit('import-update');
|
|
450
|
+
}
|
|
451
|
+
catch (err) {
|
|
452
|
+
this.logError(err, 'emitImportUpdate');
|
|
453
|
+
}
|
|
449
454
|
}
|
|
450
455
|
getWorkoutList() {
|
|
451
456
|
return useWorkoutList();
|
|
@@ -6,8 +6,10 @@ export declare class Workout extends Segment implements WorkoutDefinition {
|
|
|
6
6
|
name: string;
|
|
7
7
|
description: string;
|
|
8
8
|
category?: Category;
|
|
9
|
+
protected explicitId: boolean;
|
|
9
10
|
constructor(opts: WorkoutDefinition);
|
|
10
11
|
get hash(): string;
|
|
12
|
+
protected refreshHash(): void;
|
|
11
13
|
getSegment(time: number): Segment;
|
|
12
14
|
addStep(step: StepDefinition): void;
|
|
13
15
|
addSegment(segment: SegmentDefinition): void;
|
|
@@ -8,9 +8,9 @@ export declare class WorkoutListPageService extends IncyclistPageService impleme
|
|
|
8
8
|
protected groupFilter: string | null;
|
|
9
9
|
protected detailWorkoutId: string | null;
|
|
10
10
|
protected importPhase: 'landing' | 'importing' | 'result' | 'error' | undefined;
|
|
11
|
-
protected importGroup: string;
|
|
12
11
|
protected importingFileName: string;
|
|
13
12
|
protected importResult: {
|
|
13
|
+
id: string;
|
|
14
14
|
workoutName: string;
|
|
15
15
|
group: string;
|
|
16
16
|
};
|
|
@@ -37,8 +37,8 @@ export declare class WorkoutListPageService extends IncyclistPageService impleme
|
|
|
37
37
|
onMarkForRoute(id: string): void;
|
|
38
38
|
onClearSelection(): void;
|
|
39
39
|
onImportOpen(): void;
|
|
40
|
-
onImportGroupChange(name: string): void;
|
|
41
40
|
onImportFile(file: FileInfo): IObserver;
|
|
41
|
+
onImportSetGroup(id: string, group: string): void;
|
|
42
42
|
onImportClose(): void;
|
|
43
43
|
protected getUpcomingTrainingProps(): UpcomingTrainingProps | null;
|
|
44
44
|
protected getGroupFilterProps(): GroupFilterProps;
|
|
@@ -60,12 +60,12 @@ export interface WorkoutDetailsProps {
|
|
|
60
60
|
}
|
|
61
61
|
export interface WorkoutImportDisplayProps {
|
|
62
62
|
phase: 'landing' | 'importing' | 'result' | 'error';
|
|
63
|
-
group: string;
|
|
64
63
|
knownGroups: string[];
|
|
65
64
|
importing?: {
|
|
66
65
|
fileName: string;
|
|
67
66
|
};
|
|
68
67
|
result?: {
|
|
68
|
+
id: string;
|
|
69
69
|
workoutName: string;
|
|
70
70
|
group: string;
|
|
71
71
|
};
|
|
@@ -85,8 +85,8 @@ export interface WorkoutListPageCallbacks {
|
|
|
85
85
|
onMarkForRoute?: (id: string) => void;
|
|
86
86
|
onClearSelection: () => void;
|
|
87
87
|
onImportOpen: () => void;
|
|
88
|
-
onImportGroupChange: (name: string) => void;
|
|
89
88
|
onImportFile: (file: FileInfo) => IObserver;
|
|
89
|
+
onImportSetGroup: (id: string, group: string) => void;
|
|
90
90
|
onImportClose: () => void;
|
|
91
91
|
}
|
|
92
92
|
export interface IWorkoutListPageService extends WorkoutListPageCallbacks {
|