Skip to content

Commit

Permalink
Merge branch 'develop' into feature/linkedin-widget
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Oct 24, 2023
2 parents 8e73723 + b229dd2 commit 3049143
Show file tree
Hide file tree
Showing 155 changed files with 7,693 additions and 48 deletions.
58 changes: 58 additions & 0 deletions app/admin/ascor/assessment_indicators.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
ActiveAdmin.register ASCOR::AssessmentIndicator do
config.sort_order = 'id_asc'

menu label: 'Assessment Indicators', parent: 'ASCOR', priority: 4

actions :all, except: [:new, :create]

filter :code
filter :text
filter :indicator_type, as: :check_boxes, collection: ASCOR::AssessmentIndicator::INDICATOR_TYPES

data_export_sidebar 'ASCORAssessmentIndicators', display_name: 'ASCOR AssessmentIndicators'

permit_params :code, :indicator_type, :text

show do
attributes_table do
row :id
row :code
row :indicator_type
row :text
row :units_or_response_type
row :created_at
row :updated_at
end

active_admin_comments
end

form html: {'data-controller' => 'check-modified'} do |f|
f.semantic_errors(*f.object.errors.keys)

f.inputs do
f.input :indicator_type, as: :select, collection: ASCOR::AssessmentIndicator::INDICATOR_TYPES
f.input :code
f.input :text
f.input :units_or_response_type
end

f.actions
end

index do
id_column
column :indicator_type
column :code
column :text
actions
end

csv do
column :id
column :type, &:indicator_type
column :code
column :text
column :units_or_response_type
end
end
102 changes: 102 additions & 0 deletions app/admin/ascor/assessments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
ActiveAdmin.register ASCOR::Assessment do
config.sort_order = 'assessment_date_desc'
includes :country

menu label: 'Assessments', parent: 'ASCOR', priority: 5

permit_params :country_id, :assessment_date, :publication_date, :notes,
results_attributes: [:id, :assessment_id, :indicator_id, :answer, :source, :year, :_destroy]

filter :country
filter :assessment_date, as: :select

data_export_sidebar 'ASCORAssessments', display_name: 'ASCOR Assessments'

index do
selectable_column
id_column
column :country, sortable: 'ascor_countries.name'
column :assessment_date
column :publication_date
column :notes

actions
end

show do
attributes_table do
row :id
row :country
row :assessment_date
row :publication_date
row :notes
row :created_at
row :updated_at
end

panel 'Assessment Results' do
table_for resource.results.includes(:indicator).order(:indicator_id) do
column(:indicator)
column(:answer)
column(:source)
column(:year)
end
end

active_admin_comments
end

form do |f|
f.semantic_errors(*f.object.errors.keys)

f.inputs do
f.input :country, as: :select, collection: ASCOR::Country.all.order(:name)
f.input :assessment_date, as: :datepicker
f.input :publication_date, as: :datepicker
f.input :notes
end

f.has_many :results, allow_destroy: true, heading: false do |ff|
ff.inputs 'Assessment Results' do
ff.input :indicator, as: :select, collection: ASCOR::AssessmentIndicator.all.order(:code)
ff.input :answer
ff.input :source
ff.input :year
end
end

f.actions
end

csv do
column :id
column :country do |resource|
resource.country.name
end
column :assessment_date
column :publication_date
ASCOR::AssessmentIndicator.where.not(indicator_type: 'pillar')
.where.not(code: %w[EP.1.a.i EP.1.a.ii]).order(:id).all.each do |indicator|
column "#{indicator.indicator_type} #{indicator.code}", humanize_name: false do |resource|
controller.assessment_results[[resource.id, indicator.id]]&.first&.answer
end
end
ASCOR::AssessmentIndicator.where(indicator_type: %w[indicator metric]).order(:id).all.each do |indicator|
column "source #{indicator.indicator_type} #{indicator.code}", humanize_name: false do |resource|
controller.assessment_results[[resource.id, indicator.id]]&.first&.source
end
end
ASCOR::AssessmentIndicator.where(indicator_type: 'metric').order(:id).all.each do |indicator|
column "year #{indicator.indicator_type} #{indicator.code}", humanize_name: false do |resource|
controller.assessment_results[[resource.id, indicator.id]]&.first&.year
end
end
column :notes
end

controller do
def assessment_results
@assessment_results ||= ASCOR::AssessmentResult.all.group_by { |r| [r.assessment_id, r.indicator_id] }
end
end
end
88 changes: 88 additions & 0 deletions app/admin/ascor/benchmarks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
ActiveAdmin.register ASCOR::Benchmark do
config.sort_order = 'country_id_asc'
includes :country

menu label: 'Benchmarks', parent: 'ASCOR', priority: 2

permit_params :country_id, :publication_date, :emissions_metric, :emissions_boundary, :units, :benchmark_type, :emissions

filter :country, as: :select, collection: -> { ASCOR::Country.all.order(:name) }
filter :emissions_metric, as: :select, collection: -> { ASCOR::EmissionsMetric::VALUES }
filter :emissions_boundary, as: :select, collection: -> { ASCOR::EmissionsBoundary::VALUES }
filter :benchmark_type, as: :select, collection: -> { ASCOR::BenchmarkType::VALUES }

data_export_sidebar 'ASCORBenchmarks', display_name: 'ASCOR Benchmarks'

index do
selectable_column
id_column
column :country, sortable: 'ascor_countries.name'
column :emissions_metric
column :emissions_boundary
column :units
column :benchmark_type

actions
end

show do
attributes_table do
row :id
row :country
row :publication_date
row :emissions_metric
row :emissions_boundary
row :units
row :benchmark_type
row :created_at
row :updated_at
end

panel 'Benchmark emission values' do
render 'admin/cp/emissions_table', emissions: resource.emissions
end

active_admin_comments
end

form html: {'data-controller' => 'check-modified with-emission-table-form'} do |f|
f.semantic_errors(*f.object.errors.keys)

f.inputs do
f.input :country, as: :select, collection: ASCOR::Country.all.order(:name)
f.input :publication_date, as: :datepicker
f.input :emissions_metric, as: :select, collection: ASCOR::EmissionsMetric::VALUES
f.input :emissions_boundary, as: :select, collection: ASCOR::EmissionsBoundary::VALUES
f.input :units
f.input :benchmark_type, as: :select, collection: ASCOR::BenchmarkType::VALUES
f.input :emissions, as: :hidden, input_html: {value: f.object.emissions.to_json, id: 'input_emissions'}
end

div class: 'panel' do
h3 'Benchmark emission values'
div class: 'panel-contents padding-20' do
render 'admin/cp/emissions_table_edit', f: f
end
end

f.actions
end

csv do
year_columns = ASCOR::Benchmark.select(:emissions).flat_map(&:emissions_all_years).uniq.sort

column :id
column(:country) { |b| b.country.name }
column(:publication_date) { |b| b.publication_date.to_s(:year_month) }
column :emissions_metric
column :emissions_boundary
column :units
column :benchmark_type

year_columns.map do |year|
column year do |benchmark|
benchmark.emissions[year]
end
end
end
end
65 changes: 65 additions & 0 deletions app/admin/ascor/countries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
ActiveAdmin.register ASCOR::Country do
config.batch_actions = false
config.sort_order = 'name_asc'

menu label: 'Countries', parent: 'ASCOR', priority: 1

permit_params :name, :iso, :region, :wb_lending_group, :fiscal_monitor_category, :type_of_party

filter :iso_contains, label: 'ISO'
filter :name_contains, label: 'Name'
filter :region, as: :check_boxes, collection: proc { Geography::REGIONS }

data_export_sidebar 'ASCORCountries', display_name: 'ASCOR Countries'

index do
selectable_column
id_column
column :name
column 'Country ISO code', :iso
column :region

actions
end

show do
attributes_table do
row :id
row :name
row 'Country ISO code', &:iso
row :region
row 'World Bank lending group', &:wb_lending_group
row 'International Monetary Fund fiscal monitor category', &:fiscal_monitor_category
row 'Type of Party to the United Nations Framework Convention on Climate Change', &:type_of_party
end

active_admin_comments
end

form do |f|
semantic_errors(*f.object.errors.attribute_names)

f.inputs do
f.input :name
f.input :iso, label: 'Country ISO code'
f.input :region, as: :select, collection: ASCOR::Country::REGIONS
f.input :wb_lending_group, as: :select, collection: ASCOR::Country::LENDING_GROUPS, label: 'World Bank lending group'
f.input :fiscal_monitor_category, as: :select, collection: ASCOR::Country::MONITOR_CATEGORIES,
label: 'International Monetary Fund fiscal monitor category'
f.input :type_of_party, as: :select, collection: ASCOR::Country::TYPE_OF_PARTY,
label: 'Type of Party to the United Nations Framework Convention on Climate Change'
end

f.actions
end

csv do
column :id
column :name
column 'Country ISO code', humanize_name: false, &:iso
column :region
column 'World Bank lending group', humanize_name: false, &:wb_lending_group
column 'International Monetary Fund fiscal monitor category', humanize_name: false, &:fiscal_monitor_category
column 'Type of Party to the United Nations Framework Convention on Climate Change', humanize_name: false, &:type_of_party
end
end
Loading

0 comments on commit 3049143

Please sign in to comment.