summaryrefslogtreecommitdiff
path: root/app/views/beds/index.html.erb
blob: e645dc51297437807ceaa71a585070093e327b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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