home page is restored, so is context view

This commit is contained in:
Reinier Balt 2012-04-12 17:30:05 +02:00
parent 4605b17d3c
commit e964769553
130 changed files with 89 additions and 152 deletions

View file

@ -95,10 +95,10 @@ class ApplicationController < ActionController::Base
if count == 0 && deferred_count > 0
word = deferred_count == 1 ? string.singularize : string.pluralize
word = "deferred&nbsp;" + word
deferred_count.to_s + "&nbsp;" + word
return (deferred_count.to_s + "&nbsp;" + word).html_safe
else
word = count == 1 ? string.singularize : string.pluralize
count.to_s + "&nbsp;" + word
return (count.to_s + "&nbsp;" + word).html_safe
end
end

View file

@ -1,73 +0,0 @@
class CannotAccessContext < RuntimeError; end
class BackendController < ApplicationController
acts_as_web_service
wsdl_service_name 'Backend'
web_service_api TodoApi
web_service_scaffold :invoke
skip_before_filter :login_required
def new_todo(username, token, context_id, description, notes)
check_token(username, token)
check_context_belongs_to_user(context_id)
item = create_todo(description, context_id, nil, notes)
item.id
end
def new_todo_for_project(username, token, context_id, project_id, description, notes)
check_token(username, token)
check_context_belongs_to_user(context_id)
item = create_todo(description, context_id, project_id, notes)
item.id
end
def new_rich_todo(username, token, default_context_id, description, notes)
check_token(username,token)
item = Todo.from_rich_message(@user, default_context_id, description, notes)
item.save
raise item.errors.full_messages.to_s if item.new_record?
item.id
end
def list_contexts(username, token)
check_token(username, token)
@user.contexts
end
def list_projects(username, token)
check_token(username, token)
@user.projects
end
private
# Check whether the token in the URL matches the token in the User's table
def check_token(username, token)
@user = User.find_by_login( username )
unless (token == @user.token)
raise(InvalidToken, "Sorry, you don't have permission to perform this action.")
end
end
def check_context_belongs_to_user(context_id)
unless @user.contexts.exists? context_id
raise(CannotAccessContext, "Cannot access a context that does not belong to this user.")
end
end
def create_todo(description, context_id, project_id = nil, notes="")
item = @user.todos.build
item.description = description
item.notes = notes
item.context_id = context_id
item.project_id = project_id unless project_id.nil?
item.save
raise item.errors.full_messages.to_s if item.new_record?
item
end
end
class InvalidToken < RuntimeError; end

View file

@ -263,7 +263,7 @@ class ContextsController < ApplicationController
end
def set_context_from_params
@context = current_user.contexts.find_by_params(params)
@context = current_user.contexts.find(params[:id])
rescue
@context = nil
end
@ -276,11 +276,8 @@ class ContextsController < ApplicationController
def init_todos
set_context_from_params
unless @context.nil?
@context.todos.send :with_scope, :find => { :include => Todo::DEFAULT_INCLUDES } do
@done = @context.done_todos
end
@max_completed = current_user.prefs.show_number_completed
@done = @context.todos.completed.all(:limit => @max_completed)
# @not_done_todos = @context.not_done_todos TODO: Temporarily doing this
# search manually until I can work out a way to do the same thing using