Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Add view helper methods for cms_sections.

Matthew Kennedydd64978cec16
diff --git a/backend/app/assets/javascripts/spree/backend/cms/page.es6 b/backend/app/assets/javascripts/spree/backend/cms/page.es6
index 21bb655295..186006f0da 100644
--- a/backend/app/assets/javascripts/spree/backend/cms/page.es6
+++ b/backend/app/assets/javascripts/spree/backend/cms/page.es6
@@ -1,7 +1,9 @@
document.addEventListener('DOMContentLoaded', function() {
- updateCmsPageType()
+ const pageTypeSelector = document.getElementById('cms_page_type')
const el = document.getElementById('cmsPagesectionsArea')
+ if (pageTypeSelector) { updateCmsPageType() }
+
if (el) {
Sortable.create(el, {
handle: '.move-handle',
@@ -16,7 +18,7 @@ document.addEventListener('DOMContentLoaded', function() {
})
}
- $('#cms_page_type').on('change', function() {
+ $(pageTypeSelector).on('change', function() {
updateCmsPageType()
});
diff --git a/backend/app/assets/javascripts/spree/backend/cms/section.es6 b/backend/app/assets/javascripts/spree/backend/cms/section.es6
index a9e866b547..10dad3b86a 100644
--- a/backend/app/assets/javascripts/spree/backend/cms/section.es6
+++ b/backend/app/assets/javascripts/spree/backend/cms/section.es6
@@ -4,8 +4,8 @@ document.addEventListener('DOMContentLoaded', function() {
sectionKindSelector.on('change', function() {
const selectedValue = $(sectionKindSelector).val()
const message = document.getElementById('alertToClickUpdate')
- const activeSectionKind = document.getElementById('CmsSectionKind')
- const panelType = activeSectionKind.dataset.panelKind
+ const activeSectionKind = document.getElementById('CmsSectionType')
+ const panelType = activeSectionKind.dataset.panelSectionType
if (selectedValue === panelType) {
activeSectionKind.classList = ''
diff --git a/backend/app/controllers/spree/admin/cms_sections_controller.rb b/backend/app/controllers/spree/admin/cms_sections_controller.rb
index a85f92384f..09b84ebed7 100644
--- a/backend/app/controllers/spree/admin/cms_sections_controller.rb
+++ b/backend/app/controllers/spree/admin/cms_sections_controller.rb
@@ -30,9 +30,8 @@ module Spree
end
def load_data
- @cms_section_widths = Spree::CmsSection::SECTION_WIDTHS
- @cms_section_types = Spree::CmsSection::SECTION_TYPES
- @cms_section_links_to = Spree::CmsSection::SECTION_LINKS_TO
+ @cms_section_widths = Spree::CmsSection::WIDTHS
+ @cms_section_types = Spree::CmsSection::TYPES
end
end
end
diff --git a/backend/app/helpers/spree/admin/cms_page_helper.rb b/backend/app/helpers/spree/admin/cms_page_helper.rb
index 5a9f2f3f4b..ea4ca7fe91 100644
--- a/backend/app/helpers/spree/admin/cms_page_helper.rb
+++ b/backend/app/helpers/spree/admin/cms_page_helper.rb
@@ -30,10 +30,15 @@ module Spree
formatted_types
end
- def humanize_cms_page_type(page)
- last_word = page.type.split('::', 4).last
+ def humanize_cms_type(obj)
+ last_word = obj.type.split('::', 4).last
last_word.gsub(/(?<=[a-z])(?=[A-Z])/, ' ')
end
+
+ def parametize_cms_type(obj)
+ last_word = obj.type.split('::', 4).last
+ last_word.parameterize(separator: '_')
+ end
end
end
end
diff --git a/backend/app/helpers/spree/admin/cms_section_helper.rb b/backend/app/helpers/spree/admin/cms_section_helper.rb
new file mode 100644
index 0000000000..5f3dc7c400
--- /dev/null
+++ b/backend/app/helpers/spree/admin/cms_section_helper.rb
@@ -0,0 +1,17 @@
+module Spree
+ module Admin
+ module CmsSectionHelper
+ def section_types_dropdown_values
+ formatted_types = []
+
+ Spree::CmsSection::TYPES.each do |type|
+ last_word = type.split('::', 4).last
+ readable_type = last_word.gsub(/(?<=[a-z])(?=[A-Z])/, ' ')
+ formatted_types << [readable_type, type]
+ end
+
+ formatted_types
+ end
+ end
+ end
+end
diff --git a/backend/app/views/spree/admin/cms_pages/_section_template.html.erb b/backend/app/views/spree/admin/cms_pages/_section_template.html.erb
index ad8d7999f1..6b0a60ffe9 100644
--- a/backend/app/views/spree/admin/cms_pages/_section_template.html.erb
+++ b/backend/app/views/spree/admin/cms_pages/_section_template.html.erb
@@ -5,7 +5,7 @@
<div class="d-flex align-items-center overflow-hidden w-100">
<div>
<h5 class="mb-0"><%= section.name %></h5>
- <small class="form-text text-muted mt-0">Type: <%= section.type %></small>
+ <small class="form-text text-muted mt-0">Type: <%= humanize_cms_type(section) %></small>
</div>
<div class="ml-4 pl-4 v-seperator">
diff --git a/backend/app/views/spree/admin/cms_pages/index.html.erb b/backend/app/views/spree/admin/cms_pages/index.html.erb
index 7be69d84bf..1392524e03 100644
--- a/backend/app/views/spree/admin/cms_pages/index.html.erb
+++ b/backend/app/views/spree/admin/cms_pages/index.html.erb
@@ -27,7 +27,7 @@
<%= active_badge(page.draft_mode?) %>
</td>
<td>
- <%= humanize_cms_page_type(page) %>
+ <%= humanize_cms_type(page) %>
</td>
<td>
<%= page.store.unique_name %>
diff --git a/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erb b/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erb
index 6742da5baa..0cc7c6d60b 100644
--- a/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erb
+++ b/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erb
@@ -5,7 +5,7 @@
</div>
<div class="col text-center">
<div>Name: <%= section.name %></div>
- <div>Type: <%= section.type %></div>
+ <div>Type: <%= humanize_cms_type(section) %></div>
<div class="m-auto" style="width:50px;">
<% if section.icon.present? %>
<div class="cms_section_preview_image_holder">
diff --git a/backend/app/views/spree/admin/cms_sections/_form.html.erb b/backend/app/views/spree/admin/cms_sections/_form.html.erb
index aaa3230664..665db9debb 100644
--- a/backend/app/views/spree/admin/cms_sections/_form.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/_form.html.erb
@@ -17,7 +17,7 @@
<div class="col-12 col-md-6">
<%= f.field_container :type, class: ['form-group'] do %>
<%= f.label :type, Spree.t('admin.navigation.section_type') %>
- <%= f.select(:type, @cms_section_types, {include_blank: false}) %>
+ <%= f.select(:type, section_types_dropdown_values, {include_blank: false}) %>
<%= f.error_message_on :type %>
<% end %>
</div>
@@ -42,14 +42,16 @@
</div>
<% if @cms_section.type.present? %>
- <div id="CmsSectionKind"
+ <div id="CmsSectionType"
data-hook="admin_cms_section_form_fields"
- data-panel-type="<%= @cms_section.type %>">
+ data-panel-section-type="<%= @cms_section.type %>">
<div class="row">
<div class="col-12">
<div class="card mb-3">
<div class="card-header">
- <h5 class="mb-0"><%#= Spree.t('admin.cms.settings_for', section_type: @cms_section.type) %></h5>
+ <h5 class="mb-0">
+ <%= Spree.t('admin.cms.settings_for', section: humanize_cms_type(@cms_section)) %>
+ </h5>
</div>
<div class="card-body">
<% if @cms_section.type.present? %>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
index 3ea1aa713d..83a1fba655 100644
--- a/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/types/_spree_cms_sections_hero.html.erb
@@ -47,11 +47,11 @@
<div class="col-12 col-md-6">
<%= f.field_container :linked_resource_type, class: ['form-group'] do %>
<%= f.label :linked_resource_type, Spree.t('admin.navigation.link_to') %>
- <%= f.select(:linked_resource_type, @cms_section_links_to, {include_blank: false}, class: 'link_switcher') %>
+ <%= f.select(:linked_resource_type, Spree::Cms::Sections::Hero::LINKS_TO, {include_blank: false}, class: 'link_switcher') %>
<%= f.error_message_on :linked_resource_type %>
<% end %>
</div>
<div class="col-12 col-md-6">
- <%= render "spree/admin/shared/link_switcher", resource: @cms_section, f: f %>
+ <%= render "spree/admin/shared/link_fields", resource: @cms_section, f: f %>
</div>
</div>
diff --git a/backend/app/views/spree/admin/shared/_link_switcher.html.erb b/backend/app/views/spree/admin/shared/_link_switcher.html.erb
deleted file mode 100644
index 1c7138b819..0000000000
--- a/backend/app/views/spree/admin/shared/_link_switcher.html.erb
+++ /dev/null
@@ -1,14 +0,0 @@
-<% if resource.linked_resource_type.present? %>
- <div data-panel-type="<%= resource.linked_resource_type %>">
- <%= render "spree/admin/shared/linkables/#{linkable_as_path(resource.linked_resource_type)}", resource: resource, f: f %>
- </div>
-<% end %>
-<div id="linkClickUpdate" class="d-none">
- <div class="alert alert-warning mt-3">
- <% if %w[new create].include? controller.action_name %>
- <%= raw Spree.t('admin.navigation.click_create_to_load_new_link') %>
- <% else %>
- <%= raw Spree.t('admin.navigation.click_update_to_load_new_link') %>
- <% end %>
- </div>
-</div>
diff --git a/core/app/models/spree/cms/sections/hero.rb b/core/app/models/spree/cms/sections/hero.rb
index 2f8c3965e4..1bde02e758 100644
--- a/core/app/models/spree/cms/sections/hero.rb
+++ b/core/app/models/spree/cms/sections/hero.rb
@@ -1,4 +1,5 @@
module Spree::Cms::Sections
class Hero < Spree::CmsSection
+ LINKS_TO = ['Spree::Taxon', 'Spree::Product']
end
end
diff --git a/core/app/models/spree/cms_section.rb b/core/app/models/spree/cms_section.rb
index ff315b93f7..82ed6736a7 100644
--- a/core/app/models/spree/cms_section.rb
+++ b/core/app/models/spree/cms_section.rb
@@ -12,11 +12,11 @@ module Spree
has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::Icon'
accepts_nested_attributes_for :icon, reject_if: :all_blank
- SECTION_WIDTHS = ['Edge-to-Edge', 'Full', 'Half']
- SECTION_TYPES = ['Spree::Cms::Sections::Hero',
+ WIDTHS = ['Edge-to-Edge', 'Full', 'Half']
+ TYPES = ['Spree::Cms::Sections::Hero',
'Spree::Cms::Sections::Promo',
'Spree::Cms::Sections::Featured Atricle']
- SECTION_LINKS_TO = ['Spree::Taxon', 'Spree::Product']
+ LINKS_TO = []
end
end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index 1843d5ebad..5e2bed7452 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -556,7 +556,7 @@ en:
seo_settings: SEO Settings
click_create_to_load_new_link: 'Click the <b>Create</b> button below to save your new page section, and load the section settings.'
click_update_to_load_new_link: 'Click the <b>Update</b> button below to load the new section settings.'
- settings_for: 'Available Options For %{section_kind}'
+ settings_for: 'Available Options For %{section}'
page_sections: '%{page_name} Sections'
page_sections_info: 'The area below represents your %{page_type} displayed in %{store}, add sections and drag them into position'
tab: