From c596846a6cbf969572b9e53c05b1a46b49cee4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ha=C3=AFssous?= Date: Sun, 26 Mar 2023 15:03:06 +0200 Subject: [PATCH] waw les formations trop belles --- components/search.riot | 56 ++++++++++++++++++++++------------ components/testformation.riot | 52 +++++++++++++++++++++++++++++++ index.html | 6 ++-- javascript/controllerSearch.js | 31 ------------------- javascript/modelSearch.js | 21 ------------- javascript/viewSearch.js | 51 ------------------------------- 6 files changed, 93 insertions(+), 124 deletions(-) create mode 100644 components/testformation.riot delete mode 100644 javascript/controllerSearch.js delete mode 100644 javascript/modelSearch.js delete mode 100644 javascript/viewSearch.js diff --git a/components/search.riot b/components/search.riot index 3f734d2..cab63af 100644 --- a/components/search.riot +++ b/components/search.riot @@ -1,32 +1,50 @@ - \ No newline at end of file diff --git a/components/testformation.riot b/components/testformation.riot new file mode 100644 index 0000000..d4eec3e --- /dev/null +++ b/components/testformation.riot @@ -0,0 +1,52 @@ + + + + + + + + + +
+ + +
\ No newline at end of file diff --git a/index.html b/index.html index cb2fe7c..a269569 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ Parcoursup - + @@ -14,7 +14,9 @@ diff --git a/javascript/controllerSearch.js b/javascript/controllerSearch.js deleted file mode 100644 index 3788a29..0000000 --- a/javascript/controllerSearch.js +++ /dev/null @@ -1,31 +0,0 @@ -class Controller { - constructor(view,model){ - this.view = view - this.model = model - - this.loading = false - this.lastSearch = null - this.error = null - this.results = [] - - this.view.setLoading(false) - this.view.bindSearch(this.search.bind(this)) - } - reset() { - this.loading = false - this.error = null - this.results = [] - } - - async search(formation) { - this.model.getFormations(formation).then((response) => { - let table = response["facet groups"][0]["facets"] - this.view.renderList(table) - }).catch((error) => { - this.view.renderMessage(error) - }) - } -} - -export default Controller - diff --git a/javascript/modelSearch.js b/javascript/modelSearch.js deleted file mode 100644 index 4e78cb8..0000000 --- a/javascript/modelSearch.js +++ /dev/null @@ -1,21 +0,0 @@ -let model = { - getFormations(search) { - return new Promise((resolve, reject) => { - let xhr = new XMLHttpRequest() - xhr.open("GET", "/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&sort=tri&facet=fili&timezone=Europe%2FBerlin") - xhr.responseType = "json" - - xhr.onload = (ev) => { - if (xhr.status == 200) - resolve(xhr.response) - } - xhr.onerror = () => { - reject("error") - } - xhr.send() - }) - - } -} - -export default model \ No newline at end of file diff --git a/javascript/viewSearch.js b/javascript/viewSearch.js deleted file mode 100644 index 5b8043b..0000000 --- a/javascript/viewSearch.js +++ /dev/null @@ -1,51 +0,0 @@ -function debounce(fn, wait) { - let timeout - - return (...args) => { - clearTimeout(timeout) - timeout = setTimeout(() => fn(...args), wait) - } -} - -class View { - constructor(){ - this.listFormations = document.querySelector("#list-formations") - this.inputSearch = document.querySelector("input") - this.message = document.querySelector("p.error") - } - - _getInput(){ - return this.inputSearch.value - } - renderMessage(error){ - this.message.style.display = "block" - this.message.textContent = error - } - - renderList(formations){ - let ul = document.createElement("ul") - formations.forEach((formation)=>{ - let li = document.createElement("li") - let a = document.createElement("a") - let span = document.createElement("span") - //a.href = `test` - a.target="_blank" - a.textContent = formation.name - span.textContent = formation.name - - li.appendChild(a) - li.appendChild(span) - ul.appendChild(li) - }) - - this.listFormations.replaceChildren(ul) - } - - bindSearch(handler){ - this.inputSearch.addEventListener("input",debounce((e)=>{ - handler(this._getInput()) - },500)) - } -} - -export default View