@esfaenza/extensions 19.2.32 → 19.2.34

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,7 +3,7 @@ import { InjectionToken, Optional, Inject, Injectable, Pipe, NgModule, Injector
3
3
  import * as i1 from '@esfaenza/localizations';
4
4
  import { LocalizationModule } from '@esfaenza/localizations';
5
5
  import { first, filter, take, map } from 'rxjs/operators';
6
- import { ReplaySubject, of, Subject, filter as filter$1 } from 'rxjs';
6
+ import { ReplaySubject, of, Subject, filter as filter$1, take as take$1, debounceTime } from 'rxjs';
7
7
  import { ToastrService } from 'ngx-toastr';
8
8
  import swal from 'sweetalert2';
9
9
  import * as i2 from '@angular/router';
@@ -1326,6 +1326,192 @@ class AppEmbeddingExtensions {
1326
1326
  if (left)
1327
1327
  left.style.setProperty("width", leftSpace + "px");
1328
1328
  }
1329
+ onEmbeddedDialogShow(dialog) {
1330
+ dialog._renderer.setStyle(dialog._element.nativeElement, "padding-top", "5%");
1331
+ dialog._renderer.setStyle(dialog._element.nativeElement, "margin-left", "-110px");
1332
+ dialog._renderer.setStyle(dialog._element.nativeElement, "width", "calc(100% + 110px)");
1333
+ dialog._renderer.setStyle(dialog._element.nativeElement, "overflow", "hidden");
1334
+ if (dialog._config.animated)
1335
+ setTimeout(() => { this.doFixBody(dialog._element); }, 300);
1336
+ else
1337
+ this.doFixBody(dialog._element);
1338
+ let backdropHeight = dialog.backdrop.instance.element.nativeElement.clientHeight;
1339
+ this.MainWindow.postMessage({ type: "modal-open", backdropHeight: backdropHeight }, "*");
1340
+ dialog.onHidden.pipe(take$1(1)).subscribe(() => {
1341
+ document.body.style.setProperty("overflow-y", "auto", "important");
1342
+ });
1343
+ }
1344
+ doFixBody(modalElement) {
1345
+ let body = modalElement.nativeElement.getElementsByClassName("modal-body")[0];
1346
+ // Ci prova finch� non trova il body dato che potrebbe essere creato in qualsiasi momento
1347
+ if (!body) {
1348
+ setTimeout(() => this.doFixBody(modalElement), 250);
1349
+ return;
1350
+ }
1351
+ body.style.setProperty("max-height", "600px", "important");
1352
+ body.style.setProperty("overflow-x", "hidden");
1353
+ body.style.setProperty("overflow-y", "auto");
1354
+ }
1355
+ onEmbeddedDialogHide(dialog) {
1356
+ if (dialog._config.animated)
1357
+ setTimeout(() => { this.doHide(); }, 300);
1358
+ else
1359
+ this.doHide();
1360
+ }
1361
+ doHide() {
1362
+ this.MainWindow.postMessage({ type: "modal-close" }, "*");
1363
+ }
1364
+ onComponentCreation(CompletePath, InternalNavigation, NavigationTitle) {
1365
+ // Per i componenti navigabili non embeddati è inutile mandare il messaggio di navigazione
1366
+ // Così come per quelli per cui non esiste un titolo (cioè compoennti verso cui non si è navigato direttamente)
1367
+ if (!this.Embedded || NavigationTitle)
1368
+ return;
1369
+ this.MainWindow.postMessage({ type: "navigation", url: CompletePath, internalNavigation: InternalNavigation, title: NavigationTitle }, "*");
1370
+ }
1371
+ handleBack() {
1372
+ if (this.Embedded) {
1373
+ this.MainWindow.postMessage({ type: "navigate-back" }, "*");
1374
+ setTimeout(() => { this.location.back(); });
1375
+ }
1376
+ else
1377
+ this.location.back();
1378
+ }
1379
+ handleNavigation(command, extras, EMBEDDED_ROUTE, ROUTE, basePath) {
1380
+ let commands = command;
1381
+ // Fix della path esattamente come in esRouterLink
1382
+ commands = Array.isArray(commands) ? commands : [commands];
1383
+ let route = commands[0];
1384
+ if (!route.startsWith("/" + EMBEDDED_ROUTE) && !route.startsWith("/" + ROUTE))
1385
+ commands[0] = basePath + commands[0];
1386
+ this.router.navigate(command, extras);
1387
+ }
1388
+ // TODO: Automatizzare
1389
+ LocalhostModuleMap = {
1390
+ "crm": "31813",
1391
+ "sii": "21645",
1392
+ "pp": "1616",
1393
+ "sales": "19112"
1394
+ };
1395
+ Reloading = false;
1396
+ setupEmbedding(route, ParametersRetrieveFunction, QueryParametersRetrieveFunction, completePathRetrieveFunction, currentModuleRetrieveFunction, currentPageRetrieveFunction, onEmbeddingSuccesful) {
1397
+ route.url.subscribe(_ => { this.performNewEmbeddingOperations(ParametersRetrieveFunction, QueryParametersRetrieveFunction, null, completePathRetrieveFunction, currentModuleRetrieveFunction, currentPageRetrieveFunction, onEmbeddingSuccesful); });
1398
+ route.params.pipe(debounceTime(100)).subscribe((res) => { this.performNewEmbeddingOperations(ParametersRetrieveFunction, QueryParametersRetrieveFunction, res["module"], completePathRetrieveFunction, currentModuleRetrieveFunction, currentPageRetrieveFunction, onEmbeddingSuccesful); });
1399
+ }
1400
+ performNewEmbeddingOperations(ParametersRetrieveFunction, QueryParametersRetrieveFunction, module, completePathRetrieveFunction, currentModuleRetrieveFunction, currentPageRetrieveFunction, onEmbeddingSuccesful) {
1401
+ let Module = currentModuleRetrieveFunction();
1402
+ let Localhost;
1403
+ let Page = currentPageRetrieveFunction();
1404
+ let Pars;
1405
+ let CompletePath = completePathRetrieveFunction();
1406
+ if (!module && !Module) {
1407
+ console.log(`Module parameter missing. Ignoring embed request`);
1408
+ return;
1409
+ }
1410
+ if (this.Reloading) {
1411
+ console.log(`Already reloading. Embedding ignored`);
1412
+ return;
1413
+ }
1414
+ if (module)
1415
+ Module = module;
1416
+ Localhost = this.LocalhostModuleMap[Module];
1417
+ this.Reloading = true;
1418
+ console.log(`Recognized a new navigation to the embedding component: ${Module} - ${CompletePath}`);
1419
+ let reloadAllowed = this.IsReloadAllowed();
1420
+ if (Page && reloadAllowed) {
1421
+ Page = Pars = null;
1422
+ requestAnimationFrame(() => {
1423
+ this.assignPageLoadParameters(ParametersRetrieveFunction, QueryParametersRetrieveFunction, Localhost, Page, CompletePath, Module, true, onEmbeddingSuccesful);
1424
+ requestAnimationFrame(() => { this.Reloading = false; });
1425
+ });
1426
+ }
1427
+ else {
1428
+ this.assignPageLoadParameters(ParametersRetrieveFunction, QueryParametersRetrieveFunction, Localhost, Page, CompletePath, Module, reloadAllowed, onEmbeddingSuccesful);
1429
+ requestAnimationFrame(() => { this.Reloading = false; });
1430
+ }
1431
+ }
1432
+ assignPageLoadParameters(ParametersRetrieveFunction, QueryParametersRetrieveFunction, Localhost, _Page, CompletePath, Module, reloadAllowed, onEmbeddingSuccesful) {
1433
+ let EmbeddingSuccesfull;
1434
+ let Page = _Page;
1435
+ let Pars;
1436
+ let QueryPars;
1437
+ // Esempio di Complete path: "/pages/embed/crm/leads/leads_search"
1438
+ // Esempio di slices: ["", "pages", "embed", "crm", "leads", "leads_search"]
1439
+ // Io devo sostanzialmente prendere dal nome del modulo ("crm") in poi. Nome del modulo embeddato eslcuso
1440
+ console.log("Embedding...");
1441
+ if (reloadAllowed)
1442
+ EmbeddingSuccesfull = false;
1443
+ // Per seccare e ricreare il componente che altrimenti non prenderebbe gli input nuovi
1444
+ requestAnimationFrame(() => {
1445
+ let Parameters = ParametersRetrieveFunction();
1446
+ let QueryParameters = QueryParametersRetrieveFunction();
1447
+ Page = CompletePath.split("/").slice(4).join("/");
1448
+ console.log("Page: " + Page);
1449
+ let navParKeys = Object.keys(Parameters)?.filter(p => p != "module");
1450
+ Pars = (navParKeys?.length || 0) == 0 ? "" : ";" + navParKeys.map(t => `${t}=${Parameters[t]}`).join(";");
1451
+ console.log("Pars: " + Pars);
1452
+ let queryParKeys = Object.keys(QueryParameters);
1453
+ QueryPars = (queryParKeys?.length || 0) == 0 ? "" : "?" + queryParKeys.map(t => `${t}=${QueryParameters[t]}`).join(";");
1454
+ console.log("QueryPars: " + QueryPars);
1455
+ let QueryPAramsWithoutIgnoreStorage = queryParKeys.map(t => t == "ignoreStorage" ? null : `${t}=${QueryParameters[t]}`).filter(t => !!t).join(";");
1456
+ // Per rimuovere eventuali ignoreStorage se sto navigando a una ricerca
1457
+ this.location.replaceState(CompletePath + Pars + (QueryPAramsWithoutIgnoreStorage ? '?' + QueryPAramsWithoutIgnoreStorage : ""));
1458
+ EmbeddingSuccesfull = !!Page && !!Module && !!Localhost;
1459
+ onEmbeddingSuccesful(EmbeddingSuccesfull, Page, Pars, QueryPars, Module, Localhost);
1460
+ });
1461
+ }
1462
+ navigate(url) {
1463
+ if (this.Embedded)
1464
+ this.MainWindow.postMessage({ type: "navigate", url }, "*");
1465
+ else
1466
+ this.router.navigate([url]);
1467
+ }
1468
+ loadExternalPage(Username, Password, Tenant, EmbeddingSource, _state, currentIdentity, aac) {
1469
+ var Localhost;
1470
+ if (!this.Embedded) {
1471
+ console.log("Pagina ext richiamata in ambiente non embeddato. Sono in una nuova scheda!!");
1472
+ console.log("L'embedder originale doveva essere: " + EmbeddingSource);
1473
+ console.log("Dato che sono in una nuova scheda devo in realtà navigare a lui, con link su emb/ecc in modo da aprire una scheda embeddata su questa pagina. Se funziona già fino a qui sono a cavallo");
1474
+ Localhost = this.LocalhostModuleMap[EmbeddingSource];
1475
+ if (_state.Modules?.length > 0)
1476
+ this.afterModulesRetrieve(_state.Modules, EmbeddingSource, Localhost);
1477
+ else {
1478
+ _state.subscribe("modules.Retrieved", (modules) => {
1479
+ this.afterModulesRetrieve(modules, EmbeddingSource, Localhost);
1480
+ });
1481
+ }
1482
+ return;
1483
+ }
1484
+ console.log("Caricamento pagina nell'IFRAME completato!");
1485
+ if (Tenant || Username || Password)
1486
+ console.log("[" + Tenant + "]" + Username + " - " + Password);
1487
+ // Le info di login che ho passato sono le stesse delle info di login salvate nel token --> È un redirect da un sito esterno ma il token c'è già. Esco
1488
+ // Ho un token di login e non ho nessuna info sull'utente da usare --> È un redirect da Jace, quindi sono a posto. Esco
1489
+ if ((!(Tenant + Username + Password) || currentIdentity.Idtenant == Tenant && currentIdentity.DsUser == Username)) {
1490
+ aac.initializeIdentity(currentIdentity);
1491
+ return;
1492
+ }
1493
+ // Altrimenti devo effettuare il login
1494
+ // Non è utilizzata, porcoddinci
1495
+ // let LoginDTO = { tenant: "FX", username: Username, password: Password, client_id: "jacedev" };
1496
+ // this.http.post(`${myconfig.AuthUrl}/api/login/dologin`, LoginDTO).subscribe(t => {
1497
+ // });
1498
+ }
1499
+ afterModulesRetrieve(modules, EmbeddingSource, Localhost) {
1500
+ // Sto navigando a {sito}/#/pages_ext/{origine}/etc...
1501
+ // Devo ridirezionare a {sorgente}/#/pages/embed/{thisModule}/etc...
1502
+ let module = modules.find(t => t.altname == EmbeddingSource);
1503
+ if (!module) {
1504
+ console.error(`Impossibile trovare il modulo con altname uguale a ${this.EmbeddingSource}`);
1505
+ }
1506
+ let afterPagesExt = this.router.url.split("pages_ext")[1].substring(1).split("/").slice(1).join("/");
1507
+ let sourceModuleUrl = myconfig.AuthUrl.includes("localhost") ? `http://localhost:${Localhost}` : module.uiurl;
1508
+ let finalUrl = `${sourceModuleUrl}/#/pages/embed/${myconfig.AppData.ModuleId}/${afterPagesExt}`;
1509
+ console.log("@esfaenza/core: navigating to " + finalUrl);
1510
+ location.replace(finalUrl);
1511
+ }
1512
+ getPageRoute() {
1513
+ return this.Embedded ? "pages_ext/" : "pages/";
1514
+ }
1329
1515
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AppEmbeddingExtensions, deps: [{ token: MessageService }, { token: i2.Router }, { token: i3.Location }], target: i0.ɵɵFactoryTarget.Injectable });
1330
1516
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.15", ngImport: i0, type: AppEmbeddingExtensions, providedIn: "root" });
1331
1517
  }