From f99883c1bd98a70f7851c089bed95ce0b2c68814 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Tue, 20 May 2008 19:48:15 -0700 Subject: [PATCH] Basic deliverable table implemented. #1135 --- app/controllers/deliverables_controller.rb | 18 ++++++++++++- app/models/deliverable.rb | 15 +++++++++++ app/views/deliverables/_list.html.erb | 27 +++++++++++++++++++ app/views/deliverables/index.html.erb | 7 ++++- assets/stylesheets/budget.css | 6 +++++ .../deliverables_controller_spec.rb | 9 +++++-- 6 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 app/views/deliverables/_list.html.erb diff --git a/app/controllers/deliverables_controller.rb b/app/controllers/deliverables_controller.rb index a1d3502..d7f2ef8 100644 --- a/app/controllers/deliverables_controller.rb +++ b/app/controllers/deliverables_controller.rb @@ -3,8 +3,24 @@ class DeliverablesController < ApplicationController layout 'base' before_filter :find_project, :authorize, :get_settings + helper :sort + include SortHelper + def index - @deliverables = Deliverable.find_all_by_project_id(@project.id) + sort_init "#{Deliverable.table_name}.id", "desc" + sort_update + limit = per_page_option + @deliverable_count = Deliverable.count(:conditions => { :project_id => @project.id }) + @deliverable_pages = Paginator.new self, @deliverable_count, limit, params['page'] + @deliverables = Deliverable.find(:all, + :order => sort_clause, + :conditions => { :project_id => @project.id }, + :limit => limit, + :offset => @deliverable_pages.current.offset) + + respond_to do |format| + format.html { render :action => 'index', :layout => !request.xhr? } + end end private diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index ad031e7..21bbc29 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -1,3 +1,18 @@ class Deliverable < ActiveRecord::Base belongs_to :project + + # TODO: mocked + def score + 0 + end + + # TODO: mocked + def spent + 0 + end + + # TODO: mocked + def progress + 0 + end end diff --git a/app/views/deliverables/_list.html.erb b/app/views/deliverables/_list.html.erb new file mode 100644 index 0000000..c584804 --- /dev/null +++ b/app/views/deliverables/_list.html.erb @@ -0,0 +1,27 @@ +<% form_tag({}) do -%> + + + <%# TODO: Other sorts %> + <%= sort_header_tag("#{Deliverable.table_name}.id", :caption => '#', :default_order => 'desc') %> + <%= content_tag('th', "Score") %> + <%= sort_header_tag("#{Deliverable.table_name}.subject", :caption => 'Subject') %> + <%= sort_header_tag("#{Deliverable.table_name}.cost", :caption => 'Budget') %> + <%= content_tag('th', "Spent") %> + <%= sort_header_tag("#{Deliverable.table_name}.due_date", :caption => 'Due') %> + <%= content_tag('th', "Progress") %> + + + <% deliverables.each do |deliverable| -%> + + <%= content_tag(:td, deliverable.id) %> + <%= content_tag(:td, deliverable.score) %> + <%= content_tag(:td, deliverable.subject) %> + <%= content_tag(:td, number_to_currency(deliverable.cost)) %> + <%= content_tag(:td, number_to_currency(deliverable.spent)) %> + <%= content_tag(:td, format_date(deliverable.due_date)) %> + <%= content_tag(:td, progress_bar(deliverable.progress, :width => '80px')) %> + + <% end -%> + +
+<% end -%> diff --git a/app/views/deliverables/index.html.erb b/app/views/deliverables/index.html.erb index 35935cb..116844c 100644 --- a/app/views/deliverables/index.html.erb +++ b/app/views/deliverables/index.html.erb @@ -35,8 +35,13 @@
- +<% if @deliverables.empty? %> +

<%= l(:label_no_data) %>

+<% else %> + <%= render :partial => 'list', :locals => { :deliverables => @deliverables} %> +

<%# TODO: pagination_links_full @issue_pages, @issue_count %>

+<% end %> <% content_for :sidebar do %> <%= render :partial => 'deliverables/sidebar' %> diff --git a/assets/stylesheets/budget.css b/assets/stylesheets/budget.css index ee90ea5..fface3d 100644 --- a/assets/stylesheets/budget.css +++ b/assets/stylesheets/budget.css @@ -1,2 +1,8 @@ #budget-summary { background-color:#507AAA;padding:10px; } #budget-list { } + +table.list.deliverables { margin-top: 10px; } +tr.deliverable { text-align: center; white-space: nowrap; } +tr.deliverable td.subject, tr.deliverable td.category { white-space: normal; } +tr.deliverable td.subject { text-align: left; } +tr.deliverable td.done_ratio table.progress { margin-left:auto; margin-right: auto;} diff --git a/spec/controllers/deliverables_controller_spec.rb b/spec/controllers/deliverables_controller_spec.rb index 01e0253..1ece172 100644 --- a/spec/controllers/deliverables_controller_spec.rb +++ b/spec/controllers/deliverables_controller_spec.rb @@ -12,7 +12,10 @@ end describe DeliverablesController,"#index when logged in" do before(:each) do @project = mock_model(Project) - Deliverable.stub!(:find_all_by_project_id).and_return([]) + + Deliverable.stub!(:count).and_return(0) + Deliverable.stub!(:find).and_return([]) + Project.should_receive(:find).with(@project.to_param).and_return(@project) controller.stub!(:authorize).and_return(true) end @@ -28,7 +31,9 @@ describe DeliverablesController,"#index when logged in" do end it "should only show the deliverables for the current project only" do - Deliverable.should_receive(:find_all_by_project_id).with(@project.id) + # TODO: Get spec working for full finder + Deliverable.should_receive(:find) get :index, :id => @project.id end end +