aboutsummaryrefslogtreecommitdiff
path: root/app/views/resources
diff options
context:
space:
mode:
authorIN COMMON Collective <collective@incommon.cc>2021-04-08 16:34:15 +0200
committerIN COMMON Collective <collective@incommon.cc>2021-04-08 16:34:15 +0200
commitd14700c51d692335f001a93c2f6b13b135783206 (patch)
tree1204bc1ae744098eba6604a961765187984a90d8 /app/views/resources
parentc738e96b2b99bfd92b70d4cec26d6874a7f609e4 (diff)
downloadincommon-map-d14700c51d692335f001a93c2f6b13b135783206.tar.gz
[FIX] Use form model to create/edit resources (fixes #4, fixes #5, refs #3)v0.1.10
Since we must associate other models (e.g., classifications) to a Resource, we use a composite model to save all changes inside a database transaction. This approach makes it simpler to handle resources and their associations. Work remains to fix the geolocation and reverse geolocation to ensure these are in sync.
Diffstat (limited to 'app/views/resources')
-rw-r--r--app/views/resources/_edit.html.erb4
-rw-r--r--app/views/resources/_form.html.erb37
-rw-r--r--app/views/resources/new.html.erb4
3 files changed, 30 insertions, 15 deletions
diff --git a/app/views/resources/_edit.html.erb b/app/views/resources/_edit.html.erb
index 55c59f6..f22aee3 100644
--- a/app/views/resources/_edit.html.erb
+++ b/app/views/resources/_edit.html.erb
@@ -1,6 +1,6 @@
-<h3>Edit <%= @resource.presence.feature['properties']['name'] || 'new resource' %></h3>
+<h3>Edit <%= @resource.presence.name || 'new resource' %></h3>
<h2>Context: <%= current_agent %></h2>
-<%= form_with model: [current_agent,@resource], url: controller.action_name == 'new' ? agent_resources_path(agent: current_agent) : resource_path(@resource) do |f| %>
+<%= form_with model: @resource, url: @resource.presence.new_record? ? agent_resources_path(current_agent) : resource_path(@resource.resource) do |f| %>
<%= render partial: 'form', locals: { resource: resource, f: f } %>
<% end %>
diff --git a/app/views/resources/_form.html.erb b/app/views/resources/_form.html.erb
index 89745bd..648834d 100644
--- a/app/views/resources/_form.html.erb
+++ b/app/views/resources/_form.html.erb
@@ -1,12 +1,24 @@
-<fieldset>
+<% if resource.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(resource.errors.count, "error") %> prohibited this resource from being saved:</h2>
+
+ <ul>
+ <% resource.errors.each do |error| %>
+ <li><%= error.full_message %></li>
+ <% end %>
+ </ul>
+ </div>
+<% end %>
+
+ <fieldset>
<%= tag.legend "Propriétés de la ressource" %>
- <dl>
+ <dl class="field">
<dt><%= f.label :name %></dt>
- <dd><%= f.text_field :name, maxlength: 64, placeholder: 'La ferme des animaux', value: resource.name %></dd>
+ <dd><%= f.text_field :name, maxlength: 64, placeholder: 'La ferme des animaux' %></dd>
<dt><%= f.label :summary %></dt>
- <dd><%= f.text_field :summary, maxlength: 136, placeholder: 'Une ferme locale', value: resource.name %></dd>
+ <dd><%= f.text_field :summary, maxlength: 136, placeholder: 'Une ferme locale' %></dd>
<dt><%= f.label :description %></dt>
<dd><%= f.text_area :description, cols: 72, rows: 10, placeholder: '## Un choix pertinent
@@ -29,33 +41,34 @@ La description _peut_ comporter du [Markdown].
<fieldset>
<%= tag.legend "Classification" %>
<%# TODO Add a taxonomy selector %>
- <%= section_select(current_agent.taxonomies&.first || Taxonomy.first) %>
+ <%= section_select(current_agent.taxonomies&.first || Taxonomy.first, resource.section_ids, name: 'resource_form[section_ids]') %>
</fieldset>
<fieldset>
<%= tag.legend "Coordonées géographiques" %>
<%# TODO Add a graphical geo selector %>
- <dl>
+ <dl class="field">
<dt><%= f.label :address %></dt>
- <dd><%= f.text_field :address, value: resource.address, placeholder: 'Rue aux herbes, 123' %></dd>
+ <dd><%= f.text_field :address, placeholder: 'Rue aux herbes, 123' %></dd>
<dt><%= f.label :postal_code %></dt>
- <dd><%= f.text_field :postal_code, value: resource.postal_code, placeholder: '1000' %></dd>
+ <dd><%= f.text_field :postal_code, placeholder: '1000' %></dd>
<dt><%= f.label :city %></dt>
- <dd><%= f.text_field :city, value: resource.city, placeholder: 'Bruxelles' %></dd>
+ <dd><%= f.text_field :city, placeholder: 'Bruxelles' %></dd>
</dl>
- <dl>
+ <dl class="field">
<dt><%= f.label :longitude %></dt>
- <dd><%= f.text_field :longitude, value: resource.longitude, placeholder: '0.56789012' %></dd>
+ <dd><%= f.text_field :longitude, placeholder: '0.56789012', pattern: '[\d]+.[\d]+' %></dd>
<dt><%= f.label :latitude %></dt>
- <dd><%= f.text_field :latitude, value: resource.latitude, placeholder: '50.12345678' %></dd>
+ <dd><%= f.text_field :latitude, placeholder: '50.12345678', pattern: '[\d]+.[\d]+' %></dd>
</dl>
</fieldset>
<%= f.hidden_field :agent_id, value: current_agent.id %>
+<%= f.hidden_field :source, value: current_agent.name %>
<p><%= f.submit 'Save' %></p>
diff --git a/app/views/resources/new.html.erb b/app/views/resources/new.html.erb
index 80d8206..e8347b4 100644
--- a/app/views/resources/new.html.erb
+++ b/app/views/resources/new.html.erb
@@ -1,2 +1,4 @@
-<%= render partial: 'edit', locals: { resource: @resource } %>
+<%= render 'edit', resource: @resource %>
+
+<#%= render partial: 'edit', locals: { resource: @resource } %>