Skip to content

Commit

Permalink
Rework site new and edit forms
Browse files Browse the repository at this point in the history
  • Loading branch information
joeroe committed Nov 29, 2023
1 parent e46f67c commit c379fd8
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 172 deletions.
4 changes: 2 additions & 2 deletions app/views/application/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
data-action="scroll@window->home-hero#scroll"
<% end %>>

<div class="container-xxl">
<div class="container-fluid">

<a class="navbar-brand" href="/">
<%= image_tag "xronos_logo_light.svg", alt: "XRONOS", style: 'max-height: 1.5rem' %>
Expand All @@ -24,7 +24,7 @@
<% if user_signed_in? %>
<li class="nav-item dropdown">
<a class="nav-link link-info dropdown-toggle" href="#" id="contribDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Contribute
Add data
</a>
<ul class="dropdown-menu" aria-labelledby="contribDropdown">
<li class="nav-item"><a class="dropdown-item nav-link <%= active_class new_site_path %>" href="<%= new_site_path %>">New site</a></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<%= f.text_field :revision_comment, label: "Briefly describe your changes...", label_as_placeholder: true %>
<%= f.text_field :revision_comment,
label: "Briefly describe what you changed and why...",
label_as_placeholder: true %>
3 changes: 2 additions & 1 deletion app/views/shared/_record_metadata.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
Record created in XRONOS on <%= record.created_at %>.
Last updated on <%= record.updated_at %>.
<% if record.versions.any? %>
<a href="#changelog">See changelog for details</a>.
<br />
Contributors:
<%= record.versions.collect(&:whodunnit_user_email).uniq.to_sentence %>
<%= record.versions.collect(&:whodunnit_user_email).uniq.to_sentence %>.
<% end %>
</small>
</div>
61 changes: 42 additions & 19 deletions app/views/sites/_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
<%= f.text_field :name, label: "Canonical name", help: "Aliases and names in other languages can be added after the site is created." %>
<section class="my-3">
<h2 class="h5">Site names</h2>
<%= f.text_field :name, label: "Preferred name", help: "Use the most common name for the site in recent scientific literature" %>
</section>

<%# country_select is not supported by bootstrap_forms gem, so we need to
<section class="my-3">
<h2 class="h5">Location</h2>

<div class="row">
<div class="col">
<%= f.number_field :lat,
label: "Latitude",
step: "any",
placeholder: "NA",
append: "°N",
help: '<a href="https://www.fcc.gov/media/radio/dms-decimal" target="_blank">Convert DMS to decimal degrees</a>.'.html_safe %>
</div>
<div class="col">
<%= f.number_field :lng,
label: "Longitude",
step: "any",
placeholder: "NA",
append: "°E" %>
</div>
</div>

<%# country_select is not supported by bootstrap_forms gem, so we need to
construct the label and wrapper HTML manually here %>
<div class="mb-3">
<%= f.label :country_code, "Country", class: "form-label" %>
<%=
country_select_options = { include_blank: na_value }
if @site.country_from_coordinates.present?
country_select_options[:priority_countries] = [@site.country_from_coordinates.alpha2]
end
<div>
<%= f.label :country_code, "Country", class: "form-label" %>
<%=
country_select_options = { include_blank: na_value }
if @site.country_from_coordinates.present?
country_select_options[:priority_countries] = [@site.country_from_coordinates.alpha2]
end

f.country_select :country_code, country_select_options,
{ data: { controller: 'tom-select' } }
%>
</div>
f.country_select :country_code, country_select_options,
{ data: { controller: 'tom-select' } }
%>
<small class="form-text text-muted">
Country in whose territory the site is currently situated, following the <a href="https://www.iso.org/iso-3166-country-codes.html">ISO 3166</a> standard for country codes and names.
</small>
</div>

<div class="row">
<div class="col"><%= f.number_field :lat, label: "Latitude", step: "any", append: "°N",
help: '<a href="https://www.fcc.gov/media/radio/dms-decimal" target="_blank">Convert DMS to decimal degrees</a>.'.html_safe %></div>
<div class="col"><%= f.number_field :lng, label: "Longitude", step: "any", append: "°E" %></div>
</div>
</section>

<%= f.collection_select :site_type_ids, SiteType.all, :id, :name,
<%# f.collection_select :site_type_ids, SiteType.all, :id, :name,
{ label: "Site type(s)", include_blank: na_value },
{ multiple: true, data: { controller: "tom-select" } }
%>
Expand Down
13 changes: 0 additions & 13 deletions app/views/sites/_form.html.erb

This file was deleted.

87 changes: 42 additions & 45 deletions app/views/sites/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,52 +1,49 @@
<header id="site-header" class="bg-light text-primary">
<div class="container my-5">

<div class="d-flex">
<h1 class="display-3"><%= site.name %></h1>
<% if can? :edit, Site %>
<div class="ms-auto">
<%= link_to edit_icon,
edit_site_path,
title: "Edit site details",
class: "btn btn-sm btn-outline-primary",
data: { turbo_frame: "remote_modal" } %>
</div>
<% end %>
</div>
<header id="site-header">
<div class="d-flex">
<h1 class="display-3"><%= site.name %></h1>
<% if can? :edit, Site %>
<div class="ms-auto">
<%= link_to edit_icon,
edit_site_path,
title: "Edit site details",
class: "btn btn-sm btn-outline-primary",
data: { turbo_frame: "remote_modal" } %>
</div>
<% end %>
</div>

<div class="h5">
<%= xr_icon Site, {}, { style: "width: auto; height: 1.25rem;" } %>
Archaeological site
in <%= render "country", site: @site %>
</div>
<div class="h5">
<%= xr_icon Site, {}, { style: "width: auto; height: 1.25rem;" } %>
Archaeological site
in <%= render "country", site: @site %>
</div>

<% if @site.site_names.any? %>
<dl>
<dt>Also known as</dt>
<dd>
<ul class="list-unstyled">
<%= turbo_frame_tag "site_names", class: "my-3" do %>
<% for site_name in @site.site_names.order(:language, :name) do %>
<%= turbo_frame_tag site_name do %>
<li><%= render site_name %></li>
<% end %>
<% if @site.site_names.any? %>
<dl>
<dt>Also known as</dt>
<dd>
<ul class="list-unstyled">
<%= turbo_frame_tag "site_names", class: "my-3" do %>
<% for site_name in @site.site_names.order(:language, :name) do %>
<%= turbo_frame_tag site_name do %>
<li><%= render site_name %></li>
<% end %>
<% end %>
<% if can? :create, :site_name %>
<%= turbo_frame_tag SiteName.new %>
<% end %>
</ul>
</dd>
</dl>
<% end %>
<% if can? :create, :site_name %>
<%= link_to create_icon + "Add alias", [:new, @site, :site_name],
data: { turbo_frame: dom_id(SiteName.new) } %>
<% end %>

<div class="my-3">
<%= render "shared/record_metadata", record: @site %>
</div>
<% end %>
<% if can? :create, :site_name %>
<%= turbo_frame_tag SiteName.new %>
<% end %>
</ul>
</dd>
</dl>
<% end %>
<% if can? :create, :site_name %>
<%= link_to create_icon + "Add alias", [:new, @site, :site_name],
data: { turbo_frame: dom_id(SiteName.new) } %>
<% end %>

<div class="my-3">
<%= render "shared/record_metadata", record: @site %>
</div>

</header>
18 changes: 17 additions & 1 deletion app/views/sites/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<% content_for :title, "Edit site details" %>

<%= render "shared/remote_modal", title: "Edit site details" do %>

<%= render 'form' %>
<%= bootstrap_form_with(model: @site, local: true, id: "siteForm") do |f| %>

<%= render 'fields', f: f %>

<section class="my-3">
<h2 class="h5">Change summary</h2>
<%= render "application/paper_trail/revision_comment_field", f: f %>
</section>

<% end %>

<%= content_for :buttons do %>
<%= button_tag "Cancel", type: 'reset', class: 'btn btn-outline-primary', form: "siteForm", data: { "bs-dismiss": "modal" } %>
<%= button_tag "Save changes", class: 'btn btn-primary', form: "siteForm" %>
<% end %>

<% end %>
21 changes: 19 additions & 2 deletions app/views/sites/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
<% content_for :title, "New site" %>

<main class="container my-5">
<h1>New site</h1>

<%= render 'form', site: @site %>
<div class="row">
<div class="col-auto">

<h1>New site</h1>

<section class="my-3">
Please check that the site does not already exist in XRONOS first!
</section>

<%= bootstrap_form_with(model: @site, local: true, id: "siteForm") do |f| %>
<%= render "fields", f: f %>
<%= f.submit class: 'btn btn-primary' %>
<% end %>

</div>
</div>

</main>
Loading

0 comments on commit c379fd8

Please sign in to comment.