diff options
author | Marius Peter <marius.peter@tutanota.com> | 2025-08-29 14:22:37 +0200 |
---|---|---|
committer | Marius Peter <marius.peter@tutanota.com> | 2025-08-29 14:22:37 +0200 |
commit | 075665c588989ed0decdfb20d83f32b33eed4639 (patch) | |
tree | d9ec78be7338bd51c895b7fb311f081a7c77c45f /app/views | |
parent | 52b044d6a4278c229992404ad5801769c2d13363 (diff) |
Properly implement bed and raft management logic.
Diffstat (limited to 'app/views')
-rw-r--r-- | app/views/application/_navbar.html.erb | 12 | ||||
-rw-r--r-- | app/views/beds/_bed.html.erb | 2 | ||||
-rw-r--r-- | app/views/beds/_form.html.erb | 28 | ||||
-rw-r--r-- | app/views/beds/edit.html.erb | 11 | ||||
-rw-r--r-- | app/views/beds/index.html.erb | 54 | ||||
-rw-r--r-- | app/views/dashboard/_nutrient_measurements.html.erb (renamed from app/views/dashboard/_recent_measurements.html.erb) | 0 | ||||
-rw-r--r-- | app/views/dashboard/_raft_allocation.html.erb | 4 | ||||
-rw-r--r-- | app/views/dashboard/index.html.erb | 2 | ||||
-rw-r--r-- | app/views/rafts/_form.html.erb | 23 | ||||
-rw-r--r-- | app/views/rafts/edit.html.erb | 5 | ||||
-rw-r--r-- | app/views/rafts/editor.html.erb | 108 |
11 files changed, 132 insertions, 117 deletions
diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb index 9fa250a..89dfe3d 100644 --- a/app/views/application/_navbar.html.erb +++ b/app/views/application/_navbar.html.erb @@ -3,12 +3,12 @@ <span class="navbar-brand">FAPG</span> <button class="navbar-toggler" - type="button" - data-bs-toggle="collapse" - data-bs-target="#navbarSupportedContent" - aria-controls="navbarSupportedContent" - aria-expanded="false" - aria-label="Toggle navigation"> + type="button" + data-bs-toggle="collapse" + data-bs-target="#navbarSupportedContent" + aria-controls="navbarSupportedContent" + aria-expanded="false" + aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> diff --git a/app/views/beds/_bed.html.erb b/app/views/beds/_bed.html.erb new file mode 100644 index 0000000..6961f9b --- /dev/null +++ b/app/views/beds/_bed.html.erb @@ -0,0 +1,2 @@ +<div id="<%= dom_id bed %>"> +</div> diff --git a/app/views/beds/_form.html.erb b/app/views/beds/_form.html.erb new file mode 100644 index 0000000..e3a5c35 --- /dev/null +++ b/app/views/beds/_form.html.erb @@ -0,0 +1,28 @@ +<%= form_with(model: bed) do |form| %> + <% if bed.errors.any? %> + <div style="color: red"> + <h2><%= pluralize(bed.errors.count, "error") %> prohibited this bed from being saved:</h2> + <ul> + <% bed.errors.each do |error| %> + <li><%= error.full_message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div class="my-3"> + <%= form.fields_for :rafts do |raft| %> + <div class="input-group input-group-sm my-2"> + <span class="input-group-text">Raft <%= raft.object.location %></span> + <%= raft.collection_select :crop_id, @crops, :id, :name, + { include_blank: "Unassigned" }, + { class: "form-select" } %> + </div> + <%= raft.hidden_field :id %> + <% end %> + </div> + + <div> + <%= form.submit class: "btn btn-primary" %> + </div> +<% end %> diff --git a/app/views/beds/edit.html.erb b/app/views/beds/edit.html.erb new file mode 100644 index 0000000..6887586 --- /dev/null +++ b/app/views/beds/edit.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "Editing bed #{@bed.location}" %> + +<h1 class="display-1">Editing bed <%= @bed.location %></h1> + +<%= render "form", bed: @bed %> + +<br> + +<div> + <%= link_to "Back to beds", beds_path, class: "btn btn-secondary" %> +</div> diff --git a/app/views/beds/index.html.erb b/app/views/beds/index.html.erb new file mode 100644 index 0000000..e645dc5 --- /dev/null +++ b/app/views/beds/index.html.erb @@ -0,0 +1,54 @@ +<% content_for :title, "Crop Allocation" %> + +<h1 class="display-1">Beds and Rafts</h1> + +<%= link_to "Back to dashboard", root_path, class: "btn btn-outline-secondary my-3" %> + + +<p> + Click on a bed row or an individual raft to update the corresponding crop. +</p> + +<%= form_with url: bulk_assign_crops_beds_path, + method: :patch, + local: true do %> + <div class="btn-group" role="group" aria-label="Raft crop bulk actions"> + <select class="form-select" name="crop_id"> + <% @crops.each do |crop| %> + <option value="<%= crop.id %>"><%= crop.name.titleize %></option> + <% end %> + </select> + <button type="submit" class="btn btn-outline-primary">Apply to all</button> + </div> +<% end %> + +<div class="table-responsive"> + <table class="table table-sm small text-center align-middle my-3"> + <thead> + <tr> + <th>Bed</th> + <% max_cols = @beds.map { |b| b.rafts.count }.max %> + <% (1..max_cols).each do |i| %> + <th>R<%= i %></th> + <% end %> + </tr> + </thead> + <tbody> + <% @beds.each do |bed| %> + <tr> + <th><%= link_to bed.location, edit_bed_path(bed), class: "btn btn-outline-secondary" %></th> + <% bed.rafts.each do |raft| %> + <td> + <%= link_to (raft&.crop&.name || "—"), edit_raft_path(raft), class: "btn btn-sm" %> + </td> + <% end %> + </tr> + <% end %> + </tbody> + </table> +</div> + +<%= button_to "Reset crop allocation", reset_seed_crops_beds_path, + method: :post, + form: { data: { turbo: false } }, + class: "btn btn-outline-danger" %> diff --git a/app/views/dashboard/_recent_measurements.html.erb b/app/views/dashboard/_nutrient_measurements.html.erb index bc63a60..bc63a60 100644 --- a/app/views/dashboard/_recent_measurements.html.erb +++ b/app/views/dashboard/_nutrient_measurements.html.erb diff --git a/app/views/dashboard/_raft_allocation.html.erb b/app/views/dashboard/_raft_allocation.html.erb index ef95cdd..a2128ea 100644 --- a/app/views/dashboard/_raft_allocation.html.erb +++ b/app/views/dashboard/_raft_allocation.html.erb @@ -1,7 +1,7 @@ <div class="card shadow mb-4"> <div class="card-header d-flex justify-content-between align-items-center"> - <h5 class="mb-0">Raft Allocation</h5> - <%= link_to "Edit raft allocation", editor_rafts_path, class: "btn btn-sm btn-primary" %> + <h5 class="mb-0">Crop Allocation</h5> + <%= link_to "Edit allocation", beds_path, class: "btn btn-sm btn-primary" %> </div> <%= bar_chart @raft_data, stacked: true %> diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 2902ada..b1b2d87 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -4,4 +4,4 @@ <%= render "target_table" %> -<%= render "recent_measurements" %> +<%= render "nutrient_measurements" %> diff --git a/app/views/rafts/_form.html.erb b/app/views/rafts/_form.html.erb new file mode 100644 index 0000000..7b5d382 --- /dev/null +++ b/app/views/rafts/_form.html.erb @@ -0,0 +1,23 @@ +<%= form_with(model: raft) do |form| %> + <% if raft.errors.any? %> + <div style="color: red"> + <h2><%= pluralize(bed.errors.count, "error") %> prohibited this raft from being saved:</h2> + + <ul> + <% raft.errors.each do |error| %> + <li><%= error.full_message %></li> + <% end %> + </ul> + </div> + <% end %> + + <div class="my-3"> + <label class="form-label">Crop</label> + <%= form.collection_select :crop_id, @crops, :id, :name, + { include_blank: "Unassigned" }, { class: "form-select" } %> + </div> + + <div> + <%= form.submit class: "btn btn-primary" %> + </div> +<% end %> diff --git a/app/views/rafts/edit.html.erb b/app/views/rafts/edit.html.erb new file mode 100644 index 0000000..bf975dc --- /dev/null +++ b/app/views/rafts/edit.html.erb @@ -0,0 +1,5 @@ +<% content_for :title, "Editing bed #{@raft.bed.location}, raft #{@raft.location}" %> + +<h1 class="display-1">Editing bed <%= @raft.bed.location %>, raft <%= @raft.location %></h1> + +<%= render "form", raft: @raft %> diff --git a/app/views/rafts/editor.html.erb b/app/views/rafts/editor.html.erb deleted file mode 100644 index cde56d8..0000000 --- a/app/views/rafts/editor.html.erb +++ /dev/null @@ -1,108 +0,0 @@ -<div class="d-flex justify-content-between align-items-center mb-3"> - <h1 class="display-1">Rafts editor</h1> - <%= link_to "Back to dashboard", root_path, class: "btn btn-outline-secondary" %> -</div> - -<!-- Bulk assign all rafts --> -<div class="card"> - <div class="card-header">Assign ALL rafts</div> - <div class="card-body"> - <%= form_with url: assign_all_rafts_path, method: :patch, class: "row g-2", data: { turbo: false } do %> - <div class="col-12 col-md-6"> - <select class="form-select" name="crop_id"> - <option value="">— Unassigned (clear) —</option> - <% @crops.each do |crop| %> - <option value="<%= crop.id %>"><%= crop.name %></option> - <% end %> - </select> - </div> - <div class="col-12 col-md-auto"> - <button class="btn btn-primary">Apply to all</button> - </div> - <% end %> - </div> -</div> - -<div class="table-responsive"> - <table class="table table-sm table-striped text-center align-middle my-3"> - <thead> - <tr> - <th class="text-start">Bed</th> - <% max_cols = @beds.map { |b| b.rafts.count }.max %> - <% (1..max_cols).each do |i| %> - <th>R<%= i %></th> - <% end %> - </tr> - </thead> - <tbody> - <% @beds.each do |bed| %> - <tr> - <th><%= bed.location %></th> - <% bed.rafts.order(:location).each do |raft| %> - <td> - <% if raft.crop %> - <%= raft.crop.name %> - <% else %> - — - <% end %> - </td> - <% end %> - </tr> - <% end %> - </tbody> - </table> -</div> - -<!-- Per-bed tables --> -<% @beds.each do |bed| %> - <div class="card mb-3" id="bed-<%= bed.id %>"> - <div class="card-header d-flex flex-wrap gap-2 align-items-center"> - <span class="me-auto">Bed <strong>#<%= bed.location %></strong></span> - <%= form_with url: assign_bed_rafts_path, method: :patch, class: "d-flex gap-2 align-items-center", data: { turbo: false } do %> - <input type="hidden" name="bed_id" value="<%= bed.id %>"> - <select class="form-select" name="crop_id"> - <option value="">— Unassigned (clear) —</option> - <% @crops.each do |crop| %> - <option value="<%= crop.id %>"><%= crop.name %></option> - <% end %> - </select> - <button class="btn btn-primary">Apply</button> - <% end %> - </div> - <div class="card-body p-0"> - <div class="table-responsive"> - <table class="table table-sm mb-0 align-middle"> - <thead class="table-light"> - <tr> - <th class="text-nowrap text-center">Raft</th> - <th>Crop</th> - <th class="text-end">Actions</th> - </tr> - </thead> - <tbody> - <% bed.rafts.order(:location).each do |raft| %> - <tr> - <td class="text-center"><strong><%= raft.location %></strong></td> - <td style="max-width: 280px;"> - <%= form_with url: assign_one_raft_path(raft), method: :patch, class: "d-flex gap-2", data: { turbo: false } do %> - <select class="form-select" name="crop_id"> - <option value="">— Unassigned (clear) —</option> - <% @crops.each do |crop| %> - <option value="<%= crop.id %>" <%= "selected" if raft.crop_id == crop.id %>><%= crop.name %></option> - <% end %> - </select> - <button class="btn btn-outline-primary">Save</button> - <% end %> - </td> - <td class="text-end"> - <%= button_to "Clear", assign_one_raft_path(raft, crop_id: ""), method: :patch, - form: { data: { turbo: false } }, class: "btn btn-outline-secondary btn-sm" %> - </td> - </tr> - <% end %> - </tbody> - </table> - </div> - </div> - </div> -<% end %> |