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:
Javi Martín
2024-10-11 22:39:08 +02:00
parent 9c057d5695
commit 233ba3c72f
4 changed files with 19 additions and 5 deletions

View 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 %>

View 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