From 3006fb52db1d352feb9cdc5643aceb616a580799 Mon Sep 17 00:00:00 2001 From: Dave Baker Date: Sat, 5 Mar 2016 18:01:03 -0800 Subject: [PATCH 1/2] Issue-24: Add feature to filter people report by staff / not staff --- app/controllers/reports_controller.rb | 4 +++- app/models/person.rb | 4 ++++ app/views/reports/people.html.haml | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index ee49ea14..fd1fa432 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -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, diff --git a/app/models/person.rb b/app/models/person.rb index 623fa517..702a249a 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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' diff --git a/app/views/reports/people.html.haml b/app/views/reports/people.html.haml index 6e256b33..ea22965c 100644 --- a/app/views/reports/people.html.haml +++ b/app/views/reports/people.html.haml @@ -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 + = radio_button_tag 'report[is_staff]', "all", @report[:is_staff] == nil + %label{:for => 'report[is_staff]'} All + %span + = radio_button_tag 'report[is_staff]', 1, @report[:is_staff] == "1" + %label{:for => 'report[is_staff]'} Staff + %span + = radio_button_tag 'report[is_staff]', 0, @report[:is_staff] == "0" + %label{:for => 'report[is_staff]'} Patrons + %p.instruct Select Staff, Patrons or all =labeled_input 'Date Range', :for => 'date_from' do -capture do %span From 62560b7539883d5ca7b652c4f10ad4fac77c37d3 Mon Sep 17 00:00:00 2001 From: Dave Baker Date: Tue, 17 May 2016 16:58:26 -0700 Subject: [PATCH 2/2] Adding test and UI changes based on feedback --- app/views/reports/people.html.haml | 8 ++++---- public/stylesheets/form.css | 4 ++++ test/unit/person_test.rb | 11 +++++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/views/reports/people.html.haml b/app/views/reports/people.html.haml index ea22965c..bde1cde5 100644 --- a/app/views/reports/people.html.haml +++ b/app/views/reports/people.html.haml @@ -10,16 +10,16 @@ %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 + %span.option = radio_button_tag 'report[is_staff]', "all", @report[:is_staff] == nil %label{:for => 'report[is_staff]'} All - %span + %span.option = radio_button_tag 'report[is_staff]', 1, @report[:is_staff] == "1" %label{:for => 'report[is_staff]'} Staff - %span + %span.option = radio_button_tag 'report[is_staff]', 0, @report[:is_staff] == "0" %label{:for => 'report[is_staff]'} Patrons - %p.instruct Select Staff, Patrons or all + %p.instruct Select All, Staff, or Patrons =labeled_input 'Date Range', :for => 'date_from' do -capture do %span diff --git a/public/stylesheets/form.css b/public/stylesheets/form.css index 72d6c8c9..3c31b2fa 100644 --- a/public/stylesheets/form.css +++ b/public/stylesheets/form.css @@ -84,6 +84,10 @@ form p.instruct { z-index:1000; } +form span.option { + width:10%; +} + input.checkbox, input.radio { display: block; diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 9dc2184a..10c478b0 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -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 => 'mary@example.com').errors.invalid?(:email) assert Person.create(:organization => organizations(:sfbk), :email => 'mary@example').errors.invalid?(:email)