Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rudimentary support for saving completed tasks. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Todos.todosController = SC.ResourceCollection.create({
});
},

watchForCompletion: function() {
if (SC.none(Todos) || SC.none(Todos.todosController)) { return }
Todos.todosController.get('content').forEach(function(t) { t.save() });
}.observes('@each.isDone'),

remaining: function() {
return this.filterProperty('isDone', false).get('length');
}.property('@each.isDone'),
Expand Down
10 changes: 10 additions & 0 deletions todos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def todo_as_json(todo)
todo_as_json(todo).to_json
end

put '/todos/:id' do
id = BSON::ObjectId(params[:id])

todos.update({ :_id => id }, { title:params[:title], isDone:params[:isDone] })

todo = todos.find_one(id)
content_type :json
todo_as_json(todo).to_json
end

delete '/todos/:id' do
todos.remove({:_id => BSON::ObjectId(params[:id])})
200
Expand Down