incyclist-services 1.9.7 → 1.9.8

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.
Files changed (55) hide show
  1. package/lib/cjs/api/rest/api.js +7 -3
  2. package/lib/cjs/api/rest/external.js +26 -0
  3. package/lib/cjs/apps/googleMaps/service.js +2 -0
  4. package/lib/cjs/apps/service.js +4 -1
  5. package/lib/cjs/devices/pairing/service.js +0 -1
  6. package/lib/cjs/i18n/countries/service.js +2 -2
  7. package/lib/cjs/routes/base/api/api.js +196 -0
  8. package/lib/cjs/routes/base/api/factory.js +93 -0
  9. package/lib/cjs/routes/base/api/index.js +14 -184
  10. package/lib/cjs/routes/base/parsers/tacx/TacxParser.js +1 -1
  11. package/lib/cjs/routes/free-ride/service.js +41 -0
  12. package/lib/cjs/routes/list/loaders/DBLoader.js +0 -1
  13. package/lib/cjs/routes/list/loaders/api.js +270 -176
  14. package/lib/cjs/routes/list/service.js +401 -357
  15. package/lib/cjs/ui/service.js +1 -2
  16. package/lib/cjs/utils/string.js +21 -1
  17. package/lib/esm/api/rest/api.js +7 -3
  18. package/lib/esm/api/rest/external.js +22 -0
  19. package/lib/esm/api/rest/incyclist copy.js +33 -0
  20. package/lib/esm/apps/googleMaps/service.js +2 -0
  21. package/lib/esm/apps/service.js +4 -1
  22. package/lib/esm/devices/configuration/model/add/index.js +1 -0
  23. package/lib/esm/devices/configuration/model/exclusion/index.js +1 -0
  24. package/lib/esm/devices/pairing/capability.js +1 -0
  25. package/lib/esm/devices/pairing/service.js +0 -1
  26. package/lib/esm/i18n/countries/service.js +2 -2
  27. package/lib/esm/routes/base/api/api.js +194 -0
  28. package/lib/esm/routes/base/api/factory.js +86 -0
  29. package/lib/esm/routes/base/api/index.js +2 -186
  30. package/lib/esm/routes/base/parsers/tacx/TacxParser.js +1 -1
  31. package/lib/esm/routes/free-ride/service.js +41 -0
  32. package/lib/esm/routes/list/loaders/DBLoader.js +0 -1
  33. package/lib/esm/routes/list/loaders/api.js +272 -174
  34. package/lib/esm/routes/list/service.js +401 -357
  35. package/lib/esm/ui/service.js +2 -3
  36. package/lib/esm/utils/string.js +18 -0
  37. package/lib/types/api/rest/api.d.ts +2 -2
  38. package/lib/types/api/rest/external.d.ts +7 -0
  39. package/lib/types/api/rest/incyclist copy.d.ts +7 -0
  40. package/lib/types/api/rest/types.d.ts +5 -3
  41. package/lib/types/apps/service.d.ts +1 -0
  42. package/lib/types/devices/configuration/model/add/index.d.ts +10 -0
  43. package/lib/types/devices/configuration/model/exclusion/index.d.ts +19 -0
  44. package/lib/types/devices/pairing/capability.d.ts +10 -0
  45. package/lib/types/routes/base/api/api.d.ts +23 -0
  46. package/lib/types/routes/base/api/factory.d.ts +7 -0
  47. package/lib/types/routes/base/api/index.d.ts +2 -26
  48. package/lib/types/routes/base/api/types.d.ts +10 -0
  49. package/lib/types/routes/base/parsers/tacx/TacxParser.d.ts +1 -1
  50. package/lib/types/routes/base/types/index.d.ts +1 -0
  51. package/lib/types/routes/free-ride/service.d.ts +6 -0
  52. package/lib/types/routes/list/loaders/api.d.ts +6 -3
  53. package/lib/types/routes/list/service.d.ts +37 -29
  54. package/lib/types/utils/string.d.ts +2 -0
  55. package/package.json +1 -1
@@ -53,7 +53,6 @@ const db_1 = require("./loaders/db");
53
53
  const valid_1 = require("../../utils/valid");
54
54
  const countries_1 = require("../../i18n/countries");
55
55
  const RouteListObserver_1 = require("./RouteListObserver");
56
- const api_3 = __importDefault(require("../base/api"));
57
56
  const ActiveImportCard_1 = require("./cards/ActiveImportCard");
58
57
  const selected_1 = require("./lists/selected");
59
58
  const alternatives_1 = require("./lists/alternatives");
@@ -70,6 +69,9 @@ const clone_1 = __importDefault(require("../../utils/clone"));
70
69
  const store_1 = require("../previews/store");
71
70
  const store_2 = require("../shapes/store");
72
71
  const service_2 = require("../library/service");
72
+ const factory_2 = require("../base/api/factory");
73
+ const utils_2 = require("../../utils");
74
+ const free_ride_1 = require("../free-ride");
73
75
  const SYNC_INTERVAL = 5 * 60 * 1000;
74
76
  const round = (value, digits) => {
75
77
  if (!Number.isFinite(value))
@@ -95,6 +97,8 @@ let RouteListService = (() => {
95
97
  let _getPreviewStore_decorators;
96
98
  let _getRouteShapeStore_decorators;
97
99
  let _getRouteLibraryScanner_decorators;
100
+ let _getIncyclistRoutesApi_decorators;
101
+ let _getFreeRideService_decorators;
98
102
  var RouteListService = class extends _classSuper {
99
103
  static { _classThis = this; }
100
104
  static {
@@ -108,6 +112,8 @@ let RouteListService = (() => {
108
112
  _getPreviewStore_decorators = [decorators_1.Injectable];
109
113
  _getRouteShapeStore_decorators = [decorators_1.Injectable];
110
114
  _getRouteLibraryScanner_decorators = [decorators_1.Injectable];
115
+ _getIncyclistRoutesApi_decorators = [decorators_1.Injectable];
116
+ _getFreeRideService_decorators = [decorators_1.Injectable];
111
117
  __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
112
118
  __esDecorate(this, null, _getRouteSyncFactory_decorators, { kind: "method", name: "getRouteSyncFactory", static: false, private: false, access: { has: obj => "getRouteSyncFactory" in obj, get: obj => obj.getRouteSyncFactory }, metadata: _metadata }, null, _instanceExtraInitializers);
113
119
  __esDecorate(this, null, _getAppState_decorators, { kind: "method", name: "getAppState", static: false, private: false, access: { has: obj => "getAppState" in obj, get: obj => obj.getAppState }, metadata: _metadata }, null, _instanceExtraInitializers);
@@ -117,6 +123,8 @@ let RouteListService = (() => {
117
123
  __esDecorate(this, null, _getPreviewStore_decorators, { kind: "method", name: "getPreviewStore", static: false, private: false, access: { has: obj => "getPreviewStore" in obj, get: obj => obj.getPreviewStore }, metadata: _metadata }, null, _instanceExtraInitializers);
118
124
  __esDecorate(this, null, _getRouteShapeStore_decorators, { kind: "method", name: "getRouteShapeStore", static: false, private: false, access: { has: obj => "getRouteShapeStore" in obj, get: obj => obj.getRouteShapeStore }, metadata: _metadata }, null, _instanceExtraInitializers);
119
125
  __esDecorate(this, null, _getRouteLibraryScanner_decorators, { kind: "method", name: "getRouteLibraryScanner", static: false, private: false, access: { has: obj => "getRouteLibraryScanner" in obj, get: obj => obj.getRouteLibraryScanner }, metadata: _metadata }, null, _instanceExtraInitializers);
126
+ __esDecorate(this, null, _getIncyclistRoutesApi_decorators, { kind: "method", name: "getIncyclistRoutesApi", static: false, private: false, access: { has: obj => "getIncyclistRoutesApi" in obj, get: obj => obj.getIncyclistRoutesApi }, metadata: _metadata }, null, _instanceExtraInitializers);
127
+ __esDecorate(this, null, _getFreeRideService_decorators, { kind: "method", name: "getFreeRideService", static: false, private: false, access: { has: obj => "getFreeRideService" in obj, get: obj => obj.getFreeRideService }, metadata: _metadata }, null, _instanceExtraInitializers);
120
128
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
121
129
  RouteListService = _classThis = _classDescriptor.value;
122
130
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
@@ -272,7 +280,7 @@ let RouteListService = (() => {
272
280
  }
273
281
  this.filters = (0, clone_1.default)(requestedFilters);
274
282
  const settingsFilter = (0, clone_1.default)(requestedFilters);
275
- const [C, U] = this.getUnitConverter().getUnitConversionShortcuts();
283
+ const [C] = this.getUnitConverter().getUnitConversionShortcuts();
276
284
  const Dist = (v) => {
277
285
  if (v?.value !== undefined && v.unit) {
278
286
  return C(v.value, 'distance', { from: v.unit, to: 'm' });
@@ -416,41 +424,6 @@ let RouteListService = (() => {
416
424
  isStillLoading() {
417
425
  return !!this.preloadObserver;
418
426
  }
419
- applyRouteTypeFilter(filters, routes) {
420
- if (filters.routeType) {
421
- const loop = filters.routeType === undefined || filters.routeType === 'Loop';
422
- const p2p = filters.routeType === undefined || filters.routeType === 'Point to Point';
423
- routes = routes.filter(r => (loop && r.isLoop) || (p2p && !r.isLoop));
424
- }
425
- return routes;
426
- }
427
- applySourceFilter(filters, routes) {
428
- routes = routes.filter(r => r.source === undefined || this.getAppsService().isEnabled(r.source, 'RouteDownload'));
429
- if (filters.routeSource) {
430
- const local = filters.routeSource === 'Local';
431
- const internal = filters.routeSource === 'Incyclist';
432
- const sources = filters.routeSource.split('|').map(s => this.getAppsService().getKey(s));
433
- routes = routes.filter(r => (r.source === undefined && !r.isLocal && internal) ||
434
- (r.source === undefined && r.isLocal && local) ||
435
- (r.source && !internal && sources.includes(r.source)));
436
- }
437
- return routes;
438
- }
439
- applyContentTypeFilter(filters, routes) {
440
- if (filters.contentType) {
441
- const video = filters.contentType === undefined || filters.contentType === 'Video';
442
- const gpx = filters.contentType === undefined || filters.contentType === 'GPX';
443
- routes = routes.filter(r => (video && r.hasVideo) || (gpx && !r.hasVideo));
444
- }
445
- return routes;
446
- }
447
- applyCountryFilter(filters, routes) {
448
- if (filters.country) {
449
- const iso = filters.country === 'Unknown' ? undefined : (0, countries_1.getCountries)().getIsoFromCountry(filters.country);
450
- routes = routes.filter(r => r.country === iso);
451
- }
452
- return routes;
453
- }
454
427
  getFilterValue(filters, scope, minMax) {
455
428
  if (!filters)
456
429
  return;
@@ -467,30 +440,6 @@ let RouteListService = (() => {
467
440
  }
468
441
  return;
469
442
  }
470
- applyElevationFilter(filters, routes) {
471
- const elevationMin = this.getFilterValue(filters, 'elevation', 'min');
472
- const elevationMax = this.getFilterValue(filters, 'elevation', 'max');
473
- if (elevationMin !== undefined)
474
- routes = routes.filter(r => r.elevation >= elevationMin);
475
- if (elevationMax !== undefined)
476
- routes = routes.filter(r => r.elevation <= elevationMax);
477
- return routes;
478
- }
479
- applyDistanceFilter(filters, routes) {
480
- const distanceMin = this.getFilterValue(filters, 'distance', 'min');
481
- const distanceMax = this.getFilterValue(filters, 'distance', 'max');
482
- if (distanceMin !== undefined)
483
- routes = routes.filter(r => r.distance >= distanceMin);
484
- if (distanceMax !== undefined)
485
- routes = routes.filter(r => r.distance <= distanceMax);
486
- return routes;
487
- }
488
- applyTitleFilter(filters, routes) {
489
- if (filters.title?.length) {
490
- routes = routes.filter(r => r.title?.toUpperCase()?.includes(filters.title.toUpperCase()));
491
- }
492
- return routes;
493
- }
494
443
  stopSearch() {
495
444
  try {
496
445
  this.observer.reset();
@@ -515,21 +464,6 @@ let RouteListService = (() => {
515
464
  }
516
465
  return { countries, contentTypes, routeTypes, routeSources };
517
466
  }
518
- getRoutesForFilterOptions(filters, excludeKey) {
519
- const activeFilters = { ...filters, [excludeKey]: undefined };
520
- let routes = this.getAllSearchCards().map(c => c.getDisplayProperties());
521
- if (!activeFilters.includeDeleted) {
522
- routes = routes.filter(r => !r?.isDeleted);
523
- }
524
- routes = this.applyTitleFilter(activeFilters, routes);
525
- routes = this.applyDistanceFilter(activeFilters, routes);
526
- routes = this.applyElevationFilter(activeFilters, routes);
527
- routes = this.applyCountryFilter(activeFilters, routes);
528
- routes = this.applyContentTypeFilter(activeFilters, routes);
529
- routes = this.applyRouteTypeFilter(activeFilters, routes);
530
- routes = this.applySourceFilter(activeFilters, routes);
531
- return routes;
532
- }
533
467
  onResize() {
534
468
  try {
535
469
  this.resetCards();
@@ -545,7 +479,7 @@ let RouteListService = (() => {
545
479
  card.setInitialized(true);
546
480
  });
547
481
  setTimeout(() => {
548
- list.getCards().forEach((card, idx) => {
482
+ list.getCards().forEach((card) => {
549
483
  card.setVisible(true);
550
484
  });
551
485
  }, 100);
@@ -602,28 +536,6 @@ let RouteListService = (() => {
602
536
  }
603
537
  return this.preloadObserver;
604
538
  }
605
- createRoutesLogEntry(includeDetails = false) {
606
- try {
607
- const log = {
608
- counts: {
609
- myRoutes: this.myRoutes.length,
610
- selected: this.selectedRoutes.length,
611
- alternatives: this.alternatives.length
612
- }
613
- };
614
- if (includeDetails) {
615
- log.titles = {};
616
- const getTitleLog = (list) => list?.getCards()?.map(r => r.getTitle()).join(',');
617
- log.titles.myRoutes = getTitleLog(this.myRoutes);
618
- log.titles.selected = getTitleLog(this.selectedRoutes);
619
- log.titles.alternaties = getTitleLog(this.alternatives);
620
- }
621
- return log;
622
- }
623
- catch (err) {
624
- this.logError(err, 'createRoutesLogEntry');
625
- }
626
- }
627
539
  getLists(forUi = true) {
628
540
  try {
629
541
  if (forUi && (!this.initialized))
@@ -692,16 +604,6 @@ let RouteListService = (() => {
692
604
  this.logError(err, 'loadRouteShape', { id });
693
605
  }
694
606
  }
695
- backfillRouteShape(route) {
696
- if (!route?.details || this.getRouteShapeStore().get(route.description?.id))
697
- return;
698
- this.getRouteShapeStore().backfill(route)
699
- .then(added => {
700
- if (added)
701
- this.getCard(route.description.id)?.emitUpdate();
702
- })
703
- .catch(err => this.logError(err, 'backfillRouteShape', { id: route.description?.id }));
704
- }
705
607
  getRouteDescription(id) {
706
608
  try {
707
609
  if (!id)
@@ -731,11 +633,369 @@ let RouteListService = (() => {
731
633
  this.rideRoute = { source: selected, route, appliedLevel: level };
732
634
  this.logNoiseStats(selected);
733
635
  }
734
- return this.rideRoute.route;
636
+ return this.rideRoute.route;
637
+ }
638
+ getAppliedSmoothingLevel() {
639
+ this.getRideRoute();
640
+ return this.rideRoute?.appliedLevel ?? 0;
641
+ }
642
+ async getSelectedRouteDetails() {
643
+ try {
644
+ const selected = this.getSelected();
645
+ if (selected.details)
646
+ return selected.details;
647
+ return this.getRouteDetails(selected.description.id);
648
+ }
649
+ catch (err) {
650
+ this.logError(err, 'getSelectedRouteDetails');
651
+ }
652
+ }
653
+ unselect() {
654
+ this.selectedRoute = null;
655
+ this.startSettings = null;
656
+ this.sessionSmoothingLevel = undefined;
657
+ this.rideRoute = undefined;
658
+ this.observer?.emit('selected', null);
659
+ }
660
+ select(route) {
661
+ this.selectedRoute = route;
662
+ this.observer?.emit('selected', route);
663
+ }
664
+ selectCard(card) {
665
+ this.selectedRoute = card.getData();
666
+ }
667
+ unselectCard(card) {
668
+ if (this.selectedRoute === card.getData())
669
+ this.selectedRoute = undefined;
670
+ }
671
+ import(info, props) {
672
+ try {
673
+ const files = Array.isArray(info) ? info : [info];
674
+ const importCards = [];
675
+ const { retry, importId, observer } = props ?? {};
676
+ if (!retry && !importId) {
677
+ files.forEach((file) => {
678
+ if (!file)
679
+ return;
680
+ const card = this.addImportCard(file);
681
+ importCards.push(card);
682
+ this.emitLists('updated');
683
+ });
684
+ }
685
+ else if (retry) {
686
+ importCards.push(retry);
687
+ }
688
+ files.forEach((file, idx) => {
689
+ const importCard = importId ? null : importCards[idx];
690
+ this.importOneFile(file, importCard, importId, observer).catch(err => { this.logError(err, 'import'); });
691
+ });
692
+ }
693
+ catch (err) {
694
+ this.logError(err, 'import', info);
695
+ }
696
+ }
697
+ pauseListUpdates() {
698
+ this.isListUpdatePaused = true;
699
+ }
700
+ resumeListUpdates() {
701
+ this.isListUpdatePaused = false;
702
+ }
703
+ emitLists(event, props) {
704
+ if (this.isListUpdatePaused)
705
+ return;
706
+ try {
707
+ const { log, source = 'user' } = props ?? {};
708
+ if (this.currentView === 'grid' || this.currentView === 'list') {
709
+ const d = this.searchAgain();
710
+ this.observer.emit(event, d, source);
711
+ return;
712
+ }
713
+ if (log) {
714
+ const logs = this.createRoutesLogEntry(true) ?? {};
715
+ this.logEvent({ message: `RoutesList ${event}`, ...logs });
716
+ }
717
+ const lists = this.getLists();
718
+ if (this.observer)
719
+ this.observer.emit(event, lists, source);
720
+ }
721
+ catch (err) {
722
+ this.logError(err, 'emitLists', event);
723
+ }
724
+ }
725
+ getCard(id) {
726
+ const res = this.findCard(id);
727
+ return res?.card;
728
+ }
729
+ addCardAgain(card) {
730
+ const route = card.getData();
731
+ const list = this.selectList(route);
732
+ list.add(card);
733
+ card.enableDelete(list.getId() === 'myRoutes');
734
+ card.setList(list);
735
+ this.emitLists('updated', { log: true });
736
+ }
737
+ existsBySourceUri(uri) {
738
+ try {
739
+ return this.routes.some(r => r.description?.sourceTreeUri === uri ||
740
+ r.description?.videoUrl === uri);
741
+ }
742
+ catch (err) {
743
+ this.logError(err, 'existsBySourceUri', { uri });
744
+ return false;
745
+ }
746
+ }
747
+ getBySourceUri(uri) {
748
+ try {
749
+ return this.routes.find(r => r.description?.sourceTreeUri === uri ||
750
+ r.description?.videoUrl === uri);
751
+ }
752
+ catch (err) {
753
+ this.logError(err, 'getBySourceUri', { uri });
754
+ }
755
+ }
756
+ isFreeRideSupported() {
757
+ return this.getFreeRideService().isInitialized();
758
+ }
759
+ addRoute(route, source = 'system') {
760
+ const existing = source === 'system' ? this.getRoute(route.description.id) :
761
+ this.routes.find(r => r.description?.id === route.description.id);
762
+ if (existing) {
763
+ const wasDeleted = existing.description?.isDeleted;
764
+ existing.replace(route);
765
+ if (source === 'system' || (!wasDeleted && this.hasAttachedCard(existing))) {
766
+ return;
767
+ }
768
+ route = existing;
769
+ }
770
+ else {
771
+ this.routes.push(route);
772
+ }
773
+ if (route.description?.isDeleted) {
774
+ return;
775
+ }
776
+ if (!route.description?.isDeleted) {
777
+ if (source === 'user') {
778
+ this.logEvent({ message: 'route added', route: route.description.title, source: route.description.source });
779
+ }
780
+ if (!route.description.country) {
781
+ this.logEvent({ message: 'route update required (country)', route: route.title });
782
+ route.updateCountryFromPoints()
783
+ .then((updated) => {
784
+ if (updated) {
785
+ this.logEvent({ message: 'route updated (country)', route: route.title, country: route.description?.country });
786
+ const saved = this.db.save(route, false);
787
+ const cardInfo = this.findCard(route);
788
+ cardInfo?.card?.emitUpdate();
789
+ return saved;
790
+ }
791
+ })
792
+ .catch(err => { this.logError(err, 'addRoute'); });
793
+ }
794
+ }
795
+ const list = this.selectList(route);
796
+ const card = new RouteCard_1.RouteCard(route, { list });
797
+ this.cardLookup[route.description.id] = { card, list };
798
+ card.verify();
799
+ list.add(card);
800
+ if (list.getId() === 'myRoutes')
801
+ card.enableDelete(true);
802
+ this.emitLists('updated', { source: source === 'user' ? 'user' : 'system' });
803
+ }
804
+ forgetRoute(target) {
805
+ const id = typeof target === 'string' ? target : target?.description?.id;
806
+ if (!id)
807
+ return;
808
+ const card = this.cardLookup[id]?.card;
809
+ this.routes = this.routes.filter(r => r.description?.id !== id);
810
+ delete this.cardLookup[id];
811
+ this.cardPropsCache.delete(id);
812
+ if (card)
813
+ this.cardPropsSubscribed.delete(card);
814
+ this.sortedSearchCache = undefined;
815
+ }
816
+ async createPreview(descr) {
817
+ try {
818
+ const routesApi = this.getIncyclistRoutesApi().create();
819
+ const res = await Promise.allSettled([
820
+ routesApi.getRoutePreview(descr.id),
821
+ routesApi.getRoutePreview(descr.originalName || descr.title)
822
+ ]);
823
+ const previewUrl = (res[0].status === 'fulfilled' ? res[0].value : undefined) ??
824
+ (res[1].status === 'fulfilled' ? res[1].value : undefined);
825
+ if (previewUrl) {
826
+ descr.previewUrl = previewUrl;
827
+ return;
828
+ }
829
+ this.logEvent({ message: 'preview not found', title: descr.originalName || descr.title, id: descr.id });
830
+ }
831
+ catch (err) {
832
+ this.logError(err, 'createPreview');
833
+ }
834
+ return new Promise(done => {
835
+ this.createPreviewQueue.push({ descr, done });
836
+ this.processPreviewQueue();
837
+ });
838
+ }
839
+ findCard(target) {
840
+ try {
841
+ let id;
842
+ let legacyId;
843
+ if (typeof target === 'string') {
844
+ id = target;
845
+ }
846
+ else {
847
+ const route = target;
848
+ id = route?.description?.id;
849
+ legacyId = route?.description?.legacyId;
850
+ }
851
+ if (!id && !legacyId) {
852
+ return;
853
+ }
854
+ const res = this.cardLookup[id];
855
+ if (res?.card) {
856
+ return res;
857
+ }
858
+ let card = this.myRoutes.getCards().find(c => c.getData()?.description?.id === id || c.getData()?.description?.legacyId === id);
859
+ if (card)
860
+ return { card, list: this.myRoutes };
861
+ if (legacyId) {
862
+ const legacyCard = this.myRoutes.getCards().find(c => c.getData()?.description?.id === legacyId);
863
+ if (legacyCard) {
864
+ this.myRoutes.remove(legacyCard);
865
+ const idx = this.routes.findIndex(r => r?.description?.id === legacyId && !r?.description?.isDeleted);
866
+ if (idx !== -1) {
867
+ this.routes.splice(idx, 1);
868
+ }
869
+ return;
870
+ }
871
+ }
872
+ const lists = [this.selectedRoutes, this.alternatives, ...this.custom ?? []];
873
+ for (const list of lists) {
874
+ card = list.getCards().find(c => c.getData()?.description?.id === id);
875
+ if (card)
876
+ return { card, list };
877
+ }
878
+ }
879
+ catch (err) {
880
+ this.logError(err, 'findCard', { target });
881
+ }
882
+ }
883
+ getExternalApiProviders() {
884
+ const obj = this.getUserSettings().getValue('routes.servers', null);
885
+ if (!obj)
886
+ return null;
887
+ return new Map(Object.entries(obj));
888
+ }
889
+ addExternalApiProvider(key, url) {
890
+ this.getUserSettings().set(`routes.servers.${key}`, url);
891
+ }
892
+ deleteExternalApiProvider(key) {
893
+ this.getUserSettings().set(`routes.servers.${key}`, null);
894
+ }
895
+ applyRouteTypeFilter(filters, routes) {
896
+ if (filters.routeType) {
897
+ const loop = filters.routeType === undefined || filters.routeType === 'Loop';
898
+ const p2p = filters.routeType === undefined || filters.routeType === 'Point to Point';
899
+ routes = routes.filter(r => (loop && r.isLoop) || (p2p && !r.isLoop));
900
+ }
901
+ return routes;
902
+ }
903
+ applySourceFilter(filters, routes) {
904
+ if (filters.routeSource) {
905
+ const local = filters.routeSource === 'Local';
906
+ const internal = filters.routeSource === 'Incyclist';
907
+ const sources = new Set(filters.routeSource.split('|').map(utils_2.pascalCase));
908
+ routes = routes.filter(r => (r.source === undefined && !r.isLocal && internal) ||
909
+ (r.source === undefined && r.isLocal && local) ||
910
+ (r.source && !internal && sources.has((0, utils_2.pascalCase)(r.source))));
911
+ }
912
+ return routes;
913
+ }
914
+ applyContentTypeFilter(filters, routes) {
915
+ if (filters.contentType) {
916
+ const video = filters.contentType === undefined || filters.contentType === 'Video';
917
+ const gpx = filters.contentType === undefined || filters.contentType === 'GPX';
918
+ routes = routes.filter(r => (video && r.hasVideo) || (gpx && !r.hasVideo));
919
+ }
920
+ return routes;
921
+ }
922
+ applyCountryFilter(filters, routes) {
923
+ if (filters.country) {
924
+ const iso = filters.country === 'Unknown' ? undefined : (0, countries_1.getCountries)().getIsoFromCountry(filters.country);
925
+ routes = routes.filter(r => r.country === iso);
926
+ }
927
+ return routes;
928
+ }
929
+ applyElevationFilter(filters, routes) {
930
+ const elevationMin = this.getFilterValue(filters, 'elevation', 'min');
931
+ const elevationMax = this.getFilterValue(filters, 'elevation', 'max');
932
+ if (elevationMin !== undefined)
933
+ routes = routes.filter(r => r.elevation >= elevationMin);
934
+ if (elevationMax !== undefined)
935
+ routes = routes.filter(r => r.elevation <= elevationMax);
936
+ return routes;
937
+ }
938
+ applyDistanceFilter(filters, routes) {
939
+ const distanceMin = this.getFilterValue(filters, 'distance', 'min');
940
+ const distanceMax = this.getFilterValue(filters, 'distance', 'max');
941
+ if (distanceMin !== undefined)
942
+ routes = routes.filter(r => r.distance >= distanceMin);
943
+ if (distanceMax !== undefined)
944
+ routes = routes.filter(r => r.distance <= distanceMax);
945
+ return routes;
946
+ }
947
+ applyTitleFilter(filters, routes) {
948
+ if (filters.title?.length) {
949
+ routes = routes.filter(r => r.title?.toUpperCase()?.includes(filters.title.toUpperCase()));
950
+ }
951
+ return routes;
952
+ }
953
+ getRoutesForFilterOptions(filters, excludeKey) {
954
+ const activeFilters = { ...filters, [excludeKey]: undefined };
955
+ let routes = this.getAllSearchCards().map(c => c.getDisplayProperties());
956
+ if (!activeFilters.includeDeleted) {
957
+ routes = routes.filter(r => !r?.isDeleted);
958
+ }
959
+ routes = this.applyTitleFilter(activeFilters, routes);
960
+ routes = this.applyDistanceFilter(activeFilters, routes);
961
+ routes = this.applyElevationFilter(activeFilters, routes);
962
+ routes = this.applyCountryFilter(activeFilters, routes);
963
+ routes = this.applyContentTypeFilter(activeFilters, routes);
964
+ routes = this.applyRouteTypeFilter(activeFilters, routes);
965
+ routes = this.applySourceFilter(activeFilters, routes);
966
+ return routes;
967
+ }
968
+ createRoutesLogEntry(includeDetails = false) {
969
+ try {
970
+ const log = {
971
+ counts: {
972
+ myRoutes: this.myRoutes.length,
973
+ selected: this.selectedRoutes.length,
974
+ alternatives: this.alternatives.length
975
+ }
976
+ };
977
+ if (includeDetails) {
978
+ log.titles = {};
979
+ const getTitleLog = (list) => list?.getCards()?.map(r => r.getTitle()).join(',');
980
+ log.titles.myRoutes = getTitleLog(this.myRoutes);
981
+ log.titles.selected = getTitleLog(this.selectedRoutes);
982
+ log.titles.alternaties = getTitleLog(this.alternatives);
983
+ }
984
+ return log;
985
+ }
986
+ catch (err) {
987
+ this.logError(err, 'createRoutesLogEntry');
988
+ }
735
989
  }
736
- getAppliedSmoothingLevel() {
737
- this.getRideRoute();
738
- return this.rideRoute?.appliedLevel ?? 0;
990
+ backfillRouteShape(route) {
991
+ if (!route?.details || this.getRouteShapeStore().get(route.description?.id))
992
+ return;
993
+ this.getRouteShapeStore().backfill(route)
994
+ .then(added => {
995
+ if (added)
996
+ this.getCard(route.description.id)?.emitUpdate();
997
+ })
998
+ .catch(err => this.logError(err, 'backfillRouteShape', { id: route.description?.id }));
739
999
  }
740
1000
  logNoiseStats(route) {
741
1001
  try {
@@ -791,61 +1051,6 @@ let RouteListService = (() => {
791
1051
  const level = settings?.smoothingLevel;
792
1052
  return Number.isFinite(level) ? level : 0;
793
1053
  }
794
- async getSelectedRouteDetails() {
795
- try {
796
- const selected = this.getSelected();
797
- if (selected.details)
798
- return selected.details;
799
- return this.getRouteDetails(selected.description.id);
800
- }
801
- catch (err) {
802
- this.logError(err, 'getSelectedRouteDetails');
803
- }
804
- }
805
- unselect() {
806
- this.selectedRoute = null;
807
- this.startSettings = null;
808
- this.sessionSmoothingLevel = undefined;
809
- this.rideRoute = undefined;
810
- this.observer?.emit('selected', null);
811
- }
812
- select(route) {
813
- this.selectedRoute = route;
814
- this.observer?.emit('selected', route);
815
- }
816
- selectCard(card) {
817
- this.selectedRoute = card.getData();
818
- }
819
- unselectCard(card) {
820
- if (this.selectedRoute === card.getData())
821
- this.selectedRoute = undefined;
822
- }
823
- import(info, props) {
824
- try {
825
- const files = Array.isArray(info) ? info : [info];
826
- const importCards = [];
827
- const { retry, importId, observer } = props ?? {};
828
- if (!retry && !importId) {
829
- files.forEach((file) => {
830
- if (!file)
831
- return;
832
- const card = this.addImportCard(file);
833
- importCards.push(card);
834
- this.emitLists('updated');
835
- });
836
- }
837
- else if (retry) {
838
- importCards.push(retry);
839
- }
840
- files.forEach((file, idx) => {
841
- const importCard = importId ? null : importCards[idx];
842
- this.importOneFile(file, importCard, importId, observer).catch(err => { this.logError(err, 'import'); });
843
- });
844
- }
845
- catch (err) {
846
- this.logError(err, 'import', info);
847
- }
848
- }
849
1054
  async importOneFile(file, importCard, importId, observer) {
850
1055
  if (!file)
851
1056
  return;
@@ -867,46 +1072,6 @@ let RouteListService = (() => {
867
1072
  importCard.setError(err);
868
1073
  }
869
1074
  }
870
- pauseListUpdates() {
871
- this.isListUpdatePaused = true;
872
- }
873
- resumeListUpdates() {
874
- this.isListUpdatePaused = false;
875
- }
876
- emitLists(event, props) {
877
- if (this.isListUpdatePaused)
878
- return;
879
- try {
880
- const { log, source = 'user' } = props ?? {};
881
- if (this.currentView === 'grid' || this.currentView === 'list') {
882
- const d = this.searchAgain();
883
- this.observer.emit(event, d, source);
884
- return;
885
- }
886
- if (log) {
887
- const logs = this.createRoutesLogEntry(true) ?? {};
888
- this.logEvent({ message: `RoutesList ${event}`, ...logs });
889
- }
890
- const lists = this.getLists();
891
- if (this.observer)
892
- this.observer.emit(event, lists, source);
893
- }
894
- catch (err) {
895
- this.logError(err, 'emitLists', event);
896
- }
897
- }
898
- getCard(id) {
899
- const res = this.findCard(id);
900
- return res?.card;
901
- }
902
- addCardAgain(card) {
903
- const route = card.getData();
904
- const list = this.selectList(route);
905
- list.add(card);
906
- card.enableDelete(list.getId() === 'myRoutes');
907
- card.setList(list);
908
- this.emitLists('updated', { log: true });
909
- }
910
1075
  addImportCard(file) {
911
1076
  const card = new ActiveImportCard_1.ActiveImportCard(file);
912
1077
  this.myRoutes.addImport(card);
@@ -933,17 +1098,29 @@ let RouteListService = (() => {
933
1098
  }
934
1099
  getFilterRouteSources(filters = {}) {
935
1100
  const options = ['Local', 'Incyclist'];
1101
+ const apps = this.getAllAppSources();
1102
+ const external = this.getAllExternalRouteSources();
936
1103
  this.getRoutesForFilterOptions(filters, 'routeSource').forEach(r => {
937
- const source = r.source;
938
- if (!source)
1104
+ const source = (0, utils_2.pascalCase)(r.source);
1105
+ if (!source || options.includes(source))
939
1106
  return;
940
- const option = this.getAppsService().getName(source);
941
- if (option && !options.includes(option)) {
942
- options.push(option);
1107
+ if (apps.includes(source) || external.includes(source)) {
1108
+ options.push(source);
943
1109
  }
944
1110
  });
945
1111
  return options;
946
1112
  }
1113
+ getAllAppSources() {
1114
+ const apps = this.getAppsService().getAvailableServices('RouteDownload') ?? [];
1115
+ return apps.map(utils_2.pascalCase);
1116
+ }
1117
+ getAllExternalRouteSources() {
1118
+ const external = this.getUserSettings().getValue('routes.servers', null);
1119
+ if (!external)
1120
+ return [];
1121
+ const keys = Object.keys(external) ?? [];
1122
+ return keys.map(utils_2.pascalCase);
1123
+ }
947
1124
  getFilterCountries(filters = {}) {
948
1125
  try {
949
1126
  const countries = [];
@@ -969,93 +1146,19 @@ let RouteListService = (() => {
969
1146
  return [];
970
1147
  }
971
1148
  }
972
- existsBySourceUri(uri) {
973
- try {
974
- return this.routes.some(r => r.description?.sourceTreeUri === uri ||
975
- r.description?.videoUrl === uri);
976
- }
977
- catch (err) {
978
- this.logError(err, 'existsBySourceUri', { uri });
979
- return false;
980
- }
981
- }
982
- getBySourceUri(uri) {
983
- try {
984
- return this.routes.find(r => r.description?.sourceTreeUri === uri ||
985
- r.description?.videoUrl === uri);
986
- }
987
- catch (err) {
988
- this.logError(err, 'getBySourceUri', { uri });
989
- }
990
- }
991
- addRoute(route, source = 'system') {
992
- const existing = source === 'system' ? this.getRoute(route.description.id) :
993
- this.routes.find(r => r.description?.id === route.description.id);
994
- if (existing) {
995
- const wasDeleted = existing.description?.isDeleted;
996
- existing.replace(route);
997
- if (source === 'system' || (!wasDeleted && this.hasAttachedCard(existing)))
998
- return;
999
- route = existing;
1000
- }
1001
- else {
1002
- this.routes.push(route);
1003
- }
1004
- if (route.description?.isDeleted) {
1005
- return;
1006
- }
1007
- if (!route.description?.isDeleted) {
1008
- if (source === 'user') {
1009
- this.logEvent({ message: 'route added', route: route.description.title, source: route.description.source });
1010
- }
1011
- if (!route.description.country) {
1012
- this.logEvent({ message: 'route update required (country)', route: route.title });
1013
- route.updateCountryFromPoints()
1014
- .then((updated) => {
1015
- if (updated) {
1016
- this.logEvent({ message: 'route updated (country)', route: route.title, country: route.description?.country });
1017
- const saved = this.db.save(route, false);
1018
- const cardInfo = this.findCard(route);
1019
- cardInfo?.card?.emitUpdate();
1020
- return saved;
1021
- }
1022
- })
1023
- .catch(err => { this.logError(err, 'addRoute'); });
1024
- }
1025
- }
1026
- const list = this.selectList(route);
1027
- const card = new RouteCard_1.RouteCard(route, { list });
1028
- this.cardLookup[route.description.id] = { card, list };
1029
- card.verify();
1030
- list.add(card);
1031
- if (list.getId() === 'myRoutes')
1032
- card.enableDelete(true);
1033
- this.emitLists('updated', { source: source === 'user' ? 'user' : 'system' });
1034
- }
1035
1149
  hasAttachedCard(route) {
1036
1150
  const id = route.description?.id;
1037
1151
  return [this.myRoutes, this.selectedRoutes, this.alternatives, ...(this.custom ?? [])]
1038
1152
  .some(l => l?.getCards()?.some(c => c.getData?.()?.description?.id === id));
1039
1153
  }
1040
- forgetRoute(target) {
1041
- const id = typeof target === 'string' ? target : target?.description?.id;
1042
- if (!id)
1043
- return;
1044
- const card = this.cardLookup[id]?.card;
1045
- this.routes = this.routes.filter(r => r.description?.id !== id);
1046
- delete this.cardLookup[id];
1047
- this.cardPropsCache.delete(id);
1048
- if (card)
1049
- this.cardPropsSubscribed.delete(card);
1050
- this.sortedSearchCache = undefined;
1051
- }
1052
1154
  async addFromApi(route) {
1053
1155
  this.addRoute(route, 'system');
1054
1156
  }
1055
- async update(route, source = 'user') {
1157
+ update(route, _source = 'user') {
1056
1158
  const existing = this.findCard(route);
1057
1159
  if (existing)
1058
1160
  existing.card.updateRoute(route);
1161
+ return Promise.resolve();
1059
1162
  }
1060
1163
  async loadRoutes() {
1061
1164
  await this.loadRoutesFromRepo();
@@ -1286,7 +1389,9 @@ let RouteListService = (() => {
1286
1389
  selectList(route) {
1287
1390
  const description = route.description;
1288
1391
  if (description.source) {
1289
- return this.selectListForSource(route);
1392
+ const apps = this.getAllAppSources();
1393
+ if (apps.includes((0, utils_2.pascalCase)(description.source)))
1394
+ return this.selectListForSource(route);
1290
1395
  }
1291
1396
  if (!description.hasVideo) {
1292
1397
  return this.selectListForGPX(route);
@@ -1333,29 +1438,6 @@ let RouteListService = (() => {
1333
1438
  this.custom.push(customList);
1334
1439
  return customList;
1335
1440
  }
1336
- async createPreview(descr) {
1337
- try {
1338
- const routesApi = api_3.default.getInstance();
1339
- const res = await Promise.allSettled([
1340
- routesApi.getRoutePreview(descr.id),
1341
- routesApi.getRoutePreview(descr.originalName || descr.title)
1342
- ]);
1343
- const previewUrl = (res[0].status === 'fulfilled' ? res[0].value : undefined) ??
1344
- (res[1].status === 'fulfilled' ? res[1].value : undefined);
1345
- if (previewUrl) {
1346
- descr.previewUrl = previewUrl;
1347
- return;
1348
- }
1349
- this.logEvent({ message: 'preview not found', title: descr.originalName || descr.title, id: descr.id });
1350
- }
1351
- catch (err) {
1352
- this.logError(err, 'createPreview');
1353
- }
1354
- return new Promise(done => {
1355
- this.createPreviewQueue.push({ descr, done });
1356
- this.processPreviewQueue();
1357
- });
1358
- }
1359
1441
  async checkExistingPreviewFiles(descr) {
1360
1442
  const videoUrl = descr.videoUrl || descr.downloadUrl;
1361
1443
  const path = (0, api_1.getBindings)().path;
@@ -1465,50 +1547,6 @@ let RouteListService = (() => {
1465
1547
  }
1466
1548
  return this.previewProcessing;
1467
1549
  }
1468
- findCard(target) {
1469
- try {
1470
- let id;
1471
- let legacyId;
1472
- if (typeof target === 'string') {
1473
- id = target;
1474
- }
1475
- else {
1476
- const route = target;
1477
- id = route?.description?.id;
1478
- legacyId = route?.description?.legacyId;
1479
- }
1480
- if (!id && !legacyId) {
1481
- return;
1482
- }
1483
- const res = this.cardLookup[id];
1484
- if (res?.card) {
1485
- return res;
1486
- }
1487
- let card = this.myRoutes.getCards().find(c => c.getData()?.description?.id === id || c.getData()?.description?.legacyId === id);
1488
- if (card)
1489
- return { card, list: this.myRoutes };
1490
- if (legacyId) {
1491
- const legacyCard = this.myRoutes.getCards().find(c => c.getData()?.description?.id === legacyId);
1492
- if (legacyCard) {
1493
- this.myRoutes.remove(legacyCard);
1494
- const idx = this.routes.findIndex(r => r?.description?.id === legacyId && !r?.description?.isDeleted);
1495
- if (idx !== -1) {
1496
- this.routes.splice(idx, 1);
1497
- }
1498
- return;
1499
- }
1500
- }
1501
- const lists = [this.selectedRoutes, this.alternatives, ...this.custom ?? []];
1502
- for (const list of lists) {
1503
- card = list.getCards().find(c => c.getData()?.description?.id === id);
1504
- if (card)
1505
- return { card, list };
1506
- }
1507
- }
1508
- catch (err) {
1509
- this.logError(err, 'findCard', { target });
1510
- }
1511
- }
1512
1550
  resetCards() {
1513
1551
  const lists = this.getLists() ?? [];
1514
1552
  lists.forEach(list => {
@@ -1676,6 +1714,12 @@ let RouteListService = (() => {
1676
1714
  getRouteLibraryScanner() {
1677
1715
  return (0, service_2.useRouteLibraryScanner)();
1678
1716
  }
1717
+ getIncyclistRoutesApi() {
1718
+ return (0, factory_2.useIncyclistRoutesApi)();
1719
+ }
1720
+ getFreeRideService() {
1721
+ return (0, free_ride_1.useFreeRideService)();
1722
+ }
1679
1723
  reset() {
1680
1724
  super.reset();
1681
1725
  if (this.syncInfo?.iv) {