Add progress bar polymorphic views
This commit is contained in:
@@ -23,8 +23,14 @@ App.Forms =
|
||||
false
|
||||
)
|
||||
|
||||
synchronizeInputs: ->
|
||||
$("[name='progress_bar[percentage]']").on
|
||||
input: ->
|
||||
$("[name='#{this.name}']").val($(this).val())
|
||||
|
||||
initialize: ->
|
||||
App.Forms.disableEnter()
|
||||
App.Forms.submitOnChange()
|
||||
App.Forms.toggleLink()
|
||||
App.Forms.synchronizeInputs()
|
||||
false
|
||||
|
||||
69
app/controllers/admin/progress_bars_controller.rb
Normal file
69
app/controllers/admin/progress_bars_controller.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
class Admin::ProgressBarsController < Admin::BaseController
|
||||
include Translatable
|
||||
|
||||
before_action :load_progressable
|
||||
before_action :load_progress_bar, only: [:edit, :update, :destroy]
|
||||
helper_method :progress_bars_index
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def new
|
||||
@progress_bar = @progressable.progress_bars.new
|
||||
end
|
||||
|
||||
def create
|
||||
@progress_bar = @progressable.progress_bars.new(progress_bar_params)
|
||||
if @progress_bar.save
|
||||
redirect_to progress_bars_index, notice: t("admin.progress_bars.create.notice")
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
if @progress_bar.update(progress_bar_params)
|
||||
redirect_to progress_bars_index, notice: t('admin.progress_bars.update.notice')
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@progress_bar.destroy
|
||||
redirect_to progress_bars_index, notice: t('admin.progress_bars.delete.notice')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def progress_bar_params
|
||||
params.require(:progress_bar).permit(allowed_params)
|
||||
end
|
||||
|
||||
def allowed_params
|
||||
[
|
||||
:kind,
|
||||
:percentage,
|
||||
translation_params(ProgressBar)
|
||||
]
|
||||
end
|
||||
|
||||
def load_progressable
|
||||
@progressable = progressable
|
||||
end
|
||||
|
||||
def progressable
|
||||
raise "This method must be implemented in subclass #{self.class.name}"
|
||||
end
|
||||
|
||||
def load_progress_bar
|
||||
@progress_bar = progressable.progress_bars.find(params[:id])
|
||||
end
|
||||
|
||||
def progress_bars_index
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(@progressable), ProgressBar.new])
|
||||
end
|
||||
end
|
||||
16
app/views/admin/progress_bars/_form.html.erb
Normal file
16
app/views/admin/progress_bars/_form.html.erb
Normal file
@@ -0,0 +1,16 @@
|
||||
<%= render "admin/shared/globalize_locales", resource: @progress_bar %>
|
||||
|
||||
<%= translatable_form_for [:admin, *resource_hierarchy_for(@progress_bar)] do |f| %>
|
||||
|
||||
<%= f.enum_select :kind %>
|
||||
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<%= translations_form.text_field :title %>
|
||||
<% end %>
|
||||
|
||||
<% progress_options = { min: ProgressBar::RANGE.min, max: ProgressBar::RANGE.max, step: 1 } %>
|
||||
<%= f.text_field :percentage, { type: :range, id: "percentage_range" }.merge(progress_options) %>
|
||||
<%= f.text_field :percentage, { type: :number, label: false }.merge(progress_options) %>
|
||||
|
||||
<%= f.submit nil, class: "button success" %>
|
||||
<% end %>
|
||||
49
app/views/admin/progress_bars/_progress_bars.html.erb
Normal file
49
app/views/admin/progress_bars/_progress_bars.html.erb
Normal file
@@ -0,0 +1,49 @@
|
||||
<h2><%= t("admin.progress_bars.index.title") %></h2>
|
||||
|
||||
<% if progressable.progress_bars.any? %>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= ProgressBar.human_attribute_name("id") %></th>
|
||||
<th><%= ProgressBar.human_attribute_name("kind") %></th>
|
||||
<th><%= ProgressBar.human_attribute_name("title") %></th>
|
||||
<th><%= ProgressBar.human_attribute_name("percentage") %></th>
|
||||
<th><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% progressable.progress_bars.each do |progress_bar| %>
|
||||
<tr id="<%= dom_id(progress_bar) %>" class="progress-bar">
|
||||
<td>
|
||||
<%= progress_bar.id %>
|
||||
</td>
|
||||
<td><%= ProgressBar.human_attribute_name("kind.#{progress_bar.kind}") %></td>
|
||||
<td><%= progress_bar.title %></td>
|
||||
<td>
|
||||
<%= number_to_percentage(progress_bar.percentage, strip_insignificant_zeros: true) %>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to t("admin.actions.edit"),
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(progress_bar)],
|
||||
action: :edit),
|
||||
class: "button hollow expanded" %>
|
||||
|
||||
<%= link_to t("admin.actions.delete"),
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(progress_bar)]),
|
||||
method: :delete,
|
||||
class: "button hollow alert expanded" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p><%= t("admin.progress_bars.index.no_progress_bars") %></p>
|
||||
<% end %>
|
||||
|
||||
<p>
|
||||
<%= link_to t("admin.progress_bars.index.new_progress_bar"),
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(progressable.progress_bars.new)],
|
||||
action: :new),
|
||||
class: "button hollow" %>
|
||||
</p>
|
||||
15
app/views/admin/progress_bars/edit.html.erb
Normal file
15
app/views/admin/progress_bars/edit.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<% if @progress_bar.primary? %>
|
||||
<% bar_title = t("admin.progress_bars.edit.title.primary") %>
|
||||
<% else %>
|
||||
<% bar_title = t("admin.progress_bars.edit.title.secondary", title: @progress_bar.title) %>
|
||||
<% end %>
|
||||
|
||||
<% provide :title do %>
|
||||
<%= "#{t("admin.header.title")} - #{bar_title}" %>
|
||||
<% end %>
|
||||
|
||||
<%= back_link_to progress_bars_index %>
|
||||
|
||||
<h2><%= bar_title %></h2>
|
||||
|
||||
<%= render "form" %>
|
||||
7
app/views/admin/progress_bars/index.html.erb
Normal file
7
app/views/admin/progress_bars/index.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<% provide :title do %>
|
||||
<%= "#{t("admin.header.title")} - #{t("admin.progress_bars.index.title")}" %>
|
||||
<% end %>
|
||||
|
||||
<%= back_link_to polymorphic_path([:admin, *resource_hierarchy_for(@progressable)]) %>
|
||||
|
||||
<%= render "admin/progress_bars/progress_bars", progressable: @progressable %>
|
||||
9
app/views/admin/progress_bars/new.html.erb
Normal file
9
app/views/admin/progress_bars/new.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<% provide :title do %>
|
||||
<%= "#{t("admin.header.title")} - #{t("admin.progress_bars.new.creating")}" %>
|
||||
<% end %>
|
||||
|
||||
<%= back_link_to progress_bars_index %>
|
||||
|
||||
<h2><%= t("admin.progress_bars.new.creating") %></h2>
|
||||
|
||||
<%= render "form" %>
|
||||
@@ -5,5 +5,13 @@ module FoundationRailsHelper
|
||||
super(attribute, opts)
|
||||
end
|
||||
end
|
||||
|
||||
def enum_select(attribute, options = {}, html_options = {})
|
||||
choices = object.class.send(attribute.to_s.pluralize).keys.map do |name|
|
||||
[object.class.human_attribute_name("#{attribute}.#{name}"), name]
|
||||
end
|
||||
|
||||
select attribute, choices, options, html_options
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,6 +9,8 @@ module ActionDispatch::Routing::UrlFor
|
||||
[resource.budget, resource]
|
||||
when "Milestone"
|
||||
[*resource_hierarchy_for(resource.milestoneable), resource]
|
||||
when "ProgressBar"
|
||||
[*resource_hierarchy_for(resource.progressable), resource]
|
||||
when "Legislation::Annotation"
|
||||
[resource.draft_version.process, resource.draft_version, resource]
|
||||
when "Legislation::Proposal", "Legislation::Question", "Legislation::DraftVersion"
|
||||
|
||||
@@ -332,6 +332,24 @@ en:
|
||||
notice: Milestone status created successfully
|
||||
delete:
|
||||
notice: Milestone status deleted successfully
|
||||
progress_bars:
|
||||
manage: "Manage progress bars"
|
||||
index:
|
||||
title: "Progress bars"
|
||||
no_progress_bars: "There are no progress bars"
|
||||
new_progress_bar: "Create new progress bar"
|
||||
new:
|
||||
creating: "Create progress bar"
|
||||
edit:
|
||||
title:
|
||||
primary: "Edit primary progress bar"
|
||||
secondary: "Edit progress bar %{title}"
|
||||
create:
|
||||
notice: "Progress bar created successfully!"
|
||||
update:
|
||||
notice: "Progress bar updated successfully"
|
||||
delete:
|
||||
notice: "Progress bar deleted successfully"
|
||||
comments:
|
||||
index:
|
||||
filter: Filter
|
||||
|
||||
@@ -332,6 +332,25 @@ es:
|
||||
notice: Estado de seguimiento creado correctamente
|
||||
delete:
|
||||
notice: Estado de seguimiento eliminado correctamente
|
||||
progress_bars:
|
||||
manage: "Gestionar barras de progreso"
|
||||
index:
|
||||
title: "Barras de progreso"
|
||||
no_progress_bars: "No hay barras de progreso"
|
||||
new_progress_bar: "Crear nueva barra de progreso"
|
||||
new:
|
||||
creating: "Crear barra de progreso"
|
||||
edit:
|
||||
title:
|
||||
primary: "Editar barra de progreso principal"
|
||||
secondary: "Editar barra de progreso %{title}"
|
||||
create:
|
||||
notice: "¡Barra de progreso creada con éxito!"
|
||||
update:
|
||||
notice: "Barra de progreso actualizada"
|
||||
delete:
|
||||
notice: "Barra de progreso eliminada correctamente"
|
||||
|
||||
comments:
|
||||
index:
|
||||
filter: Filtro
|
||||
|
||||
109
spec/shared/features/progressable.rb
Normal file
109
spec/shared/features/progressable.rb
Normal file
@@ -0,0 +1,109 @@
|
||||
shared_examples "progressable" do |factory_name, path_name|
|
||||
let!(:progressable) { create(factory_name) }
|
||||
|
||||
feature "Manage progress bars" do
|
||||
let(:progressable_path) { send(path_name, *resource_hierarchy_for(progressable)) }
|
||||
|
||||
let(:path) do
|
||||
polymorphic_path([:admin, *resource_hierarchy_for(progressable.progress_bars.new)])
|
||||
end
|
||||
|
||||
context "Index" do
|
||||
scenario "Link to index path" do
|
||||
create(:progress_bar, :secondary, progressable: progressable,
|
||||
title: "Reading documents",
|
||||
percentage: 20)
|
||||
|
||||
visit progressable_path
|
||||
click_link "Manage progress bars"
|
||||
|
||||
expect(page).to have_content "Reading documents"
|
||||
end
|
||||
|
||||
scenario "No progress bars" do
|
||||
visit path
|
||||
|
||||
expect(page).to have_content("There are no progress bars")
|
||||
end
|
||||
end
|
||||
|
||||
context "New" do
|
||||
scenario "Primary progress bar", :js do
|
||||
visit path
|
||||
click_link "Create new progress bar"
|
||||
|
||||
select "Primary", from: "Type"
|
||||
|
||||
fill_in "Current progress", with: 43
|
||||
click_button "Create Progress bar"
|
||||
|
||||
expect(page).to have_content "Progress bar created successfully"
|
||||
expect(page).to have_content "43%"
|
||||
expect(page).to have_content "Primary"
|
||||
end
|
||||
|
||||
scenario "Secondary progress bar", :js do
|
||||
visit path
|
||||
click_link "Create new progress bar"
|
||||
|
||||
select "Secondary", from: "Type"
|
||||
fill_in "Current progress", with: 36
|
||||
fill_in "Title", with: "Plant trees"
|
||||
click_button "Create Progress bar"
|
||||
|
||||
expect(page).to have_content "Progress bar created successfully"
|
||||
expect(page).to have_content "36%"
|
||||
expect(page).to have_content "Secondary"
|
||||
expect(page).to have_content "Plant trees"
|
||||
end
|
||||
end
|
||||
|
||||
context "Edit" do
|
||||
scenario "Primary progress bar", :js do
|
||||
bar = create(:progress_bar, progressable: progressable)
|
||||
|
||||
visit path
|
||||
within("#progress_bar_#{bar.id}") { click_link "Edit" }
|
||||
|
||||
fill_in "Current progress", with: 44
|
||||
click_button "Update Progress bar"
|
||||
|
||||
expect(page).to have_content "Progress bar updated successfully"
|
||||
|
||||
within("#progress_bar_#{bar.id}") do
|
||||
expect(page).to have_content "44%"
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Secondary progress bar", :js do
|
||||
bar = create(:progress_bar, :secondary, progressable: progressable)
|
||||
|
||||
visit path
|
||||
within("#progress_bar_#{bar.id}") { click_link "Edit" }
|
||||
|
||||
fill_in "Current progress", with: 76
|
||||
fill_in "Title", with: "Updated title"
|
||||
click_button "Update Progress bar"
|
||||
|
||||
expect(page).to have_content "Progress bar updated successfully"
|
||||
|
||||
within("#progress_bar_#{bar.id}") do
|
||||
expect(page).to have_content "76%"
|
||||
expect(page).to have_content "Updated title"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "Delete" do
|
||||
scenario "Remove progress bar" do
|
||||
bar = create(:progress_bar, progressable: progressable, percentage: 34)
|
||||
|
||||
visit path
|
||||
within("#progress_bar_#{bar.id}") { click_link "Delete" }
|
||||
|
||||
expect(page).to have_content "Progress bar deleted successfully"
|
||||
expect(page).not_to have_content "34%"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user