From 71a3bb77dacb98301e95b89bd8d5251c7aa1a6b4 Mon Sep 17 00:00:00 2001 From: Alix Jaugey <jaugey.alix@gmail.com> Date: Thu, 21 Mar 2024 16:40:27 +0100 Subject: [PATCH 1/2] Refactor relative path logic in Utils.js and login.html/signing.html/index.html --- FRONT/index.html | 27 +++++---------------------- FRONT/js/model/Utils.js | 22 ++++------------------ FRONT/visual/pages/login.html | 25 ++++--------------------- FRONT/visual/pages/signedList.html | 25 ++++--------------------- FRONT/visual/pages/signing.html | 25 ++++--------------------- 5 files changed, 21 insertions(+), 103 deletions(-) diff --git a/FRONT/index.html b/FRONT/index.html index bb03053..5122ffe 100644 --- a/FRONT/index.html +++ b/FRONT/index.html @@ -88,37 +88,20 @@ <h1 id="title" class="center fullcaps">Documents</h1> <script> // if path end with /, we remove it if (window.location.pathname.endsWith('/')) window.location.pathname = window.location.pathname.slice(0, -1); - + // get the path of the current page (without the domain name) - let path = window.location.pathname; - - // replace the '/posign' because the website is in a folder called 'posign' - path = path.replace('/posign', ''); - path = path.replace('/FRONT', ''); - - // split the path into an array of strings - const pathArray = path.split('/'); - let relativePath = ''; - - // depending on the path, we set the relative path to the root of the website or to the 'posign' folder - if (path == '') relativePath = 'posign/'; - else relativePath = './'; - - // for each element in the array, we add a '../' to the relative path to go to the root of the website - for (let i = 0; i < pathArray.length - 2; i++) - relativePath += '../'; - + const path = `/${window.location.pathname.split('/')[1]}/`; // we add the main.js and Utils.js scripts to the head of the document // they will load the other scripts, styles and the page content - let script = document.createElement('script'); - script.src = relativePath + 'js/model/Utils.js'; + const script = document.createElement('script'); + script.src = path + 'js/model/Utils.js'; document.querySelector('head').appendChild(script); // when the Utils.js script is loaded, we load the main.js script (which will load the other scripts and the page content through the Utils.js script) script.onload = () => { let script = document.createElement('script'); - script.src = relativePath + 'js/main.js'; + script.src = path + 'js/main.js'; document.querySelector('head').appendChild(script); } diff --git a/FRONT/js/model/Utils.js b/FRONT/js/model/Utils.js index d3e73ba..83d5dcc 100644 --- a/FRONT/js/model/Utils.js +++ b/FRONT/js/model/Utils.js @@ -63,25 +63,11 @@ class Utils { * @returns {string} The relative path to the root of the website */ static getRelativePathToRoot() { + // if path end with /, we remove it + if (window.location.pathname.endsWith('/')) window.location.pathname = window.location.pathname.slice(0, -1); + // get the path of the current page (without the domain name) - let path = window.location.pathname; - - // replace the '/posign' because the website is in a folder called 'posign' - path = path.replace('/posign', ''); - path = path.replace('/front', ''); - - // split the path into an array of strings - const pathArray = path.split('/'); - let relativePath = ''; - - if (path == '') relativePath = 'posign/'; - else relativePath = './'; - - // for each element in the array, we add a '../' to the relative path to go to the root of the website - for (let i = 0; i < pathArray.length - 2; i++) { - relativePath += '../'; - } - return relativePath; + return `/${window.location.pathname.split('/')[1]}/`; } /** diff --git a/FRONT/visual/pages/login.html b/FRONT/visual/pages/login.html index 677312b..08a1780 100644 --- a/FRONT/visual/pages/login.html +++ b/FRONT/visual/pages/login.html @@ -66,35 +66,18 @@ <h2 class="smallcaps">Connexion</h2> if (window.location.pathname.endsWith('/')) window.location.pathname = window.location.pathname.slice(0, -1); // get the path of the current page (without the domain name) - let path = window.location.pathname; - - // replace the '/posign' because the website is in a folder called 'posign' - path = path.replace('/posign', ''); - path = path.replace('/FRONT', ''); - - // split the path into an array of strings - const pathArray = path.split('/'); - let relativePath = ''; - - // depending on the path, we set the relative path to the root of the website or to the 'posign' folder - if (path == '') relativePath = 'posign/'; - else relativePath = './'; - - // for each element in the array, we add a '../' to the relative path to go to the root of the website - for (let i = 0; i < pathArray.length - 2; i++) - relativePath += '../'; - + const path = `/${window.location.pathname.split('/')[1]}/`; // we add the main.js and Utils.js scripts to the head of the document // they will load the other scripts, styles and the page content - let script = document.createElement('script'); - script.src = relativePath + 'js/model/Utils.js'; + const script = document.createElement('script'); + script.src = path + 'js/model/Utils.js'; document.querySelector('head').appendChild(script); // when the Utils.js script is loaded, we load the main.js script (which will load the other scripts and the page content through the Utils.js script) script.onload = () => { let script = document.createElement('script'); - script.src = relativePath + 'js/main.js'; + script.src = path + 'js/main.js'; document.querySelector('head').appendChild(script); } diff --git a/FRONT/visual/pages/signedList.html b/FRONT/visual/pages/signedList.html index 2c325d0..891b068 100644 --- a/FRONT/visual/pages/signedList.html +++ b/FRONT/visual/pages/signedList.html @@ -68,35 +68,18 @@ <h3 id="no-signing" class="disabled">Aucune personne n'a signé ce document pour if (window.location.pathname.endsWith('/')) window.location.pathname = window.location.pathname.slice(0, -1); // get the path of the current page (without the domain name) - let path = window.location.pathname; - - // replace the '/posign' because the website is in a folder called 'posign' - path = path.replace('/posign', ''); - path = path.replace('/FRONT', ''); - - // split the path into an array of strings - const pathArray = path.split('/'); - let relativePath = ''; - - // depending on the path, we set the relative path to the root of the website or to the 'posign' folder - if (path == '') relativePath = 'posign/'; - else relativePath = './'; - - // for each element in the array, we add a '../' to the relative path to go to the root of the website - for (let i = 0; i < pathArray.length - 2; i++) - relativePath += '../'; - + const path = `/${window.location.pathname.split('/')[1]}/`; // we add the main.js and Utils.js scripts to the head of the document // they will load the other scripts, styles and the page content - let script = document.createElement('script'); - script.src = relativePath + 'js/model/Utils.js'; + const script = document.createElement('script'); + script.src = path + 'js/model/Utils.js'; document.querySelector('head').appendChild(script); // when the Utils.js script is loaded, we load the main.js script (which will load the other scripts and the page content through the Utils.js script) script.onload = () => { let script = document.createElement('script'); - script.src = relativePath + 'js/main.js'; + script.src = path + 'js/main.js'; document.querySelector('head').appendChild(script); } diff --git a/FRONT/visual/pages/signing.html b/FRONT/visual/pages/signing.html index 21bc266..fec23a6 100644 --- a/FRONT/visual/pages/signing.html +++ b/FRONT/visual/pages/signing.html @@ -77,35 +77,18 @@ <h2 id="doc-title" class="smallcaps">[NOM DOC]</h2> if (window.location.pathname.endsWith('/')) window.location.pathname = window.location.pathname.slice(0, -1); // get the path of the current page (without the domain name) - let path = window.location.pathname; - - // replace the '/posign' because the website is in a folder called 'posign' - path = path.replace('/posign', ''); - path = path.replace('/FRONT', ''); - - // split the path into an array of strings - const pathArray = path.split('/'); - let relativePath = ''; - - // depending on the path, we set the relative path to the root of the website or to the 'posign' folder - if (path == '') relativePath = 'posign/'; - else relativePath = './'; - - // for each element in the array, we add a '../' to the relative path to go to the root of the website - for (let i = 0; i < pathArray.length - 2; i++) - relativePath += '../'; - + const path = `/${window.location.pathname.split('/')[1]}/`; // we add the main.js and Utils.js scripts to the head of the document // they will load the other scripts, styles and the page content - let script = document.createElement('script'); - script.src = relativePath + 'js/model/Utils.js'; + const script = document.createElement('script'); + script.src = path + 'js/model/Utils.js'; document.querySelector('head').appendChild(script); // when the Utils.js script is loaded, we load the main.js script (which will load the other scripts and the page content through the Utils.js script) script.onload = () => { let script = document.createElement('script'); - script.src = relativePath + 'js/main.js'; + script.src = path + 'js/main.js'; document.querySelector('head').appendChild(script); } From 73a0e44e1e649edf812afabe76eedf07e61491c4 Mon Sep 17 00:00:00 2001 From: Alix Jaugey <jaugey.alix@gmail.com> Date: Thu, 21 Mar 2024 16:41:22 +0100 Subject: [PATCH 2/2] Sort users by the size of docs_waiting --- FRONT/js/view/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/FRONT/js/view/index.js b/FRONT/js/view/index.js index 88f2096..4891a06 100644 --- a/FRONT/js/view/index.js +++ b/FRONT/js/view/index.js @@ -272,6 +272,9 @@ class IndexView extends View { } } + // order by the biggest size of docs_waiting + users.sort((a, b) => b.docs_waiting.length - a.docs_waiting.length); + // add the users to the container await this.userTemplateManager.addUsers(users); }