@senior-gestao-empresarial/angular-components 5.1.1 → 6.0.1

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.
@@ -257,7 +257,15 @@ var ErpLookups = /** @class */ (function () {
257
257
  ErpLookups.prototype.mountFormField = function (fields, prefix) {
258
258
  var _this = this;
259
259
  return fields.map(function (field) {
260
- return new FormField(__assign(__assign({}, field), { label: _this.translate.instant(prefix + ".lookup_" + _this.toSnakeCase(_this.entity) + "_" + _this.toSnakeCase(field.name)) }));
260
+ var translationKey = prefix + ".lookup_" + _this.toSnakeCase(_this.entity) + "_" + _this.toSnakeCase(field.name);
261
+ var label = _this.translate.instant(translationKey);
262
+ if (label === translationKey) {
263
+ // Manter compatibilidade com os lookups atuais até todos ajustarem
264
+ var fieldName = field.name.split('.').join('_');
265
+ translationKey = prefix + ".lookup_" + _this.toSnakeCase(_this.entity) + "_" + _this.toSnakeCase(fieldName);
266
+ label = _this.translate.instant(translationKey);
267
+ }
268
+ return new FormField(__assign(__assign({}, field), { label: label }));
261
269
  });
262
270
  };
263
271
  ErpLookups.prototype.mountDefaultFilter = function (defaultFilter) {
@@ -6552,14 +6560,23 @@ var NpsService = /** @class */ (function () {
6552
6560
 
6553
6561
  var WebsocketService = /** @class */ (function () {
6554
6562
  function WebsocketService() {
6563
+ /** @private */
6555
6564
  this.focused = true;
6565
+ /** @private */
6556
6566
  this.wasConnected = false;
6567
+ /** @private */
6557
6568
  this.connected = false;
6569
+ /** @private */
6558
6570
  this.isConnecting = false;
6571
+ /** @private */
6559
6572
  this.primitiveManagers = new Map();
6573
+ /** @private */
6560
6574
  this.connect$ = new Subject();
6575
+ /** @private */
6561
6576
  this.disconnect$ = new Subject();
6577
+ /** @private */
6562
6578
  this.reconnect$ = new Subject();
6579
+ /** @private */
6563
6580
  this.error$ = new Subject();
6564
6581
  window.onfocus = this.onFocus;
6565
6582
  window.onblur = this.onBlur;
@@ -6601,18 +6618,19 @@ var WebsocketService = /** @class */ (function () {
6601
6618
  return this.error$.asObservable();
6602
6619
  };
6603
6620
  /**
6604
- * Observable responsável por emitir uma notificação quando um evento é publicado.
6605
6621
  * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6606
- * @param domain Dominio da primitiva.
6607
- * @param service Service da primitiva.
6608
- * @param primitive Primitiva que será "observada" pelo client.
6609
- * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
6610
- * @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
6622
+ * @param {Object} options Objeto de configuração do evento.
6623
+ * @param {string} options.domain Domínio da primitiva.
6624
+ * @param {string} options.service Serviço da primitiva.
6625
+ * @param {string} options.primitive Primitiva que será "observada".
6626
+ * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
6611
6627
  */
6612
- WebsocketService.prototype.onEvent = function (domain, service, primitive, identifierPath) {
6628
+ WebsocketService.prototype.onEvent = function (options) {
6613
6629
  var _this = this;
6614
- if (this.primitiveManagers.has(primitive)) {
6615
- return this.primitiveManagers.get(primitive).subject.asObservable();
6630
+ var domain = options.domain, service = options.service, primitive = options.primitive;
6631
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
6632
+ if (this.primitiveManagers.has(key)) {
6633
+ return this.primitiveManagers.get(key).subject.asObservable();
6616
6634
  }
6617
6635
  var primitiveManager = {
6618
6636
  domain: domain,
@@ -6620,13 +6638,11 @@ var WebsocketService = /** @class */ (function () {
6620
6638
  primitive: primitive,
6621
6639
  stompSubscriptions: [],
6622
6640
  subject: new Subject(),
6623
- identifierPath: identifierPath,
6624
- publishedEvents: [],
6625
6641
  };
6626
- this.primitiveManagers.set(primitive, primitiveManager);
6642
+ this.primitiveManagers.set(key, primitiveManager);
6627
6643
  if (this.isConnected()) {
6628
6644
  this.createStompSubscriptions(primitiveManager);
6629
- return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6645
+ return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6630
6646
  }
6631
6647
  else {
6632
6648
  if (!this.isConnecting) {
@@ -6635,53 +6651,10 @@ var WebsocketService = /** @class */ (function () {
6635
6651
  this.connect$.pipe(first()).subscribe(function () {
6636
6652
  _this.createStompSubscriptions(primitiveManager);
6637
6653
  });
6638
- return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6639
- }
6640
- };
6641
- /**
6642
- * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6643
- * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6644
- * @param primitive Primitiva que será "observada" pelo client.
6645
- * @param identifiers Array com os identificadores interessados.
6646
- * @return Array contendo o último evento recebido de cada identificador fornecido.
6647
- */
6648
- WebsocketService.prototype.getPublishedEvents = function (primitive, identifiers) {
6649
- var e_1, _a;
6650
- var _this = this;
6651
- var publishedEvents = [];
6652
- var primitiveManager = this.primitiveManagers.get(primitive);
6653
- var _loop_1 = function (identifier) {
6654
- var event_1 = primitiveManager.publishedEvents.find(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6655
- if (event_1) {
6656
- publishedEvents.push(event_1);
6657
- }
6658
- };
6659
- try {
6660
- for (var identifiers_1 = __values(identifiers), identifiers_1_1 = identifiers_1.next(); !identifiers_1_1.done; identifiers_1_1 = identifiers_1.next()) {
6661
- var identifier = identifiers_1_1.value;
6662
- _loop_1(identifier);
6663
- }
6664
- }
6665
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6666
- finally {
6667
- try {
6668
- if (identifiers_1_1 && !identifiers_1_1.done && (_a = identifiers_1.return)) _a.call(identifiers_1);
6669
- }
6670
- finally { if (e_1) throw e_1.error; }
6671
- }
6672
- return publishedEvents;
6673
- };
6674
- WebsocketService.prototype.addPublishedEvent = function (primitiveManager, event) {
6675
- var _this = this;
6676
- var identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6677
- var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6678
- if (eventIndex !== -1) {
6679
- primitiveManager.publishedEvents[eventIndex] = __assign(__assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6680
- }
6681
- else {
6682
- primitiveManager.publishedEvents.push(event);
6654
+ return primitiveManager.subject.pipe(finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6683
6655
  }
6684
6656
  };
6657
+ /** @private */
6685
6658
  WebsocketService.prototype.createStompSubscriptions = function (primitiveManager) {
6686
6659
  var withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6687
6660
  var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
@@ -6689,25 +6662,7 @@ var WebsocketService = /** @class */ (function () {
6689
6662
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6690
6663
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
6691
6664
  };
6692
- WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6693
- var e_2, _a;
6694
- var properties = identifierPath.split(".");
6695
- var identifier = event;
6696
- try {
6697
- for (var properties_1 = __values(properties), properties_1_1 = properties_1.next(); !properties_1_1.done; properties_1_1 = properties_1.next()) {
6698
- var property = properties_1_1.value;
6699
- identifier = identifier[property];
6700
- }
6701
- }
6702
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
6703
- finally {
6704
- try {
6705
- if (properties_1_1 && !properties_1_1.done && (_a = properties_1.return)) _a.call(properties_1);
6706
- }
6707
- finally { if (e_2) throw e_2.error; }
6708
- }
6709
- return identifier;
6710
- };
6665
+ /** @private */
6711
6666
  WebsocketService.prototype.connect = function () {
6712
6667
  var _this = this;
6713
6668
  this.createStompClient();
@@ -6730,14 +6685,16 @@ var WebsocketService = /** @class */ (function () {
6730
6685
  _this.reconnect();
6731
6686
  });
6732
6687
  };
6688
+ /** @private */
6733
6689
  WebsocketService.prototype.onFocus = function () {
6734
6690
  this.focused = true;
6735
6691
  };
6692
+ /** @private */
6736
6693
  WebsocketService.prototype.onBlur = function () {
6737
6694
  this.focused = false;
6738
6695
  };
6739
6696
  WebsocketService.prototype.disconnect = function () {
6740
- var e_3, _a, e_4, _b, e_5, _c;
6697
+ var e_1, _a, e_2, _b, e_3, _c;
6741
6698
  var observersCount = this.getObserversCount();
6742
6699
  if (observersCount > 0)
6743
6700
  return;
@@ -6745,26 +6702,26 @@ var WebsocketService = /** @class */ (function () {
6745
6702
  for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
6746
6703
  var primitiveManager = _e.value;
6747
6704
  try {
6748
- for (var _f = (e_4 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6705
+ for (var _f = (e_2 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6749
6706
  var stompSubscription = _g.value;
6750
6707
  stompSubscription.unsubscribe();
6751
6708
  }
6752
6709
  }
6753
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
6710
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
6754
6711
  finally {
6755
6712
  try {
6756
6713
  if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
6757
6714
  }
6758
- finally { if (e_4) throw e_4.error; }
6715
+ finally { if (e_2) throw e_2.error; }
6759
6716
  }
6760
6717
  }
6761
6718
  }
6762
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
6719
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
6763
6720
  finally {
6764
6721
  try {
6765
6722
  if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
6766
6723
  }
6767
- finally { if (e_3) throw e_3.error; }
6724
+ finally { if (e_1) throw e_1.error; }
6768
6725
  }
6769
6726
  try {
6770
6727
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
@@ -6772,12 +6729,12 @@ var WebsocketService = /** @class */ (function () {
6772
6729
  primitiveManager.subject.complete();
6773
6730
  }
6774
6731
  }
6775
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
6732
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
6776
6733
  finally {
6777
6734
  try {
6778
6735
  if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
6779
6736
  }
6780
- finally { if (e_5) throw e_5.error; }
6737
+ finally { if (e_3) throw e_3.error; }
6781
6738
  }
6782
6739
  this.primitiveManagers.clear();
6783
6740
  this._stompClient.disconnect();
@@ -6787,35 +6744,40 @@ var WebsocketService = /** @class */ (function () {
6787
6744
  this.wasConnected = false;
6788
6745
  this.disconnect$.next();
6789
6746
  };
6747
+ /** @private */
6790
6748
  WebsocketService.prototype.isConnected = function () {
6791
6749
  return this.connected;
6792
6750
  };
6751
+ /** @private */
6793
6752
  WebsocketService.prototype.setConnected = function (connected) {
6794
6753
  this.connected = connected;
6795
6754
  };
6755
+ /** @private */
6796
6756
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
6797
6757
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6798
6758
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
6799
6759
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
6800
6760
  };
6761
+ /** @private */
6801
6762
  WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
6802
6763
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6803
6764
  return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
6804
6765
  };
6766
+ /** @private */
6805
6767
  WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
6806
- var _this = this;
6807
6768
  return this._stompClient.subscribe(destination, function (message) {
6808
6769
  var event = JSON.parse(message.body || "{}");
6809
- _this.addPublishedEvent(primitiveManager, event);
6810
6770
  primitiveManager.subject.next(event);
6811
6771
  });
6812
6772
  };
6773
+ /** @private */
6813
6774
  WebsocketService.prototype.createStompClient = function () {
6814
6775
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6815
6776
  this._stompClient = Stomp.over(ws);
6816
6777
  // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
6817
6778
  this._stompClient.debug = function () { }; // Para remover os logs.
6818
6779
  };
6780
+ /** @private */
6819
6781
  WebsocketService.prototype.reconnect = function () {
6820
6782
  var _this = this;
6821
6783
  if (this.connected)
@@ -6831,37 +6793,39 @@ var WebsocketService = /** @class */ (function () {
6831
6793
  }
6832
6794
  }, WebsocketService_1.RECONNECT_TIMER);
6833
6795
  };
6796
+ /** @private */
6834
6797
  WebsocketService.prototype.reconnectPrimitives = function () {
6835
- var e_6, _a, e_7, _b;
6798
+ var e_4, _a, e_5, _b;
6836
6799
  try {
6837
6800
  for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
6838
6801
  var primitiveManager = _d.value;
6839
6802
  try {
6840
- for (var _e = (e_7 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
6803
+ for (var _e = (e_5 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
6841
6804
  var stompSubscription = _f.value;
6842
6805
  stompSubscription.unsubscribe();
6843
6806
  }
6844
6807
  }
6845
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
6808
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
6846
6809
  finally {
6847
6810
  try {
6848
6811
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
6849
6812
  }
6850
- finally { if (e_7) throw e_7.error; }
6813
+ finally { if (e_5) throw e_5.error; }
6851
6814
  }
6852
6815
  this.createStompSubscriptions(primitiveManager);
6853
6816
  }
6854
6817
  }
6855
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
6818
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
6856
6819
  finally {
6857
6820
  try {
6858
6821
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
6859
6822
  }
6860
- finally { if (e_6) throw e_6.error; }
6823
+ finally { if (e_4) throw e_4.error; }
6861
6824
  }
6862
6825
  };
6826
+ /** @private */
6863
6827
  WebsocketService.prototype.getObserversCount = function () {
6864
- var e_8, _a;
6828
+ var e_6, _a;
6865
6829
  var observersCount = 0;
6866
6830
  try {
6867
6831
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -6869,21 +6833,19 @@ var WebsocketService = /** @class */ (function () {
6869
6833
  observersCount += primitiveManager.subject.observers.length;
6870
6834
  }
6871
6835
  }
6872
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
6836
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
6873
6837
  finally {
6874
6838
  try {
6875
6839
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6876
6840
  }
6877
- finally { if (e_8) throw e_8.error; }
6841
+ finally { if (e_6) throw e_6.error; }
6878
6842
  }
6879
6843
  return observersCount;
6880
6844
  };
6881
- WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitive) {
6882
- var e_9, _a;
6883
- var primitiveManager = this.primitiveManagers.get(primitive);
6884
- if (!primitiveManager)
6885
- return;
6886
- // @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
6845
+ /** @private */
6846
+ WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
6847
+ var e_7, _a;
6848
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
6887
6849
  var hasObservers = !(primitiveManager.subject.observers.length === 1);
6888
6850
  if (hasObservers)
6889
6851
  return;
@@ -6893,22 +6855,33 @@ var WebsocketService = /** @class */ (function () {
6893
6855
  stompSubscription.unsubscribe();
6894
6856
  }
6895
6857
  }
6896
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
6858
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
6897
6859
  finally {
6898
6860
  try {
6899
6861
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
6900
6862
  }
6901
- finally { if (e_9) throw e_9.error; }
6863
+ finally { if (e_7) throw e_7.error; }
6902
6864
  }
6903
- this.primitiveManagers.delete(primitive);
6865
+ var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6866
+ this.primitiveManagers.delete(key);
6904
6867
  this.disconnect();
6905
6868
  };
6869
+ /** @private */
6870
+ WebsocketService.prototype.getPrimitiveManagerKey = function (domain, service, primitive) {
6871
+ return domain + "/" + service + "/" + primitive;
6872
+ };
6906
6873
  var WebsocketService_1;
6874
+ /** @private */
6907
6875
  WebsocketService.RECONNECT_TIMER = 3000;
6876
+ /** @private */
6908
6877
  WebsocketService.CONNECTION_TIMEOUT = 15000;
6878
+ /** @private */
6909
6879
  WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
6880
+ /** @private */
6910
6881
  WebsocketService.TOKEN_COOKIE = "com.senior.token";
6882
+ /** @private */
6911
6883
  WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || "{}");
6884
+ /** @private */
6912
6885
  WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
6913
6886
  WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
6914
6887
  WebsocketService = WebsocketService_1 = __decorate([