mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-29 13:28:49 +01:00
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:
parent
78a89ccf3b
commit
1d4c33e21d
10 changed files with 80 additions and 39 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -13,10 +13,12 @@
|
|||
<% end -%>
|
||||
</li>
|
||||
<ul>
|
||||
<% if @todos_pages.length > 1 -%>
|
||||
<hr />
|
||||
Pages: <%= pagination_links( @todos_pages, :always_show_anchors => true ) %>
|
||||
<% end -%>
|
||||
<% if !@todos_pages.nil? -%>
|
||||
<% if @todos_pages.length > 1 -%>
|
||||
<hr />
|
||||
Pages: <%= pagination_links( @todos_pages, :always_show_anchors => true ) %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<hr />
|
||||
<%= form_tag( { :action => "filter", :type => "context" } ) %>
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
<%= error_messages_for("item") %>
|
||||
</span>
|
||||
<% this_year = Date.today.strftime("%Y").to_i -%>
|
||||
<p><label for="item_done">Done?</label></p>
|
||||
<p><%= check_box("item", "done", "tabindex" => 1) %></p>
|
||||
<p><label for="item_state">Done?</label></p>
|
||||
<p><%= check_box( "item", "state", "tabindex" => 1) %></p>
|
||||
<p><label for="item_description">Next action</label></p>
|
||||
<p><%= text_field( "item", "description", "tabindex" => 2) %></p>
|
||||
<p><label for="item_notes">Notes</label></p>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_tag :action => 'update_action', :id => @item.id %>
|
||||
<%= form_tag :action => 'update', :id => @item.id %>
|
||||
<%= render :partial => 'mobile_edit' %>
|
||||
<%= end_form_tag %>
|
||||
<%= button_to "Back", :controller => 'mobile', :action => 'list' %>
|
||||
<%= button_to "Back", :controller => 'mobile', :action => 'index' %>
|
||||
|
|
@ -3,4 +3,4 @@
|
|||
<hr />
|
||||
<%= render :partial => 'mobile_actions' %>
|
||||
|
||||
<%= link_to "View All", :controller => 'mobile', :action => 'list' %>
|
||||
<%= link_to "View All", :controller => 'mobile', :action => 'index' %>
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<h1><span class="count"><%= @count.to_s %></span> <%= @desc %>
|
||||
<%= puts params[:item].to_s %>
|
||||
<%= link_to "+", :controller => 'mobile', :action => 'show_add_form' %></h1>
|
||||
<%= link_to "+", :controller => 'mobile', :action => 'add_action' %></h1>
|
||||
<hr />
|
||||
<%= render :partial => 'mobile_actions' %>
|
||||
<%= link_to "Logout", :controller => 'login', :action => 'logout' %>
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<%= form_tag :action => 'update_action' %>
|
||||
<%= form_tag :action => 'update' %>
|
||||
<%= render :partial => 'mobile_edit' %>
|
||||
<%= end_form_tag %>
|
||||
<%= button_to "Back", :controller => 'mobile', :action => 'list' %>
|
||||
<%= button_to "Back", :controller => 'mobile', :action => 'index' %>
|
||||
|
|
@ -18,7 +18,7 @@ ActionController::Routing::Routes.draw do |map|
|
|||
map.connect '', :controller => 'todo', :action => 'index'
|
||||
|
||||
# Mobile/lite version
|
||||
map.connect 'mobile', :controller => 'mobile', :action => 'list'
|
||||
map.connect 'mobile', :controller => 'mobile', :action => 'index'
|
||||
map.connect 'mobile/add_action', :controller => 'mobile', :action => 'show_add_form'
|
||||
|
||||
# Login Routes
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ ActiveRecord::Schema.define(:version => 20) do
|
|||
|
||||
create_table "contexts", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "hide", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
t.column "hide", :boolean, :default => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
end
|
||||
|
||||
create_table "notes", :force => true do |t|
|
||||
|
|
@ -56,7 +56,7 @@ ActiveRecord::Schema.define(:version => 20) do
|
|||
create_table "projects", :force => true do |t|
|
||||
t.column "name", :string, :default => "", :null => false
|
||||
t.column "position", :integer, :default => 0, :null => false
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "description", :text
|
||||
t.column "state", :string, :limit => 20, :default => "active", :null => false
|
||||
end
|
||||
|
|
@ -71,22 +71,22 @@ ActiveRecord::Schema.define(:version => 20) do
|
|||
|
||||
create_table "todos", :force => true do |t|
|
||||
t.column "context_id", :integer, :default => 0, :null => false
|
||||
t.column "description", :string, :limit => 100, :default => "", :null => false
|
||||
t.column "project_id", :integer
|
||||
t.column "description", :string, :default => "", :null => false
|
||||
t.column "notes", :text
|
||||
t.column "created_at", :datetime
|
||||
t.column "due", :date
|
||||
t.column "completed_at", :datetime
|
||||
t.column "project_id", :integer
|
||||
t.column "user_id", :integer, :default => 0, :null => false
|
||||
t.column "user_id", :integer, :default => 1
|
||||
t.column "show_from", :date
|
||||
t.column "state", :string, :limit => 20, :default => "immediate", :null => false
|
||||
end
|
||||
|
||||
create_table "users", :force => true do |t|
|
||||
t.column "login", :string, :limit => 80
|
||||
t.column "password", :string, :limit => 40
|
||||
t.column "login", :string, :limit => 80, :default => "", :null => false
|
||||
t.column "password", :string, :limit => 40, :default => "", :null => false
|
||||
t.column "word", :string
|
||||
t.column "is_admin", :integer, :limit => 4, :default => 0, :null => false
|
||||
t.column "is_admin", :boolean, :default => false, :null => false
|
||||
t.column "first_name", :string
|
||||
t.column "last_name", :string
|
||||
t.column "auth_type", :string, :default => "database", :null => false
|
||||
|
|
|
|||
|
|
@ -5,14 +5,50 @@ require 'mobile_controller'
|
|||
class MobileController; def rescue_action(e) raise e end; end
|
||||
|
||||
class MobileControllerTest < Test::Unit::TestCase
|
||||
fixtures :users, :preferences, :projects, :contexts, :todos
|
||||
|
||||
def setup
|
||||
@controller = MobileController.new
|
||||
@request = ActionController::TestRequest.new
|
||||
@response = ActionController::TestResponse.new
|
||||
end
|
||||
|
||||
# Replace this with your real tests.
|
||||
def test_truth
|
||||
assert true
|
||||
def test_get_index_when_not_logged_in
|
||||
get :index
|
||||
assert_redirected_to :controller => 'login', :action => 'login'
|
||||
end
|
||||
|
||||
def test_create_item
|
||||
@count = Todo.find(:all)
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
xhr :post, :update, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "notes"=>"", "description"=>"Invest in spam stock offer", "due"=>"01/01/2007"}
|
||||
@todos = Todo.find(:all)
|
||||
assert_equal @count.size+1, @todos.size
|
||||
t = Todo.find(15)
|
||||
assert_equal "Invest in spam stock offer", t.description
|
||||
assert_equal Date.parse("01/01/2007"), t.due
|
||||
assert_equal users(:admin_user).id, t.user_id
|
||||
assert_equal 1, t.context_id
|
||||
assert_equal 2, t.project_id
|
||||
assert_equal "active", t.state
|
||||
end
|
||||
|
||||
def test_update_item
|
||||
t = Todo.find(1)
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Warren Buffet to find out how much he makes per day", "due"=>"11/30/2006"}
|
||||
t = Todo.find(1)
|
||||
assert_equal "Call Warren Buffet to find out how much he makes per day", t.description
|
||||
assert_equal Date.parse("11/30/2006"), t.due
|
||||
assert_equal users(:admin_user).id, t.user_id
|
||||
assert_equal "active", t.state
|
||||
end
|
||||
|
||||
def test_complete_item
|
||||
t = Todo.find(1)
|
||||
@request.session['user_id'] = users(:admin_user).id
|
||||
xhr :post, :update, :id => 1, :_source_view => 'todo', "item"=>{"context_id"=>"1", "project_id"=>"2", "id"=>"1", "notes"=>"", "description"=>"Call Bill Gates to find out how much he makes per day", "state"=>"1"}
|
||||
t = Todo.find(1)
|
||||
assert_equal "completed", t.state
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue