incyclist-services 1.0.59 → 1.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/devices/access/service.js +2 -1
- package/lib/devices/pairing/service.js +2 -2
- package/lib/routes/list/ImportCard.d.ts +8 -0
- package/lib/routes/list/ImportCard.js +11 -0
- package/lib/routes/list/service.d.ts +15 -3
- package/lib/routes/list/service.js +106 -22
- package/lib/routes/list/types.d.ts +11 -0
- package/package.json +2 -2
|
@@ -66,7 +66,7 @@ class DeviceAccessService extends events_1.default {
|
|
|
66
66
|
existing.state = state;
|
|
67
67
|
(0, merge_1.merge)(existing.properties || this.defaultProps, props);
|
|
68
68
|
this.emit('interface-changed', ifaceName, Object.assign({}, existing));
|
|
69
|
-
if (!existing.interface.isConnected()) {
|
|
69
|
+
if (!existing.interface.isConnected() && (props === null || props === void 0 ? void 0 : props.autoConnect)) {
|
|
70
70
|
this.emit('interface-changed', ifaceName, Object.assign(Object.assign({}, existing), { state: 'connecting' }));
|
|
71
71
|
const conected = yield this.connect(ifaceName);
|
|
72
72
|
const state = conected ? 'connected' : 'disconnected';
|
|
@@ -175,6 +175,7 @@ class DeviceAccessService extends events_1.default {
|
|
|
175
175
|
this.connect(name); });
|
|
176
176
|
return;
|
|
177
177
|
}
|
|
178
|
+
console.log('~~~ DEBUG:connect if', ifaceName, this.interfaces[ifaceName]);
|
|
178
179
|
if (((_a = this.interfaces[ifaceName]) === null || _a === void 0 ? void 0 : _a.enabled) === false)
|
|
179
180
|
return;
|
|
180
181
|
const impl = this.getInterface(ifaceName);
|
|
@@ -371,7 +371,7 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
371
371
|
const current = getInterfaceSettings(ifName, prev);
|
|
372
372
|
if (settings.enabled && !current.enabled) {
|
|
373
373
|
const { port, protocol } = settings;
|
|
374
|
-
this.access.enableInterface(ifName, undefined, { port: Number(port), protocol });
|
|
374
|
+
this.access.enableInterface(ifName, undefined, { port: Number(port), protocol, autoConnect: true });
|
|
375
375
|
this.selectFromInterface(ifName);
|
|
376
376
|
}
|
|
377
377
|
else if (!settings.enabled && current.enabled) {
|
|
@@ -670,7 +670,7 @@ class DevicePairingService extends service_2.IncyclistService {
|
|
|
670
670
|
}
|
|
671
671
|
connectInterface(name) {
|
|
672
672
|
try {
|
|
673
|
-
this.access.enableInterface(name);
|
|
673
|
+
this.access.enableInterface(name, undefined, { autoConnect: true });
|
|
674
674
|
}
|
|
675
675
|
catch (err) {
|
|
676
676
|
this.logError(err, 'enableInterface');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportCard = void 0;
|
|
4
|
+
class ImportCard {
|
|
5
|
+
constructor(state, title) {
|
|
6
|
+
this.type = 'import';
|
|
7
|
+
this.state = state;
|
|
8
|
+
this.title = title || 'Import Route';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ImportCard = ImportCard;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Page, InternalRouteListState, List, RouteInfo, Route, RouteListEntry, RouteListStartProps, RouteListData, RouteStartSettings, onRouteStatusUpdateCallback, onCarouselStateChangedCallback, RoutesDB } from "./types";
|
|
1
|
+
import { Page, InternalRouteListState, List, RouteInfo, Route, RouteListEntry, RouteListStartProps, RouteListData, RouteStartSettings, onRouteStatusUpdateCallback, onCarouselStateChangedCallback, RoutesDB, FreeRideSettings } from "./types";
|
|
2
2
|
import IncyclistRoutesApi from "../base/api";
|
|
3
3
|
import { RouteApiDescription, RouteApiDetail } from "../base/api/types";
|
|
4
4
|
import { IncyclistService } from "../../base/service";
|
|
5
5
|
import { IJsonRepositoryBinding, JsonRepository } from "../../api";
|
|
6
|
+
import { LatLng } from "../../utils/geo";
|
|
6
7
|
type filterFn = (route: Route, idx: number, obj: Route[]) => boolean;
|
|
7
8
|
export declare class RouteListService extends IncyclistService {
|
|
8
9
|
protected static _instance: any;
|
|
@@ -30,14 +31,21 @@ export declare class RouteListService extends IncyclistService {
|
|
|
30
31
|
onResize(pageId: string): void;
|
|
31
32
|
openStartSettings(r: RouteInfo | string): RouteStartSettings;
|
|
32
33
|
cancelStartSettings(r: RouteInfo | string): {};
|
|
34
|
+
acceptStartSettings(r: RouteInfo | string, startSettings: RouteStartSettings): {};
|
|
35
|
+
openFreeRideSettings(): FreeRideSettings;
|
|
36
|
+
cancelFreeRideSettings(): void;
|
|
37
|
+
changeFreeRideSettings(props: {
|
|
38
|
+
position: LatLng;
|
|
39
|
+
}): void;
|
|
40
|
+
acceptFreeRideSettings(options: any): void;
|
|
41
|
+
import(pageId: any, files: any): void;
|
|
33
42
|
setCardUpdateHandler(pageId: string, r: RouteInfo | string, list: List, idx: number, onRouteStateChanged: onRouteStatusUpdateCallback, onCarouselStateChanged: onCarouselStateChangedCallback): void;
|
|
34
43
|
onCarouselInitialized(pageId: string, list: List, startIdx: number, visibleSize: number): void;
|
|
35
44
|
onCarouselUpdated(pageId: string, list: List, startIdx: number, visibleSize: number): void;
|
|
36
|
-
acceptStartSettings(r: RouteInfo | string, startSettings: RouteStartSettings): {};
|
|
37
45
|
getSelectedRoute(): RouteApiDetail;
|
|
38
46
|
getStartSettings(routeId?: string): RouteStartSettings;
|
|
39
47
|
startRide(r?: RouteInfo | string): {};
|
|
40
|
-
stopRide(r?: RouteInfo | string):
|
|
48
|
+
stopRide(r?: RouteInfo | string): void;
|
|
41
49
|
startDownload(routeId: any, onStatusUpdate: any): void;
|
|
42
50
|
cancelDownload(routeId: any): void;
|
|
43
51
|
protected _preload(carouselSize?: number, detailsOnly?: boolean): Promise<void>;
|
|
@@ -47,6 +55,10 @@ export declare class RouteListService extends IncyclistService {
|
|
|
47
55
|
realityFactor: number;
|
|
48
56
|
segment: any;
|
|
49
57
|
};
|
|
58
|
+
protected loadFreeRideSettingsFromUserSettings(): {
|
|
59
|
+
position: LatLng;
|
|
60
|
+
};
|
|
61
|
+
protected writeFreeRideSettingsToUserSettings(position: LatLng): void;
|
|
50
62
|
protected writeStartSettingsToUserSettings(route: Route, startSettings: RouteStartSettings): void;
|
|
51
63
|
protected writeStartSettings(route: Route, startSettings: RouteStartSettings): void;
|
|
52
64
|
protected getUserSetting(key: string, defValue?: any): any;
|
|
@@ -21,6 +21,8 @@ const settings_1 = require("../../settings");
|
|
|
21
21
|
const api_2 = require("../../api");
|
|
22
22
|
const clone_1 = __importDefault(require("../../utils/clone"));
|
|
23
23
|
const FreeRideCard_1 = require("./FreeRideCard");
|
|
24
|
+
const ImportCard_1 = require("./ImportCard");
|
|
25
|
+
const utils_1 = require("../../utils");
|
|
24
26
|
class RouteListService extends service_1.IncyclistService {
|
|
25
27
|
static getInstance(binding) {
|
|
26
28
|
if (!RouteListService._instance)
|
|
@@ -131,6 +133,7 @@ class RouteListService extends service_1.IncyclistService {
|
|
|
131
133
|
try {
|
|
132
134
|
if (!route)
|
|
133
135
|
return {};
|
|
136
|
+
this.state.selectedType = 'route';
|
|
134
137
|
let startSettings = route.startSettings;
|
|
135
138
|
this.stopRide();
|
|
136
139
|
if (!startSettings) {
|
|
@@ -146,6 +149,7 @@ class RouteListService extends service_1.IncyclistService {
|
|
|
146
149
|
}
|
|
147
150
|
cancelStartSettings(r) {
|
|
148
151
|
var _a;
|
|
152
|
+
delete this.state.selectedType;
|
|
149
153
|
const route = this.getRouteFromStartProps(r);
|
|
150
154
|
try {
|
|
151
155
|
route.startState = 'idle';
|
|
@@ -156,6 +160,61 @@ class RouteListService extends service_1.IncyclistService {
|
|
|
156
160
|
return {};
|
|
157
161
|
}
|
|
158
162
|
}
|
|
163
|
+
acceptStartSettings(r, startSettings) {
|
|
164
|
+
var _a;
|
|
165
|
+
const route = this.getRouteFromStartProps(r);
|
|
166
|
+
try {
|
|
167
|
+
this.writeStartSettings(route, startSettings);
|
|
168
|
+
route.startState = 'selected';
|
|
169
|
+
}
|
|
170
|
+
catch (err) {
|
|
171
|
+
this.logError(err, 'acceptStartSettings', { info: { id: route === null || route === void 0 ? void 0 : route.id, title: (_a = route === null || route === void 0 ? void 0 : route.data) === null || _a === void 0 ? void 0 : _a.title } });
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
openFreeRideSettings() {
|
|
176
|
+
this.state.selectedType = 'free-ride';
|
|
177
|
+
try {
|
|
178
|
+
this.stopRide();
|
|
179
|
+
const settings = this.loadFreeRideSettingsFromUserSettings();
|
|
180
|
+
return settings;
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
this.logError(err, 'openFreeRideSettings');
|
|
184
|
+
return {};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
cancelFreeRideSettings() {
|
|
188
|
+
delete this.state.selectedType;
|
|
189
|
+
delete this.state.selectedPosition;
|
|
190
|
+
delete this.state.selectedOptions;
|
|
191
|
+
}
|
|
192
|
+
changeFreeRideSettings(props) {
|
|
193
|
+
const { position: pos } = props;
|
|
194
|
+
const position = utils_1.geo.getLatLng(pos);
|
|
195
|
+
this.state.selectedPosition = position;
|
|
196
|
+
this.writeFreeRideSettingsToUserSettings(position);
|
|
197
|
+
}
|
|
198
|
+
acceptFreeRideSettings(options) {
|
|
199
|
+
this.state.selectedOptions = options;
|
|
200
|
+
this.state.selectedType = 'free-ride';
|
|
201
|
+
}
|
|
202
|
+
import(pageId, files) {
|
|
203
|
+
console.log('~~~ import ', pageId, files);
|
|
204
|
+
const page = this.getPage(pageId);
|
|
205
|
+
console.log('~~~ import ', files, page);
|
|
206
|
+
const route = {
|
|
207
|
+
id: Date.now().toString(),
|
|
208
|
+
data: {
|
|
209
|
+
type: 'route',
|
|
210
|
+
id: Date.now().toString(),
|
|
211
|
+
state: 'prepared',
|
|
212
|
+
title: 'Test'
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
this.addRouteToList('myRoutes', route);
|
|
216
|
+
this.emitPageUpdate();
|
|
217
|
+
}
|
|
159
218
|
setCardUpdateHandler(pageId, r, list, idx, onRouteStateChanged, onCarouselStateChanged) {
|
|
160
219
|
const route = this.getRouteFromStartProps(r);
|
|
161
220
|
if (!route)
|
|
@@ -206,46 +265,51 @@ class RouteListService extends service_1.IncyclistService {
|
|
|
206
265
|
}
|
|
207
266
|
});
|
|
208
267
|
}
|
|
209
|
-
acceptStartSettings(r, startSettings) {
|
|
210
|
-
var _a;
|
|
211
|
-
const route = this.getRouteFromStartProps(r);
|
|
212
|
-
try {
|
|
213
|
-
this.writeStartSettings(route, startSettings);
|
|
214
|
-
route.startState = 'selected';
|
|
215
|
-
}
|
|
216
|
-
catch (err) {
|
|
217
|
-
this.logError(err, 'acceptStartSettings', { info: { id: route === null || route === void 0 ? void 0 : route.id, title: (_a = route === null || route === void 0 ? void 0 : route.data) === null || _a === void 0 ? void 0 : _a.title } });
|
|
218
|
-
return {};
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
268
|
getSelectedRoute() {
|
|
222
269
|
const route = this.getRoute(v => v.startState === 'selected');
|
|
223
270
|
return route === null || route === void 0 ? void 0 : route.details;
|
|
224
271
|
}
|
|
225
272
|
getStartSettings(routeId) {
|
|
226
|
-
|
|
227
|
-
|
|
273
|
+
console.log('~~ getStartSettings', this.state);
|
|
274
|
+
switch (this.state.selectedType) {
|
|
275
|
+
case 'free-ride':
|
|
276
|
+
return { type: 'free-ride', options: this.state.selectedOptions, position: this.state.selectedPosition };
|
|
277
|
+
break;
|
|
278
|
+
case 'route':
|
|
279
|
+
{
|
|
280
|
+
const route = routeId ? this.getRoute(routeId) : this.getRoute(v => v.startState === 'selected');
|
|
281
|
+
if (route)
|
|
282
|
+
return Object.assign({ type: 'route' }, route.startSettings);
|
|
283
|
+
}
|
|
284
|
+
break;
|
|
285
|
+
default:
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
228
288
|
}
|
|
229
289
|
startRide(r) {
|
|
230
290
|
var _a;
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
291
|
+
if (this.state.selectedType === 'route') {
|
|
292
|
+
const route = r ? this.getRoute(v => v.startState === 'selected') : this.getRouteFromStartProps(r);
|
|
293
|
+
try {
|
|
294
|
+
route.startState = 'started';
|
|
295
|
+
}
|
|
296
|
+
catch (err) {
|
|
297
|
+
this.logError(err, 'startRide', { info: { id: route === null || route === void 0 ? void 0 : route.id, title: (_a = route === null || route === void 0 ? void 0 : route.data) === null || _a === void 0 ? void 0 : _a.title } });
|
|
298
|
+
return {};
|
|
299
|
+
}
|
|
238
300
|
}
|
|
239
301
|
}
|
|
240
302
|
stopRide(r) {
|
|
241
303
|
var _a;
|
|
304
|
+
delete this.state.selectedType;
|
|
242
305
|
const route = r ? this.getRoute(v => v.startState === 'selected') : this.getRouteFromStartProps(r);
|
|
306
|
+
if (!route)
|
|
307
|
+
return;
|
|
243
308
|
try {
|
|
244
309
|
route.startState = 'idle';
|
|
245
310
|
}
|
|
246
311
|
catch (err) {
|
|
247
312
|
this.logError(err, 'stopRide', { info: { id: route === null || route === void 0 ? void 0 : route.id, title: (_a = route === null || route === void 0 ? void 0 : route.data) === null || _a === void 0 ? void 0 : _a.title } });
|
|
248
|
-
return {};
|
|
249
313
|
}
|
|
250
314
|
}
|
|
251
315
|
startDownload(routeId, onStatusUpdate) {
|
|
@@ -315,6 +379,21 @@ class RouteListService extends service_1.IncyclistService {
|
|
|
315
379
|
}
|
|
316
380
|
return { startPos, realityFactor, segment };
|
|
317
381
|
}
|
|
382
|
+
loadFreeRideSettingsFromUserSettings() {
|
|
383
|
+
let position;
|
|
384
|
+
const prevSetting = this.getUserSetting(`routeSelection.freeRide`, null);
|
|
385
|
+
if (prevSetting) {
|
|
386
|
+
position = prevSetting.position;
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
position = this.getUserSetting(`position`, null);
|
|
390
|
+
}
|
|
391
|
+
return { position };
|
|
392
|
+
}
|
|
393
|
+
writeFreeRideSettingsToUserSettings(position) {
|
|
394
|
+
const userSettings = (0, settings_1.useUserSettings)();
|
|
395
|
+
userSettings.set('routeSelection.freeRide', { position });
|
|
396
|
+
}
|
|
318
397
|
writeStartSettingsToUserSettings(route, startSettings) {
|
|
319
398
|
var _a;
|
|
320
399
|
const routeId = route.id;
|
|
@@ -364,6 +443,11 @@ class RouteListService extends service_1.IncyclistService {
|
|
|
364
443
|
const route = { data: card, id: 'free-ride', };
|
|
365
444
|
data.unshift(route);
|
|
366
445
|
}
|
|
446
|
+
if (list === 'myRoutes' && !data.find(r => r.data.type === 'import')) {
|
|
447
|
+
const card = new ImportCard_1.ImportCard('loaded');
|
|
448
|
+
const route = { data: card, id: 'import', };
|
|
449
|
+
data.unshift(route);
|
|
450
|
+
}
|
|
367
451
|
if ((data === null || data === void 0 ? void 0 : data.length) > 0) {
|
|
368
452
|
lists.push(this.getRouteListDataEntry(list, data, language, listHeader));
|
|
369
453
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LatLng } from "../../utils/geo";
|
|
1
2
|
import { RouteApiDetail } from "../base/api/types";
|
|
2
3
|
import { RoutePoint, RouteSegment } from "../base/types";
|
|
3
4
|
import { RouteState, RouteCategory, RouteProvider } from "../base/types";
|
|
@@ -69,15 +70,22 @@ export type RouteListData = {
|
|
|
69
70
|
};
|
|
70
71
|
export type RouteListStatusUpdateCallback = (data: RouteListData) => void;
|
|
71
72
|
export type RouteStartSettings = {
|
|
73
|
+
type?: CardType;
|
|
72
74
|
startPos?: number;
|
|
73
75
|
endPos?: number;
|
|
74
76
|
segment?: string;
|
|
75
77
|
realityFactor?: number;
|
|
78
|
+
position?: LatLng;
|
|
79
|
+
options?: any;
|
|
76
80
|
};
|
|
77
81
|
export type RouteSettingsState = {
|
|
78
82
|
route: RouteInfo;
|
|
79
83
|
settings: RouteStartSettings;
|
|
80
84
|
};
|
|
85
|
+
export type FreeRideSettings = {
|
|
86
|
+
position?: LatLng;
|
|
87
|
+
options?: any;
|
|
88
|
+
};
|
|
81
89
|
export type Page = {
|
|
82
90
|
id: string;
|
|
83
91
|
state: RouteListData;
|
|
@@ -105,6 +113,9 @@ export interface InternalRouteListState {
|
|
|
105
113
|
pages: Array<Page>;
|
|
106
114
|
loading?: LoadingState;
|
|
107
115
|
preloadDone: boolean;
|
|
116
|
+
selectedType?: CardType;
|
|
117
|
+
selectedPosition?: LatLng;
|
|
118
|
+
selectedOptions?: any;
|
|
108
119
|
}
|
|
109
120
|
export type RouteStartState = 'idle' | 'preparing' | 'selected' | 'started';
|
|
110
121
|
export type Card<T> = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"gd-eventlog": "^0.1.26"
|
|
6
6
|
},
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"axios": "^1.6.1",
|
|
42
|
-
"incyclist-devices": "^2.1.
|
|
42
|
+
"incyclist-devices": "^2.1.26",
|
|
43
43
|
"uuid": "^9.0.0"
|
|
44
44
|
}
|
|
45
45
|
}
|