@senior-gestao-empresarial/angular-components 4.21.1 → 4.22.0-c6f90211-2bfd-46c1-b41f-98ce3aba88b5

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,7 +6421,7 @@ 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.
6424
+ * Observable responsável por emitir uma notificação quando a conexão websocket é estabelecida.
6426
6425
  * @return Um `Observable<void>` que emite uma notificação quando a conexão websocket é estabelecida ou já está em andamento.
6427
6426
  */
6428
6427
  WebsocketService.prototype.onConnect = function () {
@@ -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 () {
@@ -6462,14 +6461,7 @@ var WebsocketService = /** @class */ (function () {
6462
6461
  publishedEvents: [],
6463
6462
  };
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,22 +6469,15 @@ 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
6483
  * @param identifiers Array com os indentificadores interessados.
@@ -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,23 @@ 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 _this = this;
6525
+ var withUserUrl = this.getSubscriptionWithUserUrl(domain, service, primitive);
6526
+ this.primitiveManagers.set(primitive, primitiveManager);
6527
+ var stompSubscriptionWithUser = this._stompClient.subscribe(withUserUrl, function (message) {
6528
+ var event = JSON.parse(message.body || "{}");
6529
+ _this.addPublishedEvent(primitiveManager, event);
6530
+ primitiveManager.subject.next(event);
6531
+ });
6532
+ var withoutUserUrl = this.getSubscriptionWithoutUserUrl(domain, service, primitive);
6533
+ var stompSubscriptionWithoutUser = this._stompClient.subscribe(withoutUserUrl, function (message) {
6534
+ var event = JSON.parse(message.body || "{}");
6535
+ _this.addPublishedEvent(primitiveManager, event);
6536
+ primitiveManager.subject.next(event);
6537
+ });
6538
+ this.stompSubscriptions.set(primitive, [stompSubscriptionWithUser, stompSubscriptionWithoutUser]);
6539
+ };
6540
6540
  WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6541
6541
  var e_2, _a;
6542
6542
  var properties = identifierPath.split(".");
@@ -6562,9 +6562,7 @@ var WebsocketService = /** @class */ (function () {
6562
6562
  this.isConnecting = true;
6563
6563
  this._stompClient.connect({}, function () {
6564
6564
  _this.setConnected(true);
6565
- // console.log('setou false isConnecting');
6566
6565
  _this.isConnecting = false;
6567
- // console.log('connectou dentro do connect cb');
6568
6566
  _this.publishOnConnect();
6569
6567
  }, function () {
6570
6568
  _this.setConnected(false);
@@ -6598,8 +6596,21 @@ var WebsocketService = /** @class */ (function () {
6598
6596
  finally { if (e_3) throw e_3.error; }
6599
6597
  }
6600
6598
  if (observersCount === 0) {
6601
- this.stompSubscriptions.forEach(function (stompSubscription) {
6602
- stompSubscription.unsubscribe();
6599
+ this.stompSubscriptions.forEach(function (stompSubscriptions) {
6600
+ var e_5, _a;
6601
+ try {
6602
+ for (var stompSubscriptions_1 = __values(stompSubscriptions), stompSubscriptions_1_1 = stompSubscriptions_1.next(); !stompSubscriptions_1_1.done; stompSubscriptions_1_1 = stompSubscriptions_1.next()) {
6603
+ var stompSubscription = stompSubscriptions_1_1.value;
6604
+ stompSubscription.unsubscribe();
6605
+ }
6606
+ }
6607
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
6608
+ finally {
6609
+ try {
6610
+ if (stompSubscriptions_1_1 && !stompSubscriptions_1_1.done && (_a = stompSubscriptions_1.return)) _a.call(stompSubscriptions_1);
6611
+ }
6612
+ finally { if (e_5) throw e_5.error; }
6613
+ }
6603
6614
  });
6604
6615
  try {
6605
6616
  for (var _e = __values(this.primitiveManagers.values()), _f = _e.next(); !_f.done; _f = _e.next()) {
@@ -6629,11 +6640,15 @@ var WebsocketService = /** @class */ (function () {
6629
6640
  WebsocketService.prototype.setConnected = function (connected) {
6630
6641
  this.connected = connected;
6631
6642
  };
6632
- WebsocketService.prototype.getSubscriptionUserUrl = function (domain, service, primitive) {
6643
+ WebsocketService.prototype.getSubscriptionWithUserUrl = function (domain, service, primitive) {
6633
6644
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6634
6645
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
6635
6646
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
6636
6647
  };
6648
+ WebsocketService.prototype.getSubscriptionWithoutUserUrl = function (domain, service, primitive) {
6649
+ var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6650
+ return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
6651
+ };
6637
6652
  WebsocketService.prototype.createStompClient = function () {
6638
6653
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6639
6654
  this._stompClient = Stomp.over(ws);
@@ -6651,12 +6666,10 @@ var WebsocketService = /** @class */ (function () {
6651
6666
  this._stompClient.disconnect();
6652
6667
  var baseUrl = this.getBaseUrl();
6653
6668
  if (this.baseUrl !== null && baseUrl != this.baseUrl) {
6654
- // //console.log('ws disconnected: base url changed', this.baseUrl, ' -> ', baseUrl || 'null');
6655
6669
  return;
6656
6670
  }
6657
6671
  var username = this.getUserName();
6658
6672
  if (this.username !== null && username != this.username) {
6659
- // //console.log('ws disconnected: username changed', this.username, ' -> ', username || 'null');
6660
6673
  return;
6661
6674
  }
6662
6675
  setTimeout(function () {
@@ -6717,18 +6730,20 @@ var VerifyModulePermission = /** @class */ (function () {
6717
6730
  /**
6718
6731
  * Method to verify if user has permission on a specific module
6719
6732
  * @param module Module to verify the permission
6733
+ * @param requestPermission Indicative if must be call the primitive
6720
6734
  * @returns An boolean Observable
6721
6735
  */
6722
- VerifyModulePermission.prototype.hasPermission = function (module) {
6736
+ VerifyModulePermission.prototype.hasPermission = function (module, requestPermission) {
6723
6737
  var moduleSubject = VerifyModulePermission_1.subjectsPerModuleMap.get(module);
6724
- if (!moduleSubject) {
6738
+ if (!moduleSubject || requestPermission) {
6725
6739
  var newModuleSubject_1 = new ReplaySubject(1);
6726
6740
  VerifyModulePermission_1.subjectsPerModuleMap.set(module, newModuleSubject_1);
6727
6741
  this.verifyModulePermissionService
6728
- .queryModule({ modulo: module })
6742
+ .queryModule({ modulo: module, somenteAtivo: true })
6729
6743
  .pipe(take(1))
6730
6744
  .subscribe(function (response) {
6731
- var hasPermission = !!response.modulos.find(function (modulo) { return modulo.ativo && !modulo.empresa; });
6745
+ var _a;
6746
+ var hasPermission = ((_a = response === null || response === void 0 ? void 0 : response.modulos) === null || _a === void 0 ? void 0 : _a.length) > 0;
6732
6747
  newModuleSubject_1.next(hasPermission);
6733
6748
  }, function (err) {
6734
6749
  VerifyModulePermission_1.subjectsPerModuleMap.delete(module);