redirect fixes

This commit is contained in:
Dennis Eichhorn 2024-04-26 22:02:22 +00:00
parent 31419927be
commit d3337d327d
2 changed files with 42 additions and 27 deletions

View File

@ -1194,14 +1194,15 @@ export class Form
} }
let statusCode = null; let statusCode = null;
let responseData = null;
if (xhr.getResponseHeader('content-type').includes('application/octet-stream')) { if (xhr.getResponseHeader('content-type').includes('application/octet-stream')) {
const blob = new Blob([xhr.response], { type: 'application/octet-stream' }); responseData = new Blob([xhr.response], { type: 'application/octet-stream' });
const doc = document.createElement('a'); const doc = document.createElement('a');
doc.style = 'display: none'; doc.style = 'display: none';
document.body.appendChild(doc); document.body.appendChild(doc);
const url = window.URL.createObjectURL(blob); const url = window.URL.createObjectURL(responseData);
doc.href = url; doc.href = url;
const disposition = xhr.getResponseHeader('content-disposition'); const disposition = xhr.getResponseHeader('content-disposition');
@ -1222,6 +1223,7 @@ export class Form
} else if (xhr.getResponseHeader('content-type').includes('text/html')) { } else if (xhr.getResponseHeader('content-type').includes('text/html')) {
// window.location = UriFactory.build(uri); // window.location = UriFactory.build(uri);
responseData = xhr.response;
document.documentElement.innerHTML = xhr.response; document.documentElement.innerHTML = xhr.response;
/* This is not working as it reloads the page ?! /* This is not working as it reloads the page ?!
document.open(); document.open();
@ -1232,8 +1234,8 @@ export class Form
window.omsApp.reInit(); // @todo fix memory leak which most likely exists because of continuous binding without removing binds window.omsApp.reInit(); // @todo fix memory leak which most likely exists because of continuous binding without removing binds
} else { } else {
try { try {
const o = JSON.parse(xhr.response)[0]; responseData = JSON.parse(xhr.response);
const response = new Response(o); const response = new Response(responseData[0]);
let successInject = null; let successInject = null;
statusCode = parseInt(xhr.getResponseHeader('status')); statusCode = parseInt(xhr.getResponseHeader('status'));
@ -1247,9 +1249,16 @@ export class Form
if (response.get('type') !== null) { if (response.get('type') !== null) {
self.app.responseManager.run(response.get('type'), response.get(), null); self.app.responseManager.run(response.get('type'), response.get(), null);
} else if (typeof o.status !== 'undefined' && o.status !== NotificationLevel.HIDDEN) { } else if (typeof responseData[0].status !== 'undefined'
&& responseData[0].status !== NotificationLevel.HIDDEN
) {
self.app.notifyManager.send( self.app.notifyManager.send(
new NotificationMessage(o.status, o.title, o.message), NotificationType.APP_NOTIFICATION new NotificationMessage(
responseData[0].status,
responseData[0].title,
responseData[0].message
),
NotificationType.APP_NOTIFICATION
); );
} }
} catch (e) { } catch (e) {
@ -1267,33 +1276,36 @@ export class Form
'Some failure happened' 'Some failure happened'
), NotificationType.APP_NOTIFICATION ), NotificationType.APP_NOTIFICATION
); );
statusCode = 400;
} }
} }
if (redirect !== null if (redirect !== null
&& (statusCode === 200 || statusCode === null) && (statusCode === 200 || statusCode === null)
) { ) {
fetch(UriFactory.build(redirect)) const redirectUrl = UriFactory.build(redirect, responseData)
.then((response) => response.text()) fetch(redirectUrl)
.then((html) => { .then((response) => response.text())
document.documentElement.innerHTML = html; .then((html) => {
document.documentElement.innerHTML = html;
if (window.omsApp.state) { if (window.omsApp.state) {
window.omsApp.state.hasChanges = false; window.omsApp.state.hasChanges = false;
} }
history.pushState({}, null, UriFactory.build(redirect)); history.pushState({}, null, redirectUrl);
/* This is not working as it reloads the page ?! /* This is not working as it reloads the page ?!
document.open(); document.open();
document.write(html); document.write(html);
document.close(); document.close();
*/ */
// @todo fix memory leak which most likely exists because of continuous binding without removing binds // @todo fix memory leak which most likely exists because of continuous binding without removing binds
window.omsApp.reInit(); window.omsApp.reInit();
}) })
.catch((error) => { .catch((error) => {
console.warn(error); console.warn(error);
}); });
} }
}); });

View File

@ -215,8 +215,11 @@ export class UriFactory
let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$\!].*?\}', 'g'), function (match) { let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$\!].*?\}', 'g'), function (match) {
match = match.substring(1, match.length - 1); match = match.substring(1, match.length - 1);
if (toMatch !== null && Object.prototype.hasOwnProperty.call(toMatch, match)) { if (toMatch !== null
return toMatch[match]; && (Object.prototype.hasOwnProperty.call(toMatch, match)
|| match.includes('/'))
) {
return match.includes('/') ? jsOMS.getArray(match, toMatch) : toMatch[match];
} else if (typeof UriFactory.uri[match] !== 'undefined') { } else if (typeof UriFactory.uri[match] !== 'undefined') {
return UriFactory.uri[match]; return UriFactory.uri[match];
} else if (match.indexOf('!') === 0) { } else if (match.indexOf('!') === 0) {