@esfaenza/extensions 13.1.5 → 13.1.6

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.
@@ -3,6 +3,7 @@ import { InjectionToken, NgModule, Injectable, Optional, Inject } from '@angular
3
3
  import swal from 'sweetalert2';
4
4
  import * as i1 from 'ngx-toastr';
5
5
  import { Deserialize } from 'cerialize';
6
+ import { Subject } from 'rxjs';
6
7
 
7
8
  /**
8
9
  * Token che identifica il locale da utilizzare per questa libreria, sono supportati i locali 'it-IT' ed 'en-US'
@@ -1755,6 +1756,67 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
1755
1756
  type: Injectable
1756
1757
  }] });
1757
1758
 
1759
+ /** Classe che rappresenta un generico messaggio scambiato fra applicazione e moduli */
1760
+ class InterComMessage {
1761
+ /**
1762
+ * Costruttore
1763
+ *
1764
+ * @param type Tipo di messaggio
1765
+ * @param message Contenuto del messaggio
1766
+ */
1767
+ constructor(type, message) {
1768
+ this.type = type;
1769
+ this.message = message;
1770
+ }
1771
+ }
1772
+
1773
+ // Angular
1774
+ /** Service che si occupa di gestire la comunicazione fra i moduli interni ed esterni dell'applicativo */
1775
+ class InterComService {
1776
+ constructor() {
1777
+ /** Messaggi in uscita, uno per ogni recipient registratosi dall'entrypoint **register** */
1778
+ this.outbounds = {};
1779
+ /** Messaggi in entrata, unico per applicazione principale */
1780
+ this.inbounds = new Subject();
1781
+ }
1782
+ /**
1783
+ * Metodo che permette di inviare un messaggio dall'applicazione ad un modulo esterno o viceversa
1784
+ *
1785
+ * @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)
1786
+ * @param {any} message Messaggio da inviare che può essere un dto in casi complessi ma dovrà essere gestito a dovere lato implementativo
1787
+ * @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
1788
+ */
1789
+ send(messageType, message, recipient) {
1790
+ let msg = new InterComMessage(messageType, message);
1791
+ // Se non c'è un recipient significa che è un modulo esterno che invia messaggi al modulo main (quindi messaggio in entrata - inbound)
1792
+ // Altrimenti significa che è il modulo main ad inviare messaggi ai moduli esterni (messaggio in uscita - outbound)
1793
+ if (!recipient) {
1794
+ this.inbounds.next(msg);
1795
+ }
1796
+ else {
1797
+ if (!this.outbounds[recipient])
1798
+ 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'");
1799
+ else
1800
+ this.outbounds[recipient].next(msg);
1801
+ }
1802
+ }
1803
+ /**
1804
+ * Permette di registrare un modulo esterno alla lista dei moduli in listening sulla coda di messaggi
1805
+ *
1806
+ * @param {string} key Chiave del modulo da registrare. Tutti i messaggi inbound saranno inviati dall'applicazione principale su questa chiave
1807
+ */
1808
+ register(key) {
1809
+ if (this.outbounds[key])
1810
+ throw "@esfaenza/extensions - InterComService: Impossibile registrare più volte lo stesso modulo";
1811
+ this.outbounds[key] = new Subject();
1812
+ }
1813
+ }
1814
+ InterComService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: InterComService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
1815
+ InterComService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: InterComService });
1816
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImport: i0, type: InterComService, decorators: [{
1817
+ type: Injectable
1818
+ }] });
1819
+
1758
1820
  // Angular
1759
1821
  /**
1760
1822
  * Modulo di estensione che registra autonomamente **TUTTI** i servizi di estensione:
@@ -1764,6 +1826,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.1.1", ngImpor
1764
1826
  * HashingService,
1765
1827
  * MessageService,
1766
1828
  * UtilityService
1829
+ * InterComService
1767
1830
  *
1768
1831
  * con eventuali provider che utilizzano
1769
1832
  */
@@ -1778,6 +1841,7 @@ class FullExtensionsModule {
1778
1841
  HashingService,
1779
1842
  MessageService,
1780
1843
  UtilityService,
1844
+ InterComService,
1781
1845
  { provide: EXT_LOCALE, useValue: config?.locale || 'it-IT' },
1782
1846
  { provide: EXT_FANCY_ALERTS, useValue: config?.fancy_alerts || true },
1783
1847
  { provide: APPSEARCH_PREFIX, useValue: config?.appsearch_prefix || 'Hot' },
@@ -1811,6 +1875,13 @@ class CsvHeaders {
1811
1875
  class GenericItem {
1812
1876
  }
1813
1877
 
1878
+ /** Enumeratore dei tipi di messaggio che i moduli esterni possono contattare sull'applicazione principale */
1879
+ var InboundMessageTypes;
1880
+ (function (InboundMessageTypes) {
1881
+ /** Evento di navigazione */
1882
+ InboundMessageTypes[InboundMessageTypes["Navigation"] = 0] = "Navigation";
1883
+ })(InboundMessageTypes || (InboundMessageTypes = {}));
1884
+
1814
1885
  /*
1815
1886
  * Public API Surface of extensions
1816
1887
  */
@@ -1819,5 +1890,5 @@ class GenericItem {
1819
1890
  * Generated bundle index. Do not edit.
1820
1891
  */
1821
1892
 
1822
- 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 };
1893
+ 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 };
1823
1894
  //# sourceMappingURL=esfaenza-extensions.mjs.map