summaryrefslogtreecommitdiff
path: root/app/views/rafts/editor.html.erb
blob: cde56d8a3029d96467a184511572de59a5f0804d (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<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 %>
Copyright 2019--2025 Marius PETER