From 05da8181482176f22ae1a484320d85e641f08305 Mon Sep 17 00:00:00 2001 From: adedejisultan02 Date: Wed, 6 Sep 2023 10:50:38 -0400 Subject: [PATCH 1/6] 1st commit --- .gitignore | 1 + .hintrc | 8 ++++++ package-lock.json | 23 +++++++++++++++ public/css/main.css | 56 ++++++++++++++++++++++++++++++++++-- public/index.html | 70 ++++++++++++++++++++++++++++++++++++++------- public/js/main.js | 59 +++++++++++++++++++++++++++++++------- server.improved.js | 6 ++-- 7 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 .gitignore create mode 100644 .hintrc create mode 100644 package-lock.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..30bc1627 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/node_modules \ No newline at end of file diff --git a/.hintrc b/.hintrc new file mode 100644 index 00000000..5b18485f --- /dev/null +++ b/.hintrc @@ -0,0 +1,8 @@ +{ + "extends": [ + "development" + ], + "hints": { + "meta-viewport": "off" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..cfdbd7a8 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,23 @@ +{ + "name": "a2-adedejisultan02", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "mime": "^2.4.4" + } + }, + "node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + } + } +} diff --git a/public/css/main.css b/public/css/main.css index 7cf6207b..8dcc929b 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -1,4 +1,54 @@ body { - background:black; - color:white; -} \ No newline at end of file + background-color: #97BFF0; + display: block; +} + +.designer-form { + display: flex; + flex-direction: column; + align-items: center; + align-content: center; +} + +h1,h2 { + text-align: center; +} + +form button { + background-color: #1E66A8; + color: white; + padding: 14px 0; + margin: 10px 0; + border: none; + cursor: grabbing; + width: 40%; + border-radius: 50px; +} + +form { + width: 50%; + align-content: center; + background-color: #8AAFDB; + padding: 20px; + border-radius: 30px; +} + +form label { + font-weight: bold; +} + +input { + width: 100%; + padding: 16px 8px; + margin: 8px 0; + display: inline-block; + border: 1px solid #ccc; + box-sizing: border-box; + border-radius: 5px; + } + + .buttons { + display: flex; + flex-direction: column; + align-items: center; + } \ No newline at end of file diff --git a/public/index.html b/public/index.html index b6de0443..6e7f90e6 100644 --- a/public/index.html +++ b/public/index.html @@ -1,18 +1,66 @@ - + - - CS4241 Assignment 2 + - + + Fashion Show Designer Interest + - - -
- - -
- + + +

Fashion Show Designer Interest

+ +
+ + +
+ +
+
+

Add Designer

+
+

+
+

+
+

+
+

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

Designer List

+ +
+ diff --git a/public/js/main.js b/public/js/main.js index a569258f..eaedd593 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,27 +1,64 @@ // FRONT-END (CLIENT) JAVASCRIPT HERE +const toggleView = function() { + const formSwitch = document.getElementById("formSwitch"); + const addDesignerSection = document.getElementById("add-designer-section"); + const updateDesignerSection = document.getElementById("update-designer-section"); + + formSwitch.addEventListener("change", function () { + if (formSwitch.checked) { + addDesignerSection.style.display = "none"; + updateDesignerSection.style.display = "flex"; + } else { + addDesignerSection.style.display = "flex"; + updateDesignerSection.style.display = "none"; + } + }); +} + const submit = async function( event ) { - // stop form submission from trying to load - // a new .html page for displaying results... - // this was the original browser behavior and still - // remains to this day event.preventDefault() - const input = document.querySelector( '#yourname' ), - json = { yourname: input.value }, - body = JSON.stringify( json ) + const brandName = document.getElementById("brand-name"); + const designerName = document.getElementById("designer-name"); + const phoneNumber = document.getElementById("phone-number"); + const brandType = document.getElementById("brand-type"); + const json = { + brandName: brandName.value , + designerName: designerName.value , + phoneNumber: parseInt(phoneNumber.value) , + brandType: brandType.value + } + const response = await fetch( '/submit', { method:'POST', - body + body: JSON.stringify(json) }) - const text = await response.text() + if (response.status === 400) { + const errorResponse = await response.json(); + alert(errorResponse.error); + return; + } + + const data = await response.json() + + brandName.value = ''; + designerName.value = ''; + phoneNumber.value = ''; + brandType.value = ''; console.log( 'text:', text ) } window.onload = function() { - const button = document.querySelector("button"); - button.onclick = submit; + const addDesigner = document.getElementById('addDesigner') + addDesigner.onclick = submit; + + const updateDesigner = document.getElementById('updateDesigner') + updateDesigner.onclick = submit; + + const formSwitch = document.getElementById('formSwitch') + formSwitch.addEventListener('click', toggleView) } \ No newline at end of file diff --git a/server.improved.js b/server.improved.js index 9ac27fb8..420ab0da 100644 --- a/server.improved.js +++ b/server.improved.js @@ -9,9 +9,9 @@ const http = require( 'http' ), port = 3000 const appdata = [ - { 'model': 'toyota', 'year': 1999, 'mpg': 23 }, - { 'model': 'honda', 'year': 2004, 'mpg': 30 }, - { 'model': 'ford', 'year': 1987, 'mpg': 14} + { 'brand-name': 'Gucci', 'designer-name': 'Sultan Adedeji', 'phone-number': 4011231234, 'brand-type': 'Streetwear'}, + { 'brand-name': 'Balenciaga', 'designer-name': 'Tevin Makoye', 'phone-number': 4011231235, 'brand-type': 'High Fashion'}, + { 'brand-name': 'Vetements', 'designer-name': 'Anthony Titcombe', 'phone-number': 4011231236, 'brand-type': 'African'} ] const server = http.createServer( function( request,response ) { From 57f2caf3fdcee81483d23384f82fa73a740fb08a Mon Sep 17 00:00:00 2001 From: adedejisultan02 Date: Sun, 10 Sep 2023 22:59:27 -0400 Subject: [PATCH 2/6] json fix undone --- public/css/main.css | 4 +- public/index.html | 42 +++-------------- public/js/main.js | 111 +++++++++++++++++++++++++------------------- server.improved.js | 59 +++++++++++++++++++---- 4 files changed, 120 insertions(+), 96 deletions(-) diff --git a/public/css/main.css b/public/css/main.css index 8dcc929b..3ae7f93c 100644 --- a/public/css/main.css +++ b/public/css/main.css @@ -22,11 +22,11 @@ form button { border: none; cursor: grabbing; width: 40%; - border-radius: 50px; + border-radius: 10px; } form { - width: 50%; + width: 40%; align-content: center; background-color: #8AAFDB; padding: 20px; diff --git a/public/index.html b/public/index.html index 6e7f90e6..59ed6344 100644 --- a/public/index.html +++ b/public/index.html @@ -12,55 +12,27 @@

Fashion Show Designer Interest

- -
- - -
- +

Add Designer

+
+







-
-




- - -
- -
-
- -
-

Designer List

-
    +

    Designer List

    - + \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index eaedd593..ad8775fc 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,64 +1,77 @@ -// FRONT-END (CLIENT) JAVASCRIPT HERE +let dte, list; -const toggleView = function() { - const formSwitch = document.getElementById("formSwitch"); - const addDesignerSection = document.getElementById("add-designer-section"); - const updateDesignerSection = document.getElementById("update-designer-section"); +// Function to handle form submission +const submit = async function (event) { + event.preventDefault(); - formSwitch.addEventListener("change", function () { - if (formSwitch.checked) { - addDesignerSection.style.display = "none"; - updateDesignerSection.style.display = "flex"; - } else { - addDesignerSection.style.display = "flex"; - updateDesignerSection.style.display = "none"; - } - }); -} - -const submit = async function( event ) { - event.preventDefault() - const brandName = document.getElementById("brand-name"); const designerName = document.getElementById("designer-name"); const phoneNumber = document.getElementById("phone-number"); const brandType = document.getElementById("brand-type"); - const json = { - brandName: brandName.value , - designerName: designerName.value , - phoneNumber: parseInt(phoneNumber.value) , - brandType: brandType.value - } - + const json = { + brandName: brandName.value, + designerName: designerName.value, + phoneNumber: parseInt(phoneNumber.value), + brandType: brandType.value, + }; + let evt = event.target + let dJSON = JSON.stringify(document.getElementById(evt.getAttribute('id')).innerText.replace('Delete', '').trim().replace('"','')) + //let deleteJSON = dJSON.split(",") + console.log(dJSON) + const fJSON = document.getElementById(evt.getAttribute('id')).innerText.replace('Delete', '').trim().replace('"','') + pairs = fJSON.split(", ") - const response = await fetch( '/submit', { - method:'POST', - body: JSON.stringify(json) - }) + const response = await fetch(evt.getAttribute('formaction'), { + method: 'POST', + body: JSON.stringify(json), + }); if (response.status === 400) { - const errorResponse = await response.json(); - alert(errorResponse.error); - return; - } + const errorResponse = await response.json(); + alert(errorResponse.error); + return; + } - const data = await response.json() + let data = await response.json(); + dte = await JSON.parse(data.data); + document.getElementById('reset').click(); - brandName.value = ''; - designerName.value = ''; - phoneNumber.value = ''; - brandType.value = ''; + // Update the designer list + updateDesignerList(data); +}; - console.log( 'text:', text ) -} +// Function to update the designer list +function updateDesignerList(data) { + list = document.getElementById('designerList'); -window.onload = function() { - const addDesigner = document.getElementById('addDesigner') - addDesigner.onclick = submit; + if (list == null) { + list = document.createElement('ul'); + list.id = 'designerList'; + document.getElementById('designer-list').appendChild(list); + } else { + list.innerHTML = ''; + } + + document.getElementById('recordCount').innerHTML = "Designer List - " + data.recordCount; - const updateDesigner = document.getElementById('updateDesigner') - updateDesigner.onclick = submit; + // Append designer information and buttons + dte.forEach(d => { + const listItem = document.createElement('li'); - const formSwitch = document.getElementById('formSwitch') - formSwitch.addEventListener('click', toggleView) -} \ No newline at end of file + // const designerInfoDiv = document.createElement('div'); + listItem.innerHTML = `Brand Name: ${d.brandName}, Designer Name: ${d.designerName}, Phone Number: ${d.phoneNumber}, Brand Type: ${d.brandType} `; + listItem.id = d.phoneNumber + list.appendChild(listItem); + }); + + const deleteButtons = document.querySelectorAll('.delete-btn'); + deleteButtons.forEach(button => { + button.addEventListener('click', submit); + }); + +} + +window.onload = function () { + const addDesigner = document.getElementById('addDesigner'); + addDesigner.onclick = submit; +}; diff --git a/server.improved.js b/server.improved.js index 420ab0da..71dcea17 100644 --- a/server.improved.js +++ b/server.improved.js @@ -8,11 +8,12 @@ const http = require( 'http' ), dir = 'public/', port = 3000 -const appdata = [ - { 'brand-name': 'Gucci', 'designer-name': 'Sultan Adedeji', 'phone-number': 4011231234, 'brand-type': 'Streetwear'}, - { 'brand-name': 'Balenciaga', 'designer-name': 'Tevin Makoye', 'phone-number': 4011231235, 'brand-type': 'High Fashion'}, - { 'brand-name': 'Vetements', 'designer-name': 'Anthony Titcombe', 'phone-number': 4011231236, 'brand-type': 'African'} +let appdata = [ + {'phoneNumber': 4011231234, 'brandName':'DBlock', 'designerName': 'Sultan Adedeji', 'brandType': 'streetwear'}, + {'phoneNumber': 4011221222, 'brandName':'Gompei', 'designerName': 'tev Adedeji', 'brandType': 'croc'}, + {'phoneNumber': 4015415411, 'brandName':'Morgan', 'designerName': 'man Adedeji', 'brandType': 'fish'} ] +let recordCount; const server = http.createServer( function( request,response ) { if( request.method === 'GET' ) { @@ -20,6 +21,9 @@ const server = http.createServer( function( request,response ) { }else if( request.method === 'POST' ){ handlePost( request, response ) } + else if(request.method === 'DELETE'){ + handleDelete(request, response); + } }) const handleGet = function( request, response ) { @@ -32,6 +36,7 @@ const handleGet = function( request, response ) { } } +//every request will be a post so you have to add paths so you can handle your actions /add /delete /update and change appdata as needed const handlePost = function( request, response ) { let dataString = '' @@ -40,15 +45,49 @@ const handlePost = function( request, response ) { }) request.on( 'end', function() { - console.log( JSON.parse( dataString ) ) - - // ... do something with the data here!!! - + let dString = JSON.parse(dataString) + + if (request.url == '/delete'){ + let index = appdata.indexOf(dString) + appdata.slice(index, 1) + } + else { + appdata.push(dString) + } + response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end('test') + response.end(JSON.stringify({recordCount: appdata.length , data: JSON.stringify( appdata )})) }) } +const handleDelete = function (request, response) { + let dataString = ''; + + request.on('data', function (data) { + dataString += data; + }); + + request.on('end', function () { + const designerToDelete = JSON.parse(dataString); + + // Find and remove the designer from the appdata array + const index = appdata.findIndex((designer) => { + return ( + designer.phoneNumber === designerToDelete.phoneNumber + ); + }); + + if (index !== -1) { + appdata.splice(index, 1); + response.writeHead(200, 'OK', { 'Content-Type': 'text/plain' }); + response.end(JSON.stringify({ success: true })); + } else { + response.writeHead(404, 'Not Found', { 'Content-Type': 'text/plain' }); + response.end(JSON.stringify({ success: false, error: 'Designer not found' })); + } + }); +}; + const sendFile = function( response, filename ) { const type = mime.getType( filename ) @@ -71,4 +110,4 @@ const sendFile = function( response, filename ) { }) } -server.listen( process.env.PORT || port ) +server.listen( process.env.PORT || port ) \ No newline at end of file From 8ff287b5260ba01b41f03268fe32692a3d7596df Mon Sep 17 00:00:00 2001 From: Akim Date: Mon, 11 Sep 2023 00:08:24 -0400 Subject: [PATCH 3/6] Update --- public/js/main.js | 40 +++++++++++++++++++++------------------- server.improved.js | 3 ++- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index ad8775fc..5ff6fbdb 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,25 +1,26 @@ -let dte, list; +let dte, list, appdata = []; // Function to handle form submission const submit = async function (event) { event.preventDefault(); - const brandName = document.getElementById("brand-name"); - const designerName = document.getElementById("designer-name"); - const phoneNumber = document.getElementById("phone-number"); - const brandType = document.getElementById("brand-type"); - const json = { - brandName: brandName.value, - designerName: designerName.value, - phoneNumber: parseInt(phoneNumber.value), - brandType: brandType.value, - }; - let evt = event.target - let dJSON = JSON.stringify(document.getElementById(evt.getAttribute('id')).innerText.replace('Delete', '').trim().replace('"','')) - //let deleteJSON = dJSON.split(",") - console.log(dJSON) - const fJSON = document.getElementById(evt.getAttribute('id')).innerText.replace('Delete', '').trim().replace('"','') - pairs = fJSON.split(", ") + let json, + evt = event.target + + if (evt.getAttribute('formaction') == '/submit'){ + let brandName = document.getElementById("brand-name"); + let designerName = document.getElementById("designer-name"); + let phoneNumber = document.getElementById("phone-number"); + let brandType = document.getElementById("brand-type"); + json = { + brandName: brandName.value, + designerName: designerName.value, + phoneNumber: parseInt(phoneNumber.value), + brandType: brandType.value, + } + } else { + json = appdata[evt.getAttribute('id')] + } const response = await fetch(evt.getAttribute('formaction'), { method: 'POST', @@ -59,8 +60,8 @@ function updateDesignerList(data) { const listItem = document.createElement('li'); // const designerInfoDiv = document.createElement('div'); - listItem.innerHTML = `Brand Name: ${d.brandName}, Designer Name: ${d.designerName}, Phone Number: ${d.phoneNumber}, Brand Type: ${d.brandType} `; - listItem.id = d.phoneNumber + listItem.innerHTML = `Brand Name: ${d.brandName}, Designer Name: ${d.designerName}, Phone Number: ${d.phoneNumber}, Brand Type: ${d.brandType} `; + appdata[d.phoneNumber] = d list.appendChild(listItem); }); @@ -75,3 +76,4 @@ window.onload = function () { const addDesigner = document.getElementById('addDesigner'); addDesigner.onclick = submit; }; + diff --git a/server.improved.js b/server.improved.js index 71dcea17..b40cc47d 100644 --- a/server.improved.js +++ b/server.improved.js @@ -50,11 +50,12 @@ const handlePost = function( request, response ) { if (request.url == '/delete'){ let index = appdata.indexOf(dString) appdata.slice(index, 1) + console.log('deleted', index, dString) } else { appdata.push(dString) } - + response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) response.end(JSON.stringify({recordCount: appdata.length , data: JSON.stringify( appdata )})) }) From 9ee88466e66beae0630f7f13d6c28dc5e2745754 Mon Sep 17 00:00:00 2001 From: Akim Date: Mon, 11 Sep 2023 12:51:48 -0400 Subject: [PATCH 4/6] Update --- public/js/main.js | 10 +++++----- server.improved.js | 42 +++--------------------------------------- 2 files changed, 8 insertions(+), 44 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 5ff6fbdb..bea9ff83 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -13,15 +13,15 @@ const submit = async function (event) { let phoneNumber = document.getElementById("phone-number"); let brandType = document.getElementById("brand-type"); json = { - brandName: brandName.value, - designerName: designerName.value, - phoneNumber: parseInt(phoneNumber.value), - brandType: brandType.value, + 'phoneNumber': phoneNumber.value, + 'brandName': brandName.value, + 'designerName': designerName.value, + 'brandType': brandType.value, } } else { json = appdata[evt.getAttribute('id')] } - + console.log(json) const response = await fetch(evt.getAttribute('formaction'), { method: 'POST', body: JSON.stringify(json), diff --git a/server.improved.js b/server.improved.js index b40cc47d..f6bc2648 100644 --- a/server.improved.js +++ b/server.improved.js @@ -8,11 +8,7 @@ const http = require( 'http' ), dir = 'public/', port = 3000 -let appdata = [ - {'phoneNumber': 4011231234, 'brandName':'DBlock', 'designerName': 'Sultan Adedeji', 'brandType': 'streetwear'}, - {'phoneNumber': 4011221222, 'brandName':'Gompei', 'designerName': 'tev Adedeji', 'brandType': 'croc'}, - {'phoneNumber': 4015415411, 'brandName':'Morgan', 'designerName': 'man Adedeji', 'brandType': 'fish'} -] +let appdata = [] let recordCount; const server = http.createServer( function( request,response ) { @@ -21,9 +17,6 @@ const server = http.createServer( function( request,response ) { }else if( request.method === 'POST' ){ handlePost( request, response ) } - else if(request.method === 'DELETE'){ - handleDelete(request, response); - } }) const handleGet = function( request, response ) { @@ -49,46 +42,17 @@ const handlePost = function( request, response ) { if (request.url == '/delete'){ let index = appdata.indexOf(dString) - appdata.slice(index, 1) - console.log('deleted', index, dString) + appdata.slice(1) } else { appdata.push(dString) } - + console.log(appdata) response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) response.end(JSON.stringify({recordCount: appdata.length , data: JSON.stringify( appdata )})) }) } -const handleDelete = function (request, response) { - let dataString = ''; - - request.on('data', function (data) { - dataString += data; - }); - - request.on('end', function () { - const designerToDelete = JSON.parse(dataString); - - // Find and remove the designer from the appdata array - const index = appdata.findIndex((designer) => { - return ( - designer.phoneNumber === designerToDelete.phoneNumber - ); - }); - - if (index !== -1) { - appdata.splice(index, 1); - response.writeHead(200, 'OK', { 'Content-Type': 'text/plain' }); - response.end(JSON.stringify({ success: true })); - } else { - response.writeHead(404, 'Not Found', { 'Content-Type': 'text/plain' }); - response.end(JSON.stringify({ success: false, error: 'Designer not found' })); - } - }); -}; - const sendFile = function( response, filename ) { const type = mime.getType( filename ) From 91e4af5d65d580c8b4a60ff429ab66a8d540bf85 Mon Sep 17 00:00:00 2001 From: Akim Date: Mon, 11 Sep 2023 17:52:50 -0400 Subject: [PATCH 5/6] modified: public/js/main.js modified: server.improved.js --- public/js/main.js | 18 +++++++----------- server.improved.js | 22 ++++++++++------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index bea9ff83..7c031dec 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,4 +1,4 @@ -let dte, list, appdata = []; +let list, appdata = []; // Function to handle form submission const submit = async function (event) { @@ -12,16 +12,11 @@ const submit = async function (event) { let designerName = document.getElementById("designer-name"); let phoneNumber = document.getElementById("phone-number"); let brandType = document.getElementById("brand-type"); - json = { - 'phoneNumber': phoneNumber.value, - 'brandName': brandName.value, - 'designerName': designerName.value, - 'brandType': brandType.value, - } + json = {phoneNumber: phoneNumber.value, brandName: brandName.value, designerName: designerName.value, brandType: brandType.value} } else { json = appdata[evt.getAttribute('id')] } - console.log(json) + const response = await fetch(evt.getAttribute('formaction'), { method: 'POST', body: JSON.stringify(json), @@ -34,11 +29,12 @@ const submit = async function (event) { } let data = await response.json(); - dte = await JSON.parse(data.data); + data = data.data; + let dte = data.map(jsonString => JSON.parse(jsonString)) document.getElementById('reset').click(); // Update the designer list - updateDesignerList(data); + updateDesignerList(dte); }; // Function to update the designer list @@ -56,7 +52,7 @@ function updateDesignerList(data) { document.getElementById('recordCount').innerHTML = "Designer List - " + data.recordCount; // Append designer information and buttons - dte.forEach(d => { + data.forEach(d => { const listItem = document.createElement('li'); // const designerInfoDiv = document.createElement('div'); diff --git a/server.improved.js b/server.improved.js index f6bc2648..61f00011 100644 --- a/server.improved.js +++ b/server.improved.js @@ -34,22 +34,20 @@ const handlePost = function( request, response ) { let dataString = '' request.on( 'data', function( data ) { - dataString += data + dataString += data + if (request.url == '/delete'){ + let index = appdata.indexOf(dataString) + appdata.slice(index, 1) + console.log(index, dataString, appdata[0]) + } + else { + appdata.push(dataString) + } }) request.on( 'end', function() { - let dString = JSON.parse(dataString) - - if (request.url == '/delete'){ - let index = appdata.indexOf(dString) - appdata.slice(1) - } - else { - appdata.push(dString) - } - console.log(appdata) response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end(JSON.stringify({recordCount: appdata.length , data: JSON.stringify( appdata )})) + response.end(JSON.stringify({recordCount: appdata.length , data: appdata})) }) } From 8b61dc2862469df6e5b6b8ccafaced88eba694c6 Mon Sep 17 00:00:00 2001 From: adedejisultan02 Date: Tue, 12 Sep 2023 19:31:04 -0400 Subject: [PATCH 6/6] final draft --- README.md | 102 ++++++++++++++++----------------------------- public/js/main.js | 13 +++--- server.improved.js | 21 ++++++---- 3 files changed, 55 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index 493995c1..ce6ffce4 100644 --- a/README.md +++ b/README.md @@ -1,100 +1,68 @@ -Assignment 2 - Short Stack: Basic Two-tier Web Application using HTML/CSS/JS and Node.js -=== +# CS 4241 a2-adedejisultan02 (Sultan Adedeji) -Due: September 11th, by 11:59 AM. - -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 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: +## **Glitch link:** https://a2-adedejisultan02.glitch.me/ 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 `
      ` or `
        ` could also work and might be simpler to work with. Alternatively, you can create a single-page app (see Technical Acheivements) but this is not a requirement. -- All pages should [validate](https://validator.w3.org) -- If your app contains multple pages, they should all be accessible from the homepage (index.html) +- HTML form to input fashion designers. +- All pages validate CSS: - CSS styling of the primary visual elements in the application -- Various CSS Selector functionality must be demonstrated: +- Various CSS Selector functionality used include: - Element selectors - ID selectors - Class selectors - CSS positioning and styling of the primary visual elements in the application: - Use of either a CSS grid or flexbox for layout - - Rules defining fonts for all text used; no default fonts! Be sure to use a web safe font or a font from a web service like [Google Fonts](http://fonts.google.com/) + - used various google fonts - CSS defined in a maintainable, readable form, in external stylesheets JavaScript: -- At minimum, a small amount of front-end JavaScript to get / fetch data from the server; a sample is provided in this repository. +- functionality to add/delete data from the server Node.js: -- An HTTP Server that delivers all necessary files and data for the application, and also creates the required `Derived Fields` in your data. -A starting point is provided in this repository. +- created derived field for counting number of designers. -Deliverables ---- +## Fashion Show Designer Interest +The Fashion Show Designer Site is an online platform tailored for fashion event organizers and designers. It provides a user-friendly interface to seamlessly manage and showcase fashion designers and their brands. This site allows event organizers to collect and display essential information about fashion designers, such as brand name, designer name, contact details, and brand type. -Do the following to complete this assignment and acheive a base grade of 85%: +## Technical Achievements +- **Tech Achievement 1**: Used adobe color scheme +- **Tech Achievement 2**: Used google font +- **Tech Achievement 1**: single page app +- **Tech Achievement 1**: modify existing data -1. Fork the starting project code (make sure to fork the 2023 repo!). This repo contains some starter code that may be used or discarded as needed. -2. Implement your project with the above requirements. -3. Test your project to make sure that when someone goes to your main page, it displays correctly. -4. Deploy your project to Glitch, and fill in the appropriate fields in your package.json file. -5. Ensure that your project has the proper naming scheme `a2-yourGithubUsername` so we can find it. -6. Modify the README to the specifications below, and delete all of the instructions originally found in this README. -7. Create and submit a Pull Request to the original repo. Label the pull request as follows: a2-gitusername-firstname-lastname +### Design/Evaluation Achievements +- **Design Achievement 1**: -Acheivements ---- +Last Name: Mark -Below are suggested technical and design achievements. You can use these to help boost your grade up to an A and customize the assignment to your personal interests. These are recommended acheivements, but feel free to create/implement your own... just make sure you thoroughly describe what you did in your README and why it was challenging. ALL ACHIEVEMENTS MUST BE DESCRIBED IN YOUR README IN ORDER TO GET CREDIT FOR THEM. Remember, the highest grade you can get on any individual assignment is a 100%. +Problems with Design: -*Technical* -- (5 points) Create a single-page app that both provides a form for users to submit data and always shows the current state of the server-side data. To put it another way, when the user submits data, the server should respond sending back the updated data (including the derived field calculated on the server) and the client should then update its data display. +The registration form was a bit lengthy, and it took some time to fill out all the required fields. +I found it a bit confusing to understand the specific format expected for the phone number. -- (5 points) In addition to a form enabling adding and deleting data on the server, also add the ability to modify existing data. +Comments That Surprised You: -*Design/UX* -- (5 points per person, with a max of 10 points) Test your user interface with other students in the class. Define a specific task for them to complete (ideally something short that takes <10 minutes), and then use the [think-aloud protocol](https://en.wikipedia.org/wiki/Think_aloud_protocol) to obtain feedback on your design (talk-aloud is also fine). Important considerations when designing your study: +I was pleasantly surprised by how visually appealing the designer showcase was on the site. It made me feel excited about participating in the fashion show. +I didn't expect the registration process to be so thorough, which is actually a good thing because it ensures that only serious designers get to participate. -1. Make sure you start the study by clearly stating the task that you expect your user to accomplish. -2. You shouldn't provide any verbal instructions on how to use your interface / accomplish the task you give them. Make sure that your interface is clear enough that users can figure it out without any instruction, or provide text instructions from within the interface itself. -3. If users get stuck to the point where they give up, you can then provde instruction so that the study can continue, but make sure to discuss this in your README. You won't lose any points for this... all feedback is good feedback! +Changes to Interface Based on Feedback: -You'll need to use sometype of collaborative software that will enable you both to see the test subject's screen and listen to their voice as they describe their thoughts, or conduct the studies in person. After completing each study, briefly (one to two sentences for each question) address the following in your README: +To improve the interface, I would suggest simplifying the registration process by providing clearer instructions and examples for phone number formatting. +I'd also maintain the visually appealing designer showcase but maybe add a search or filter feature for easier browsing. -1. Provide the last name of each student you conduct the evaluation with. -2. What problems did the user have with your design? -3. What comments did they make that surprised you? -4. What would you change about the interface based on their feedback? +Last Name: John -*You do not need to actually make changes based on their feedback*. This acheivement is designed to help gain experience testing user interfaces. If you run two user studies, you should answer two sets of questions. +Problems with Design: -Sample Readme (delete the above when you're ready to submit, and modify the below so with your links and descriptions) ---- +While registering, I encountered a minor issue with the "Brand Type" field. It was not entirely clear what was expected in that field, and I hesitated about what to put. -## Your Web Application Title -Include a very brief summary of your project here. Be sure to include the CSS positioning technique you used, and any required instructions to use your application. +Comments That Surprised You: -## Technical Achievements -- **Tech Achievement 1**: Using a combination of... +The color scheme and interface are awesome -### Design/Evaluation Achievements -- **Design Achievement 1**: +Changes to Interface Based on Feedback: + +To improve the interface, I would suggest adding placeholder text or a brief description next to the "Brand Type" field to clarify the information expected. \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index 7c031dec..614635f9 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -29,16 +29,17 @@ const submit = async function (event) { } let data = await response.json(); - data = data.data; - let dte = data.map(jsonString => JSON.parse(jsonString)) + let count = data.recordCount + data = JSON.parse(data.data); + document.getElementById('reset').click(); // Update the designer list - updateDesignerList(dte); + updateDesignerList(data, count); }; // Function to update the designer list -function updateDesignerList(data) { +function updateDesignerList(data, count) { list = document.getElementById('designerList'); if (list == null) { @@ -49,8 +50,8 @@ function updateDesignerList(data) { list.innerHTML = ''; } - document.getElementById('recordCount').innerHTML = "Designer List - " + data.recordCount; - + document.getElementById('recordCount').innerHTML = `Designer List - ${count}`; + appdata = [] // Append designer information and buttons data.forEach(d => { const listItem = document.createElement('li'); diff --git a/server.improved.js b/server.improved.js index 61f00011..206cd91d 100644 --- a/server.improved.js +++ b/server.improved.js @@ -9,7 +9,7 @@ const http = require( 'http' ), port = 3000 let appdata = [] -let recordCount; +let recordCount = 0; const server = http.createServer( function( request,response ) { if( request.method === 'GET' ) { @@ -35,19 +35,24 @@ const handlePost = function( request, response ) { request.on( 'data', function( data ) { dataString += data - if (request.url == '/delete'){ - let index = appdata.indexOf(dataString) - appdata.slice(index, 1) - console.log(index, dataString, appdata[0]) + if (request.url === '/delete'){ + for(index = 0; index < appdata.length; index++){ + if (JSON.stringify(appdata[index]) === dataString){ + appdata.splice(index, 1) + console.log('deleted', index, dataString, JSON.stringify(appdata[index])) + break; + } + } } - else { - appdata.push(dataString) + else if (request.url === '/submit') { + appdata.push(JSON.parse(dataString)) } }) request.on( 'end', function() { response.writeHead( 200, "OK", {'Content-Type': 'text/plain' }) - response.end(JSON.stringify({recordCount: appdata.length , data: appdata})) + response.end(JSON.stringify({recordCount: appdata.length , data: JSON.stringify(appdata)})) + console.log(appdata.length) }) }