diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..565d866 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/models/.DS_Store b/models/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/models/.DS_Store differ diff --git a/models/todo.js b/models/todo.js new file mode 100644 index 0000000..c6a47ef --- /dev/null +++ b/models/todo.js @@ -0,0 +1,15 @@ +var mongoose = require('mongoose'), + Schema = mongoose.Schema; + +// Provide the schema for the Todo model +var TodoSchema = new Schema({ + task: String, + description: String, + // done: Boolean +}); + +// Define the model using the schema we provided +var Todo = mongoose.model('Todo', TodoSchema); + +// We export the Todo model to use in other files +module.exports = Todo; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..1e85f16 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "todo-api", + "version": "1.0.0", + "description": "**Objective:** Use Express to make a RESTful API for a to do list. Build a client for your app that uses AJAX and Handlebars templating to `CREATE`, `READ`, `UPDATE`, and `DELETE` todos.", + "main": "server.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node server.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "body-parser": "^1.14.1", + "express": "^4.13.3", + "hbs": "^4.0.0", + "mongoose": "^4.2.5" + }, + "devDependencies": {}, + "repository": { + "type": "git", + "url": "git+https://github.com/stevennoble78/express-todo-app.git" + }, + "bugs": { + "url": "https://github.com/stevennoble78/express-todo-app/issues" + }, + "homepage": "https://github.com/stevennoble78/express-todo-app#readme" +} diff --git a/public/.DS_Store b/public/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/public/.DS_Store differ diff --git a/public/main.css b/public/main.css new file mode 100644 index 0000000..b4ce8b6 --- /dev/null +++ b/public/main.css @@ -0,0 +1,12 @@ +body { + background-color: #AE6D11; +} + +#appcontainer { + background-color: #86D5B7; + border-color: #0B754D; +} + +.editTodo { + display: none; +} \ No newline at end of file diff --git a/public/main.js b/public/main.js new file mode 100644 index 0000000..d56f139 --- /dev/null +++ b/public/main.js @@ -0,0 +1,113 @@ +// wait for DOM to load before running JS +$(document).ready (function () { + + // check to make sure JS is loaded + console.log('JS is loaded!'); + + // Compile the template + var source = $('#template').html(); + var template = Handlebars.compile(source); + + // Set variables + var todoResults = [], + baseUrl = '/', + apiUrl = baseUrl + 'api/todos/', + $todolist = $('#todo-list'), + $newTodo = $('#newTodo'); + + // Use AJAX to get data and append it to the page + $.get(apiUrl, function(data) { + console.log(data.todos); + todoResults = data.todos; + + // Render the data + var todoHTML = template({todos: todoResults}); + $todolist.append(todoHTML); + }); + + // Refresh function + function refresh (data) { + console.log('refreshing'); + $todolist.empty(); + $('input.formdata').val(''); + // Rerender the data + var todoHTML = template({todos: todoResults}); + $todolist.append(todoHTML); + } + + // Add todo function called by submit button handler + function addTodo(data) { + event.preventDefault(); + var newTodo = $(this).serialize(); + $.post(apiUrl, newTodo, function(data) { + todoResults.push(data); + refresh(); + }); + } + + // Put todo function called by glyphicon pencil handler + function putTodo() { + event.preventDefault(); + var id = $(this).attr('id'); + $('#form' + id).toggle(); + $('#form' + id).on('submit', function(event) { + event.preventDefault(); + var updatedTodo = $(this).serialize(); + $.ajax({ + type: 'PUT', + url: apiUrl + id, + data: updatedTodo, + success: function (data) { + var index = todoResults.indexOf(updatedTodo); + for (var i=0; i + + + + + + + + + + To Do List + + +
+
+
+

To Do List

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

Task

+
+
+

Description

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