@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.
@@ -463,7 +463,15 @@
463
463
  ErpLookups.prototype.mountFormField = function (fields, prefix) {
464
464
  var _this = this;
465
465
  return fields.map(function (field) {
466
- return new angularComponents.FormField(__assign(__assign({}, field), { label: _this.translate.instant(prefix + ".lookup_" + _this.toSnakeCase(_this.entity) + "_" + _this.toSnakeCase(field.name)) }));
466
+ var translationKey = prefix + ".lookup_" + _this.toSnakeCase(_this.entity) + "_" + _this.toSnakeCase(field.name);
467
+ var label = _this.translate.instant(translationKey);
468
+ if (label === translationKey) {
469
+ // Manter compatibilidade com os lookups atuais até todos ajustarem
470
+ var fieldName = field.name.split('.').join('_');
471
+ translationKey = prefix + ".lookup_" + _this.toSnakeCase(_this.entity) + "_" + _this.toSnakeCase(fieldName);
472
+ label = _this.translate.instant(translationKey);
473
+ }
474
+ return new angularComponents.FormField(__assign(__assign({}, field), { label: label }));
467
475
  });
468
476
  };
469
477
  ErpLookups.prototype.mountDefaultFilter = function (defaultFilter) {
@@ -6758,14 +6766,23 @@
6758
6766
 
6759
6767
  var WebsocketService = /** @class */ (function () {
6760
6768
  function WebsocketService() {
6769
+ /** @private */
6761
6770
  this.focused = true;
6771
+ /** @private */
6762
6772
  this.wasConnected = false;
6773
+ /** @private */
6763
6774
  this.connected = false;
6775
+ /** @private */
6764
6776
  this.isConnecting = false;
6777
+ /** @private */
6765
6778
  this.primitiveManagers = new Map();
6779
+ /** @private */
6766
6780
  this.connect$ = new rxjs.Subject();
6781
+ /** @private */
6767
6782
  this.disconnect$ = new rxjs.Subject();
6783
+ /** @private */
6768
6784
  this.reconnect$ = new rxjs.Subject();
6785
+ /** @private */
6769
6786
  this.error$ = new rxjs.Subject();
6770
6787
  window.onfocus = this.onFocus;
6771
6788
  window.onblur = this.onBlur;
@@ -6807,18 +6824,19 @@
6807
6824
  return this.error$.asObservable();
6808
6825
  };
6809
6826
  /**
6810
- * Observable responsável por emitir uma notificação quando um evento é publicado.
6811
6827
  * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6812
- * @param domain Dominio da primitiva.
6813
- * @param service Service da primitiva.
6814
- * @param primitive Primitiva que será "observada" pelo client.
6815
- * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
6816
- * @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
6828
+ * @param {Object} options Objeto de configuração do evento.
6829
+ * @param {string} options.domain Domínio da primitiva.
6830
+ * @param {string} options.service Serviço da primitiva.
6831
+ * @param {string} options.primitive Primitiva que será "observada".
6832
+ * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
6817
6833
  */
6818
- WebsocketService.prototype.onEvent = function (domain, service, primitive, identifierPath) {
6834
+ WebsocketService.prototype.onEvent = function (options) {
6819
6835
  var _this = this;
6820
- if (this.primitiveManagers.has(primitive)) {
6821
- return this.primitiveManagers.get(primitive).subject.asObservable();
6836
+ var domain = options.domain, service = options.service, primitive = options.primitive;
6837
+ var key = this.getPrimitiveManagerKey(domain, service, primitive);
6838
+ if (this.primitiveManagers.has(key)) {
6839
+ return this.primitiveManagers.get(key).subject.asObservable();
6822
6840
  }
6823
6841
  var primitiveManager = {
6824
6842
  domain: domain,
@@ -6826,13 +6844,11 @@
6826
6844
  primitive: primitive,
6827
6845
  stompSubscriptions: [],
6828
6846
  subject: new rxjs.Subject(),
6829
- identifierPath: identifierPath,
6830
- publishedEvents: [],
6831
6847
  };
6832
- this.primitiveManagers.set(primitive, primitiveManager);
6848
+ this.primitiveManagers.set(key, primitiveManager);
6833
6849
  if (this.isConnected()) {
6834
6850
  this.createStompSubscriptions(primitiveManager);
6835
- return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6851
+ return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6836
6852
  }
6837
6853
  else {
6838
6854
  if (!this.isConnecting) {
@@ -6841,53 +6857,10 @@
6841
6857
  this.connect$.pipe(operators.first()).subscribe(function () {
6842
6858
  _this.createStompSubscriptions(primitiveManager);
6843
6859
  });
6844
- return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitive); }));
6845
- }
6846
- };
6847
- /**
6848
- * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6849
- * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6850
- * @param primitive Primitiva que será "observada" pelo client.
6851
- * @param identifiers Array com os identificadores interessados.
6852
- * @return Array contendo o último evento recebido de cada identificador fornecido.
6853
- */
6854
- WebsocketService.prototype.getPublishedEvents = function (primitive, identifiers) {
6855
- var e_1, _a;
6856
- var _this = this;
6857
- var publishedEvents = [];
6858
- var primitiveManager = this.primitiveManagers.get(primitive);
6859
- var _loop_1 = function (identifier) {
6860
- var event_1 = primitiveManager.publishedEvents.find(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6861
- if (event_1) {
6862
- publishedEvents.push(event_1);
6863
- }
6864
- };
6865
- try {
6866
- for (var identifiers_1 = __values(identifiers), identifiers_1_1 = identifiers_1.next(); !identifiers_1_1.done; identifiers_1_1 = identifiers_1.next()) {
6867
- var identifier = identifiers_1_1.value;
6868
- _loop_1(identifier);
6869
- }
6870
- }
6871
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
6872
- finally {
6873
- try {
6874
- if (identifiers_1_1 && !identifiers_1_1.done && (_a = identifiers_1.return)) _a.call(identifiers_1);
6875
- }
6876
- finally { if (e_1) throw e_1.error; }
6877
- }
6878
- return publishedEvents;
6879
- };
6880
- WebsocketService.prototype.addPublishedEvent = function (primitiveManager, event) {
6881
- var _this = this;
6882
- var identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6883
- var eventIndex = primitiveManager.publishedEvents.findIndex(function (x) { return _this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier; });
6884
- if (eventIndex !== -1) {
6885
- primitiveManager.publishedEvents[eventIndex] = __assign(__assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6886
- }
6887
- else {
6888
- primitiveManager.publishedEvents.push(event);
6860
+ return primitiveManager.subject.pipe(operators.finalize(function () { return _this.disconnectPrimitiveOnFinalize(primitiveManager); }));
6889
6861
  }
6890
6862
  };
6863
+ /** @private */
6891
6864
  WebsocketService.prototype.createStompSubscriptions = function (primitiveManager) {
6892
6865
  var withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6893
6866
  var stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
@@ -6895,25 +6868,7 @@
6895
6868
  var stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6896
6869
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
6897
6870
  };
6898
- WebsocketService.prototype.getIdentifierFromEvent = function (identifierPath, event) {
6899
- var e_2, _a;
6900
- var properties = identifierPath.split(".");
6901
- var identifier = event;
6902
- try {
6903
- for (var properties_1 = __values(properties), properties_1_1 = properties_1.next(); !properties_1_1.done; properties_1_1 = properties_1.next()) {
6904
- var property = properties_1_1.value;
6905
- identifier = identifier[property];
6906
- }
6907
- }
6908
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
6909
- finally {
6910
- try {
6911
- if (properties_1_1 && !properties_1_1.done && (_a = properties_1.return)) _a.call(properties_1);
6912
- }
6913
- finally { if (e_2) throw e_2.error; }
6914
- }
6915
- return identifier;
6916
- };
6871
+ /** @private */
6917
6872
  WebsocketService.prototype.connect = function () {
6918
6873
  var _this = this;
6919
6874
  this.createStompClient();
@@ -6936,14 +6891,16 @@
6936
6891
  _this.reconnect();
6937
6892
  });
6938
6893
  };
6894
+ /** @private */
6939
6895
  WebsocketService.prototype.onFocus = function () {
6940
6896
  this.focused = true;
6941
6897
  };
6898
+ /** @private */
6942
6899
  WebsocketService.prototype.onBlur = function () {
6943
6900
  this.focused = false;
6944
6901
  };
6945
6902
  WebsocketService.prototype.disconnect = function () {
6946
- var e_3, _a, e_4, _b, e_5, _c;
6903
+ var e_1, _a, e_2, _b, e_3, _c;
6947
6904
  var observersCount = this.getObserversCount();
6948
6905
  if (observersCount > 0)
6949
6906
  return;
@@ -6951,26 +6908,26 @@
6951
6908
  for (var _d = __values(this.primitiveManagers.values()), _e = _d.next(); !_e.done; _e = _d.next()) {
6952
6909
  var primitiveManager = _e.value;
6953
6910
  try {
6954
- for (var _f = (e_4 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6911
+ for (var _f = (e_2 = void 0, __values(primitiveManager.stompSubscriptions)), _g = _f.next(); !_g.done; _g = _f.next()) {
6955
6912
  var stompSubscription = _g.value;
6956
6913
  stompSubscription.unsubscribe();
6957
6914
  }
6958
6915
  }
6959
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
6916
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
6960
6917
  finally {
6961
6918
  try {
6962
6919
  if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
6963
6920
  }
6964
- finally { if (e_4) throw e_4.error; }
6921
+ finally { if (e_2) throw e_2.error; }
6965
6922
  }
6966
6923
  }
6967
6924
  }
6968
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
6925
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
6969
6926
  finally {
6970
6927
  try {
6971
6928
  if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
6972
6929
  }
6973
- finally { if (e_3) throw e_3.error; }
6930
+ finally { if (e_1) throw e_1.error; }
6974
6931
  }
6975
6932
  try {
6976
6933
  for (var _h = __values(this.primitiveManagers.values()), _j = _h.next(); !_j.done; _j = _h.next()) {
@@ -6978,12 +6935,12 @@
6978
6935
  primitiveManager.subject.complete();
6979
6936
  }
6980
6937
  }
6981
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
6938
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
6982
6939
  finally {
6983
6940
  try {
6984
6941
  if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
6985
6942
  }
6986
- finally { if (e_5) throw e_5.error; }
6943
+ finally { if (e_3) throw e_3.error; }
6987
6944
  }
6988
6945
  this.primitiveManagers.clear();
6989
6946
  this._stompClient.disconnect();
@@ -6993,35 +6950,40 @@
6993
6950
  this.wasConnected = false;
6994
6951
  this.disconnect$.next();
6995
6952
  };
6953
+ /** @private */
6996
6954
  WebsocketService.prototype.isConnected = function () {
6997
6955
  return this.connected;
6998
6956
  };
6957
+ /** @private */
6999
6958
  WebsocketService.prototype.setConnected = function (connected) {
7000
6959
  this.connected = connected;
7001
6960
  };
6961
+ /** @private */
7002
6962
  WebsocketService.prototype.getSubscriptionUrlWithToken = function (domain, service, primitive) {
7003
6963
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7004
6964
  var token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
7005
6965
  return "/topic/" + tenant + "/" + token + "/" + domain + "/" + service + "/" + primitive;
7006
6966
  };
6967
+ /** @private */
7007
6968
  WebsocketService.prototype.getSubscriptionUrlWithoutToken = function (domain, service, primitive) {
7008
6969
  var tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
7009
6970
  return "/topic/" + tenant + "/" + domain + "/" + service + "/" + primitive;
7010
6971
  };
6972
+ /** @private */
7011
6973
  WebsocketService.prototype.createStompSubscription = function (destination, primitiveManager) {
7012
- var _this = this;
7013
6974
  return this._stompClient.subscribe(destination, function (message) {
7014
6975
  var event = JSON.parse(message.body || "{}");
7015
- _this.addPublishedEvent(primitiveManager, event);
7016
6976
  primitiveManager.subject.next(event);
7017
6977
  });
7018
6978
  };
6979
+ /** @private */
7019
6980
  WebsocketService.prototype.createStompClient = function () {
7020
6981
  var ws = new SockJS(WebsocketService_1.WEBSOCKET_URL + "subscription", null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
7021
6982
  this._stompClient = stompjs.Stomp.over(ws);
7022
6983
  // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
7023
6984
  this._stompClient.debug = function () { }; // Para remover os logs.
7024
6985
  };
6986
+ /** @private */
7025
6987
  WebsocketService.prototype.reconnect = function () {
7026
6988
  var _this = this;
7027
6989
  if (this.connected)
@@ -7037,37 +6999,39 @@
7037
6999
  }
7038
7000
  }, WebsocketService_1.RECONNECT_TIMER);
7039
7001
  };
7002
+ /** @private */
7040
7003
  WebsocketService.prototype.reconnectPrimitives = function () {
7041
- var e_6, _a, e_7, _b;
7004
+ var e_4, _a, e_5, _b;
7042
7005
  try {
7043
7006
  for (var _c = __values(this.primitiveManagers.values()), _d = _c.next(); !_d.done; _d = _c.next()) {
7044
7007
  var primitiveManager = _d.value;
7045
7008
  try {
7046
- for (var _e = (e_7 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
7009
+ for (var _e = (e_5 = void 0, __values(primitiveManager.stompSubscriptions)), _f = _e.next(); !_f.done; _f = _e.next()) {
7047
7010
  var stompSubscription = _f.value;
7048
7011
  stompSubscription.unsubscribe();
7049
7012
  }
7050
7013
  }
7051
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
7014
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
7052
7015
  finally {
7053
7016
  try {
7054
7017
  if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
7055
7018
  }
7056
- finally { if (e_7) throw e_7.error; }
7019
+ finally { if (e_5) throw e_5.error; }
7057
7020
  }
7058
7021
  this.createStompSubscriptions(primitiveManager);
7059
7022
  }
7060
7023
  }
7061
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
7024
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
7062
7025
  finally {
7063
7026
  try {
7064
7027
  if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
7065
7028
  }
7066
- finally { if (e_6) throw e_6.error; }
7029
+ finally { if (e_4) throw e_4.error; }
7067
7030
  }
7068
7031
  };
7032
+ /** @private */
7069
7033
  WebsocketService.prototype.getObserversCount = function () {
7070
- var e_8, _a;
7034
+ var e_6, _a;
7071
7035
  var observersCount = 0;
7072
7036
  try {
7073
7037
  for (var _b = __values(this.primitiveManagers.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
@@ -7075,21 +7039,19 @@
7075
7039
  observersCount += primitiveManager.subject.observers.length;
7076
7040
  }
7077
7041
  }
7078
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
7042
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
7079
7043
  finally {
7080
7044
  try {
7081
7045
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7082
7046
  }
7083
- finally { if (e_8) throw e_8.error; }
7047
+ finally { if (e_6) throw e_6.error; }
7084
7048
  }
7085
7049
  return observersCount;
7086
7050
  };
7087
- WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitive) {
7088
- var e_9, _a;
7089
- var primitiveManager = this.primitiveManagers.get(primitive);
7090
- if (!primitiveManager)
7091
- return;
7092
- // @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
7051
+ /** @private */
7052
+ WebsocketService.prototype.disconnectPrimitiveOnFinalize = function (primitiveManager) {
7053
+ var e_7, _a;
7054
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
7093
7055
  var hasObservers = !(primitiveManager.subject.observers.length === 1);
7094
7056
  if (hasObservers)
7095
7057
  return;
@@ -7099,22 +7061,33 @@
7099
7061
  stompSubscription.unsubscribe();
7100
7062
  }
7101
7063
  }
7102
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
7064
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
7103
7065
  finally {
7104
7066
  try {
7105
7067
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
7106
7068
  }
7107
- finally { if (e_9) throw e_9.error; }
7069
+ finally { if (e_7) throw e_7.error; }
7108
7070
  }
7109
- this.primitiveManagers.delete(primitive);
7071
+ var key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
7072
+ this.primitiveManagers.delete(key);
7110
7073
  this.disconnect();
7111
7074
  };
7075
+ /** @private */
7076
+ WebsocketService.prototype.getPrimitiveManagerKey = function (domain, service, primitive) {
7077
+ return domain + "/" + service + "/" + primitive;
7078
+ };
7112
7079
  var WebsocketService_1;
7080
+ /** @private */
7113
7081
  WebsocketService.RECONNECT_TIMER = 3000;
7082
+ /** @private */
7114
7083
  WebsocketService.CONNECTION_TIMEOUT = 15000;
7084
+ /** @private */
7115
7085
  WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
7086
+ /** @private */
7116
7087
  WebsocketService.TOKEN_COOKIE = "com.senior.token";
7088
+ /** @private */
7117
7089
  WebsocketService.TOKEN = JSON.parse(jsCookie.get(WebsocketService_1.TOKEN_COOKIE) || "{}");
7090
+ /** @private */
7118
7091
  WebsocketService.WEBSOCKET_URL = jsCookie.get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
7119
7092
  WebsocketService.ɵprov = core.ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
7120
7093
  WebsocketService = WebsocketService_1 = __decorate([