From 0521b2fa0c6b651f8178d109cbf221e87fd031f0 Mon Sep 17 00:00:00 2001 From: Jan Skowronski Date: Fri, 9 Aug 2019 11:15:24 +0100 Subject: [PATCH 1/4] Tidy up --- database/db_build.js | 4 ---- public/index.html | 8 ++++---- src/handlers.js | 6 ------ src/queries/postSHAPEquery.js | 1 - src/router.js | 1 - 5 files changed, 4 insertions(+), 16 deletions(-) diff --git a/database/db_build.js b/database/db_build.js index f75d1a3..dbe8257 100644 --- a/database/db_build.js +++ b/database/db_build.js @@ -7,8 +7,4 @@ const sql = fs.readFileSync(buildLink).toString();//listing of sql we create const runBuild = cb =>dbConnection.query(sql, cb); module.exports = runBuild; -// dbConnection.query(sql, (error, res)=> { -// if (error) throw error; -// console.log('Tables are created', res) -// }); diff --git a/public/index.html b/public/index.html index d2b432a..7ada6f4 100644 --- a/public/index.html +++ b/public/index.html @@ -26,16 +26,16 @@

SaVaGe
ARTWORK
CREATOR

Create a new SVG

- + - +

Create a new shape

- + - +
diff --git a/src/handlers.js b/src/handlers.js index 611786f..97ad947 100644 --- a/src/handlers.js +++ b/src/handlers.js @@ -34,11 +34,9 @@ module.exports = { data += chunk; }); req.on("end", () => { - console.log(data); let dataObject = JSON.parse(data); postSVGquery(dataObject.name, dataObject.props, (error, result) => { if (error) console.log(error); - console.log(result); res.writeHead(200, { "content-type": "text/html" }); res.end("{}"); }); @@ -46,14 +44,12 @@ module.exports = { }, getAllData(req, res) { getAllDataQuery(result => { - console.log(result.rows); res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(result.rows)); }); }, getSVGs(req, res) { getSVGsQuery(result => { - console.log(result.rows); res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(result.rows)); }); @@ -65,7 +61,6 @@ module.exports = { data2 += chunk; }); req.on("end", () => { - console.log(data2); let data2Obj = JSON.parse(data2); postSHAPEquery( data2Obj.name, @@ -82,7 +77,6 @@ module.exports = { getSHAPEs(req, res) { getSHAPEsquery(result => { - console.log(result.rows); res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(result.rows)); }); diff --git a/src/queries/postSHAPEquery.js b/src/queries/postSHAPEquery.js index 0c39c19..c868013 100644 --- a/src/queries/postSHAPEquery.js +++ b/src/queries/postSHAPEquery.js @@ -1,7 +1,6 @@ const dbConnection = require("../../database/db_connection"); const postSHAPEquery = (name, props, type, cb) =>{ - console.log("params", name, props, type); dbConnection.query("INSERT INTO shape(name,props,type) VALUES ($1,$2,$3)", [name, props, type], (err, res)=>{ diff --git a/src/router.js b/src/router.js index c871f8a..8454f41 100644 --- a/src/router.js +++ b/src/router.js @@ -4,7 +4,6 @@ const router = (req, res) => { if (req.url === "/") { req.url = "/public/index.html"; } - console.log("Received URL: ", req.url); if (req.url.startsWith("/public")) { handlers.staticAssets(req, res); } else if (req.url === "/postSVG") { From 95b2497fa3d208a3fc9cfb816b75dcda8b9de8b1 Mon Sep 17 00:00:00 2001 From: Jan Skowronski Date: Fri, 9 Aug 2019 11:26:12 +0100 Subject: [PATCH 2/4] Query functions together --- src/handlers.js | 20 ++++++++------------ tests/db_test.js | 9 +++++---- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/handlers.js b/src/handlers.js index 97ad947..e52089b 100644 --- a/src/handlers.js +++ b/src/handlers.js @@ -1,11 +1,7 @@ const fs = require("fs"); const path = require("path"); -const getAllDataQuery = require("./queries/getAllDataquery"); -const getSVGsQuery = require("./queries/getSVGsquery"); -const postSVGquery = require("./queries/postSVGquery"); -const postSHAPEquery = require("./queries/postSHAPEquery"); -const getSHAPEsquery = require("./queries/getSHAPEsquery"); -const insertSVG_SHAPEquery= require("./queries/post_SVG_SHAPE"); +const queries = require('./queries'); + module.exports = { staticAssets(req, res) { @@ -35,7 +31,7 @@ module.exports = { }); req.on("end", () => { let dataObject = JSON.parse(data); - postSVGquery(dataObject.name, dataObject.props, (error, result) => { + queries.postSVGquery(dataObject.name, dataObject.props, (error, result) => { if (error) console.log(error); res.writeHead(200, { "content-type": "text/html" }); res.end("{}"); @@ -43,13 +39,13 @@ module.exports = { }); }, getAllData(req, res) { - getAllDataQuery(result => { + queries.getAllDataQuery(result => { res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(result.rows)); }); }, getSVGs(req, res) { - getSVGsQuery(result => { + queries.getSVGsQuery(result => { res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(result.rows)); }); @@ -62,7 +58,7 @@ module.exports = { }); req.on("end", () => { let data2Obj = JSON.parse(data2); - postSHAPEquery( + queries.postSHAPEquery( data2Obj.name, data2Obj.props, data2Obj.type, @@ -76,7 +72,7 @@ module.exports = { }, getSHAPEs(req, res) { - getSHAPEsquery(result => { + queries.getSHAPEsquery(result => { res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(result.rows)); }); @@ -89,7 +85,7 @@ module.exports = { }); req.on("end", () => { let obj = JSON.parse(data3); - insertSVG_SHAPEquery(obj.svg_id, obj.shape_id, (error,result) => { + queries.insertSVG_SHAPEquery(obj.svg_id, obj.shape_id, (error,result) => { if (error) return (error); res.writeHead(200, { "content-type": "text/html"}); res.end("{}"); diff --git a/tests/db_test.js b/tests/db_test.js index 1ac6a3f..79700f6 100644 --- a/tests/db_test.js +++ b/tests/db_test.js @@ -1,4 +1,5 @@ const tape = require("tape"); +const queries = require('../src/queries'); const runDBbuild = require("../database/db_build"); const getSvgquery = require("../src/queries/getSVGsquery"); const getShapequery = require("../src/queries/getSHAPEsquery"); @@ -11,7 +12,7 @@ tape("tape is working?", t => { tape("What is the number of rows in svg table?", t => { runDBbuild(function(err, res) { t.error(err, "No error"); - getSvgquery(result => { + queries.getSVGsQuery(result => { t.equal(result.rows.length, 3); t.end(); @@ -23,7 +24,7 @@ tape("What is the value of name and props in the first row?", t => { runDBbuild(function(err, res) { t.error(err, "No error "); let expected= {name:'picasso',props:'{"fill":"pink"}',id:1}; - getSvgquery(result => { + queries.getSVGsQuery(result => { t.deepEqual(result.rows[0], expected); t.end(); }) @@ -33,7 +34,7 @@ tape("What is the value of name and props in the first row?", t => { tape("What is the number of rows in shape table?", t => { runDBbuild(function(err, res) { t.error(err, "No error"); - getShapequery(result => { + queries.getSHAPEsquery(result => { t.equal(result.rows.length, 5) t.end(); }) @@ -44,7 +45,7 @@ tape("What are the values of name, props and type in the second row?- shape tabl runDBbuild(function(err, res) { t.error(err, "No error "); let expected= { name:'sq',type:'rect',props:'{"x":20,"y":30,"width":40,"height":40}', id:2}; - getShapequery(result => { + queries.getSHAPEsquery(result => { t.deepEqual(result.rows[1], expected); t.end(); }) From 35a052dc7a1ff038f74e60d3ed94de3c09bdf39a Mon Sep 17 00:00:00 2001 From: Jan Skowronski Date: Fri, 9 Aug 2019 11:35:15 +0100 Subject: [PATCH 3/4] Css adjusts --- public/style.css | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/public/style.css b/public/style.css index 87f5f8e..b561624 100644 --- a/public/style.css +++ b/public/style.css @@ -34,6 +34,12 @@ button { width: 10rem; padding: 1%; border-radius: 3px; + cursor: pointer; +} + +button:hover { + color:white; + background-color: black; } input, @@ -43,6 +49,8 @@ select { font-size: 1rem; padding: 1% !important; border-radius: 3px; + cursor: pointer; + } /*----------------------------LAYOUT/GRID-------------------------*/ body { @@ -102,6 +110,7 @@ label { .interface-add-shape-to-svg { display: flex; margin-top: 2%; + align-items: center; } .list-of-shapes, .list-of-svgs { From 7dc712f17b44d767fed5318bbe16bfbf33490738 Mon Sep 17 00:00:00 2001 From: Jan Skowronski Date: Fri, 9 Aug 2019 11:57:24 +0100 Subject: [PATCH 4/4] Query functions together with index --- src/queries/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/queries/index.js diff --git a/src/queries/index.js b/src/queries/index.js new file mode 100644 index 0000000..0c6383d --- /dev/null +++ b/src/queries/index.js @@ -0,0 +1,8 @@ +module.exports = { + getAllDataQuery: require("./getAllDataquery"), + getSVGsQuery: require("./getSVGsquery"), + postSVGquery: require("./postSVGquery"), + postSHAPEquery: require("./postSHAPEquery"), + getSHAPEsquery: require("./getSHAPEsquery"), + insertSVG_SHAPEquery: require("./post_SVG_SHAPE") +};