Move progress bars form partial to a component
This way we can move some of the view logic to the Ruby class. It'll also make it easier to write tests for it.
This commit is contained in:
41
app/components/admin/progress_bars/form_component.html.erb
Normal file
41
app/components/admin/progress_bars/form_component.html.erb
Normal file
@@ -0,0 +1,41 @@
|
||||
<%= render "shared/globalize_locales", resource: progress_bar %>
|
||||
|
||||
<%= translatable_form_for progress_bar, url: admin_polymorphic_path(progress_bar) do |f| %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 column">
|
||||
<%= f.enum_select :kind %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="small-12 medium-6 column end">
|
||||
<%= translations_form.text_field :title %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-6 large-2 column">
|
||||
<%= f.label :percentage %>
|
||||
<%= f.text_field :percentage, { type: :range,
|
||||
id: "percentage_range",
|
||||
label: false,
|
||||
class: "column" }.merge(progress_options) %>
|
||||
</div>
|
||||
|
||||
<div class="small-12 medium-6 large-2 column">
|
||||
<div class="input-group">
|
||||
<%= f.text_field :percentage, { type: :number,
|
||||
label: false,
|
||||
class: "input-group-field" }.merge(progress_options) %>
|
||||
<span class="input-group-label">%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="column">
|
||||
<%= f.submit nil, class: "button success" %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
15
app/components/admin/progress_bars/form_component.rb
Normal file
15
app/components/admin/progress_bars/form_component.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
class Admin::ProgressBars::FormComponent < ApplicationComponent
|
||||
include TranslatableFormHelper
|
||||
include GlobalizeHelper
|
||||
attr_reader :progress_bar
|
||||
|
||||
def initialize(progress_bar)
|
||||
@progress_bar = progress_bar
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def progress_options
|
||||
{ min: ProgressBar::RANGE.min, max: ProgressBar::RANGE.max, step: 1 }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user