diff --git a/public/controllers/controller.js b/public/controllers/controller.js index 0b67206..b7f3d72 100755 --- a/public/controllers/controller.js +++ b/public/controllers/controller.js @@ -9,13 +9,40 @@ $scope.todolist = response; }); $scope.task = { - taskname: "E.g Task", + taskname: "", Done: false, - details: '' - } + details: "" + } $scope.addTask = function() { //console.log($scope.todo); + $http.post('/todolist', $scope.task).success(function(response){ + $http.get('/todolist').success(function(response) { + $scope.todolist = response; + }); + console.log(response); + $scope.task = { + taskname: "", + Done: false, + details: "" + } + }); + + + + }; + + $scope.updateTask = function(task) { + $http.put('/todolist/'+task._id,task).success(function(response) { + + }); + }; + + $scope.deleteTask = function(id) { + var x=confirm("Are you sure?") + + if(x==true){ + $http.delete('/todolist/' + id).success(function(response) { console.log(response); }); $http.get('/todolist').success(function(response) { @@ -23,10 +50,7 @@ }); $scope.todo = ""; }; - - $scope.markTaskDone = function() { - console.log($scope.todo); - }; + } }]); diff --git a/public/index.html b/public/index.html index a53bf1e..b4d8563 100755 --- a/public/index.html +++ b/public/index.html @@ -12,8 +12,11 @@ text-decoration: line-through; color:#ccc; } - small { - cursor: pointer; + button{ + display:none; + } + .delete:hover button{ +display:inline; } @@ -24,24 +27,21 @@ Tasks - Details Actions - + - + - x -    - {{todo.taskname}} {{(more)? 'Hide Desc' : 'Show Desc'}}
- {{todo.details}} +
    {{todo.taskname}}
+ diff --git a/server.js b/server.js index e3c7289..d078989 100755 --- a/server.js +++ b/server.js @@ -36,13 +36,29 @@ app.post('/todolist', function(req, res) { }); }); -app.put('/todolist', function(req, res){ - var id = req.params.id; - console.log(req.body.Done); - db.contactlist.findAndModify({query: {_id: mongojs.ObjectId(id)}, - update: {$set: {name: req.body.name, email: req.body.email, number: req.body.number}}, - new: true}, function(err, doc) { - res.json(doc); +app.put('/todolist/:id', function(req, res){ + console.log(req.body); + Todo.update({_id:req.params.id},req.body,{upsert:true},function(err) { + if(!err) { + res.send('updated'); + } + else { + console.log(err); + res.send(404); + } + }); +}); + +app.delete('/todolist/:id', function(req, res){ + Todo.remove({_id: req.params.id}, function(err) { + if(!err) { + res.send('deleted'); + } + else { + console.log(err); + res.send(404); + } + }); }); -- libgit2 0.21.0