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.

Enable drag and drop for sections.

Matthew Kennedye1d70752276c
diff --git a/backend/app/assets/javascripts/spree/backend.js b/backend/app/assets/javascripts/spree/backend.js
index ccc7e450e3..d41eee98bf 100644
--- a/backend/app/assets/javascripts/spree/backend.js
+++ b/backend/app/assets/javascripts/spree/backend.js
@@ -51,6 +51,7 @@
//= require spree/backend/progress
//= require spree/backend/promotions
//= require spree/backend/menus/_index
+//= require spree/backend/cms_pages/_index
//= require spree/backend/returns/expedited_exchanges_warning
//= require spree/backend/returns/return_item_selection
//= require spree/backend/shipments
diff --git a/backend/app/assets/javascripts/spree/backend/cms_pages/_index.es6 b/backend/app/assets/javascripts/spree/backend/cms_pages/_index.es6
new file mode 100644
index 0000000000..4ea08fe53f
--- /dev/null
+++ b/backend/app/assets/javascripts/spree/backend/cms_pages/_index.es6
@@ -0,0 +1,29 @@
+document.addEventListener('DOMContentLoaded', function() {
+const el = document.getElementById('cmsPagesectionsArea')
+
+ if (el) {
+ Sortable.create(el, {
+ handle: '.move-handle',
+ ghostClass: 'moving-this',
+ animation: 550,
+ easing: 'cubic-bezier(1, 0, 0, 1)',
+ swapThreshold: 0.9,
+ forceFallback: true
+ // onEnd: function (evt) {
+ // var itemEl = evt.item.getAttribute('data-section-id')
+ // var newin = evt.newIndex
+ // return $.ajax({
+ // url: Spree.routes.classifications_api,
+ // method: 'PUT',
+ // dataType: 'json',
+ // data: {
+ // token: Spree.api_key,
+ // product_id: itemEl,
+ // taxon_id: $('#taxon_id').val(),
+ // position: newin
+ // }
+ // })
+ // }
+ })
+ }
+})
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 c18538695f..84714b7261 100644
--- a/backend/app/views/spree/admin/cms_pages/edit.html.erb
+++ b/backend/app/views/spree/admin/cms_pages/edit.html.erb
@@ -40,7 +40,7 @@
<div class="row pb-0">
<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>
+ <small><%= Spree.t('admin.cms.page_sections_info', page_type: @cms_page.kind, store: @cms_page.store.unique_name ) %></small>
</div>
<div class="col d-flex justify-content-end">
<%= 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' %>
@@ -49,12 +49,10 @@
</div>
<% if @cms_page.cms_sections.any? %>
- <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>
+ <div id="cmsPagesectionsArea" class="card-body row m-0 p-0 py-3 bg-light">
+ <% @cms_page.cms_sections.each do |section| %>
+ <%= build_page_section(section) %>
+ <% end %>
</div>
<% else %>
<div class="alert alert-info no-objects-found">
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 7a5ab19aef..6d01b42d9d 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
@@ -1,7 +1,22 @@
-<div class="<%= width %>">
- <% if section.icon.present? %>
- <div class="cms_section_preview_image_holder">
- <%= image_tag main_app.url_for(section.icon.attachment) %>
+<div class="<%= width %>" data-section-id="<%= section.id %>">
+ <div class="row m-0 p-0 py-3 mb-3 border bg-white">
+ <div class="col" style="width:30px; max-width: 70px; text-align: center;">
+ <span class="move-handle"><%= svg_icon(name: 'sort.svg', width: '20', height: '20') %></span>
</div>
- <% end %>
+ <div class="col text-center">
+ <div>Name: <%= section.name %></div>
+ <div>Type: <%= section.kind %></div>
+ <div class="m-auto" style="width:50px;">
+ <% if section.icon.present? %>
+ <div class="cms_section_preview_image_holder">
+ <%= image_tag main_app.url_for(section.icon.attachment) %>
+ </div>
+ <% end %>
+ </div>
+ </div>
+ <div class="col actions" style="width:30px; max-width: 70px; text-align: center;">
+ <%= link_to_edit(section, no_text: true, url: spree.edit_admin_cms_page_cms_section_path(@cms_page, section)) %>
+ <%= link_to_delete(section, no_text: true, url: spree.admin_cms_page_cms_section_path(@cms_page, section)) if can?(:destroy, section) %>
+ </div>
+ </div>
</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
index 7a8f4875c7..f20f267c96 100644
--- 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
@@ -1,12 +1,15 @@
-<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 class="<%= width %>" data-section-id="<%= section.id %>">
+ <div class="row m-0 p-0 py-3 mb-3 border bg-white">
+ <div class="col" style="width:30px; max-width: 70px; text-align: center;">
+ <span class="move-handle"><%= svg_icon(name: 'sort.svg', width: '20', height: '20') %></span>
+ </div>
+ <div class="col text-center">
+ <div>Name: <%= section.name %></div>
+ <div>Type: <%= section.kind %></div>
+ </div>
+ <div class="col actions" style="width:30px; max-width: 70px; text-align: center;">
+ <%= link_to_edit(section, no_text: true, url: spree.edit_admin_cms_page_cms_section_path(@cms_page, section)) %>
+ <%= link_to_delete(section, no_text: true, url: spree.admin_cms_page_cms_section_path(@cms_page, section)) if can?(:destroy, section) %>
</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 6967543786..82603f7ae7 100644
--- a/backend/app/views/spree/admin/cms_sections/_form.html.erb
+++ b/backend/app/views/spree/admin/cms_sections/_form.html.erb
@@ -21,6 +21,15 @@
<%= f.error_message_on :kind %>
<% end %>
</div>
+
+ <div class="col-6">
+ <%= f.field_container :width, class: ['form-group'] do %>
+ <%= f.label :width, Spree.t('admin.navigation.width') %>
+ <%= f.select(:width, @cms_section_widths, {include_blank: false}, class: 'select2') %>
+ <%= f.error_message_on :width %>
+ <% end %>
+ </div>
+
</div>
</div>
</div>
diff --git a/core/config/locales/en.yml b/core/config/locales/en.yml
index ca0fc6cf6d..498d9a8efe 100644
--- a/core/config/locales/en.yml
+++ b/core/config/locales/en.yml
@@ -535,7 +535,7 @@ en:
admin:
cms:
page_sections: '%{page_name} Sections'
- page_sections_info: 'below represents your page area, add sections and drag them into position'
+ page_sections_info: 'The area below represents your %{page_type} displayed in %{store}, add sections and drag them into position'
tab:
configuration: Configuration
content: Content