Tidied up the mobile view.

* Fixed a bug where pages other than the first page in filtered views would generate an error. It turns out to be difficult to paginate the filtered pages without increasing complexity quite a lot, so I'm leaving them unpaginated. By definition, viewing single contexts or projects should involve a much smaller subset than all the active todos.
* Edited actions were getting 'state' set to zero rather than active or completed. Fixed that and made sure that checking the 'done' box completes the action
* Changed some of the names of actions to bring them more in line with the todo_controller (i.e. list -> index, update_action -> update)
* Added functional tests for mobile actions

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@347 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2006-11-17 12:44:27 +00:00
parent 78a89ccf3b
commit 1d4c33e21d
10 changed files with 80 additions and 39 deletions

View file

@ -8,12 +8,12 @@ class MobileController < ApplicationController
layout 'mobile'
prepend_before_filter :login_required
before_filter :init, :except => :update
# Plain list of all next actions, paginated 6 per page
# Sorted by due date, then creation date
#
def list
self.init
def index
@page_title = @desc = "All actions"
@todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC',
:conditions => ['user_id = ? and state = ?', @user.id, "active"],
@ -22,14 +22,19 @@ class MobileController < ApplicationController
end
def detail
self.init
@item = check_user_return_item
@place = @item.context.id
end
def update_action
def update
if params[:id]
@item = check_user_return_item
@item = check_user_return_item
@item.update_attributes params[:item]
if params[:item][:state] == "1"
@item.state = "completed"
else
@item.state = "active"
end
else
if params[:item][:"show_from(1i)"] == ""
@item = Todo.create(params[:item]) if params[:item]
@ -42,7 +47,7 @@ class MobileController < ApplicationController
@item.user_id = @user.id
if @item.save
redirect_to :action => 'list'
redirect_to :action => 'index'
else
self.init
if params[:id]
@ -54,24 +59,23 @@ class MobileController < ApplicationController
end
def show_add_form
self.init
# Just render the view
end
def filter
self.init
@type = params[:type]
case params[:type]
when 'context'
@context = Context.find( params[:context][:id] )
@page_title = @desc = "#{@context.name}"
@todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC',
:conditions => ['user_id = ? and state = ? and context_id = ?', @user.id, "active", @context.id], :per_page => 6 )
@todos = Todo.find( :all, :order => 'due IS NULL, due ASC, created_at ASC',
:conditions => ['user_id = ? and state = ? and context_id = ?', @user.id, "active", @context.id] )
@count = @all_todos.reject { |x| x.completed? || x.context_id != @context.id }.size
when 'project'
@project = Project.find( params[:project][:id] )
@page_title = @desc = "#{@project.name}"
@todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC',
:conditions => ['user_id = ? and state = ? and project_id = ?', @user.id, "active", @project.id], :per_page => 6 )
@todos = Todo.find( :all, :order => 'due IS NULL, due ASC, created_at ASC',
:conditions => ['user_id = ? and state = ? and project_id = ?', @user.id, "active", @project.id] )
@count = @all_todos.reject { |x| x.completed? || x.project_id != @project.id }.size
end
end
@ -91,7 +95,7 @@ class MobileController < ApplicationController
def init
@contexts = @user.contexts.find(:all, :order => 'position ASC')
@projects = @user.projects.find_in_state(:all, :active, :order => 'position ASC')
@all_todos = @user.todos.find(:all, :conditions => ['state = ? or state =?', "active", "completed"])
@all_todos = @user.todos.find(:all, :conditions => ['state = ? or state = ?', "active", "completed"])
end
end