From cc12fa9b99288570878760b5d74dd670098d3265 Mon Sep 17 00:00:00 2001
From: Benoit Alessandroni <benoit@happy-dev.fr>
Date: Sun, 19 Apr 2020 17:17:07 +0200
Subject: [PATCH 1/3] Fixing the login based on sib-auth last version

---
 src/includes/components/widgets.pug        |  2 +-
 src/includes/entrepreneur/profile/view.pug |  6 +--
 src/includes/head.pug                      |  6 +++
 src/includes/mentor/components/header.pug  |  2 +-
 src/includes/mentor/profile/view.pug       |  6 +--
 src/includes/mentor/resources/list.pug     |  1 +
 src/includes/public/profile/view.pug       |  6 +--
 src/includes/splash.pug                    |  2 +-
 src/scripts/coopstarter.js                 | 53 ++++++++++++----------
 src/scripts/dispatch-space-n-user.js       | 27 ++++++-----
 10 files changed, 63 insertions(+), 48 deletions(-)

diff --git a/src/includes/components/widgets.pug b/src/includes/components/widgets.pug
index 219dc85e..405c3e93 100644
--- a/src/includes/components/widgets.pug
+++ b/src/includes/components/widgets.pug
@@ -39,7 +39,7 @@ sib-widget(name='cs-display-user-link')
 
 sib-widget(name='cs-display-property')
   template
-    p ${value} 
+    p ${await value} 
 
 sib-widget(name='cs-display-page-title')
   template
diff --git a/src/includes/entrepreneur/profile/view.pug b/src/includes/entrepreneur/profile/view.pug
index 6bad6b20..fe9af731 100644
--- a/src/includes/entrepreneur/profile/view.pug
+++ b/src/includes/entrepreneur/profile/view.pug
@@ -12,7 +12,7 @@ div.block_list.flex
                 div.button_base.ico_gauche.ico_database=`${data.BrowseDatabase}`
 
     div.profile_information.block_log.w_75
-        sib-display#mentor_info(
+        sib-display.user_info(
             bind-resources
             fields='account.picture, name, mentorProfile.headline, mentorProfile.city, mentorProfile.country.name, registered_on'
             widget-account.picture='cs-profile-picture'
@@ -30,7 +30,7 @@ div.block_list.flex
             bind-resources
         )
 
-        sib-display#mentor_complementary(
+        sib-display.user_complementary(
             bind-resources
             fields='biography_label, mentorProfile.biography, skills_label, mentorProfile.skills'
             widget-biography_label='cs-display-label'
@@ -41,7 +41,7 @@ div.block_list.flex
             widget-mentorProfile.biography='cs-display-property'
         )
 
-        sib-display#mentor_contact(
+        sib-display.user_contact(
             bind-resources
             fields='email, mentorProfile.phone, mentorProfile.linkedin, mentorProfile.twitter'
             label-email=`${data.Email} : `
diff --git a/src/includes/head.pug b/src/includes/head.pug
index 9643a940..97f16314 100644
--- a/src/includes/head.pug
+++ b/src/includes/head.pug
@@ -12,6 +12,12 @@ head
     script(src="/scripts/coopstarter.js")
     script(async src="https://platform.twitter.com/widgets.js" charset="utf-8")
     link(rel="stylesheet" href="/styles/index.css")
+    sib-analytics(
+        type="matomo"
+        url="https://sib.matomo.cloud/"
+        id="1"
+    )
+
     script(data-default-context type="application/ld+json" ).
         
             {
diff --git a/src/includes/mentor/components/header.pug b/src/includes/mentor/components/header.pug
index ac47ea5f..628c69be 100644
--- a/src/includes/mentor/components/header.pug
+++ b/src/includes/mentor/components/header.pug
@@ -17,7 +17,7 @@
                 naked
             )
             .dropdownWrapper
-                sib-display#user_account_picture.dropdownLabel(
+                sib-display#mentor_account_picture.dropdownLabel(
                     bind-user
                     fields='account.picture',
                     widget-account.picture='cs-account-picture'
diff --git a/src/includes/mentor/profile/view.pug b/src/includes/mentor/profile/view.pug
index 279c4e7e..1525ae11 100644
--- a/src/includes/mentor/profile/view.pug
+++ b/src/includes/mentor/profile/view.pug
@@ -12,7 +12,7 @@ div.block_list.flex
                 div.button_base.ico_gauche.ico_database=`${data.BrowseDatabase}`
 
     div.profile_information.block_log
-        sib-display#mentor_info(
+        sib-display.user_info(
             bind-resources
             fields='account.picture, name, mentorProfile.headline, mentorProfile.city, mentorProfile.country.name, registered_on'
             widget-account.picture='cs-profile-picture'
@@ -30,7 +30,7 @@ div.block_list.flex
             bind-resources
         )
 
-        sib-display#mentor_complementary(
+        sib-display.user_complementary(
             bind-resources
             fields='biography_label, mentorProfile.biography, skills_label, mentorProfile.skills'
             widget-biography_label='cs-display-label'
@@ -41,7 +41,7 @@ div.block_list.flex
             widget-mentorProfile.biography='cs-display-property'
         )
 
-        sib-display#mentor_contact(
+        sib-display.user_contact(
             bind-resources
             fields='email, mentorProfile.phone, mentorProfile.linkedin, mentorProfile.twitter'
             label-email=`${data.Email} : `
diff --git a/src/includes/mentor/resources/list.pug b/src/includes/mentor/resources/list.pug
index cac962f6..34360256 100644
--- a/src/includes/mentor/resources/list.pug
+++ b/src/includes/mentor/resources/list.pug
@@ -98,6 +98,7 @@ div.block_list
                 div#loader-history-mentor
                     hidden 
                         i.fas.fa-spinner.fa-spin
+
                 sib-display#resources_history(
                     loader-id="loader-history-mentor"
                     bind-user
diff --git a/src/includes/public/profile/view.pug b/src/includes/public/profile/view.pug
index 890c3edc..0ee6b03c 100644
--- a/src/includes/public/profile/view.pug
+++ b/src/includes/public/profile/view.pug
@@ -12,7 +12,7 @@ div.block_list.flex
                 div.button_base.ico_gauche.ico_database=`${data.BrowseDatabase}`
 
     div.profile_information.block_log
-        sib-display#mentor_info(
+        sib-display.user_info(
             bind-resources
             fields='account.picture, name, mentorProfile.headline, mentorProfile.city, mentorProfile.country.name, registered_on'
             widget-account.picture='cs-profile-picture'
@@ -30,7 +30,7 @@ div.block_list.flex
             bind-resources
         )
 
-        sib-display#mentor_complementary(
+        sib-display.user_complementary(
             bind-resources
             fields='biography_label, mentorProfile.biography, skills_label, mentorProfile.skills'
             widget-biography_label='cs-display-label'
@@ -41,7 +41,7 @@ div.block_list.flex
             widget-mentorProfile.biography='cs-display-property'
         )
 
-        sib-display#mentor_contact(
+        sib-display.user_contact(
             bind-resources
             fields='email, mentorProfile.phone, mentorProfile.linkedin, mentorProfile.twitter'
             label-email=`${data.Email} : `
diff --git a/src/includes/splash.pug b/src/includes/splash.pug
index 3f87edfb..576d2d6f 100644
--- a/src/includes/splash.pug
+++ b/src/includes/splash.pug
@@ -12,7 +12,7 @@ h2.title_lead=`${data.welcome}`
             alt="Connect as mentor")
 
     cs-login(bind-user)
-        button#mentor_login.button_base=`${data.ConnectKnowledgeBase}`
+        button#kldb_login.button_base=`${data.ConnectKnowledgeBase}`
     
     sib-link(next='public-dashboard')
         button#public-access.button_base=`${data.AccessWithoutRegistration}`
diff --git a/src/scripts/coopstarter.js b/src/scripts/coopstarter.js
index 6fa6facf..0d737871 100644
--- a/src/scripts/coopstarter.js
+++ b/src/scripts/coopstarter.js
@@ -99,9 +99,12 @@ async function refreshList(formId, listId) {
   let form = document.getElementById(formId);
   form.addEventListener("save", async function() {
     let list = document.getElementById(listId);
-    let listProxy = await list.component.resource
-    listProxy.clearCache();
-    list.dataset.src = list.dataset.src;
+
+    if (list) {
+      let listProxy = await list.component.resource
+      listProxy.clearCache();
+      list.dataset.src = list.dataset.src;
+    }
   });
 }
 
@@ -200,8 +203,10 @@ function selectHiddenManagementForType(tab, form) {
 
       //Trigerring a reload of the associated form
       let parent_form = select_hidden.closest("sib-form");
-      parent_form.component.inputChange();
-      refreshPagination();
+      if (parent_form) {
+        parent_form.component.inputChange();
+        refreshPagination();
+      }
     });
   }
 }
@@ -659,7 +664,6 @@ jQuery(document).ready(function($) {
     submitInput.disabled = true;
     submitInput.classList.add('disabled');
     let inputs = mentorResourceCreationForm.querySelectorAll('input[type="text"]' + ',select' + ',textarea');
-    console.log(inputs);
     inputs.forEach(function(input) {
       input.addEventListener('focusout', (() => {
         listenToInputChangeOnResourceCreation(mentorResourceCreationForm);
@@ -675,9 +679,7 @@ jQuery(document).ready(function($) {
     let submitInput = mentorResourceEditionForm.querySelectorAll('input[type=submit]')[0];
     submitInput.disabled = true;
     submitInput.classList.add('disabled');
-    console.log(submitInput);
     let inputs = mentorResourceEditionForm.querySelectorAll('input[type="text"]' + ',select' + ',textarea');
-    console.log(inputs);
     inputs.forEach(function(input) {
       input.addEventListener('focusout', (() => {
         listenToInputChangeOnResourceCreation(mentorResourceEditionForm);
@@ -713,41 +715,41 @@ jQuery(document).ready(function($) {
   document.getElementById("defaultOpen").click();
 
   //Retrieve the current user
-  let userAccountDataSrc = document.getElementById("user_account_picture");
+  let mentorAccountDataSrc = document.getElementById("mentor_account_picture");
 
-  if (userAccountDataSrc) {
+  if (mentorAccountDataSrc) {
     //Add the current user as reviewer.
-    linkDatasetToField(userAccountDataSrc, "validation_form", "reviewer");
-    linkDatasetToField(userAccountDataSrc, "improvement_dialog_form", "reviewer");
-    linkDatasetToField(userAccountDataSrc, "refusal_dialog_form", "reviewer");
-    linkDatasetToField(userAccountDataSrc, "change_status_request", "reviewer");
+    linkDatasetToField(mentorAccountDataSrc, "validation_form", "reviewer");
+    linkDatasetToField(mentorAccountDataSrc, "improvement_dialog_form", "reviewer");
+    linkDatasetToField(mentorAccountDataSrc, "refusal_dialog_form", "reviewer");
+    linkDatasetToField(mentorAccountDataSrc, "change_status_request", "reviewer");
     // linkDatasetToField(userAccountDataSrc, "add-like", "sender");
     // linkDatasetToField(userAccountDataSrc, "add-dislike", "sender");
   }
 
-  //On form submission, we sometime have to refresh a list.
+  //On form submission, we sometimes have to refresh a list.
   refreshList("resource_creation_form", "resources_history");
   refreshList("validation_form", "pending_resources");
   refreshList("refusal_dialog_form", "pending_resources");
   refreshList("improvement_dialog_form", "pending_resources");
+  initFileUpload("entrepreneur_profile_creation", "account.picture");
   refreshList("entrepreneur_profile_creation", "entrepreneur_info");
   refreshList("entrepreneur_profile_creation", "entrepreneur_contact");
   refreshList("entrepreneur_profile_creation", "entrepreneur_account_picture");
-  initFileUpload("entrepreneur_profile_creation", "account.picture");
+  initFileUpload("mentor_profile_creation", "account.picture");
   refreshList("mentor_profile_creation", "mentor_info");
   refreshList("mentor_profile_creation", "mentor_complementary");
   refreshList("mentor_profile_creation", "mentor_contact");
-  refreshList("mentor_profile_creation", "user_account_picture");
-  initFileUpload("mentor_profile_creation", "account.picture");
+  refreshList("mentor_profile_creation", "mentor_account_picture");
+  initFileUpload("entrepreneur_profile_edition", "account.picture");
   refreshList("entrepreneur_profile_edition", "entrepreneur_info");
   refreshList("entrepreneur_profile_edition", "entrepreneur_contact");
   refreshList("entrepreneur_profile_edition", "entrepreneur_account_picture");
-  initFileUpload("entrepreneur_profile_edition", "account.picture");
+  initFileUpload("mentor_profile_edition", "account.picture");
   refreshList("mentor_profile_edition", "mentor_info");
   refreshList("mentor_profile_edition", "mentor_complementary");
   refreshList("mentor_profile_edition", "mentor_contact");
-  refreshList("mentor_profile_edition", "user_account_picture");
-  initFileUpload("mentor_profile_edition", "account.picture");
+  refreshList("mentor_profile_edition", "mentor_account_picture");
   refreshList("change_status_request", "request_list");
 
   addProperFilterToSearchComponents("entrepreneur-resource-list");
@@ -788,7 +790,7 @@ jQuery(document).ready(function($) {
     //Manage the form to report broken link.
     let detailsContributor = document.getElementById("detail-mentor");
     detailsContributor.addEventListener("populate", event => {
-      var userWhoSubmitReport =  userAccountDataSrc.dataset.src
+      var userWhoSubmitReport =  mentorAccountDataSrc.dataset.src
       var formBrokenLink = document.getElementById("report-broken-link-mentor");
       fillReportBrokenLinkForm(event, userWhoSubmitReport, formBrokenLink);
 
@@ -851,12 +853,15 @@ jQuery(document).ready(function($) {
         );
       });
     };
-    
+
+    //Retrieve the current user
+    let searcherAccountDataSrc = document.getElementById("entrepreneur_account_picture");
+
     //Manage the form to report broken link.
     let detailsSearcher = document.getElementById("detail-entrepreneur");
     detailsSearcher.addEventListener("populate", event => {
       var formBrokenLink = document.getElementById("report-broken-link-entrepreneur");
-      var userWhoSubmitReport =  userAccountDataSrc.dataset.src
+      var userWhoSubmitReport =  searcherAccountDataSrc.dataset.src
       fillReportBrokenLinkForm(event, userWhoSubmitReport, formBrokenLink);
     });
 
diff --git a/src/scripts/dispatch-space-n-user.js b/src/scripts/dispatch-space-n-user.js
index 4af132f5..f4ccae84 100644
--- a/src/scripts/dispatch-space-n-user.js
+++ b/src/scripts/dispatch-space-n-user.js
@@ -23,7 +23,7 @@ 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();
+    kldb_login.onclick = () => this.triggerLogin();
     this.update();
   }
 
@@ -46,21 +46,24 @@ class CoopStarterLoginComponent extends HTMLElement {
       .replace(/^@/, '');
   }
 
-  
   async update() {
     let loader = document.getElementById('main-loader');
     loader.removeAttribute('hidden');
     let user = await sibAuth.getUser();
+    if (!user) {
+      loader.toggleAttribute('hidden', true);
+      return;
+    }
 
-    //Set a userprefix default status
+    // console.log("Users get from the store", user);
+    // Set a userprefix default status
     var userPrefix = "public"
     
     // Idenfify the space we should go
     if (user) {
       await store.initGraph(user['@id'], context);
       let userFromStore = await store.get(user['@id']);
-      
-      //If the user is a mentor or an entreprenur, change user prefix
+      // If the user is a mentor or an entreprenur, change user prefix
       if(userFromStore) {
         let is_mentor = await userFromStore.mentor_profile;
         let is_entrepreneur = await userFromStore.entrepreneur_profile;
@@ -72,11 +75,11 @@ class CoopStarterLoginComponent extends HTMLElement {
       }
     }
 
-    //If the url asked pointed to a resource
+    // If the url asked pointed to a resource
     if (window.location.href.indexOf('resource-detail') > -1) {
       var newUrl = window.location.href.replace(/\/([a-z]+)-dashboard\/([a-z]+)-resource-detail/, `/${userPrefix}-dashboard/${userPrefix}-resource-detail`)
 
-      //If the url is different after the treatment, we reload with the good url
+      // If the url is different after the treatment, we reload with the good url
       if (newUrl !== window.location.href) {
         var newRoute = new URL(newUrl).pathname.replace(/^\/([a-z]{2})\//, "");
         window.dispatchEvent(
@@ -93,26 +96,26 @@ class CoopStarterLoginComponent extends HTMLElement {
         loader.toggleAttribute('hidden', true);
       }
     } else {
-      //User is a mentor
+      // User is a mentor
       if (userPrefix === "mentor") {
         window.dispatchEvent(
             new CustomEvent('requestNavigation', { detail: { route: 'mentor-dashboard' } })
           );
-      //User is a entrepreneur
+      // User is a entrepreneur
       } else if (userPrefix === "entrepreneur") {
         window.dispatchEvent(
           new CustomEvent('requestNavigation', { detail: { route: 'entrepreneur-dashboard' } })
         );
       } else if(user) {
+        loader.toggleAttribute('hidden', true);
         window.dispatchEvent(
           new CustomEvent('requestNavigation', { detail: { route: 'account-creation' } })
         );
-        loader.toggleAttribute('hidden', true);
-      } else {        
+      } else {
+        loader.toggleAttribute('hidden', true);   
         window.dispatchEvent(
           new CustomEvent('requestNavigation', { detail: { route: 'splash' } })
         );
-        loader.toggleAttribute('hidden', true);
       }
     }
   }
-- 
GitLab


From fd93ccd77aa12d043e8447470e22d51ac887116f Mon Sep 17 00:00:00 2001
From: Benoit Alessandroni <benoit@happy-dev.fr>
Date: Sun, 19 Apr 2020 17:19:22 +0200
Subject: [PATCH 2/3] Switch to last version of sib(auth

---
 src/includes/head.pug | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/includes/head.pug b/src/includes/head.pug
index 97f16314..957e4f5a 100644
--- a/src/includes/head.pug
+++ b/src/includes/head.pug
@@ -4,8 +4,11 @@ head
     script(src="https://unpkg.com/@webcomponents/webcomponentsjs@1.2.7/webcomponents-loader.js")
     //- script(type="module" src="/scripts/sib-core/dist/index.js")
     script(type="module" src="https://unpkg.com/@startinblox/core@0.9")
+    //- script(type="module" src="/scripts/sib-auth/index.js")
+    //- script(type="module" src="https://unpkg.com/@startinblox/core@beta")
+    //- script(type="module" src="/scripts/sib-router/src/index.js")
     script(type="module" src="https://unpkg.com/@startinblox/router@0.7")
-    script(type="module" src="https://unpkg.com/@startinblox/oidc@0.8.4")
+    script(type="module" src="https://unpkg.com/@startinblox/oidc@0.8")
     script(type="module" src="https://unpkg.com/@startinblox/component-conversation@0.4")
     script(src="https://kit.fontawesome.com/48014d2af3.js")
     script(src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous")
-- 
GitLab


From 38eb5936dd44814928df4ba14392f6658a8a80ed Mon Sep 17 00:00:00 2001
From: Benoit Alessandroni <benoit@happy-dev.fr>
Date: Tue, 28 Apr 2020 11:07:58 +0200
Subject: [PATCH 3/3] Fix store collision by updating oidc version

---
 src/includes/head.pug | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/includes/head.pug b/src/includes/head.pug
index 163b6579..73072a18 100644
--- a/src/includes/head.pug
+++ b/src/includes/head.pug
@@ -6,7 +6,7 @@ head
     script(type="module" src="https://unpkg.com/@startinblox/core@0.9.27")
     script(type="module" src="https://unpkg.com/@startinblox/router@0.7")
     //- script(type="module" src="/scripts/sib-auth/index.js")
-    script(type="module" src="https://unpkg.com/@startinblox/oidc@0.8.4")
+    script(type="module" src="https://unpkg.com/@startinblox/oidc@0.8")
     script(type="module" src="https://unpkg.com/@startinblox/component-conversation@0.4")
     script(src="https://kit.fontawesome.com/48014d2af3.js")
     script(src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous")
-- 
GitLab