@senior-gestao-empresarial/angular-components 4.22.0 → 4.22.1-706afb94-1b58-4cb7-9006-8d9033881f51

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.
@@ -4,7 +4,7 @@ import { CommonModule } from '@angular/common';
4
4
  import { BreadcrumbModule as BreadcrumbModule$1 } from 'primeng/breadcrumb';
5
5
  import { NavigationEnd, PRIMARY_OUTLET, ActivatedRoute, Router, RouterModule } from '@angular/router';
6
6
  import { Subject, throwError, interval, of, ReplaySubject } from 'rxjs';
7
- import { takeUntil, filter, catchError, map, takeWhile, switchMap, take } from 'rxjs/operators';
7
+ import { takeUntil, filter, catchError, map, takeWhile, switchMap, first, take } from 'rxjs/operators';
8
8
  import * as moment_ from 'moment';
9
9
  import { FormField, FieldType } from '@seniorsistemas/angular-components';
10
10
  import { HttpParams, HttpClient } from '@angular/common/http';
@@ -6412,7 +6412,6 @@ var WebsocketService = /** @class */ (function () {
6412
6412
  this.connected = false;
6413
6413
  this.isConnecting = false;
6414
6414
  this.stompSubscriptions = new Map();
6415
- // private primitiveSubjects: Map<string, Subject<any>> = new Map<string, Subject<any>>();
6416
6415
  this.primitiveManagers = new Map();
6417
6416
  this.disconnectSubject = new Subject();
6418
6417
  this.connect$ = new Subject();
@@ -6422,8 +6421,8 @@ var WebsocketService = /** @class */ (function () {
6422
6421
  }
6423
6422
  WebsocketService_1 = WebsocketService;
6424
6423
  /**
6425
- * Observable resposável por emitir uma notificação quando a conexão websocket é estabelecida.
6426
- * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida ou já está em andamento.
6424
+ * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida.
6425
+ * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida.
6427
6426
  */
6428
6427
  WebsocketService.prototype.onConnect = function () {
6429
6428
  var _this = this;
@@ -6435,7 +6434,7 @@ var WebsocketService = /** @class */ (function () {
6435
6434
  return this.connect$.asObservable();
6436
6435
  };
6437
6436
  /**
6438
- * Observable resposável por emitir uma notificação quando a conexão é finalizada.
6437
+ * Observable responsável por emitir uma notificação quando a conexão é finalizada.
6439
6438
  * @return Um `Observable<void>` que emite uma notificação quando a conexão é finalizada.
6440
6439
  */
6441
6440
  WebsocketService.prototype.onDisconnect = function () {
@@ -6447,29 +6446,22 @@ var WebsocketService = /** @class */ (function () {
6447
6446
  * @param domain Dominio da primitva.
6448
6447
  * @param service Service da primitiva.
6449
6448
  * @param primitive Primitiva que será "observada" pelo client.
6450
- * @param identifierPath Caminho até a propriedade considerada o indentificador do registro.
6449
+ * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
6451
6450
  * @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
6452
6451
  */
6453
6452
  WebsocketService.prototype.onEvent = function (domain, service, primitive, identifierPath) {
6454
6453
  var _this = this;
6455
- var primitiveManager = this.primitiveManagers.get(primitive);
6456
- if (primitiveManager) {
6457
- return primitiveManager.subject.asObservable();
6454
+ if (this.primitiveManagers.has(primitive)) {
6455
+ return this.primitiveManagers.get(primitive).subject.asObservable();
6458
6456
  }
6459
- primitiveManager = {
6457
+ var primitiveManager = {
6460
6458
  subject: new Subject(),
6461
6459
  identifierPath: identifierPath,
6462
6460
  publishedEvents: [],
6463
6461
  };
6462
+ this.primitiveManagers.set(primitive, primitiveManager);
6464
6463
  if (this.isConnected()) {
6465
- var url = this.getSubscriptionUserUrl(domain, service, primitive);
6466
- this.primitiveManagers.set(primitive, primitiveManager);
6467
- var stompSubscription = this._stompClient.subscribe(url, function (message) {
6468
- var event = JSON.parse(message.body || "{}");
6469
- _this.addPublishedEvent(primitiveManager, event);
6470
- primitiveManager.subject.next(event);
6471
- });
6472
- this.stompSubscriptions.set(primitive, stompSubscription);
6464
+ this.createStompSubscriptions(domain, service, primitive, primitiveManager);
6473
6465
  return primitiveManager.subject.asObservable();
6474
6466
  }
6475
6467
  else {
@@ -6477,25 +6469,18 @@ var WebsocketService = /** @class */ (function () {
6477
6469
  this.connect();
6478
6470
  }
6479
6471
  this.onConnect()
6480
- .pipe(take(1))
6472
+ .pipe(first())
6481
6473
  .subscribe(function () {
6482
- var url = _this.getSubscriptionUserUrl(domain, service, primitive);
6483
- _this.primitiveManagers.set(primitive, primitiveManager);
6484
- var stompSubscription = _this._stompClient.subscribe(url, function (message) {
6485
- var event = JSON.parse(message.body || "{}");
6486
- _this.addPublishedEvent(primitiveManager, event);
6487
- primitiveManager.subject.next(event);
6488
- });
6489
- _this.stompSubscriptions.set(primitive, stompSubscription);
6474
+ _this.createStompSubscriptions(domain, service, primitive, primitiveManager);
6490
6475
  });
6491
6476
  return primitiveManager.subject.asObservable();
6492
6477
  }
6493
6478
  };
6494
6479
  /**
6495
- * Retorna todos os eventos ouvidos para a respectiva primitiva.
6480
+ * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6496
6481
  * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6497
6482
  * @param primitive Primitiva que será "observada" pelo client.
6498
- * @param identifiers Array com os indentificadores interessados.
6483
+ * @param identifiers Array com os identificadores interessados.
6499
6484
  * @return Array contendo o último evento recebido de cada identificador fornecido.
6500
6485
  */
6501
6486
  WebsocketService.prototype.getPublishedEvents = function (primitive, identifiers) {
@@ -6527,9 +6512,7 @@ var WebsocketService = /** @class */ (function () {
6527
6512
  WebsocketService.prototype.addPublishedEvent = function (primitiveManager, event) {
6528
6513
  var _this = this;
6529
6514
  var identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6530
- var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) {
6531
- return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier;
6532
- });
6515
+ var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6533
6516
  if (eventIndex !== -1) {
6534
6517
  primitiveManager.publishedEvents[eventIndex] = __assign(__assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6535
6518
  }
@@ -6537,6 +6520,13 @@ var WebsocketService = /** @class */ (function () {
6537
6520
  primitiveManager.publishedEvents.push(event);
6538
6521
  }
6539
6522
  };
6523
+ WebsocketService.prototype.createStompSubscriptions = function (domain, service, primitive, primitiveManager) {
6524
+ var withTokenUrl = this.getSubscriptionUrlWithToken(domain, service, primitive);
6525
+ var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
6526
+ var withoutTokenUrl = this.getSubscriptionUrlWithoutToken(domain, service, primitive);
6527
+ var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6528
+ this.stompSubscriptions.set(primitive, [stompSubscriptionWithToken, stompSubscriptionWithoutToken]);
6529
+ };
6540
6530
  WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6541
6531
  var e_2, _a;
6542
6532
  var properties = identifierPath.split(".");
@@ -6562,9 +6552,7 @@ var WebsocketService = /** @class */ (function () {
6562
6552
  this.isConnecting = true;
6563
6553
  this._stompClient.connect({}, function () {
6564
6554
  _this.setConnected(true);
6565
- // console.log('setou false isConnecting');
6566
6555
  _this.isConnecting = false;
6567
- // console.log('connectou dentro do connect cb');
6568
6556
  _this.publishOnConnect();
6569
6557
  }, function () {
6570
6558
  _this.setConnected(false);
@@ -6598,8 +6586,21 @@ var WebsocketService = /** @class */ (function () {
6598
6586
  finally { if (e_3) throw e_3.error; }
6599
6587
  }
6600
6588
  if (observersCount === 0) {
6601
- this.stompSubscriptions.forEach(function (stompSubscription) {
6602
- stompSubscription.unsubscribe();
6589
+ this.stompSubscriptions.forEach(function (stompSubscriptions) {
6590
+ var e_5, _a;
6591
+ try {
6592
+ for (var stompSubscriptions_1 = __values(stompSubscriptions), stompSubscriptions_1_1 = stompSubscriptions_1.next(); !stompSubscriptions_1_1.done; stompSubscriptions_1_1 = stompSubscriptions_1.next()) {
6593
+ var stompSubscription = stompSubscriptions_1_1.value;
6594
+ stompSubscription.unsubscribe();
6595
+ }
6596
+ }
6597
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
6598
+ finally {
6599
+ try {
6600
+ if (stompSubscriptions_1_1 && !stompSubscriptions_1_1.done && (_a = stompSubscriptions_1.return)) _a.call(stompSubscriptions_1);
6601
+ }
6602
+ finally { if (e_5) throw e_5.error; }
6603
+ }
6603
6604
  });
6604
6605
  try {
6605
6606
  for (var _e = __values(this.primitiveManagers.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
@@ -6629,11 +6630,23 @@ var WebsocketService = /** @class */ (function () {
6629
6630
  WebsocketService.prototype.setConnected = function (connected) {
6630
6631
  this.connected = connected;
6631
6632
  };
6632
- WebsocketService.prototype.getSubscriptionUserUrl = function (domain, service, primitive) {
6633
+ WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
6633
6634
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6634
6635
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
6635
6636
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
6636
6637
  };
6638
+ WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
6639
+ var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6640
+ return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
6641
+ };
6642
+ WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
6643
+ var _this = this;
6644
+ return this._stompClient.subscribe(destination, function (message) {
6645
+ var event = JSON.parse(message.body || "{}");
6646
+ _this.addPublishedEvent(primitiveManager, event);
6647
+ primitiveManager.subject.next(event);
6648
+ });
6649
+ };
6637
6650
  WebsocketService.prototype.createStompClient = function () {
6638
6651
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6639
6652
  this._stompClient = Stomp.over(ws);
@@ -6651,12 +6664,10 @@ var WebsocketService = /** @class */ (function () {
6651
6664
  this._stompClient.disconnect();
6652
6665
  var baseUrl = this.getBaseUrl();
6653
6666
  if (this.baseUrl !== null && baseUrl != this.baseUrl) {
6654
- // //console.log('ws disconnected: base url changed', this.baseUrl, ' -> ', baseUrl || 'null');
6655
6667
  return;
6656
6668
  }
6657
6669
  var username = this.getUserName();
6658
6670
  if (this.username !== null && username != this.username) {
6659
- // //console.log('ws disconnected: username changed', this.username, ' -> ', username || 'null');
6660
6671
  return;
6661
6672
  }
6662
6673
  setTimeout(function () {