Extract components to edit and add cards
This way we'll be able to reuse it in the SDG Management section while reusing the `title` method to set the page title.
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
<%= back_link_to index_path %>
|
||||||
|
<%= header %>
|
||||||
|
<%= render "admin/widget/cards/form", card: card %>
|
||||||
19
app/components/admin/widget/cards/edit_component.rb
Normal file
19
app/components/admin/widget/cards/edit_component.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
class Admin::Widget::Cards::EditComponent < ApplicationComponent
|
||||||
|
include Header
|
||||||
|
attr_reader :card, :index_path
|
||||||
|
|
||||||
|
def initialize(card, index_path:)
|
||||||
|
@card = card
|
||||||
|
@index_path = index_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def title
|
||||||
|
if card.header?
|
||||||
|
t("admin.homepage.edit.header_title")
|
||||||
|
else
|
||||||
|
t("admin.homepage.edit.card_title")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/components/admin/widget/cards/new_component.html.erb
Normal file
3
app/components/admin/widget/cards/new_component.html.erb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<%= back_link_to index_path %>
|
||||||
|
<%= header %>
|
||||||
|
<%= render "admin/widget/cards/form", card: card %>
|
||||||
19
app/components/admin/widget/cards/new_component.rb
Normal file
19
app/components/admin/widget/cards/new_component.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
class Admin::Widget::Cards::NewComponent < ApplicationComponent
|
||||||
|
include Header
|
||||||
|
attr_reader :card, :index_path
|
||||||
|
|
||||||
|
def initialize(card, index_path:)
|
||||||
|
@card = card
|
||||||
|
@index_path = index_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def title
|
||||||
|
if card.header?
|
||||||
|
t("admin.homepage.new.header_title")
|
||||||
|
else
|
||||||
|
t("admin.homepage.new.card_title")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
class ApplicationComponent < ViewComponent::Base
|
class ApplicationComponent < ViewComponent::Base
|
||||||
include SettingsHelper
|
include SettingsHelper
|
||||||
|
delegate :back_link_to, to: :helpers
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
class SDG::Goals::ShowComponent < ApplicationComponent
|
class SDG::Goals::ShowComponent < ApplicationComponent
|
||||||
attr_reader :goal
|
attr_reader :goal
|
||||||
delegate :back_link_to, to: :helpers
|
|
||||||
|
|
||||||
def initialize(goal)
|
def initialize(goal)
|
||||||
@goal = goal
|
@goal = goal
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
class SDGManagement::LocalTargets::FormComponent < ApplicationComponent
|
class SDGManagement::LocalTargets::FormComponent < ApplicationComponent
|
||||||
delegate :back_link_to, to: :helpers
|
|
||||||
include Header
|
include Header
|
||||||
include TranslatableFormHelper
|
include TranslatableFormHelper
|
||||||
include GlobalizeHelper
|
include GlobalizeHelper
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<%= render "shared/globalize_locales", resource: @card %>
|
<%= render "shared/globalize_locales", resource: card %>
|
||||||
|
|
||||||
<%= translatable_form_for [:admin, @page, @card] do |f| %>
|
<%= translatable_form_for [namespace, card.cardable, card] do |f| %>
|
||||||
<%= render "shared/errors", resource: @card %>
|
<%= render "shared/errors", resource: card %>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<%= f.translatable_fields do |translations_form| %>
|
<%= f.translatable_fields do |translations_form| %>
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<% unless @card.header? %>
|
<% unless card.header? %>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<%= f.label :columns %>
|
<%= f.label :columns %>
|
||||||
<p class="help-text"><%= t("admin.site_customization.pages.cards.columns_help") %></p>
|
<p class="help-text"><%= t("admin.site_customization.pages.cards.columns_help") %></p>
|
||||||
@@ -41,16 +41,16 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= f.hidden_field :header, value: @card.header? %>
|
<%= f.hidden_field :header, value: card.header? %>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="image-form">
|
<div class="image-form">
|
||||||
<div class="image small-12 column">
|
<div class="image small-12 column">
|
||||||
<%= render "images/nested_image", imageable: @card, f: f %>
|
<%= render "images/nested_image", imageable: card, f: f %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<%= f.submit(
|
<%= f.submit(
|
||||||
t("admin.homepage.#{admin_submit_action(@card)}.#{@card.header? ? "submit_header" : "submit_card"}"),
|
t("admin.homepage.#{admin_submit_action(card)}.#{card.header? ? "submit_header" : "submit_card"}"),
|
||||||
class: "button success"
|
class: "button success"
|
||||||
) %>
|
) %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +1 @@
|
|||||||
<%= back_link_to index_path %>
|
<%= render Admin::Widget::Cards::EditComponent.new(@card, index_path: index_path) %>
|
||||||
|
|
||||||
<h2>
|
|
||||||
<% if @card.header? %>
|
|
||||||
<%= t("admin.homepage.edit.header_title") %>
|
|
||||||
<% else %>
|
|
||||||
<%= t("admin.homepage.edit.card_title") %>
|
|
||||||
<% end %>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<%= render "admin/widget/cards/form" %>
|
|
||||||
|
|||||||
@@ -1,11 +1 @@
|
|||||||
<%= back_link_to index_path %>
|
<%= render Admin::Widget::Cards::NewComponent.new(@card, index_path: index_path) %>
|
||||||
|
|
||||||
<h2>
|
|
||||||
<% if @card.header? %>
|
|
||||||
<%= t("admin.homepage.new.header_title") %>
|
|
||||||
<% else %>
|
|
||||||
<%= t("admin.homepage.new.card_title") %>
|
|
||||||
<% end %>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<%= render "admin/widget/cards/form" %>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user