fix: getRoute within envoy

This commit is contained in:
Jean-Baptiste Pasquier 2021-07-05 18:29:02 +02:00
parent cf1add07cb
commit 287666e560
4 changed files with 28 additions and 27 deletions

View File

@ -1,23 +0,0 @@
window.orbit.getRoute = (type, returnFirst = false) => {
let availables = window.orbit.components.filter(c => c.type == type || c.uniq == type);
window.orbit.components.forEach(c => {
if (c.extensions) {
c.extensions.forEach(e => {
if (e.type == type || e.uniq == type) {
availables.push(e);
}
});
}
});
if (availables.length > 1) {
if (returnFirst) {
return availables[0].route;
} else {
return availables[availables.length - 1].route;
}
} else if (availables.length < 1) {
console.error(`No component found for route ${type}`);
} else {
return availables[0].route;
}
}

View File

@ -1,4 +1,4 @@
import(`https://storage.googleapis.com/workbox-cdn/releases/6.1.1/workbox-window.prod.mjs`).then(workboxWindow => { import(`https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-window.prod.mjs`).then(workboxWindow => {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
window.addEventListener('load', function () { window.addEventListener('load', function () {

View File

@ -196,5 +196,29 @@ for component of components
defaultRoute = defaultComponent[0].uniq; defaultRoute = defaultComponent[0].uniq;
} }
- const orbitComponents = `window.orbit={};window.orbit.components = ${JSON.stringify(components)};window.orbit.federations = ${JSON.stringify(federations)};window.orbit.defaultRoute = "${defaultRoute}";window.orbit.client = ${JSON.stringify(client)};window.hubl = window.orbit;`; - const orbitComponents = `window.orbit={};window.orbit.components = ${JSON.stringify(components)};window.orbit.federations = ${JSON.stringify(federations)};window.orbit.defaultRoute = "${defaultRoute}";window.orbit.client = ${JSON.stringify(client)};`;
script!=orbitComponents script!=orbitComponents
| window.orbit.getRoute = (type, returnFirst = false) => {
| let availables = window.orbit.components.filter(c => c.type == type || c.uniq == type);
| window.orbit.components.forEach(c => {
| if (c.extensions) {
| c.extensions.forEach(e => {
| if (e.type == type || e.uniq == type) {
| availables.push(e);
| }
| });
| }
| });
| if (availables.length > 1) {
| if (returnFirst) {
| return availables[0].route;
| } else {
| return availables[availables.length - 1].route;
| }
| } else if (availables.length < 1) {
| console.error(`No component found for route ${type}`);
| } else {
| return availables[0].route;
| }
| }
| window.hubl = window.orbit;

View File

@ -36,7 +36,7 @@ document.addEventListener("DOMContentLoaded", function () {
} }
}); });
window.addEventListener("navigate", e => { window.addEventListener("navigate", e => {
if (e.detail.route == "login" && !window.requestLogin) { if (e.detail.route == "login" && !window.requestLogin && window.orbit.getRoute) {
window.dispatchEvent( window.dispatchEvent(
new CustomEvent('requestNavigation', { new CustomEvent('requestNavigation', {
detail: { detail: {