@senior-gestao-empresarial/angular-components 5.1.0 → 6.0.0

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 (34) hide show
  1. package/bundles/senior-gestao-empresarial-angular-components.umd.js +118 -148
  2. package/bundles/senior-gestao-empresarial-angular-components.umd.js.map +1 -1
  3. package/bundles/senior-gestao-empresarial-angular-components.umd.min.js +2 -2
  4. package/bundles/senior-gestao-empresarial-angular-components.umd.min.js.map +1 -1
  5. package/components/lookups/erp-lookups.d.ts +1 -0
  6. package/components/nps/index.d.ts +1 -0
  7. package/components/nps/nps.service.d.ts +4 -35
  8. package/components/nps/protocols/index.d.ts +3 -0
  9. package/components/nps/protocols/tenant-full-dto.d.ts +3 -0
  10. package/components/nps/protocols/token-senior-x.d.ts +14 -0
  11. package/components/nps/protocols/tracksale-request.d.ts +18 -0
  12. package/components/websocket/websocket.service.d.ts +42 -17
  13. package/esm2015/components/lookups/erp-lookups.js +14 -19
  14. package/esm2015/components/nps/index.js +1 -1
  15. package/esm2015/components/nps/nps.service.js +12 -9
  16. package/esm2015/components/nps/protocols/index.js +1 -0
  17. package/esm2015/components/nps/protocols/tenant-full-dto.js +1 -0
  18. package/esm2015/components/nps/protocols/token-senior-x.js +1 -0
  19. package/esm2015/components/nps/protocols/tracksale-request.js +1 -0
  20. package/esm2015/components/websocket/websocket.service.js +51 -58
  21. package/esm5/components/lookups/erp-lookups.js +15 -19
  22. package/esm5/components/nps/index.js +1 -1
  23. package/esm5/components/nps/nps.service.js +32 -23
  24. package/esm5/components/nps/protocols/index.js +1 -0
  25. package/esm5/components/nps/protocols/tenant-full-dto.js +1 -0
  26. package/esm5/components/nps/protocols/token-senior-x.js +1 -0
  27. package/esm5/components/nps/protocols/tracksale-request.js +1 -0
  28. package/esm5/components/websocket/websocket.service.js +72 -107
  29. package/fesm2015/senior-gestao-empresarial-angular-components.js +74 -83
  30. package/fesm2015/senior-gestao-empresarial-angular-components.js.map +1 -1
  31. package/fesm5/senior-gestao-empresarial-angular-components.js +115 -145
  32. package/fesm5/senior-gestao-empresarial-angular-components.js.map +1 -1
  33. package/package.json +1 -1
  34. package/senior-gestao-empresarial-angular-components.metadata.json +1 -1
@@ -13,8 +13,8 @@ import { TranslateService } from '@ngx-translate/core';
13
13
  import { HttpInterceptorModule } from '@seniorsistemas/platform-components';
14
14
  import { user } from '@seniorsistemas/senior-platform-data';
15
15
  import { FormControl, FormGroup } from '@angular/forms';
16
- import { get } from 'js-cookie';
17
16
  import { Stomp } from '@stomp/stompjs';
17
+ import { get } from 'js-cookie';
18
18
  import * as SockJS from 'sockjs-client';
19
19
 
20
20
  let BreadcrumbComponent = class BreadcrumbComponent {
@@ -407,15 +407,7 @@ class ErpLookups {
407
407
  displayFields
408
408
  }, this.entity, options.domain || this.domain, options.service || this.service)
409
409
  .pipe(takeUntil(this.ngUnsubscribe))
410
- .pipe(map((list) => list.contents.map((item) => (Object.assign(Object.assign({}, item), { label: lookupDisplayFields
411
- .map((field) => {
412
- if (field.indexOf(".") > 0)
413
- return this.getProp(item, field, prefix);
414
- return item[field] !== undefined && item[field] !== null
415
- ? item[field]
416
- : this.translate.instant(`${prefix}.empty_label`);
417
- })
418
- .join(" - ") })))))
410
+ .pipe(map((list) => list.contents.map((item) => (Object.assign(Object.assign({}, item), { label: this.getItemLabel(item, prefix, lookupDisplayFields) })))))
419
411
  .subscribe((data) => {
420
412
  this.lookupSuggestionsObservable.next(data);
421
413
  });
@@ -475,21 +467,24 @@ class ErpLookups {
475
467
  .list({ page, sort, filterQuery, displayFields }, this.entity, options.domain || this.domain, options.service || this.service)
476
468
  .pipe(takeUntil(this.ngUnsubscribe))
477
469
  .pipe(map((list) => ({
478
- gridData: list.contents.map((item) => (Object.assign(Object.assign({}, item), { label: lookupDisplayFields
479
- .map((field) => {
480
- if (field.indexOf(".") > 0)
481
- return this.getProp(item, field, prefix);
482
- return item[field] !== undefined && item[field] !== null
483
- ? item[field]
484
- : this.translate.instant(`${prefix}.empty_label`);
485
- })
486
- .join(" - ") }))),
470
+ gridData: list.contents.map((item) => (Object.assign(Object.assign({}, item), { label: this.getItemLabel(item, prefix, lookupDisplayFields) }))),
487
471
  totalRecords: list.totalElements
488
472
  })))
489
473
  .subscribe((data) => {
490
474
  this.lookupSearchObservable.next(data);
491
475
  });
492
476
  }
477
+ getItemLabel(item, prefix, lookupDisplayFields) {
478
+ return lookupDisplayFields
479
+ .map((field) => {
480
+ if (field.indexOf(".") > 0)
481
+ return this.getProp(item, field, prefix);
482
+ return item[field] !== undefined && item[field] !== null
483
+ ? item[field]
484
+ : this.translate.instant(`${prefix}.empty_label`);
485
+ })
486
+ .join(" - ");
487
+ }
493
488
  };
494
489
  ErpLookups.ctorParameters = () => [
495
490
  { type: ErpLookupsService },
@@ -6087,27 +6082,30 @@ UtilsModule = UtilsModule_1 = __decorate([
6087
6082
  })
6088
6083
  ], UtilsModule);
6089
6084
 
6085
+ // https://widget.tracksale.co/
6090
6086
  let NpsService = class NpsService {
6091
- constructor() { }
6092
- get cookieInformation() {
6093
- return JSON.parse(get(`com.senior.pau.userdata`) || "{}");
6087
+ getUserInformation() {
6088
+ return __awaiter(this, void 0, void 0, function* () {
6089
+ return yield user.getToken();
6090
+ });
6094
6091
  }
6095
6092
  /**
6096
6093
  * Executa o serviço de NPS utilizando os dados do usuário atual, no caso sobreescrevendos os campos name, email, identification,
6097
6094
  * tags.tenant e tags.email fornecidos no request original. Esses serão sobreescritos com os valores retornados pelo cookie
6098
- * com.senior.pau.userdata. *
6095
+ * com.senior.pau.userdata.
6096
+ *
6099
6097
  * @param tracksaleRequest request que será enviado ao serviço de nps
6100
6098
  */
6101
6099
  currentUserInitNPS(tracksaleRequest) {
6102
6100
  return __awaiter(this, void 0, void 0, function* () {
6103
- const { tenantName, email, fullname, id } = this.cookieInformation;
6101
+ const { tenantName, email, fullName } = yield this.getUserInformation();
6104
6102
  const copyTracksaleRequest = Object.assign({}, tracksaleRequest);
6105
6103
  copyTracksaleRequest.tags =
6106
6104
  (tracksaleRequest.tags && Object.assign({}, tracksaleRequest.tags)) ||
6107
6105
  {};
6108
- copyTracksaleRequest.name = fullname;
6106
+ copyTracksaleRequest.name = fullName;
6109
6107
  copyTracksaleRequest.email = email;
6110
- copyTracksaleRequest.identification = id;
6108
+ copyTracksaleRequest.identification = email;
6111
6109
  copyTracksaleRequest.tags.tenant = tenantName;
6112
6110
  copyTracksaleRequest.tags.email = email;
6113
6111
  this.initNPS(copyTracksaleRequest);
@@ -6155,14 +6153,23 @@ NpsService = __decorate([
6155
6153
  var WebsocketService_1;
6156
6154
  let WebsocketService = WebsocketService_1 = class WebsocketService {
6157
6155
  constructor() {
6156
+ /** @private */
6158
6157
  this.focused = true;
6158
+ /** @private */
6159
6159
  this.wasConnected = false;
6160
+ /** @private */
6160
6161
  this.connected = false;
6162
+ /** @private */
6161
6163
  this.isConnecting = false;
6164
+ /** @private */
6162
6165
  this.primitiveManagers = new Map();
6166
+ /** @private */
6163
6167
  this.connect$ = new Subject();
6168
+ /** @private */
6164
6169
  this.disconnect$ = new Subject();
6170
+ /** @private */
6165
6171
  this.reconnect$ = new Subject();
6172
+ /** @private */
6166
6173
  this.error$ = new Subject();
6167
6174
  window.onfocus = this.onFocus;
6168
6175
  window.onblur = this.onBlur;
@@ -6202,17 +6209,18 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6202
6209
  return this.error$.asObservable();
6203
6210
  }
6204
6211
  /**
6205
- * Observable responsável por emitir uma notificação quando um evento é publicado.
6206
6212
  * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6207
- * @param domain Dominio da primitiva.
6208
- * @param service Service da primitiva.
6209
- * @param primitive Primitiva que será "observada" pelo client.
6210
- * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
6211
- * @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
6213
+ * @param {Object} options Objeto de configuração do evento.
6214
+ * @param {string} options.domain Domínio da primitiva.
6215
+ * @param {string} options.service Serviço da primitiva.
6216
+ * @param {string} options.primitive Primitiva que será "observada".
6217
+ * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
6212
6218
  */
6213
- onEvent(domain, service, primitive, identifierPath) {
6214
- if (this.primitiveManagers.has(primitive)) {
6215
- return this.primitiveManagers.get(primitive).subject.asObservable();
6219
+ onEvent(options) {
6220
+ const { domain, service, primitive } = options;
6221
+ const key = this.getPrimitiveManagerKey(domain, service, primitive);
6222
+ if (this.primitiveManagers.has(key)) {
6223
+ return this.primitiveManagers.get(key).subject.asObservable();
6216
6224
  }
6217
6225
  const primitiveManager = {
6218
6226
  domain: domain,
@@ -6220,13 +6228,11 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6220
6228
  primitive: primitive,
6221
6229
  stompSubscriptions: [],
6222
6230
  subject: new Subject(),
6223
- identifierPath: identifierPath,
6224
- publishedEvents: [],
6225
6231
  };
6226
- this.primitiveManagers.set(primitive, primitiveManager);
6232
+ this.primitiveManagers.set(key, primitiveManager);
6227
6233
  if (this.isConnected()) {
6228
6234
  this.createStompSubscriptions(primitiveManager);
6229
- return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitive)));
6235
+ return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
6230
6236
  }
6231
6237
  else {
6232
6238
  if (!this.isConnecting) {
@@ -6235,37 +6241,10 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6235
6241
  this.connect$.pipe(first()).subscribe(() => {
6236
6242
  this.createStompSubscriptions(primitiveManager);
6237
6243
  });
6238
- return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitive)));
6239
- }
6240
- }
6241
- /**
6242
- * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6243
- * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6244
- * @param primitive Primitiva que será "observada" pelo client.
6245
- * @param identifiers Array com os identificadores interessados.
6246
- * @return Array contendo o último evento recebido de cada identificador fornecido.
6247
- */
6248
- getPublishedEvents(primitive, identifiers) {
6249
- const publishedEvents = [];
6250
- const primitiveManager = this.primitiveManagers.get(primitive);
6251
- for (const identifier of identifiers) {
6252
- const event = primitiveManager.publishedEvents.find(x => this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier);
6253
- if (event) {
6254
- publishedEvents.push(event);
6255
- }
6256
- }
6257
- return publishedEvents;
6258
- }
6259
- addPublishedEvent(primitiveManager, event) {
6260
- const identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6261
- const eventIndex = primitiveManager.publishedEvents.findIndex(x => this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier);
6262
- if (eventIndex !== -1) {
6263
- primitiveManager.publishedEvents[eventIndex] = Object.assign(Object.assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6264
- }
6265
- else {
6266
- primitiveManager.publishedEvents.push(event);
6244
+ return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
6267
6245
  }
6268
6246
  }
6247
+ /** @private */
6269
6248
  createStompSubscriptions(primitiveManager) {
6270
6249
  const withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6271
6250
  const stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
@@ -6273,14 +6252,7 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6273
6252
  const stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6274
6253
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
6275
6254
  }
6276
- getIdentifierFromEvent(identifierPath, event) {
6277
- const properties = identifierPath.split(".");
6278
- let identifier = event;
6279
- for (const property of properties) {
6280
- identifier = identifier[property];
6281
- }
6282
- return identifier;
6283
- }
6255
+ /** @private */
6284
6256
  connect() {
6285
6257
  this.createStompClient();
6286
6258
  this.isConnecting = true;
@@ -6302,9 +6274,11 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6302
6274
  this.reconnect();
6303
6275
  });
6304
6276
  }
6277
+ /** @private */
6305
6278
  onFocus() {
6306
6279
  this.focused = true;
6307
6280
  }
6281
+ /** @private */
6308
6282
  onBlur() {
6309
6283
  this.focused = false;
6310
6284
  }
@@ -6328,34 +6302,40 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6328
6302
  this.wasConnected = false;
6329
6303
  this.disconnect$.next();
6330
6304
  }
6305
+ /** @private */
6331
6306
  isConnected() {
6332
6307
  return this.connected;
6333
6308
  }
6309
+ /** @private */
6334
6310
  setConnected(connected) {
6335
6311
  this.connected = connected;
6336
6312
  }
6313
+ /** @private */
6337
6314
  getSubscriptionUrlWithToken(domain, service, primitive) {
6338
6315
  const tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6339
6316
  const token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
6340
6317
  return `/topic/${tenant}/${token}/${domain}/${service}/${primitive}`;
6341
6318
  }
6319
+ /** @private */
6342
6320
  getSubscriptionUrlWithoutToken(domain, service, primitive) {
6343
6321
  const tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6344
6322
  return `/topic/${tenant}/${domain}/${service}/${primitive}`;
6345
6323
  }
6324
+ /** @private */
6346
6325
  createStompSubscription(destination, primitiveManager) {
6347
6326
  return this._stompClient.subscribe(destination, (message) => {
6348
6327
  const event = JSON.parse(message.body || "{}");
6349
- this.addPublishedEvent(primitiveManager, event);
6350
6328
  primitiveManager.subject.next(event);
6351
6329
  });
6352
6330
  }
6331
+ /** @private */
6353
6332
  createStompClient() {
6354
6333
  const ws = new SockJS(`${WebsocketService_1.WEBSOCKET_URL}subscription`, null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6355
6334
  this._stompClient = Stomp.over(ws);
6356
6335
  // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
6357
6336
  this._stompClient.debug = () => { }; // Para remover os logs.
6358
6337
  }
6338
+ /** @private */
6359
6339
  reconnect() {
6360
6340
  if (this.connected)
6361
6341
  this._stompClient.disconnect();
@@ -6370,6 +6350,7 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6370
6350
  }
6371
6351
  }, WebsocketService_1.RECONNECT_TIMER);
6372
6352
  }
6353
+ /** @private */
6373
6354
  reconnectPrimitives() {
6374
6355
  for (const primitiveManager of this.primitiveManagers.values()) {
6375
6356
  for (const stompSubscription of primitiveManager.stompSubscriptions) {
@@ -6378,6 +6359,7 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6378
6359
  this.createStompSubscriptions(primitiveManager);
6379
6360
  }
6380
6361
  }
6362
+ /** @private */
6381
6363
  getObserversCount() {
6382
6364
  let observersCount = 0;
6383
6365
  for (const primitiveManager of this.primitiveManagers.values()) {
@@ -6385,26 +6367,35 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6385
6367
  }
6386
6368
  return observersCount;
6387
6369
  }
6388
- disconnectPrimitiveOnFinalize(primitive) {
6389
- const primitiveManager = this.primitiveManagers.get(primitive);
6390
- if (!primitiveManager)
6391
- return;
6392
- // @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
6370
+ /** @private */
6371
+ disconnectPrimitiveOnFinalize(primitiveManager) {
6372
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
6393
6373
  const hasObservers = !(primitiveManager.subject.observers.length === 1);
6394
6374
  if (hasObservers)
6395
6375
  return;
6396
6376
  for (const stompSubscription of primitiveManager.stompSubscriptions) {
6397
6377
  stompSubscription.unsubscribe();
6398
6378
  }
6399
- this.primitiveManagers.delete(primitive);
6379
+ const key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6380
+ this.primitiveManagers.delete(key);
6400
6381
  this.disconnect();
6401
6382
  }
6383
+ /** @private */
6384
+ getPrimitiveManagerKey(domain, service, primitive) {
6385
+ return `${domain}/${service}/${primitive}`;
6386
+ }
6402
6387
  };
6388
+ /** @private */
6403
6389
  WebsocketService.RECONNECT_TIMER = 3000;
6390
+ /** @private */
6404
6391
  WebsocketService.CONNECTION_TIMEOUT = 15000;
6392
+ /** @private */
6405
6393
  WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
6394
+ /** @private */
6406
6395
  WebsocketService.TOKEN_COOKIE = "com.senior.token";
6396
+ /** @private */
6407
6397
  WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || "{}");
6398
+ /** @private */
6408
6399
  WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
6409
6400
  WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
6410
6401
  WebsocketService = WebsocketService_1 = __decorate([