@smarterplan/ngx-smarterplan-core 1.4.25 → 1.4.26

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.
@@ -2128,6 +2128,8 @@ class PoiService {
2128
2128
  currentSpaceID;
2129
2129
  zoneIDFilter;
2130
2130
  destroy$ = new Subject();
2131
+ /** Elements whose POI was written in this session: a copy loaded earlier with the element is outdated. */
2132
+ changedElementIDs = new Set();
2131
2133
  constructor(apiInjected, awsKinesisAnalyticsInjected, userService, zoneChangeService // inject ZoneChangeService instead of NavigatorService to fix circular dependancy
2132
2134
  ) {
2133
2135
  this.userService = userService;
@@ -2161,6 +2163,28 @@ class PoiService {
2161
2163
  }
2162
2164
  return null;
2163
2165
  }
2166
+ /**
2167
+ * POI of an object already loaded. Reuses the copy embedded by its list query when it is complete
2168
+ * and up to date, so that placing hundreds of tags does not send one request per tag.
2169
+ */
2170
+ async getPoiForObject(object) {
2171
+ const items = object.pois?.items;
2172
+ const embedded = items?.length === 1 && !object.pois.nextToken ? items[0] : null;
2173
+ if (embedded
2174
+ && embedded.coordinate !== undefined
2175
+ && embedded.metadata !== undefined
2176
+ && embedded.tagIcon !== undefined
2177
+ && !this.changedElementIDs.has(object.id)) {
2178
+ return embedded;
2179
+ }
2180
+ return this.getPoiByElementId(object.id);
2181
+ }
2182
+ markChanged(poi) {
2183
+ if (poi?.elementID) {
2184
+ this.changedElementIDs.add(poi.elementID);
2185
+ }
2186
+ return poi;
2187
+ }
2164
2188
  async getPoisByType(type) {
2165
2189
  return this.API.PoisByType(type).then((pois) => pois.items);
2166
2190
  }
@@ -2184,6 +2208,7 @@ class PoiService {
2184
2208
  // partitionKey: "",
2185
2209
  }, 'AWSKinesis');
2186
2210
  }
2211
+ this.markChanged(poi);
2187
2212
  return this.API.CreatePOI(poi);
2188
2213
  }
2189
2214
  poiIsVirtual(poi) {
@@ -2191,10 +2216,10 @@ class PoiService {
2191
2216
  return !coordinate;
2192
2217
  }
2193
2218
  async updatePoi(poi) {
2194
- return this.API.UpdatePOI(poi);
2219
+ return this.markChanged(await this.API.UpdatePOI(poi));
2195
2220
  }
2196
2221
  async deletePoi(poiID) {
2197
- return this.API.DeletePOI({ id: poiID });
2222
+ return this.markChanged(await this.API.DeletePOI({ id: poiID }));
2198
2223
  }
2199
2224
  async getPoisByMatterportSweepByType(sweep, type) {
2200
2225
  return this.API.ListPOIS({ matterportSweepID: { eq: sweep } }, 300)
@@ -10584,12 +10609,18 @@ class ViewerService {
10584
10609
  * @param objects List of objects (tickets, equipments) etc to be added as Mattertags
10585
10610
  */
10586
10611
  async addObjectTagsToViewer(objects) {
10587
- await Promise.all(objects.map(async (object) => {
10588
- const poi = await this.poiService.getPoiByElementId(object.id);
10589
- if (poi && poi.coordinate) {
10590
- await this.actionAddObjectFromPOI(object, poi);
10591
- }
10592
- }));
10612
+ // By batches, yielding between them: the POIs usually need no request now, and creating
10613
+ // hundreds of tags in a row would freeze the page.
10614
+ const batchSize = 50;
10615
+ for (let start = 0; start < objects.length; start += batchSize) {
10616
+ await Promise.all(objects.slice(start, start + batchSize).map(async (object) => {
10617
+ const poi = await this.poiService.getPoiForObject(object);
10618
+ if (poi && poi.coordinate) {
10619
+ await this.actionAddObjectFromPOI(object, poi);
10620
+ }
10621
+ }));
10622
+ await new Promise((resolve) => setTimeout(resolve));
10623
+ }
10593
10624
  // Newly created tags have no opacity/allowAction applied yet (only set by
10594
10625
  // updateTagsVisibilityForContext, which runs on Mode/Sweep/Floor/Room/Camera
10595
10626
  // events). If this batch loaded after those fired, the tags stay in whatever
@@ -12474,7 +12505,7 @@ class FilterService {
12474
12505
  return false;
12475
12506
  });
12476
12507
  const byParentDomain = equips.filter((eq) => {
12477
- if (eq.domain && eq.domain.parentID) {
12508
+ if (eq.domain && eq.domain.parentID && eq.domain.parent) {
12478
12509
  const normalizedParent = eq.domain.parent.name.toLowerCase();
12479
12510
  const lev = levenshtein(normalizedParent, term);
12480
12511
  return lev <= 2 || normalizedParent.includes(term);
@@ -14240,6 +14271,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
14240
14271
 
14241
14272
  class OperationService {
14242
14273
  API; //AWS
14274
+ /** Equipments linked to a ticket in this session: their loaded `operations` may be outdated. */
14275
+ linkedEquipmentIDs = new Set();
14243
14276
  constructor(apiInjected) {
14244
14277
  this.API = apiInjected;
14245
14278
  }
@@ -14254,6 +14287,16 @@ class OperationService {
14254
14287
  const tickets = operations.map((operation) => operation.ticket);
14255
14288
  return tickets;
14256
14289
  }
14290
+ /** Tickets of a loaded equipment, without a request when its list query shows it has no operation. */
14291
+ async getTicketsForEquipment(equip) {
14292
+ const operations = equip.operations;
14293
+ if (operations?.items?.length === 0
14294
+ && !operations.nextToken
14295
+ && !this.linkedEquipmentIDs.has(equip.id)) {
14296
+ return [];
14297
+ }
14298
+ return this.getTicketsByEquipmentID(equip.id);
14299
+ }
14257
14300
  async deleteOperationsForEquipment(equipID) {
14258
14301
  const deleted = [];
14259
14302
  await this.getOperationsByEquipmentID(equipID)
@@ -14281,6 +14324,9 @@ class OperationService {
14281
14324
  return this.API.__proto__.DeleteOperation({ id: operationID });
14282
14325
  }
14283
14326
  async createOperation(operation) {
14327
+ if (operation.equipmentID) {
14328
+ this.linkedEquipmentIDs.add(operation.equipmentID);
14329
+ }
14284
14330
  return this.API.__proto__.CreateOperation(operation);
14285
14331
  }
14286
14332
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: OperationService, deps: [{ token: 'currentAPIService' }], target: i0.ɵɵFactoryTarget.Injectable });