Skip to content

Commit

Permalink
Merge pull request #27 from wonderificdave/issue24
Browse files Browse the repository at this point in the history
Issue-24: Add feature to filter people report by staff / not staff
  • Loading branch information
asalant committed May 18, 2016
2 parents 570538e + 62560b7 commit 7c84e53
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ def people
if (params[:report])
@report = params[:report].merge :for_organization => @organization,
:after => params[:report][:after],
:before => params[:report][:before]
:before => params[:report][:before],
:is_staff => params[:report][:is_staff]
@report.delete(:matching_name) if @report[:matching_name] && @report[:matching_name].length < 3
@report.delete(:is_staff) if @report[:is_staff] && @report[:is_staff] == "all"
@report.delete_if { |key, value| value.nil? || (value.respond_to?(:empty?) && value.empty?) }
else
@report = {:for_organization => @organization,
Expand Down
4 changes: 4 additions & 0 deletions app/models/person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def on(service_type, time)
:conditions => [ "LOWER(full_name) LIKE :name", { :name => "%#{name.downcase}%"} ]
} }

named_scope :is_staff, lambda { |is_staff| {
:conditions => [ "people.staff = ?", is_staff]
} }

def initialize(params={})
super
self.country ||= 'US'
Expand Down
12 changes: 12 additions & 0 deletions app/views/reports/people.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
-capture do
%div= text_field_tag 'report[matching_name]', @report[:matching_name]
%p.instruct Match 3 or more letters in a person's first and last name.
=labeled_input 'Type', :for => 'report[is_staff]' do
-capture do
%span.option
= radio_button_tag 'report[is_staff]', "all", @report[:is_staff] == nil
%label{:for => 'report[is_staff]'} All
%span.option
= radio_button_tag 'report[is_staff]', 1, @report[:is_staff] == "1"
%label{:for => 'report[is_staff]'} Staff
%span.option
= radio_button_tag 'report[is_staff]', 0, @report[:is_staff] == "0"
%label{:for => 'report[is_staff]'} Patrons
%p.instruct Select All, Staff, or Patrons
=labeled_input 'Date Range', :for => 'date_from' do
-capture do
%span
Expand Down
4 changes: 4 additions & 0 deletions public/stylesheets/form.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ form p.instruct {
z-index:1000;
}

form span.option {
width:10%;
}

input.checkbox,
input.radio {
display: block;
Expand Down
11 changes: 11 additions & 0 deletions test/unit/person_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ def test_in_date_range
assert_equal 2, Person.after(from).before(to).size
end

def test_is_staff
assert_equal 2, Person.is_staff(true).size
Person.is_staff(true).each do |person|
assert person.staff
end
assert_equal 6, Person.is_staff(false).size
Person.is_staff(false).each do |person|
assert !person.staff
end
end

def test_email_validation
assert Person.create(:organization => organizations(:sfbk), :email => '[email protected]').errors.invalid?(:email)
assert Person.create(:organization => organizations(:sfbk), :email => 'mary@example').errors.invalid?(:email)
Expand Down

0 comments on commit 7c84e53

Please sign in to comment.