@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.
@@ -250,7 +250,15 @@ class ErpLookups {
250
250
  }
251
251
  mountFormField(fields, prefix) {
252
252
  return fields.map((field) => {
253
- return new FormField(Object.assign(Object.assign({}, field), { label: this.translate.instant(`${prefix}.lookup_${this.toSnakeCase(this.entity)}_${this.toSnakeCase(field.name)}`) }));
253
+ let translationKey = `${prefix}.lookup_${this.toSnakeCase(this.entity)}_${this.toSnakeCase(field.name)}`;
254
+ let label = this.translate.instant(translationKey);
255
+ if (label === translationKey) {
256
+ // Manter compatibilidade com os lookups atuais até todos ajustarem
257
+ const fieldName = field.name.split('.').join('_');
258
+ translationKey = `${prefix}.lookup_${this.toSnakeCase(this.entity)}_${this.toSnakeCase(fieldName)}`;
259
+ label = this.translate.instant(translationKey);
260
+ }
261
+ return new FormField(Object.assign(Object.assign({}, field), { label }));
254
262
  });
255
263
  }
256
264
  mountDefaultFilter(defaultFilter = [{ field: "excluido", operator: EnumLogicalOperator.Eq, values: ["false"] }]) {
@@ -6153,14 +6161,23 @@ NpsService = __decorate([
6153
6161
  var WebsocketService_1;
6154
6162
  let WebsocketService = WebsocketService_1 = class WebsocketService {
6155
6163
  constructor() {
6164
+ /** @private */
6156
6165
  this.focused = true;
6166
+ /** @private */
6157
6167
  this.wasConnected = false;
6168
+ /** @private */
6158
6169
  this.connected = false;
6170
+ /** @private */
6159
6171
  this.isConnecting = false;
6172
+ /** @private */
6160
6173
  this.primitiveManagers = new Map();
6174
+ /** @private */
6161
6175
  this.connect$ = new Subject();
6176
+ /** @private */
6162
6177
  this.disconnect$ = new Subject();
6178
+ /** @private */
6163
6179
  this.reconnect$ = new Subject();
6180
+ /** @private */
6164
6181
  this.error$ = new Subject();
6165
6182
  window.onfocus = this.onFocus;
6166
6183
  window.onblur = this.onBlur;
@@ -6200,17 +6217,18 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6200
6217
  return this.error$.asObservable();
6201
6218
  }
6202
6219
  /**
6203
- * Observable responsável por emitir uma notificação quando um evento é publicado.
6204
6220
  * @typeParam `<T>` Tipo do objeto que o retorno do `observable` vai devolver.
6205
- * @param domain Dominio da primitiva.
6206
- * @param service Service da primitiva.
6207
- * @param primitive Primitiva que será "observada" pelo client.
6208
- * @param identifierPath Caminho até a propriedade considerada o identificador do registro.
6209
- * @return Um `observable` que emite notificações toda vez que o respectivo evento é publicado no sistema.
6221
+ * @param {Object} options Objeto de configuração do evento.
6222
+ * @param {string} options.domain Domínio da primitiva.
6223
+ * @param {string} options.service Serviço da primitiva.
6224
+ * @param {string} options.primitive Primitiva que será "observada".
6225
+ * @return Um Observable<T> que emite notificações toda vez que o respectivo evento é publicado.
6210
6226
  */
6211
- onEvent(domain, service, primitive, identifierPath) {
6212
- if (this.primitiveManagers.has(primitive)) {
6213
- return this.primitiveManagers.get(primitive).subject.asObservable();
6227
+ onEvent(options) {
6228
+ const { domain, service, primitive } = options;
6229
+ const key = this.getPrimitiveManagerKey(domain, service, primitive);
6230
+ if (this.primitiveManagers.has(key)) {
6231
+ return this.primitiveManagers.get(key).subject.asObservable();
6214
6232
  }
6215
6233
  const primitiveManager = {
6216
6234
  domain: domain,
@@ -6218,13 +6236,11 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6218
6236
  primitive: primitive,
6219
6237
  stompSubscriptions: [],
6220
6238
  subject: new Subject(),
6221
- identifierPath: identifierPath,
6222
- publishedEvents: [],
6223
6239
  };
6224
- this.primitiveManagers.set(primitive, primitiveManager);
6240
+ this.primitiveManagers.set(key, primitiveManager);
6225
6241
  if (this.isConnected()) {
6226
6242
  this.createStompSubscriptions(primitiveManager);
6227
- return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitive)));
6243
+ return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
6228
6244
  }
6229
6245
  else {
6230
6246
  if (!this.isConnecting) {
@@ -6233,37 +6249,10 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6233
6249
  this.connect$.pipe(first()).subscribe(() => {
6234
6250
  this.createStompSubscriptions(primitiveManager);
6235
6251
  });
6236
- return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitive)));
6237
- }
6238
- }
6239
- /**
6240
- * Retorna todos os eventos ouvidos pela primitiva com os respectivos identificadores.
6241
- * @typeParam `<T>` Tipo do evento retornado pela primitiva.
6242
- * @param primitive Primitiva que será "observada" pelo client.
6243
- * @param identifiers Array com os identificadores interessados.
6244
- * @return Array contendo o último evento recebido de cada identificador fornecido.
6245
- */
6246
- getPublishedEvents(primitive, identifiers) {
6247
- const publishedEvents = [];
6248
- const primitiveManager = this.primitiveManagers.get(primitive);
6249
- for (const identifier of identifiers) {
6250
- const event = primitiveManager.publishedEvents.find(x => this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier);
6251
- if (event) {
6252
- publishedEvents.push(event);
6253
- }
6254
- }
6255
- return publishedEvents;
6256
- }
6257
- addPublishedEvent(primitiveManager, event) {
6258
- const identifier = this.getIdentifierFromEvent(primitiveManager.identifierPath, event);
6259
- const eventIndex = primitiveManager.publishedEvents.findIndex(x => this.getIdentifierFromEvent(primitiveManager.identifierPath, x) === identifier);
6260
- if (eventIndex !== -1) {
6261
- primitiveManager.publishedEvents[eventIndex] = Object.assign(Object.assign({}, primitiveManager.publishedEvents[eventIndex]), event);
6262
- }
6263
- else {
6264
- primitiveManager.publishedEvents.push(event);
6252
+ return primitiveManager.subject.pipe(finalize(() => this.disconnectPrimitiveOnFinalize(primitiveManager)));
6265
6253
  }
6266
6254
  }
6255
+ /** @private */
6267
6256
  createStompSubscriptions(primitiveManager) {
6268
6257
  const withTokenUrl = this.getSubscriptionUrlWithToken(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6269
6258
  const stompSubscriptionWithToken = this.createStompSubscription(withTokenUrl, primitiveManager);
@@ -6271,14 +6260,7 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6271
6260
  const stompSubscriptionWithoutToken = this.createStompSubscription(withoutTokenUrl, primitiveManager);
6272
6261
  primitiveManager.stompSubscriptions = [stompSubscriptionWithToken, stompSubscriptionWithoutToken];
6273
6262
  }
6274
- getIdentifierFromEvent(identifierPath, event) {
6275
- const properties = identifierPath.split(".");
6276
- let identifier = event;
6277
- for (const property of properties) {
6278
- identifier = identifier[property];
6279
- }
6280
- return identifier;
6281
- }
6263
+ /** @private */
6282
6264
  connect() {
6283
6265
  this.createStompClient();
6284
6266
  this.isConnecting = true;
@@ -6300,9 +6282,11 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6300
6282
  this.reconnect();
6301
6283
  });
6302
6284
  }
6285
+ /** @private */
6303
6286
  onFocus() {
6304
6287
  this.focused = true;
6305
6288
  }
6289
+ /** @private */
6306
6290
  onBlur() {
6307
6291
  this.focused = false;
6308
6292
  }
@@ -6326,34 +6310,40 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6326
6310
  this.wasConnected = false;
6327
6311
  this.disconnect$.next();
6328
6312
  }
6313
+ /** @private */
6329
6314
  isConnected() {
6330
6315
  return this.connected;
6331
6316
  }
6317
+ /** @private */
6332
6318
  setConnected(connected) {
6333
6319
  this.connected = connected;
6334
6320
  }
6321
+ /** @private */
6335
6322
  getSubscriptionUrlWithToken(domain, service, primitive) {
6336
6323
  const tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6337
6324
  const token = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.access_token : null;
6338
6325
  return `/topic/${tenant}/${token}/${domain}/${service}/${primitive}`;
6339
6326
  }
6327
+ /** @private */
6340
6328
  getSubscriptionUrlWithoutToken(domain, service, primitive) {
6341
6329
  const tenant = WebsocketService_1.TOKEN ? WebsocketService_1.TOKEN.username.split("@")[1] : null;
6342
6330
  return `/topic/${tenant}/${domain}/${service}/${primitive}`;
6343
6331
  }
6332
+ /** @private */
6344
6333
  createStompSubscription(destination, primitiveManager) {
6345
6334
  return this._stompClient.subscribe(destination, (message) => {
6346
6335
  const event = JSON.parse(message.body || "{}");
6347
- this.addPublishedEvent(primitiveManager, event);
6348
6336
  primitiveManager.subject.next(event);
6349
6337
  });
6350
6338
  }
6339
+ /** @private */
6351
6340
  createStompClient() {
6352
6341
  const ws = new SockJS(`${WebsocketService_1.WEBSOCKET_URL}subscription`, null, { timeout: WebsocketService_1.CONNECTION_TIMEOUT });
6353
6342
  this._stompClient = Stomp.over(ws);
6354
6343
  // this._stompClient.debug = (str) => console.log(new Date().toISOString(), str);
6355
6344
  this._stompClient.debug = () => { }; // Para remover os logs.
6356
6345
  }
6346
+ /** @private */
6357
6347
  reconnect() {
6358
6348
  if (this.connected)
6359
6349
  this._stompClient.disconnect();
@@ -6368,6 +6358,7 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6368
6358
  }
6369
6359
  }, WebsocketService_1.RECONNECT_TIMER);
6370
6360
  }
6361
+ /** @private */
6371
6362
  reconnectPrimitives() {
6372
6363
  for (const primitiveManager of this.primitiveManagers.values()) {
6373
6364
  for (const stompSubscription of primitiveManager.stompSubscriptions) {
@@ -6376,6 +6367,7 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6376
6367
  this.createStompSubscriptions(primitiveManager);
6377
6368
  }
6378
6369
  }
6370
+ /** @private */
6379
6371
  getObserversCount() {
6380
6372
  let observersCount = 0;
6381
6373
  for (const primitiveManager of this.primitiveManagers.values()) {
@@ -6383,26 +6375,35 @@ let WebsocketService = WebsocketService_1 = class WebsocketService {
6383
6375
  }
6384
6376
  return observersCount;
6385
6377
  }
6386
- disconnectPrimitiveOnFinalize(primitive) {
6387
- const primitiveManager = this.primitiveManagers.get(primitive);
6388
- if (!primitiveManager)
6389
- return;
6390
- // @IMPORTANT: Replace .observers.length with .observed in rxjs 7.0+
6378
+ /** @private */
6379
+ disconnectPrimitiveOnFinalize(primitiveManager) {
6380
+ // @IMPORTANT: Replace .observers.length === 1 with .observed in rxjs 7.0+
6391
6381
  const hasObservers = !(primitiveManager.subject.observers.length === 1);
6392
6382
  if (hasObservers)
6393
6383
  return;
6394
6384
  for (const stompSubscription of primitiveManager.stompSubscriptions) {
6395
6385
  stompSubscription.unsubscribe();
6396
6386
  }
6397
- this.primitiveManagers.delete(primitive);
6387
+ const key = this.getPrimitiveManagerKey(primitiveManager.domain, primitiveManager.service, primitiveManager.primitive);
6388
+ this.primitiveManagers.delete(key);
6398
6389
  this.disconnect();
6399
6390
  }
6391
+ /** @private */
6392
+ getPrimitiveManagerKey(domain, service, primitive) {
6393
+ return `${domain}/${service}/${primitive}`;
6394
+ }
6400
6395
  };
6396
+ /** @private */
6401
6397
  WebsocketService.RECONNECT_TIMER = 3000;
6398
+ /** @private */
6402
6399
  WebsocketService.CONNECTION_TIMEOUT = 15000;
6400
+ /** @private */
6403
6401
  WebsocketService.BASE_URL_COOKIE = "com.senior.base.url";
6402
+ /** @private */
6404
6403
  WebsocketService.TOKEN_COOKIE = "com.senior.token";
6404
+ /** @private */
6405
6405
  WebsocketService.TOKEN = JSON.parse(get(WebsocketService_1.TOKEN_COOKIE) || "{}");
6406
+ /** @private */
6406
6407
  WebsocketService.WEBSOCKET_URL = get(WebsocketService_1.BASE_URL_COOKIE) + "/websocket/";
6407
6408
  WebsocketService.ɵprov = ɵɵdefineInjectable({ factory: function WebsocketService_Factory() { return new WebsocketService(); }, token: WebsocketService, providedIn: "root" });
6408
6409
  WebsocketService = WebsocketService_1 = __decorate([