diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..d6b8cf7 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "express-server", + "version": "1.0.0", + "description": "", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "body-parser": "^1.14.1", + "express": "^4.13.3" + } +} diff --git a/public/main.css b/public/main.css new file mode 100644 index 0000000..7935999 --- /dev/null +++ b/public/main.css @@ -0,0 +1,4 @@ +#listCanvas { + background-color: lightgrey; + height: 500px; +} \ No newline at end of file diff --git a/public/scripts.js b/public/scripts.js new file mode 100644 index 0000000..f0e1dc8 --- /dev/null +++ b/public/scripts.js @@ -0,0 +1,54 @@ +$(function() { + //Compile handlebars + var source = $('#template').html(); + var template = Handlebars.compile(source); + // set global id variable + var id; + + // client side page info array + var todoList = []; + + $.get('localhost:3000/api/todos', function(){ + todoItems = data.todos; + }); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +}); \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..9eaf7ed --- /dev/null +++ b/server.js @@ -0,0 +1,69 @@ +var express = require('express'); +var bodyParser = require('body-parser'); + +var app = express(); + +// Set up Body Parser +app.use(bodyParser.urlencoded({ extended : true })); + +var todoList = [ + { + task : "Buy bread", + description : "Obtain consumable wheat product, sliced", + _id : 1},{ + task : "Buy bananas", + description : "Obtain consumable fruit product, whole", + _id : 2},{ + task : "Buy peanut butter", + description : "Obtain consumable legume product, whipped", + _id : 3 + }]; + +// Set up routes +app.get('/api/todos', function (req, res){ + res.json(todoList); +}); + +app.get('/api/todos/:id', function (req, res){ + var todoId = parseInt(req.params.id); + var foundTodo = todoList.filter(function (todo){ + return todos._id == todoId; + }); + res.json(foundTodo); +}); + +app.post('/api/todos',function (req, res) { + var newTodo = req.body; + if (todoList.length > 0) { + newTodo._id = todoList[todoList.length - 1]._id + 1; + } else { + newTodo._id = 1; + } + todoList.push(newTodo); + res.json(newTodo); +}); + +app.put('/api/todos/:id', function (req, res) { + var todoId = parseInt(req.params.id); + var todoToUpdate = todoList.filter(function (todo){ + return todo._id === todoId; + })[0]; + todoToUpdate.task = req.body.task; + todoToUpdate.description = req.body.description; + res.json(todoToUpdate); +}); + +app.delete('/api/todos/:id', function (req, res){ + var todoId = parseInt(req.params.id); + var todoToUpdate = todoList.filter(function (todo){ + return todo._id === todoId; + })[0]; + var todoIndex = myTodos.indexOf(todoToDelete); + myTodos.splice(todoIndex, 1); + res.json(todoToDelete); +}); + +// Server listening check +var server = app.listen(process.env.PORT || 3000, function(){ + console.log("HEY! LISTEN!"); +}); \ No newline at end of file diff --git a/views/index.html b/views/index.html new file mode 100644 index 0000000..fa77d0e --- /dev/null +++ b/views/index.html @@ -0,0 +1,59 @@ + + + + + + + + + + + To Do List + + + +
+ +
+ +
+

My To Do List

+

+
+ +
+ +
+
+
+ + + + + + + + + + \ No newline at end of file