From de42c831ca2284786496c62df69972d0d7e34232 Mon Sep 17 00:00:00 2001 From: Ngoodman <112005039+poz123@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:02:04 -0400 Subject: [PATCH 1/6] Update style.css --- public/css/style.css | 52 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/public/css/style.css b/public/css/style.css index d5f842a..16987d0 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -1 +1,51 @@ -/*Style your own assignment! This is fun! */ \ No newline at end of file +/*Style your own assignment! This is fun! */ +body{ + background-color: #D3D3D3; + font-family: "Antonio",sans-serif; +} +.res{ + margin: auto; + width: 50%; + + padding: 10px; +} +p{ + color:#2F4F4F +} +table, th, td { + background-color:lightgray; + + table-layout: auto; + width: 180px; +} + + +.flex { + margin-right:auto; + margin-left:auto; + + +} +.pm { + text-align: center; + +} +button:hover{ + background-color:green +} +#submitButton { + background-color: #2F4F4F; + border-radius: 5px; + color: white; + padding: 10px 16px; + text-align: center; + display: inline-block; + font-size: 11px; + margin-left:50%; + + + +} +#submitButton:hover{ + background-color:black +} From 037e18f01871632578d424e42c44e54c2e3e2af9 Mon Sep 17 00:00:00 2001 From: Ngoodman <112005039+poz123@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:02:45 -0400 Subject: [PATCH 2/6] Update scripts.js --- public/js/scripts.js | 71 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/public/js/scripts.js b/public/js/scripts.js index de052ea..9ce195f 100644 --- a/public/js/scripts.js +++ b/public/js/scripts.js @@ -1,3 +1,72 @@ // Add some Javascript code here, to run on the front end. +const submit = function (e) { +let d1 = document.getElementById("data1").value; +let d2 = document.getElementById("data2").value; +let d3 = document.getElementById("data3").value; + let json = { + data: d1, + data2: d2, + data3: d3, + init:"", + + } + let body = JSON.stringify(json) + fetch( '/submit', { + method:'POST', + body + }) + .then( async function ( response ) { + let tData = await response.json() + makeTable(tData) + console.log( tData ) + }) + return false +} + function makeTable(tData){ + const table = document.getElementById("table") + table.innerHTML = "
" + table.innerHTML = "firstmiddlelastinitials" + + tData.forEach((element, i)=>{ + table.innerHTML += + + " " + element.data + "" + + element.data2 + "" + + element.data3 + "" + + element.init + "" + + "" + + + }) + table.innerHTML+= "
" + return false + } + function deleteRow( ind) { + + console.log(ind) + let json = { + index: ind + } + let body = JSON.stringify(json) + fetch( '/delete', { + method:'POST', + body + }) + .then( async function ( response ) { + let dData = await response.json() + makeTable(dData) + console.log( dData ) + }) + + +} + + + window.onload = function () { + const button = document.getElementById("submitButton"); + button.onclick = submit + }; +console.log("Welcome to assignment 2!") + + -console.log("Welcome to assignment 2!") \ No newline at end of file From 6e0e11831e1406dc9a628d839b1484bac3f6da20 Mon Sep 17 00:00:00 2001 From: Ngoodman <112005039+poz123@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:03:19 -0400 Subject: [PATCH 3/6] Update index.html --- public/index.html | 63 +++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/public/index.html b/public/index.html index c56d620..531ec95 100644 --- a/public/index.html +++ b/public/index.html @@ -1,41 +1,46 @@ - + CS4241 Assignment 2 - + + + + -
- - -
- - +
+ + +
+
+ + + From 2528b54ab1664f422968dcd65b405182dc0598c5 Mon Sep 17 00:00:00 2001 From: Ngoodman <112005039+poz123@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:04:16 -0400 Subject: [PATCH 4/6] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 988f135..9297c8e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "", + "name": "a2-poz123", "version": "", "description": "", - "author": "", + "author": "Noah Goodman", "scripts": { "start": "node server.improved.js" }, From 25fc3ef779ea3afb3784ab42b519da34ed485a25 Mon Sep 17 00:00:00 2001 From: Ngoodman <112005039+poz123@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:05:38 -0400 Subject: [PATCH 5/6] Update server.improved.js --- server.improved.js | 139 ++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/server.improved.js b/server.improved.js index 26673fc..a7249af 100644 --- a/server.improved.js +++ b/server.improved.js @@ -1,72 +1,71 @@ -const http = require( 'http' ), - fs = require( 'fs' ), - // IMPORTANT: you must run `npm install` in the directory for this assignment - // to install the mime library used in the following line of code - mime = require( 'mime' ), - dir = 'public/', - port = 3000 - -const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} -] - -const server = http.createServer( function( request,response ) { - if( request.method === 'GET' ) { - handleGet( request, response ) - }else if( request.method === 'POST' ){ - handlePost( request, response ) +const http = require("http"), + fs = require("fs"), + // IMPORTANT: you must run `npm install` in the directory for this assignment + // to install the mime library used in the following line of code + mime = require("mime"), + dir = "public/", + port = 3000; + +const appdata = []; + +const server = http.createServer(function (request, response) { + if (request.method === "GET") { + handleGet(request, response); + } else if (request.method === "POST") { + handlePost(request, response); } -}) - -const handleGet = function( request, response ) { - const filename = dir + request.url.slice( 1 ) - - if( request.url === '/' ) { - sendFile( response, 'public/index.html' ) - }else{ - sendFile( response, filename ) +}); +const handleGet = function (request, response) { + const filename = dir + request.url.slice(1); + if (request.url === "/") { + sendFile(response, "public/index.html"); + } else { + sendFile(response, filename); } -} - -const handlePost = function( request, response ) { - let dataString = '' - - request.on( 'data', function( data ) { - dataString += data - }) - - request.on( 'end', function() { - console.log( JSON.parse( dataString ) ) - - // ... do something with the data here!!! - - response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end() - }) -} - -const sendFile = function( response, filename ) { - const type = mime.getType( filename ) - - fs.readFile( filename, function( err, content ) { - - // if the error = null, then we've loaded the file successfully - if( err === null ) { - - // status code: https://httpstatuses.com - response.writeHeader( 200, { 'Content-Type': type }) - response.end( content ) - - }else{ - - // file not found, error code 404 - response.writeHeader( 404 ) - response.end( '404 Error: File Not Found' ) - - } - }) -} - -server.listen( process.env.PORT || port ) +}; + +const handlePost = function (request, response) { + let dataString = ""; + + request.on("data", function (data) { + dataString += data; + console.log(data); + }); + + request.on("end", function () { + console.log(JSON.parse(dataString)); + if (request.url === "/submit") { + let item = JSON.parse(dataString); + item.init += item.data.charAt(); + item.init += item.data2.charAt(); + item.init += item.data3.charAt(); + + appdata.push(item); + console.log(item); + } else if (request.url === "/delete") { + let i = JSON.parse(dataString).index; + appdata.splice(i, 1); + } + + response.writeHead(200, "OK", { "Content-Type": "text/plain" }); + + response.end(JSON.stringify(appdata)); + }); +}; + +const sendFile = function (response, filename) { + const type = mime.getType(filename); + + fs.readFile(filename, function (err, content) { + if (err === null) { + // status code: https://httpstatuses.com + response.writeHeader(200, { "Content-Type": type }); + response.end(content); + } else { + response.writeHeader(404); + response.end("404 Error: File Not Found"); + } + }); +}; + +server.listen(process.env.PORT || port); From 772ffca505bf74cdd0e08cefa3dab257f7748f3b Mon Sep 17 00:00:00 2001 From: Ngoodman <112005039+poz123@users.noreply.github.com> Date: Fri, 9 Sep 2022 13:06:12 -0400 Subject: [PATCH 6/6] Update README.md --- README.md | 97 +++---------------------------------------------------- 1 file changed, 5 insertions(+), 92 deletions(-) diff --git a/README.md b/README.md index 9434c98..58d479d 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,11 @@ -Assignment 2 - Short Stack: Basic Two-tier Web Application using HTML/CSS/JS and Node.js -=== -Due: September 8th, by 11:59 AM. +## Name Repository -This assignment aims to introduce you to creating a prototype two-tiered web application. -Your application will include the use of HTML, CSS, JavaScript, and Node.js functionality, with active communication between the client and the server over the life of a user session. - -Baseline Requirements ---- - -There is a large range of application areas and possibilities that meet these baseline requirements. -Try to make your application do something useful! A todo list, storing / retrieving high scores for a very simple game... have a little fun with it. - -Your application is required to implement the following functionalities: - -- a `Server` which not only serves files, but also maintains a tabular dataset with 3 or more fields related to your application -- a `Results` functionality which shows the entire dataset residing in the server's memory -- a `Form/Entry` functionality which allows a user to add, modify, or delete data items residing in the server's memory -- a `Server Logic` which, upon receiving new or modified "incoming" data, includes and uses a function that adds at least one additional derived field to this incoming data before integrating it with the existing dataset -- the `Derived field` for a new row of data must be computed based on fields already existing in the row. -For example, a `todo` dataset with `task`, `priority`, and `creation_date` may generate a new field `deadline` by looking at `creation_date` and `priority` - -Your application is required to demonstrate the use of the following concepts: - -HTML: -- One or more [HTML Forms](https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms), with any combination of form tags appropriate for the user input portion of the application -- A results page displaying all data currently available on the server. You will most likely use a `` tag for this, but `