diff --git a/ProjetProgWeb/app.js b/ProjetProgWeb/app.js
index 2cdc1f5..007d543 100644
--- a/ProjetProgWeb/app.js
+++ b/ProjetProgWeb/app.js
@@ -146,7 +146,8 @@ function displayResults(results) {
let qTitle = elem[2]
let title = document.createElement('p')
- title.innerText = qTitle
+ pre_replacement = new RegExp(searchString, 'gi').exec(qTitle)
+ title.innerHTML = qTitle.replace(pre_replacement, `${pre_replacement}`)
let firstElement = document.createElement('div')
firstElement.classList.add('result-element-header')
@@ -187,7 +188,7 @@ function displayResults(results) {
})
let nb = document.createElement("p")
- nb.innerHTML = `Nombre de résultats pour "${searchString}":
+ nb.innerHTML = `Nombre de résultats en ${queryOption} pour "${searchString}":
${new Intl.NumberFormat('fr-FR', { maximumSignificantDigits: 3 }).format(count)}.`
resultsCount.appendChild(nb)
@@ -245,21 +246,23 @@ function realTimeDisplay() {
fetch(`api.php?q=suggestion&search=${search}&option=${queryOption}`)
.then(response => response.json())
.then(results => {
- suggestions.innerHTML = ""
- if (!results.data.length) {
- hideSuggestions()
- } else if (document.activeElement === searchBar) {
- showSuggestions()
- }
- results.data.forEach(elem => {
- let name = document.createElement('p')
- name.innerHTML = elem
- name.addEventListener('click', () => {
- searchBar.value = elem
- apiRequestThese(elem)
+ if (results.data) {
+ suggestions.innerHTML = ""
+ if (!results.data.length) {
+ hideSuggestions()
+ } else if (document.activeElement === searchBar) {
+ showSuggestions()
+ }
+ results.data.forEach(elem => {
+ let name = document.createElement('p')
+ name.innerHTML = elem
+ name.addEventListener('click', () => {
+ searchBar.value = elem
+ apiRequestThese(elem)
+ })
+ suggestions.appendChild(name)
})
- suggestions.appendChild(name)
- })
+ }
})
}
}
@@ -325,7 +328,7 @@ document.addEventListener('click', e => {
toggleSwitch = e.target.firstElementChild
toggleSwitchParent = e.target
}
- if (toggleSwitch !== null) {
+ if (toggleSwitch !== null && toggleSwitchParent !== null) {
if (toggleSwitch.classList.contains('untoggle')) {
toggleSwitchParent.style.backgroundColor = '#FFF'
toggleSwitch.classList.replace('untoggle', 'toggle')
diff --git a/ProjetProgWeb/class/dump.php b/ProjetProgWeb/class/dump.php
index 4b43033..a6c4812 100644
--- a/ProjetProgWeb/class/dump.php
+++ b/ProjetProgWeb/class/dump.php
@@ -55,7 +55,7 @@ class dump {
return $theses_array;
}
- public static function getSuggestions(string $search, string $option) : array {
+ public static function getSuggestions(string $search, string $option) : ?array {
$array = [];
$search = '%' . $search . '%';
@@ -63,7 +63,17 @@ class dump {
$pdo_obj = new conf();
$pdo = $pdo_obj->getPDO();
- $stmt = $pdo->prepare("SELECT DISTINCT author FROM theses WHERE author LIKE :search LIMIT 10;");
+ if ($option == 'auto') {
+ return null;
+ }
+
+ $stmt = match ($option) {
+ 'author' => $pdo->prepare("SELECT DISTINCT author FROM theses WHERE author LIKE :search LIMIT 10;"),
+ 'title' => $pdo->prepare("SELECT DISTINCT title FROM theses WHERE title LIKE :search LIMIT 5;"),
+ 'director' => $pdo->prepare("SELECT DISTINCT these_director FROM theses WHERE these_director LIKE :search LIMIT 10;"),
+ 'establishment' => $pdo->prepare("SELECT DISTINCT soutenance_establishment FROM theses WHERE soutenance_establishment LIKE :search LIMIT 10;"),
+ default => "",
+ };
$stmt->bindParam(':search', $search, PDO::PARAM_STR, 100);
$stmt->execute();
diff --git a/ProjetProgWeb/navbar.php b/ProjetProgWeb/navbar.php
index e922daa..920e0ad 100644
--- a/ProjetProgWeb/navbar.php
+++ b/ProjetProgWeb/navbar.php
@@ -7,7 +7,7 @@