Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4-10-stable #59

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spree_slider
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-3.3.0
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source 'https://rubygems.org'

spree_version = '~> 4.0'
spree_version = '~> 4.10.1'
gem 'spree', spree_version

gemspec
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ If you desire to have a customized carousel template you can specify your own li

## Dynamic content management

To add dynamic content, go to the spree admin section, under 'Configuration'
To add dynamic content, go to the spree admin section, under 'Settings'
and find the Spree Slider & Spree Slider Locations menu.

You can create new slides and new locations. Then to fetch & render the slider for a particular location you can do the following:
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/spree/admin/slides_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def location_after_save
end

def slide_params
params.require(:slide).permit(:name, :body, :link_url, :published, :image, :position, :product_id)
params.require(:slide).permit(:name, :body, :link_url, :published, :image, :position)
end
end
end
Expand Down
19 changes: 0 additions & 19 deletions app/helpers/spree/admin/slides_helper.rb

This file was deleted.

14 changes: 0 additions & 14 deletions app/models/spree/product_decorator.rb

This file was deleted.

25 changes: 6 additions & 19 deletions app/models/spree/slide.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
class Spree::Slide < ActiveRecord::Base
has_and_belongs_to_many :slide_locations,
class_name: 'Spree::SlideLocation',
join_table: 'spree_slide_slide_locations'

belongs_to :product, touch: true, optional: true
belongs_to :slide_location, class_name: 'Spree::SlideLocation', optional: true

has_one_attached :image

validates :link_url, presence: true, url: true, unless: -> { product }
validates :name, :image, presence: true, unless: -> { product }
validates :name, :image, presence: true
validates :image, content_type: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']

scope :published, -> { where(published: true).order('position ASC') }
scope :location, ->(location) { joins(:slide_locations).where('spree_slide_locations.name = ?', location) }
scope :product_slides, -> { published.where.not(product_id: nil).order('position ASC') }
scope :image_slides, -> { published.where(product_id: nil).order('position ASC') }
scope :location, ->(location) { joins(:slide_location).where(spree_slide_locations: { name: location })}

acts_as_list

STYLES = {
preview: [120, 120],
Expand All @@ -26,16 +21,8 @@ def initialize(attrs = nil)
super
end

def slide_name
name.blank? && product.present? ? product.name : name
end

def slide_link
link_url.blank? && product.present? ? product : link_url
end

def slide_image
!image.attached? && product.present? && product.images.any? ? product.images.first.attachment : image.attachment
image.attachment
end

# Helper for resizing
Expand Down
4 changes: 1 addition & 3 deletions app/models/spree/slide_location.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
class Spree::SlideLocation < ActiveRecord::Base
has_and_belongs_to_many :slides,
class_name: 'Spree::Slide',
join_table: 'spree_slide_slide_locations'
has_many :slides, class_name: 'Spree::Slide', dependent: :nullify

validates :name, presence: true
end

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions app/overrides/spree/home/index/add_slider.html.erb.deface

This file was deleted.

2 changes: 0 additions & 2 deletions app/overrides/spree/shared/_header/add_slider.html.erb.deface

This file was deleted.

4 changes: 1 addition & 3 deletions app/views/spree/admin/slide_locations/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<div class="row">

<div class="col-md-12">
<%= f.field_container :name do %>
<%= f.label :name, t(:name) %><br>
<%= f.label :name, raw(Spree.t(:name) + required_span_tag) %><br>
<%= f.text_field :name, class: "form-control fullwidth" %>
<% end %>
</div>

</div>
7 changes: 2 additions & 5 deletions app/views/spree/admin/slide_locations/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<% content_for :page_title do %>
<%= t('spree_slider_locations.editing_location') %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to t('spree_slider_locations.back_to_locations'), spree.admin_slide_locations_path, icon: 'arrow-left' %>
<%= link_to Spree.t(:slider_locations), spree.admin_slide_locations_url %> /
<%= @slide_location.name %>
<% end %>

<%= render 'spree/shared/error_messages', target: @slide_location %>
Expand Down
53 changes: 30 additions & 23 deletions app/views/spree/admin/slide_locations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
<% content_for :page_actions do %>
<%= button_link_to t('spree_slider_locations.new_location'), new_object_url, { class: 'btn-success', icon: 'add', id: 'admin_new_slide_link' } %>
<%= button_link_to t('spree_slider_locations.new_location'), new_object_url, { class: 'btn-primary', icon: 'add.svg', id: 'admin_new_slide_link' } %>
<% end %>

<% content_for :page_title do %>
<%= t('spree_slider_locations.title') %>
<% end %>

<table class="table" id="listing_slide_locations" data-hook >
<thead>
<tr data-hook="admin_slides_index_headers">
<th><%= Spree.t(:name) %></th>
<th data-hook="admin_slides_index_header_actions" class="actions"></th>
</tr>
</thead>
<tbody>
<% @slide_locations.each do |location|%>
<tr>
<td class="align-center"><%= location.name %></td>
<td data-hook="admin_slide_locations_index_row_actions" class="actions">
<%= link_to_edit location, no_text: true, class: 'edit' %>
&nbsp;
<%= link_to_delete location, no_text: true %>
</td>
</tr>
<% end %>
</tbody>
</table>

<% if @slide_locations.any? %>
<div class="table-responsive border rounded bg-white">
<table class="table" id="listing_slide_locations" data-hook >
<thead class="text-muted">
<tr data-hook="admin_slides_index_headers">
<th><%= Spree.t(:name) %></th>
<th data-hook="admin_slides_index_header_actions" class="actions"></th>
</tr>
</thead>
<tbody>
<% @slide_locations.each do |location|%>
<tr>
<td class="align-center"><%= location.name %></td>
<td data-hook="admin_slide_locations_index_row_actions" class="actions d-flex justify-content-end">
<%= link_to_edit location, no_text: true, class: 'edit' %>
&nbsp;
<%= link_to_delete location, no_text: true %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% else %>
<div class="text-center no-objects-found m-5">
<%= Spree.t(:no_resource_found, resource: plural_resource_name(Spree::SlideLocation)) %>,
<%= link_to Spree.t(:add_one), new_object_url if can?(:create, Spree::SlideLocation) %>!
</div>
<% end %>
5 changes: 1 addition & 4 deletions app/views/spree/admin/slide_locations/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<% content_for :page_title do %>
<%= link_to Spree.t(:slider_locations), spree.admin_slide_locations_url %> /
<%= t('spree_slider_locations.new_location') %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to t('spree_slider_locations.back_to_locations'), spree.admin_slide_locations_path, icon: 'arrow-left' %>
<% end %>

<%= render 'spree/shared/error_messages', :target => @slide_location %>

<%= form_for [:admin, @slide_location] do |f| %>
Expand Down
26 changes: 0 additions & 26 deletions app/views/spree/admin/slides/_edit_slider_locations.html.erb

This file was deleted.

52 changes: 18 additions & 34 deletions app/views/spree/admin/slides/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,59 +1,43 @@
<div class="row">
<div class="col-md-2">
<%= f.field_container :position do %>
<%= f.label :position, t(:position) %>
<%= f.number_field :position, class: 'fullwidth form-control' %>
<% end %>
</div>

<div class="col-md-10">
<div class="field checkbox">
<label>
<%= f.check_box :published, class: "form-control" %>
<%= t(:published) %>
</label>
</div>
</div>

<div class="col-md-12">
<%= f.field_container :product_id do %>
<%= label_tag :product_id, t(:product) %><br>
<%= hidden_field_tag 'slide[product_id]', f.object.product_id.to_s, class: "product_picker fullwidth" %>
<% end %>
</div>

<div class="col-md-6">
<%= f.field_container :name do %>
<%= f.label :name, t(:name) %><br>
<%= f.text_field :name, class: 'fullwidth form-control', placeholder: t('spree_slider.placeholder_name') %>
<%= f.text_field :name, class: 'fullwidth form-control' %>
<% end %>
</div>

<div class="col-md-6">
<%= f.field_container :link_url do %>
<%= f.label :link_url, t(:link_url) %><br>
<%= f.text_field :link_url, class: 'fullwidth form-control', placeholder: t('spree_slider.placeholder_link_url') %>
<%= f.text_field :link_url, class: 'fullwidth form-control' %>
<% end %>
</div>

<div class="col-md-6">
<%= render 'spree/admin/slides/edit_slider_locations', f: f %>
<%= f.field_container :image do %>
<%= f.label :image, t(:image) %><br>
<%= f.file_field :image %>
<% end %>
</div>

<div class="col-md-12">
<%= f.field_container :body do %>
<%= f.label :body, t(:body) %><br>
<%= f.text_area :body, {cols: 60, rows: 4, class: 'fullwidth form-control'} %>
<% end %>
<div class="col-md-6">
<div class="field checkbox">
<label>
<%= f.check_box :published, class: "form-control" %>
<%= t(:published) %>
</label>
</div>
</div>

<div class="col-md-6">
<%= f.field_container :image do %>
<%= f.label :image, t(:image) %> <i>(<%= t('spree_slider.image_tip') %>)</i><br>
<%= f.file_field :image %>
<%= f.field_container :slide_location do %>
<%= f.label :slide_location_id, Spree.t(:location) %>
<%= f.collection_select(:slide_location_id, Spree::SlideLocation.all, :id, :name, { include_blank: Spree.t('match_choices.none') }, { class: 'select2', disabled: (cannot? :edit, Spree::SlideLocation) }) %>
<%= f.error_message_on :slide_location_id %>
<% end %>
</div>


<div class="col-md-6">
<%= f.field_container :image do %>
<% if f.object.image.attached? %>
Expand Down
7 changes: 2 additions & 5 deletions app/views/spree/admin/slides/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<% content_for :page_title do %>
<%= t('spree_slider.editing_slide') %>
<% end %>

<% content_for :page_actions do %>
<%= button_link_to t('spree_slider.back_to_slides'), spree.admin_slides_path, icon: 'arrow-left' %>
<%= link_to Spree.t(:slides), spree.admin_slides_url %> /
<%= @slide.name %>
<% end %>

<%= render 'spree/shared/error_messages', target: @slide %>
Expand Down
Loading