Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KG - SPARCRequest Reports Code Cleanup #194

Merged
merged 5 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 15 additions & 14 deletions app/assets/javascripts/reporting.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,28 @@
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

$(document).ready ->

$(document).on "click", "#reporting_return_to_list", (event) ->
$(document).on "click", "#reporting-return-to-list", (event) ->
event.preventDefault()
$('#defined_reports_step_2').hide()
$("#report_selection").show()
$('#report-container').hide()
$('#report-selection').show()

$(document).on "change", ".reporting_field", ->
$(document).on "change", ".reporting-field", ->
parent_id = "#" + $(this).attr('id')
window.check_deps(parent_id)
if $(this).val() != ""
$(".check_dep_class.needs_update").each ->
$(this).removeClass('needs_update')
$(this).prop('disabled', false)
$(".check-dep.needs-update").each ->
$(this).removeClass('needs-update')
$(this).siblings('.bootstrap-select').children('button').prop('disabled', false)
cattype = $(parent_id).val()
optionswitch(cattype, "#" + $(this).attr('id'))

$(document).on "submit", "#reporting_form", (event) ->
empty = $('.required_field').filter ->
$(document).on "submit", "#reporting-form", (event) ->
empty = $('.required').filter ->
this.value == ""

if empty.length
event.preventDefault()
alert "Please fill out all required fields"
alert I18n['reporting']['actions']['errors']

optionswitch = (myfilter, res) ->
#Populate the optionstore if the first time through
Expand All @@ -60,6 +59,7 @@ optionswitch = (myfilter, res) ->
#put the filtered stuff back
populateoption = rewriteoption(myfilter, res)
$(res).html(populateoption)
$(res).selectpicker('refresh')

rewriteoption = (myfilter, res) ->
#rewrite only the filtered stuff back into the option
Expand Down Expand Up @@ -91,12 +91,13 @@ window.create_single_date_pickers = ->
$(".datetimepicker").datetimepicker(format: 'YYYY-MM-DD', allowInputToggle: true)

window.check_deps = (parent_id) ->
$(".check_dep_class").each ->
$("select.check-dep").each ->
dep = $(this).data("dependency")

if dep.match(parent_id)
$(this).addClass("needs_update")
$(this).addClass("needs-update")
$(this).val("")

if $(dep).val() == ""
$(this).prop('disabled', true)
$(this).siblings('.bootstrap-select').children('button').prop('disabled', true)

7 changes: 4 additions & 3 deletions app/assets/stylesheets/dashboard/layout.sass
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@
padding-bottom: 15px

// Custom Reporting Styling
h2.report_title
h2.report-title
padding: 10px
margin-bottom: 50px

#reporting_form #report_fields .checkbox-inline
#reporting-form #report-fields .checkbox-inline
margin: 0px 30px 0 0
cursor: auto

#reporting_form .report_actions
#reporting-form .report-actions
margin-top: 40px

//Custom Navbar Styling
Expand Down Expand Up @@ -148,6 +148,7 @@ h2.report_title
#container > #inner-content
// these are cwf specs
width: 1300px !important
min-height: 625px
margin-left: auto
margin-right: auto
padding-left: 15px
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/proper/layout.sass
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
color: #555

#inner-content
min-height: 625px
width: 1300px
margin-left: auto
margin-right: auto
Expand Down
27 changes: 7 additions & 20 deletions app/views/layouts/reporting.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
!!!
%html
%head
%title SPARC Request Reporting
= stylesheet_link_tag "#{CUSTOM_ASSET_PATH}dashboard/application"
%title
= t(:reporting)[:header]
= stylesheet_link_tag "dashboard/application"
= javascript_include_tag 'dashboard/application'
/[if IE]
= stylesheet_link_tag 'ie'
Expand All @@ -35,32 +36,18 @@
window.I18n = #{current_translations.to_json.html_safe};

%body#body
#ie7_warning{style: 'display: none'}
%p
= t('ie_warning.text1')
%br
%p
= t('ie_warning.text2')

= image_tag 'cancel.png', :style => 'display:none'

#container
#processing_request.ui-corner-all{style: 'display:none'}
%br
= t(:cm_index)[:processing]
%br
= image_tag 'spinner.gif'
#header
= render 'layouts/header_logos', in_dashboard: true, location: @location
%input#current_user_id{type: 'hidden', value: @user.try(:id)}
= render 'layouts/dashboard/dashboard_header', user: @user

.notification_dialog
.flash
= render "shared/flash"
#inner-content
= render 'shared/flash'
#inner-content.row
= yield

%footer
= render 'layouts/footer'
= render 'shared/piwik_tracking' if Rails.env == 'production'
= render 'shared/ie7_modal'
= render 'shared/modal'
158 changes: 12 additions & 146 deletions app/views/reports/_setup.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -17,153 +17,19 @@
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

%h2.report_title.text-center.bg-primary= @report.title

= form_tag generate_reports_path, :id => "reporting_form", :class => "form-horizontal" do
= hidden_field_tag "report[type]", @report.class.name

#report_fields
- @report.options.each do |field,options|
%h2.report-title.text-center.bg-primary
= report.title
= form_tag generate_reports_path, id: 'reporting-form', class: "form-horizontal" do
= hidden_field_tag 'report[type]', report.class.name
#report-fields
- report.options.each do |field, options|
.form-group
- field_type = options[:field_type] || 'text_field_tag'
- field_label = options[:field_label] || field.to_s.titleize
- field_label += " *" if options[:required] and not field_type == :date_range

/* TODO - extract these into either helpers or a custom form builder */
/* text_field_tag */
- if field_type == :text_field_tag
- dependency = options[:dependency]
- default_classes = "form-control text_field"
- default_classes = " required_field" if options[:required]
- check_dep_class = dependency ? 'check_dep_class' : nil
- id = options[:for] ? options[:for] : field.delete(" ").underscore
- name = options[:for] ? "report[" + options[:for] + "]" : "report[" + id + "]"

%label{:for => id, :class => "col-sm-3 control-label"}= field_label
.col-sm-9
= text_field_tag name, nil, :id => id, :class => default_classes, :type => "text"
/* end text_field_tag */

/* select_tag */
- if field_type == :select_tag
- if field.is_a? Class and field.respond_to?(:where) # we have a select tag that we need to get records for
- records = field.where(options[:filters])
- dependency = options[:dependency]
- default_classes = "form-control reporting_field"
- default_classes += " required_field" if options[:required]
- default_classes += " selectpicker" if options[:selectpicker]
- check_dep_class = dependency ? 'check_dep_class' : nil
- id = options[:for] || "#{field.name.underscore}_id"
- name = options[:for] ? "report[#{options[:for]}]" : "report[#{field.name.underscore}_id]"
- name_method = options[:custom_name_method] || :name

%label{:for => id, :class => "col-sm-3 control-label"}= field_label
.col-sm-9
%select{:"data-dependency" => dependency, :class => [default_classes, check_dep_class].join(" "), :name => name, :id => id}
%option{:value => ""} Select One
- records.each do |record|
- #next if record.respond_to?(:is_available) and not record.is_available?
- option_class = nil
- if dependency
- dependency_id = options[:dependency_id] || dependency.sub(/^#/, "") # either an id is specified or we assume the dependency is the id
- if record.respond_to? dependency_id.to_s
- option_class = "sub-#{record.send dependency_id}"
%option{:value => record.id, :class => option_class}
- if record.class.to_s == "Survey"
= record.title + " - Version " + record.survey_version.to_s
- else
= record.send(name_method)
/* end select_tag */

/* date_field */
- if field_type == :date_field
- default_classes = "form-control date datetimepicker"
- default_classes += " required_field" if options[:required]
- id = options[:for] ? options[:for] : field.delete(" ").underscore
- name = options[:for] ? "report[" + options[:for] + "]" : "report[" + id + "]"
%label{:for => id, :class => "col-sm-3 control-label"}= field_label
.col-sm-9
.input-group.date
= text_field_tag name, nil, :id => id, :class => default_classes
%span.input-group-addon
%span.glyphicon.glyphicon-calendar

/* date_range */
- if field_type == :date_range
- default_classes = "form-control date datetimepicker"
- default_classes += " required_field" if options[:required]
%label{:class => "col-sm-3 control-label"}= field_label

/* from information */
- from_id = options[:for] ? options[:for] + "_from" : field.delete(" ").underscore + "_from"
- from_name = options[:for] ? "report[" + options[:for] + "_from]" : "report[" + from_id + "]"
- from_label = options[:from_label] || "From"
- from_label += " *" if options[:required]
- from_date = options[:from] ? options[:from].strftime('%B %d, %Y %H:%M:%S') : nil

/* to information */
- to_id = options[:for] ? options[:for] + "_to" : field.delete(" ").underscore + "_to"
- to_name = options[:for] ? "report[" + options[:for] + "_to]" : "report[" + to_id + "]"
- to_label = options[:to_label] || "To"
- to_label += " *" if options[:required]
- to_date = options[:to] ? options[:to].strftime('%B %d, %Y %H:%M:%S') : nil

%label{:for => from_id, :class => 'col-sm-1 col-sm-offset-1 control-label'}= from_label
.col-sm-3
.input-group.date
= text_field_tag from_name, nil, :id => from_id, :"data-from" => from_date, :class => default_classes
%span.input-group-addon
%span.glyphicon.glyphicon-calendar

%label{:for => to_id, :class => 'col-sm-1 control-label'}= to_label
.col-sm-3
.input-group.date
= text_field_tag to_name, nil, :id => to_id, :"data-to" => to_date, :class => default_classes
%span.input-group-addon
%span.glyphicon.glyphicon-calendar
/* end date_range */

/* check_box_tag */
- if field_type == :check_box_tag
- multiple = options[:multiple]
- grouping = options[:grouping]
- selected = options[:selected] || []
- default_classes = options[:required] ? "required_field" : ""
- name = options[:for] ? "report[#{options[:for]}]" : "report[#{field.name.underscore}_id]"
- name += "[]" if multiple
%label.col-sm-3.control-label= field_label

- if grouping and multiple # we have a defined grouping
.col-sm-9
- grouping.each do |k,v|
.row
%fieldset
%legend= k
- v.each do |sv|
%label{:for => sv, :class => 'checkbox-inline'}
= check_box_tag name, sv, selected.include?(sv), :class => default_classes, :type => "checkbox"
= multiple[sv]

- elsif multiple
- if multiple.is_a? Hash
.col-sm-9
- multiple.each do |k,v|
%label{:for => k, :class => 'checkbox-inline'}
= check_box_tag name, k, selected.include?(v), :class => default_classes, :type => "checkbox"
= v

- else # for individual checkboxes that have true/false
/ %label{:for => options[:for]}= field_label
.col-sm-9
= check_box_tag name, true, nil, :class => default_classes, :type => "checkbox"
/* TODO define behavior if multiple is a method or string representation of method chain */

/* end check_box_tag */
- field_type = options[:field_type] || 'text_field_tag'
- field_label = "#{options[:field_label] || field.to_s.titleize}:"

/* submit button */
.report_actions.text-center
= submit_tag t(:reports)[:create_report], :class => "btn btn-success"
= button_to "Return to reports list", reports_path, :method => :get, :id => "reporting_return_to_list", :class => "btn btn-primary"
= render "reports/form_partials/#{options[:field_type]}_form_partial", options: options, field_label: field_label, field: field
.report-actions.text-center
= submit_tag t(:reporting)[:actions][:create], class: "btn btn-success"
= button_to t(:reporting)[:actions][:return], reports_path, method: :get, id: "reporting-return-to-list", class: "btn btn-primary"
%br
%br
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-# Copyright © 2011-2016 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- multiple = options[:multiple]
- grouping = options[:grouping]
- selected = options[:selected] || []
- default_classes = options[:required] ? "required" : ""
- name = options[:for] ? "report[#{options[:for]}]" : "report[#{field.name.underscore}_id]"
- name += "[]" if multiple

= label_tag nil, field_label, class: ['col-sm-3 control-label', default_classes]
- if grouping && multiple # we have a defined grouping
.col-sm-9
- grouping.each do |k,v|
.row
%fieldset
%legend
= k
- v.each do |sv|
= label_tag sv, '', class: ['checkbox-inline', default_classes] do
= check_box_tag name, sv, selected.include?(sv), class: default_classes, type: "checkbox"
= multiple[sv]

- elsif multiple
- if multiple.is_a?(Hash)
.col-sm-9
- multiple.each do |k,v|
= label_tag k, '', class: ['checkbox-inline', default_classes] do
= check_box_tag name, k, selected.include?(v), class: default_classes, type: "checkbox"
= v

- else # for individual checkboxes that have true/false
.col-sm-9
= check_box_tag name, true, '', class: default_classes, type: "checkbox"

-# TODO define behavior if multiple is a method or string representation of method chain
30 changes: 30 additions & 0 deletions app/views/reports/form_partials/_date_field_form_partial.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-# Copyright © 2011-2016 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- required_class = options[:required] ? 'required' : ''
- default_classes = ['form-control date datetimepicker', required_class]
- id = options[:for] ? options[:for] : field.delete(" ").underscore
- name = options[:for] ? "report[#{options[:for]}]" : "report[#{id}]"

= label_tag id, field_label, class: ['col-sm-3 control-label', required_class]
.col-sm-9
.input-group.date
= text_field_tag name, nil, id: id, class: [default_classes, required_class]
%span.input-group-addon
%span.glyphicon.glyphicon-calendar