Skip to content

Commit

Permalink
Merge branch 'qa'
Browse files Browse the repository at this point in the history
  • Loading branch information
smeeks committed Jan 21, 2024
2 parents 306d2b5 + c150abc commit 16fc36f
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 7 deletions.
33 changes: 31 additions & 2 deletions app/controllers/scenarios_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def show
end
#@phase_filter_ali_code = params[:filter_ali] || @scenario.draft_project_phases.min_by(&:fy_year).team_ali_code #TODO: what should be default here?
respond_to do |format|
format.html
format.html {render :show, locals: {new_scenario: params[:new_scenario]}}
end

end
Expand Down Expand Up @@ -90,7 +90,7 @@ def create

respond_to do |format|
if @scenario.update(form_params)
format.html { redirect_to scenario_path(@scenario) }
format.html { redirect_to scenario_path(@scenario, new_scenario: true) }
else
format.html
end
Expand Down Expand Up @@ -139,6 +139,35 @@ def copy
end
end

#-----------------------------------------------------------------------------
# Toggle Primary Scenario
#-----------------------------------------------------------------------------
def toggle_primary
set_scenario

unless @scenario.primary_scenario
if old_primary = Scenario.find_by(organization: @scenario.organization, fy_year: @scenario.fy_year, primary_scenario: true)
unless old_primary.update(primary_scenario: false)
error = old_primary.errors.try(:first)
if error
flash.alert = error.try(:last)
end
end
end
end

respond_to do |format|
if @scenario.update(primary_scenario: !@scenario.primary_scenario)
format.html { redirect_to scenario_path(@scenario) }
else
error = @scenario.errors.try(:first)
if error
flash.alert = error.try(:last)
end
end
end
end

#-----------------------------------------------------------------------------
# Transition States
#
Expand Down
2 changes: 2 additions & 0 deletions app/models/draft_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def as_json(options={})
agency: organization.try(:to_s),
fy_year: formatted_fiscal_year,
project_number: project_number,
primary_scenario: scenario.try(:primary_scenario),
scope: team_ali_code.try(:scope),
is_emergency: emergency?,
is_sogr: sogr?,
Expand Down Expand Up @@ -218,6 +219,7 @@ def self.to_csv scenarios
"Org": "organization_short_name",
"FY": "formatted_fiscal_year",
"Project": "project_number",
"Primary Scenario": "primary_scenario",
"Title": "title",
"Scope": "scope",
"Cost": "cost",
Expand Down
1 change: 1 addition & 0 deletions app/models/scenario.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Scenario < ApplicationRecord
validates :organization_id, presence: true
validates :fy_year, presence: true
validates :ending_fy_year, presence: true
validates :primary_scenario, uniqueness: {scope: [:organization, :fy_year]}, if: :primary_scenario

#------------------------------------------------------------------------------
# Scopes
Expand Down
1 change: 1 addition & 0 deletions app/views/draft_projects/_index_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
%th.left{data: {field: 'agency', visible: "#{@organization_list.count > 1}"}} Agency
%th.center.nowrap{data: {field: 'fy_year'}} #{get_fy_label}
%th.left.nowrap{data: {field: 'project_number'}} Project Name
%th.center{data: {field: 'primary_scenario', formatter: 'raw_boolean_x_formatter'}} Primary Scenario
%th.left{data: {visible: 'false', field: 'title'}} Title
%th.left.nowrap{data: {visible: 'false', field: 'description'}} Project Description
%th.left.nowrap{data: {visible: 'false', field: 'justification'}} Project Justification
Expand Down
1 change: 1 addition & 0 deletions app/views/draft_projects/index.xlsx.axlsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ wb.styles do |style|
organization: ["Agency", "project.organization.short_name"],
year: ["FY", "format_as_fiscal_year(project.fy_year)"],
project_id: ["Project Name", "project.project_number.to_s.split('#').last"],
primary_scenario: ["Primary Scenario", "format_as_yes_no(project.scenario.try(:primary_scenario))"],
title: ["Title", "project.title"],
project_description: ["Project Description", "project.description"],
project_justification: ["Project Justification", "project.justification"],
Expand Down
1 change: 1 addition & 0 deletions app/views/draft_projects/phases.xlsx.axlsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ wb.styles do |style|
project_id: ["Project ID", "phase.draft_project.project_number.to_s.split('#').last"],
organization: ["Organization", "phase.scenario.organization"],
project_year: ["Project Year", "format_as_fiscal_year(phase.draft_project.fy_year)"],
primary_scenario: ["Primary Scenario", "format_as_yes_no(phase.scenario.primary_scenario)"],
project_title: ["Project Title", "phase.draft_project.title"],
scope: ["Scope", "phase.team_ali_code.try(:scope)"],
project_type: ["Project Type", "phase.draft_project.capital_project_type"],
Expand Down
6 changes: 4 additions & 2 deletions app/views/scenarios/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@
:search => 'client',
:export => "['csv', 'txt']",
:columns => '{"name":{"name": "Name","type":"drilldown-link"},
"primary_scenario":{"name":"Primary Scenario","type":"x-column"},
"status":{"name":"Status"},
"org":{"name":"Organization"},
"created_at":{"name":"Created At"}}',
:selected_columns => "name,status,org,created_at",
:selected_columns => "name,primary_scenario,status,org,created_at",
:cookies => "true",
:sort => 'client',
:sort_params => @params,
Expand All @@ -105,7 +106,8 @@
add_row('#{table_dom_id}',
{
"name": '#{link_to scenario.name, scenario_path(scenario)}',
"primary_scenario": "#{format_as_boolean(scenario.primary_scenario, "fa-times")}",
"status": '#{scenario.state_title}',
"org": '#{scenario.organization.name}',
"created_at": "#{format_as_date_time(scenario.created_at)}"
}, #{index});
}, #{index});
26 changes: 24 additions & 2 deletions app/views/scenarios/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
cursor: pointer;
}

#primary-scenario-selector {
font-size: large;
}

#primary-scenario-selector a {
text-decoration: none;
color: inherit;
}

.row.text-center
%h1
=@scenario.name
Expand Down Expand Up @@ -44,7 +53,17 @@
=link_to assets_scenario_path(@scenario), target: "_blank" do
%i.fa.fa-search
Assets

.row
#primary-scenario-selector
- if [email protected]_scenario
- old_primary = Scenario.find_by(organization: @scenario.organization, fy_year: @scenario.fy_year, primary_scenario: true)
=link_to toggle_primary_scenario_path(@scenario),
method: :put,
data: old_primary ? {confirm: "This agency already has a Primary Scenario for this fiscal year. Would you like to mark this scenario as the new Primary Scenario?"} : {} do
%i{class: "fa fa-square-o"}
- else
%i{class: "fa fa-times-rectangle-o"}
%strong Primary Scenario
.col-md-4
// .progress
Expand Down Expand Up @@ -287,7 +306,10 @@
}
});


// Check the Primary Scenario box if this scenario is new, triggering confirmation if previous scenario selected
if (#{new_scenario == "true"}) {
$('#primary-scenario-selector a').click();
}
});


1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
get 'assets'
post 'copy'
get 'dotgrants_export'
put 'toggle_primary'
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPrimaryScenarioToScenarios < ActiveRecord::Migration[5.2]
def change
add_column :scenarios, :primary_scenario, :boolean
end
end
2 changes: 1 addition & 1 deletion lib/transam_cpt/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module TransamCpt
VERSION = "2.35.0"
VERSION = "2.38.0"
end

0 comments on commit 16fc36f

Please sign in to comment.