From d242fb5bbc423876f4c192b5f133619a2d4f0113 Mon Sep 17 00:00:00 2001 From: hellekin Date: Fri, 9 Oct 2020 10:29:34 +0200 Subject: 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. --- app/views/agents/_agent.html.erb | 15 ++++++++ app/views/application/_user_info.html.erb | 2 +- app/views/resources/_edit.html.erb | 6 +++ app/views/resources/_form.html.erb | 61 +++++++++++++++++++++++++++++++ app/views/resources/edit.html.erb | 17 +-------- app/views/resources/new.html.erb | 4 +- app/views/welcome/dashboard.html.erb | 14 ++++++- config/routes.rb | 15 +++++++- 8 files changed, 111 insertions(+), 23 deletions(-) create mode 100644 app/views/agents/_agent.html.erb create mode 100644 app/views/resources/_edit.html.erb create mode 100644 app/views/resources/_form.html.erb 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 @@ +
+
+

<%= link_to agent.name, agent_url(agent) %>

+

<%= link_to agent_url(agent) %>

+ +
+

Statistiques

+
    +
  • <%= link_to pluralize(agent.resources.count, 'Resource'), agent_resources_url(agent) %>
  • +
  • <%= pluralize(agent.taxonomies.count, 'Taxonomy') %> with + <%= pluralize(agent.categories.count, 'Category') %> and + <%= pluralize(agent.sections.count, 'Section') %>.
  • +
+
+
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) %> 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 @@ +

Edit <%= resource.presence&.name || 'new resource' %>

+

Context: <%= current_agent %>

+ +<%= 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 @@ +
+ <%= tag.legend "Propriétés de la ressource" %> + +
+
<%= f.label :name %>
+
<%= f.text_field :name, maxlength: 64, placeholder: 'La ferme des animaux', value: resource.name %>
+ +
<%= f.label :summary %>
+
<%= f.text_field :summary, maxlength: 136, placeholder: 'Une ferme locale', value: resource.name %>
+ +
<%= f.label :description %>
+
<%= 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/' %>
+ +
<%= f.label :email %>
+
<%= f.email_field :email, placeholder: 'bonjour@la-ferme-des-animaux.example' %>
+ +
<%= f.label :website %>
+
<%= f.url_field :website, placeholder: 'https://la-ferme-des-animaux.example' %>
+ +
<%= f.label :phone_number %>
+
<%= f.telephone_field :phone_number, placeholder: '+32 489 000 0000' %>
+
+
+ +
+ <%= tag.legend "Classification" %> + <%# TODO Add a taxonomy selector %> + <%= section_select(current_agent.taxonomies.first) %> +
+ +
+ <%= tag.legend "Coordonées géographiques" %> + <%# TODO Add a graphical geo selector %> + +
+
<%= f.label :address %>
+
<%= f.text_field :address, value: resource.address, placeholder: 'Rue aux herbes, 123' %>
+ +
<%= f.label :postal_code %>
+
<%= f.text_field :postal_code, value: resource.postal_code, placeholder: '1000' %>
+ +
<%= f.label :city %>
+
<%= f.text_field :city, value: resource.city, placeholder: 'Bruxelles' %>
+
+ +
+
<%= f.label :longitude %>
+
<%= f.text_field :longitude, value: resource.longitude, placeholder: '0.56789012' %>
+ +
<%= f.label :latitude %>
+
<%= f.text_field :latitude, value: resource.latitude, placeholder: '50.12345678' %>
+
+
+ +<%= f.hidden_field :agent_id, value: current_agent.id %> + +

<%= f.submit 'Save' %>

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 @@ -

Resources#new

-

Find me in app/views/resources/new.html.erb

+<%= 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 @@

Welcome <%= h current_user.name %>!

-

Current Agent: <%= current_user&.agencies&.first&.agent&.name %>

+

Current Agent: <%= current_agent&.name %>

-

Cool, what can we do now?

+
+

Global Count

+

<%#= @stats[:counts].map { |k,v| pluralize(k.to_s.singularize, v) }.to_sentence %>

+

<%= p @stats[:count] %> +

+ +
+

Current Agent: <%= current_agent %>

+

<%#= @stats[:current_agent][:counts].map { |k,v| pluralize(k.to_s.singularize, v) }.to_sentence %>

+ <%= render partial: current_agent %> +
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' -- cgit v1.2.3