incyclist-services 1.3.50 → 1.3.51

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.
@@ -115,7 +115,7 @@ let ActivitiesRepository = (() => {
115
115
  return;
116
116
  const id = target.summary.id;
117
117
  const idx = this.activities.findIndex(ai => ai.summary.id === id);
118
- if (idx) {
118
+ if (idx !== -1) {
119
119
  this.activities.splice(idx, 1);
120
120
  this.write(true);
121
121
  }
@@ -145,7 +145,8 @@ let ActivitiesRepository = (() => {
145
145
  });
146
146
  }
147
147
  search(criteria) {
148
- let result = this.activities;
148
+ var _a;
149
+ let result = (_a = this.activities) === null || _a === void 0 ? void 0 : _a.filter(ai => ai.summary.rideTime > 30);
149
150
  result = this.checkIdFilter(result, criteria);
150
151
  result = this.checkHashFilter(result, criteria);
151
152
  result = this.checkStartPosFilter(result, criteria);
@@ -155,6 +156,9 @@ let ActivitiesRepository = (() => {
155
156
  result = this.checkUploadStatusFilter(result, criteria);
156
157
  result = this.checkTimeFilter(result, criteria);
157
158
  result = this.checkDistanceFilter(result, criteria);
159
+ if ((criteria === null || criteria === void 0 ? void 0 : criteria.maxValues) !== undefined && (result === null || result === void 0 ? void 0 : result.length) > criteria.maxValues) {
160
+ result = result.slice(0, criteria.maxValues - 1);
161
+ }
158
162
  return result;
159
163
  }
160
164
  checkIdFilter(result, criteria) {
@@ -9,4 +9,5 @@ export interface ActivitySearchCriteria {
9
9
  isSaved?: boolean;
10
10
  minTime?: number;
11
11
  minDistance?: number;
12
+ maxValues?: number;
12
13
  }
@@ -7,14 +7,30 @@ export declare class ActivityListService extends IncyclistService {
7
7
  protected initialized: boolean;
8
8
  protected repo: ActivitiesRepository;
9
9
  protected observer: Observer;
10
+ protected filter: ActivitySearchCriteria;
10
11
  constructor();
11
12
  preload(): PromiseObserver<void>;
12
- getPastActivities(filter: ActivitySearchCriteria): Array<ActivityInfo>;
13
+ openList(): {
14
+ filter: ActivitySearchCriteria;
15
+ activities: ActivityInfo[];
16
+ };
17
+ getListObserver(): Observer;
18
+ closeList(): void;
19
+ isStillLoading(): boolean;
20
+ setFilter(filter: ActivitySearchCriteria): void;
21
+ protected getPastActivities(): Array<ActivityInfo>;
22
+ getActivityDetails(id: string): Observer;
23
+ delete(id: string): Promise<boolean>;
13
24
  getPastActivitiesWithDetails(filter: ActivitySearchCriteria): Promise<Array<ActivityInfo>>;
14
25
  protected loadActivities(): Promise<void>;
26
+ protected loadDetails(activity: any): Promise<void>;
15
27
  protected getRepo(): ActivitiesRepository;
16
28
  protected get activities(): Array<ActivityInfo>;
17
- protected getListDisplayProperties(activities: Array<ActivityInfo>): ActivityInfo[];
29
+ protected getActivity(id: string): ActivityInfo;
30
+ protected getListDisplayProperties(): {
31
+ filter: ActivitySearchCriteria;
32
+ activities: ActivityInfo[];
33
+ };
18
34
  protected emitLists(event: 'loaded' | 'updated'): void;
19
35
  }
20
36
  export declare const useActivityList: () => ActivityListService;
@@ -46,11 +46,16 @@ var __setFunctionName = (this && this.__setFunctionName) || function (f, name, p
46
46
  if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
47
47
  return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
48
48
  };
49
+ var __importDefault = (this && this.__importDefault) || function (mod) {
50
+ return (mod && mod.__esModule) ? mod : { "default": mod };
51
+ };
49
52
  Object.defineProperty(exports, "__esModule", { value: true });
50
53
  exports.getActivityList = exports.useActivityList = exports.ActivityListService = void 0;
51
54
  const service_1 = require("../../base/service");
52
55
  const types_1 = require("../../base/types");
53
56
  const observer_1 = require("../../base/types/observer");
57
+ const utils_1 = require("../../utils");
58
+ const clone_1 = __importDefault(require("../../utils/clone"));
54
59
  const base_1 = require("../base");
55
60
  let ActivityListService = (() => {
56
61
  let _classDecorators = [types_1.Singleton];
@@ -74,10 +79,15 @@ let ActivityListService = (() => {
74
79
  this.preloadObserver.start()
75
80
  .then(() => {
76
81
  var _a;
77
- this.logEvent({ message: 'preload route list completed', cnt: (_a = this.activities) === null || _a === void 0 ? void 0 : _a.length });
78
- this.initialized = true;
79
- this.emitLists('loaded');
80
- process.nextTick(() => { delete this.preloadObserver; });
82
+ const getDetails = ((_a = this.getRepo().search({})) !== null && _a !== void 0 ? _a : []).filter((a, i) => i < 20).map(a => this.loadDetails(a));
83
+ Promise.allSettled(getDetails).then(() => {
84
+ var _a;
85
+ this.logEvent({ message: 'preload activity list completed', cnt: (_a = this.activities) === null || _a === void 0 ? void 0 : _a.length });
86
+ console.log('~~~~ ACTIVITIES', (0, clone_1.default)(this.activities));
87
+ this.initialized = true;
88
+ this.emitLists('loaded');
89
+ process.nextTick(() => { delete this.preloadObserver; });
90
+ });
81
91
  })
82
92
  .catch((err) => {
83
93
  this.logError(err, 'preload');
@@ -92,17 +102,77 @@ let ActivityListService = (() => {
92
102
  }
93
103
  return this.preloadObserver;
94
104
  }
95
- getPastActivities(filter) {
105
+ openList() {
106
+ if (!this.observer)
107
+ this.observer = new observer_1.Observer();
108
+ return this.getListDisplayProperties();
109
+ }
110
+ getListObserver() {
111
+ if (!this.observer)
112
+ this.observer = new observer_1.Observer();
113
+ return this.observer;
114
+ }
115
+ closeList() {
116
+ if (this.observer) {
117
+ this.observer.stop();
118
+ delete this.observer;
119
+ }
120
+ }
121
+ isStillLoading() {
122
+ return !this.initialized;
123
+ }
124
+ setFilter(filter) {
125
+ this.filter = filter;
126
+ }
127
+ getPastActivities() {
96
128
  var _a;
97
129
  try {
98
- const activities = (_a = this.getRepo().search(filter)) !== null && _a !== void 0 ? _a : [];
99
- return activities;
130
+ const activities = (_a = this.getRepo().search(this.filter)) !== null && _a !== void 0 ? _a : [];
131
+ return activities.sort((a, b) => { var _a, _b; return ((_a = b.summary) === null || _a === void 0 ? void 0 : _a.startTime) - ((_b = a.summary) === null || _b === void 0 ? void 0 : _b.startTime); });
100
132
  }
101
133
  catch (err) {
102
134
  this.logError(err, 'getPastActivities');
103
135
  return [];
104
136
  }
105
137
  }
138
+ getActivityDetails(id) {
139
+ const observer = new observer_1.Observer();
140
+ try {
141
+ const activity = this.getActivity(id);
142
+ if (activity.details) {
143
+ (0, utils_1.waitNextTick)().then(() => observer.emit('loaded', activity.details));
144
+ return;
145
+ }
146
+ this.getRepo().getWithDetails(id).then(ai => {
147
+ if (!ai)
148
+ return;
149
+ if (activity) {
150
+ activity.details = ai.details;
151
+ }
152
+ observer.emit('loaded', activity.details);
153
+ })
154
+ .catch(err => {
155
+ this.logError(err, 'getActivityDetails#getWithDetails');
156
+ });
157
+ }
158
+ catch (err) {
159
+ this.logError(err, 'getActivityDetails');
160
+ }
161
+ return observer;
162
+ }
163
+ delete(id) {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ try {
166
+ yield this.getRepo().delete(id);
167
+ this.emitLists('updated');
168
+ return true;
169
+ }
170
+ catch (err) {
171
+ this.logError(err, 'delete');
172
+ return false;
173
+ }
174
+ });
175
+ }
106
176
  getPastActivitiesWithDetails(filter) {
107
177
  return __awaiter(this, void 0, void 0, function* () {
108
178
  var _a;
@@ -130,6 +200,16 @@ let ActivityListService = (() => {
130
200
  });
131
201
  });
132
202
  }
203
+ loadDetails(activity) {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ const ai = yield this.getRepo().getWithDetails(activity.summary.id);
206
+ if (!ai)
207
+ return;
208
+ if (activity) {
209
+ activity.details = ai.details;
210
+ }
211
+ });
212
+ }
133
213
  getRepo() {
134
214
  if (!this.repo)
135
215
  this.repo = new base_1.ActivitiesRepository();
@@ -138,17 +218,22 @@ let ActivityListService = (() => {
138
218
  get activities() {
139
219
  return this.getRepo().getAll();
140
220
  }
141
- getListDisplayProperties(activities) {
142
- return activities;
221
+ getActivity(id) {
222
+ var _a;
223
+ return (_a = this.activities) === null || _a === void 0 ? void 0 : _a.find(a => a.summary.id === id);
224
+ }
225
+ getListDisplayProperties() {
226
+ const activities = this.getPastActivities();
227
+ const filter = this.filter;
228
+ return { filter, activities };
143
229
  }
144
230
  emitLists(event) {
145
231
  try {
146
- const activities = this.getRepo().getAll();
147
232
  if (this.observer)
148
- this.observer.emit(event, this.getListDisplayProperties(activities));
233
+ this.observer.emit(event, this.getListDisplayProperties());
149
234
  }
150
235
  catch (err) {
151
- this.logError(err, 'emitLists', event);
236
+ this.logError(err, 'emitLists', { event });
152
237
  }
153
238
  }
154
239
  };
@@ -1,2 +1,3 @@
1
1
  export * from "./singleton";
2
2
  export * from './lists';
3
+ export * from './observer';
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./singleton"), exports);
18
18
  __exportStar(require("./lists"), exports);
19
+ __exportStar(require("./observer"), exports);
package/lib/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from './activities';
9
9
  export { useUserSettings, initUserSettings, UserSettingsService, UserSettingsBinding, IUserSettingsBinding } from './settings';
10
10
  export * from './autoupdate';
11
11
  export * from './monitoring';
12
+ export * from './base/types';
package/lib/index.js CHANGED
@@ -30,3 +30,4 @@ Object.defineProperty(exports, "UserSettingsService", { enumerable: true, get: f
30
30
  Object.defineProperty(exports, "UserSettingsBinding", { enumerable: true, get: function () { return settings_1.UserSettingsBinding; } });
31
31
  __exportStar(require("./autoupdate"), exports);
32
32
  __exportStar(require("./monitoring"), exports);
33
+ __exportStar(require("./base/types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.3.50",
3
+ "version": "1.3.51",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },