@esfaenza/extensions 11.2.22 → 11.2.25

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.
@@ -1,6 +1,8 @@
1
1
  import { InjectionToken, NgModule, Injectable, Optional, Inject } from '@angular/core';
2
2
  import { ToastrService } from 'ngx-toastr';
3
3
  import swal from 'sweetalert2';
4
+ import { of, Subject } from 'rxjs';
5
+ import { map } from 'rxjs/operators';
4
6
  import { Deserialize } from 'cerialize';
5
7
 
6
8
  /**
@@ -253,6 +255,15 @@ class MessageService {
253
255
  onerror();
254
256
  });
255
257
  }
258
+ /**
259
+ * Mostra un messaggio di avviso con richiesta di conferma e gestisce il risultato chiamato i callback **onsuccess** o **onerror**
260
+ *
261
+ * @param {string} title Titolo del messaggio
262
+ * @param {string} text Contenuto del messaggio
263
+ */
264
+ observableSimpleWarningWithChoice(title, text) {
265
+ return of(this.warningSwalWithCancel.fire(title, text)).pipe(map(t => !!t.value));
266
+ }
256
267
  /**
257
268
  * Mostra un messaggio di avviso che la sessione corrente è scaduta e propone all'utente di navigare al login. Qualora l'utente decidesse di farlo
258
269
  * verrà chiamata la funzione di callback **onnavigate
@@ -684,7 +695,7 @@ class DateService {
684
695
  tryThis = toCall(date, this.cfg.smallDate);
685
696
  else if (length == this.cfg.fulldateNoSS.length)
686
697
  tryThis = toCall(date, this.cfg.fulldateNoSS);
687
- if (tryThis.isValid())
698
+ if (tryThis && tryThis.isValid())
688
699
  return tryThis;
689
700
  // Se niente funziona, null.
690
701
  // Ricondurre l'Input ad una data non è possibile.
@@ -1735,6 +1746,65 @@ UtilityService.decorators = [
1735
1746
  { type: Injectable }
1736
1747
  ];
1737
1748
 
1749
+ /** Classe che rappresenta un generico messaggio scambiato fra applicazione e moduli */
1750
+ class InterComMessage {
1751
+ /**
1752
+ * Costruttore
1753
+ *
1754
+ * @param type Tipo di messaggio
1755
+ * @param message Contenuto del messaggio
1756
+ */
1757
+ constructor(type, message) {
1758
+ this.type = type;
1759
+ this.message = message;
1760
+ }
1761
+ }
1762
+
1763
+ // Angular
1764
+ /** Service che si occupa di gestire la comunicazione fra i moduli interni ed esterni dell'applicativo */
1765
+ class InterComService {
1766
+ constructor() {
1767
+ /** Messaggi in uscita, uno per ogni recipient registratosi dall'entrypoint **register** */
1768
+ this.outbounds = {};
1769
+ /** Messaggi in entrata, unico per applicazione principale */
1770
+ this.inbounds = new Subject();
1771
+ }
1772
+ /**
1773
+ * Metodo che permette di inviare un messaggio dall'applicazione ad un modulo esterno o viceversa
1774
+ *
1775
+ * @param {any} messageType Tipologia di messaggio. Sarà di tipo **InboundMessageTypes** per tutti i messaggi inbound, dinamico per tutti i mesaggi outbound (il tipo dipenderà dagli enum dei messaggi dei moduli esterni)
1776
+ * @param {any} message Messaggio da inviare che può essere un dto in casi complessi ma dovrà essere gestito a dovere lato implementativo
1777
+ * @param {string} recipient Destinatario del messaggio. Per i messaggi inbound dev'essere lasciato vuoto, per i messaggi outbound sarà valorizzato alla chiave del modulo a cui si vuole inviare il messaggio
1778
+ */
1779
+ send(messageType, message, recipient) {
1780
+ let msg = new InterComMessage(messageType, message);
1781
+ // Se non c'è un recipient significa che è un modulo esterno che invia messaggi al modulo main (quindi messaggio in entrata - inbound)
1782
+ // Altrimenti significa che è il modulo main ad inviare messaggi ai moduli esterni (messaggio in uscita - outbound)
1783
+ if (!recipient) {
1784
+ this.inbounds.next(msg);
1785
+ }
1786
+ else {
1787
+ if (!this.outbounds[recipient])
1788
+ console.warn("@esfaenza/extensions - InterComService: Impossibile inviare il messaggio al recipient " + recipient + " assicurarsi che il modulo sia caricato e che effettui la chiamata al metodo 'regisster'");
1789
+ else
1790
+ this.outbounds[recipient].next(msg);
1791
+ }
1792
+ }
1793
+ /**
1794
+ * Permette di registrare un modulo esterno alla lista dei moduli in listening sulla coda di messaggi
1795
+ *
1796
+ * @param {string} key Chiave del modulo da registrare. Tutti i messaggi inbound saranno inviati dall'applicazione principale su questa chiave
1797
+ */
1798
+ register(key) {
1799
+ if (this.outbounds[key])
1800
+ throw "@esfaenza/extensions - InterComService: Impossibile registrare più volte lo stesso modulo";
1801
+ this.outbounds[key] = new Subject();
1802
+ }
1803
+ }
1804
+ InterComService.decorators = [
1805
+ { type: Injectable }
1806
+ ];
1807
+
1738
1808
  // Angular
1739
1809
  /**
1740
1810
  * Modulo di estensione che registra autonomamente **TUTTI** i servizi di estensione:
@@ -1744,6 +1814,7 @@ UtilityService.decorators = [
1744
1814
  * HashingService,
1745
1815
  * MessageService,
1746
1816
  * UtilityService
1817
+ * InterComService
1747
1818
  *
1748
1819
  * con eventuali provider che utilizzano
1749
1820
  */
@@ -1758,6 +1829,7 @@ class FullExtensionsModule {
1758
1829
  HashingService,
1759
1830
  MessageService,
1760
1831
  UtilityService,
1832
+ InterComService,
1761
1833
  { provide: EXT_LOCALE, useValue: (config === null || config === void 0 ? void 0 : config.locale) || 'it-IT' },
1762
1834
  { provide: EXT_FANCY_ALERTS, useValue: (config === null || config === void 0 ? void 0 : config.fancy_alerts) || true },
1763
1835
  { provide: APPSEARCH_PREFIX, useValue: (config === null || config === void 0 ? void 0 : config.appsearch_prefix) || 'Hot' },
@@ -1788,6 +1860,13 @@ class CsvHeaders {
1788
1860
  class GenericItem {
1789
1861
  }
1790
1862
 
1863
+ /** Enumeratore dei tipi di messaggio che i moduli esterni possono contattare sull'applicazione principale */
1864
+ var InboundMessageTypes;
1865
+ (function (InboundMessageTypes) {
1866
+ /** Evento di navigazione */
1867
+ InboundMessageTypes[InboundMessageTypes["Navigation"] = 0] = "Navigation";
1868
+ })(InboundMessageTypes || (InboundMessageTypes = {}));
1869
+
1791
1870
  /*
1792
1871
  * Public API Surface of extensions
1793
1872
  */
@@ -1796,5 +1875,5 @@ class GenericItem {
1796
1875
  * Generated bundle index. Do not edit.
1797
1876
  */
1798
1877
 
1799
- export { APPSEARCH_PREFIX, CallResult, ClipboardService, CsvHeaders, DateService, EXT_ALLOW_UTC, EXT_FANCY_ALERTS, EXT_LOCALE, Export, ExportAs, ExportDictionary, ExportList, ExportService, ExtensionsModule, FullExtensionsModule, GenericItem, HashingService, MessageService, UtilityService };
1878
+ export { APPSEARCH_PREFIX, CallResult, ClipboardService, CsvHeaders, DateService, EXT_ALLOW_UTC, EXT_FANCY_ALERTS, EXT_LOCALE, Export, ExportAs, ExportDictionary, ExportList, ExportService, ExtensionsModule, FullExtensionsModule, GenericItem, HashingService, InboundMessageTypes, InterComMessage, InterComService, MessageService, UtilityService };
1800
1879
  //# sourceMappingURL=esfaenza-extensions.js.map