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
This commit is contained in:
lukemelia 2006-12-30 09:52:39 +00:00
parent a65e66168c
commit 6e5b574406
8 changed files with 159 additions and 111 deletions

View file

@ -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. <home>/project/show/<project_name> shows just <project_name>.
#
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

View file

@ -1,6 +1,7 @@
<div id="display_box">
<%= 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" } %>
<div class="container">

View file

@ -0,0 +1,18 @@
<% suffix = append_descriptor ? append_descriptor : '' -%>
<div class="container tickler" id="tickler_container">
<h2>
<% if collapsible %>
<a href="#" class="container_toggle" id="toggle_deferred"><%= image_tag("collapse.png") %></a>
<% end %>
Deferred actions <%= append_descriptor ? append_descriptor : '' %>
</h2>
<div id="tickler" class="items toggle_target">
<div id="tickler-empty-nd" style="display:<%= deferred.empty? ? 'block' : 'none'%>;">
<div class="message"><p>Currently there are no deferred actions</p></div>
</div>
<%= render :partial => "todo/item", :collection => deferred, :locals => { :parent_container_type => 'tickler' } %>
</div><!-- [end:items] -->
</div><!-- [end:tickler] -->

View file

@ -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

View file

@ -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']

View file

@ -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'

View file

@ -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

View file

@ -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