diff --git a/app/controllers/scenarios_controller.rb b/app/controllers/scenarios_controller.rb index 9f771e25..d5615e7b 100644 --- a/app/controllers/scenarios_controller.rb +++ b/app/controllers/scenarios_controller.rb @@ -19,8 +19,13 @@ class ScenariosController < OrganizationAwareController #----------------------------------------------------------------------------- def index @fy_year = allowed_params[:fy_year] || current_planning_year_year + @status = allowed_params[:status] @scenarios = Scenario.where(fy_year: @fy_year, organization: current_user.viewable_organizations).order(created_at: :desc) + if @status + @scenarios = @scenarios.where(state: @status) + end + respond_to do |format| format.html end @@ -187,7 +192,7 @@ def form_params end def allowed_params - params.permit(:fy_year) + params.permit(:fy_year, :status) end def set_scenario diff --git a/app/views/scenarios/index.html.haml b/app/views/scenarios/index.html.haml index d6a26033..1e4a6d90 100644 --- a/app/views/scenarios/index.html.haml +++ b/app/views/scenarios/index.html.haml @@ -4,15 +4,21 @@ %i.fa.fa-plus %h5 .row - .col-md-1 + .col-md-4 %form %select#yearSelector -(2020..2050).each do |year| %option{value: "#{year}", selected: (year.to_s==@fy_year.to_s)} =format_as_fiscal_year year + %label{style: "margin-left: 5px;"} Filter by Status + %select#statusFilter + %option{value: "", selected: @status == nil} + - Scenario.all.map{|s| s.state}.uniq.each do |state| + %option{value: state, selected: state == @status} + = state == "cancelled" ? "Closed" : state.titleize -if current_user.organization.try(:organization_type).try(:name) == "Grantor" - .col-md-10 + .col-md-7 .col-md-1 =link_to export_to_csv_draft_projects_path(fy_year: @fy_year) do %i.fa.fa-file-excel-o @@ -21,26 +27,51 @@ .row .col-md-12 - =column_chart Scenario.peaks_and_valleys_chart_data(nil, @fy_year), prefix: "$", stacked: true + =column_chart Scenario.peaks_and_valleys_chart_data(nil, @fy_year), prefix: "$", library: {scales: {yAxes: [{id: 'y-axis', type: 'logarithmic'},]}} :javascript $(document).ready(function () { + // Pre-populate filters used for the scenarios table + var scenarioFilters = {fy_year: #{@fy_year}, status: "#{@status}"}; // This controls the year dropdown in each asset table $("#yearSelector").change(function(){ var year = $(this).val(); - goToYear(year); + scenarioFilters["fy_year"] = year; + applyFilters(scenarioFilters); }); + // Filter the table by scenario status + $("#statusFilter").change(function(){ + var scenarioStatus = $(this).val(); + scenarioFilters["status"] = scenarioStatus; + applyFilters(scenarioFilters); + }); }); - function goToYear(year){ - window.location.replace("/scenarios?fy_year=" + year); + // function goToYear(year){ + // window.location.replace("/scenarios?fy_year=" + year); + // } + + function applyFilters(filters){ + // Construct params string using filter values + var filtersParamString = "?"; + Object.keys(filters).forEach(function(filter) { + if (filters[filter] != "") { + filtersParamString += filter + "=" + filters[filter] + "&"; + } + }); + filtersParamString = filtersParamString.slice(0, -1); + + window.location.replace("/scenarios" + filtersParamString); } + // function filterByStatus(status){ + // window.location.replace("/scenarios?status=" + status); + // } :ruby table_dom_id = SecureRandom.hex diff --git a/app/views/scenarios/show.html.haml b/app/views/scenarios/show.html.haml index 192d6530..01c7395a 100644 --- a/app/views/scenarios/show.html.haml +++ b/app/views/scenarios/show.html.haml @@ -71,7 +71,7 @@ .row .col-md-12 - =column_chart Scenario.peaks_and_valleys_chart_data(@scenario), prefix: "$", stacked: true, label: "Value" + =column_chart Scenario.peaks_and_valleys_chart_data(@scenario), prefix: "$", label: "Value", library: {scales: {yAxes: [{id: 'y-axis', type: 'logarithmic'},]}} .row -@budgets.each_slice(6) do |budgets| diff --git a/lib/transam_cpt/version.rb b/lib/transam_cpt/version.rb index eb0cab1c..d86d3186 100644 --- a/lib/transam_cpt/version.rb +++ b/lib/transam_cpt/version.rb @@ -1,3 +1,3 @@ module TransamCpt - VERSION = "2.23.0" + VERSION = "2.26.0" end