@esfaenza/extensions 19.2.17 → 19.2.20
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';
|
|
@@ -1079,12 +1079,14 @@ class AppEmbeddingExtensions {
|
|
|
1079
1079
|
router;
|
|
1080
1080
|
location;
|
|
1081
1081
|
sidebarWidth = 230;
|
|
1082
|
+
EmbeddingSource = new ReplaySubject();
|
|
1082
1083
|
Embedded = false;
|
|
1083
1084
|
EmbeddingLevel = 0;
|
|
1084
1085
|
MainWindow;
|
|
1085
1086
|
MessageObserver = new Subject();
|
|
1086
1087
|
_reloadAllowed = true;
|
|
1087
1088
|
EmbeddedModule;
|
|
1089
|
+
pushedHistories = [];
|
|
1088
1090
|
constructor(msgService, router, location) {
|
|
1089
1091
|
this.msgService = msgService;
|
|
1090
1092
|
this.router = router;
|
|
@@ -1102,6 +1104,21 @@ class AppEmbeddingExtensions {
|
|
|
1102
1104
|
this.configureEmbeddability();
|
|
1103
1105
|
if (this.Embedded)
|
|
1104
1106
|
this.msgService.configureEmbeddability(this.MainWindow, this.MessageObserver);
|
|
1107
|
+
this.MessageObserver.pipe(filter$1(ev => ev.event == "menu-navigation")).subscribe(event => {
|
|
1108
|
+
// Mi interessa solo roba relativa all'embedding
|
|
1109
|
+
if (!event.data.routerLink.startsWith("embed"))
|
|
1110
|
+
return;
|
|
1111
|
+
// emb/crm/parties/parties_search;blabla=xyz?blabla --> parties/parties_search
|
|
1112
|
+
let normalizedRequestedRoute = event.data.routerLink.split("?")[0].split(";")[0].split("/").slice(2).join("/");
|
|
1113
|
+
///pages_ext/{module}/parties/parties_search;blabla=xyz?blabla --> parties/parties_search
|
|
1114
|
+
let normalizedFirstRoute = this.pushedHistories.length > 0 ? this.pushedHistories[0].from.split("?")[0].split(";")[0].split("/").slice(3).join("/") : "";
|
|
1115
|
+
// La route su cui sto navigando ora è uguale alla route in cui l'embedding è iniziato.
|
|
1116
|
+
// Significa che devo simulare dei back fino a che non sono arrivato all'inizio
|
|
1117
|
+
if (normalizedRequestedRoute == normalizedFirstRoute) {
|
|
1118
|
+
this.router.navigate(["pages/" + event.data.routerLink, { wakeup: 1 }], { queryParams: event.data.queryParams, onSameUrlNavigation: "reload" });
|
|
1119
|
+
this.pushedHistories = [];
|
|
1120
|
+
}
|
|
1121
|
+
});
|
|
1105
1122
|
}
|
|
1106
1123
|
waitForMyConfigAndForceEmbeddedModule() {
|
|
1107
1124
|
// 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 +1134,29 @@ class AppEmbeddingExtensions {
|
|
|
1117
1134
|
this._reloadAllowed = true;
|
|
1118
1135
|
return ret;
|
|
1119
1136
|
}
|
|
1137
|
+
MessageBarrierDebouncMs = 250;
|
|
1138
|
+
OnMessageCallBarrier = {};
|
|
1139
|
+
messageHash(event) {
|
|
1140
|
+
return `${JSON.parse(JSON.stringify(event?.data))}`;
|
|
1141
|
+
}
|
|
1120
1142
|
configureEmbeddability() {
|
|
1143
|
+
if (this.Embedded)
|
|
1144
|
+
this.MainWindow.postMessage({ type: "whois" }, "*");
|
|
1145
|
+
else
|
|
1146
|
+
this.EmbeddingSource.next("");
|
|
1121
1147
|
window.onmessage = (event) => {
|
|
1122
1148
|
// Ignoro i miei messaggi dato che mi interessano solo quelli degli altri iframe
|
|
1123
1149
|
if (event.source == window && event?.data?.type != "modal-open")
|
|
1124
1150
|
return;
|
|
1151
|
+
let sourceWindow = event.source;
|
|
1152
|
+
// Posso gestire lo stesso identico messaggio solo 1 volta ogni MessageBarrierDebouncMs
|
|
1153
|
+
let messageHash = this.messageHash(event);
|
|
1154
|
+
if (this.OnMessageCallBarrier[messageHash])
|
|
1155
|
+
return;
|
|
1156
|
+
else {
|
|
1157
|
+
this.OnMessageCallBarrier[messageHash] = true;
|
|
1158
|
+
setTimeout(() => delete this.OnMessageCallBarrier[messageHash], this.MessageBarrierDebouncMs);
|
|
1159
|
+
}
|
|
1125
1160
|
this.MessageObserver.next({ event: "window-message", data: event?.data });
|
|
1126
1161
|
if (event?.data?.type == "alert") {
|
|
1127
1162
|
console.log(`Window message - alert -> Level: ${event?.data?.level}, Message: ${event?.data?.msg}`);
|
|
@@ -1140,13 +1175,20 @@ class AppEmbeddingExtensions {
|
|
|
1140
1175
|
break;
|
|
1141
1176
|
}
|
|
1142
1177
|
}
|
|
1178
|
+
else if (event?.data?.type == "whois") {
|
|
1179
|
+
console.log(`Window message - Whois?`);
|
|
1180
|
+
sourceWindow.postMessage({ type: "itsme", module: myconfig.AppData.ModuleId }, "*");
|
|
1181
|
+
}
|
|
1182
|
+
else if (event?.data?.type == "itsme") {
|
|
1183
|
+
console.log(`Window message - It'sme -> ` + event?.data?.module);
|
|
1184
|
+
this.EmbeddingSource.next(event?.data?.module);
|
|
1185
|
+
}
|
|
1143
1186
|
else if (event?.data?.type == "replace-state") {
|
|
1144
1187
|
console.log(`Window message - replace-state -> Url: ${event?.data?.url}`);
|
|
1145
1188
|
this.location.replaceState(event?.data?.url);
|
|
1146
1189
|
}
|
|
1147
1190
|
else if (event?.data?.type == "confirm") {
|
|
1148
1191
|
console.log(`Window message - confirm -> Level: ${event?.data?.level}, Message: ${event?.data?.text}, Title: ${event?.data?.title}, ID: ${event?.data?.guid}`);
|
|
1149
|
-
var sourceWindow = event.source;
|
|
1150
1192
|
var baseResponse = { type: "confirm-response", guid: event?.data?.guid };
|
|
1151
1193
|
switch (event?.data?.level) {
|
|
1152
1194
|
case "success":
|
|
@@ -1169,26 +1211,27 @@ class AppEmbeddingExtensions {
|
|
|
1169
1211
|
console.log(`Window message - navigate -> ${event?.data?.url}`);
|
|
1170
1212
|
var newTab = event?.data?.newTab;
|
|
1171
1213
|
var replaceState = event?.data?.replaceState;
|
|
1214
|
+
var current = event?.data?.current;
|
|
1172
1215
|
// Controllo se il router sta seguendo la chiamata attuale. Escludo i query params che sono gli unici che possono essere seccati dai replaceState
|
|
1173
|
-
// e che potrebbero fare del casino
|
|
1174
|
-
if (!window.location.href.includes(this.router.url.split("?")[0])) {
|
|
1216
|
+
// e che potrebbero fare del casino. Stesso discorso per i parametri semplici (ad esempio il parametro di wakeup)
|
|
1217
|
+
if (!window.location.href.includes(this.router.url.split("?")[0].split(";")[0])) {
|
|
1175
1218
|
console.warn("Doppia chiamata di navigazione, ignoro il secondo evento scoordinato dal router");
|
|
1176
1219
|
return;
|
|
1177
1220
|
}
|
|
1178
1221
|
let newRelativeUrl = this.router.createUrlTree([event?.data?.url]);
|
|
1179
|
-
let baseUrl = window.location.href.
|
|
1180
|
-
let
|
|
1181
|
-
|
|
1222
|
+
let baseUrl = window.location.href.split("#")[0] + "#";
|
|
1223
|
+
let appPath = decodeURIComponent(newRelativeUrl.toString());
|
|
1224
|
+
let newUrl = baseUrl + appPath;
|
|
1225
|
+
if (replaceState) {
|
|
1226
|
+
this.pushedHistories.push({ _pushed: true, url: newUrl, from: current });
|
|
1182
1227
|
history.pushState({ _pushed: true }, "", newUrl);
|
|
1228
|
+
}
|
|
1183
1229
|
else if (newTab)
|
|
1184
1230
|
window.open(newUrl, '_blank');
|
|
1185
1231
|
}
|
|
1186
1232
|
else if (event?.data?.type == "navigate-back") {
|
|
1187
1233
|
console.log(`Window message - navigate-back -> ${event?.data?.url}`);
|
|
1188
|
-
|
|
1189
|
-
this._reloadAllowed = false;
|
|
1190
|
-
history.back();
|
|
1191
|
-
}
|
|
1234
|
+
this.onNavigateBack();
|
|
1192
1235
|
}
|
|
1193
1236
|
else if (event?.data?.type == "redirect") {
|
|
1194
1237
|
console.log(`Window message - redirect -> ${event?.data?.url}`);
|
|
@@ -1204,7 +1247,8 @@ class AppEmbeddingExtensions {
|
|
|
1204
1247
|
const wrapperPaddingLeft = parseInt(wrapperStyles.getPropertyValue("padding-left"));
|
|
1205
1248
|
const wrapperPaddingRight = parseInt(wrapperStyles.getPropertyValue("padding-right"));
|
|
1206
1249
|
console.log(`Window message - Modal Open -> Backdrop Height: ${event?.data?.backdropHeight}`);
|
|
1207
|
-
var
|
|
1250
|
+
var bottomLeftover = 7; // Valore fisso... robina che rimane di sotto per un motivo o quell'altro
|
|
1251
|
+
var topHeight = 86; // valore fisso, distanza fra il top e l'inizio dell'iframe, non sarà mai diverso
|
|
1208
1252
|
var rightSpace = wrapperPaddingRight; // valore fisso, distanza fra la fine dell'iframe e il lato sinistro dello schermo, non sarà mai diverso
|
|
1209
1253
|
var leftSpace = this.sidebarWidth + wrapperPaddingLeft;
|
|
1210
1254
|
let commonStyles = "position: absolute; z-index: 9999; background-color: #000; opacity: 0.5; ";
|
|
@@ -1221,13 +1265,14 @@ class AppEmbeddingExtensions {
|
|
|
1221
1265
|
right.className = "embedded-modal-right";
|
|
1222
1266
|
right.style.cssText = commonStyles + `height: calc(100% - ${topHeight}px); top: ${topHeight}px; right: 0; width: ${rightSpace}px;`;
|
|
1223
1267
|
right.id = "right";
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1268
|
+
const bottom = document.createElement("div");
|
|
1269
|
+
bottom.className = "embedded-modal-bottom";
|
|
1270
|
+
bottom.style.cssText = commonStyles + `height: ${bottomLeftover}px; bottom: 0; width: calc(100% - ${leftSpace + rightSpace}px); left: ${leftSpace}px`;
|
|
1271
|
+
bottom.id = "bottom";
|
|
1228
1272
|
document.body.appendChild(top);
|
|
1229
1273
|
document.body.appendChild(left);
|
|
1230
1274
|
document.body.appendChild(right);
|
|
1275
|
+
document.body.appendChild(bottom);
|
|
1231
1276
|
}
|
|
1232
1277
|
else if (event?.data?.type == "modal-close") {
|
|
1233
1278
|
console.log(`Window message - Modal Close`);
|
|
@@ -1236,17 +1281,27 @@ class AppEmbeddingExtensions {
|
|
|
1236
1281
|
const top = document.getElementById("top");
|
|
1237
1282
|
const left = document.getElementById("left");
|
|
1238
1283
|
const right = document.getElementById("right");
|
|
1284
|
+
const bottom = document.getElementById("bottom");
|
|
1239
1285
|
if (top)
|
|
1240
1286
|
document.body.removeChild(top);
|
|
1241
1287
|
if (left)
|
|
1242
1288
|
document.body.removeChild(left);
|
|
1243
1289
|
if (right)
|
|
1244
1290
|
document.body.removeChild(right);
|
|
1291
|
+
if (bottom)
|
|
1292
|
+
document.body.removeChild(bottom);
|
|
1245
1293
|
}
|
|
1246
1294
|
};
|
|
1247
1295
|
if (this.Embedded)
|
|
1248
1296
|
document.body.style.setProperty("overflow-y", "auto", "important");
|
|
1249
1297
|
}
|
|
1298
|
+
onNavigateBack() {
|
|
1299
|
+
if (history?.state?._pushed) {
|
|
1300
|
+
this._reloadAllowed = false;
|
|
1301
|
+
this.pushedHistories.pop();
|
|
1302
|
+
history.back();
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1250
1305
|
replaceState(basePath, url) {
|
|
1251
1306
|
// Esempio basePath: pages
|
|
1252
1307
|
// Esempio url: parties/leads_search
|