incyclist-services 1.1.97 → 1.1.98

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.
@@ -352,29 +352,35 @@ class DeviceConfigurationService extends events_1.default {
352
352
  });
353
353
  }
354
354
  getDeviceConfigurationInfo() {
355
- const { capabilities = [], devices = [] } = this.settings;
356
- const { adapters } = this;
357
- const info = capabilities.map(c => {
358
- const ci = {
359
- capability: c.capability,
360
- disabled: c.disabled || false,
361
- devices: c.devices.filter(udid => devices.find(d => d.udid === udid)).map(udid => {
362
- const adapter = adapters[udid];
363
- const device = devices.find(d => d.udid === udid);
364
- const mode = device.mode;
365
- const modeSetting = device.modes ? device.modes[mode] : undefined;
366
- const interfaceName = device.settings.interface;
367
- const name = (device === null || device === void 0 ? void 0 : device.displayName) || (adapter === null || adapter === void 0 ? void 0 : adapter.getUniqueName()) || (adapter === null || adapter === void 0 ? void 0 : adapter.getName());
368
- return { udid, name, interface: interfaceName, selected: udid === c.selected, mode, modeSetting };
369
- })
370
- };
371
- return ci;
372
- });
373
355
  const configuration = {};
374
- info.forEach(ci => {
375
- const c = ci.capability.toString();
376
- configuration[c] = ci;
377
- });
356
+ try {
357
+ const { capabilities = [], devices = [] } = this.settings;
358
+ const { adapters } = this;
359
+ const info = capabilities.map(c => {
360
+ var _a;
361
+ const ci = {
362
+ capability: c.capability,
363
+ disabled: c.disabled || false,
364
+ devices: ((_a = c.devices) !== null && _a !== void 0 ? _a : []).filter(udid => devices.find(d => d.udid === udid)).map(udid => {
365
+ const adapter = adapters[udid];
366
+ const device = devices.find(d => d.udid === udid);
367
+ const mode = device.mode;
368
+ const modeSetting = device.modes ? device.modes[mode] : undefined;
369
+ const interfaceName = device.settings.interface;
370
+ const name = (device === null || device === void 0 ? void 0 : device.displayName) || (adapter === null || adapter === void 0 ? void 0 : adapter.getUniqueName()) || (adapter === null || adapter === void 0 ? void 0 : adapter.getName());
371
+ return { udid, name, interface: interfaceName, selected: udid === c.selected, mode, modeSetting };
372
+ })
373
+ };
374
+ return ci;
375
+ });
376
+ info.forEach(ci => {
377
+ const c = ci.capability.toString();
378
+ configuration[c] = ci;
379
+ });
380
+ }
381
+ catch (err) {
382
+ this.logError(err, 'getDeviceConfigurationInfo');
383
+ }
378
384
  return configuration;
379
385
  }
380
386
  emitCapabiltyChanged(capability) {
@@ -31,6 +31,7 @@ export declare class UserSettingsService {
31
31
  updateSettings(data: any): Promise<boolean>;
32
32
  save(): Promise<void>;
33
33
  onAppClose(): Promise<void>;
34
+ protected reset(): void;
34
35
  }
35
36
  export declare const useUserSettings: () => UserSettingsService;
36
37
  export declare const initUserSettings: (binding: IUserSettingsBinding) => UserSettingsService;
@@ -194,6 +194,9 @@ class UserSettingsService {
194
194
  this.binding.save(this.settings, true);
195
195
  });
196
196
  }
197
+ reset() {
198
+ delete UserSettingsService._instance;
199
+ }
197
200
  }
198
201
  exports.UserSettingsService = UserSettingsService;
199
202
  const useUserSettings = () => UserSettingsService.getInstance();
@@ -1,6 +1,5 @@
1
1
  import { FileInfo } from "../../../api";
2
2
  import { Card } from "../../../base/cardlist";
3
- import { ImportFilter } from "../../../base/cardlist/types";
4
3
  import { PromiseObserver } from "../../../base/types/observer";
5
4
  import { AppStatus } from "../../../routes/base/types";
6
5
  import { WP } from "../types";
@@ -13,16 +12,16 @@ export declare class ActiveImportCard extends BaseCard implements Card<WP> {
13
12
  protected deleteObserver: PromiseObserver<void>;
14
13
  constructor(file: FileInfo);
15
14
  setVisible(): void;
15
+ canDelete(): boolean;
16
16
  canStart(status: AppStatus): boolean;
17
17
  delete(): PromiseObserver<boolean>;
18
18
  setError(error: Error): void;
19
- setData(): void;
20
- emitUpdate(): void;
21
19
  getData(): any;
22
20
  getCardType(): WorkoutCardType;
23
21
  getId(): string;
24
- getFilters(): Array<ImportFilter>;
25
22
  getTitle(): string;
26
23
  getDisplayProperties(): ActiveImportProps;
27
24
  retry(): void;
25
+ protected emitUpdate(): void;
26
+ protected getWorkoutList(): import("../service").WorkoutListService;
28
27
  }
@@ -15,14 +15,18 @@ class ActiveImportCard extends base_1.BaseCard {
15
15
  setVisible() {
16
16
  this.visible = true;
17
17
  }
18
+ canDelete() {
19
+ return true;
20
+ }
18
21
  canStart(status) {
19
22
  return false;
20
23
  }
21
24
  delete() {
22
- const list = (0, service_1.useWorkoutList)().getLists().find(l => l.getId() === 'myRoutes');
25
+ const listService = this.getWorkoutList();
26
+ const list = listService.getLists().find(l => l.getId() === 'myWorkouts');
23
27
  if (list) {
24
28
  list.remove(this);
25
- (0, service_1.useWorkoutList)().emitLists('updated');
29
+ listService.emitLists('updated');
26
30
  }
27
31
  return observer_1.PromiseObserver.alwaysReturning(true);
28
32
  }
@@ -30,11 +34,6 @@ class ActiveImportCard extends base_1.BaseCard {
30
34
  this.error = error;
31
35
  this.emitUpdate();
32
36
  }
33
- setData() {
34
- }
35
- emitUpdate() {
36
- this.cardObserver.emit('update', this.getDisplayProperties());
37
- }
38
37
  getData() {
39
38
  return undefined;
40
39
  }
@@ -45,9 +44,6 @@ class ActiveImportCard extends base_1.BaseCard {
45
44
  const { type, url, filename, name } = this.file || {};
46
45
  return type === 'file' ? filename || name : url;
47
46
  }
48
- getFilters() {
49
- return types_1.DEFAULT_FILTERS;
50
- }
51
47
  getTitle() {
52
48
  return types_1.DEFAULT_TITLE;
53
49
  }
@@ -60,7 +56,13 @@ class ActiveImportCard extends base_1.BaseCard {
60
56
  retry() {
61
57
  this.error = null;
62
58
  this.emitUpdate();
63
- (0, service_1.useWorkoutList)().import(this.file, this);
59
+ this.getWorkoutList().import(this.file, { card: this });
60
+ }
61
+ emitUpdate() {
62
+ this.cardObserver.emit('update', this.getDisplayProperties());
63
+ }
64
+ getWorkoutList() {
65
+ return (0, service_1.useWorkoutList)();
64
66
  }
65
67
  }
66
68
  exports.ActiveImportCard = ActiveImportCard;
@@ -3,7 +3,7 @@ import { Card, CardList } from "../../../base/cardlist";
3
3
  import { Observer, PromiseObserver } from "../../../base/types/observer";
4
4
  import { Workout } from "../../base/model/Workout";
5
5
  import { BaseCard } from "./base";
6
- import { WorkoutCardType, WorkoutSettings } from "./types";
6
+ import { WorkoutCardDisplayProperties, WorkoutCardType, WorkoutSettings, WorkoutSettingsDisplayProps } from "./types";
7
7
  import { WorkoutsDbLoader } from "../loaders/db";
8
8
  export declare class WorkoutCard extends BaseCard implements Card<Workout> {
9
9
  protected workout: Workout;
@@ -15,39 +15,22 @@ export declare class WorkoutCard extends BaseCard implements Card<Workout> {
15
15
  constructor(workout: Workout, props?: {
16
16
  list?: CardList<Workout>;
17
17
  });
18
- openSettings(): {
19
- settings: any;
20
- ftpRequired: any;
21
- canStart: any;
22
- duration: any;
23
- categories: any[];
24
- category: any;
25
- };
18
+ openSettings(): WorkoutSettingsDisplayProps;
26
19
  select(settings?: WorkoutSettings): void;
27
20
  unselect(): void;
28
21
  move(targetListName: string): void;
29
22
  save(): Promise<void>;
30
- setList(list: CardList<Workout>): void;
31
23
  delete(): PromiseObserver<boolean>;
32
- protected _delete(): Promise<boolean>;
33
24
  getId(): string;
25
+ getTitle(): string;
34
26
  update(workout: Workout): void;
35
27
  getData(): Workout;
36
- setData(data: Workout): void;
37
28
  getCardType(): WorkoutCardType;
38
- getDisplayProperties(): {
39
- title: string;
40
- workout: Workout;
41
- ftp: any;
42
- duration: string;
43
- canDelete: boolean;
44
- visible: boolean;
45
- selected: boolean;
46
- observer: Observer;
47
- };
29
+ getDisplayProperties(): WorkoutCardDisplayProperties;
48
30
  enableDelete(enabled?: boolean): void;
49
31
  canDelete(): boolean;
50
32
  setVisible(visible: boolean): void;
33
+ protected _delete(): Promise<boolean>;
51
34
  protected calculateDuration(): string;
52
35
  protected deleteFromUIList(): void;
53
36
  protected logError(err: Error, fn: string): void;
@@ -25,12 +25,12 @@ class WorkoutCard extends base_1.BaseCard {
25
25
  const { list } = props || {};
26
26
  this.workout = workout;
27
27
  this.list = list;
28
- this.deleteable = false;
28
+ this.deleteable = true;
29
29
  this.initialized = false;
30
30
  this.logger = new gd_eventlog_1.EventLogger('WorkoutCard');
31
31
  }
32
32
  openSettings() {
33
- var _a;
33
+ var _a, _b;
34
34
  let settings, canStart, duration, ftpRequired, categories = [], category;
35
35
  try {
36
36
  const service = (0, service_1.useWorkoutList)();
@@ -41,8 +41,8 @@ class WorkoutCard extends base_1.BaseCard {
41
41
  return (s.type == 'step' && ((_a = s.power) === null || _a === void 0 ? void 0 : _a.type) === 'pct of FTP') ||
42
42
  (s.type == 'segment' && (s === null || s === void 0 ? void 0 : s.steps.find(s => { var _a; return (s.type == 'step' && ((_a = s.power) === null || _a === void 0 ? void 0 : _a.type) === 'pct of FTP'); })));
43
43
  }));
44
- settings = service.getStartSettings();
45
- categories = ((_a = service.getLists()) !== null && _a !== void 0 ? _a : []).map(l => l.getTitle());
44
+ settings = (_a = service.getStartSettings()) !== null && _a !== void 0 ? _a : {};
45
+ categories = ((_b = service.getLists()) !== null && _b !== void 0 ? _b : []).map(l => l.getTitle());
46
46
  category = this.list.getTitle();
47
47
  }
48
48
  catch (err) {
@@ -67,8 +67,9 @@ class WorkoutCard extends base_1.BaseCard {
67
67
  return;
68
68
  const service = (0, service_1.getWorkoutList)();
69
69
  const newList = service.moveCard(this, this.list, targetListName);
70
- if (newList)
70
+ if (newList) {
71
71
  this.list = newList;
72
+ }
72
73
  this.workout.category = { name: targetListName, index: newList === null || newList === void 0 ? void 0 : newList.length };
73
74
  this.save();
74
75
  }
@@ -82,9 +83,6 @@ class WorkoutCard extends base_1.BaseCard {
82
83
  }
83
84
  });
84
85
  }
85
- setList(list) {
86
- this.list = list;
87
- }
88
86
  delete() {
89
87
  try {
90
88
  const service = (0, service_1.getWorkoutList)();
@@ -98,39 +96,15 @@ class WorkoutCard extends base_1.BaseCard {
98
96
  this.logError(err, 'delete');
99
97
  }
100
98
  }
101
- _delete() {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- yield (0, utils_1.waitNextTick)();
104
- let deleted = false;
105
- try {
106
- this.deleteObserver.emit('started');
107
- this.emitUpdate();
108
- if (this.list.getId() === 'myWorkouts') {
109
- yield this.getRepo().delete(this.workout);
110
- }
111
- else {
112
- }
113
- this.deleteFromUIList();
114
- (0, service_1.getWorkoutList)().emitLists('updated');
115
- deleted = true;
116
- }
117
- catch (err) {
118
- deleted = false;
119
- }
120
- finally {
121
- this.deleteObserver.emit('done', deleted);
122
- (0, utils_1.waitNextTick)().then(() => {
123
- delete this.deleteObserver;
124
- this.emitUpdate();
125
- });
126
- }
127
- return deleted;
128
- });
129
- }
130
99
  getId() {
131
100
  return this.workout.id;
132
101
  }
102
+ getTitle() {
103
+ return this.workout.name;
104
+ }
133
105
  update(workout) {
106
+ if (!(0, valid_1.valid)(workout))
107
+ return;
134
108
  try {
135
109
  this.workout = workout;
136
110
  this.save();
@@ -143,14 +117,6 @@ class WorkoutCard extends base_1.BaseCard {
143
117
  getData() {
144
118
  return this.workout;
145
119
  }
146
- setData(data) {
147
- try {
148
- this.workout = data;
149
- }
150
- catch (err) {
151
- this.logError(err, 'setData');
152
- }
153
- }
154
120
  getCardType() {
155
121
  return "Workout";
156
122
  }
@@ -179,6 +145,29 @@ class WorkoutCard extends base_1.BaseCard {
179
145
  this.logError(err, 'setVisible');
180
146
  }
181
147
  }
148
+ _delete() {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ yield (0, utils_1.waitNextTick)();
151
+ let deleted = false;
152
+ try {
153
+ this.deleteObserver.emit('started');
154
+ yield this.getRepo().delete(this.workout);
155
+ this.deleteFromUIList();
156
+ (0, service_1.getWorkoutList)().emitLists('updated');
157
+ deleted = true;
158
+ }
159
+ catch (err) {
160
+ deleted = false;
161
+ }
162
+ finally {
163
+ this.deleteObserver.emit('done', deleted);
164
+ (0, utils_1.waitNextTick)().then(() => {
165
+ delete this.deleteObserver;
166
+ });
167
+ }
168
+ return deleted;
169
+ });
170
+ }
182
171
  calculateDuration() {
183
172
  const { duration } = this.workout;
184
173
  if (duration < 120)
@@ -215,6 +204,7 @@ class WorkoutCard extends base_1.BaseCard {
215
204
  const selectedWorkout = service.getSelected();
216
205
  if ((selectedWorkout === null || selectedWorkout === void 0 ? void 0 : selectedWorkout.id) === this.workout.id)
217
206
  return true;
207
+ return false;
218
208
  }
219
209
  }
220
210
  exports.WorkoutCard = WorkoutCard;
@@ -7,9 +7,9 @@ import { BaseCard } from "./base";
7
7
  import { WorkoutCardType, WorkoutImportProps } from "./types";
8
8
  export declare class WorkoutImportCard extends BaseCard implements Card<Workout> {
9
9
  setVisible(): void;
10
+ canDelete(): boolean;
10
11
  canStart(status: AppStatus): boolean;
11
12
  delete(): PromiseObserver<boolean>;
12
- setData(): void;
13
13
  getData(): any;
14
14
  getCardType(): WorkoutCardType;
15
15
  getId(): string;
@@ -8,14 +8,15 @@ class WorkoutImportCard extends base_1.BaseCard {
8
8
  setVisible() {
9
9
  this.visible = true;
10
10
  }
11
+ canDelete() {
12
+ return false;
13
+ }
11
14
  canStart(status) {
12
15
  return false;
13
16
  }
14
17
  delete() {
15
18
  return observer_1.PromiseObserver.alwaysReturning(false);
16
19
  }
17
- setData() {
18
- }
19
20
  getData() {
20
21
  return undefined;
21
22
  }
@@ -0,0 +1,3 @@
1
+ export * from './WorkoutCard';
2
+ export * from './WorkoutImportCard';
3
+ export * from './types';
@@ -0,0 +1,19 @@
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("./WorkoutCard"), exports);
18
+ __exportStar(require("./WorkoutImportCard"), exports);
19
+ __exportStar(require("./types"), exports);
@@ -1,5 +1,6 @@
1
1
  import { ImportFilter } from "../../../base/cardlist/types";
2
2
  import { Observer } from "../../../base/types/observer";
3
+ import { Workout } from "../../base/model";
3
4
  export type WorkoutCardType = 'WorkoutImport' | 'Workout' | 'ActiveWorkoutImport';
4
5
  export declare const DEFAULT_TITLE = "Import Workout";
5
6
  export declare const DEFAULT_FILTERS: {
@@ -21,3 +22,21 @@ export interface WorkoutSettings {
21
22
  ftp?: number;
22
23
  useErgMode?: boolean;
23
24
  }
25
+ export interface WorkoutSettingsDisplayProps {
26
+ settings: WorkoutSettings;
27
+ ftpRequired: boolean;
28
+ canStart: boolean;
29
+ duration: string;
30
+ categories: string[];
31
+ category: string;
32
+ }
33
+ export interface WorkoutCardDisplayProperties {
34
+ title: string;
35
+ workout: Workout;
36
+ ftp: number;
37
+ duration: string;
38
+ canDelete: boolean;
39
+ visible: boolean;
40
+ selected: boolean;
41
+ observer: Observer;
42
+ }
@@ -1 +1,2 @@
1
1
  export * from './service';
2
+ export * from './cards';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./service"), exports);
18
+ __exportStar(require("./cards"), exports);
@@ -5,6 +5,7 @@ import { IListService, ListObserver } from "../../base/types";
5
5
  import { PromiseObserver } from "../../base/types/observer";
6
6
  import { Plan, Workout } from "../base/model/Workout";
7
7
  import { ActiveImportCard } from "./cards/ActiveImportCard";
8
+ import { WorkoutCard } from "./cards/WorkoutCard";
8
9
  import { WorkoutSettings } from "./cards/types";
9
10
  import { WorkoutsDbLoader } from "./loaders/db";
10
11
  import { WP } from "./types";
@@ -26,23 +27,25 @@ export declare class WorkoutListService extends IncyclistService implements ILis
26
27
  getSelected(): Workout;
27
28
  setScreenProps(props: any): void;
28
29
  getScreenProps(): any;
29
- getStartSettings(): WorkoutSettings;
30
- setStartSettings(settings: WorkoutSettings): void;
31
30
  open(): {
32
31
  observer: ListObserver<WP>;
33
32
  lists: Array<CardList<WP>>;
34
33
  };
34
+ close(): void;
35
35
  openSettings(): {
36
36
  observer: ListObserver<WP>;
37
37
  workouts: CardList<Workout>;
38
38
  };
39
- close(): void;
39
+ getStartSettings(): WorkoutSettings;
40
+ setStartSettings(settings: WorkoutSettings): void;
40
41
  onResize(): void;
41
42
  onCarouselInitialized(list: CardList<WP>, item: any, itemsInSlide: any): void;
42
43
  onCarouselUpdated(list: any, item: any, itemsInSlide: any): void;
43
44
  preload(): PromiseObserver<void>;
44
- import(info: FileInfo | Array<FileInfo>, retry?: ActiveImportCard): void;
45
- importSingle(info: FileInfo): Promise<Workout>;
45
+ import(info: FileInfo | Array<FileInfo>, props: {
46
+ card?: ActiveImportCard;
47
+ showImportCards?: boolean;
48
+ }): void;
46
49
  addList(name: string): CardList<WP>;
47
50
  getLists(forUi?: boolean): Array<CardList<WP>>;
48
51
  emitLists(event: 'loaded' | 'updated'): void;
@@ -52,6 +55,7 @@ export declare class WorkoutListService extends IncyclistService implements ILis
52
55
  unselectCard(card: Card<WP>): void;
53
56
  moveCard(card: Card<WP>, source: CardList<WP>, target: string | CardList<WP>): CardList<WP>;
54
57
  canDisplayStart(): boolean;
58
+ protected createSettingsList(): CardList<WP>;
55
59
  protected resetLists(): void;
56
60
  protected resetCards(): void;
57
61
  protected loadWorkouts(): Promise<void>;
@@ -63,9 +67,14 @@ export declare class WorkoutListService extends IncyclistService implements ILis
63
67
  list: CardList<WP>;
64
68
  };
65
69
  protected addImportCard(file: FileInfo): ActiveImportCard;
70
+ protected _import(info: FileInfo): Promise<WorkoutCard>;
71
+ protected addImportCards(retry: ActiveImportCard, files: FileInfo[]): ActiveImportCard[];
66
72
  protected initStartSettings(): void;
67
73
  protected updateStartSettings(): void;
68
- createSettingsList(): CardList<WP>;
74
+ protected getUserSettings(): import("../../settings").UserSettingsService;
75
+ protected getRouteList(): import("../../routes").RouteListService;
76
+ protected emitStartEvent(): void;
77
+ protected emitLoadedEvent(): void;
69
78
  }
70
79
  export declare const useWorkoutList: () => WorkoutListService;
71
80
  export declare const getWorkoutList: () => WorkoutListService;
@@ -74,6 +74,7 @@ let WorkoutListService = (() => {
74
74
  this.lists = [this.myWorkouts];
75
75
  this.db = new db_1.WorkoutsDbLoader();
76
76
  this.items = [];
77
+ this.language = 'en';
77
78
  this.myWorkouts.add(new WorkoutImportCard_1.WorkoutImportCard());
78
79
  }
79
80
  setLanguage(language) { this.language = language; }
@@ -81,49 +82,31 @@ let WorkoutListService = (() => {
81
82
  getSelected() { return this.selectedWorkout; }
82
83
  setScreenProps(props) { this.screenProps = props; }
83
84
  getScreenProps() { return this.screenProps; }
84
- getStartSettings() {
85
- if (!this.startSettings) {
86
- this.initStartSettings();
87
- }
88
- return this.startSettings;
89
- }
90
- setStartSettings(settings) {
91
- this.startSettings = settings;
92
- this.updateStartSettings();
93
- }
94
85
  open() {
95
- var _a;
86
+ let lists = null;
96
87
  try {
97
88
  this.logEvent({ message: 'open workout list' });
98
- const hasLists = ((_a = this.getLists()) === null || _a === void 0 ? void 0 : _a.length) > 0;
99
- const emitStartEvent = () => __awaiter(this, void 0, void 0, function* () {
100
- process.nextTick(() => {
101
- var _a;
102
- (_a = this.observer) === null || _a === void 0 ? void 0 : _a.emit('started');
103
- });
104
- });
105
- const emitLoadedEvent = () => __awaiter(this, void 0, void 0, function* () {
106
- process.nextTick(() => {
107
- this.emitLists('loaded');
108
- });
109
- });
89
+ lists = this.getLists();
90
+ const hasLists = (lists === null || lists === void 0 ? void 0 : lists.length) > 0;
110
91
  this.resetLists();
111
92
  if (!this.observer) {
112
93
  this.observer = new types_1.ListObserver(this);
113
- emitStartEvent();
94
+ this.emitStartEvent();
114
95
  }
115
96
  if (!this.initialized && !this.preloadObserver) {
116
97
  this.preload();
117
98
  }
118
99
  if (this.initialized && !hasLists)
119
- emitLoadedEvent();
100
+ this.emitLoadedEvent();
120
101
  else
121
102
  this.emitLists('updated');
122
103
  }
123
104
  catch (err) {
124
105
  this.logError(err, 'open');
125
106
  }
126
- return { observer: this.observer, lists: this.getLists() };
107
+ return { observer: this.observer, lists };
108
+ }
109
+ close() {
127
110
  }
128
111
  openSettings() {
129
112
  let workouts;
@@ -150,7 +133,15 @@ let WorkoutListService = (() => {
150
133
  console.log('~~~ returning', { observer: this.observer, workouts });
151
134
  return { observer: this.observer, workouts };
152
135
  }
153
- close() {
136
+ getStartSettings() {
137
+ if (!this.startSettings) {
138
+ this.initStartSettings();
139
+ }
140
+ return this.startSettings;
141
+ }
142
+ setStartSettings(settings) {
143
+ this.startSettings = settings;
144
+ this.updateStartSettings();
154
145
  }
155
146
  onResize() {
156
147
  try {
@@ -212,69 +203,34 @@ let WorkoutListService = (() => {
212
203
  }
213
204
  return this.preloadObserver;
214
205
  }
215
- import(info, retry) {
206
+ import(info, props) {
216
207
  try {
208
+ const { card, showImportCards = true } = props !== null && props !== void 0 ? props : {};
217
209
  const files = Array.isArray(info) ? info : [info];
218
- const importCards = [];
219
- if (!retry) {
220
- files.forEach((file) => {
221
- if (!file)
222
- return;
223
- const card = this.addImportCard(file);
224
- importCards.push(card);
225
- this.emitLists('updated');
226
- });
227
- }
228
- else {
229
- importCards.push(retry);
230
- }
210
+ const importCards = showImportCards ? this.addImportCards(card, files) : [];
231
211
  files.forEach((file, idx) => __awaiter(this, void 0, void 0, function* () {
232
212
  if (!file)
233
213
  return;
234
- const importCard = importCards[idx];
214
+ const importCard = showImportCards ? importCards[idx] : null;
235
215
  try {
236
- const workout = yield parsers_1.WorkoutParser.parse(file);
237
- const existing = this.findCard(workout);
238
- if (existing) {
239
- existing.list.remove(existing.card);
240
- }
241
- else {
242
- this.items.push(workout);
243
- }
244
- const card = new WorkoutCard_1.WorkoutCard(workout, { list: this.myWorkouts });
245
- card.save();
246
- card.enableDelete();
247
- this.myWorkouts.add(card);
216
+ yield this._import(file);
248
217
  this.myWorkouts.remove(importCard);
249
- card.enableDelete(true);
250
218
  this.emitLists('updated');
251
219
  }
252
220
  catch (err) {
253
- importCard.setError(err);
221
+ if (importCard)
222
+ importCard.setError(err);
223
+ else
224
+ throw err;
254
225
  }
255
226
  }));
256
227
  }
257
228
  catch (err) {
229
+ if ((props === null || props === void 0 ? void 0 : props.showImportCards) === false)
230
+ throw err;
258
231
  this.logError(err, 'import', info);
259
232
  }
260
233
  }
261
- importSingle(info) {
262
- return __awaiter(this, void 0, void 0, function* () {
263
- const workout = yield parsers_1.WorkoutParser.parse(info);
264
- const existing = this.findCard(workout);
265
- if (existing) {
266
- existing.list.remove(existing.card);
267
- }
268
- else {
269
- this.items.push(workout);
270
- }
271
- const card = new WorkoutCard_1.WorkoutCard(workout, { list: this.myWorkouts });
272
- card.save();
273
- card.enableDelete(true);
274
- this.myWorkouts.add(card);
275
- return workout;
276
- });
277
- }
278
234
  addList(name) {
279
235
  const cnt = this.lists.length;
280
236
  const list = new cardlist_1.CardList(`${cnt}:${name}`, name);
@@ -347,9 +303,22 @@ let WorkoutListService = (() => {
347
303
  }
348
304
  }
349
305
  canDisplayStart() {
350
- const routes = (0, routes_1.getRouteList)();
306
+ const routes = this.getRouteList();
351
307
  return (0, valid_1.valid)(routes.getSelected());
352
308
  }
309
+ createSettingsList() {
310
+ const list = new cardlist_1.CardList('settings', 'Workouts');
311
+ list.add(new WorkoutImportCard_1.WorkoutImportCard());
312
+ const sorted = this.items
313
+ .sort((a, b) => a.name > b.name ? 1 : -1);
314
+ sorted.forEach(i => {
315
+ if (i.type === 'workout') {
316
+ const card = new WorkoutCard_1.WorkoutCard(i, { list });
317
+ list.add(card);
318
+ }
319
+ });
320
+ return list;
321
+ }
353
322
  resetLists() {
354
323
  var _a;
355
324
  (_a = this.getLists(false)) === null || _a === void 0 ? void 0 : _a.forEach(list => {
@@ -464,30 +433,67 @@ let WorkoutListService = (() => {
464
433
  this.emitLists('updated');
465
434
  return card;
466
435
  }
436
+ _import(info) {
437
+ return __awaiter(this, void 0, void 0, function* () {
438
+ const workout = yield parsers_1.WorkoutParser.parse(info);
439
+ const existing = this.findCard(workout);
440
+ if (existing) {
441
+ existing.list.remove(existing.card);
442
+ }
443
+ else {
444
+ this.items.push(workout);
445
+ }
446
+ const card = new WorkoutCard_1.WorkoutCard(workout, { list: this.myWorkouts });
447
+ card.save();
448
+ card.enableDelete(true);
449
+ this.myWorkouts.add(card);
450
+ return card;
451
+ });
452
+ }
453
+ addImportCards(retry, files) {
454
+ const importCards = [];
455
+ if (!retry) {
456
+ files.forEach((file) => {
457
+ if (!file)
458
+ return;
459
+ const card = this.addImportCard(file);
460
+ importCards.push(card);
461
+ this.emitLists('updated');
462
+ });
463
+ }
464
+ else {
465
+ importCards.push(retry);
466
+ }
467
+ return importCards;
468
+ }
467
469
  initStartSettings() {
468
470
  var _a;
469
- const userSettings = (0, settings_1.useUserSettings)();
471
+ const userSettings = this.getUserSettings();
470
472
  const useErgMode = userSettings.get('preferences.useErgMode', true);
471
473
  const ftp = (_a = userSettings.get('user', undefined)) === null || _a === void 0 ? void 0 : _a.ftp;
472
474
  this.startSettings = { ftp, useErgMode };
473
475
  }
474
476
  updateStartSettings() {
475
477
  var _a;
476
- const userSettings = (0, settings_1.useUserSettings)();
478
+ const userSettings = this.getUserSettings();
477
479
  userSettings.set('preferences.useErgMode', (_a = this.startSettings) === null || _a === void 0 ? void 0 : _a.useErgMode);
478
480
  }
479
- createSettingsList() {
480
- const list = new cardlist_1.CardList('settings', 'Workouts');
481
- list.add(new WorkoutImportCard_1.WorkoutImportCard());
482
- const sorted = this.items
483
- .sort((a, b) => a.name > b.name ? 1 : -1);
484
- sorted.forEach(i => {
485
- if (i.type === 'workout') {
486
- const card = new WorkoutCard_1.WorkoutCard(i, { list });
487
- list.add(card);
488
- }
481
+ getUserSettings() {
482
+ return (0, settings_1.useUserSettings)();
483
+ }
484
+ getRouteList() {
485
+ return (0, routes_1.useRouteList)();
486
+ }
487
+ emitStartEvent() {
488
+ process.nextTick(() => {
489
+ var _a;
490
+ (_a = this.observer) === null || _a === void 0 ? void 0 : _a.emit('started');
491
+ });
492
+ }
493
+ emitLoadedEvent() {
494
+ process.nextTick(() => {
495
+ this.emitLists('loaded');
489
496
  });
490
- return list;
491
497
  }
492
498
  };
493
499
  __setFunctionName(_classThis, "WorkoutListService");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.1.97",
3
+ "version": "1.1.98",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },