summaryrefslogtreecommitdiff
path: root/app/views/beds
diff options
context:
space:
mode:
Diffstat (limited to 'app/views/beds')
-rw-r--r--app/views/beds/_bed.html.erb2
-rw-r--r--app/views/beds/_form.html.erb28
-rw-r--r--app/views/beds/edit.html.erb11
-rw-r--r--app/views/beds/index.html.erb54
4 files changed, 95 insertions, 0 deletions
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" %>
Copyright 2019--2025 Marius PETER