forked from fixin.me/fixin.me
Render units from collection, without redirects
This commit is contained in:
parent
de995aa586
commit
5047d4909f
@ -361,6 +361,12 @@ table.items td:not(:first-child) {
|
||||
color: #909090;
|
||||
fill: #909090;
|
||||
}
|
||||
table.items td.hint {
|
||||
color: #909090;
|
||||
font-style: italic;
|
||||
font-size: 0.8rem;
|
||||
padding: 1em;
|
||||
}
|
||||
table.items svg {
|
||||
height: 1.2rem;
|
||||
vertical-align: middle;
|
||||
|
@ -44,4 +44,9 @@ class ApplicationController < ActionController::Base
|
||||
flash.alert = t("actioncontroller.exceptions.status.#{message_id}")
|
||||
redirect_to request.referer
|
||||
end
|
||||
|
||||
def run_and_render(action)
|
||||
send action
|
||||
render action
|
||||
end
|
||||
end
|
||||
|
@ -5,7 +5,7 @@ class UnitsController < ApplicationController
|
||||
raise AccessForbidden unless current_user.at_least(:active)
|
||||
end
|
||||
before_action only: [:edit, :update, :destroy] do
|
||||
raise ArgumentError unless current_user == @unit.user
|
||||
raise ParameterInvalid unless current_user == @unit.user
|
||||
end
|
||||
|
||||
def index
|
||||
@ -20,7 +20,7 @@ class UnitsController < ApplicationController
|
||||
@unit = current_user.units.new(unit_params)
|
||||
if @unit.save
|
||||
flash[:notice] = t(".success")
|
||||
@units = current_user.units
|
||||
run_and_render :index
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@ -32,7 +32,7 @@ class UnitsController < ApplicationController
|
||||
def update
|
||||
if @unit.update(unit_params)
|
||||
flash[:notice] = t(".success")
|
||||
redirect_to units_url
|
||||
run_and_render :index
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
@ -42,7 +42,7 @@ class UnitsController < ApplicationController
|
||||
if @unit.destroy
|
||||
flash[:notice] = t(".success")
|
||||
end
|
||||
redirect_to units_url
|
||||
run_and_render :index
|
||||
end
|
||||
|
||||
private
|
||||
|
@ -98,6 +98,10 @@ module ApplicationHelper
|
||||
end.join.html_safe
|
||||
end
|
||||
|
||||
def render_no_items
|
||||
tag.tr tag.td t('.no_items'), colspan: 10, class: 'hint'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def image_element_to(type, name, image = nil, options = nil, html_options = {})
|
||||
|
@ -1,15 +0,0 @@
|
||||
<% Unit.each_with_level(@units) do |unit, level| %>
|
||||
<tr>
|
||||
<td class="link">
|
||||
<%= link_to unit.symbol, edit_unit_path(unit), class: level > 0 ? 'subunit' : '' %>
|
||||
</td>
|
||||
<td><%= unit.name %></td>
|
||||
<td class="number"><%= scientifize(unit.multiplier) if unit.multiplier %></td>
|
||||
<% if current_user.at_least(:active) %>
|
||||
<td class="actions">
|
||||
<%= image_button_to t(".delete_unit"), "delete-outline", unit_path(unit),
|
||||
method: :delete %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
13
app/views/units/_unit.html.erb
Normal file
13
app/views/units/_unit.html.erb
Normal file
@ -0,0 +1,13 @@
|
||||
<tr>
|
||||
<td class="link">
|
||||
<%= link_to unit.symbol, edit_unit_path(unit), class: unit.base.nil? ? '' : 'subunit' %>
|
||||
</td>
|
||||
<td><%= unit.name %></td>
|
||||
<td class="number"><%= scientifize(unit.multiplier) if unit.multiplier %></td>
|
||||
<% if current_user.at_least(:active) %>
|
||||
<td class="actions">
|
||||
<%= image_button_to t(".delete_unit"), "delete-outline", unit_path(unit),
|
||||
method: :delete %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
@ -21,7 +21,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="units" is="turbo-frame">
|
||||
<%= render partial: 'index' %>
|
||||
<%= render(@units) || render_no_items %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
<%= turbo_stream.update :units do %>
|
||||
<%= render partial: 'index' %>
|
||||
<%= render(@units) || render_no_items %>
|
||||
<% end %>
|
@ -33,9 +33,11 @@ en:
|
||||
units: Units
|
||||
users: Users
|
||||
units:
|
||||
unit:
|
||||
delete_unit: Delete
|
||||
index:
|
||||
add_unit: Add unit
|
||||
delete_unit: Delete
|
||||
no_items: There are no configured units. You can try to import some defaults.
|
||||
new:
|
||||
none: none
|
||||
create:
|
||||
|
Loading…
x
Reference in New Issue
Block a user