Skip to content
Snippets Groups Projects
Commit 09ba7e6c authored by Benoit Alessandroni's avatar Benoit Alessandroni
Browse files

Merge branch 'fix-router-bug' of...

Merge branch 'fix-router-bug' of git.startinblox.com:applications/knowledge-base/knowledgebase-front into fix-router-bug
parents 481fae7a ae50da6f
No related branches found
No related tags found
1 merge request!137Fix router bug
Pipeline #5013 failed with stage
in 1 hour
.container //- .container
.flex.flex_espace.flex_item_center //- .flex.flex_espace.flex_item_center
a.logo_footer(href='https://coopseurope.coop/') //- a.logo_footer(href='https://coopseurope.coop/')
figure.margin_bord_ecran //- figure.margin_bord_ecran
img(src="../images/logo_CE.png" alt="Coopstarter") //- img(src="../images/logo_CE.png" alt="Coopstarter")
a.logo_footer(href='mentor-resource-list') //- a.logo_footer(href='mentor-resource-list')
figure.margin_bord_ecran //- figure.margin_bord_ecran
img(src="../images/logo_coops4dev.jpg" alt="Coopstarter") //- img(src="../images/logo_coops4dev.jpg" alt="Coopstarter")
a.logo_footer(href='mentor-resource-list') //- a.logo_footer(href='mentor-resource-list')
figure.flex.flex_item_center //- figure.flex.flex_item_center
img.textMore(src="../images/ica_logo.png" alt="Coopstarter") //- img.textMore(src="../images/ica_logo.png" alt="Coopstarter")
div //- div
p International //- p International
p Co-operative //- p Co-operative
p Alliance //- p Alliance
a.logo_footer(href='mentor-resource-list') //- a.logo_footer(href='mentor-resource-list')
figure.flex.flex_item_center //- figure.flex.flex_item_center
img.textMore(src="../images/logo_UE.jpg" alt="Coopstarter") //- img.textMore(src="../images/logo_UE.jpg" alt="Coopstarter")
div //- div
p Co-funded //- p Co-funded
p by the //- p by the
p European Union //- p European Union
p.footer_warning.flex_item_center This software has been co-funded by the European Union. The contents of this software are the sole responsibility of Cooperatives Europe and can in no way be taken to reflect the views of the European Union. //- p.footer_warning.flex_item_center This software has been co-funded by the European Union. The contents of this software are the sole responsibility of Cooperatives Europe and can in no way be taken to reflect the views of the European Union.
\ No newline at end of file \ No newline at end of file
...@@ -27,7 +27,7 @@ html ...@@ -27,7 +27,7 @@ html
#public-dashboard(hidden).no-sidebar #public-dashboard(hidden).no-sidebar
include includes/public/dashboard.pug include includes/public/dashboard.pug
#main-loader(hidden) Loading… #main-loader(hidden style="display: none") Loading…
sib-auth sib-auth
sib-auth-provider( sib-auth-provider(
...@@ -36,64 +36,6 @@ sib-auth ...@@ -36,64 +36,6 @@ sib-auth
data-id="coopstarter" data-id="coopstarter"
) )
script(type='module'). script(type='module' src='/scripts/dispatch-space-n-user.js')
import { store } from 'https://unpkg.com/@startinblox/core@0.8';
const sibAuth = document.querySelector('sib-auth');
class CoopStarterLoginComponent extends HTMLElement {
async connectedCallback() {
mentor_login.onclick = () => this.triggerLogin();
this.update();
}
async triggerLogin() {
let loader = document.getElementById('main-loader');
loader.removeAttribute('hidden');
await sibAuth.login();
}
async update() {
let loader = document.getElementById('main-loader');
loader.removeAttribute('hidden');
let user = await sibAuth.getUser();
let idToken = await sibAuth.getUserIdToken();
console.log(window.location);
if ( !user && window.location.href.indexOf('public-dashboard/public-resource-detail') === -1) {
console.log("We have no user and not in public")
loader.setAttribute("hidden", true);
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'splash' } })
);
}
if(!user && window.location.href.indexOf('public-dashboard/public-resource-detail') > -1) {
console.log("We are targetting the public space !")
//- window.dispatchEvent(
//- new CustomEvent('requestNavigation', { detail: {
//- route: 'public-resource-detail'
//- } })
//- );
loader.setAttribute("hidden", true);
}
user = await store.get(user);
if (user && user.mentor_profile) {
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'mentor-dashboard' } })
);
} else if (user && user.entrepreneur_profile) {
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'entrepreneur-dashboard' } })
);
} else {
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'account-creation' } })
);
}
}
empty(){}
populate(){}
}
customElements.define('cs-login', CoopStarterLoginComponent);
...@@ -585,8 +585,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/ ...@@ -585,8 +585,8 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX*/
jQuery(document).ready(function($) { jQuery(document).ready(function($) {
window.addEventListener('requestNavigation', function(e) { window.addEventListener('requestNavigation', function(e) {
setTimeout(function() { setTimeout(function() {
let loader = document.getElementById('main-loader'); // let loader = document.getElementById('main-loader');
loader.setAttribute('hidden', true); // loader.setAttribute('hidden', true);
}, 2000); }, 2000);
}); });
......
import { store } from 'https://unpkg.com/@startinblox/core@0.8';
const sibAuth = document.querySelector('sib-auth');
//We create a custom element
class CoopStarterLoginComponent extends HTMLElement {
// Those function will be call the element is connected to the dom
async connectedCallback() {
document.getElementById("mentor_login").onclick = () => this.triggerLogin();
this.update();
}
async triggerLogin() {
let loader = document.getElementById('main-loader');
loader.removeAttribute('hidden');
await sibAuth.login();
}
async update() {
let loader = document.getElementById('main-loader');
loader.removeAttribute('hidden');
let user = await sibAuth.getUser();
// let idToken = await sibAuth.getUserIdToken();
// console.log(window.location);
// //Not connected and not sharing public resource
// // console.log( user, sibAuth, window.location.href.indexOf('public-dashboard/public-resource-detail') === -1)
// if ( !user && window.location.href.indexOf('public-dashboard/public-resource-detail') === -1) {
// console.log("We have no user and not in public")
// loader.setAttribute("hidden", true);
// window.dispatchEvent(
// new CustomEvent('requestNavigation', { detail: { route: 'splash' } })
// );
// }
// //Not connected but sharing public resource
// if(window.location.href.indexOf('public-dashboard/public-resource-detail') > -1) {
// console.log("We are targetting the public space !")
// //- window.dispatchEvent(
// //- new CustomEvent('requestNavigation', { detail: {
// //- route: 'public-resource-detail'
// //- } })
// //- );
// loader.setAttribute("hidden", true);
// return
// }
// Idenfify the space we should go
user = await store.get(user);
console.log("the curent user is ", user)
//Set a userprefix default status
var userPrefix = "public"
//If the user is a mentor or an entreprenur, change user prefix
if(user && user.mentor_profile) {
userPrefix = "mentor"
console.log("he is a ",userPrefix )
} else if (user && user.entrepreneur_profile) {
userPrefix = "entrepreneur"
console.log("he is a ",userPrefix )
}
//If the url asked pointed to a resource
if(window.location.href.indexOf('resource-detail') > -1) {
console.log(" the link contains ressource detail")
console.log("the current link is ", window.location.href)
//We adapt the url with its status
console.log("userPrefix", userPrefix)
var newUrl = window.location.href.replace(/\/([a-z]+)-dashboard\/([a-z]+)-resource-detail/, `/${userPrefix}-dashboard/${userPrefix}-resource-detail`)
// http://localhost:9000/fr/mentor-dashboard/@https~@~_~_api-staging~!coopstarter~!happy-dev~!fr~_resources~_7~_/mentor-resource-detail/@https~@~_~_api-staging~!coopstarter~!happy-dev~!fr~_resources~_7~_
console.log("After treatement, the link is ", newUrl)
//If the url is different after the treatment, we reload with the good url
if(newUrl !== window.location.href){
console.log("the url are ifférent, we relaod")
var newRoute = new URL(newUrl).pathname.replace(/^\/([a-z]{2})\//, "")
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: newRoute } })
);
console.log("newRoute", newRoute)
// window.location.href = newUrl
}
else{
console.log("the url identique, let it go")
loader.toggleAttribute('hidden', true);
}
}else {
console.log("the current link doesn't concern a detail resource")
if (user && user.mentor_profile) {
//si y a un lien public alors on traite la chaine
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'mentor-dashboard' } })
);
//User is a entrepreneur
} else if (user && user.entrepreneur_profile) {
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'entrepreneur-dashboard' } })
);
} else {
window.dispatchEvent(
new CustomEvent('requestNavigation', { detail: { route: 'account-creation' } })
);
}
//user-dashboard
}
// //???
// user = await store.get(user);
// console.log(user)
//User is a mentor
}
empty(){}
populate(){}
}
// We can use <cs-login/>
customElements.define('cs-login', CoopStarterLoginComponent);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment