diff --git a/tracks/app/controllers/application.rb b/tracks/app/controllers/application.rb index 439bea7c..232abab0 100644 --- a/tracks/app/controllers/application.rb +++ b/tracks/app/controllers/application.rb @@ -11,7 +11,7 @@ class ApplicationController < ActionController::Base helper :application include LoginSystem - + before_filter :set_session_expiration before_filter :get_current_user diff --git a/tracks/app/controllers/mobile_controller.rb b/tracks/app/controllers/mobile_controller.rb new file mode 100644 index 00000000..2d3ae245 --- /dev/null +++ b/tracks/app/controllers/mobile_controller.rb @@ -0,0 +1,85 @@ +class MobileController < ApplicationController + + model :user + model :project + model :context + model :todo + + layout 'mobile' + + prepend_before_filter :login_required + + # Plain list of all next actions, paginated 6 per page + # Sorted by due date, then creation date + # + def list + self.init + @page_title = @desc = "All actions" + @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 ) + end + + def detail + self.init + @item = check_user_return_item + @place = @item.context.id + end + + def update_action + if params[:id] + @item = check_user_return_item + else + @item = @user.todos.build + end + + @item.attributes = params[:item] + + if @item.save + redirect_to :action => 'list' + else + flash["warning"] = "Action could not be saved" + redirect_to :action => 'list' + end + end + + def show_add_form + self.init + end + + def filter + self.init + 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 ) + 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 ) + end + end + + protected + + def check_user_return_item + item = Todo.find( params['id'] ) + if @user == item.user + return item + else + flash["warning"] = "Item and session user mis-match: #{item.user.name} and #{@user.name}!" + render_text "" + end + end + + def init + @contexts = Context.find :all, :order => 'position ASC', + :conditions => ['user_id = ?', @user.id] + @projects = Project.find :all, :order => 'position ASC', + :conditions => ['user_id = ? and done = ?', @user.id, false] + end + +end diff --git a/tracks/app/helpers/application_helper.rb b/tracks/app/helpers/application_helper.rb index cb85fe24..be708224 100644 --- a/tracks/app/helpers/application_helper.rb +++ b/tracks/app/helpers/application_helper.rb @@ -50,4 +50,65 @@ module ApplicationHelper "#{name || url}" end + + # Check due date in comparison to today's date + # Flag up date appropriately with a 'traffic light' colour code + # + def due_date(due) + if due == nil + return "" + end + + @now = Date.today + @days = due-@now + + case @days + # overdue or due very soon! sound the alarm! + when -1000..-1 + "Overdue by " + (@days * -1).to_s + " days " + when 0 + "Due Today " + when 1 + "Due Tomorrow " + # due 2-7 days away + when 2..7 + if @user.preferences["due_style"] == "1" + "Due on " + due.strftime("%A") + " " + else + "Due in " + @days.to_s + " days " + end + # more than a week away - relax + else + "Due in " + @days.to_s + " days " + end + end + + # Check due date in comparison to today's date + # Flag up date appropriately with a 'traffic light' colour code + # Modified method for mobile screen + # + def due_date_mobile(due) + if due == nil + return "" + end + + @now = Date.today + @days = due-@now + + case @days + # overdue or due very soon! sound the alarm! + when -1000..-1 + "" + format_date(due) +"" + when 0 + ""+ format_date(due) + "" + when 1 + "" + format_date(due) + "" + # due 2-7 days away + when 2..7 + "" + format_date(due) + "" + # more than a week away - relax + else + "" + format_date(due) + "" + end + end end diff --git a/tracks/app/helpers/mobile_helper.rb b/tracks/app/helpers/mobile_helper.rb new file mode 100644 index 00000000..c5b21b82 --- /dev/null +++ b/tracks/app/helpers/mobile_helper.rb @@ -0,0 +1,2 @@ +module MobileHelper +end diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index 0d982911..8faa84e0 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -63,38 +63,6 @@ module TodoHelper end end - # Check due date in comparison to today's date - # Flag up date appropriately with a 'traffic light' colour code - # - def due_date(due) - if due == nil - return "" - end - - @now = Date.today - @days = due-@now - - case @days - # overdue or due very soon! sound the alarm! - when -1000..-1 - "Overdue by " + (@days * -1).to_s + " days " - when 0 - "Due Today " - when 1 - "Due Tomorrow " - # due 2-7 days away - when 2..7 - if @user.preferences["due_style"] == "1" - "Due on " + due.strftime("%A") + " " - else - "Due in " + @days.to_s + " days " - end - # more than a week away - relax - else - "Due in " + @days.to_s + " days " - end - end - # Check show_from date in comparison to today's date # Flag up date appropriately with a 'traffic light' colour code # diff --git a/tracks/app/views/layouts/mobile.rhtml b/tracks/app/views/layouts/mobile.rhtml new file mode 100644 index 00000000..124c1eb4 --- /dev/null +++ b/tracks/app/views/layouts/mobile.rhtml @@ -0,0 +1,15 @@ + + + + + <%= stylesheet_link_tag "mobile" %> + +<%= @page_title %> + + + + +<%= yield %> + + + \ No newline at end of file diff --git a/tracks/app/views/mobile/_add_new_action_form.rhtml b/tracks/app/views/mobile/_add_new_action_form.rhtml new file mode 100644 index 00000000..2e705249 --- /dev/null +++ b/tracks/app/views/mobile/_add_new_action_form.rhtml @@ -0,0 +1,14 @@ +

+

<%= text_field( "item", "description", "size" => 25, "tabindex" => 1) %>

+

+

<%= text_area( "item", "notes", "cols" => 25, "rows" => 10, "tabindex" => 2) %>

+

+

<%= collection_select( "item", "context_id", @contexts, "id", "name", + {}, {"tabindex" => 3}) %>

+

+

<%= collection_select( "item", "project_id", @projects, "id", "name", + { :include_blank => true }, {"tabindex" => 4}) %>

+

+

<%= text_field("item", "due", "size" => 10, "tabindex" => 5, "autocomplete" => "off") %>

+<%= hidden_field("type", "new") %> +

\ No newline at end of file diff --git a/tracks/app/views/mobile/_mobile_actions.rhtml b/tracks/app/views/mobile/_mobile_actions.rhtml new file mode 100644 index 00000000..f1403518 --- /dev/null +++ b/tracks/app/views/mobile/_mobile_actions.rhtml @@ -0,0 +1,27 @@ +