@smarterplan/ngx-smarterplan-core 1.4.25 → 1.4.27

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)
@@ -4804,7 +4829,10 @@ class MatterportTagService {
4804
4829
  mattertagData.setObject(object, poiType);
4805
4830
  }
4806
4831
  await setTagIconAndOpacity(mattertagID, mattertagData);
4807
- await injectHtmlInTag(poiType, object, mattertagID);
4832
+ // Without an object (a placement just validated) there is nothing to show yet.
4833
+ if (object) {
4834
+ await injectHtmlInTag(poiType, object, mattertagID);
4835
+ }
4808
4836
  }
4809
4837
  /** Registers a custom texture and applies it to a tag, optionally adjusting opacity. */
4810
4838
  async addNewIconAndSetForTag(sdk, mattertagID, iconPath, applyOpacity, opacity) {
@@ -5954,7 +5982,6 @@ class MatterportService {
5954
5982
  mattertagData.setSweepID(this.navigationService.resolveSweepUuid(this.poseCamera.sweep));
5955
5983
  mattertagData.setRotation(this.poseCamera.rotation);
5956
5984
  mattertagData.setObject(element, poiType);
5957
- this.mattertagToFollow = await this.addMattertagToViewer(mattertagData);
5958
5985
  this.setInteractionMode(ViewerInteractions.POSITIONING);
5959
5986
  await this.addCursorMattertag(mattertagData);
5960
5987
  }
@@ -10584,12 +10611,18 @@ class ViewerService {
10584
10611
  * @param objects List of objects (tickets, equipments) etc to be added as Mattertags
10585
10612
  */
10586
10613
  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
- }));
10614
+ // By batches, yielding between them: the POIs usually need no request now, and creating
10615
+ // hundreds of tags in a row would freeze the page.
10616
+ const batchSize = 50;
10617
+ for (let start = 0; start < objects.length; start += batchSize) {
10618
+ await Promise.all(objects.slice(start, start + batchSize).map(async (object) => {
10619
+ const poi = await this.poiService.getPoiForObject(object);
10620
+ if (poi && poi.coordinate) {
10621
+ await this.actionAddObjectFromPOI(object, poi);
10622
+ }
10623
+ }));
10624
+ await new Promise((resolve) => setTimeout(resolve));
10625
+ }
10593
10626
  // Newly created tags have no opacity/allowAction applied yet (only set by
10594
10627
  // updateTagsVisibilityForContext, which runs on Mode/Sweep/Floor/Room/Camera
10595
10628
  // events). If this batch loaded after those fired, the tags stay in whatever
@@ -10598,9 +10631,24 @@ class ViewerService {
10598
10631
  this.matterportService.refreshTagsVisibility();
10599
10632
  }
10600
10633
  }
10634
+ /** Type of a POI recorded without one, deduced from the object it belongs to. */
10635
+ poiTypeFromObject(object) {
10636
+ switch (object?.__typename) {
10637
+ case 'Equipment':
10638
+ return PoiType.EQUIPMENT;
10639
+ case 'Ticket':
10640
+ return PoiType.TICKET;
10641
+ case 'Comment':
10642
+ return PoiType.MEASURE;
10643
+ case 'Feature':
10644
+ return object.type === FeatureType.DESK ? PoiType.DESK : PoiType.DATA;
10645
+ default:
10646
+ return null;
10647
+ }
10648
+ }
10601
10649
  async actionAddObjectFromPOI(object, poi) {
10602
10650
  if (this.checkMode('Matterport')) {
10603
- return this.matterportService.createMattertagFromPOI(poi.type, object, poi);
10651
+ return this.matterportService.createMattertagFromPOI(poi.type ?? this.poiTypeFromObject(object), object, poi);
10604
10652
  }
10605
10653
  if (this.checkMode('threejs')) {
10606
10654
  return this.addThreeJsTagFromPOI(object, poi);
@@ -11167,8 +11215,9 @@ class ViewerService {
11167
11215
  };
11168
11216
  const updatedPoi = await this.poiService.updatePoi(poiInput);
11169
11217
  tagData.setPoi(updatedPoi);
11170
- await this.matterportService.setObjectAndPoiInTag(lastTag, element, PoiType.DESK, updatedPoi);
11171
- await this.matterportService.injectHtmlInTag(poi.type, element, lastTag);
11218
+ const poiType = poi.type ?? tagData.getType();
11219
+ await this.matterportService.setObjectAndPoiInTag(lastTag, element, poiType, updatedPoi);
11220
+ await this.matterportService.injectHtmlInTag(poiType, element, lastTag);
11172
11221
  await this.matterportService.setTagIconAndOpacity(lastTag, tagData);
11173
11222
  this.matterportService.goToTag(lastTag);
11174
11223
  return Promise.resolve(updatedPoi);
@@ -12474,7 +12523,7 @@ class FilterService {
12474
12523
  return false;
12475
12524
  });
12476
12525
  const byParentDomain = equips.filter((eq) => {
12477
- if (eq.domain && eq.domain.parentID) {
12526
+ if (eq.domain && eq.domain.parentID && eq.domain.parent) {
12478
12527
  const normalizedParent = eq.domain.parent.name.toLowerCase();
12479
12528
  const lev = levenshtein(normalizedParent, term);
12480
12529
  return lev <= 2 || normalizedParent.includes(term);
@@ -14240,6 +14289,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.12", ngImpo
14240
14289
 
14241
14290
  class OperationService {
14242
14291
  API; //AWS
14292
+ /** Equipments linked to a ticket in this session: their loaded `operations` may be outdated. */
14293
+ linkedEquipmentIDs = new Set();
14243
14294
  constructor(apiInjected) {
14244
14295
  this.API = apiInjected;
14245
14296
  }
@@ -14254,6 +14305,16 @@ class OperationService {
14254
14305
  const tickets = operations.map((operation) => operation.ticket);
14255
14306
  return tickets;
14256
14307
  }
14308
+ /** Tickets of a loaded equipment, without a request when its list query shows it has no operation. */
14309
+ async getTicketsForEquipment(equip) {
14310
+ const operations = equip.operations;
14311
+ if (operations?.items?.length === 0
14312
+ && !operations.nextToken
14313
+ && !this.linkedEquipmentIDs.has(equip.id)) {
14314
+ return [];
14315
+ }
14316
+ return this.getTicketsByEquipmentID(equip.id);
14317
+ }
14257
14318
  async deleteOperationsForEquipment(equipID) {
14258
14319
  const deleted = [];
14259
14320
  await this.getOperationsByEquipmentID(equipID)
@@ -14281,6 +14342,9 @@ class OperationService {
14281
14342
  return this.API.__proto__.DeleteOperation({ id: operationID });
14282
14343
  }
14283
14344
  async createOperation(operation) {
14345
+ if (operation.equipmentID) {
14346
+ this.linkedEquipmentIDs.add(operation.equipmentID);
14347
+ }
14284
14348
  return this.API.__proto__.CreateOperation(operation);
14285
14349
  }
14286
14350
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.12", ngImport: i0, type: OperationService, deps: [{ token: 'currentAPIService' }], target: i0.ɵɵFactoryTarget.Injectable });