From 1d4c33e21d59b8b81e50f452f695aa097fb33f9a Mon Sep 17 00:00:00 2001 From: bsag Date: Fri, 17 Nov 2006 12:44:27 +0000 Subject: [PATCH] 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 --- tracks/app/controllers/mobile_controller.rb | 30 +++++++------ tracks/app/views/mobile/_mobile_actions.rhtml | 10 +++-- tracks/app/views/mobile/_mobile_edit.rhtml | 4 +- tracks/app/views/mobile/detail.rhtml | 4 +- tracks/app/views/mobile/filter.rhtml | 2 +- .../views/mobile/{list.rhtml => index.rhtml} | 3 +- tracks/app/views/mobile/show_add_form.rhtml | 4 +- tracks/config/routes.rb | 2 +- tracks/db/schema.rb | 18 ++++---- .../test/functional/mobile_controller_test.rb | 42 +++++++++++++++++-- 10 files changed, 80 insertions(+), 39 deletions(-) rename tracks/app/views/mobile/{list.rhtml => index.rhtml} (62%) diff --git a/tracks/app/controllers/mobile_controller.rb b/tracks/app/controllers/mobile_controller.rb index 55f80ace..2d257e40 100644 --- a/tracks/app/controllers/mobile_controller.rb +++ b/tracks/app/controllers/mobile_controller.rb @@ -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 diff --git a/tracks/app/views/mobile/_mobile_actions.rhtml b/tracks/app/views/mobile/_mobile_actions.rhtml index feaa71c4..b1f45731 100644 --- a/tracks/app/views/mobile/_mobile_actions.rhtml +++ b/tracks/app/views/mobile/_mobile_actions.rhtml @@ -13,10 +13,12 @@ <% end -%>