From 2ca153a771f6f690e23f223a7cf3c35fecbb8e66 Mon Sep 17 00:00:00 2001 From: bsag Date: Sun, 18 Jun 2006 17:17:34 +0000 Subject: [PATCH] Implemented a proper mobile view, designed for viewing on a mobile phone browser (so far only tested on 'small screen' view of Opera, which mimics Opera mini). To get the mobile view, enter the URL http://yoururl.com/mobile/ That will take you to the login page, and then to the mobile view. I've tried to make the interface as functional as possible, while still fitting neatly on a small screen, being very lightweight in terms of page size (those data plans are expensive!), and not requiring too much messing about with a phone keyboard. The main screen lists all uncompleted next actions, 6 per page. If you select the double right arrow link, you'll be taken to a detail view which doubles as a place to view all the details, or an editing page (hit the back button to get back if you're just viewing, update to commit your edits). At the bottom of each page there are two select boxes which allow you to filter the view to a particular context or project. It needs a little more work, but it's quite functional right now. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@263 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/application.rb | 2 +- tracks/app/controllers/mobile_controller.rb | 85 +++++++++++++++++++ tracks/app/helpers/application_helper.rb | 61 +++++++++++++ tracks/app/helpers/mobile_helper.rb | 2 + tracks/app/helpers/todo_helper.rb | 32 ------- tracks/app/views/layouts/mobile.rhtml | 15 ++++ .../views/mobile/_add_new_action_form.rhtml | 14 +++ tracks/app/views/mobile/_mobile_actions.rhtml | 27 ++++++ tracks/app/views/mobile/_mobile_edit.rhtml | 14 +++ tracks/app/views/mobile/detail.rhtml | 4 + tracks/app/views/mobile/filter.rhtml | 5 ++ tracks/app/views/mobile/list.rhtml | 4 + tracks/app/views/mobile/show_add_form.rhtml | 4 + tracks/config/routes.rb | 4 + tracks/public/stylesheets/mobile.css | 42 +++++++++ .../test/functional/mobile_controller_test.rb | 18 ++++ 16 files changed, 300 insertions(+), 33 deletions(-) create mode 100644 tracks/app/controllers/mobile_controller.rb create mode 100644 tracks/app/helpers/mobile_helper.rb create mode 100644 tracks/app/views/layouts/mobile.rhtml create mode 100644 tracks/app/views/mobile/_add_new_action_form.rhtml create mode 100644 tracks/app/views/mobile/_mobile_actions.rhtml create mode 100644 tracks/app/views/mobile/_mobile_edit.rhtml create mode 100644 tracks/app/views/mobile/detail.rhtml create mode 100644 tracks/app/views/mobile/filter.rhtml create mode 100644 tracks/app/views/mobile/list.rhtml create mode 100644 tracks/app/views/mobile/show_add_form.rhtml create mode 100644 tracks/public/stylesheets/mobile.css create mode 100644 tracks/test/functional/mobile_controller_test.rb 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 @@ +