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.

Update pages

Matthew Kennedy55c4dc7ce063
diff --git a/backend/app/assets/stylesheets/spree/backend/shared/_base.scss b/backend/app/assets/stylesheets/spree/backend/shared/_base.scss
index 767813109d..ce6d5f9043 100644
--- a/backend/app/assets/stylesheets/spree/backend/shared/_base.scss
+++ b/backend/app/assets/stylesheets/spree/backend/shared/_base.scss
@@ -15,6 +15,10 @@
z-index: $zindex-dropdown;
}
+.tox-statusbar__branding {
+ display: none;
+}
+
// No-margin and no-padding helper classes
@each $side in top bottom left right {
.no-margin-#{$side} { margin-#{side}: 0; }
diff --git a/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss b/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss
index 512b9caf80..d1705a2033 100644
--- a/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss
+++ b/backend/app/assets/stylesheets/spree/backend/spree_admin.css.scss
@@ -29,6 +29,7 @@
@import 'shared/forms';
@import 'views/menus';
+@import 'views/cms_pages';
@import 'views/order_payments';
@import 'views/product_properties';
@import 'views/prototypes';
diff --git a/backend/app/assets/stylesheets/spree/backend/views/_cms_pages.scss b/backend/app/assets/stylesheets/spree/backend/views/_cms_pages.scss
new file mode 100644
index 0000000000..015dca007a
--- /dev/null
+++ b/backend/app/assets/stylesheets/spree/backend/views/_cms_pages.scss
@@ -0,0 +1,3 @@
+.cms_section_preview_image_holder img {
+ max-width: 100%;
+}
diff --git a/backend/app/controllers/spree/admin/cms_sections_controller.rb b/backend/app/controllers/spree/admin/cms_sections_controller.rb
index ea8fe3a122..24ef76e40f 100644
--- a/backend/app/controllers/spree/admin/cms_sections_controller.rb
+++ b/backend/app/controllers/spree/admin/cms_sections_controller.rb
@@ -27,6 +27,7 @@ module Spree
def load_data
@cms_section_widths = Spree::CmsSection::SECTION_WIDTHS
+ @cms_section_types = Spree::CmsSection::SECTION_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
new file mode 100644
index 0000000000..0939f9141d
--- /dev/null
+++ b/backend/app/helpers/spree/admin/cms_page_helper.rb
@@ -0,0 +1,18 @@
+module Spree
+ module Admin
+ module CmsPageHelper
+ def build_page_section(section)
+ preview_type = section.kind.parameterize(separator: '_')
+
+ case section.width
+ when 'Full'
+ css_width = 'col-12'
+ when 'Half'
+ css_width = 'col-6'
+ end
+
+ render "spree/admin/cms_pages/sections/#{preview_type}", section: section, width: css_width
+ end
+ end
+ end
+end
diff --git a/backend/app/helpers/spree/admin/page_helper.rb b/backend/app/helpers/spree/admin/page_helper.rb
deleted file mode 100644
index e8bb833904..0000000000
--- a/backend/app/helpers/spree/admin/page_helper.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-module Spree
- module Admin
- module PageHelper
-
- end
- end
-end
diff --git a/backend/app/views/spree/admin/cms_pages/edit.html.erb b/backend/app/views/spree/admin/cms_pages/edit.html.erb
index d43d3606b3..030278df85 100644
--- a/backend/app/views/spree/admin/cms_pages/edit.html.erb
+++ b/backend/app/views/spree/admin/cms_pages/edit.html.erb
@@ -27,25 +27,28 @@
<div class="card mb-3">
<div class="card-header">
<div class="row pb-0">
- <div class="col d-flex">
- <h5 class="mb-0 align-self-center"> PAGE<%#= Spree.t('admin.navigation.menu_items', menu_name: @page.title) %></h5>
+ <div class="col">
+ <h5 class="mb-0 align-self-center"> <%= Spree.t('admin.cms.page_sections', page_name: @cms_page.title) %></h5>
+ <small><%= Spree.t('admin.cms.page_sections_info') %></small>
</div>
<div class="col d-flex justify-content-end">
- <%= button_link_to 'LL', spree.new_admin_cms_page_cms_section_path(@cms_page), icon: 'add.svg', class: 'no-wrap btn btn-success align-self-center' %>
+ <%= button_link_to Spree.t('admin.pages.add_new_section'), spree.new_admin_cms_page_cms_section_path(@cms_page), icon: 'add.svg', class: 'no-wrap btn btn-success align-self-center' %>
</div>
</div>
</div>
<% if @cms_page.cms_sections.any? %>
- <% @cms_page.cms_sections.each do |section| %>
- <div>
- <%= section.content %>
+ <div class="card-body p-0">
+ <div class="row pb-0 no-gutters">
+ <% @cms_page.cms_sections.each do |section| %>
+ <%= build_page_section(section) %>
+ <% end %>
</div>
- <% end %>
+ </div>
<% else %>
<div class="alert alert-info no-objects-found">
- <%#= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::CmsSection)) %>
- <%#= link_to Spree.t(:add_one), new_object_url if can?(:create, Spree::CmsSection) %>
+ <%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::CmsSection)) %>
+ <%= link_to Spree.t(:add_one), new_object_url if can?(:create, Spree::CmsSection) %>
</div>
<% end %>
</div>
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
new file mode 100644
index 0000000000..7a5ab19aef
--- /dev/null
+++ b/backend/app/views/spree/admin/cms_pages/sections/_hero.html.erb
@@ -0,0 +1,7 @@
+<div class="<%= width %>">
+ <% if section.icon.present? %>
+ <div class="cms_section_preview_image_holder">
+ <%= image_tag main_app.url_for(section.icon.attachment) %>
+ </div>
+ <% end %>
+</div>
diff --git a/backend/app/views/spree/admin/cms_pages/sections/_text_block.html.erb b/backend/app/views/spree/admin/cms_pages/sections/_text_block.html.erb
new file mode 100644
index 0000000000..7a8f4875c7
--- /dev/null
+++ b/backend/app/views/spree/admin/cms_pages/sections/_text_block.html.erb
@@ -0,0 +1,12 @@
+<div class="<%= width %> mb-4">
+ <div class="card">
+ <div class="card-body">
+ <h5 class="card-title"><%= section.name %></h5>
+ <% if section.content.present? %>
+ <span class="small">
+ <%= section.content.html_safe %>
+ </span>
+ <% end %>
+ </div>
+ </div>
+</div>
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 26c8a5ac08..6967543786 100644
--- a/backend/app/views/spree/admin/cms_sections/_form.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/_form.html.erb
@@ -1,36 +1,37 @@
-<div class="row" data-hook="admin_menu_item_form_fields">
- <div class="col-6">
- <%= f.field_container :name, class: ['form-group'] do %>
- <%= f.label :name, raw(Spree.t(:name) + required_span_tag) %>
- <%= f.text_field :name, class: 'form-control', required: true %>
- <%= f.error_message_on :name %>
- <% end %>
-
- <%= f.field_container :kind, class: ['form-group'] do %>
- <%= f.label :kind, Spree.t('admin.navigation.item_type') %>
- <%= f.select(:kind, @menu_item_types, {include_blank: false}) %>
- <%= f.error_message_on :kind %>
- <% end %>
-
- <%= f.field_container :content, class: ['form-group'] do %>
- <%= f.text_area :content, { rows: "20", class: 'form-control' } %>
- <%= f.error_message_on :content %>
- <% end %>
+<div data-hook="admin_cms_section_form_fields">
+ <div class="row">
+ <div class="col-12">
+ <div class="card mb-3">
+ <div class="card-header">
+ <h5 class="mb-0"><%= Spree.t('admin.cms_section.settings') %></h5>
+ </div>
+ <div class="card-body">
+ <div class="row">
+ <div class="col-6">
+ <%= f.field_container :name, class: ['form-group'] do %>
+ <%= f.label :name, raw(Spree.t(:name) + required_span_tag) %>
+ <%= f.text_field :name, class: 'form-control', required: true %>
+ <%= f.error_message_on :name %>
+ <% end %>
+ </div>
+ <div class="col-6">
+ <%= f.field_container :kind, class: ['form-group'] do %>
+ <%= f.label :kind, Spree.t('admin.navigation.section_type') %>
+ <%= f.select(:kind, @cms_section_types, {include_blank: false}, class: 'select2') %>
+ <%= f.error_message_on :kind %>
+ <% end %>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
</div>
+</div>
- <div class="col-6">
- <%= @cms_section.content.html_safe %>
+<% if @cms_section.kind.present? %>
+<div class="row">
+ <div class="col-12">
+ <%= render "spree/admin/cms_sections/types/#{@cms_section.kind.parameterize(separator: '_')}", f: f %>
</div>
</div>
-
-<script type="text/javascript">
- tinymce.init({
- selector: "#cms_section_content",
- plugins: [
- "image table paste code",
- ],
- menubar: false,
- toolbar:
- "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code ",
- });
-</script>
+<% end %>
diff --git a/backend/app/views/spree/admin/cms_sections/edit.html.erb b/backend/app/views/spree/admin/cms_sections/edit.html.erb
index 0ecad53841..708a93dad7 100644
--- a/backend/app/views/spree/admin/cms_sections/edit.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/edit.html.erb
@@ -1,4 +1,5 @@
<% content_for :page_title do %>
+ <%= link_to Spree.t('admin.cms_section.all_pages'), spree.admin_cms_pages_path %> /
<%= link_to @cms_page.title, spree.edit_admin_cms_page_path(@cms_page) %> / <%= @cms_section.name %>
<% end %>
diff --git a/backend/app/views/spree/admin/cms_sections/new.html.erb b/backend/app/views/spree/admin/cms_sections/new.html.erb
index 2a318b1589..917a773e2c 100644
--- a/backend/app/views/spree/admin/cms_sections/new.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/new.html.erb
@@ -1,5 +1,6 @@
<% content_for :page_title do %>
- <%= link_to @cms_page.title, spree.edit_admin_cms_page_path(@cms_page) %> / <%= Spree.t('admin.page.new_section') %>
+ <%= link_to Spree.t('admin.cms_section.all_pages'), spree.admin_cms_pages_path %> /
+ <%= link_to @cms_page.title, spree.edit_admin_cms_page_path(@cms_page) %> / <%= Spree.t('admin.cms.new_section') %>
<% end %>
<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @cms_section } %>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_hero.html.erb b/backend/app/views/spree/admin/cms_sections/types/_hero.html.erb
new file mode 100644
index 0000000000..159ecf2efe
--- /dev/null
+++ b/backend/app/views/spree/admin/cms_sections/types/_hero.html.erb
@@ -0,0 +1,23 @@
+<% @cms_section.build_icon unless @cms_section.icon %>
+ <%= f.fields_for :icon do |icon_field| %>
+ <%= f.field_container :icon_attachment do %>
+ <% unless @cms_section.icon.new_record? %>
+ <div id="menuItemImgContainer" class="my-3 ">
+ <%= image_tag(main_app.url_for(@cms_section.icon.attachment)) %>
+ <%#= link_to Spree.t(:remove_image), remove_icon_admin_menu_menu_item_path(@cms_page, @cms_section), method: :delete %>
+ </div>
+ <% end %>
+ <div id="<% unless @cms_section.icon.new_record? %>MenuItemImageButton<% end %>">
+ <%= icon_field.file_field :attachment %>
+ </div>
+ <% end %>
+
+ <%= f.field_container :icon_alt do %>
+ <% unless @cms_section.icon.new_record? %>
+ <div class="form-group my-3">
+ <%= icon_field.label :alt, Spree.t('admin.navigation.image_alt_text') %>
+ <%= icon_field.text_field :alt, class: 'form-control' %>
+ </div>
+ <% end %>
+ <% end %>
+<% end %>
diff --git a/backend/app/views/spree/admin/cms_sections/types/_text_block.html.erb b/backend/app/views/spree/admin/cms_sections/types/_text_block.html.erb
new file mode 100644
index 0000000000..176d8f5f97
--- /dev/null
+++ b/backend/app/views/spree/admin/cms_sections/types/_text_block.html.erb
@@ -0,0 +1,16 @@
+<%= f.field_container :content, class: ['form-group'] do %>
+ <%= f.text_area :content, { rows: "20", class: 'form-control' } %>
+ <%= f.error_message_on :content %>
+<% end %>
+
+<script type="text/javascript">
+ tinymce.init({
+ selector: "#cms_section_content",
+ plugins: [
+ "image table paste code",
+ ],
+ menubar: false,
+ toolbar:
+ "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code ",
+ });
+</script>
diff --git a/core/app/models/spree/cms_section.rb b/core/app/models/spree/cms_section.rb
index 3ac0cc7ad1..261827dd4a 100644
--- a/core/app/models/spree/cms_section.rb
+++ b/core/app/models/spree/cms_section.rb
@@ -3,6 +3,10 @@ module Spree
acts_as_list scope: :cms_page
belongs_to :cms_page
+ has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::Icon'
+ accepts_nested_attributes_for :icon, reject_if: :all_blank
+
SECTION_WIDTHS = ['Full', 'Half']
+ SECTION_TYPES = ['Text Block', 'Hero']
end
end
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index b325678f3a..ca0fc6cf6d 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -533,6 +533,9 @@ en:
adjustment_total: Adjustment Total
adjustments: Adjustments
admin:
+ cms:
+ page_sections: '%{page_name} Sections'
+ page_sections_info: 'below represents your page area, add sections and drag them into position'
tab:
configuration: Configuration
content: Content
diff --git a/core/db/migrate/20210514204251_create_spree_cms_sections.rb b/core/db/migrate/20210514204251_create_spree_cms_sections.rb
index 8f7b55c888..b695377f94 100644
--- a/core/db/migrate/20210514204251_create_spree_cms_sections.rb
+++ b/core/db/migrate/20210514204251_create_spree_cms_sections.rb
@@ -8,7 +8,7 @@ class CreateSpreeCmsSections < ActiveRecord::Migration[6.0]
t.column :width, :string
t.column :kind, :string
t.column :position, :integer
- t.column :linked_resource_type, :string, default: 'None'
+ t.column :linked_resource_type, :string, default: 'Text Block'
t.column :linked_resource_id, :integer
t.belongs_to :cms_page