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;
|
color: #909090;
|
||||||
fill: #909090;
|
fill: #909090;
|
||||||
}
|
}
|
||||||
|
table.items td.hint {
|
||||||
|
color: #909090;
|
||||||
|
font-style: italic;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
padding: 1em;
|
||||||
|
}
|
||||||
table.items svg {
|
table.items svg {
|
||||||
height: 1.2rem;
|
height: 1.2rem;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
@ -44,4 +44,9 @@ class ApplicationController < ActionController::Base
|
|||||||
flash.alert = t("actioncontroller.exceptions.status.#{message_id}")
|
flash.alert = t("actioncontroller.exceptions.status.#{message_id}")
|
||||||
redirect_to request.referer
|
redirect_to request.referer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run_and_render(action)
|
||||||
|
send action
|
||||||
|
render action
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ class UnitsController < ApplicationController
|
|||||||
raise AccessForbidden unless current_user.at_least(:active)
|
raise AccessForbidden unless current_user.at_least(:active)
|
||||||
end
|
end
|
||||||
before_action only: [:edit, :update, :destroy] do
|
before_action only: [:edit, :update, :destroy] do
|
||||||
raise ArgumentError unless current_user == @unit.user
|
raise ParameterInvalid unless current_user == @unit.user
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@ -20,7 +20,7 @@ class UnitsController < ApplicationController
|
|||||||
@unit = current_user.units.new(unit_params)
|
@unit = current_user.units.new(unit_params)
|
||||||
if @unit.save
|
if @unit.save
|
||||||
flash[:notice] = t(".success")
|
flash[:notice] = t(".success")
|
||||||
@units = current_user.units
|
run_and_render :index
|
||||||
else
|
else
|
||||||
render :new
|
render :new
|
||||||
end
|
end
|
||||||
@ -32,7 +32,7 @@ class UnitsController < ApplicationController
|
|||||||
def update
|
def update
|
||||||
if @unit.update(unit_params)
|
if @unit.update(unit_params)
|
||||||
flash[:notice] = t(".success")
|
flash[:notice] = t(".success")
|
||||||
redirect_to units_url
|
run_and_render :index
|
||||||
else
|
else
|
||||||
render :edit
|
render :edit
|
||||||
end
|
end
|
||||||
@ -42,7 +42,7 @@ class UnitsController < ApplicationController
|
|||||||
if @unit.destroy
|
if @unit.destroy
|
||||||
flash[:notice] = t(".success")
|
flash[:notice] = t(".success")
|
||||||
end
|
end
|
||||||
redirect_to units_url
|
run_and_render :index
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -98,6 +98,10 @@ module ApplicationHelper
|
|||||||
end.join.html_safe
|
end.join.html_safe
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_no_items
|
||||||
|
tag.tr tag.td t('.no_items'), colspan: 10, class: 'hint'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def image_element_to(type, name, image = nil, options = nil, html_options = {})
|
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>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="units" is="turbo-frame">
|
<tbody id="units" is="turbo-frame">
|
||||||
<%= render partial: 'index' %>
|
<%= render(@units) || render_no_items %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<%= turbo_stream.update :units do %>
|
<%= turbo_stream.update :units do %>
|
||||||
<%= render partial: 'index' %>
|
<%= render(@units) || render_no_items %>
|
||||||
<% end %>
|
<% end %>
|
@ -33,9 +33,11 @@ en:
|
|||||||
units: Units
|
units: Units
|
||||||
users: Users
|
users: Users
|
||||||
units:
|
units:
|
||||||
|
unit:
|
||||||
|
delete_unit: Delete
|
||||||
index:
|
index:
|
||||||
add_unit: Add unit
|
add_unit: Add unit
|
||||||
delete_unit: Delete
|
no_items: There are no configured units. You can try to import some defaults.
|
||||||
new:
|
new:
|
||||||
none: none
|
none: none
|
||||||
create:
|
create:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user