From ab48753cba5ee0e3cd3cbdc8d657d569c2daef0f Mon Sep 17 00:00:00 2001 From: sinbad Date: Mon, 20 May 2024 15:32:04 +0200 Subject: [PATCH] =?UTF-8?q?Finished=20!!!!=20(Juste=20il=20faut=20tester?= =?UTF-8?q?=20quand=20un=20medecin=20n'a=20pas=20de=20cr=C3=A9neau=20car?= =?UTF-8?q?=20moi=20=C3=A7a=20me=20met=20un=20ancien=20code=20que=20j'ai?= =?UTF-8?q?=20supprim=C3=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/API/test/database.php | 15 +--- src/js/AJAX/home.js | 4 + src/js/AJAX/rdv-patient.js | 161 ++++++++++++++++++++--------------- src/js/AJAX/rdv-praticien.js | 9 +- 4 files changed, 106 insertions(+), 83 deletions(-) diff --git a/src/API/test/database.php b/src/API/test/database.php index fff740f..75fd92e 100644 --- a/src/API/test/database.php +++ b/src/API/test/database.php @@ -32,12 +32,7 @@ function dbRequestRdvPraticien($pdo, $id){ $statement->execute(); $result = $statement->fetchAll(PDO::FETCH_ASSOC); - if (!empty($result)) { - Response::HTTP200($result); - } else { - Response::HTTP404(["error" => "No data found"]); - } - + Response::HTTP200($result); } function dbRequestRdvPatient($pdo, $id){ @@ -56,15 +51,11 @@ function dbRequestRdvPatient($pdo, $id){ $statement->execute(); $result = $statement->fetchAll(PDO::FETCH_ASSOC); - if (!empty($result)) { - Response::HTTP200($result); - } else { - Response::HTTP404(["error" => "No data found"]); - } + Response::HTTP200($result); } function getPastRdvByPatient($pdo, $id){ - $statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty as med_spe, medecin.m_id as med_id, concat(p_name, ' ', p_surname) as patient, l_adress as adresse, concat(l_postal, ' ', l_city) as ville + $statement = $pdo->prepare("SELECT rdv_date, rdv_time, concat(m_name, ' ', m_surname) as medecin, medecin.m_specialty as med_spe, medecin.m_id, concat(p_name, ' ', p_surname) as patient, l_adress as adresse, concat(l_postal, ' ', l_city) as ville FROM rendez_vous INNER JOIN patient ON rendez_vous.p_id = patient.p_id INNER JOIN propose ON rendez_vous.rdv_id = propose.rdv_id diff --git a/src/js/AJAX/home.js b/src/js/AJAX/home.js index 2ce4fb1..b3a9fad 100644 --- a/src/js/AJAX/home.js +++ b/src/js/AJAX/home.js @@ -2,6 +2,8 @@ import {TokenDecode} from "./lib.js"; import {attachSearchEventListener, removeSearchTopBar} from "./search.js"; import {displayAlert} from "./alert.js"; import {attachLoginPraticienDisplayEventListener, attachLoginUserDisplayEventListener, attachDisconnectEventListener} from "./login.js"; +import {ButtonShowRdvPraticient} from "./rdv-praticien.js"; +import {ButtonShowRdvPatient} from "./rdv-patient.js"; console.log("home.js loaded"); function displayHomeTopBar() { @@ -137,6 +139,8 @@ function displayHome(text) { `; attachSearchEventListener(); attachLoginUserDisplayEventListener(); + ButtonShowRdvPraticient(); + ButtonShowRdvPatient(); if(text !== ""){ displayAlert(text); } diff --git a/src/js/AJAX/rdv-patient.js b/src/js/AJAX/rdv-patient.js index a0d98b1..e01e3e4 100644 --- a/src/js/AJAX/rdv-patient.js +++ b/src/js/AJAX/rdv-patient.js @@ -5,63 +5,7 @@ import {attachReturnHomeEventListener, attachProfileEventListener, horizontalDro function ButtonShowRdvPatient() { try { - document.getElementById("user-calendar").addEventListener("click", function () { - let content = document.getElementById("content"); - content.innerHTML = ""; - let h100 = document.createElement("div"); - h100.classList.add("h-100"); - let row = document.createElement("div"); - row.classList.add("row"); - let column = document.createElement("div"); - column.classList.add("col-3", "border-end", "border-dark", "border-3", "h-100", "mt-2", "text-center", "d-flex", "flex-column", "justify-content-center"); - let column2 =document.createElement("div"); - column2.classList.add("d-flex", "flex-column"); - let next_rdv = document.createElement("div"); - next_rdv.classList.add("border-bottom", "pb-3", "border-dark", "border-3", "align-self-center"); - - - - let nextRDV; - let past_rdv = document.createElement("div"); - let the_rdv = document.createElement("div"); - let searchbar = document.createElement("div") - let user = TokenDecode(sessionStorage.getItem("token")); - ajaxRequest('GET', "src/API/requests.php/api/next-rdv-patient?id=" + user.id, function (data) { - nextRDV = data - DisplayNextRDVPatient(next_rdv, data); - - past_rdv.classList.add("mt-3", "align-self-center", "d-flex", "flex-column", "gap-2"); - ajaxRequest('GET', "src/API/requests.php/api/past-rdv-patient?id=" + user.id, function (data) { - DisplayPastRDVPatient(past_rdv, data); - - the_rdv.classList.add("col", "border-end", "border-dark", "border-3", "h-100", "mt-2", "text-center", "d-flex", "flex-column", "justify-content-center"); - - DisplayRDV(the_rdv, nextRDV); - - searchbar.classList.add("col", "h-100"); - searchbar.innerHTML = ` -
- - - -
`; - - attachSearchEventListener(); - attachReturnHomeEventListener(); - attachProfileEventListener(); - horizontalDropdown(); - }); - }); - - column2.append(next_rdv) - column2.append(past_rdv) - column.append(column2) - row.append(column) - row.append(the_rdv) - row.append(searchbar) - h100.appendChild(row); - content.appendChild(h100); - }); + document.getElementById("user-calendar").addEventListener("click", DisplayRDVPatientPage); } catch (e) { //Do nothing @@ -69,10 +13,74 @@ function ButtonShowRdvPatient() { } } +function DisplayRDVPatientPage(){ + let content = document.getElementById("content"); + content.innerHTML = ""; + let h100 = document.createElement("div"); + h100.classList.add("h-100"); + let row = document.createElement("div"); + row.classList.add("row"); + let column = document.createElement("div"); + column.classList.add("col-3", "border-end", "border-dark", "border-3", "h-100", "mt-2", "text-center", "d-flex", "flex-column", "justify-content-center"); + let column2 =document.createElement("div"); + column2.classList.add("d-flex", "flex-column"); + let next_rdv = document.createElement("div"); + next_rdv.classList.add("border-bottom", "pb-3", "border-dark", "border-3", "align-self-center"); + + + + let nextRDV; + let past_rdv = document.createElement("div"); + let the_rdv = document.createElement("div"); + let searchbar = document.createElement("div") + let user = TokenDecode(sessionStorage.getItem("token")); + ajaxRequest('GET', "src/API/requests.php/api/next-rdv-patient?id=" + user.id, function (data) { + nextRDV = data + DisplayNextRDVPatient(next_rdv, data); + + past_rdv.classList.add("mt-3", "align-self-center", "d-flex", "flex-column", "gap-2"); + ajaxRequest('GET', "src/API/requests.php/api/past-rdv-patient?id=" + user.id, function (data) { + DisplayPastRDVPatient(past_rdv, data); + + the_rdv.classList.add("col", "border-end", "border-dark", "border-3", "h-100", "mt-2", "text-center", "d-flex", "flex-column", "justify-content-center"); + + DisplayRDV(the_rdv, nextRDV); + + searchbar.classList.add("col", "h-100"); + searchbar.innerHTML = ` +
+ + + +
`; + + attachSearchEventListener(); + attachReturnHomeEventListener(); + attachProfileEventListener(); + horizontalDropdown(); + }); + }); + + column2.append(next_rdv) + column2.append(past_rdv) + column.append(column2) + row.append(column) + row.append(the_rdv) + row.append(searchbar) + h100.appendChild(row); + content.appendChild(h100); +} + function DisplayNextRDVPatient(next_rdv, rdv){ next_rdv.innerHTML = "
Vos rendez-vous à venir
"; - if(rdv.length === 0){ - next_rdv.innerHTML += "

Vous n'avez pas de rendez-vous à venir

"; + if(rdv === null || rdv.length === 0){ + next_rdv.innerHTML += "
" + + "
" + + "
" + + "

" + + "
" + + "
Vous n'avez pas de rendez-vous à venir
" + + "
"; } else{ for(let i = 0; i < rdv.length; i++) { @@ -91,10 +99,8 @@ function DisplayNextRDVPatient(next_rdv, rdv){ } -function attachEventListener(i, rdv) { - document.getElementById("retake-rdv-" + i + "-" + rdv[i].m_id).addEventListener("click", function () { - console.log("Retake RDV") - let id = rdv[i].m_id; +function attachEventListener(i, id) { + document.getElementById("retake-rdv-" + i + "-" + id).addEventListener("click", function () { let today = new Date(); let date = today.getFullYear() + "-" + (today.getMonth() + 1).toString().padStart(2, "0") + "-" + today.getDate().toString().padStart(2, "0"); ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) { @@ -122,23 +128,31 @@ function DisplayPastRDVPatient(past_rdv, rdv) { "
" + " " + "
"; - attachEventListener(i, rdv); } - - } + for(let i = 0; i < rdv.length; i++) { + document.getElementById("retake-rdv-" + i + "-" + rdv[i].m_id).addEventListener("click", function () { + attachEventListener(i, rdv[i].m_id); + }); + } + } } function attachEventListenerDeplacer(rdv){ document.getElementById("deplacer_button").addEventListener("click", function () { let id = rdv[0].m_id; + let rdv_id = rdv[0].rdv_id; + let data = "id=" + rdv_id let today = new Date(); let date = today.getFullYear() + "-" + (today.getMonth() + 1).toString().padStart(2, "0") + "-" + today.getDate().toString().padStart(2, "0"); - ajaxRequest('DELETE', "src/API/requests.php/api/cancel-rdv-patient?id=" + id, function () { + console.log(data); + ajaxRequest('PUT', "src/API/requests.php/api/cancel-rdv-patient", function () { + console.log("Rendez-vous annulé"); ajaxRequest('GET', "src/API/requests.php/api/rdv-date?date=" + date + "&id=" + id, function (data) { displayCalendar(data); }); - }); + }, data); + }); } @@ -147,8 +161,9 @@ function attachEventListenerAnnuler(rdv){ let id = rdv[0].rdv_id; let data = "id=" + id console.log(data); - ajaxRequest('DELETE', "src/API/requests.php/api/cancel-rdv-patient", function (id) { + ajaxRequest('PUT', "src/API/requests.php/api/cancel-rdv-patient", function (id) { console.log("Rendez-vous annulé"); + DisplayRDVPatientPage(); },data); }); @@ -156,7 +171,13 @@ function attachEventListenerAnnuler(rdv){ function DisplayRDV(the_rdv, rdv){ if(rdv.length === 0){ - the_rdv.innerHTML = "

Vous n'avez pas de rendez-vous à venir

" + the_rdv.innerHTML = "
" + + "
" + + "
" + + "

" + + "
" + + "
Vous n'avez pas de rendez-vous à venir
" + + "
"; } else{ the_rdv.innerHTML += "
" + diff --git a/src/js/AJAX/rdv-praticien.js b/src/js/AJAX/rdv-praticien.js index 3ac7a73..bfff1fc 100644 --- a/src/js/AJAX/rdv-praticien.js +++ b/src/js/AJAX/rdv-praticien.js @@ -22,7 +22,14 @@ function DisplayRDVPraticient(rdv){ content.innerHTML = ""; content.innerHTML = '
'; if(count === 0){ - content.append('

Vous n\'avez pas de rendez-vous

'); + content.innerHTML += '
' + + '
' + + '
' + + '

' + + '
' + '
' + + '
' + + '
Vous n\'avez pas de rendez-vous de planifié
' + + '
' + '
'; } else { for (let i = 0; i < count; i++) {