@esfaenza/extensions 19.2.17 → 19.2.18

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 } from 'rxjs';
6
+ import { ReplaySubject, of, Subject, filter as filter$1 } from 'rxjs';
7
7
  import { ToastrService } from 'ngx-toastr';
8
8
  import swal from 'sweetalert2';
9
9
  import * as i2 from '@angular/router';
@@ -1085,6 +1085,7 @@ class AppEmbeddingExtensions {
1085
1085
  MessageObserver = new Subject();
1086
1086
  _reloadAllowed = true;
1087
1087
  EmbeddedModule;
1088
+ pushedHistories = [];
1088
1089
  constructor(msgService, router, location) {
1089
1090
  this.msgService = msgService;
1090
1091
  this.router = router;
@@ -1102,6 +1103,21 @@ class AppEmbeddingExtensions {
1102
1103
  this.configureEmbeddability();
1103
1104
  if (this.Embedded)
1104
1105
  this.msgService.configureEmbeddability(this.MainWindow, this.MessageObserver);
1106
+ this.MessageObserver.pipe(filter$1(ev => ev.event == "menu-navigation")).subscribe(event => {
1107
+ // Mi interessa solo roba relativa all'embedding
1108
+ if (!event.data.routerLink.startsWith("embed"))
1109
+ return;
1110
+ // emb/crm/parties/parties_search?blabla --> parties/parties_search
1111
+ let normalizedRequestedRoute = event.data.routerLink.split("?")[0].split("/").slice(2).join("/");
1112
+ ///pages_ext/parties/parties_search?blabla --> parties/parties_search
1113
+ let normalizedFirstRoute = this.pushedHistories.length > 0 ? this.pushedHistories[0].from.split("?")[0].split("/").slice(2).join("/") : "";
1114
+ // La route su cui sto navigando ora è uguale alla route in cui l'embedding è iniziato.
1115
+ // Significa che devo simulare dei back fino a che non sono arrivato all'inizio
1116
+ if (normalizedRequestedRoute == normalizedFirstRoute) {
1117
+ this.router.navigate(["pages/" + event.data.routerLink, { wakeup: 1 }], { queryParams: event.data.queryParams, onSameUrlNavigation: "reload" });
1118
+ this.pushedHistories = [];
1119
+ }
1120
+ });
1105
1121
  }
1106
1122
  waitForMyConfigAndForceEmbeddedModule() {
1107
1123
  // Aspetto di ricevere il myconfig e setto con lui l'embeddedmodule. Questo viene eseguito solo se this.location.path() per qualche motivo non contiene il module
@@ -1117,11 +1133,24 @@ class AppEmbeddingExtensions {
1117
1133
  this._reloadAllowed = true;
1118
1134
  return ret;
1119
1135
  }
1136
+ MessageBarrierDebouncMs = 250;
1137
+ OnMessageCallBarrier = {};
1138
+ messageHash(event) {
1139
+ return `${JSON.parse(JSON.stringify(event?.data))}`;
1140
+ }
1120
1141
  configureEmbeddability() {
1121
1142
  window.onmessage = (event) => {
1122
1143
  // Ignoro i miei messaggi dato che mi interessano solo quelli degli altri iframe
1123
1144
  if (event.source == window && event?.data?.type != "modal-open")
1124
1145
  return;
1146
+ // Posso gestire lo stesso identico messaggio solo 1 volta ogni MessageBarrierDebouncMs
1147
+ let messageHash = this.messageHash(event);
1148
+ if (this.OnMessageCallBarrier[messageHash])
1149
+ return;
1150
+ else {
1151
+ this.OnMessageCallBarrier[messageHash] = true;
1152
+ setTimeout(() => delete this.OnMessageCallBarrier[messageHash], this.MessageBarrierDebouncMs);
1153
+ }
1125
1154
  this.MessageObserver.next({ event: "window-message", data: event?.data });
1126
1155
  if (event?.data?.type == "alert") {
1127
1156
  console.log(`Window message - alert -> Level: ${event?.data?.level}, Message: ${event?.data?.msg}`);
@@ -1169,6 +1198,7 @@ class AppEmbeddingExtensions {
1169
1198
  console.log(`Window message - navigate -> ${event?.data?.url}`);
1170
1199
  var newTab = event?.data?.newTab;
1171
1200
  var replaceState = event?.data?.replaceState;
1201
+ var current = event?.data?.current;
1172
1202
  // Controllo se il router sta seguendo la chiamata attuale. Escludo i query params che sono gli unici che possono essere seccati dai replaceState
1173
1203
  // e che potrebbero fare del casino
1174
1204
  if (!window.location.href.includes(this.router.url.split("?")[0])) {
@@ -1178,17 +1208,16 @@ class AppEmbeddingExtensions {
1178
1208
  let newRelativeUrl = this.router.createUrlTree([event?.data?.url]);
1179
1209
  let baseUrl = window.location.href.replace(this.router.url.replace("?ignoreStorage=true", ''), '');
1180
1210
  let newUrl = baseUrl + decodeURIComponent(newRelativeUrl.toString());
1181
- if (replaceState)
1211
+ if (replaceState) {
1212
+ this.pushedHistories.push({ _pushed: true, url: newUrl, from: current });
1182
1213
  history.pushState({ _pushed: true }, "", newUrl);
1214
+ }
1183
1215
  else if (newTab)
1184
1216
  window.open(newUrl, '_blank');
1185
1217
  }
1186
1218
  else if (event?.data?.type == "navigate-back") {
1187
1219
  console.log(`Window message - navigate-back -> ${event?.data?.url}`);
1188
- if (history?.state?._pushed) {
1189
- this._reloadAllowed = false;
1190
- history.back();
1191
- }
1220
+ this.onNavigateBack();
1192
1221
  }
1193
1222
  else if (event?.data?.type == "redirect") {
1194
1223
  console.log(`Window message - redirect -> ${event?.data?.url}`);
@@ -1204,7 +1233,8 @@ class AppEmbeddingExtensions {
1204
1233
  const wrapperPaddingLeft = parseInt(wrapperStyles.getPropertyValue("padding-left"));
1205
1234
  const wrapperPaddingRight = parseInt(wrapperStyles.getPropertyValue("padding-right"));
1206
1235
  console.log(`Window message - Modal Open -> Backdrop Height: ${event?.data?.backdropHeight}`);
1207
- var topHeight = 80; // valore fisso, distanza fra il top e l'inizio dell'iframe, non sarà mai diverso
1236
+ var bottomLeftover = 7; // Valore fisso... robina che rimane di sotto per un motivo o quell'altro
1237
+ var topHeight = 86; // valore fisso, distanza fra il top e l'inizio dell'iframe, non sarà mai diverso
1208
1238
  var rightSpace = wrapperPaddingRight; // valore fisso, distanza fra la fine dell'iframe e il lato sinistro dello schermo, non sarà mai diverso
1209
1239
  var leftSpace = this.sidebarWidth + wrapperPaddingLeft;
1210
1240
  let commonStyles = "position: absolute; z-index: 9999; background-color: #000; opacity: 0.5; ";
@@ -1221,13 +1251,14 @@ class AppEmbeddingExtensions {
1221
1251
  right.className = "embedded-modal-right";
1222
1252
  right.style.cssText = commonStyles + `height: calc(100% - ${topHeight}px); top: ${topHeight}px; right: 0; width: ${rightSpace}px;`;
1223
1253
  right.id = "right";
1224
- // const bottom = document.createElement("div");
1225
- // bottom.className = "embedded-modal-bottom";
1226
- // bottom.style.cssText = commonStyles + `height: ${topHeight}px; bottom: 0; width: calc(100% - ${leftSpace}px); left: ${leftSpace}px`;
1227
- // bottom.id = "bottom";
1254
+ const bottom = document.createElement("div");
1255
+ bottom.className = "embedded-modal-bottom";
1256
+ bottom.style.cssText = commonStyles + `height: ${bottomLeftover}px; bottom: 0; width: calc(100% - ${leftSpace + rightSpace}px); left: ${leftSpace}px`;
1257
+ bottom.id = "bottom";
1228
1258
  document.body.appendChild(top);
1229
1259
  document.body.appendChild(left);
1230
1260
  document.body.appendChild(right);
1261
+ document.body.appendChild(bottom);
1231
1262
  }
1232
1263
  else if (event?.data?.type == "modal-close") {
1233
1264
  console.log(`Window message - Modal Close`);
@@ -1236,17 +1267,27 @@ class AppEmbeddingExtensions {
1236
1267
  const top = document.getElementById("top");
1237
1268
  const left = document.getElementById("left");
1238
1269
  const right = document.getElementById("right");
1270
+ const bottom = document.getElementById("bottom");
1239
1271
  if (top)
1240
1272
  document.body.removeChild(top);
1241
1273
  if (left)
1242
1274
  document.body.removeChild(left);
1243
1275
  if (right)
1244
1276
  document.body.removeChild(right);
1277
+ if (bottom)
1278
+ document.body.removeChild(bottom);
1245
1279
  }
1246
1280
  };
1247
1281
  if (this.Embedded)
1248
1282
  document.body.style.setProperty("overflow-y", "auto", "important");
1249
1283
  }
1284
+ onNavigateBack() {
1285
+ if (history?.state?._pushed) {
1286
+ this._reloadAllowed = false;
1287
+ this.pushedHistories.pop();
1288
+ history.back();
1289
+ }
1290
+ }
1250
1291
  replaceState(basePath, url) {
1251
1292
  // Esempio basePath: pages
1252
1293
  // Esempio url: parties/leads_search