incyclist-services 1.3.3 → 1.3.5

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.
@@ -28,6 +28,7 @@ export declare class ActivityRideService extends IncyclistService {
28
28
  speed: number;
29
29
  };
30
30
  protected saveObserver: PromiseObserver<boolean>;
31
+ protected isSaveDone: boolean;
31
32
  protected statsCalculator: ActivityStatsCalculator;
32
33
  protected durationCalculator: ActivityDuration;
33
34
  protected deviceDataHandler: any;
@@ -52,7 +53,7 @@ export declare class ActivityRideService extends IncyclistService {
52
53
  pause(autoResume?: boolean): void;
53
54
  resume(requester?: 'user' | 'system'): void;
54
55
  getDashboardDisplayProperties(): any[];
55
- getActivitySummaryDisplayProperties(): void;
56
+ getActivitySummaryDisplayProperties(): {};
56
57
  getActivity(): ActivityDetails;
57
58
  setTitle(title: string): void;
58
59
  delete(): Promise<void>;
@@ -72,6 +73,7 @@ export declare class ActivityRideService extends IncyclistService {
72
73
  protected getRepo(): ActivitiesRepository;
73
74
  protected createLogRecord(): ActivityLogRecord;
74
75
  protected createActivity(requestedId?: string): ActivityDetails;
76
+ protected changeTitle(newTitle: string): void;
75
77
  protected updateActivityState(): void;
76
78
  protected getTotalDistance(): number;
77
79
  protected getTotalElevation(): number;
@@ -91,5 +93,6 @@ export declare class ActivityRideService extends IncyclistService {
91
93
  protected getDeviceConfiguration(): import("../../devices").DeviceConfigurationService;
92
94
  protected getActivityUploadFactory(): ActivityUploadFactory;
93
95
  protected getActivityConverterfactory(): ActivityConverterFactory;
96
+ protected getFileSystemBinding(): import("../../api/fs").IFileSystem;
94
97
  }
95
98
  export declare const useActivityRide: () => ActivityRideService;
@@ -64,6 +64,7 @@ const route_2 = require("../../routes/base/model/route");
64
64
  const stats_1 = require("./stats");
65
65
  const duration_1 = require("./duration");
66
66
  const upload_1 = require("../upload");
67
+ const api_1 = require("../../api");
67
68
  const SAVE_INTERVAL = 5000;
68
69
  let ActivityRideService = (() => {
69
70
  let _classDecorators = [types_1.Singleton];
@@ -116,6 +117,7 @@ let ActivityRideService = (() => {
116
117
  this.state = 'active';
117
118
  this.tsStart = Date.now();
118
119
  this.tsPauseStart = undefined;
120
+ this.isSaveDone = false;
119
121
  this.logEvent({ message: 'activity started' });
120
122
  this.startWorker();
121
123
  this.emit('started');
@@ -158,6 +160,7 @@ let ActivityRideService = (() => {
158
160
  this.logEvent({ message: 'activity resumed', requester });
159
161
  this.updateActivityTime();
160
162
  this._save();
163
+ this.isSaveDone = false;
161
164
  }
162
165
  getDashboardDisplayProperties() {
163
166
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
@@ -223,6 +226,26 @@ let ActivityRideService = (() => {
223
226
  }
224
227
  }
225
228
  getActivitySummaryDisplayProperties() {
229
+ var _a, _b;
230
+ try {
231
+ const route = (0, routes_1.useRouteList)().getSelected();
232
+ const showSave = this.activity !== undefined && !this.isSaveDone;
233
+ const showContinue = this.state !== 'completed';
234
+ const showMap = (_a = route === null || route === void 0 ? void 0 : route.description) === null || _a === void 0 ? void 0 : _a.hasGpx;
235
+ const preview = showMap ? undefined : (_b = route === null || route === void 0 ? void 0 : route.description) === null || _b === void 0 ? void 0 : _b.previewUrl;
236
+ const props = {
237
+ activity: this.activity,
238
+ showSave,
239
+ showContinue,
240
+ showMap,
241
+ preview
242
+ };
243
+ return props;
244
+ }
245
+ catch (err) {
246
+ this.logError(err, 'getActivitySummaryDisplayProperties()');
247
+ return {};
248
+ }
226
249
  }
227
250
  getActivity() {
228
251
  return this.activity;
@@ -244,12 +267,14 @@ let ActivityRideService = (() => {
244
267
  });
245
268
  }
246
269
  save() {
270
+ console.log('~~~ ActivityRide.save', this.saveObserver !== undefined, this.isSaveDone);
247
271
  if (this.saveObserver) {
248
272
  return this.saveObserver;
249
273
  }
250
274
  const emit = (event, ...args) => {
251
275
  if (this.saveObserver)
252
276
  this.saveObserver.emit(event, ...args);
277
+ console.log('~~~ ActivityRide.emit', event, args, this.saveObserver !== undefined, this.isSaveDone);
253
278
  };
254
279
  const run = () => __awaiter(this, void 0, void 0, function* () {
255
280
  let success = false;
@@ -272,6 +297,7 @@ let ActivityRideService = (() => {
272
297
  uploadSuccess = yield this.upload(format);
273
298
  }
274
299
  success = convertSuccess && uploadSuccess;
300
+ this.isSaveDone = true;
275
301
  }
276
302
  catch (err) {
277
303
  success = false;
@@ -283,6 +309,7 @@ let ActivityRideService = (() => {
283
309
  return success;
284
310
  });
285
311
  this.saveObserver = new observer_1.PromiseObserver(run());
312
+ console.log('~~~ ActivityRide.save returns', this.saveObserver !== undefined, this.isSaveDone);
286
313
  return this.saveObserver;
287
314
  }
288
315
  getObserver() {
@@ -385,19 +412,39 @@ let ActivityRideService = (() => {
385
412
  }
386
413
  convert(format) {
387
414
  return __awaiter(this, void 0, void 0, function* () {
388
- this.saveObserver.emit('convert.start', format);
415
+ const emit = (event, ...args) => {
416
+ if (this.saveObserver)
417
+ this.saveObserver.emit(event, ...args);
418
+ else {
419
+ try {
420
+ throw new Error('');
421
+ }
422
+ catch (err) {
423
+ console.log('~~~ WARN: emitting on non existing observer', event.args, err.stack);
424
+ }
425
+ }
426
+ };
427
+ const fs = this.getFileSystemBinding();
428
+ emit('convert.start', format);
389
429
  try {
390
- base_1.ActivityConverter.convert(this.activity, format);
391
- this.saveObserver.emit('convert.done', format, true);
392
- if (format.toLowerCase() === 'fit')
393
- this.activity.fitFileName = this.activity.fileName.replace('json', 'fit');
394
- if (format.toLowerCase() === 'tcx')
395
- this.activity.tcxFileName = this.activity.fileName.replace('json', 'tcx');
430
+ let data;
431
+ data = yield base_1.ActivityConverter.convert(this.activity, format);
432
+ emit('convert.done', format, true);
433
+ if (format.toLowerCase() === 'fit') {
434
+ const fileName = this.activity.fileName.replace('json', 'fit');
435
+ yield fs.writeFile(fileName, Buffer.from(data));
436
+ this.activity.fitFileName = fileName;
437
+ }
438
+ if (format.toLowerCase() === 'tcx') {
439
+ const fileName = this.activity.fileName.replace('json', 'tcx');
440
+ yield fs.writeFile(fileName, Buffer.from(data));
441
+ this.activity.tcxFileName = fileName;
442
+ }
396
443
  yield this._save();
397
444
  return true;
398
445
  }
399
446
  catch (err) {
400
- this.saveObserver.emit('convert.error', format, err);
447
+ emit('convert.error', format, err);
401
448
  return false;
402
449
  }
403
450
  });
@@ -405,9 +452,9 @@ let ActivityRideService = (() => {
405
452
  upload(format) {
406
453
  return __awaiter(this, void 0, void 0, function* () {
407
454
  const factory = this.getActivityUploadFactory();
408
- this.saveObserver.emit('upload.start');
455
+ this.saveObserver.emit('upload.start', format);
409
456
  try {
410
- yield factory.upload(this.activity, format);
457
+ yield factory.upload(this.activity, format.toLowerCase());
411
458
  this.saveObserver.emit('upload.done', format, true);
412
459
  return true;
413
460
  }
@@ -521,6 +568,11 @@ let ActivityRideService = (() => {
521
568
  };
522
569
  return activity;
523
570
  }
571
+ changeTitle(newTitle) {
572
+ if (!(newTitle === null || newTitle === void 0 ? void 0 : newTitle.length))
573
+ return;
574
+ this.activity.title = newTitle;
575
+ }
524
576
  updateActivityState() {
525
577
  var _a, _b;
526
578
  if (this.state !== 'active')
@@ -711,6 +763,9 @@ let ActivityRideService = (() => {
711
763
  getActivityConverterfactory() {
712
764
  return new base_1.ActivityConverterFactory();
713
765
  }
766
+ getFileSystemBinding() {
767
+ return (0, api_1.getBindings)().fs;
768
+ }
714
769
  };
715
770
  __setFunctionName(_classThis, "ActivityRideService");
716
771
  (() => {
@@ -162,7 +162,7 @@ let StravaUpload = (() => {
162
162
  this.logger.logEvent({ message: 'Strava Upload', format });
163
163
  const fileName = activity[`${format}FileName`];
164
164
  const res = yield this.getApi().upload(fileName, {
165
- name: activity.name,
165
+ name: activity.title,
166
166
  description: '',
167
167
  format: this.getStravaFormat(format)
168
168
  });
@@ -211,7 +211,7 @@ let StravaUpload = (() => {
211
211
  this.getUserSettings().set('user.auth.strava', {
212
212
  accesstoken: this.config.accessToken,
213
213
  refreshToken: this.config.refreshToken,
214
- expiration: this.config.expiration.toUTCString()
214
+ expiration: this.config.expiration.toISOString()
215
215
  });
216
216
  }
217
217
  catch (err) {
@@ -27,12 +27,15 @@ class AppApiBase {
27
27
  }
28
28
  postForm(form) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
+ var _a, _b;
30
31
  try {
31
32
  const fp = this.getFormBinding();
32
- return yield fp.post(form);
33
+ const response = yield fp.post(form);
34
+ if ((_a = response.data) === null || _a === void 0 ? void 0 : _a.data)
35
+ response.data = (_b = response.data) === null || _b === void 0 ? void 0 : _b.data;
36
+ return response;
33
37
  }
34
38
  catch (err) {
35
- console.log('~~~ POST ERROR', err);
36
39
  throw err;
37
40
  }
38
41
  });
@@ -104,7 +104,7 @@ class StravaApi extends base_1.AppApiBase {
104
104
  }
105
105
  createUpload(request) {
106
106
  return __awaiter(this, void 0, void 0, function* () {
107
- var _a, _b, _c;
107
+ var _a, _b, _c, _d, _e;
108
108
  const reqOpts = {
109
109
  headers: {
110
110
  Authorization: 'Bearer ' + this.config.accessToken
@@ -116,7 +116,7 @@ class StravaApi extends base_1.AppApiBase {
116
116
  return response.data;
117
117
  }
118
118
  else {
119
- throw new Error(((_c = (_b = (_a = response.error) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) || response.error.message || response.error || `HTTP error ${response.status}`);
119
+ throw new Error(((_c = (_b = (_a = response.error) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) || ((_e = (_d = response.error) === null || _d === void 0 ? void 0 : _d.response) === null || _e === void 0 ? void 0 : _e.message) || response.error.message || `HTTP error ${response.status}`);
120
120
  }
121
121
  });
122
122
  }
@@ -60,7 +60,7 @@ class VeloHeroApi extends base_1.AppApiBase {
60
60
  }
61
61
  upload(fileName, props) {
62
62
  return __awaiter(this, void 0, void 0, function* () {
63
- var _a, _b, _c, _d, _e;
63
+ var _a, _b, _c, _d, _e, _f, _g;
64
64
  if (!this.loginResponse && (!(props === null || props === void 0 ? void 0 : props.username) && !(props === null || props === void 0 ? void 0 : props.password))) {
65
65
  throw new Error('not authenticated');
66
66
  }
@@ -78,7 +78,8 @@ class VeloHeroApi extends base_1.AppApiBase {
78
78
  return true;
79
79
  }
80
80
  else {
81
- throw new Error(((_e = (_d = (_c = response.error) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error) || response.error.message || response.error || `HTTP error ${response.status}`);
81
+ const errMessage = ((_e = (_d = (_c = response.error) === null || _c === void 0 ? void 0 : _c.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error) || ((_g = (_f = response.error) === null || _f === void 0 ? void 0 : _f.response) === null || _g === void 0 ? void 0 : _g.message) || response.error.message;
82
+ throw new Error(errMessage || `HTTP error ${response.status}`);
82
83
  }
83
84
  });
84
85
  }
@@ -67,7 +67,7 @@ class GPXParser extends xml_1.XMLParser {
67
67
  const point = {
68
68
  lat: Number(gpxPt.lat),
69
69
  lng: Number(gpxPt.lon),
70
- elevation: gpxPt.ele ? Number(gpxPt.ele) : undefined,
70
+ elevation: gpxPt.ele ? Number(gpxPt.ele) : prev === null || prev === void 0 ? void 0 : prev.elevation,
71
71
  routeDistance: 0,
72
72
  distance: 0
73
73
  };
@@ -254,7 +254,7 @@ const getNextPosition = (route, props) => {
254
254
  if (props.routeDistance === undefined && (props.prev === undefined || props.prev.routeDistance === undefined)) {
255
255
  return;
256
256
  }
257
- let pPrev = props.prev || Object.assign(Object.assign({}, points[0]), { lap: 1 });
257
+ let pPrev = Object.assign({}, (props.prev || Object.assign(Object.assign({}, points[0]), { lap: 1 })));
258
258
  const distance = props.distance !== undefined ? props.distance : props.routeDistance - getLapTotalDistance(route, pPrev);
259
259
  const targetRouteDistance = props.routeDistance !== undefined ? props.routeDistance : getLapTotalDistance(route, pPrev) + distance;
260
260
  let point, p;
@@ -375,6 +375,7 @@ function updatePoint(pPrev, point, props, p, distance, targetRouteInLap, route,
375
375
  const distanceToPrev = targetRouteInLap - pPrev.routeDistance;
376
376
  pDest = utils_1.geo.getPointBetween(pPrev, p, distanceToPrev);
377
377
  point.cnt = pPrev.cnt;
378
+ point.slope = pPrev.slope;
378
379
  }
379
380
  point.lat = pDest.lat;
380
381
  point.lng = pDest.lng;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },