Made some more improvements to the mobile view:

* A count of actions in each situation is shown (i.e. all uncompleted actions on main page, all actions in context on filtered context page etc.)
* Validation errors when adding a new action are now caught and displayed on the form. I can't seem to get validation errors displayed for existing items which are being edited, but the action is (correctly) not saved.
* You can now add deferred actions through the standard form (these are not displayed on the mobile view currently).
* There's a logout link on the main page.



git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@270 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
bsag 2006-06-25 17:29:22 +00:00
parent 822ac881f6
commit 13e2a13ca5
9 changed files with 55 additions and 32 deletions

View file

@ -18,6 +18,7 @@ class MobileController < ApplicationController
@todos_pages, @todos = paginate( :todos, :order => 'due IS NULL, due ASC, created_at ASC',
:conditions => ['user_id = ? and type = ? and done = ?', @user.id, "Immediate", false],
:per_page => 6 )
@count = @all_todos.reject { |x| x.done? || x.context.hide? }.size
end
def detail
@ -30,16 +31,24 @@ class MobileController < ApplicationController
if params[:id]
@item = check_user_return_item
else
@item = @user.todos.build
if params[:item][:"show_from(1i)"] == ""
@item = Immediate.create(params[:item]) if params[:item]
else
@item = Deferred.create(params[:item]) if params[:item]
end
end
@item.attributes = params[:item]
@item.user_id = @user.id
if @item.save
redirect_to :action => 'list'
else
flash["warning"] = "Action could not be saved"
redirect_to :action => 'list'
self.init
if params[:id]
render :partial => 'mobile_edit'
else
render :action => 'show_add_form'
end
end
end
@ -49,17 +58,20 @@ class MobileController < ApplicationController
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 type = ? and done = ? and context_id = ?', @user.id, "Immediate", false, @context.id], :per_page => 6 )
@count = @all_todos.reject { |x| x.done? || 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 type = ? and done = ? and project_id = ?', @user.id, "Immediate", false, @project.id], :per_page => 6 )
@count = @all_todos.reject { |x| x.done? || x.project_id != @project.id }.size
end
end
@ -80,6 +92,7 @@ class MobileController < ApplicationController
:conditions => ['user_id = ?', @user.id]
@projects = Project.find :all, :order => 'position ASC',
:conditions => ['user_id = ? and done = ?', @user.id, false]
@all_todos = Todo.find(:all, :conditions => ['user_id = ? and type = ?', @user.id, "Immediate"])
end
end

View file

@ -1,14 +0,0 @@
<p><label for="item_description">Description</label></p>
<p><%= text_field( "item", "description", "size" => 25, "tabindex" => 1) %></p>
<p><label for="item_notes">Notes</label></p>
<p><%= text_area( "item", "notes", "cols" => 25, "rows" => 10, "tabindex" => 2) %></p>
<p><label for="item_context_id">Context</label></p>
<p><%= collection_select( "item", "context_id", @contexts, "id", "name",
{}, {"tabindex" => 3}) %></p>
<p><label for="item_project_id">Project</label></p>
<p><%= collection_select( "item", "project_id", @projects, "id", "name",
{ :include_blank => true }, {"tabindex" => 4}) %></p>
<p><label for="item_due">Due</label></p>
<p><%= text_field("item", "due", "size" => 10, "tabindex" => 5, "autocomplete" => "off") %></p>
<%= hidden_field("type", "new") %>
<p><input type="submit" value="Add action" tabindex="6"></p>

View file

@ -1,3 +1,6 @@
<% if @todos.length == 0 -%>
<p>There are no uncompleted actions in this <%= @type %></p>
<% else -%>
<ul>
<% for todo in @todos -%>
<li>
@ -10,9 +13,11 @@
<% end -%>
</li>
<ul>
<hr />
Pages: <%= pagination_links( @todos_pages, :always_show_anchors => true ) %>
<% if @todos_pages.length > 1 -%>
<hr />
Pages: <%= pagination_links( @todos_pages, :always_show_anchors => true ) %>
<% end -%>
<% end -%>
<hr />
<%= form_tag( { :action => "filter", :type => "context" } ) %>
<%= collection_select( "context", "id", @contexts, "id", "name",

View file

@ -1,4 +1,7 @@
<span class="errors">
<%= 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_description">Next action</label></p>
@ -10,5 +13,9 @@
<p><%= collection_select( "item", "project_id", @projects, "id", "name",
{:include_blank => true}, {"tabindex" => 5} ) %></p>
<p><label for="item_due">Due</label></p>
<p><%= date_select("item", "due", :order => [:day, :month, :year], :include_blank => true) %></p>
<p><%= date_select("item", "due", :order => [:day, :month, :year],
:start_year => this_year, :include_blank => true) %></p>
<p><label for="item_show_from">Show from</label></p>
<p><%= date_select("item", "show_from", :order => [:day, :month, :year],
:start_year => this_year, :include_blank => true) %></p>
<p><input type="submit" value="Update" tabindex="6" /></p>

View file

@ -1,4 +1,4 @@
<%= form_tag :action => 'update_action', :id => @item.id %>
<%= render :partial => 'mobile_edit', :locals => {:type => "updated"} %>
<%= render :partial => 'mobile_edit' %>
<%= end_form_tag %>
<%= button_to "Back", :controller => 'mobile', :action => 'list' %>

View file

@ -1,5 +1,6 @@
<h1><%= @desc %>
<h1><span class="count"><%= @count.to_s %></span> <%= @desc %>
<%= link_to "+", :controller => 'mobile', :action => 'add_action' %></h1>
<hr />
<%= render :partial => 'mobile_actions' %>
<%= link_to "View All", :controller => 'mobile', :action => 'list' %>

View file

@ -1,4 +1,6 @@
<h1><%= @desc %>
<h1><span class="count"><%= @count.to_s %></span> <%= @desc %>
<%= puts params[:item].to_s %>
<%= link_to "+", :controller => 'mobile', :action => 'show_add_form' %></h1>
<hr />
<%= render :partial => 'mobile_actions' %>
<%= render :partial => 'mobile_actions' %>
<%= link_to "Logout", :controller => 'login', :action => 'logout' %>

View file

@ -1,4 +1,4 @@
<%= form_tag :action => 'update_action' %>
<%= render :partial => 'mobile_edit', :locals => {:type => "new"} %>
<%= render :partial => 'mobile_edit' %>
<%= end_form_tag %>
<%= button_to "Back", :controller => 'mobile', :action => 'list' %>

View file

@ -11,32 +11,41 @@ ul {list-style-type: none;}
background: #f00;
padding: 1px;
font-size: 10px;
}
}
.amber {
color: #fff;
background: #ff6600;
padding: 1px;
font-size: 10px;
}
}
.orange {
color: #fff;
background: #FFA500;
padding: 1px;
font-size: 10px;
}
}
.green {
color: #fff;
background: #33cc00;
padding: 1px;
font-size: 10px;
}
}
.grey {
color: #fff;
background: #999;
padding: 1px;
font-size: 10px;
}
}
.count {
color: #fff;
background: #000;
}
.errors {
background: #FFC2C2;
}