aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhellekin <hellekin@cepheide.org>2020-10-09 10:29:34 +0200
committerhellekin <hellekin@cepheide.org>2020-10-09 10:29:34 +0200
commitd242fb5bbc423876f4c192b5f133619a2d4f0113 (patch)
tree5da6478cd67c49406d8678aa7e99f949419f905c
parentf48ce2f4c934fde3862cdad593eececc7a567d61 (diff)
downloadincommon-map-d242fb5bbc423876f4c192b5f133619a2d4f0113.tar.gz
Scope routes to Agent
Since an Agent is required for all records, we scope the routes and get it present for free ;) This commit also adds resource views.
-rw-r--r--app/views/agents/_agent.html.erb15
-rw-r--r--app/views/application/_user_info.html.erb2
-rw-r--r--app/views/resources/_edit.html.erb6
-rw-r--r--app/views/resources/_form.html.erb61
-rw-r--r--app/views/resources/edit.html.erb17
-rw-r--r--app/views/resources/new.html.erb4
-rw-r--r--app/views/welcome/dashboard.html.erb14
-rw-r--r--config/routes.rb15
8 files changed, 111 insertions, 23 deletions
diff --git a/app/views/agents/_agent.html.erb b/app/views/agents/_agent.html.erb
new file mode 100644
index 0000000..5a74df1
--- /dev/null
+++ b/app/views/agents/_agent.html.erb
@@ -0,0 +1,15 @@
+<article class="agent" id="agent-<%= agent.to_param %>">
+ <header>
+ <h1><%= link_to agent.name, agent_url(agent) %></h1>
+ <h2><%= link_to agent_url(agent) %></h1>
+ </head>
+ <section id="stats">
+ <h3>Statistiques</h3>
+ <ul>
+ <li><%= link_to pluralize(agent.resources.count, 'Resource'), agent_resources_url(agent) %></li>
+ <li><%= pluralize(agent.taxonomies.count, 'Taxonomy') %> with
+ <%= pluralize(agent.categories.count, 'Category') %> and
+ <%= pluralize(agent.sections.count, 'Section') %>.</li>
+ </ul>
+ </section>
+</article>
diff --git a/app/views/application/_user_info.html.erb b/app/views/application/_user_info.html.erb
index 8e90501..3220c89 100644
--- a/app/views/application/_user_info.html.erb
+++ b/app/views/application/_user_info.html.erb
@@ -6,7 +6,7 @@
<%= tag.li(link_to(new_agent_switch_url, method: :get, remote: true, title: "Changer d'Agent") do
"Agent: %s" % current_agent
end, id: 'current_agent_name') %>
- <%= tag.li link_to("Ajouter un point", new_resource_url) %>
+ <%= tag.li link_to("Ajouter un point", new_agent_resource_url(agent_id: current_agent)) %>
<%= tag.li link_to("Mon compte", account_url(current_user.id)) %>
<%= tag.li link_to("Terminer la session", logout_url) %>
</ul>
diff --git a/app/views/resources/_edit.html.erb b/app/views/resources/_edit.html.erb
new file mode 100644
index 0000000..fdb2921
--- /dev/null
+++ b/app/views/resources/_edit.html.erb
@@ -0,0 +1,6 @@
+<h3>Edit <%= resource.presence&.name || 'new resource' %></h3>
+<h2>Context: <%= current_agent %></h2>
+
+<%= form_with model: [current_agent,@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
new file mode 100644
index 0000000..fe5f532
--- /dev/null
+++ b/app/views/resources/_form.html.erb
@@ -0,0 +1,61 @@
+<fieldset>
+ <%= tag.legend "Propriétés de la ressource" %>
+
+ <dl>
+ <dt><%= f.label :name %></dt>
+ <dd><%= f.text_field :name, maxlength: 64, placeholder: 'La ferme des animaux', value: resource.name %></dd>
+
+ <dt><%= f.label :summary %></dt>
+ <dd><%= f.text_field :summary, maxlength: 136, placeholder: 'Une ferme locale', value: resource.name %></dd>
+
+ <dt><%= f.label :description %></dt>
+ <dd><%= f.text_area :description, cols: 72, rows: 10, placeholder: '## Un choix pertinent
+
+La description _peut_ comporter du [Markdown].
+
+[Markdown]: https://www.markdownguide.org/getting-started/' %></dd>
+
+ <dt><%= f.label :email %></dt>
+ <dd><%= f.email_field :email, placeholder: 'bonjour@la-ferme-des-animaux.example' %></dd>
+
+ <dt><%= f.label :website %></dt>
+ <dd><%= f.url_field :website, placeholder: 'https://la-ferme-des-animaux.example' %></dd>
+
+ <dt><%= f.label :phone_number %></dt>
+ <dd><%= f.telephone_field :phone_number, placeholder: '+32 489 000 0000' %></dd>
+ </dl>
+</fieldset>
+
+<fieldset>
+ <%= tag.legend "Classification" %>
+ <%# TODO Add a taxonomy selector %>
+ <%= section_select(current_agent.taxonomies.first) %>
+</fieldset>
+
+<fieldset>
+ <%= tag.legend "Coordonées géographiques" %>
+ <%# TODO Add a graphical geo selector %>
+
+ <dl>
+ <dt><%= f.label :address %></dt>
+ <dd><%= f.text_field :address, value: resource.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>
+
+ <dt><%= f.label :city %></dt>
+ <dd><%= f.text_field :city, value: resource.city, placeholder: 'Bruxelles' %></dd>
+ </dl>
+
+ <dl>
+ <dt><%= f.label :longitude %></dt>
+ <dd><%= f.text_field :longitude, value: resource.longitude, placeholder: '0.56789012' %></dd>
+
+ <dt><%= f.label :latitude %></dt>
+ <dd><%= f.text_field :latitude, value: resource.latitude, placeholder: '50.12345678' %></dd>
+ </dl>
+</fieldset>
+
+<%= f.hidden_field :agent_id, value: current_agent.id %>
+
+<p><%= f.submit 'Save' %></p>
diff --git a/app/views/resources/edit.html.erb b/app/views/resources/edit.html.erb
index b051bae..80d8206 100644
--- a/app/views/resources/edit.html.erb
+++ b/app/views/resources/edit.html.erb
@@ -1,17 +1,2 @@
-<%= form_with model: @resource, local: true do |f| %>
- <%= tag.legend " " %>
- <%= f.label :name %>
- <%= f.text_field :name, value: @resource.name %>
-
- <%= tag.legend " " %>
- <%= f.label :categories %>
- <%= f.text_field :categories, value: @resource.categories %>
+<%= render partial: 'edit', locals: { resource: @resource } %>
- <%= tag.legend "Coordonées géographiques" %>
- <%= f.label :longitude %>
- <%= f.text_field :longitude, value: @resource.lon %>
- <%= f.label :latitude %>
- <%= f.text_field :latitude, value: @resource.lat %>
-
- <%= f.submit 'Save' %>
-<% end %>
diff --git a/app/views/resources/new.html.erb b/app/views/resources/new.html.erb
index c29e88a..80d8206 100644
--- a/app/views/resources/new.html.erb
+++ b/app/views/resources/new.html.erb
@@ -1,2 +1,2 @@
-<h1>Resources#new</h1>
-<p>Find me in app/views/resources/new.html.erb</p>
+<%= render partial: 'edit', locals: { resource: @resource } %>
+
diff --git a/app/views/welcome/dashboard.html.erb b/app/views/welcome/dashboard.html.erb
index 81264e2..8880434 100644
--- a/app/views/welcome/dashboard.html.erb
+++ b/app/views/welcome/dashboard.html.erb
@@ -1,5 +1,15 @@
<h1>Welcome <%= h current_user.name %>!</h1>
-<p>Current Agent: <%= current_user&.agencies&.first&.agent&.name %></p>
+<p>Current Agent: <%= current_agent&.name %></p>
-<p>Cool, what can we do now?</p>
+<section id="global_stats">
+ <h2>Global Count</h2>
+ <p><%#= @stats[:counts].map { |k,v| pluralize(k.to_s.singularize, v) }.to_sentence %></p>
+ <p><%= p @stats[:count] %>
+</section>
+
+<section id="current_agent_stats">
+ <h2>Current Agent: <%= current_agent %></h2>
+ <p><%#= @stats[:current_agent][:counts].map { |k,v| pluralize(k.to_s.singularize, v) }.to_sentence %></p>
+ <%= render partial: current_agent %>
+</section>
diff --git a/config/routes.rb b/config/routes.rb
index d22ee2e..fdecb3d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,8 +3,19 @@ Rails.application.routes.draw do
root to: 'welcome#index'
- # Resource routes
- resources :resources
+ # Agent routes
+ resources :agents do
+ shallow do
+ # Classification routes
+ resources :taxonomies do
+ resources :categories do
+ resources :sections
+ end
+ end
+ # Resource routes
+ resources :resources
+ end
+ end
# User routes
get '/my/account', to: 'users#show', as: 'account'