From 8d79696ce0a20297db182d61a94e2072c537649b Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Fri, 7 Jan 2022 18:07:20 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=8E=A8=20Little=20improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjetProgWeb/app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ProjetProgWeb/app.js b/ProjetProgWeb/app.js index 4676e92..b2ed48b 100644 --- a/ProjetProgWeb/app.js +++ b/ProjetProgWeb/app.js @@ -95,7 +95,7 @@ window.addEventListener('scroll', fadeIn); function updatePageNumber(number) { pagesNumbers.childNodes.forEach(elem => { - if (elem.innerHTML == number) { + if (parseInt(elem.innerHTML) === number) { elem.style.fontWeight = "bold" elem.style.textDecoration = "underline" pagesNumbers.scrollLeft += elem.getBoundingClientRect().left - @@ -133,7 +133,6 @@ function displayResults(results, aCount) { error.classList.add("fade-in"); errorMessage.innerHTML = results.message pagesNumbersContainer.style.display = 'none' - return; } else if (results.status === 200) { count = aCount resultsArray = [] From a2d42aaa6124bc6f26201feec755a1bbcf939a17 Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Fri, 7 Jan 2022 18:07:45 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20error=20when=20searc?= =?UTF-8?q?h=20too=20short?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjetProgWeb/app.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ProjetProgWeb/app.js b/ProjetProgWeb/app.js index b2ed48b..033f232 100644 --- a/ProjetProgWeb/app.js +++ b/ProjetProgWeb/app.js @@ -72,7 +72,13 @@ function apiRequestThese(search, offset) { .then(data => { fetch(`api.php?q=count&search=${searchString}&option=${queryOption}&offset=0`) .then(response => response.json()) - .then(aCount => displayResults(data, aCount.data[0])) + .then(aCount => { + if (aCount.data) { + displayResults(data, aCount.data[0]) + } else { + displayResults(data, 0) + } + }) }) } else { alert('Veuillez attendre une seconde entre chaque recherche.') From 131a466b17cf61d59631515df217a2a52d27fb40 Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Fri, 7 Jan 2022 18:10:40 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=8E=A8=20Condensed=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjetProgWeb/app.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ProjetProgWeb/app.js b/ProjetProgWeb/app.js index 033f232..fc0c2a7 100644 --- a/ProjetProgWeb/app.js +++ b/ProjetProgWeb/app.js @@ -72,13 +72,7 @@ function apiRequestThese(search, offset) { .then(data => { fetch(`api.php?q=count&search=${searchString}&option=${queryOption}&offset=0`) .then(response => response.json()) - .then(aCount => { - if (aCount.data) { - displayResults(data, aCount.data[0]) - } else { - displayResults(data, 0) - } - }) + .then(aCount => displayResults(data, aCount.data ? aCount.data[0] : 0)) }) } else { alert('Veuillez attendre une seconde entre chaque recherche.') From 64e70c6c5ce75d68fd73466c25731f0c366bd04c Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Fri, 7 Jan 2022 18:22:44 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=8E=A8=20Little=20code=20cleaning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjetProgWeb/app.js | 11 ++++++----- ProjetProgWeb/scripts/extract.php | 12 ++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ProjetProgWeb/app.js b/ProjetProgWeb/app.js index fc0c2a7..fda3f58 100644 --- a/ProjetProgWeb/app.js +++ b/ProjetProgWeb/app.js @@ -26,7 +26,7 @@ let resultsCount = document.querySelector('#results-count') let filters = document.querySelectorAll('.filters p') function sanitize(chain) { - return chain.replace(/[^a-zA-Z0-9\- ]/g,'') + return chain.replace(/[^a-zA-Z0-9\- ]/g, '') } function showSuggestions() { @@ -162,7 +162,7 @@ function displayResults(results, aCount) { if (elem[14] === 'no') { onlineButton.disabled = true } else { - onlineButton.onclick = function() { + onlineButton.onclick = function () { window.open('https://www.theses.fr/' + elem[13] + '/document', ',_blank') } } @@ -179,7 +179,8 @@ function displayResults(results, aCount) { let pre_replacement = new RegExp(searchString, 'gi').exec(e) child.innerHTML = e.replace(pre_replacement, `${pre_replacement}`) content.appendChild(child) - } i += 1 + } + i += 1 }) header.addEventListener('click', () => { @@ -193,14 +194,14 @@ function displayResults(results, aCount) { let nb = document.createElement("p") nb.innerHTML = `Nombre de résultats en ${queryOption} pour "${searchString}": - ${new Intl.NumberFormat('fr-FR', { maximumSignificantDigits: 3 }).format(count)}.` + ${new Intl.NumberFormat('fr-FR', {maximumSignificantDigits: 3}).format(count)}.` resultsCount.appendChild(nb) loader.style.display = "none" nbPages = Math.ceil(count / RESULTS_NUMBER) - for (let i = 0 ; i < nbPages ; i++) { + for (let i = 0; i < nbPages; i++) { let number = document.createElement('p') number.innerHTML = i + 1 if (i === 0) diff --git a/ProjetProgWeb/scripts/extract.php b/ProjetProgWeb/scripts/extract.php index 0775a2f..206fadb 100644 --- a/ProjetProgWeb/scripts/extract.php +++ b/ProjetProgWeb/scripts/extract.php @@ -9,25 +9,29 @@ require_once('../class/dotEnv.php'); if (($handle = fopen(getenv('FILE'), "r")) !== FALSE) { + $dbname = getenv('DBNAME'); + $pdo_obj = new conf(); $pdo = $pdo_obj->getPDO(); - $stmt = $pdo->query("TRUNCATE `" . getenv('DBNAME') ."`.`theses`"); + $stmt = $pdo->prepare("TRUNCATE `:dbname`.`theses`"); + $stmt->bindParam(':dbname', $dbname); $row = 1; while (($data = fgetcsv($handle, 10000, ";")) !== FALSE) { $new_these = these::emptyThese(); $num = count($data); if ($row > 1) { - for ($c = 0 ; $c < $num ; $c++) { + for ($c = 0; $c < $num; $c++) { $new_these->insertField($data[$c], $c); } $dump = new dump($new_these); try { $dump->sendThese($pdo); } catch (Exception $e) { - echo "

Failed on " . $row ." ( " . $e->getMessage() . " ) :
"; + echo "

Failed on " . $row . " ( " . $e->getMessage() . " ) :
"; } - } $row++; + } + $row++; } fclose($handle); echo "

CSV file imported into DB. (" . $row . " results)"; From 780c465e2682957baa868ce477a35dff6991bd70 Mon Sep 17 00:00:00 2001 From: Florian Sylvain Date: Sat, 8 Jan 2022 15:10:52 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=94=A7=20Deployment=20now=20ignore=20?= =?UTF-8?q?.env=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deployment.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.idea/deployment.xml b/.idea/deployment.xml index 4458653..52e2038 100644 --- a/.idea/deployment.xml +++ b/.idea/deployment.xml @@ -1,6 +1,6 @@ - +