aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-10-06 19:29:04 +0200
committerhellekin <hellekin@cepheide.org>2020-10-06 19:29:04 +0200
commit1564af069472e32ed322bf9acedc9c487bce1a15 (patch)
treed3bd0061dd08b4d236b02f1cf978466873ecc83d
parentb5052d4beeb7fd0bc14db21336588bb0483f7d09 (diff)
downloadincommon-map-1564af069472e32ed322bf9acedc9c487bce1a15.tar.gz
First pass at listing Resources
This implements resource listing and pagination. See /resources
-rw-r--r--app/controllers/resources_controller.rb42
-rw-r--r--app/models/resource.rb19
-rw-r--r--app/views/resources/_resource.html.erb10
-rw-r--r--app/views/resources/index.html.erb8
4 files changed, 77 insertions, 2 deletions
diff --git a/app/controllers/resources_controller.rb b/app/controllers/resources_controller.rb
index 1253b5d..d7fd822 100644
--- a/app/controllers/resources_controller.rb
+++ b/app/controllers/resources_controller.rb
@@ -1,13 +1,55 @@
class ResourcesController < ApplicationController
+ before_action :set_resource, only: [:new, :edit, :update, :delete, :destroy]
+
+ # GET /resources
def index
+ @resources = Resource.order(:uuid).page params[:page]
end
+ # GET /resources/new
def new
end
+ # POST /resources
+ def create
+ # Check list:
+ # 1. UUID is not set, or not known
+ # 2. Agent is correct
+ # 3. Name, Description, Phone, Email, etc. do not yield results
+ # 4. Background job to validate fields and save
+ # 5. Or Background job to list similar items
+ # 6. Return to user with new record or list of mergeable ones
+ end
+
+ # GET /resources/:id
+ def show
+ end
+
+ # GET /resources/:id/edit
def edit
end
+ # PATCH /resources/:id
+ def update
+ # Check list:
+ # 1. Compare records for changes
+ # 2. Validate each change
+ # 3. Moderate queue or save
+ end
+
+ # GET /resources/:id/delete
def delete
end
+
+ # DELETE /resources/:id
+ def destroy
+ # Check list
+ # 1. User belongs to Agent and is :maintainer?
+ end
+
+ private
+
+ def set_resource
+ @resource = Resource.find_by(uuid: params[:id]) || Resource.new
+ end
end
diff --git a/app/models/resource.rb b/app/models/resource.rb
index ba3dd1f..e67d164 100644
--- a/app/models/resource.rb
+++ b/app/models/resource.rb
@@ -3,4 +3,23 @@ class Resource < ApplicationRecord
include UUIDParameter
belongs_to :agent
+
+ # Figure out the requested property name
+ def method_missing(name, *args, &block)
+ Rails.logger.info("method_missing: #{name} // #{feature['properties'][name.to_s]}")
+ if feature['properties'].key?(name.to_s)
+ feature['properties'][name.to_s]
+ else
+ case name.to_s
+ when 'lon', 'longitude'
+ feature['geometry']['coordinates'].first
+ when 'lat', 'latitude'
+ feature['geometry']['coordinates'].last
+ when 'geo_type'
+ feature['geometry']['type']
+ else
+ super
+ end
+ end
+ end
end
diff --git a/app/views/resources/_resource.html.erb b/app/views/resources/_resource.html.erb
new file mode 100644
index 0000000..39997ef
--- /dev/null
+++ b/app/views/resources/_resource.html.erb
@@ -0,0 +1,10 @@
+<section id="resource-<%= resource.uuid %>">
+ <header>
+ <h2><%= h resource.name %></h2>
+ <time datetime="<%= h resource.created_at %>" class="created_at">
+ <time datetime="<%= h resource.updated_at %>" class="updated_at">
+ <p class="identifier"><%= resource_url(resource) %></p>
+ </header>
+ <div><%= h resource.description %></div>
+ <code><%= h resource.feature.as_json %></code>
+</section>
diff --git a/app/views/resources/index.html.erb b/app/views/resources/index.html.erb
index 320849a..473bcbb 100644
--- a/app/views/resources/index.html.erb
+++ b/app/views/resources/index.html.erb
@@ -1,2 +1,6 @@
-<h1>Resources#index</h1>
-<p>Find me in app/views/resources/index.html.erb</p>
+<h1>Listing Resources</h1>
+
+<%= paginate @resources %>
+
+<%= render partial: 'resource', collection: @resources %>
+