incyclist-services 1.5.3 → 1.5.4

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.
@@ -164,9 +164,8 @@ let GpxDisplayService = (() => {
164
164
  const rideView = this.getUserSettings().get('preferences.rideView', 'sv');
165
165
  if (rideView === 'sv') {
166
166
  const updatePending = (Date.now() - ((_b = this.tsPrevSVUpdate) !== null && _b !== void 0 ? _b : 0)) > this.getDefaultUpdateFrequency();
167
- const stillBusy = (!this.tsPositionUpdateConfirmed && (Date.now() - ((_c = this.tsPrevSVUpdate) !== null && _c !== void 0 ? _c : 0)) < 500) || (Date.now() - this.tsLastSVEvent) < this.getMinimalPause();
167
+ const stillBusy = (!this.tsPositionUpdateConfirmed && (Date.now() - ((_c = this.tsPrevSVUpdate) !== null && _c !== void 0 ? _c : 0)) < 500) || (Date.now() - ((_d = this.tsLastSVEvent) !== null && _d !== void 0 ? _d : 0)) < this.getMinimalPause();
168
168
  const updatePossible = this.tsPositionUpdateConfirmed && (Date.now() - this.tsLastSVEvent) > this.getBestCaseUpdateFrequency();
169
- console.log('# service.onPositionUpdate', rideView, this.tsLastSVEvent - ((_d = this.tsPrevSVUpdate) !== null && _d !== void 0 ? _d : 0), Object.assign({ stillBusy, updatePossible, updatePending }, state));
170
169
  if ((!stillBusy || !this.tsPrevSVUpdate) && (updatePending || updatePossible)) {
171
170
  if (position) {
172
171
  const freq = this.tsPrevSVUpdate ? Date.now() - this.tsPrevSVUpdate : undefined;
@@ -180,6 +179,17 @@ let GpxDisplayService = (() => {
180
179
  delete this.tsLastSVEvent;
181
180
  }
182
181
  }
182
+ else {
183
+ const duration = this.tsPrevSVUpdate ? Date.now() - this.tsPrevSVUpdate : undefined;
184
+ if (stillBusy) {
185
+ this.logEvent({ message: 'street view position update skipped', reason: 'busy', duration });
186
+ if (duration > 10000) {
187
+ delete this.tsPrevSVUpdate;
188
+ delete this.tsPositionUpdateConfirmed;
189
+ delete this.tsLastSVEvent;
190
+ }
191
+ }
192
+ }
183
193
  }
184
194
  else {
185
195
  console.log('# position update', this.position);
@@ -37,4 +37,5 @@ export declare class WorkoutCard extends BaseCard implements Card<Workout> {
37
37
  protected getRepo(): WorkoutsDbLoader;
38
38
  protected emitUpdate(): void;
39
39
  protected isSelected(): boolean;
40
+ protected getRouteList(): import("../../../routes").RouteListService;
40
41
  }
@@ -1,4 +1,38 @@
1
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
+ };
2
36
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
37
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
38
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -18,200 +52,223 @@ const settings_1 = require("../../../settings");
18
52
  const service_1 = require("../service");
19
53
  const utils_1 = require("../../../utils");
20
54
  const valid_1 = require("../../../utils/valid");
21
- class WorkoutCard extends base_1.BaseCard {
22
- constructor(workout, props) {
23
- super();
24
- this.cardObserver = new observer_1.Observer();
25
- const { list } = props || {};
26
- this.workout = workout;
27
- this.list = list;
28
- this.deleteable = true;
29
- this.initialized = false;
30
- this.logger = new gd_eventlog_1.EventLogger('WorkoutCard');
31
- }
32
- openSettings() {
33
- var _a, _b;
34
- let settings, canStart, duration, ftpRequired, categories = [], category, canStartWorkoutOnly;
35
- try {
36
- const service = (0, service_1.useWorkoutList)();
37
- canStart = service.canDisplayStart();
38
- canStartWorkoutOnly = !canStart;
39
- duration = this.calculateDuration();
40
- ftpRequired = (0, valid_1.valid)(this.workout.steps.find(s => {
41
- var _a;
42
- return (s.type == 'step' && ((_a = s.power) === null || _a === void 0 ? void 0 : _a.type) === 'pct of FTP') ||
43
- (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'); })));
44
- }));
45
- settings = (_a = service.getStartSettings()) !== null && _a !== void 0 ? _a : {};
46
- categories = ((_b = service.getLists()) !== null && _b !== void 0 ? _b : []).map(l => l.getTitle());
47
- category = this.list.getTitle();
48
- }
49
- catch (err) {
50
- this.logError(err, 'openSettings');
51
- }
52
- return { settings, ftpRequired, canStart, canStartWorkoutOnly, duration, categories, category };
53
- }
54
- select(settings) {
55
- const service = (0, service_1.getWorkoutList)();
56
- service.selectCard(this);
57
- if (settings)
58
- service.setStartSettings(settings);
59
- this.emitUpdate();
60
- }
61
- unselect() {
62
- const service = (0, service_1.getWorkoutList)();
63
- service.unselect();
64
- this.emitUpdate();
65
- }
66
- move(targetListName) {
67
- if (!(targetListName === null || targetListName === void 0 ? void 0 : targetListName.length))
68
- return;
69
- const service = (0, service_1.getWorkoutList)();
70
- const newList = service.moveCard(this, this.list, targetListName);
71
- if (newList) {
72
- this.list = newList;
73
- }
74
- this.workout.category = { name: targetListName, index: newList === null || newList === void 0 ? void 0 : newList.length };
75
- this.save(true);
76
- }
77
- save() {
78
- return __awaiter(this, arguments, void 0, function* (enforce = false) {
79
- try {
80
- return yield this.getRepo().save(this.workout, enforce);
55
+ const routes_1 = require("../../../routes");
56
+ const decorators_1 = require("../../../base/decorators");
57
+ let WorkoutCard = (() => {
58
+ var _a;
59
+ let _classSuper = base_1.BaseCard;
60
+ let _instanceExtraInitializers = [];
61
+ let _getRouteList_decorators;
62
+ return _a = class WorkoutCard extends _classSuper {
63
+ constructor(workout, props) {
64
+ super();
65
+ this.workout = __runInitializers(this, _instanceExtraInitializers);
66
+ this.cardObserver = new observer_1.Observer();
67
+ const { list } = props || {};
68
+ this.workout = workout;
69
+ this.list = list;
70
+ this.deleteable = true;
71
+ this.initialized = false;
72
+ this.logger = new gd_eventlog_1.EventLogger('WorkoutCard');
81
73
  }
82
- catch (err) {
83
- this.logError(err, 'save');
74
+ openSettings() {
75
+ var _b, _c;
76
+ let settings, canStart, duration, ftpRequired, categories = [], category, canStartWorkoutOnly;
77
+ try {
78
+ const service = (0, service_1.useWorkoutList)();
79
+ canStart = service.canDisplayStart();
80
+ canStartWorkoutOnly = !canStart;
81
+ duration = this.calculateDuration();
82
+ ftpRequired = (0, valid_1.valid)(this.workout.steps.find(s => {
83
+ var _b;
84
+ return (s.type == 'step' && ((_b = s.power) === null || _b === void 0 ? void 0 : _b.type) === 'pct of FTP') ||
85
+ (s.type == 'segment' && (s === null || s === void 0 ? void 0 : s.steps.find(s => { var _b; return (s.type == 'step' && ((_b = s.power) === null || _b === void 0 ? void 0 : _b.type) === 'pct of FTP'); })));
86
+ }));
87
+ settings = (_b = service.getStartSettings()) !== null && _b !== void 0 ? _b : {};
88
+ categories = ((_c = service.getLists()) !== null && _c !== void 0 ? _c : []).map(l => l.getTitle());
89
+ category = this.list.getTitle();
90
+ }
91
+ catch (err) {
92
+ this.logError(err, 'openSettings');
93
+ }
94
+ return { settings, ftpRequired, canStart, canStartWorkoutOnly, duration, categories, category };
84
95
  }
85
- });
86
- }
87
- delete() {
88
- try {
89
- const service = (0, service_1.getWorkoutList)();
90
- service.unselectCard(this);
91
- if (this.deleteObserver)
92
- return this.deleteObserver;
93
- this.deleteObserver = new observer_1.PromiseObserver(this._delete());
94
- return this.deleteObserver;
95
- }
96
- catch (err) {
97
- this.logError(err, 'delete');
98
- }
99
- }
100
- getId() {
101
- return this.workout.id;
102
- }
103
- getTitle() {
104
- return this.workout.name;
105
- }
106
- update(workout) {
107
- if (!(0, valid_1.valid)(workout))
108
- return;
109
- try {
110
- this.workout = workout;
111
- this.save();
112
- this.emitUpdate();
113
- }
114
- catch (err) {
115
- this.logError(err, 'update');
116
- }
117
- }
118
- getData() {
119
- return this.workout;
120
- }
121
- getCardType() {
122
- return "Workout";
123
- }
124
- getDisplayProperties() {
125
- const userSettings = (0, settings_1.useUserSettings)();
126
- let user;
127
- try {
128
- user = userSettings.get('user', {});
129
- }
130
- catch (_a) {
131
- user = {};
132
- }
133
- const duration = this.calculateDuration();
134
- return { title: this.workout.name, workout: this.workout, ftp: user === null || user === void 0 ? void 0 : user.ftp, duration,
135
- canDelete: this.deleteable, visible: this.visible, selected: this.isSelected(),
136
- observer: this.cardObserver };
137
- }
138
- enableDelete(enabled = true) {
139
- this.deleteable = enabled;
140
- }
141
- canDelete() {
142
- return this.deleteable;
143
- }
144
- setVisible(visible) {
145
- try {
146
- const prev = this.visible;
147
- this.visible = visible;
148
- if (visible !== prev)
96
+ select(settings) {
97
+ const service = (0, service_1.getWorkoutList)();
98
+ service.selectCard(this);
99
+ if (settings)
100
+ service.setStartSettings(settings);
101
+ if (settings.noRoute) {
102
+ this.getRouteList().unselect();
103
+ }
149
104
  this.emitUpdate();
150
- }
151
- catch (err) {
152
- this.logError(err, 'setVisible');
153
- }
154
- }
155
- _delete() {
156
- return __awaiter(this, void 0, void 0, function* () {
157
- yield (0, utils_1.waitNextTick)();
158
- let deleted = false;
159
- try {
160
- this.deleteObserver.emit('started');
161
- yield this.getRepo().delete(this.workout);
162
- this.deleteFromUIList();
163
- (0, service_1.getWorkoutList)().emitLists('updated');
164
- deleted = true;
165
- }
166
- catch (_a) {
167
- deleted = false;
168
- }
169
- finally {
170
- this.deleteObserver.emit('done', deleted);
171
- (0, utils_1.waitNextTick)().then(() => {
172
- delete this.deleteObserver;
105
+ }
106
+ unselect() {
107
+ const service = (0, service_1.getWorkoutList)();
108
+ service.unselect();
109
+ this.emitUpdate();
110
+ }
111
+ move(targetListName) {
112
+ if (!(targetListName === null || targetListName === void 0 ? void 0 : targetListName.length))
113
+ return;
114
+ const service = (0, service_1.getWorkoutList)();
115
+ const newList = service.moveCard(this, this.list, targetListName);
116
+ if (newList) {
117
+ this.list = newList;
118
+ }
119
+ this.workout.category = { name: targetListName, index: newList === null || newList === void 0 ? void 0 : newList.length };
120
+ this.save(true);
121
+ }
122
+ save() {
123
+ return __awaiter(this, arguments, void 0, function* (enforce = false) {
124
+ try {
125
+ return yield this.getRepo().save(this.workout, enforce);
126
+ }
127
+ catch (err) {
128
+ this.logError(err, 'save');
129
+ }
173
130
  });
174
131
  }
175
- return deleted;
176
- });
177
- }
178
- calculateDuration() {
179
- const { duration } = this.workout;
180
- if (duration < 120)
181
- return `${duration.toFixed(0)}s`;
182
- if (duration % 60 === 0)
183
- return `${duration / 60}min`;
184
- const secVal = duration % 60;
185
- const minVal = (duration - secVal) / 60 % 60;
186
- const h = Math.floor((duration - secVal - minVal * 60) / 3600);
187
- const sec = secVal < 10 ? `0${secVal}` : secVal;
188
- const min = minVal < 10 ? `0${minVal}` : minVal;
189
- if (h > 0)
190
- return `${h}:${min}:${sec}`;
191
- else
192
- return `${min}:${sec}`;
193
- }
194
- deleteFromUIList() {
195
- if (this.list) {
196
- this.list.remove(this);
197
- }
198
- }
199
- logError(err, fn) {
200
- this.logger.logEvent({ message: 'error', error: err.message, fn, stack: err.stack });
201
- }
202
- getRepo() {
203
- return new db_1.WorkoutsDbLoader();
204
- }
205
- emitUpdate() {
206
- if (this.cardObserver)
207
- this.cardObserver.emit('update', this.getDisplayProperties());
208
- }
209
- isSelected() {
210
- const service = (0, service_1.getWorkoutList)();
211
- const selectedWorkout = service.getSelected();
212
- if ((selectedWorkout === null || selectedWorkout === void 0 ? void 0 : selectedWorkout.id) === this.workout.id)
213
- return true;
214
- return false;
215
- }
216
- }
132
+ delete() {
133
+ try {
134
+ const service = (0, service_1.getWorkoutList)();
135
+ service.unselectCard(this);
136
+ if (this.deleteObserver)
137
+ return this.deleteObserver;
138
+ this.deleteObserver = new observer_1.PromiseObserver(this._delete());
139
+ return this.deleteObserver;
140
+ }
141
+ catch (err) {
142
+ this.logError(err, 'delete');
143
+ }
144
+ }
145
+ getId() {
146
+ return this.workout.id;
147
+ }
148
+ getTitle() {
149
+ return this.workout.name;
150
+ }
151
+ update(workout) {
152
+ if (!(0, valid_1.valid)(workout))
153
+ return;
154
+ try {
155
+ this.workout = workout;
156
+ this.save();
157
+ this.emitUpdate();
158
+ }
159
+ catch (err) {
160
+ this.logError(err, 'update');
161
+ }
162
+ }
163
+ getData() {
164
+ return this.workout;
165
+ }
166
+ getCardType() {
167
+ return "Workout";
168
+ }
169
+ getDisplayProperties() {
170
+ const userSettings = (0, settings_1.useUserSettings)();
171
+ let user;
172
+ try {
173
+ user = userSettings.get('user', {});
174
+ }
175
+ catch (_b) {
176
+ user = {};
177
+ }
178
+ const duration = this.calculateDuration();
179
+ return { title: this.workout.name, workout: this.workout, ftp: user === null || user === void 0 ? void 0 : user.ftp, duration,
180
+ canDelete: this.deleteable, visible: this.visible, selected: this.isSelected(),
181
+ observer: this.cardObserver };
182
+ }
183
+ enableDelete(enabled = true) {
184
+ this.deleteable = enabled;
185
+ }
186
+ canDelete() {
187
+ return this.deleteable;
188
+ }
189
+ setVisible(visible) {
190
+ try {
191
+ const prev = this.visible;
192
+ this.visible = visible;
193
+ if (visible !== prev)
194
+ this.emitUpdate();
195
+ }
196
+ catch (err) {
197
+ this.logError(err, 'setVisible');
198
+ }
199
+ }
200
+ _delete() {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ yield (0, utils_1.waitNextTick)();
203
+ let deleted = false;
204
+ try {
205
+ this.deleteObserver.emit('started');
206
+ yield this.getRepo().delete(this.workout);
207
+ this.deleteFromUIList();
208
+ (0, service_1.getWorkoutList)().emitLists('updated');
209
+ deleted = true;
210
+ }
211
+ catch (_b) {
212
+ deleted = false;
213
+ }
214
+ finally {
215
+ this.deleteObserver.emit('done', deleted);
216
+ (0, utils_1.waitNextTick)().then(() => {
217
+ delete this.deleteObserver;
218
+ });
219
+ }
220
+ return deleted;
221
+ });
222
+ }
223
+ calculateDuration() {
224
+ const { duration } = this.workout;
225
+ if (duration < 120)
226
+ return `${duration.toFixed(0)}s`;
227
+ if (duration % 60 === 0)
228
+ return `${duration / 60}min`;
229
+ const secVal = duration % 60;
230
+ const minVal = (duration - secVal) / 60 % 60;
231
+ const h = Math.floor((duration - secVal - minVal * 60) / 3600);
232
+ const sec = secVal < 10 ? `0${secVal}` : secVal;
233
+ const min = minVal < 10 ? `0${minVal}` : minVal;
234
+ if (h > 0)
235
+ return `${h}:${min}:${sec}`;
236
+ else
237
+ return `${min}:${sec}`;
238
+ }
239
+ deleteFromUIList() {
240
+ if (this.list) {
241
+ this.list.remove(this);
242
+ }
243
+ }
244
+ logError(err, fn) {
245
+ this.logger.logEvent({ message: 'error', error: err.message, fn, stack: err.stack });
246
+ }
247
+ getRepo() {
248
+ return new db_1.WorkoutsDbLoader();
249
+ }
250
+ emitUpdate() {
251
+ if (this.cardObserver)
252
+ this.cardObserver.emit('update', this.getDisplayProperties());
253
+ }
254
+ isSelected() {
255
+ const service = (0, service_1.getWorkoutList)();
256
+ const selectedWorkout = service.getSelected();
257
+ if ((selectedWorkout === null || selectedWorkout === void 0 ? void 0 : selectedWorkout.id) === this.workout.id)
258
+ return true;
259
+ return false;
260
+ }
261
+ getRouteList() {
262
+ return (0, routes_1.useRouteList)();
263
+ }
264
+ },
265
+ (() => {
266
+ var _b;
267
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
268
+ _getRouteList_decorators = [decorators_1.Injectable];
269
+ __esDecorate(_a, null, _getRouteList_decorators, { kind: "method", name: "getRouteList", static: false, private: false, access: { has: obj => "getRouteList" in obj, get: obj => obj.getRouteList }, metadata: _metadata }, null, _instanceExtraInitializers);
270
+ if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
271
+ })(),
272
+ _a;
273
+ })();
217
274
  exports.WorkoutCard = WorkoutCard;
@@ -27,6 +27,7 @@ export interface ActiveImportProps {
27
27
  export interface WorkoutSettings {
28
28
  ftp?: number;
29
29
  useErgMode?: boolean;
30
+ noRoute?: boolean;
30
31
  }
31
32
  export interface WorkoutSettingsDisplayProps {
32
33
  settings: WorkoutSettings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.5.3",
3
+ "version": "1.5.4",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },