From 99b958590ee907da7a3a3fe4dc05363cd3f50736 Mon Sep 17 00:00:00 2001 From: MargaretEarnest Date: Sun, 13 Sep 2020 00:12:17 -0400 Subject: [PATCH 01/11] Simple starting form added with 3 fields --- public/index.html | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/public/index.html b/public/index.html index c56d620e..85e52b7e 100755 --- a/public/index.html +++ b/public/index.html @@ -1,13 +1,19 @@ - CS4241 Assignment 2 + Coronavirus Symtom Tracker 2.0 +

Make a new user

- - +
+

+
+

+
+

+
diff --git a/server.improved.js b/server.improved.js index 605cee26..0f3eb157 100644 --- a/server.improved.js +++ b/server.improved.js @@ -6,11 +6,7 @@ const http = require( 'http' ), dir = 'public/', port = 3000 -const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} -] +var appdata = [] const server = http.createServer( function( request,response ) { if( request.method === 'GET' ) { @@ -34,12 +30,18 @@ const handlePost = function( request, response ) { let dataString = '' request.on( 'data', function( data ) { - appdata.push({data}) - dataString += data + if(request.url == "/reset") { + // appdata.push('{"resetting" : "true"}') + appdata = [] + // appdata.push('{"resetting" : "true"}') + } else { + appdata.push(data) + } + // appdata.push('{"url" : "' + request.url + '"}') }) request.on( 'end', function() { - console.log( JSON.parse( dataString ) ) + // console.log( JSON.parse( dataString ) ) // ... do something with the data here!!! From ea08fc287a2303ba476f480c6de0ba81c77a4bf2 Mon Sep 17 00:00:00 2001 From: MargaretEarnest Date: Sun, 13 Sep 2020 02:30:32 -0400 Subject: [PATCH 04/11] Added ability to check if user is in database --- public/index.html | 51 +++++++++++++++++++++++++++++++++++++++++----- server.improved.js | 12 ++++++++++- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/public/index.html b/public/index.html index 5bc2d636..6b8be371 100755 --- a/public/index.html +++ b/public/index.html @@ -13,13 +13,21 @@

Make a new user






-
+


+

Update a Current User

+
+
+

+
+

+
+
diff --git a/server.improved.js b/server.improved.js index 0f3eb157..db8acb5b 100644 --- a/server.improved.js +++ b/server.improved.js @@ -34,8 +34,18 @@ const handlePost = function( request, response ) { // appdata.push('{"resetting" : "true"}') appdata = [] // appdata.push('{"resetting" : "true"}') - } else { + } else if (request.url == "/newUser") { appdata.push(data) + } else if (request.url == "/update") { + var match = false + for (const entry of appdata) { + var entryjson = JSON.parse(entry);//can access elements with .elementName + var datajson = JSON.parse(data); + if(entryjson.userName == datajson.userName && entryjson.userPassword == datajson.userPassword) { + match = true; + } + } + appdata.push('{"matching" : "' + match + '"}') } // appdata.push('{"url" : "' + request.url + '"}') }) From 0546c80d573f18abcc4f1e0e70e7c6a8f33ef4ff Mon Sep 17 00:00:00 2001 From: MargaretEarnest Date: Sun, 13 Sep 2020 03:02:25 -0400 Subject: [PATCH 05/11] Added symptom checkbox lists --- public/index.html | 80 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/public/index.html b/public/index.html index 6b8be371..6c74d373 100755 --- a/public/index.html +++ b/public/index.html @@ -8,22 +8,72 @@

Make a new user


-

+


-

+


-

+

+
+

+

Do you have any of the following symptoms on a regular basis?

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+




Update a Current User


-

+


-

+

+

Do you have any of the following symptoms today?

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+

+
+


+

Current Users

+

+ -

Make a new user

-
-
-

-
-

-
-

-
-

-

Do you have any of the following symptoms on a regular basis?

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

Update a Current User

-
-
-

-
-

-
-

-
-

-
-

-

Do you have any of the following symptoms today?

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-

-
-
-

Current Users

-

+

Coronavirus Symptom Tracker 2.0


+ +
+
+
+
+ + + + +


+ +

+
+ + + + + + + + + + + +
+
+

+

+


+ +
+
+
+
+ + + +
+
+ + +

+ +

+
+ + + + + + + + + + + +
+
+



+
+

+

Current Users

+


+

- diff --git a/public/js/scripts.js b/public/js/scripts.js index de052eae..7ca8dc97 100755 --- a/public/js/scripts.js +++ b/public/js/scripts.js @@ -1,3 +1,131 @@ -// Add some Javascript code here, to run on the front end. +const statusMessages = ["All clear", "Be cautious", "Covid19 risk"] + const newUser = function( e ) { + // prevent default form action from being carried out + e.preventDefault() + const json = { + userName: document.querySelector( '#userName' ).value, + userID: document.querySelector( '#userID' ).value, + userPassword: document.querySelector( '#userPassword' ).value, + userTemp: document.querySelector( '#userTemp' ).value, + userChills: document.querySelector( '#userChills' ).checked, + userCough: document.querySelector( '#userCough' ).checked, + userBreath: document.querySelector( '#userBreath' ).checked, + userThroat: document.querySelector( '#userThroat' ).checked, + userFatigue: document.querySelector( '#userFatigue' ).checked, + userHeadache: document.querySelector( '#userHeadache' ).checked, + userAche: document.querySelector( '#userAche' ).checked, + userNose: document.querySelector( '#userNose' ).checked, + userLoss: document.querySelector( '#userLoss' ).checked, + userNausea: document.querySelector( '#userNausea' ).checked, + userDiarrhea: document.querySelector( '#userDiarrhea' ).checked, + userStatus: 0 + }, + body = JSON.stringify( json ) + + fetch( '/newUser', { + method:'POST', + body + }) + .then( function( response ) { + // do something with the reponse + return response.text() + }) + .then( function( text ) { + var entries = text.split("},"); + console.log("Data:") + var tableText = ""; + for (const entry of entries) { + var entryjson = JSON.parse(entry+(entry.slice(-1) == "}" ? "" : "}")); + tableText += ""; + // console.log( entryjson );//can access elements with .elementName + } + document.getElementById("database").innerHTML = tableText + "
NameID NumberCovid19 Status
" + entryjson.userName + "" + entryjson.userID + "" + statusMessages[entryjson.userStatus] + "
"; + }) -console.log("Welcome to assignment 2!") \ No newline at end of file + return false + } + + const update = function( e ) { + // prevent default form action from being carried out + e.preventDefault() + const json = { + userName: document.querySelector( '#updateUserName' ).value, + userPassword: document.querySelector( '#updateUserPassword' ).value, + userTemp: document.querySelector( '#updateUserTemp' ).value, + userPositive: document.querySelector( '#updateUserPositive' ).checked, + userContact: document.querySelector( '#updateUserContact' ).checked, + userChills: document.querySelector( '#updateUserChills' ).checked, + userCough: document.querySelector( '#updateUserCough' ).checked, + userBreath: document.querySelector( '#updateUserBreath' ).checked, + userThroat: document.querySelector( '#updateUserThroat' ).checked, + userFatigue: document.querySelector( '#updateUserFatigue' ).checked, + userHeadache: document.querySelector( '#updateUserHeadache' ).checked, + userAche: document.querySelector( '#updateUserAche' ).checked, + userNose: document.querySelector( '#updateUserNose' ).checked, + userLoss: document.querySelector( '#updateUserLoss' ).checked, + userNausea: document.querySelector( '#updateUserNausea' ).checked, + userDiarrhea: document.querySelector( '#updateUserDiarrhea' ).checked + }, + body = JSON.stringify( json ) + + fetch( '/update', { + method:'POST', + body + }) + .then( function( response ) { + // do something with the reponse + return response.text() + }) + .then( function( text ) { + var entries = text.split("},"); + console.log("Data:") + var tableText = ""; + for (const entry of entries) { + // console.log(entry); + var entryjson = JSON.parse(entry+(entry.slice(-1) == "}" ? "" : "}")); + tableText += ""; + } + document.getElementById("database").innerHTML = tableText + "
NameID NumberCovid19 Status
" + entryjson.userName + "" + entryjson.userID + "" + statusMessages[entryjson.userStatus] + "
"; + }) + + return false + } + + const reset = function( e ) { + // prevent default form action from being carried out + e.preventDefault() + + fetch( '/reset', { + method:'POST', + body: "{}" + }) + .then( function( response ) { + // do something with the reponse + console.log("RESET") + document.getElementById("database").innerText = "Database cleared."; + }) + + return false + } + + window.onload = function() { + const newUserButton = document.querySelector( '#newUserButton' ) + newUserButton.onclick = newUser + const resetButton = document.querySelector( '#resetButton' ) + resetButton.onclick = reset + const updateButton = document.querySelector( '#updateButton' ) + updateButton.onclick = update + + var coll = document.getElementsByClassName("collapsible"); + for (var i = 0; i < coll.length; i++) { + coll[i].addEventListener("click", function() { + this.classList.toggle("active"); + var content = this.nextElementSibling; + if (content.style.display === "block") { + content.style.display = "none"; + } else { + content.style.display = "block"; + } + }); + } + } From 43161a3803bdae9a7225ca1f6e6a50a996a1de23 Mon Sep 17 00:00:00 2001 From: MargaretEarnest Date: Wed, 16 Sep 2020 21:06:16 -0400 Subject: [PATCH 08/11] Fixed validation errors --- public/css/style.css | 26 ++++++++++++++++++-------- public/index.html | 12 ++++++------ public/js/scripts.js | 1 + 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/public/css/style.css b/public/css/style.css index 15bd678f..03f25bef 100755 --- a/public/css/style.css +++ b/public/css/style.css @@ -4,12 +4,12 @@ body { font-family: 'PT Sans'; } -/* Style the button that is used to open and close the collapsible content */ +/* This collapsable code is based on the code found here, with changes to colors, padding, and text-align: https://www.w3schools.com/howto/howto_js_collapsible.asp */ .collapsible { background-color: #d3d3d3; color: #AC2B37; cursor: pointer; - padding: 18px; + padding: 40px 18px 40px 18px; width: 50%; border: none; text-align: center; @@ -19,12 +19,7 @@ body { margin:auto; } -/* Add a background color to the button if it is clicked on (add the .active class with JS), and when you move the mouse over it (hover) */ -.active, .collapsible:hover { - background-color: #A9B0B7; -} - -/* Style the collapsible content. Note: hidden by default */ +/* This code is also from the above tutorial, with changes to width, color, and padding: https://www.w3schools.com/howto/howto_js_collapsible.asp */ .content { color: black; display: none; @@ -35,6 +30,10 @@ body { margin: auto; } +.active, .collapsible:hover { + background-color: #A9B0B7; +} + .symptom { width: 100%; } @@ -79,6 +78,7 @@ td, th { text-align: left; } +/* This button is based on the CSS button tutorial here, with changes to color, display, and margin: https://www.w3schools.com/css/css3_buttons.asp */ button { background-color: #AC2B37; border: none; @@ -110,4 +110,14 @@ h1, h2 { #database { text-align: center; +} + +.largeTitle { + font-size: 1.7em; + font-weight: bold; +} + +.smallTitle { + font-size: 1.2em; + font-weight: bold; } \ No newline at end of file diff --git a/public/index.html b/public/index.html index df980105..0a1a6ad7 100755 --- a/public/index.html +++ b/public/index.html @@ -9,10 +9,10 @@

Coronavirus Symptom Tracker 2.0


- +

-
+


- +



- +

-
+

- +