Skip to content

Commit

Permalink
Merge pull request #2034 from sparc-request/bs4-reports
Browse files Browse the repository at this point in the history
SAW - Bootstrap 4 Reports Fixes
  • Loading branch information
Stuart-Johnson committed Oct 8, 2019
2 parents 8bf70d2 + b2ef4a0 commit 097c914
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 13 deletions.
7 changes: 5 additions & 2 deletions app/assets/javascripts/reporting.js.coffee
Expand Up @@ -44,11 +44,14 @@ $(document).ready ->

$(document).on "submit", "#reporting-form", (event) ->
empty = $('.required').filter ->
this.value == ""
$("##{$(this).prop('for')}").selectpicker('val') == ""

if empty.length
$("[name^='report']:not([type='hidden'])").parents('.form-group').removeClass('is-invalid').addClass('is-valid')
$('.form-error').remove()
empty.each ->
$("[name='report[#{$(this).prop('for')}]']").parents('.form-group').removeClass('is-valid').addClass('is-invalid').append("<small class='form-text form-error'>#{I18n.t('constants.required_fields.required')}</small>")
event.preventDefault()
alert(I18n.t('reporting.actions.errors'))

optionswitch = (myfilter, res) ->
#Populate the optionstore if the first time through
Expand Down
2 changes: 1 addition & 1 deletion app/lib/reports/protocols.rb
Expand Up @@ -131,7 +131,7 @@ def where args={}
end

if args[:service_requests_original_submitted_date_from] and args[:service_requests_original_submitted_date_to]
submitted_at = args[:service_requests_original_submitted_date_from].to_time.strftime("%Y-%m-%d 00:00:00")..args[:service_requests_original_submitted_date_to].to_time.strftime("%Y-%m-%d 23:59:59")
submitted_at = DateTime.strptime(args[:service_requests_original_submitted_date_from], "%m/%d/%Y").to_s(:db)..DateTime.strptime(args[:service_requests_original_submitted_date_to], "%m/%d/%Y").strftime("%Y-%m-%d 23:59:59")
end

# default values if none are provided
Expand Down
2 changes: 1 addition & 1 deletion app/lib/reports/service_pricing_report.rb
Expand Up @@ -184,7 +184,7 @@ def where args={}

service_organizations = Organization.where(id: service_organization_ids)

date = args[:services_pricing_date] ? Date.parse(args[:services_pricing_date]) : Date.today
date = args[:services_pricing_date] ? Date.strptime(args[:services_pricing_date], "%m/%d/%Y") : Date.today
query = "`pricing_maps`.`display_date` <= '#{date}' and `services`.`organization_id` IN (#{service_organization_ids.join(',')})"
## commented out to remove tags, but will likely be added in later ##
return query # + (args[:tags] ? " and tags.name IN (\"#{args[:tags].join('\",\"')}\")" : "")
Expand Down
2 changes: 1 addition & 1 deletion app/lib/reports/service_requests.rb
Expand Up @@ -160,7 +160,7 @@ def where args={}
end

if args[:submitted_at_from] and args[:submitted_at_to]
submitted_at = args[:submitted_at_from].to_time.strftime("%Y-%m-%d 00:00:00")..args[:submitted_at_to].to_time.strftime("%Y-%m-%d 23:59:59")
submitted_at = DateTime.strptime(args[:submitted_at_from], "%m/%d/%Y").to_s(:db)..DateTime.strptime(args[:submitted_at_to], "%m/%d/%Y").strftime("%Y-%m-%d 23:59:59")
end

# default values if none are provided
Expand Down
4 changes: 2 additions & 2 deletions app/lib/reports/short_interactions.rb
Expand Up @@ -76,8 +76,8 @@ def includes

# Conditions
def where args={}
fdate = args[:short_interaction_created_at_from].nil? ? self.default_options["Created Date Range"][:from].to_time.strftime("%Y-%m-%d 00:00:00") : args[:short_interaction_created_at_from].to_time.strftime("%Y-%m-%d 00:00:00")
tdate = args[:short_interaction_created_at_to].nil? ? self.default_options["Created Date Range"][:to].to_time.strftime("%Y-%m-%d 23:59:59") : args[:short_interaction_created_at_to].to_time.strftime("%Y-%m-%d 23:59:59")
fdate = (args[:short_interaction_created_at_from].nil? ? self.default_options["Created Date Range"][:from] : DateTime.strptime(args[:short_interaction_created_at_from], "%m/%d/%Y")).to_s(:db)
tdate = (args[:short_interaction_created_at_to].nil? ? self.default_options["Created Date Range"][:to] : DateTime.strptime(args[:short_interaction_created_at_to], "%m/%d/%Y")).strftime("%Y-%m-%d 23:59:59")
created_at = fdate..tdate

organizations = Organization.all
Expand Down
4 changes: 2 additions & 2 deletions app/lib/reports/sparc_account.rb
Expand Up @@ -77,8 +77,8 @@ def includes

# Conditions
def where args={}
fdate = args[:created_at_from].nil? ? self.default_options["Created Date Range"][:from].to_time.strftime("%Y-%m-%d 00:00:00") : args[:created_at_from].to_time.strftime("%Y-%m-%d 00:00:00")
tdate = args[:created_at_to].nil? ? self.default_options["Created Date Range"][:to].to_time.strftime("%Y-%m-%d 23:59:59") : args[:created_at_to].to_time.strftime("%Y-%m-%d 23:59:59")
fdate = (args[:created_at_from].nil? ? self.default_options["Created Date Range"][:from] : DateTime.strptime(args[:created_at_from], "%m/%d/%Y")).to_s(:db)
tdate = (args[:created_at_to].nil? ? self.default_options["Created Date Range"][:to] : DateTime.strptime(args[:created_at_to], "%m/%d/%Y")).strftime("%Y-%m-%d 23:59:59")
created_at = fdate..tdate
statuses = args[:approved] || [1, 0]
return {:created_at => created_at, :approved => statuses}
Expand Down
9 changes: 5 additions & 4 deletions app/lib/reports/survey_responses.rb
Expand Up @@ -87,8 +87,9 @@ def joins(args={})

# Conditions
def where args={}
created_at = (args[:created_at_from] ? args[:created_at_from] : self.default_options["Date Range"][:from]).to_time.strftime("%Y-%m-%d 00:00:00")..(args[:created_at_to] ? args[:created_at_to] : self.default_options["Date Range"][:to]).to_time.strftime("%Y-%m-%d 23:59:59")

created_at_from = (args[:created_at_from] ? DateTime.strptime(args[:created_at_from], "%m/%d/%Y") : self.default_options["Date Range"][:from]).to_s(:db)
created_at_to = (args[:created_at_to] ? DateTime.strptime(args[:created_at_to], "%m/%d/%Y") : self.default_options["Date Range"][:to]).strftime("%Y-%m-%d 23:59:59")
created_at = created_at_from..created_at_to
return :responses => {:created_at => created_at, :survey_id => args[:system_survey_id]}
end

Expand All @@ -111,8 +112,8 @@ def order
def create_report(worksheet)
super

start_date = (params[:created_at_from] ? params[:created_at_from] : "2012-03-01".to_date).to_time.strftime("%Y-%m-%d 00:00:00")
end_date = (params[:created_at_to] ? params[:created_at_to] : Date.today).to_time.strftime("%Y-%m-%d 23:59:59")
start_date = (params[:created_at_from] ? DateTime.strptime(params[:created_at_from], "%m/%d/%Y") : "2012-03-01".to_date).to_s(:db)
end_date = (params[:created_at_to] ? DateTime.strptime(params[:created_at_to], "%m/%d/%Y") : Date.today).strftime("%Y-%m-%d 23:59:59")
# assumes the first question where only one option can be picked is the satisfaction question
survey = Survey.find(params[:system_survey_id])
questions = Question.where(question_type: ['yes_no', 'likert', 'radio_button'], section: Section.where(survey: survey))
Expand Down
1 change: 1 addition & 0 deletions app/views/reports/index.html.haml
Expand Up @@ -23,6 +23,7 @@
.card-body.p-xl-5#report-selection
%h1.card-title.text-center.mb-2
= t(:reporting)[:index][:intro]
%br
%small.card-subtitle.text-muted
= t(:reporting)[:index][:subtext]

Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -519,6 +519,7 @@ en:
required_fields:
indicator: "*"
message: "required fields"
required: "Required"
search:
loading: "Loading..."
no_results: "No Results"
Expand Down

0 comments on commit 097c914

Please sign in to comment.