From cf826b38fe166c1ed0beeafe3485ce8a4ac95dc6 Mon Sep 17 00:00:00 2001 From: Joe Roe Date: Mon, 20 Nov 2023 13:11:41 +0100 Subject: [PATCH] Switch to inline editing for sites --- app/controllers/sites_controller.rb | 2 +- app/helpers/application_helper.rb | 8 ++++++ app/views/sites/_fields.html.erb | 12 ++++----- app/views/sites/_form.html.erb | 7 ----- app/views/sites/_header.html.erb | 10 +++++++ app/views/sites/edit.html.erb | 28 ++++++++++++++++--- app/views/sites/show.html.erb | 42 ++++++++++++----------------- 7 files changed, 66 insertions(+), 43 deletions(-) create mode 100644 app/views/sites/_header.html.erb diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 7b9c2ecd..35cf3fcb 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -107,7 +107,7 @@ def create def update respond_to do |format| if @site.update(site_params) - format.html { redirect_back(fallback_location: @site, notice: "Saved changes to #{@site.name}.") } + format.html { redirect_to @site, notice: "Saved changes to #{@site.name}." } format.json { render :show, status: :ok, location: @site } else format.html { render :edit } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 733d2448..22ecc1fb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,6 +37,14 @@ def delete_icon(options = {}) bs_icon "trash-fill", options end + def confirm_icon(options = {}) + bs_icon "check", options + end + + def cancel_icon(options = {}) + bs_icon "x", options + end + def active_class(path) "active" if current_page?(path) end diff --git a/app/views/sites/_fields.html.erb b/app/views/sites/_fields.html.erb index 4743a25a..ae0bd81e 100644 --- a/app/views/sites/_fields.html.erb +++ b/app/views/sites/_fields.html.erb @@ -1,11 +1,5 @@ <%= f.text_field :name %> -
-
<%= f.number_field :lat, label: 'Latitude', append: '°N', - help: 'Convert DMS to decimal degrees.'.html_safe %>
-
<%= f.number_field :lng, label: 'Longitude', append: '°E' %>
-
- <%# country_select is not supported by bootstrap_forms gem, so we need to construct the label and wrapper HTML manually here %>
@@ -25,3 +19,9 @@ { label: "Site type(s)", include_blank: na_value }, { multiple: true, data: { controller: "tom-select" } } %> + +
+
<%= f.number_field :lat, label: 'Latitude', append: '°N', + help: 'Convert DMS to decimal degrees.'.html_safe %>
+
<%= f.number_field :lng, label: 'Longitude', append: '°E' %>
+
diff --git a/app/views/sites/_form.html.erb b/app/views/sites/_form.html.erb index 790a2868..453fa49e 100644 --- a/app/views/sites/_form.html.erb +++ b/app/views/sites/_form.html.erb @@ -1,11 +1,4 @@ <%= bootstrap_form_with(model: @site, local: true, id: "siteForm") do |f| %> - <%= render 'fields', f: f %> - - <%= content_for :buttons do %> - <%= button_tag "Cancel", type: 'reset', class: 'btn btn-danger', form: "siteForm", data: { "bs-dismiss": "modal" } %> - <%= button_tag "Save", class: 'btn btn-success', form: "siteForm" %> - <% end %> - <% end %> diff --git a/app/views/sites/_header.html.erb b/app/views/sites/_header.html.erb new file mode 100644 index 00000000..78ac5444 --- /dev/null +++ b/app/views/sites/_header.html.erb @@ -0,0 +1,10 @@ + diff --git a/app/views/sites/edit.html.erb b/app/views/sites/edit.html.erb index 53a63726..dcb31518 100644 --- a/app/views/sites/edit.html.erb +++ b/app/views/sites/edit.html.erb @@ -1,6 +1,26 @@ -<%= render "shared/remote_modal", title: "Edit site details" do %> +<%= render "header", site: @site %> - <%= render 'form' %> - -<% end %> +
+ <%= turbo_frame_tag @site do %> +
+

+ <%= xr_icon Site, {}, style: "width: auto; height: 2rem" %> + <%= Site.label.humanize %> details +

+ <% if can? :edit, Site %> +
+ <%= link_to cancel_icon, @site, + title: "Cancel editing", + class: "btn btn-sm btn-outline-danger", + form: "siteForm" %> + <%= button_tag confirm_icon, + title: "Save changes", + class: "btn btn-sm btn-success", + form: "siteForm" %> +
+ <% end %> +
+ <%= render 'form' %> + <% end %> +
diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index 9a8ef2ac..b6b73d12 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -1,16 +1,7 @@ <% content_for :title, @site.name %> <% content_for :meta_description, "Chronometric data for #{@site.name}, an archaeological site in #{@site.country}, including #{@site.c14s.count} radiocarbon dates, #{@site.typos.count} typological classifications, and #{@site.references.count} bibliographic references." %> - +<%= render "header", site: @site %> <% unless @site.lat.blank? or @site.lng.blank? %>
@@ -26,21 +17,22 @@
-
-

- <%= xr_icon Site, {}, style: "width: auto; height: 2rem" %> - <%= Site.label.humanize %> details -

- <% if can? :edit, Site %> -
- <%= link_to edit_icon, - edit_site_path, - class: "btn btn-sm btn-outline-primary", - data: { "turbo_frame": "remote_modal" } %> -
- <% end %> -
- <%= render "site_details", site: @site %> + <%= turbo_frame_tag @site do %> +
+

+ <%= xr_icon Site, {}, style: "width: auto; height: 2rem" %> + <%= Site.label.humanize %> details +

+ <% if can? :edit, Site %> +
+ <%= link_to edit_icon, + edit_site_path, + class: "btn btn-sm btn-outline-primary" %> +
+ <% end %> +
+ <%= render "site_details", site: @site %> + <% end %>