Skip to content

Commit

Permalink
Hiding form field label when param is hidden.
Browse files Browse the repository at this point in the history
Hiding group param on cohort reports
  • Loading branch information
rdh committed Apr 24, 2014
1 parent 2bf0687 commit e9f6cba
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/helpers/report_cat/reports_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def report_form( report )
form_tag report_path( report.name ), :method => :get do
@report.params.each do |param|
name = t( param.name, :scope => [ :report_cat, :params ] )
name = '' if param.options[ :hidden ]
concat content_tag( :div, label_tag( name ) + report_param( param ) )
end
concat submit_tag( t( :report, :scope => :report_cat ) )
Expand Down
3 changes: 3 additions & 0 deletions lib/report_cat/core/param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def value=( value )
end
end

def hide
@options[ :hidden ] = true
end
end
end
end
2 changes: 2 additions & 0 deletions lib/report_cat/reports/cohort_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def initialize( attributes = {} )
defaults = { :name => :cohort_report }
super( defaults.merge( attributes ) )

param( :group ).hide

add_column( :total, :integer )

if @cohort = attributes[ :cohort ]
Expand Down
2 changes: 1 addition & 1 deletion spec/data/helpers/report_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
<option value="30">30</option>
<option value="31">31</option>
</select>
</div><div><label for="_span_class__translation_missing__title__translation_missing:_en.report_cat.params.hidden_test__Hidden_Test__span_">&lt;span class=&quot;translation missing&quot; title=&quot;translation missing: en.report cat.params.hidden test&quot;&gt;hidden test&lt;/span&gt;</label><input id="hidden_test" name="hidden_test" type="hidden" value="true" /></div><div><label for="_span_class__translation_missing__title__translation_missing:_en.report_cat.params.select_test__Select_Test__span_">&lt;span class=&quot;translation missing&quot; title=&quot;translation missing: en.report cat.params.select test&quot;&gt;select test&lt;/span&gt;</label><select id="select_test" name="select_test"><option selected="selected" value="1">1</option>
</div><div><label></label><input id="hidden_test" name="hidden_test" type="hidden" value="true" /></div><div><label for="_span_class__translation_missing__title__translation_missing:_en.report_cat.params.select_test__Select_Test__span_">&lt;span class=&quot;translation missing&quot; title=&quot;translation missing: en.report cat.params.select test&quot;&gt;select test&lt;/span&gt;</label><select id="select_test" name="select_test"><option selected="selected" value="1">1</option>
<option value="2">2</option>
<option value="3">3</option></select></div><div><label for="_span_class__translation_missing__title__translation_missing:_en.report_cat.params.text_field_test__Text_Field_Test__span_">&lt;span class=&quot;translation missing&quot; title=&quot;translation missing: en.report cat.params.text field test&quot;&gt;text field test&lt;/span&gt;</label><input id="text_field_test" name="text_field_test" type="text" /></div><input name="commit" type="submit" value="Report" /></form>
13 changes: 12 additions & 1 deletion spec/lib/report_cat/core/param_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module ReportCat::Core

describe Param do

let( :param ) { Param.new }

before( :each ) do
@name = :test
@type = :select
Expand All @@ -24,7 +26,6 @@ module ReportCat::Core
end

it 'initializes options to an empty hash' do
param = Param.new
expect( param.options ).to eql( {} )
end

Expand Down Expand Up @@ -79,6 +80,16 @@ module ReportCat::Core

end

describe '#hide' do

it 'sets the hidden option to true' do
expect( param.options[ :hidden ] ).to be_nil
param.hide
expect( param.options[ :hidden ] ).to be_true
end

end

end

end
4 changes: 4 additions & 0 deletions spec/lib/report_cat/reports/cohort_report_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ module Reports
@report.should have_param( :bar ).with_type( :string )
end

it 'hides the group param' do
expect( @report.param( :group ).options[ :hidden ] ).to be_true
end

end

#############################################################################
Expand Down

0 comments on commit e9f6cba

Please sign in to comment.