From 6e5b574406be7d2829cfbeb69799d674a65a9852 Mon Sep 17 00:00:00 2001 From: lukemelia Date: Sat, 30 Dec 2006 09:52:39 +0000 Subject: [PATCH] First step in adding deferred section to the project detail page. Ajax needs a lot of work on this page. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@385 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/project_controller.rb | 13 +- tracks/app/views/project/show.rhtml | 3 +- tracks/app/views/todo/_deferred.rhtml | 18 ++ tracks/db/schema.rb | 192 +++++++++--------- tracks/lib/todo_list.rb | 9 + .../functional/project_controller_test.rb | 15 ++ tracks/test/unit/project_test.rb | 18 +- .../connection_adapters/sqlserver_adapter.rb | 2 +- 8 files changed, 159 insertions(+), 111 deletions(-) create mode 100644 tracks/app/views/todo/_deferred.rhtml diff --git a/tracks/app/controllers/project_controller.rb b/tracks/app/controllers/project_controller.rb index 7040a1c8..ded7bd15 100644 --- a/tracks/app/controllers/project_controller.rb +++ b/tracks/app/controllers/project_controller.rb @@ -2,7 +2,6 @@ class ProjectController < ApplicationController helper :todo before_filter :init, :except => [:create, :destroy, :order, :toggle_project_done] - before_filter :init_todos, :only => :show def index init_project_hidden_todo_counts @@ -17,7 +16,12 @@ class ProjectController < ApplicationController # e.g. /project/show/ shows just . # def show + check_user_set_project @page_title = "TRACKS::Project: #{@project.name}" + @not_done = @project.not_done_todos(:include_project_hidden_todos => true) + @deferred = @project.deferred_todos + @done = @project.done_todos + @count = @not_done.size end # Example XML usage: curl -H 'Accept: application/xml' -H 'Content-Type: application/xml' @@ -167,11 +171,4 @@ class ProjectController < ApplicationController init_data_for_sidebar end - def init_todos - check_user_set_project - @done = @project.done_todos - @not_done = @project.not_done_todos(:include_project_hidden_todos => true) - @count = @not_done.size - end - end diff --git a/tracks/app/views/project/show.rhtml b/tracks/app/views/project/show.rhtml index d120ba58..27bd894a 100644 --- a/tracks/app/views/project/show.rhtml +++ b/tracks/app/views/project/show.rhtml @@ -1,6 +1,7 @@
- + <%= render :partial => "project/project", :locals => { :project => @project, :collapsible => false } %> +<%= render :partial => "todo/deferred", :locals => { :deferred => @deferred, :collapsible => false, :append_descriptor => "in this project" } %> <%= render :partial => "todo/completed", :locals => { :done => @done, :collapsible => false, :append_descriptor => "in this project" } %>
diff --git a/tracks/app/views/todo/_deferred.rhtml b/tracks/app/views/todo/_deferred.rhtml new file mode 100644 index 00000000..62a3484c --- /dev/null +++ b/tracks/app/views/todo/_deferred.rhtml @@ -0,0 +1,18 @@ +<% suffix = append_descriptor ? append_descriptor : '' -%> +
+

+ <% if collapsible %> + <%= image_tag("collapse.png") %> + <% end %> + Deferred actions <%= append_descriptor ? append_descriptor : '' %> +

+ +
+
+

Currently there are no deferred actions

+
+ + <%= render :partial => "todo/item", :collection => deferred, :locals => { :parent_container_type => 'tickler' } %> + +
+
\ No newline at end of file diff --git a/tracks/db/schema.rb b/tracks/db/schema.rb index e16f95d1..ccb5a200 100644 --- a/tracks/db/schema.rb +++ b/tracks/db/schema.rb @@ -1,96 +1,96 @@ -# This file is autogenerated. Instead of editing this file, please use the -# migrations feature of ActiveRecord to incrementally modify your database, and -# then regenerate this schema definition. - -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 - end - - create_table "notes", :force => true do |t| - t.column "user_id", :integer, :default => 0, :null => false - t.column "project_id", :integer, :default => 0, :null => false - t.column "body", :text - t.column "created_at", :datetime - t.column "updated_at", :datetime - end - - create_table "open_id_associations", :force => true do |t| - t.column "server_url", :binary - t.column "handle", :string - t.column "secret", :binary - t.column "issued", :integer - t.column "lifetime", :integer - t.column "assoc_type", :string - end - - create_table "open_id_nonces", :force => true do |t| - t.column "nonce", :string - t.column "created", :integer - end - - create_table "open_id_settings", :force => true do |t| - t.column "setting", :string - t.column "value", :binary - end - - create_table "preferences", :force => true do |t| - t.column "user_id", :integer, :default => 0, :null => false - t.column "date_format", :string, :limit => 40, :default => "%d/%m/%Y", :null => false - t.column "week_starts", :integer, :default => 0, :null => false - t.column "show_number_completed", :integer, :default => 5, :null => false - t.column "staleness_starts", :integer, :default => 7, :null => false - t.column "show_completed_projects_in_sidebar", :boolean, :default => true, :null => false - t.column "show_hidden_contexts_in_sidebar", :boolean, :default => true, :null => false - t.column "due_style", :integer, :default => 0, :null => false - t.column "admin_email", :string, :default => "butshesagirl@rousette.org.uk", :null => false - t.column "refresh", :integer, :default => 0, :null => false - t.column "verbose_action_descriptors", :boolean, :default => false, :null => false - t.column "show_hidden_projects_in_sidebar", :boolean, :default => true, :null => false - end - - 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 "description", :text - t.column "state", :string, :limit => 20, :default => "active", :null => false - end - - create_table "sessions", :force => true do |t| - t.column "session_id", :string - t.column "data", :text - t.column "updated_at", :datetime - end - - add_index "sessions", ["session_id"], :name => "sessions_session_id_index" - - 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 "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 "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 "word", :string - t.column "is_admin", :integer, :limit => 4, :default => 0, :null => false - t.column "first_name", :string - t.column "last_name", :string - t.column "auth_type", :string, :default => "database", :null => false - t.column "open_id_url", :string - end - -end +# This file is autogenerated. Instead of editing this file, please use the +# migrations feature of ActiveRecord to incrementally modify your database, and +# then regenerate this schema definition. + +ActiveRecord::Schema.define(:version => 20) do + + create_table "contexts", :force => true do |t| + t.column "name", :string, :default => "", :null => false + t.column "position", :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| + t.column "user_id", :integer, :default => 0, :null => false + t.column "project_id", :integer, :default => 0, :null => false + t.column "body", :text + t.column "created_at", :datetime + t.column "updated_at", :datetime + end + + create_table "open_id_associations", :force => true do |t| + t.column "server_url", :binary + t.column "handle", :string + t.column "secret", :binary + t.column "issued", :integer + t.column "lifetime", :integer + t.column "assoc_type", :string + end + + create_table "open_id_nonces", :force => true do |t| + t.column "nonce", :string + t.column "created", :integer + end + + create_table "open_id_settings", :force => true do |t| + t.column "setting", :string + t.column "value", :binary + end + + create_table "preferences", :force => true do |t| + t.column "user_id", :integer, :default => 0, :null => false + t.column "date_format", :string, :limit => 40, :default => "%d/%m/%Y", :null => false + t.column "week_starts", :integer, :default => 0, :null => false + t.column "show_number_completed", :integer, :default => 5, :null => false + t.column "staleness_starts", :integer, :default => 7, :null => false + t.column "show_completed_projects_in_sidebar", :boolean, :default => true, :null => false + t.column "show_hidden_contexts_in_sidebar", :boolean, :default => true, :null => false + t.column "due_style", :integer, :default => 0, :null => false + t.column "admin_email", :string, :default => "butshesagirl@rousette.org.uk", :null => false + t.column "refresh", :integer, :default => 0, :null => false + t.column "verbose_action_descriptors", :boolean, :default => false, :null => false + t.column "show_hidden_projects_in_sidebar", :boolean, :default => true, :null => false + end + + 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 => 1 + t.column "description", :text + t.column "state", :string, :limit => 20, :default => "active", :null => false + end + + create_table "sessions", :force => true do |t| + t.column "session_id", :string + t.column "data", :text + t.column "updated_at", :datetime + end + + add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id" + + create_table "todos", :force => true do |t| + t.column "context_id", :integer, :default => 0, :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 "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, :default => "", :null => false + t.column "password", :string, :limit => 40, :default => "", :null => false + t.column "word", :string + 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 + t.column "open_id_url", :string + end + +end diff --git a/tracks/lib/todo_list.rb b/tracks/lib/todo_list.rb index c13a4420..e4dd6baf 100644 --- a/tracks/lib/todo_list.rb +++ b/tracks/lib/todo_list.rb @@ -8,11 +8,20 @@ module Tracks def done_todos @done_todos ||= self.find_done_todos end + + def deferred_todos + @deferred_todos ||= self.find_deferred_todos + end def find_not_done_todos(opts={}) self.todos.find(:all, :conditions => not_done_conditions(opts), :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC") end + + def find_deferred_todos(opts={}) + self.todos.find(:all, :conditions => ["todos.state = ?", "deferred"], + :order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC") + end def not_done_conditions(opts) conditions = ["todos.state = ?", 'active'] diff --git a/tracks/test/functional/project_controller_test.rb b/tracks/test/functional/project_controller_test.rb index 436522af..2b95e178 100644 --- a/tracks/test/functional/project_controller_test.rb +++ b/tracks/test/functional/project_controller_test.rb @@ -16,6 +16,21 @@ class ProjectControllerTest < TodoContainerControllerTestBase @request.session['user_id'] = users(:admin_user).id get :index end + + def test_show_exposes_deferred_todos + @request.session['user_id'] = users(:admin_user).id + p = projects(:timemachine) + get :show, :url_friendly_name => p.url_friendly_name + assert_not_nil assigns['deferred'] + assert_equal 0, assigns['deferred'].size + + t = p.not_done_todos[0] + t.show_from = 1.days.from_now.to_date + t.save! + + get :show, :url_friendly_name => p.url_friendly_name + assert_equal 1, assigns['deferred'].size + end def test_create_project_via_ajax_increments_number_of_projects assert_ajax_create_increments_count 'My New Project' diff --git a/tracks/test/unit/project_test.rb b/tracks/test/unit/project_test.rb index a1118d6d..4a9dc77c 100644 --- a/tracks/test/unit/project_test.rb +++ b/tracks/test/unit/project_test.rb @@ -2,12 +2,12 @@ require File.dirname(__FILE__) + '/../test_helper' class ProjectTest < Test::Unit::TestCase fixtures :projects, :todos, :users, :preferences - + def setup @timemachine = projects(:timemachine) @moremoney = projects(:moremoney) end - + def test_validate_presence_of_name @timemachine.name = "" assert !@timemachine.save @@ -30,7 +30,7 @@ class ProjectTest < Test::Unit::TestCase assert_equal 1, newproj.errors.count assert_equal "already exists", newproj.errors.on(:name) end - + def test_validate_name_does_not_contain_slash newproj = Project.new newproj.name = "Save Earth/Mankind from Evil" @@ -67,7 +67,7 @@ class ProjectTest < Test::Unit::TestCase assert_not_nil p assert_equal @timemachine.id, p.id end - + def test_find_project_by_namepart_with_starts_with p = Project.find_by_namepart('Build a') assert_not_nil p @@ -90,7 +90,7 @@ class ProjectTest < Test::Unit::TestCase t.save! assert_equal 1, Project.find(@timemachine.id).not_done_todos.size end - + def test_done_todos assert_equal 0, @timemachine.done_todos.size t = @timemachine.not_done_todos[0] @@ -99,6 +99,14 @@ class ProjectTest < Test::Unit::TestCase assert_equal 1, Project.find(@timemachine.id).done_todos.size end + def test_deferred_todos + assert_equal 0, @timemachine.deferred_todos.size + t = @timemachine.not_done_todos[0] + t.show_from = 1.days.from_now.to_date + t.save! + assert_equal 1, Project.find(@timemachine.id).deferred_todos.size + end + def test_url_friendly_name_for_name_with_spaces assert_url_friendly_name_converts_properly 'Build a playhouse', 'Build_a_playhouse' end diff --git a/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb b/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb index 3ecf26f5..f1058f45 100644 --- a/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb +++ b/tracks/vendor/rails/activerecord/lib/active_record/connection_adapters/sqlserver_adapter.rb @@ -41,7 +41,7 @@ module ActiveRecord raise ArgumentError, "Missing Database. Argument ':database' must be set in order for this adapter to work." unless config.has_key?(:database) database = config[:database] host = config[:host] ? config[:host].to_s : 'localhost' - driver_url = "DBI:ADO:Provider=SQLOLEDB;Data Source=#{host};Initial Catalog=#{database};User Id=#{username};Password=#{password};" + driver_url = "DBI:ADO:Provider=SQLNCLI;Data Source=#{host};Initial Catalog=#{database};User Id=#{username};Password=#{password};" end conn = DBI.connect(driver_url, username, password) conn["AutoCommit"] = autocommit