Permalink
Browse files

optional filtering of activities in summary_report by selection of an…

… Objective

- save an objective_id w/ summary_report
- update summary_reports/preview
  - begin to centralize activity filter conditions (in view)
  - update conditions to include activities assoc. w/ the given Objective, if any
  - skip activities w/ no participating states for given ytd period

use datepicker for summary_reports/form
  • Loading branch information...
inertialbit committed Mar 15, 2011
1 parent e7a1f3c commit 2d7206d963a5dbf220d71a0afd74a0df4bc8ff45
@@ -24,6 +24,7 @@ def cache_map(map, path)
public
def index
+ flash.keep
redirect_to reports_path
end
View
@@ -15,6 +15,7 @@ class Objective < Criterium
include GeneralScopes
+ has_one :summary_report
has_many :report_breakdowns
has_and_belongs_to_many :grant_activities
@@ -10,13 +10,16 @@
# report_title_format :string(255)
# created_at :datetime
# updated_at :datetime
+# objective_id :integer
# End Schema
class SummaryReport < ActiveRecord::Base
STATE_SHAPES_FOR_MAP = YAML::load(File.open(File.join(Rails.root, 'lib', 'state_shapes.yml')))
STATE_LABELS_FOR_MAP = YAML::load(File.open(File.join(Rails.root, 'lib', 'state_labels.yml')))
LEVEL_COLORS = { 1 => "#F8BD0E", 2 => "#BB8519", 3 => "#7B4B23", 4 => "#FFFFCC" }
+
+ belongs_to :objective
validates_presence_of :name, :start_ytd
@@ -49,7 +52,7 @@ def ytd_activities
def period_activities
return @period_activities if @period_activities
if ytd_activities
- @period_activities ||= ytd_activities.select { |activity| (start_period..end_period).include? activity.date_of_activity }
+ @period_activities = ytd_activities.select { |activity| (start_period..end_period).include? activity.date_of_activity }
else
nil
end
@@ -1,9 +1,21 @@
+<% content_for :javascript do %>
+ <%= javascript_tag do %>
+ <%= %Q{
+ jQuery(function($) {
+ $('#summary_report_start_ytd').datepicker();
+ $('#summary_report_start_period').datepicker();
+ $('#summary_report_end_period').datepicker();
+ });
+ } %>
+ <% end %>
+<% end %>
<%= semantic_form_for @summary_report do |f| -%>
<%= f.inputs do %>
<%= f.input :name, :label => 'Name' %>
- <%= f.input :start_ytd, :label => 'Start ytd' %>
- <%= f.input :start_period, :label => 'Start period' %>
- <%= f.input :end_period, :label => 'End period' %>
+ <%= f.input :start_ytd, :label => 'Start ytd', :as => :string %>
+ <%= f.input :start_period, :label => 'Start period', :as => :string %>
+ <%= f.input :end_period, :label => 'End period', :as => :string %>
+ <%= f.input :objective, :label => 'Objective', :as => :select %>
<%= f.input :report_title_format, :label => 'Report title format' %>
<%= f.buttons %>
@@ -1,3 +1,4 @@
+<% conditions = @summary_report.objective_id.blank? ? {} : {:objective_id => @summary_report.objective_id} %>
<div style="padding-bottom: 15px;text-align:center;">
<div style="text-align: left; width: 49%; display: inline-block;">
<img alt="logo" src="<%= @logo_path || image_path('logo.jpg') %>" width="175px" />
@@ -18,14 +19,15 @@
</tr>
</thead>
<tbody>
- <% bad_activities = @summary_report.activities_by_type_for_period(:grant_activities => []) %>
+ <% bad_activities = @summary_report.activities_by_type_for_period(conditions.merge({:grant_activities => []})) %>
<% unless bad_activities.empty? %>
<tr>
<td colspan="3">
Warning: The following activities are not associated with a Grant Activity
</td>
</tr>
<% bad_activities.each do |bad_act| %>
+ <% next if bad_act.states.size < 1 %>
<tr>
<td style="padding-left: 30px;">
<%= link_to truncate(bad_act.description, :length => 70), bad_act %>
@@ -45,38 +47,36 @@
<% end %>
<% @intensity_levels.each do |intensity_level| %>
- <% unless @summary_report.activities_by_type_for_ytd(:intensity_level => intensity_level).empty? %>
+ <% conditions.merge!({:intensity_level => intensity_level}) %>
+ <% unless @summary_report.activities_by_type_for_ytd(conditions).empty? %>
<tr>
<td colspan="3">
<%= intensity_level.name %>
</td>
</tr>
<% @grant_activities.each do |grant_activity| %>
- <% unless @summary_report.activities_by_type_for_ytd(
- :intensity_level => intensity_level, :grant_activity => grant_activity).empty? %>
+ <% conditions.merge!({:grant_activity => grant_activity}) %>
+ <% next if @summary_report.states_by_type_for_ytd(conditions).size < 1 %>
+
+ <% unless @summary_report.activities_by_type_for_ytd(conditions).empty? %>
<tr>
<td style="padding-left: 30px;">
- <%= @summary_report.activities_by_type_for_period(
- :intensity_level => intensity_level, :grant_activity => grant_activity).size %>
+ <%= @summary_report.activities_by_type_for_period(conditions).size %>
<%= grant_activity.name %>
- <% unless @summary_report.states_by_type_for_period(
- :intensity_level => intensity_level, :grant_activity => grant_activity).empty? %>
+ <% unless @summary_report.states_by_type_for_period(conditions).empty? %>
<div style="padding-left: 20px;">
<em>States:</em>
- <%= @summary_report.states_by_type_for_period(
- :intensity_level => intensity_level, :grant_activity => grant_activity).
+ <%= @summary_report.states_by_type_for_period(conditions).
map(&:abbreviation).join(", ") %>
</div>
<% end %>
</td>
<td class="count">
- <%= @summary_report.states_by_type_for_period(
- :intensity_level => intensity_level, :grant_activity => grant_activity).size %>
+ <%= @summary_report.states_by_type_for_period(conditions).size %>
</td>
<td class="count">
- <%= @summary_report.states_by_type_for_ytd(
- :intensity_level => intensity_level, :grant_activity => grant_activity).size %>
+ <%= @summary_report.states_by_type_for_ytd(conditions).size %>
</td>
</tr>
<% end %>
@@ -92,7 +92,6 @@
<%= @summary_report.states_by_type_for_period.size %>
</td>
<td style="border-top: 1px solid #333" class="count">
- <%= @summary_report.states_by_type_for_ytd.size %>
</td>
</tr>
<tr>
@@ -0,0 +1,10 @@
+class AddObjectiveIdToSummaryReport < ActiveRecord::Migration
+ def self.up
+ add_column :summary_reports, :objective_id, :integer
+ add_index :summary_reports, :objective_id
+ end
+
+ def self.down
+ remove_column :summary_reports, :objective_id
+ end
+end
@@ -12,6 +12,16 @@ Feature: Generate reports
Then I should see "New Report successfully created."
And I should be on the edit report page for "Q1 - 2010"
+ Scenario: create a summary report
+ Given I am on the new summary report page
+ When I fill in "Name*" with "Full Year 2010 - Evaluation"
+ And I fill in "Start ytd*" with "01/01/2011"
+ And I fill in "Start period" with "03/01/2011"
+ And I fill in "End period" with "03/30/2011"
+ And I select "1: Knowledge Development" from "Objective"
+ And I press "Create Summary report"
+ Then I should see "Summary Report was successfully created."
+
@javascript
Scenario: add report breakdowns
Given I am on the edit report page for "Q2 - 2010"
@@ -10,6 +10,7 @@
# report_title_format :string(255)
# created_at :datetime
# updated_at :datetime
+# objective_id :integer
# End Schema
# Read about fixtures at http://ar.rubyonrails.org/# == Schema Information
@@ -1,5 +1,9 @@
require 'spec_helper'
+associations = {
+ :belongs_to => %w(objective)
+}
+
describe SummaryReport do
before(:each) do
@valid_attributes = {
@@ -15,6 +19,9 @@
SummaryReport.create!(@valid_attributes)
end
+ describe "meta" do
+ spec_associations(associations, :class => SummaryReport)
+ end
describe "a valid summary report" do
before(:each) do
View
@@ -0,0 +1,15 @@
+def spec_associations(associations, options={})
+ subject = options[:class] unless subject.present?
+ if subject.blank?
+ raise ArgumentError, "spec_associations expects a subject to be set to the target class; eg subject{ YourActiveRecordModel }"
+ end
+ it_prefix = options[:it_prefix]
+ it_prefix += " " unless it_prefix.blank?
+ associations.each do |type, names|
+ names.each do |name|
+ it "#{it_prefix}#{type} #{name}" do
+ subject.to_s.constantize.reflections.should include(name.to_sym)
+ end
+ end
+ end
+end

0 comments on commit 2d7206d

Please sign in to comment.