aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/assets/stylesheets/application/_flash.scss22
-rw-r--r--app/controllers/resources_controller.rb50
-rw-r--r--app/views/application/_flash.html.erb3
-rw-r--r--app/views/layouts/application.html.erb1
-rw-r--r--app/views/resources/edit.html.erb15
5 files changed, 88 insertions, 3 deletions
diff --git a/app/assets/stylesheets/application/_flash.scss b/app/assets/stylesheets/application/_flash.scss
new file mode 100644
index 0000000..37d27b2
--- /dev/null
+++ b/app/assets/stylesheets/application/_flash.scss
@@ -0,0 +1,22 @@
+/*
+ FLASH
+*/
+
+#flash {
+ position: absolute;
+ bottom: 2rem;
+ margin: 0 auto;
+ width: 50%;
+ min-width: 24rem;
+ max-width: 64rem;
+ max-height: 10rem;
+ overflow: scroll;
+ padding: 1rem;
+
+ &.alert {
+ background-color: var(--danger-medium);
+ }
+ &.notice {
+ background-color: var(--highlight-low);
+ }
+}
diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb
index 75fcedf..fdb69cc 100644
--- a/app/controllers/resources_controller.rb
+++ b/app/controllers/resources_controller.rb
@@ -35,6 +35,52 @@ class ResourcesController < ApplicationController
# 1. Compare records for changes
# 2. Validate each change
# 3. Moderate queue or save
+
+ updated_properties = @resource.feature['properties']
+ updated_geometry = @resource.feature['geometry']
+
+ updated = false
+
+ flash.now[:notice] = updated_geometry.inspect
+
+ if @resource.uuid.present? && params[:resource][:uuid].present? && params[:resource][:uuid] != @resource.uuid
+ flash.now[:error] = "UUID cannot be changed."
+ render :edit, status: :unprocessable_entity and return
+ end
+
+ params[:resource].each do |prop|
+ next if %w(longitude latitude).include?(prop.first.to_s)
+ if prop.last.present? && prop.last != @resource.send("#{prop.first.to_s}")
+ updated = true
+ updated_properties[prop.first.to_s] = prop.last
+ end
+ end
+
+ lon, lat = updated_geometry['coordinates']
+ flash.now.notice = "lon #{lon} => #{params[:resource][:longitude]}, lat #{lat} =>#{params[:resource][:latitude]}"
+ if params[:resource][:longitude].present? && params[:resource][:longitude] != lon
+ updated = true
+ updated_geometry['coordinates'][0] = params[:resource][:longitude]
+ Rails.logger.info "UPDATED LON TO #{params[:resource][:longitude]} /// #{updated_geometry.inspect}"
+ end
+ if params[:resource][:latitude].present? && params[:resource][:latitude] != lat
+ updated = true
+ updated_geometry['coordinates'][1] = params[:resource][:latitude]
+ end
+
+ if updated == true
+ Rails.logger.info "Got a Resource update..."
+ @resource.feature['properties'] = updated_properties
+ @resource.feature['geometry'] = updated_geometry
+ if @resource.save
+ flash.notice = "Good! It worked! #{@resource.feature['geometry']}"
+ redirect_to resource_url(@resource) and return
+ else
+ flash.now[:notice] = @resource.errors.inspect
+ end
+ end
+ flash.now[:alert] = "Update failed!"
+ render :edit
end
# GET /resources/:id/delete
@@ -49,6 +95,10 @@ class ResourcesController < ApplicationController
private
+ def resource_params
+ params.require(:resource).permit(:uuid, :name, :summary, :description, :email, :city, :postal_code, :phone_number, :website, :entry_number, :categories, :latitude, :longitude)
+ end
+
def set_resource
@resource = Resource.find_by(uuid: params[:id]) || Resource.new
end
diff --git a/app/views/application/_flash.html.erb b/app/views/application/_flash.html.erb
new file mode 100644
index 0000000..0b5cc5f
--- /dev/null
+++ b/app/views/application/_flash.html.erb
@@ -0,0 +1,3 @@
+<div id="flashes"><% flash.each do |type, msg| %>
+ <span class="<%= type %>"><%= msg %></span>
+<% end %></div>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 4aae3ea..38dcf46 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -26,5 +26,6 @@
<footer>
<%= yield :footer %>
</footer>
+ <%= render partial: 'flash' %>
</body>
</html>
diff --git a/app/views/resources/edit.html.erb b/app/views/resources/edit.html.erb
index 7e9799f..fa61a0a 100644
--- a/app/views/resources/edit.html.erb
+++ b/app/views/resources/edit.html.erb
@@ -1,6 +1,15 @@
-<%= form_with model: @resource do |f| %>
- <%= f.label :name, "Name of this Resource" %>
- <%= f.text_field :name %>
+<%= form_with model: @resource, local: true do |f| %>
+ <%= f.label :name %>
+ <%= f.text_field :name, value: @resource.name %>
+
+
+ <%= tag.legend "Geographic Position" %>
+ <%= f.label :longitude %>
+ <%= f.text_field :longitude, value: @resource.lon %>
+ <%= f.label :latitude %>
+ <%= f.text_field :latitude, value: @resource.lat %>
+
+
<%= f.submit 'Save' %>
<% end %>