Skip to content

Commit

Permalink
Merge pull request #470 from wri/feature/protected-areas
Browse files Browse the repository at this point in the history
Feature/protected areas
  • Loading branch information
tsubik authored Dec 8, 2023
2 parents 763b65a + 5654d03 commit 009a41d
Show file tree
Hide file tree
Showing 32 changed files with 886 additions and 544 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ gem "interactor", "~> 3.0"
gem "sentry-rails"
gem "sentry-ruby"

# Utilities
gem "http"

group :development, :test do
gem "debug", platforms: %i[mri mingw x64_mingw]
gem "factory_bot_rails"
Expand Down
56 changes: 38 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ GEM
ast (2.4.2)
attr_extras (7.1.0)
bcrypt (3.1.20)
bigdecimal (3.1.4)
bindex (0.8.1)
bootsnap (1.17.0)
msgpack (~> 1.2)
brakeman (6.0.1)
brakeman (6.1.0)
builder (3.2.4)
bullet (7.1.4)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -209,11 +210,11 @@ GEM
carrierwave (>= 2.2.1)
marcel (~> 1.0.0)
mime-types (~> 3.0)
chartkick (5.0.4)
chartkick (5.0.5)
choice (0.2.0)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
countries (5.7.0)
countries (5.7.1)
unaccent (~> 0.3)
crack (0.4.5)
rexml
Expand All @@ -239,6 +240,7 @@ GEM
warden (~> 1.2.3)
diff-lcs (1.5.0)
docile (1.4.0)
domain_name (0.6.20231109)
dotenv (2.8.1)
dotenv-rails (2.8.1)
dotenv (= 2.8.1)
Expand All @@ -262,6 +264,9 @@ GEM
webrick (~> 1.7)
websocket-driver (>= 0.6, < 0.8)
ffi (1.16.3)
ffi-compiler (1.0.1)
ffi (>= 1.0.0)
rake
formtastic (4.0.0)
actionpack (>= 5.2.0)
formtastic_i18n (0.7.0)
Expand All @@ -278,6 +283,14 @@ GEM
activesupport (>= 5.2)
hashdiff (1.0.1)
htmlentities (4.3.4)
http (5.1.1)
addressable (~> 2.8)
http-cookie (~> 1.0)
http-form_data (~> 2.2)
llhttp-ffi (~> 0.4.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
http-form_data (2.3.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
i18n_generators (2.2.2)
Expand All @@ -293,14 +306,14 @@ GEM
responders (>= 2)
interactor (3.1.2)
io-console (0.6.0)
irb (1.9.1)
irb (1.10.1)
rdoc
reline (>= 0.3.8)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (2.7.0)
json (2.7.1)
jsonapi-resources (0.9.12)
activerecord (>= 4.1)
concurrent-ruby
Expand Down Expand Up @@ -329,6 +342,9 @@ GEM
railties (>= 5.2)
rexml
lint_roller (1.1.0)
llhttp-ffi (0.4.0)
ffi-compiler (~> 1.0)
rake (~> 13.0)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
Expand All @@ -342,7 +358,7 @@ GEM
method_source (1.0.0)
mime-types (3.5.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.1003)
mime-types-data (3.2023.1205)
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
Expand All @@ -368,7 +384,8 @@ GEM
racc (~> 1.4)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
oj (3.16.1)
oj (3.16.2)
bigdecimal (~> 3.1)
oj_mimic_json (1.0.1)
optimist (3.1.0)
orm_adapter (0.5.0)
Expand All @@ -395,6 +412,8 @@ GEM
rack (>= 2.0.0)
rack-mini-profiler (2.3.4)
rack (>= 1.2.0)
rack-session (1.0.2)
rack (< 3)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.8)
Expand Down Expand Up @@ -436,29 +455,29 @@ GEM
activerecord (>= 6.1.5)
activesupport (>= 6.1.5)
i18n
rdoc (6.6.0)
rdoc (6.6.1)
psych (>= 4.0.0)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-actionpack (5.3.0)
redis-actionpack (5.4.0)
actionpack (>= 5, < 8)
redis-rack (>= 2.1.0, < 3)
redis-rack (>= 2.1.0, < 4)
redis-store (>= 1.1.0, < 2)
redis-activesupport (5.3.0)
activesupport (>= 3, < 8)
redis-store (>= 1.3, < 2)
redis-client (0.18.0)
redis-client (0.19.0)
connection_pool
redis-rack (2.1.4)
rack (>= 2.0.8, < 3)
redis-rack (3.0.0)
rack-session (>= 0.2.0)
redis-store (>= 1.2, < 2)
redis-rails (5.0.2)
redis-actionpack (>= 5.0, < 6)
redis-activesupport (>= 5.0, < 6)
redis-store (>= 1.2, < 2)
redis-store (1.10.0)
redis (>= 4, < 6)
regexp_parser (2.8.2)
regexp_parser (2.8.3)
reline (0.4.1)
io-console (~> 0.5)
request_store (1.5.1)
Expand Down Expand Up @@ -551,10 +570,10 @@ GEM
sendgrid-ruby (~> 6.4)
sendgrid-ruby (6.7.0)
ruby_http_client (~> 3.4)
sentry-rails (5.14.0)
sentry-rails (5.15.0)
railties (>= 5.0)
sentry-ruby (~> 5.14.0)
sentry-ruby (5.14.0)
sentry-ruby (~> 5.15.0)
sentry-ruby (5.15.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
shoulda-matchers (4.0.1)
activesupport (>= 4.2.0)
Expand All @@ -580,7 +599,7 @@ GEM
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
ssrf_filter (1.1.2)
standard (1.32.0)
standard (1.32.1)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
rubocop (~> 1.57.2)
Expand Down Expand Up @@ -677,6 +696,7 @@ DEPENDENCIES
globalize
globalize-versioning!
groupdate
http
i18n_generators
interactor (~> 3.0)
jsonapi-resources (= 0.9.12)
Expand Down
1 change: 1 addition & 0 deletions app/admin/custom_admin_header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def build(namespace, menu) # rubocop:disable Metrics/AbcSize
text_node content_tag "a", t("active_admin.menu.private_sector.settings.settings"), class: "-with-children"
ul do
li { link_to t("active_admin.menu.private_sector.settings.countries"), admin_countries_path }
li { link_to t("active_admin.menu.private_sector.settings.protected_areas"), admin_protected_areas_path }
li { link_to t("active_admin.menu.private_sector.settings.fmus"), admin_fmus_path }
li { link_to t("active_admin.menu.private_sector.settings.fmu_allocations"), admin_fmu_operators_path }
end
Expand Down
90 changes: 46 additions & 44 deletions app/admin/fmu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@
config.order_clause

controller do
def preview
file = params["file"]
max_file_size = 200_000
response = if file.blank? || file.size > max_file_size
{errors: "File must exist and be smaller than #{max_file_size / 1000} KB"}
else
Fmu.file_upload(file)
end
respond_to do |format|
format.json { render json: response }
end
end

def scoped_collection
end_of_association_chain.with_translations(I18n.locale).includes(:country, :operator)
end
Expand Down Expand Up @@ -88,8 +75,13 @@ def scoped_collection
row :certification_fsc_cw
row :certification_tlv
row :certification_ls
if resource.geojson && resource.centroid.present?
row :map do |r|
render partial: "map", locals: {center: [r.centroid.x, r.centroid.y], center_marker: false, geojson: r.geojson, bbox: r.bbox}
end
end
row(:geojson) { |fmu| fmu.geojson.to_json }
row(:properties) { |fmu| fmu.geojson&.dig("properties") }
row(:properties) { |fmu| fmu.geojson&.dig("properties")&.to_json }
row :created_at
row :updated_at
row :deleted_at
Expand All @@ -114,28 +106,47 @@ def scoped_collection

form do |f|
f.semantic_errors(*f.object.errors.attribute_names)
f.inputs I18n.t("active_admin.shared.fmu_details") do
f.input :country, input_html: {disabled: object.persisted?}, required: true
f.input :esri_shapefiles_zip, as: :file, input_html: {accept: ".zip"}
render partial: "zip_hint"
f.input :forest_type, as: :select,
collection: ForestType::TYPES.map { |key, v| [v[:label], key] },
input_html: {disabled: object.persisted?}
f.input :certification_fsc
f.input :certification_pefc
f.input :certification_olb
f.input :certification_pafc
f.input :certification_fsc_cw
f.input :certification_tlv
f.input :certification_ls
end
columns class: "d-flex" do
column max_width: "500px" do
f.inputs I18n.t("active_admin.shared.fmu_details") do
f.input :country, input_html: {disabled: object.persisted?}, required: true
f.input :forest_type, as: :select,
collection: ForestType::TYPES.map { |key, v| [v[:label], key] },
input_html: {disabled: object.persisted?}
f.input :certification_fsc
f.input :certification_pefc
f.input :certification_olb
f.input :certification_pafc
f.input :certification_fsc_cw
f.input :certification_tlv
f.input :certification_ls
end

f.inputs I18n.t("activerecord.models.operator"), for: [:fmu_operator, f.object.fmu_operator || FmuOperator.new] do |fo|
fo.input :operator_id, label: I18n.t("activerecord.attributes.fmu/translation.name"), as: :select,
collection: Operator.active.map { |o| [o.name, o.id] },
input_html: {disabled: object.persisted?}, required: false
fo.input :start_date, input_html: {disabled: object.persisted?}, required: false
fo.input :end_date, input_html: {disabled: object.persisted?}
end
end

f.inputs I18n.t("activerecord.models.operator"), for: [:fmu_operator, f.object.fmu_operator || FmuOperator.new] do |fo|
fo.input :operator_id, label: I18n.t("activerecord.attributes.fmu/translation.name"), as: :select,
collection: Operator.active.map { |o| [o.name, o.id] },
input_html: {disabled: object.persisted?}, required: false
fo.input :start_date, input_html: {disabled: object.persisted?}, required: false
fo.input :end_date, input_html: {disabled: object.persisted?}
column class: "flex-1" do
f.inputs Fmu.human_attribute_name(:geometry) do
f.input :esri_shapefiles_zip, as: :esri_shapefile_zip

render partial: "upload_geometry_map",
locals: {
file_input_id: "fmu_esri_shapefiles_zip",
geojson: f.resource.geojson,
bbox: f.resource.bbox,
present: f.resource.geojson.present?,
host: Rails.env.development? ? request.base_url : request.base_url + "/api",
show_fmus: true,
api_key: ENV["API_KEY"]
}
end
end
end

f.inputs I18n.t("active_admin.shared.translated_fields") do
Expand All @@ -144,14 +155,5 @@ def scoped_collection
end
end
f.actions

render partial: "form",
locals: {
geojson: f.resource.geojson,
bbox: f.resource.bbox,
present: f.resource.geojson.present?,
host: Rails.env.development? ? request.base_url : request.base_url + "/api",
api_key: ENV["API_KEY"]
}
end
end
71 changes: 71 additions & 0 deletions app/admin/protected_area.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# frozen_string_literal: true

ActiveAdmin.register ProtectedArea do
extend BackRedirectable

menu false

permit_params [:name, :country_id, :esri_shapefiles_zip, :geojson, :wdpa_pid]

filter :wdpa_pid
filter :name
filter :country,
as: :select,
collection: -> { Country.active.with_translations(I18n.locale) }

index do
column :id
column :wdpa_pid
column :country
column :name

actions
end

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

columns class: "d-flex" do
column max_width: "500px" do
f.inputs I18n.t("active_admin.details", model: I18n.t("activerecord.models.protected_area")) do
f.input :wdpa_pid
f.input :country
f.input :name
end
end

column class: "flex-1" do
f.inputs ProtectedArea.human_attribute_name(:geometry) do
f.input :esri_shapefiles_zip, as: :esri_shapefile_zip
render partial: "upload_geometry_map",
locals: {
file_input_id: "protected_area_esri_shapefiles_zip",
geojson: f.resource.geojson,
bbox: f.resource.bbox,
present: f.resource.geojson.present?,
host: Rails.env.development? ? request.base_url : request.base_url + "/api",
show_fmus: false,
api_key: ENV["API_KEY"]
}
end
end
end

f.actions
end

show do
attributes_table do
row :wdpa_pid
row :name
row :country
row :map do |r|
render partial: "map", locals: {center: [r.centroid.x, r.centroid.y], center_marker: false, geojson: r.geojson, bbox: r.bbox}
end
row :geojson do |r|
r.geojson.to_json
end
end
active_admin_comments
end
end
Loading

0 comments on commit 009a41d

Please sign in to comment.