Add headings step to budget creation

Co-Authored-By: decabeza <alberto@decabeza.es>
This commit is contained in:
Julian Herrero
2020-03-22 04:54:10 +01:00
committed by Javi Martín
parent 0a2c70cbfe
commit f8d6ba12d7
27 changed files with 537 additions and 78 deletions

View File

@@ -0,0 +1,19 @@
<div class="budget-creation-step">
<button type="button" class="add" aria-expanded="<%= show_form? %>">
<%= t("admin.#{i18n_namespace_with_budget}.index.new_button") %>
</button>
<%= content %>
<button type="button" class="cancel delete"><%= t("links.form.cancel_button") %></button>
<% if next_step_path %>
<%= link_to t("admin.budgets_wizard.#{i18n_namespace}.continue"),
next_step_path,
class: "next-step" %>
<% else %>
<p class="next-step">
<%= t("admin.budgets_wizard.#{i18n_namespace}.continue") %>
</p>
<% end %>
</div>

View File

@@ -0,0 +1,22 @@
class Admin::BudgetsWizard::CreationStepComponent < ApplicationComponent
attr_reader :record, :next_step_path
def initialize(record, next_step_path)
@record = record
@next_step_path = next_step_path
end
private
def show_form?
record.errors.any?
end
def i18n_namespace
i18n_namespace_with_budget.gsub("budget_", "")
end
def i18n_namespace_with_budget
record.class.table_name
end
end

View File

@@ -8,6 +8,6 @@ class Admin::BudgetsWizard::CreationTimelineComponent < ApplicationComponent
private
def steps
%w[budget groups]
%w[budget groups headings]
end
end

View File

@@ -1,19 +1,3 @@
<div class="budget-creation-step">
<button type="button" class="add" aria-expanded="<%= show_form? %>">
<%= t("admin.budget_groups.index.new_button") %>
</button>
<%= render Admin::BudgetsWizard::CreationStepComponent.new(group, next_step_path) do %>
<%= render "/admin/budget_groups/form", group: group, path: form_path, action: "create" %>
<button type="button" class="cancel delete"><%= t("links.form.cancel_button") %></button>
<% if next_step_path %>
<%= link_to t("admin.budgets_wizard.groups.continue"),
next_step_path,
class: "next-step" %>
<% else %>
<p class="next-step">
<%= t("admin.budgets_wizard.groups.continue") %>
</p>
<% end %>
</div>
<% end %>

View File

@@ -12,16 +12,12 @@ class Admin::BudgetsWizard::Groups::CreationStepComponent < ApplicationComponent
group.budget
end
def show_form?
group.errors.any?
end
def form_path
admin_budgets_wizard_budget_groups_path(budget)
end
def next_step_path
admin_budget_group_headings_path(budget, next_step_group) if next_step_enabled?
admin_budgets_wizard_budget_group_headings_path(budget, next_step_group) if next_step_enabled?
end
def next_step_enabled?

View File

@@ -0,0 +1,3 @@
<%= render Admin::BudgetsWizard::CreationStepComponent.new(heading, next_step_path) do %>
<%= render "/admin/budget_headings/form", heading: heading, path: form_path, action: "create" %>
<% end %>

View File

@@ -0,0 +1,25 @@
class Admin::BudgetsWizard::Headings::CreationStepComponent < ApplicationComponent
attr_reader :heading
def initialize(heading)
@heading = heading
end
private
def budget
heading.budget
end
def form_path
admin_budgets_wizard_budget_group_headings_path(heading.group.budget, heading.group)
end
def next_step_path
admin_budget_path(budget) if next_step_enabled?
end
def next_step_enabled?
budget.headings.any?
end
end

View File

@@ -0,0 +1,7 @@
<%= back_link_to admin_budgets_wizard_budget_group_headings_path(budget, group) %>
<%= header %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("headings") %>
<%= render "/admin/budget_headings/form", heading: heading, path: form_path, action: "submit" %>

View File

@@ -0,0 +1,26 @@
class Admin::BudgetsWizard::Headings::EditComponent < ApplicationComponent
include Header
attr_reader :heading
def initialize(heading)
@heading = heading
end
def budget
heading.budget
end
def group
heading.group
end
def title
heading.name
end
private
def form_path
admin_budgets_wizard_budget_group_heading_path(budget, group, heading)
end
end

View File

@@ -0,0 +1,21 @@
<div class="budget-group-switcher">
<% if other_groups.one? %>
<p>
<%= t("admin.budget_headings.group_switcher.currently_showing", group: group.name) %>
<%= link_to t("admin.budget_headings.group_switcher.the_other_group", group: other_groups.first.name),
headings_path(other_groups.first) %>
</p>
<% else %>
<p><%= t("admin.budget_headings.group_switcher.currently_showing", group: group.name) %></p>
<ul class="dropdown menu" data-dropdown-menu data-disable-hover="true" data-click-open="true">
<li class="has-submenu">
<button type="button"><%= t("admin.budget_headings.group_switcher.different_group") %></button>
<ul class="menu" data-submenu>
<% other_groups.each do |other_group| %>
<li><%= link_to other_group.name, headings_path(other_group) %></li>
<% end %>
</ul>
</li>
</ul>
<% end %>
</div>

View File

@@ -0,0 +1,25 @@
class Admin::BudgetsWizard::Headings::GroupSwitcherComponent < ApplicationComponent
attr_reader :group
def initialize(group)
@group = group
end
def render?
other_groups.any?
end
private
def budget
group.budget
end
def other_groups
@other_groups ||= budget.groups.sort_by_name - [group]
end
def headings_path(group)
admin_budgets_wizard_budget_group_headings_path(budget, group)
end
end

View File

@@ -0,0 +1,10 @@
<%= back_link_to admin_budgets_wizard_budget_groups_path(budget), t("admin.budget_headings.index.back") %>
<%= header %>
<%= render Admin::Budgets::HelpComponent.new("budget_headings") %>
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("headings") %>
<%= render Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group) %>
<%= render Admin::BudgetHeadings::HeadingsComponent.new(headings) %>
<%= render Admin::BudgetsWizard::Headings::CreationStepComponent.new(new_heading) %>

View File

@@ -0,0 +1,21 @@
class Admin::BudgetsWizard::Headings::IndexComponent < ApplicationComponent
include Header
attr_reader :headings, :new_heading
def initialize(headings, new_heading)
@headings = headings
@new_heading = new_heading
end
def budget
group.budget
end
def group
new_heading.group
end
def title
t("admin.budget_headings.index.title", budget: budget.name, group: group.name)
end
end