From svn at explainpmt.com Sun Mar 12 18:34:42 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Sun, 12 Mar 2006 23:34:42 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [200] Creating release tag for
20060311.0
Message-ID: <20060312233442.3685DC97C4@thurlow.textdrive.com>
Revision: 200
Author: jwilger
Date: 2006-03-12 23:34:41 +0000 (Sun, 12 Mar 2006)
Log Message:
-----------
Creating release tag for 20060311.0
Added Paths:
-----------
tags/release_20060311.0/
Copied: tags/release_20060311.0 (from rev 199, trunk)
From svn at explainpmt.com Sun Mar 12 18:36:04 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Sun, 12 Mar 2006 23:36:04 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [201] Updated version tag for
release
Message-ID: <20060312233604.333BFC98A6@thurlow.textdrive.com>
Revision: 201
Author: jwilger
Date: 2006-03-12 23:36:03 +0000 (Sun, 12 Mar 2006)
Log Message:
-----------
Updated version tag for release
Modified Paths:
--------------
tags/release_20060311.0/app/helpers/application_helper.rb
Modified: tags/release_20060311.0/app/helpers/application_helper.rb
===================================================================
--- tags/release_20060311.0/app/helpers/application_helper.rb 2006-03-12 23:34:41 UTC (rev 200)
+++ tags/release_20060311.0/app/helpers/application_helper.rb 2006-03-12 23:36:03 UTC (rev 201)
@@ -20,7 +20,7 @@
# The methods added to this helper will be available to all templates in the application.
module ApplicationHelper
- VERSION = 'dev trunk'
+ VERSION = '20060311.0'
# Used to determine if the currently logged in user has administrative
# privileges
From svn at explainpmt.com Mon Mar 20 21:21:03 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Tue, 21 Mar 2006 02:21:03 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [202] Story listing on
iteration pages now show an icon next to the titles of
stories that have content in their description field.
Message-ID: <20060321022103.5BBA7C9885@thurlow.textdrive.com>
Revision: 202
Author: jwilger
Date: 2006-03-21 02:21:01 +0000 (Tue, 21 Mar 2006)
Log Message:
-----------
Story listing on iteration pages now show an icon next to the titles of stories that have content in their description field.
Modified Paths:
--------------
trunk/app/views/iterations/show.rhtml
trunk/public/stylesheets/layout.css
Added Paths:
-----------
trunk/public/images/info-icon.gif
Modified: trunk/app/views/iterations/show.rhtml
===================================================================
--- trunk/app/views/iterations/show.rhtml 2006-03-12 23:36:03 UTC (rev 201)
+++ trunk/app/views/iterations/show.rhtml 2006-03-21 02:21:01 UTC (rev 202)
@@ -193,9 +193,17 @@
""
end
stories_table.column_modifier(:title) do |s|
- link_to(s.title,
- :controller => 'stories', :action => 'show', :id => s.id,
- :project_id => s.project.id)
+ str = link_to(s.title,
+ :controller => 'stories', :action => 'show', :id => s.id,
+ :project_id => s.project.id)
+ if s.description?
+ str += ' ' +
+ link_to(image_tag('info-icon.gif', :alt => '[description]'),
+ {:controller => 'stories', :action => 'show', :id => s.id,
+ :project_id => s.project.id},
+ :class => 'story_description_icon')
+ end
+ str
end
stories_table.column_modifier(:owner) do |s|
if s.has_owner?
Added: trunk/public/images/info-icon.gif
===================================================================
(Binary files differ)
Property changes on: trunk/public/images/info-icon.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/public/stylesheets/layout.css
===================================================================
--- trunk/public/stylesheets/layout.css 2006-03-12 23:36:03 UTC (rev 201)
+++ trunk/public/stylesheets/layout.css 2006-03-21 02:21:01 UTC (rev 202)
@@ -161,6 +161,12 @@
border: none;
}
+a.story_description_icon,
+a.story_description_icon img {
+ text-decoration: none;
+ border: none;
+}
+
#Header {
margin: 0;
}
From svn at explainpmt.com Mon Mar 20 21:23:15 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Tue, 21 Mar 2006 02:23:15 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [203] Icon is now displayed
next to titles of stories that have descriptions when viewing
the backlog.
Message-ID: <20060321022315.A23D3C9886@thurlow.textdrive.com>
Revision: 203
Author: jwilger
Date: 2006-03-21 02:23:15 +0000 (Tue, 21 Mar 2006)
Log Message:
-----------
Icon is now displayed next to titles of stories that have descriptions when viewing the backlog.
Modified Paths:
--------------
trunk/app/views/stories/index.rhtml
Modified: trunk/app/views/stories/index.rhtml
===================================================================
--- trunk/app/views/stories/index.rhtml 2006-03-21 02:21:01 UTC (rev 202)
+++ trunk/app/views/stories/index.rhtml 2006-03-21 02:23:15 UTC (rev 203)
@@ -55,11 +55,17 @@
""
end
stories_table.column_modifier(:title) do |s|
- link_to(s.title,
- :controller => 'stories',
- :action => 'show',
- :id => s.id,
+ str = link_to(s.title,
+ :controller => 'stories', :action => 'show', :id => s.id,
:project_id => s.project.id)
+ if s.description?
+ str += ' ' +
+ link_to(image_tag('info-icon.gif', :alt => '[description]'),
+ {:controller => 'stories', :action => 'show', :id => s.id,
+ :project_id => s.project.id},
+ :class => 'story_description_icon')
+ end
+ str
end
stories_table.column_modifier(:edit) do |s|
link_to('Edit',
From svn at explainpmt.com Wed Mar 22 21:25:28 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Thu, 23 Mar 2006 02:25:28 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [204] SC61 - added SubProject
model and relationship between Project and SubProject
Message-ID: <20060323022528.9F418C9674@thurlow.textdrive.com>
Revision: 204
Author: jwilger
Date: 2006-03-23 02:25:06 +0000 (Thu, 23 Mar 2006)
Log Message:
-----------
SC61 - added SubProject model and relationship between Project and SubProject
Modified Paths:
--------------
trunk/app/models/project.rb
trunk/test/test_helper.rb
trunk/test/unit/project_test.rb
Added Paths:
-----------
trunk/app/models/sub_project.rb
trunk/db/migrate/002_add_sub_projects_table.rb
trunk/test/fixtures/sub_projects.yml
trunk/test/unit/sub_project_test.rb
Modified: trunk/app/models/project.rb
===================================================================
--- trunk/app/models/project.rb 2006-03-21 02:23:15 UTC (rev 203)
+++ trunk/app/models/project.rb 2006-03-23 02:25:06 UTC (rev 204)
@@ -38,6 +38,8 @@
# validates_length_of :name, :maximum => 100
#
class Project < ActiveRecord::Base
+ has_many :sub_projects, :order => 'name', :dependent => true
+
has_many :iterations, :order => 'start_date ASC', :dependent => true do
def past
self.reverse.select { |i| i.past? }
Added: trunk/app/models/sub_project.rb
===================================================================
--- trunk/app/models/sub_project.rb (rev 0)
+++ trunk/app/models/sub_project.rb 2006-03-23 02:25:06 UTC (rev 204)
@@ -0,0 +1,26 @@
+##############################################################################
+# eXPlain Project Management Tool
+# Copyright (C) 2005 John Wilger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+
+
+class SubProject < ActiveRecord::Base
+ belongs_to :project
+
+ validates_presence_of :name
+ validates_uniqueness_of :name, :scope => 'project_id'
+end
Added: trunk/db/migrate/002_add_sub_projects_table.rb
===================================================================
--- trunk/db/migrate/002_add_sub_projects_table.rb (rev 0)
+++ trunk/db/migrate/002_add_sub_projects_table.rb 2006-03-23 02:25:06 UTC (rev 204)
@@ -0,0 +1,34 @@
+##############################################################################
+# eXPlain Project Management Tool
+# Copyright (C) 2005 John Wilger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+
+
+class AddSubProjectsTable < ActiveRecord::Migration
+ def self.up
+ create_table "sub_projects" do |t|
+ t.column "project_id", :integer
+ t.column "name", :string
+ t.column "created_at", :datetime
+ t.column "updated_at", :datetime
+ end
+ end
+
+ def self.down
+ drop_table "sub_projects"
+ end
+end
Added: trunk/test/fixtures/sub_projects.yml
===================================================================
--- trunk/test/fixtures/sub_projects.yml (rev 0)
+++ trunk/test/fixtures/sub_projects.yml 2006-03-23 02:25:06 UTC (rev 204)
@@ -0,0 +1,9 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+first:
+ id: 1
+ project_id: 1
+ name: First Sub-Project
+second:
+ id: 2
+ project_id: 1
+ name: Second Sub-Project
\ No newline at end of file
Modified: trunk/test/test_helper.rb
===================================================================
--- trunk/test/test_helper.rb 2006-03-21 02:23:15 UTC (rev 203)
+++ trunk/test/test_helper.rb 2006-03-23 02:25:06 UTC (rev 204)
@@ -11,6 +11,43 @@
# Add more helper methods to be used by all tests here...
- ALL_FIXTURES = [ :iterations, :milestones, :projects_users, :projects,
- :stories, :users ]
+ ALL_FIXTURES = [ :iterations,
+ :milestones,
+ :projects_users,
+ :projects,
+ :stories,
+ :users,
+ :sub_projects ]
+
+ class << self
+ def test_required_attributes( klass, *attributes )
+ attributes.each do |attribute|
+ self.class_eval %Q{
+ def test_#{attribute}_is_required
+ object = #{klass}.new
+ assert !object.valid?
+ assert object.errors.on( :#{attribute} )
+ assert object.errors.on( :#{attribute} ).to_a.
+ include?( "can't be blank" )
+ end
+ }
+ end
+ end
+
+ def test_unique_attributes( klass, existing_id, *attributes )
+ attributes.each do |attribute|
+ self.class_eval %Q{
+ def test_#{attribute}_must_be_unique
+ existing = #{klass}.find #{existing_id}
+ object = #{klass}.new
+ object.#{attribute} = existing.#{attribute}
+ assert !object.valid?
+ assert object.errors.on( :#{attribute} )
+ assert object.errors.on( :#{attribute} ).to_a.
+ include?( 'has already been taken' )
+ end
+ }
+ end
+ end
+ end
end
Modified: trunk/test/unit/project_test.rb
===================================================================
--- trunk/test/unit/project_test.rb 2006-03-21 02:23:15 UTC (rev 203)
+++ trunk/test/unit/project_test.rb 2006-03-23 02:25:06 UTC (rev 204)
@@ -40,6 +40,24 @@
@milestone_six = Milestone.find 6
@milestone_seven = Milestone.find 7
end
+
+ def test_sub_projects_association
+ assert_equal SubProject.find( :all,
+ :conditions => [ 'project_id = ?',
+ @project_one.id ],
+ :order => 'name' ),
+ @project_one.sub_projects
+ end
+
+ def test_sub_projects_destroyed_with_project
+ sub_ids = @project_one.sub_projects.map { |s| s.id }
+ @project_one.destroy
+ sub_ids.each do |id|
+ assert_raises( ActiveRecord::RecordNotFound) do
+ SubProject.find( id )
+ end
+ end
+ end
def test_current_iteration_that_starts_today
assert_equal @iteration_one, @project_one.iterations.current
Added: trunk/test/unit/sub_project_test.rb
===================================================================
--- trunk/test/unit/sub_project_test.rb (rev 0)
+++ trunk/test/unit/sub_project_test.rb 2006-03-23 02:25:06 UTC (rev 204)
@@ -0,0 +1,50 @@
+##############################################################################
+# eXPlain Project Management Tool
+# Copyright (C) 2005 John Wilger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+
+
+require File.dirname(__FILE__) + '/../test_helper'
+
+class SubProjectTest < Test::Unit::TestCase
+ fixtures ALL_FIXTURES
+
+ def setup
+ @project_one = projects( :first )
+ @project_two = projects( :second )
+ @sub_project_one = sub_projects( :first )
+ end
+
+ test_required_attributes SubProject, :name
+
+ def test_name_unique_within_same_project
+ new_sub_proj = @sub_project_one.clone
+ assert !new_sub_proj.valid?
+ assert new_sub_proj.errors.on( :name )
+ assert_equal 'has already been taken', new_sub_proj.errors.on( :name )
+ end
+
+ def test_name_not_unique_across_projects
+ new_sub_proj = @sub_project_one.clone
+ new_sub_proj.project = @project_two
+ assert new_sub_proj.valid?
+ end
+
+ def test_project_association
+ assert_equal @project_one, @sub_project_one.project
+ end
+end
From svn at explainpmt.com Thu Mar 23 01:04:27 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Thu, 23 Mar 2006 06:04:27 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [205] SC61 - admins can now
create sub-projects and view the list of sub-projects for
each project
Message-ID: <20060323060427.49936C988C@thurlow.textdrive.com>
Revision: 205
Author: jwilger
Date: 2006-03-23 06:04:11 +0000 (Thu, 23 Mar 2006)
Log Message:
-----------
SC61 - admins can now create sub-projects and view the list of sub-projects for each project
Modified Paths:
--------------
trunk/app/controllers/projects_controller.rb
trunk/app/views/projects/index.rhtml
trunk/test/functional/projects_controller_test.rb
Added Paths:
-----------
trunk/app/views/projects/_sub_project.rhtml
trunk/app/views/projects/_sub_project_error.rhtml
trunk/app/views/projects/_sub_project_new.rhtml
trunk/public/images/spinner.gif
Modified: trunk/app/controllers/projects_controller.rb
===================================================================
--- trunk/app/controllers/projects_controller.rb 2006-03-23 02:25:06 UTC (rev 204)
+++ trunk/app/controllers/projects_controller.rb 2006-03-23 06:04:11 UTC (rev 205)
@@ -151,5 +151,14 @@
@projects = session[:current_user].projects
render_partial 'my_projects_list'
end
-end
-
+
+ def create_sub_project
+ project = Project.find params[ :project_id ]
+ @sub_project = project.sub_projects.create params[ :sub_project ]
+ if @sub_project.new_record?
+ render :partial => 'sub_project_error', :status => 500
+ else
+ render :partial => 'sub_project_new'
+ end
+ end
+end
\ No newline at end of file
Added: trunk/app/views/projects/_sub_project.rhtml
===================================================================
--- trunk/app/views/projects/_sub_project.rhtml (rev 0)
+++ trunk/app/views/projects/_sub_project.rhtml 2006-03-23 06:04:11 UTC (rev 205)
@@ -0,0 +1,5 @@
+
class CollectionTable
# The attribute of each item in the collection that can be used as a unique
@@ -80,6 +84,10 @@
# Takes an array of CSS class names. The class names will be applied in
# sequence to the +tr+ tag of each data row.
attr_writer :data_row_class
+
+ attr_writer :table_id
+
+ attr_writer :tbody_id
# Returns a new CollectionTable object that will operate on the +items+ (any
# enumerable) and will display a column for each of the specified +columns+.
@@ -116,9 +124,12 @@
# Returns the complete HTML for the table based on the options set on the
# object with a data row for each item in the collection.
def build_table
- output = "
+EOF
+ assert_equal expected, ct.build_table
+ end
end
From svn at explainpmt.com Mon Mar 27 11:21:41 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Mon, 27 Mar 2006 16:21:41 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [214] Reverted last commit
(changes to CollectionTableHelper).
Message-ID: <20060327162141.9E0C6C976D@thurlow.textdrive.com>
Revision: 214
Author: jwilger
Date: 2006-03-27 16:21:40 +0000 (Mon, 27 Mar 2006)
Log Message:
-----------
Reverted last commit (changes to CollectionTableHelper). That module is going to go away, because it's just a big, fat code-smell. It's making it really hard to set up the dnd priority sorting, because it falls apart when you try to do anything more complex than a simple table.
Modified Paths:
--------------
trunk/app/helpers/collection_table_helper.rb
trunk/test/unit/collection_table_helper_test.rb
Modified: trunk/app/helpers/collection_table_helper.rb
===================================================================
--- trunk/app/helpers/collection_table_helper.rb 2006-03-27 16:04:35 UTC (rev 213)
+++ trunk/app/helpers/collection_table_helper.rb 2006-03-27 16:21:40 UTC (rev 214)
@@ -47,34 +47,30 @@
# build_table might return the following HTML:
#
#
class CollectionTable
# The attribute of each item in the collection that can be used as a unique
@@ -84,10 +80,6 @@
# Takes an array of CSS class names. The class names will be applied in
# sequence to the +tr+ tag of each data row.
attr_writer :data_row_class
-
- attr_writer :table_id
-
- attr_writer :tbody_id
# Returns a new CollectionTable object that will operate on the +items+ (any
# enumerable) and will display a column for each of the specified +columns+.
@@ -124,12 +116,9 @@
# Returns the complete HTML for the table based on the options set on the
# object with a data row for each item in the collection.
def build_table
- output = "
+ <% end %>
<% unless hide_cols.include?( :delete ) %>
<% end %>
From svn at explainpmt.com Tue Mar 28 09:53:21 2006
From: svn at explainpmt.com (svn at explainpmt.com)
Date: Tue, 28 Mar 2006 14:53:21 +0000 (GMT)
Subject: [eXPlainPMT Developers] [SVN commit] [221] Removed
CollectionTableHelper code.
Message-ID: <20060328145321.41A5BC9865@thurlow.textdrive.com>
Revision: 221
Author: jwilger
Date: 2006-03-28 14:53:19 +0000 (Tue, 28 Mar 2006)
Log Message:
-----------
Removed CollectionTableHelper code.
Modified Paths:
--------------
trunk/app/controllers/application.rb
Removed Paths:
-------------
trunk/app/helpers/collection_table_helper.rb
trunk/test/unit/collection_table_helper_test.rb
Property Changed:
----------------
trunk/log/
Modified: trunk/app/controllers/application.rb
===================================================================
--- trunk/app/controllers/application.rb 2006-03-27 19:22:40 UTC (rev 220)
+++ trunk/app/controllers/application.rb 2006-03-28 14:53:19 UTC (rev 221)
@@ -25,12 +25,12 @@
# here to prevent an error when the session variables are read in
model :user
model :project
+ model :sub_project
model :iteration
model :story
model :milestone
helper :sort
- helper :collection_table
layout :choose_layout
before_filter :check_authentication
Deleted: trunk/app/helpers/collection_table_helper.rb
===================================================================
--- trunk/app/helpers/collection_table_helper.rb 2006-03-27 19:22:40 UTC (rev 220)
+++ trunk/app/helpers/collection_table_helper.rb 2006-03-28 14:53:19 UTC (rev 221)
@@ -1,210 +0,0 @@
-##############################################################################
-# eXPlain Project Management Tool
-# Copyright (C) 2005 John Wilger
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##############################################################################
-
-
-module CollectionTableHelper
- # Creates an HTML table based on any collection (Enumerable) of objects.
- #
- # Example:
- #
- # # Assuming we have a Person model class with the attributes
- # # id, last_name, first_name, email and we have assigned the
- # # @people variable in the controller as @people = Person.find_all
- # people_table = CollectionTable.new(@people, [:id,'ID'], :last_name,
- # :first_name, :email, [:edit,nil], [:delete,nil])
- # people_table.data_row_class = ['odd_row','even_row']
- # people_table.column_align(:id, 'right')
- # people_table.column_modifier(:email) do |p|
- # "p.email"
- # end
- # people_table.column_modifier(:edit) do |p|
- # link_to('Edit', :controller => 'people', :action => 'edit',
- # :id => p.id)
- # end
- # people_table.column_modifier(:delete) do |p|
- # link_to('Delete', :controller => 'people', :action => 'delete',
- # :id => p.id)
- # end
- # people_table.build_table
- #
- # Depending on the actual Person records in the collection, the call to
- # build_table might return the following HTML:
- #
- #
- class CollectionTable
- # The attribute of each item in the collection that can be used as a unique
- # identifier. Defaults to the +id+ attribute.
- attr_accessor :item_id_attr
-
- # Takes an array of CSS class names. The class names will be applied in
- # sequence to the +tr+ tag of each data row.
- attr_writer :data_row_class
-
- # Returns a new CollectionTable object that will operate on the +items+ (any
- # enumerable) and will display a column for each of the specified +columns+.
- # Each column can be specified either as a symbol (:column_name) which will
- # be displayed using the humanized form (Column Name), or it can be
- # specified as a two-element array ([:column_name,'Text for Header'] where
- # the first element identifies the column, and the second element specifies
- # the text to display for that column in the table header. If the second
- # element is +nil+ that column will have a blank header. In either case, the
- # column identifier (the symbol part) should usually match the name of an
- # attribute on the items in the collection. This attribute will be used as
- # the data to display in that column. If you specify an identifier which
- # _does not_ match an attribute of the items in the collection, you _must_
- # specify a #column_modifier for that column, or you will get run-time
- # exceptions.
- def initialize(items, *columns)
- @items = items
- @item_id_attr = :id
- @columns = {}
- @column_order = []
- @column_modifiers = {}
- @column_alignments = {}
- columns.each do |col|
- if col.kind_of? Enumerable
- @column_order << col.first
- @columns[col.first] = (col.last || '')
- else
- @column_order << col
- @columns[col] = Inflector.humanize(col.to_s)
- end
- end
- end
-
- # Returns the complete HTML for the table based on the options set on the
- # object with a data row for each item in the collection.
- def build_table
- output = "
\n"
- end
-
- # Allows you to modify the contents of a column for each of the data rows by
- # specifying the identifier for the column (as specified in the
- # CollectionTable.new method) and providing a block that returns the
- # contents of the cell. The block should take one argument, which is the
- # item in the collection that is being operated on (not just the property
- # that would correspond to the column).
- #
- # call-seq:
- # column_modifier(column) { |item| item.some_property.to_s }
- #
- def column_modifier(column, &block)
- @column_modifiers[column] = block
- end
-
- # Allows you to set the HTML +align+ attribute on the data cells in the
- # specified column.
- def column_align(column, alignment)
- @column_alignments[column] = alignment
- end
-
- # See the documentation for the attribute definition
- def data_row_class=(classes) #:nodoc:
- @data_row_class = classes.to_a
- end
-
- # See the documentation for the attribute definition
- def item_id_attr=(attr_name) #:nodoc:
- @items.each do |i|
- unless i.respond_to?(attr_name)
- raise "Not all items in collection have an #{attr_name.to_s} " +
- "attribute."
- end
- end
- @item_id_attr = attr_name
- end
-
- private
-
- # Returns the content for the table header for the specified column.
- def heading_for(column)
- @columns[column] or raise "Heading requested for unknown column"
- end
-
- # Returns the table data row for +item+
- def data_row(item)
- data_cells = @column_order.inject('') do |txt,col|
- if @column_modifiers[col]
- cell_content = @column_modifiers[col].call(item)
- else
- cell_content = item.send(col).to_s
- end
- if @column_alignments[col]
- td = "
"
- else
- td = "
"
- end
- txt + " #{td + cell_content}
\n"
- end
- "
\n" +
- data_cells + "
\n"
- end
-
- # Returns the complete table header row
- def header_row
- header_cells = @column_order.inject('') do |txt,col|
- txt + "
#{heading_for(col)}
\n"
- end
- "
\n" + header_cells + "
\n"
- end
-
-
- # Returns the class HTML attribute for the data table row (if any)
- def current_row_class
- unless @data_row_class.nil?
- @used_data_row_class ||= []
- if current_class = @data_row_class.shift
- @used_data_row_class << current_class
- else
- @data_row_class = @used_data_row_class
- @used_data_row_class = [ current_class = @data_row_class.shift ]
- end
- return " class=\"#{current_class}\""
- end
- end
- end
-end
Property changes on: trunk/log
___________________________________________________________________
Name: svn:ignore
- *.log
+ *.log
mongrel.pid
Deleted: trunk/test/unit/collection_table_helper_test.rb
===================================================================
--- trunk/test/unit/collection_table_helper_test.rb 2006-03-27 19:22:40 UTC (rev 220)
+++ trunk/test/unit/collection_table_helper_test.rb 2006-03-28 14:53:19 UTC (rev 221)
@@ -1,143 +0,0 @@
-##############################################################################
-# eXPlain Project Management Tool
-# Copyright (C) 2005 John Wilger
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-##############################################################################
-
-
-require File.dirname(__FILE__) + '/../test_helper'
-require 'collection_table_helper'
-
-class CollectionTableHelperTest < Test::Unit::TestCase
- TestItem = Struct.new(:id, :name, :phone)
- TestItemB = Struct.new(:id, :phone)
- def setup
- @items = [ TestItem.new(1, 'John Doe', '555-5555'),
- TestItem.new(2, 'Jane Doe', '666-6666') ]
- end
-
- def test_collection_table_initialize
- assert_nothing_raised {
- ct = CollectionTableHelper::CollectionTable.new(@items, :id, :name,
- :phone)
- }
- end
-
- def test_heading_for
- ct = CollectionTableHelper::CollectionTable.new(@items, [:id,'ID'], :name,
- :phone, [:edit,nil],
- [:delete,''])
- assert_equal 'ID', ct.send(:heading_for, :id)
- assert_equal 'Name', ct.send(:heading_for, :name)
- assert_equal 'Phone', ct.send(:heading_for, :phone)
- assert_equal '', ct.send(:heading_for, :edit)
- assert_equal '', ct.send(:heading_for, :delete)
- assert_raises(RuntimeError) { ct.send(:heading_for, :not_a_column) }
- end
-
- def test_item_id_attribute
- @items << TestItemB.new(3, '777-7777')
- ct = CollectionTableHelper::CollectionTable.new(@items, :name, :phone)
- assert_equal :id, ct.item_id_attr
-
- assert_nothing_raised { ct.item_id_attr = :phone }
- assert_equal :phone, ct.item_id_attr
-
- # TestItemB class has no 'name' attribute
- assert_raises(RuntimeError) { ct.item_id_attr = :name }
- end
-
- def test_header_row
- ct = CollectionTableHelper::CollectionTable.new(@items, [:id,'ID'], :name,
- :phone)
- expected = "