incyclist-services 1.7.103 → 1.7.105
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 +4 -0
- package/lib/cjs/workouts/base/parsers/incyclist/Json.js +1 -1
- package/lib/cjs/workouts/base/parsers/intervals/parser.js +1 -1
- package/lib/cjs/workouts/base/parsers/zwo/zwo.js +1 -1
- package/lib/cjs/workouts/list/cards/WorkoutCard.js +10 -1
- package/lib/cjs/workouts/list/service.js +23 -1
- package/lib/esm/workouts/base/model/Workout.js +4 -0
- package/lib/esm/workouts/base/parsers/incyclist/Json.js +1 -1
- package/lib/esm/workouts/base/parsers/intervals/parser.js +1 -1
- package/lib/esm/workouts/base/parsers/zwo/zwo.js +1 -1
- package/lib/esm/workouts/list/cards/WorkoutCard.js +10 -1
- package/lib/esm/workouts/list/service.js +23 -1
- package/lib/types/workouts/base/model/Workout.d.ts +2 -0
- package/lib/types/workouts/base/model/types.d.ts +2 -0
- package/lib/types/workouts/list/cards/WorkoutCard.d.ts +1 -0
- package/lib/types/workouts/list/service.d.ts +4 -0
- package/package.json +1 -1
|
@@ -11,6 +11,8 @@ class Workout extends Segment_1.Segment {
|
|
|
11
11
|
name;
|
|
12
12
|
description;
|
|
13
13
|
category;
|
|
14
|
+
isLocal;
|
|
15
|
+
isDeleted;
|
|
14
16
|
explicitId;
|
|
15
17
|
constructor(opts) {
|
|
16
18
|
super(opts, true);
|
|
@@ -21,6 +23,8 @@ class Workout extends Segment_1.Segment {
|
|
|
21
23
|
this.repeat = 1;
|
|
22
24
|
this.type = 'workout';
|
|
23
25
|
this.category = opts.category;
|
|
26
|
+
this.isLocal = opts.isLocal;
|
|
27
|
+
this.isDeleted = opts.isDeleted;
|
|
24
28
|
this.steps = [];
|
|
25
29
|
this.start = this.end = this.duration = 0;
|
|
26
30
|
opts.steps?.forEach(s => {
|
|
@@ -17,7 +17,7 @@ class JsonParser {
|
|
|
17
17
|
const str = await this.getData(file, data);
|
|
18
18
|
const parsedData = JSON.parse(str);
|
|
19
19
|
const { name, description, category, steps, type = 'workout' } = parsedData;
|
|
20
|
-
const workout = new Workout_1.Workout({ type, name, description, category });
|
|
20
|
+
const workout = new Workout_1.Workout({ type, name, description, category, isLocal: true });
|
|
21
21
|
steps.forEach(step => {
|
|
22
22
|
if (step.type === 'step') {
|
|
23
23
|
workout.addStep(step);
|
|
@@ -77,7 +77,7 @@ let IntervalsJsonParser = (() => {
|
|
|
77
77
|
}
|
|
78
78
|
fromJSON(data, fileName) {
|
|
79
79
|
const name = fileName?.replace(/\.json$/i, '');
|
|
80
|
-
const workout = new model_1.Workout({ type: 'workout', name, description: data.description });
|
|
80
|
+
const workout = new model_1.Workout({ type: 'workout', name, description: data.description, isLocal: true });
|
|
81
81
|
data.steps.forEach(s => {
|
|
82
82
|
if (s.reps !== undefined && s.reps !== null) {
|
|
83
83
|
const segment = this.convertSegment(s, data);
|
|
@@ -46,7 +46,7 @@ class ZwoParser {
|
|
|
46
46
|
xml.expectScheme('workout_file');
|
|
47
47
|
const name = (0, utils_1.ignoreEmpty)(xml.json['name']) ?? fileName;
|
|
48
48
|
const description = (0, utils_1.ignoreEmpty)(xml.json['description']);
|
|
49
|
-
const workout = new Workout_1.Workout({ type: 'workout', name, description });
|
|
49
|
+
const workout = new Workout_1.Workout({ type: 'workout', name, description, isLocal: true });
|
|
50
50
|
return this.parse(str, workout);
|
|
51
51
|
}
|
|
52
52
|
supportsExtension(extension) {
|
|
@@ -133,6 +133,10 @@ let WorkoutCard = (() => {
|
|
|
133
133
|
this.logError(err, 'save');
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
+
async markDeleted() {
|
|
137
|
+
this.workout.isDeleted = true;
|
|
138
|
+
await this.getRepo().save(this.workout, true);
|
|
139
|
+
}
|
|
136
140
|
delete() {
|
|
137
141
|
try {
|
|
138
142
|
const service = this.getWorkoutList();
|
|
@@ -206,7 +210,12 @@ let WorkoutCard = (() => {
|
|
|
206
210
|
let deleted;
|
|
207
211
|
try {
|
|
208
212
|
this.deleteObserver.emit('started');
|
|
209
|
-
|
|
213
|
+
if (this.workout.isLocal) {
|
|
214
|
+
await this.getRepo().delete(this.workout);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
await this.markDeleted();
|
|
218
|
+
}
|
|
210
219
|
this.deleteFromUIList();
|
|
211
220
|
this.getWorkoutList().emitLists('updated');
|
|
212
221
|
deleted = true;
|
|
@@ -48,6 +48,7 @@ const ActiveImportCard_1 = require("./cards/ActiveImportCard");
|
|
|
48
48
|
const WorkoutCard_1 = require("./cards/WorkoutCard");
|
|
49
49
|
const cards_1 = require("./cards");
|
|
50
50
|
const db_1 = require("./loaders/db");
|
|
51
|
+
const api_2 = require("./loaders/api");
|
|
51
52
|
const decorators_1 = require("../../base/decorators");
|
|
52
53
|
const calendar_1 = require("../calendar");
|
|
53
54
|
const ScheduledWorkoutCard_1 = require("./cards/ScheduledWorkoutCard");
|
|
@@ -84,6 +85,7 @@ let WorkoutListService = (() => {
|
|
|
84
85
|
preloadObserver;
|
|
85
86
|
items;
|
|
86
87
|
db;
|
|
88
|
+
api;
|
|
87
89
|
screenProps;
|
|
88
90
|
language;
|
|
89
91
|
selectedWorkout;
|
|
@@ -102,6 +104,7 @@ let WorkoutListService = (() => {
|
|
|
102
104
|
this.language = 'en';
|
|
103
105
|
this.myWorkouts.add(new cards_1.WorkoutImportCard());
|
|
104
106
|
this.myWorkouts.add(new cards_1.WorkoutCreateCard());
|
|
107
|
+
this.api = new api_2.WorkoutsApiLoader();
|
|
105
108
|
this.registerUserChangeHandler();
|
|
106
109
|
this.onUpdate = this.onScheduledWorkoutsUpdated.bind(this);
|
|
107
110
|
this.getWorkoutCalendar().on('updated', this.onUpdate);
|
|
@@ -504,6 +507,11 @@ let WorkoutListService = (() => {
|
|
|
504
507
|
});
|
|
505
508
|
}
|
|
506
509
|
async loadWorkouts() {
|
|
510
|
+
await this.loadWorkoutsFromRepo();
|
|
511
|
+
await this.loadWorkoutsFromApi();
|
|
512
|
+
this.logEvent({ message: 'loadWorkoutsFromApi done' });
|
|
513
|
+
}
|
|
514
|
+
async loadWorkoutsFromRepo() {
|
|
507
515
|
return new Promise((done, reject) => {
|
|
508
516
|
try {
|
|
509
517
|
const observer = this.getRepo().load();
|
|
@@ -519,7 +527,22 @@ let WorkoutListService = (() => {
|
|
|
519
527
|
}
|
|
520
528
|
});
|
|
521
529
|
}
|
|
530
|
+
async loadWorkoutsFromApi() {
|
|
531
|
+
return new Promise((done) => {
|
|
532
|
+
this.logEvent({ message: 'loadWorkoutsFromApi start' });
|
|
533
|
+
const observer = this.api.load();
|
|
534
|
+
const add = this.addItem.bind(this);
|
|
535
|
+
const update = this.updateItem.bind(this);
|
|
536
|
+
observer.on('workout.added', add);
|
|
537
|
+
observer.on('workout.updated', update);
|
|
538
|
+
observer.on('done', done);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
522
541
|
addItem(item) {
|
|
542
|
+
this.items.push(item);
|
|
543
|
+
if (item.isDeleted) {
|
|
544
|
+
return undefined;
|
|
545
|
+
}
|
|
523
546
|
const list = this.selectList(item);
|
|
524
547
|
let card;
|
|
525
548
|
if (item.type === 'workout') {
|
|
@@ -529,7 +552,6 @@ let WorkoutListService = (() => {
|
|
|
529
552
|
}
|
|
530
553
|
list.add(card);
|
|
531
554
|
card.enableDelete(true);
|
|
532
|
-
this.items.push(item);
|
|
533
555
|
this.emitLists('updated');
|
|
534
556
|
return card;
|
|
535
557
|
}
|
|
@@ -8,6 +8,8 @@ export class Workout extends Segment {
|
|
|
8
8
|
name;
|
|
9
9
|
description;
|
|
10
10
|
category;
|
|
11
|
+
isLocal;
|
|
12
|
+
isDeleted;
|
|
11
13
|
explicitId;
|
|
12
14
|
constructor(opts) {
|
|
13
15
|
super(opts, true);
|
|
@@ -18,6 +20,8 @@ export class Workout extends Segment {
|
|
|
18
20
|
this.repeat = 1;
|
|
19
21
|
this.type = 'workout';
|
|
20
22
|
this.category = opts.category;
|
|
23
|
+
this.isLocal = opts.isLocal;
|
|
24
|
+
this.isDeleted = opts.isDeleted;
|
|
21
25
|
this.steps = [];
|
|
22
26
|
this.start = this.end = this.duration = 0;
|
|
23
27
|
opts.steps?.forEach(s => {
|
|
@@ -14,7 +14,7 @@ export class JsonParser {
|
|
|
14
14
|
const str = await this.getData(file, data);
|
|
15
15
|
const parsedData = JSON.parse(str);
|
|
16
16
|
const { name, description, category, steps, type = 'workout' } = parsedData;
|
|
17
|
-
const workout = new Workout({ type, name, description, category });
|
|
17
|
+
const workout = new Workout({ type, name, description, category, isLocal: true });
|
|
18
18
|
steps.forEach(step => {
|
|
19
19
|
if (step.type === 'step') {
|
|
20
20
|
workout.addStep(step);
|
|
@@ -74,7 +74,7 @@ let IntervalsJsonParser = (() => {
|
|
|
74
74
|
}
|
|
75
75
|
fromJSON(data, fileName) {
|
|
76
76
|
const name = fileName?.replace(/\.json$/i, '');
|
|
77
|
-
const workout = new Workout({ type: 'workout', name, description: data.description });
|
|
77
|
+
const workout = new Workout({ type: 'workout', name, description: data.description, isLocal: true });
|
|
78
78
|
data.steps.forEach(s => {
|
|
79
79
|
if (s.reps !== undefined && s.reps !== null) {
|
|
80
80
|
const segment = this.convertSegment(s, data);
|
|
@@ -40,7 +40,7 @@ export class ZwoParser {
|
|
|
40
40
|
xml.expectScheme('workout_file');
|
|
41
41
|
const name = ignoreEmpty(xml.json['name']) ?? fileName;
|
|
42
42
|
const description = ignoreEmpty(xml.json['description']);
|
|
43
|
-
const workout = new Workout({ type: 'workout', name, description });
|
|
43
|
+
const workout = new Workout({ type: 'workout', name, description, isLocal: true });
|
|
44
44
|
return this.parse(str, workout);
|
|
45
45
|
}
|
|
46
46
|
supportsExtension(extension) {
|
|
@@ -130,6 +130,10 @@ let WorkoutCard = (() => {
|
|
|
130
130
|
this.logError(err, 'save');
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
|
+
async markDeleted() {
|
|
134
|
+
this.workout.isDeleted = true;
|
|
135
|
+
await this.getRepo().save(this.workout, true);
|
|
136
|
+
}
|
|
133
137
|
delete() {
|
|
134
138
|
try {
|
|
135
139
|
const service = this.getWorkoutList();
|
|
@@ -203,7 +207,12 @@ let WorkoutCard = (() => {
|
|
|
203
207
|
let deleted;
|
|
204
208
|
try {
|
|
205
209
|
this.deleteObserver.emit('started');
|
|
206
|
-
|
|
210
|
+
if (this.workout.isLocal) {
|
|
211
|
+
await this.getRepo().delete(this.workout);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
await this.markDeleted();
|
|
215
|
+
}
|
|
207
216
|
this.deleteFromUIList();
|
|
208
217
|
this.getWorkoutList().emitLists('updated');
|
|
209
218
|
deleted = true;
|
|
@@ -45,6 +45,7 @@ import { ActiveImportCard } from "./cards/ActiveImportCard";
|
|
|
45
45
|
import { WorkoutCard } from "./cards/WorkoutCard";
|
|
46
46
|
import { WorkoutImportCard, WorkoutCreateCard } from './cards';
|
|
47
47
|
import { WorkoutsDbLoader } from "./loaders/db";
|
|
48
|
+
import { WorkoutsApiLoader } from "./loaders/api";
|
|
48
49
|
import { Injectable } from "../../base/decorators";
|
|
49
50
|
import { useWorkoutCalendar } from "../calendar";
|
|
50
51
|
import { ScheduledWorkoutCard } from "./cards/ScheduledWorkoutCard";
|
|
@@ -81,6 +82,7 @@ let WorkoutListService = (() => {
|
|
|
81
82
|
preloadObserver;
|
|
82
83
|
items;
|
|
83
84
|
db;
|
|
85
|
+
api;
|
|
84
86
|
screenProps;
|
|
85
87
|
language;
|
|
86
88
|
selectedWorkout;
|
|
@@ -99,6 +101,7 @@ let WorkoutListService = (() => {
|
|
|
99
101
|
this.language = 'en';
|
|
100
102
|
this.myWorkouts.add(new WorkoutImportCard());
|
|
101
103
|
this.myWorkouts.add(new WorkoutCreateCard());
|
|
104
|
+
this.api = new WorkoutsApiLoader();
|
|
102
105
|
this.registerUserChangeHandler();
|
|
103
106
|
this.onUpdate = this.onScheduledWorkoutsUpdated.bind(this);
|
|
104
107
|
this.getWorkoutCalendar().on('updated', this.onUpdate);
|
|
@@ -501,6 +504,11 @@ let WorkoutListService = (() => {
|
|
|
501
504
|
});
|
|
502
505
|
}
|
|
503
506
|
async loadWorkouts() {
|
|
507
|
+
await this.loadWorkoutsFromRepo();
|
|
508
|
+
await this.loadWorkoutsFromApi();
|
|
509
|
+
this.logEvent({ message: 'loadWorkoutsFromApi done' });
|
|
510
|
+
}
|
|
511
|
+
async loadWorkoutsFromRepo() {
|
|
504
512
|
return new Promise((done, reject) => {
|
|
505
513
|
try {
|
|
506
514
|
const observer = this.getRepo().load();
|
|
@@ -516,7 +524,22 @@ let WorkoutListService = (() => {
|
|
|
516
524
|
}
|
|
517
525
|
});
|
|
518
526
|
}
|
|
527
|
+
async loadWorkoutsFromApi() {
|
|
528
|
+
return new Promise((done) => {
|
|
529
|
+
this.logEvent({ message: 'loadWorkoutsFromApi start' });
|
|
530
|
+
const observer = this.api.load();
|
|
531
|
+
const add = this.addItem.bind(this);
|
|
532
|
+
const update = this.updateItem.bind(this);
|
|
533
|
+
observer.on('workout.added', add);
|
|
534
|
+
observer.on('workout.updated', update);
|
|
535
|
+
observer.on('done', done);
|
|
536
|
+
});
|
|
537
|
+
}
|
|
519
538
|
addItem(item) {
|
|
539
|
+
this.items.push(item);
|
|
540
|
+
if (item.isDeleted) {
|
|
541
|
+
return undefined;
|
|
542
|
+
}
|
|
520
543
|
const list = this.selectList(item);
|
|
521
544
|
let card;
|
|
522
545
|
if (item.type === 'workout') {
|
|
@@ -526,7 +549,6 @@ let WorkoutListService = (() => {
|
|
|
526
549
|
}
|
|
527
550
|
list.add(card);
|
|
528
551
|
card.enableDelete(true);
|
|
529
|
-
this.items.push(item);
|
|
530
552
|
this.emitLists('updated');
|
|
531
553
|
return card;
|
|
532
554
|
}
|
|
@@ -6,6 +6,8 @@ export declare class Workout extends Segment implements WorkoutDefinition {
|
|
|
6
6
|
name: string;
|
|
7
7
|
description: string;
|
|
8
8
|
category?: Category;
|
|
9
|
+
isLocal?: boolean;
|
|
10
|
+
isDeleted?: boolean;
|
|
9
11
|
protected explicitId: boolean;
|
|
10
12
|
constructor(opts: WorkoutDefinition);
|
|
11
13
|
get hash(): string;
|
|
@@ -20,6 +20,7 @@ export declare class WorkoutCard extends BaseCard implements Card<Workout> {
|
|
|
20
20
|
unselect(): void;
|
|
21
21
|
move(targetListName: string): void;
|
|
22
22
|
save(enforce?: boolean): Promise<void>;
|
|
23
|
+
protected markDeleted(): Promise<void>;
|
|
23
24
|
delete(): PromiseObserver<boolean>;
|
|
24
25
|
getId(): string;
|
|
25
26
|
getTitle(): string;
|
|
@@ -8,6 +8,7 @@ import { ActiveImportCard } from "./cards/ActiveImportCard";
|
|
|
8
8
|
import { WorkoutCard } from "./cards/WorkoutCard";
|
|
9
9
|
import { WorkoutSettings } from "./cards/types";
|
|
10
10
|
import { WorkoutsDbLoader } from "./loaders/db";
|
|
11
|
+
import { WorkoutsApiLoader } from "./loaders/api";
|
|
11
12
|
import { WP, WorkoutSettingsDisplayProps } from "./types";
|
|
12
13
|
import { ScheduledWorkout, WorkoutCalendarEntry } from "../calendar";
|
|
13
14
|
export declare class WorkoutListService extends IncyclistService implements IListService<WP> {
|
|
@@ -18,6 +19,7 @@ export declare class WorkoutListService extends IncyclistService implements ILis
|
|
|
18
19
|
protected preloadObserver: PromiseObserver<void>;
|
|
19
20
|
protected items: Array<WP>;
|
|
20
21
|
protected db: WorkoutsDbLoader;
|
|
22
|
+
protected api: WorkoutsApiLoader;
|
|
21
23
|
protected screenProps: any;
|
|
22
24
|
protected language: string;
|
|
23
25
|
protected selectedWorkout: Workout;
|
|
@@ -65,6 +67,8 @@ export declare class WorkoutListService extends IncyclistService implements ILis
|
|
|
65
67
|
protected resetLists(): void;
|
|
66
68
|
protected resetCards(): void;
|
|
67
69
|
protected loadWorkouts(): Promise<void>;
|
|
70
|
+
protected loadWorkoutsFromRepo(): Promise<void>;
|
|
71
|
+
protected loadWorkoutsFromApi(): Promise<void>;
|
|
68
72
|
protected addItem(item: WP): Card<WP>;
|
|
69
73
|
protected updateItem(item: WP): Promise<void>;
|
|
70
74
|
protected selectList(item: WP): CardList<WP>;
|