ACK - Work great !
--
Benjamin LAN-SUN-LUK
Le 28/10/08 14:59, « Darryl L. Pierce » <mcpierce(a)gmail.com> a écrit :
If no date range is given, then all efforts for currently active
sprints are shown.
Signed-off-by: Darryl L. Pierce <mcpierce(a)gmail.com>
---
app/controllers/report_controller.rb | 30 ++++++++++++++++-
app/views/report/effort.html.erb | 51 +++++++++++++++++++++++++++++
app/views/report/index.html.erb | 16 +++++++++
app/views/user/view.html.erb | 1 +
config/routes.rb | 24 +++++++-------
db/schema.rb | 20 +++++++++++-
test/functional/report_controller_test.rb | 27 +++++++++++++++
7 files changed, 155 insertions(+), 14 deletions(-)
create mode 100644 app/views/report/effort.html.erb
create mode 100644 app/views/report/index.html.erb
diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb
index c3ca4a1..caebe81 100644
--- a/app/controllers/report_controller.rb
+++ b/app/controllers/report_controller.rb
@@ -18,7 +18,26 @@
# +ReportController+ allows users to view various reports.
#
class ReportController < ApplicationController
- before_filter :load_sprint
+ before_filter :load_sprint, :except => [:index, :effort]
+ before_filter :load_user, :only => [:effort]
+
+ def index
+ @users = User.find(:all, :order => 'display_name ASC')
+ end
+
+ def burndown
+
+ end
+
+ def effort
+ @tasks = Task.find(
+ :all,
+ :conditions => ['(primary_id = ? or backup_id = ?) and
+ backlog_item_id in
+ (select bi.id from backlog_items bi where bi.sprint_id in (select id from sprints
where status = ?))',
+ @this_user.id, @this_user.id, Sprint::STATUS_ACTIVE],
+ :order => 'backlog_item_id')
+ end
# Generates a burndown report.
#
@@ -53,4 +72,13 @@ class ReportController < ApplicationController
redirect_to error_url
end
end
+
+ def load_user
+ @this_user = User.find_by_id(params[:id])
+
+ unless @this_user
+ flash[:error] = "Invalid or unspecified user."
+ redirect_to error_url
+ end
+ end
end
diff --git a/app/views/report/effort.html.erb b/app/views/report/effort.html.erb
new file mode 100644
index 0000000..2ac22cd
--- /dev/null
+++ b/app/views/report/effort.html.erb
@@ -0,0 +1,51 @@
+<table class="list">
+<colgroup>
+ <col class="row_id" />
+ <col class="date" />
+ <col class="title" />
+ <col class="user" />
+ <col class="user" />
+ <col class="hours" />
+</colgroup>
+<thead>
+ <tr class="title">
+ <th colspan="6"><%= "Effort Report For
#{(a)this_user.display_name}" %></th>
+ </tr>
+ <tr>
+ <th>##</th>
+ <th>Date</th>
+ <th>Description</th>
+ <th>Primary</th>
+ <th>Backup</th>
+ <th>Hours</th>
+ </tr>
+</thead>
+
+<tbody>
+ <% backlog_item_id = -1 %>
+ <% total_hours = 0 %>
+ <% @tasks.each_with_index do |task, index| %>
+ <% row_class = index%2 == 0 ? 'even' : 'odd' %>
+ <% if backlog_item_id != task.backlog_item.id %>
+ <tr class="separator">
+ <td colspan="6"><%= "For item:
#{task.backlog_item.user_story.title}" %></td>
+ <% backlog_item_id = task.backlog_item_id %>
+ </tr>
+ <% end %>
+ <tr class="<%= row_class %>">
+ <td><%= index + 1 %></td>
+ <td><%= task.when %></td>
+ <td><%= task.description %></td>
+ <td><%= link_to_user(task.primary) %></td>
+ <td><%= link_to_user(task.backup) %></td>
+ <td><%= task.hours %><% total_hours += task.hours %></td>
+ </tr>
+ </tr>
+ <% end %>
+
+ <tr>
+ <td colspan="5"></td>
+ <td><%= format("%0.1f", total_hours) %></td>
+ </tr>
+</tbody>
+</table>
diff --git a/app/views/report/index.html.erb b/app/views/report/index.html.erb
new file mode 100644
index 0000000..4436714
--- /dev/null
+++ b/app/views/report/index.html.erb
@@ -0,0 +1,16 @@
+
+<table>
+
+ <% form_tag(:action => :effort) do %>
+ <tr>
+ <td>Effort report for: </td>
+ <td>
+ <%= select_tag "id",
+ options_from_collection_for_select(@users, :id, :display_name,
+ (@owner ? @backlog_item.owner.id : nil)) %>
+ </td>
+ <td><%= submit_tag "View" %></td>
+ </tr>
+ <% end %>
+
+</table>
diff --git a/app/views/user/view.html.erb b/app/views/user/view.html.erb
index 69a0f0a..3430325 100644
--- a/app/views/user/view.html.erb
+++ b/app/views/user/view.html.erb
@@ -3,6 +3,7 @@
<%= link_to "Edit", :action => :modify, :id => @this_user.id
%>
<% end %>
<%= link_to "View my backlog", :action => :backlog, :id =>
@this_user.id %>
+ <%= link_to "Effort report", :controller => :report, :action =>
:effort, :id => @this_user.id %>
</div>
<table class="edit">
diff --git a/config/routes.rb b/config/routes.rb
index 7f843f0..874f8e9 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,18 +1,18 @@
-# routers.rb
-# Copyright (C) 2008, Darryl L. Pierce <mcpierce(a)gmail.com>
+# routers.rb
+# Copyright (C) 2008, Darryl L. Pierce <mcpierce(a)gmail.com>
#
-# 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 3 of the License, or
-# (at your option) any later version.
+# 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 3 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.
+# 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, see <
http://www.gnu.org/licenses/>.
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <
http://www.gnu.org/licenses/>.
#
ActionController::Routing::Routes.draw do |map|
diff --git a/db/schema.rb b/db/schema.rb
index 63db227..74e9110 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -23,6 +23,7 @@ ActiveRecord::Schema.define(:version => 16) do
end
add_index "backlog_items", ["sprint_id",
"user_story_id"], :name =>
"index_backlog_items_on_sprint_id_and_user_story_id", :unique => true
+ add_index "backlog_items", ["user_story_id"], :name =>
"fk_backlog_items_user_story"
create_table "product_roles", :force => true do |t|
t.integer "user_id", :null => false
@@ -32,7 +33,9 @@ ActiveRecord::Schema.define(:version => 16) do
t.datetime "updated_at"
end
- add_index "product_roles", ["product_id", "user_id"],
:name => "index_product_roles_on_user_id_and_product_id", :unique => true
+ add_index "product_roles", ["user_id", "product_id"],
:name => "index_product_roles_on_user_id_and_product_id", :unique => true
+ add_index "product_roles", ["product_id"], :name =>
"fk_user_role_product"
+ add_index "product_roles", ["role_id"], :name =>
"fk_user_role_role"
create_table "products", :force => true do |t|
t.integer "project_id"
@@ -44,6 +47,7 @@ ActiveRecord::Schema.define(:version => 16) do
end
add_index "products", ["name"], :name =>
"index_products_on_name", :unique => true
+ add_index "products", ["project_id"], :name =>
"fk_products_project"
create_table "projects", :force => true do |t|
t.integer "owner_id", :null => false
@@ -55,6 +59,7 @@ ActiveRecord::Schema.define(:version => 16) do
end
add_index "projects", ["name"], :name =>
"index_projects_on_name", :unique => true
+ add_index "projects", ["owner_id"], :name =>
"fk_product_owner"
create_table "remaining_hours_estimates", :force => true do |t|
t.integer "backlog_item_id", :null =>
false
@@ -65,6 +70,9 @@ ActiveRecord::Schema.define(:version => 16) do
t.datetime "estimated_on", :null =>
false
end
+ add_index "remaining_hours_estimates", ["backlog_item_id"], :name
=> "fk_remaining_hours_item"
+ add_index "remaining_hours_estimates", ["user_id"], :name =>
"fk_remaining_hours_user"
+
create_table "roles", :force => true do |t|
t.string "name", :null =>
false
t.boolean "can_manage_backlog_items", :default => false, :null =>
false
@@ -96,6 +104,8 @@ ActiveRecord::Schema.define(:version => 16) do
t.integer "status", :default => 0, :null =>
false
end
+ add_index "sprints", ["product_id"], :name =>
"fk_sprint_product"
+
create_table "tasks", :force => true do |t|
t.integer "backlog_item_id",
:null => false
t.integer "primary_id",
:null => false
@@ -107,6 +117,10 @@ ActiveRecord::Schema.define(:version => 16) do
t.datetime "updated_at"
end
+ add_index "tasks", ["backlog_item_id"], :name =>
"fk_task_backlog_item"
+ add_index "tasks", ["primary_id"], :name =>
"fk_task_primary"
+ add_index "tasks", ["backup_id"], :name =>
"fk_task_backup"
+
create_table "user_privileges", :force => true do |t|
t.integer "user_id", :null => false
t.boolean "admin_projects", :default => false, :null => false
@@ -115,6 +129,8 @@ ActiveRecord::Schema.define(:version => 16) do
t.datetime "updated_at"
end
+ add_index "user_privileges", ["user_id"], :name =>
"fk_privilege_user"
+
create_table "user_stories", :force => true do |t|
t.integer "product_id"
t.integer "priority"
@@ -125,6 +141,8 @@ ActiveRecord::Schema.define(:version => 16) do
t.datetime "updated_at"
end
+ add_index "user_stories", ["product_id"], :name =>
"fk_user_story_product"
+
create_table "user_verifications", :force => true do |t|
t.integer "user_id", :null => false
t.string "token", :limit => 16, :null => false
diff --git a/test/functional/report_controller_test.rb
b/test/functional/report_controller_test.rb
index 6957fe5..902c457 100644
--- a/test/functional/report_controller_test.rb
+++ b/test/functional/report_controller_test.rb
@@ -19,10 +19,12 @@ require File.dirname(__FILE__) + '/../test_helper'
class ReportControllerTest < ActionController::TestCase
fixtures :sprints
+ fixtures :users
def setup
@pending_sprint = sprints(:inactive_sprint)
@sprint = sprints(:initial_development_sprint)
+ @user = users(:mcpierce)
end
# Ensures that an error occurs when no sprint id was provided.
@@ -49,4 +51,29 @@ class ReportControllerTest < ActionController::TestCase
assert_response :success
assert assigns['data'], "Didn't generate the data needed for a
report."
end
+
+ # Ensures that an effort report requires a user id.
+ #
+ def test_effort_without_user_id
+ get :effort
+
+ assert_redirected_to error_url
+ end
+
+ # Ensures that the user id must be valid for an effort report.
+ #
+ def test_effort_with_invalid_user_id
+ get :effort, {:id => 9999}
+
+ assert_redirected_to error_url
+ end
+
+ # Ensures that a well formed request works.
+ #
+ def test_effort
+ get :effort, {:id => @user.id}
+
+ assert_response :success
+ assert assigns['tasks'], 'Failed to load the set of tasks for the given
user.'
+ end
end
--
1.6.0.2
_______________________________________________
projxp-devel mailing list
projxp-devel(a)lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/projxp-devel