From 58d659d44a460df8a632a5c9348d560e3bd1b723 Mon Sep 17 00:00:00 2001 From: mms37 Date: Thu, 16 Jun 2022 15:36:55 -0700 Subject: [PATCH] delete student --- data.db | 5 ++--- public/index.html | 27 ++++++++++++++++++++++++- public/script.js | 51 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 5 deletions(-) diff --git a/data.db b/data.db index 24a6209..c333cdd 100644 --- a/data.db +++ b/data.db @@ -1,3 +1,2 @@ -{"name":"three","weight":"50","height":"200","hairColour":"black","gpa":"3","_id":"a84IEbquFHLCK8Zj"} -{"name":"two","weight":"60","height":"20","hairColour":"black","gpa":"3","_id":"kY56cQascxWJyh7A"} -{"name":"four","weight":"50","height":"200","hairColour":"black","gpa":"3","_id":"wIVpbISz0AOSrmmy"} +{"name":"n0","weight":"5","height":"5","hairColour":"red","gpa":"0","_id":"C7MLNJ6FdWLGty5T"} +{"name":"n1","weight":"77","height":"190","hairColour":"brown","gpa":"1","_id":"EZ5eUBQmH2I1bUov"} diff --git a/public/index.html b/public/index.html index cc84677..7b4c4f9 100644 --- a/public/index.html +++ b/public/index.html @@ -4,7 +4,14 @@ - +
+
+ + + + +
+

students

@@ -19,5 +26,23 @@
+ + + + + + + + + + + + + + + +
nameweightheighthair colourgpa
+ + \ No newline at end of file diff --git a/public/script.js b/public/script.js index 76d2048..94c614f 100644 --- a/public/script.js +++ b/public/script.js @@ -1,9 +1,11 @@ window.onload=function(){ addForm=document.getElementById("add"); addForm.style.display="none"; + table=document.getElementById("studentInfo"); +table.style.display="none" + displayStudents(); } - function addStudent(){ console.log("add student"); form=document.getElementById("add"); @@ -20,5 +22,52 @@ function addData(){ var option={method:"POST", body: JSON.stringify(data), headers:{'Content-Type':'application/json'}}; console.log(option); fetch('/student', option); +} + +async function displayStudents(){ + var response=await fetch('/student'); + var students=await response.json(); + for (s of students){ + var student=document.createElement('div'); + student.className="displayDiv"; + student.style.display="inline-block"; + student.style.textAlign="center"; + student.style.margin="20px"; + student.innerText=s.name+"\n"+s.gpa; + student.style.height=parseInt(s.height)+"px"; + student.style.width=parseInt(s.weight)+"px"; + student.style.overflow="auto"; + student.style.padding="20px"; + student.style.color=s.hairColour; + student.style.border="1px solid black"; + + student.addEventListener("mouseenter", function(event){ +table.style.display="table"; + var info=event.target.innerText; + list=info.split("\n"); + document.getElementById("sName").innerHTML=list[0]; + document.getElementById("sWeight").innerHTML=event.target.offsetWidth; + document.getElementById("sHeight").innerHTML=event.target.offsetHeight; + document.getElementById("sHairColour").innerHTML=event.target.style.color; + document.getElementById("sGpa").innerHTML=list[1]; + }) + document.body.appendChild(student); + } +} + + function deleteData() { + console.log("in delete") +var name=document.getElementById("findName").value; +var data={name}; +var option={ + method:'DELETE', + body: JSON.stringify(data), + headers:{ + 'Content-Type':'application/json' + } +} +console.log(option) + fetch('/student', option); +//window.location.reload(); } \ No newline at end of file