Skip to content
Permalink
Browse files
Release 3.10.1
  • Loading branch information
piotaixr committed Oct 29, 2020
1 parent 0618c48 commit 471af9534ba11d6d33c239d1bffdc55a4b13f9ac
Show file tree
Hide file tree
Showing 48 changed files with 131 additions and 92 deletions.
@@ -1 +1 @@
3.10.0
3.10.1
@@ -5,6 +5,10 @@ class ApiPhytosanitaryDataController < Api::V1::BaseController

private

def quote(str)
ActiveRecord::Base.connection.quote(str)
end

def paginated_result(model, order: nil)
if params.key?(:paginate)
per_page = [1000, params.fetch(:per_page, 100).to_i].min
@@ -45,7 +49,7 @@ def permitted_params
def get_removed_element(elements, table_name:)
return [] if elements.empty?

ids = elements.map { |e| "('#{e[:id]}')" }.join(',')
ids = elements.map { |e| "(#{quote(e[:id])})" }.join(',')
Ekylibre::Record::Base.connection.execute("SELECT t.id FROM (values #{ids}) as t(id) WHERE t.id not in (SELECT id from #{table_name})").to_a
end

@@ -16,7 +16,7 @@ def create
def get_removed_element(elements, table_name:)
return [] if elements.empty?

ids = elements.map { |e| "('#{e[:id]}'::integer)" }.join(',')
ids = elements.map { |e| "(#{quote(e[:id])}::integer)" }.join(',')
Ekylibre::Record::Base.connection.execute("SELECT t.id FROM (values #{ids}) as t(id) WHERE t.id not in (SELECT id from #{table_name})").to_a
end
end
@@ -20,18 +20,25 @@ module Backend
module Products
class InterventionsController < Backend::BaseController
def has_harvesting
harvesting_count = ::Interventions::HarvestInProgressQuery
.call(Intervention, permitted_params)
.count
product = Product.find_by(id: params[:id])
intervention_started_at = Time.parse(params[:intervention_started_at])

render json: { has_harvesting: harvesting_count > 0 ? true : false }
if product.present?
harvesting_count = ::Interventions::HarvestInProgressQuery
.call(Intervention, product, intervention_started_at)
.count

render json: { has_harvesting: harvesting_count > 0 ? true : false }
else
render json: { error: { message: "Cannot find product of id='#{params[:id]}'" } }, status: :not_found
end
end

private

def permitted_params
params.permit(:id, :intervention_started_at)
end
def permitted_params
params.permit(:id, :intervention_started_at)
end
end
end
end
@@ -172,7 +172,7 @@ def journal_period_crit(*args)
rescue
(fy ? fy.stopped_on : Time.zone.today)
end
params[:stopped_on] = params[:started_on] if params[:started_on] > params[:stopped_on]
params[:stopped_on] = params[:started_on] if params.key?(:started_on) && params[:started_on] > params[:stopped_on]
list.insert(0, [configuration[:custom].tl, configuration[:custom]])
end

@@ -65,13 +65,23 @@ def self.bounding_box(islets = [])
box = ActiveRecord::Base.connection.execute('SELECT ST_Extent(shape) FROM cap_islets').to_a.first['st_extent']
end

points = ActiveRecord::Base.connection.execute("SELECT ST_XMin(CAST('#{box}' As box2d)), ST_YMin(CAST('#{box}' As box2d)), ST_XMax(CAST('#{box}' As box2d)), ST_YMax(CAST('#{box}' As box2d))")
points.first.values
if box.present?
points = ActiveRecord::Base.connection.execute("SELECT ST_XMin(CAST('#{box}' As box2d)), ST_YMin(CAST('#{box}' As box2d)), ST_XMax(CAST('#{box}' As box2d)), ST_YMax(CAST('#{box}' As box2d))")
points.first.values
else
[]
end
end

# @return [String, nil]
def city_name
name = RegisteredPostalZone.find_by(code: town_number)
return name.city_name if name

if name.present?
name.city_name
else
nil
end
end

alias net_surface_area shape_area
@@ -1,14 +1,17 @@
module Interventions
class HarvestInProgressQuery
def self.call(relation, params)
product = Product.find(params[:id])
intervention_started_at = Time.parse(params[:intervention_started_at])

relation
.joins(:targets)
.where(intervention_parameters: { product_id: product.id })
.where('started_at < ?', intervention_started_at)
.select { |intervention| intervention.procedure.of_category?(:harvesting) }
class << self
# @param [ActiveRecord::Relation<Intervention>]
# @param [Product] product
# @param [Time] intervention_started_at
# @return [Boolean]
def call(relation, product, intervention_started_at)
relation
.joins(:targets)
.where(intervention_parameters: { product_id: product.id })
.where('started_at < ?', intervention_started_at)
.select { |intervention| intervention.procedure.of_category?(:harvesting) }
end
end
end
end
@@ -6,7 +6,7 @@ json.array! elements do |phytosanitary_product|
:natures,
:active_compounds,
:france_maaid,
:mix_category_code,
:mix_category_codes,
:in_field_reentry_delay,
:state,
:started_on,
@@ -43,9 +43,16 @@
- c.cobble(:cap_land_parcels) do
= cobble_list(:cap_land_parcels)

- b = CapIslet.bounding_box(resource.cap_islets)
- h = RegisteredHydroItem.in_bounding_box(b)
- z = RegisteredBuildingZone.in_bounding_box(b)
:ruby
b = CapIslet.bounding_box(resource.cap_islets)
if b.present?
h = RegisteredHydroItem.in_bounding_box(b.join(', '))
z = RegisteredBuildingZone.in_bounding_box(b)
else
h = RegisteredHydroItem.none
z = RegisteredBuildingZone.none
end

- if resource.cap_land_parcels.any?
- j.face :map do
- cache resource.cap_land_parcels + resource.cap_islets + h.pluck(:name) + z.pluck(:centroid) do
@@ -60,16 +67,15 @@
{ name: "#{p.land_parcel_number} - #{p.cap_islet.islet_number}", shape: p.shape, main_crop_code: p.main_crop_code, popup: {header: true, content: popup_content} }
end


neutral_areas = resource.cap_neutral_areas.collect do |p|
next unless p.shape

popup_content = []
popup_content << {label: CapLandParcel.human_attribute_name(:net_surface_area), value: p.human_shape_area}
popup_content << render('popup', plant: p)

{ name: "#{p.number}", shape: p.shape, category_code: p.category, popup: {header: true, content: popup_content} }
end
# neutral_areas = resource.cap_neutral_areas.collect do |p|
# next unless p.shape
#
# popup_content = []
# popup_content << {label: CapLandParcel.human_attribute_name(:net_surface_area), value: p.human_shape_area}
# popup_content << render('popup', plant: p)
#
# { name: "#{p.number}", shape: p.shape, category_code: p.category, popup: {header: true, content: popup_content} }
# end

islets = resource.cap_islets.collect do |p|
next unless p.shape
@@ -80,26 +86,34 @@
{name: p.islet_number, shape: p.shape, popup: {header: true, content: popup_content} }
end

buildings_shape = ActiveRecord::Base.connection.execute(
"SELECT ST_AsGeoJSON(ST_COLLECT(buildings.shape)) AS shape
FROM (#{z.select(:shape).to_sql}) AS buildings;").first["shape"]
if z.count > 0
buildings_shape = ActiveRecord::Base.connection.execute(
"SELECT ST_AsGeoJSON(ST_COLLECT(buildings.shape)) AS shape
FROM (#{z.select(:shape).to_sql}) AS buildings;").first["shape"]
building_zones = [{name: "Building", shape: ::Charta.new_geometry(buildings_shape).buffer(50)}]
else
building_zones = []
end

water_hydro_items_shape = ActiveRecord::Base.connection.execute(
"SELECT ST_AsGeoJSON(ST_COLLECT(hydro.shape)) AS shape
FROM (#{h.select(:shape).to_sql}) AS hydro;").first["shape"]
if h.count > 0
water_hydro_items_shape = ActiveRecord::Base.connection.execute(
"SELECT ST_AsGeoJSON(ST_COLLECT(hydro.shape)) AS shape
FROM (#{h.select(:shape).to_sql}) AS hydro;").first["shape"]

building_zones = [{name: "Building", shape: ::Charta.new_geometry(buildings_shape).buffer(50)}]
water_hydro_items_zones = [{name: "Rivers", shape: ::Charta.new_geometry(water_hydro_items_shape).buffer(50)}]
water_hydro_items_zones = [{name: "Rivers", shape: ::Charta.new_geometry(water_hydro_items_shape).buffer(50)}]
else
water_hydro_items_zones = []
end

= visualization({box: {height: "100%"}}, class: 'map-fullwidth') do |v|
- v.serie :land_parcels, land_parcels
- v.serie :islets, islets
- v.serie :waters, water_hydro_items_zones if water_hydro_items_zones
- v.serie :waters, water_hydro_items_zones
- v.serie :building_zones, building_zones
-# v.serie :neutral_area_category, neutral_areas
-# v.categories :category_code, :neutral_areas
- v.simple :cap_islets, :islets
- v.simple :waters, :waters, fill_color: 'blue' if water_hydro_items_zones
- v.simple :waters, :waters, fill_color: 'blue'
-#- v.simple :water_lakes, :water_lakes, fill_color: 'blue' if water_lakes_shape
- v.simple :building_zones, :building_zones, fill_color: 'yellow', without_ghost_label: true
- v.categories :main_crop_code, :land_parcels
@@ -1,7 +1,7 @@
.nested-fields
= link_to_remove_nested_association(:child, f)
- autocomplete_params = {controller: :product_nature_variant_components}
- autocomplete_params = {controller: '/backend/product_nature_variant_components'}
= f.input :name, autocomplete: autocomplete_params
= f.referenced_association :part_product_nature_variant
= f.referenced_association :part_product_nature_variant, controller: '/backend/product_nature_variants'
- if depth < 10
= f.nested_association(:children, locals: {depth: depth + 1 })
= f.nested_association :children, locals: {depth: depth + 1 }, controller: '/backend/product_nature_variants'
@@ -1,7 +1,7 @@
.nested-fields
= link_to_remove_nested_association(:component, f)
- autocomplete_options = {controller: :product_nature_variant_components}
- autocomplete_options = {controller: '/backend/product_nature_variant_components'}
= f.input :name, autocomplete: autocomplete_options
= f.referenced_association :part_product_nature_variant
= f.nested_association(:children, locals: {depth: 0})
= f.referenced_association :part_product_nature_variant, controller: '/backend/product_nature_variants'
= f.nested_association :children, locals: {depth: 0}, controller: '/backend/product_nature_variants'

@@ -26,9 +26,10 @@ def usage=(value)
def usage_id=(value)
@usage = RegisteredPhytosanitaryUsage.find(value)

self.allowed_harvest_factor = @usage.pre_harvest_delay
self.allowed_entry_factor = @usage.product.in_field_reentry_delay

if @usage.present?
self.allowed_harvest_factor = @usage.pre_harvest_delay
self.allowed_entry_factor = @usage.product.in_field_reentry_delay
end
end

def allowed_harvest_factor=(value)
@@ -52,7 +52,7 @@ <h1>الصفحة التي تبحث عنها غير موجودة</h1>
<p>كنت قد أخطأت في كتابة عنوان أو الصفحة قد تحركت.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>您正在寻找不存在的页面</h1>
<p>您可能输入了错误的地址或网页可能已移动。</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>Die Seite, die Sie suchen ist nicht vorhanden</h1>
<p>Sie können die Adresse falsch eingegeben oder die Seite verschoben haben.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>La page que vous voulez n’existe pas</h1>
<p>Vous pouvez avoir mal saisi l’adresse ou la page peut avoir été déplacée.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>The page you were looking for doesn't exist</h1>
<p>You may have mistyped the address or the page may have moved.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>La pagina che stavi cercando non esiste</h1>
<p>Potreste aver digitato in modo errato l'indirizzo o la pagina potrebbe essere spostato.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>あなたが探していたページは存在しません。</h1>
<p>あなたは、アドレスが間違って入力されているか、ページが移動した可能性があります。</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>A página que está procurando não existe</h1>
<p>Você deve ter digitado alguma valor errado ou a página não existe mais.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>La página que estás buscando no existe</h1>
<p>Es posible que haya escrito mal la dirección o la página puede haber movido.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>ورفض التغيير الذي أراد</h1>
<p>ربما حاولت تغيير شيء ما لم يكن لديك الوصول إليها.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>你想改变被拒绝</h1>
<p>也许你想改变的东西你没有访问。</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>Die Änderung, die Sie wollte, wurde abgelehnt</h1>
<p>Vielleicht versucht, etwas zu ändern, die Sie keinen Zugang zu haben.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>Le changement que vous avez demandé a été rejeté</h1>
<p>Peut-être que vous avez essayé de changer quelque chose auquel vous n’avez pas accès.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>The change you wanted was rejected</h1>
<p>Maybe you tried to change something you didn't have access to.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>
@@ -52,7 +52,7 @@ <h1>Il cambiamento si voleva è stata respinta</h1>
<p>Forse si è tentato di cambiare qualcosa che non ha accesso.</p>
</div>
</div>
<div class='dialog legals'>Ekylibre 3.10.0
<div class='dialog legals'>Ekylibre 3.10.1
</div>
</body>
</html>

0 comments on commit 471af95

Please sign in to comment.