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 -%>
-<% if @todos_pages.length > 1 -%>
-
- Pages: <%= pagination_links( @todos_pages, :always_show_anchors => true ) %>
-<% end -%>
+ <% if !@todos_pages.nil? -%>
+ <% if @todos_pages.length > 1 -%>
+
+ Pages: <%= pagination_links( @todos_pages, :always_show_anchors => true ) %>
+ <% end -%>
+ <% end -%>
<% end -%>
<%= form_tag( { :action => "filter", :type => "context" } ) %>
diff --git a/tracks/app/views/mobile/_mobile_edit.rhtml b/tracks/app/views/mobile/_mobile_edit.rhtml
index eaec4baf..f1a5675d 100644
--- a/tracks/app/views/mobile/_mobile_edit.rhtml
+++ b/tracks/app/views/mobile/_mobile_edit.rhtml
@@ -2,8 +2,8 @@
<%= error_messages_for("item") %>
<% this_year = Date.today.strftime("%Y").to_i -%>
-
-<%= check_box("item", "done", "tabindex" => 1) %>
+
+<%= check_box( "item", "state", "tabindex" => 1) %>
<%= text_field( "item", "description", "tabindex" => 2) %>
diff --git a/tracks/app/views/mobile/detail.rhtml b/tracks/app/views/mobile/detail.rhtml
index d8f09459..4560aa75 100644
--- a/tracks/app/views/mobile/detail.rhtml
+++ b/tracks/app/views/mobile/detail.rhtml
@@ -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' %>
\ No newline at end of file
+<%= button_to "Back", :controller => 'mobile', :action => 'index' %>
\ No newline at end of file
diff --git a/tracks/app/views/mobile/filter.rhtml b/tracks/app/views/mobile/filter.rhtml
index 05c85777..23c6f607 100644
--- a/tracks/app/views/mobile/filter.rhtml
+++ b/tracks/app/views/mobile/filter.rhtml
@@ -3,4 +3,4 @@
<%= render :partial => 'mobile_actions' %>
-<%= link_to "View All", :controller => 'mobile', :action => 'list' %>
\ No newline at end of file
+<%= link_to "View All", :controller => 'mobile', :action => 'index' %>
\ No newline at end of file
diff --git a/tracks/app/views/mobile/list.rhtml b/tracks/app/views/mobile/index.rhtml
similarity index 62%
rename from tracks/app/views/mobile/list.rhtml
rename to tracks/app/views/mobile/index.rhtml
index 31b0d72c..8fab21bd 100644
--- a/tracks/app/views/mobile/list.rhtml
+++ b/tracks/app/views/mobile/index.rhtml
@@ -1,6 +1,5 @@
<%= @count.to_s %> <%= @desc %>
- <%= puts params[:item].to_s %>
-<%= link_to "+", :controller => 'mobile', :action => 'show_add_form' %>
+<%= link_to "+", :controller => 'mobile', :action => 'add_action' %>
<%= render :partial => 'mobile_actions' %>
<%= link_to "Logout", :controller => 'login', :action => 'logout' %>
\ No newline at end of file
diff --git a/tracks/app/views/mobile/show_add_form.rhtml b/tracks/app/views/mobile/show_add_form.rhtml
index f09cd2b7..7441b50f 100644
--- a/tracks/app/views/mobile/show_add_form.rhtml
+++ b/tracks/app/views/mobile/show_add_form.rhtml
@@ -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' %>
\ No newline at end of file
+<%= button_to "Back", :controller => 'mobile', :action => 'index' %>
\ No newline at end of file
diff --git a/tracks/config/routes.rb b/tracks/config/routes.rb
index 9af9eadf..0ebdcae4 100644
--- a/tracks/config/routes.rb
+++ b/tracks/config/routes.rb
@@ -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
diff --git a/tracks/db/schema.rb b/tracks/db/schema.rb
index dab4a41e..2246ed71 100644
--- a/tracks/db/schema.rb
+++ b/tracks/db/schema.rb
@@ -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
diff --git a/tracks/test/functional/mobile_controller_test.rb b/tracks/test/functional/mobile_controller_test.rb
index e4995504..e37718f0 100644
--- a/tracks/test/functional/mobile_controller_test.rb
+++ b/tracks/test/functional/mobile_controller_test.rb
@@ -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