tb_banners 1.3.beta1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/README.markdown +0 -1
  3. data/Rakefile +1 -1
  4. data/app/assets/javascripts/admin/banners/banner_sets.js +3 -0
  5. data/app/assets/javascripts/admin/banners/banners.js +9 -12
  6. data/app/assets/stylesheets/admin/banners/banners.css.scss +6 -1
  7. data/app/controllers/admin/banner_sets_controller.rb +9 -13
  8. data/app/controllers/admin/banners_controller.rb +23 -30
  9. data/app/helpers/spud_banners_helper.rb +16 -11
  10. data/app/models/spud_banner.rb +17 -5
  11. data/app/models/spud_banner_set.rb +3 -4
  12. data/app/views/admin/banner_sets/show.html.erb +1 -0
  13. data/app/views/admin/banners/_banner.html.erb +4 -1
  14. data/app/views/admin/banners/_form.html.erb +2 -2
  15. data/db/migrate/20121116195139_create_spud_banners.rb +1 -1
  16. data/db/migrate/20121116195312_create_spud_banner_sets.rb +1 -1
  17. data/db/migrate/20130614132846_add_rich_text_to_spud_banners.rb +1 -1
  18. data/db/migrate/20140721142719_add_start_and_end_dates_to_spud_banners.rb +1 -1
  19. data/lib/spud_banners/configuration.rb +1 -1
  20. data/lib/spud_banners/engine.rb +3 -8
  21. data/lib/spud_banners/version.rb +1 -1
  22. data/lib/tb_banners.rb +0 -1
  23. data/spec/controllers/admin/banner_sets_controller_spec.rb +9 -9
  24. data/spec/dummy/config/initializers/secret_token.rb +0 -1
  25. data/spec/dummy/db/migrate/20121127192246_create_spud_admin_permissions.spud_core.rb +1 -1
  26. data/spec/dummy/db/migrate/20121127192247_create_spud_users.spud_core.rb +1 -1
  27. data/spec/dummy/db/migrate/20121127192248_add_time_zone_to_spud_user.spud_core.rb +1 -1
  28. data/spec/dummy/db/migrate/20121127192249_add_scope_to_spud_admin_permissions.spud_core.rb +1 -1
  29. data/spec/dummy/db/migrate/20121127192250_create_spud_user_settings.spud_core.rb +1 -1
  30. data/spec/dummy/db/migrate/20130920154442_create_spud_roles.tb_core.rb +1 -1
  31. data/spec/dummy/db/migrate/20130920154443_create_spud_permissions.tb_core.rb +1 -1
  32. data/spec/dummy/db/migrate/20130920154444_create_spud_role_permissions.tb_core.rb +1 -1
  33. data/spec/dummy/db/migrate/20130920154445_drop_spud_admin_permissions.tb_core.rb +1 -1
  34. data/spec/dummy/db/migrate/20160310164644_add_requires_password_change_to_spud_users.tb_core.rb +1 -1
  35. data/spec/dummy/db/schema.rb +76 -86
  36. data/spec/factories/spud_banner_sets.rb +9 -0
  37. data/spec/factories/spud_banners.rb +7 -0
  38. data/spec/models/spud_banner_spec.rb +27 -0
  39. data/spec/rails_helper.rb +6 -3
  40. metadata +56 -77
  41. data/lib/spud_banners/liquid_tags.rb +0 -34
  42. data/spec/authlogic_helper.rb +0 -2
  43. data/spec/dummy/db/migrate/20130920154446_create_spud_banners.tb_banners.rb +0 -16
  44. data/spec/dummy/db/migrate/20130920154447_create_spud_banner_sets.tb_banners.rb +0 -13
  45. data/spec/dummy/db/migrate/20130920154448_add_rich_text_to_spud_banners.tb_banners.rb +0 -7
  46. data/spec/dummy/db/migrate/20140120174546_create_tb_liquid_spud_liquid_tags.tb_liquid.rb +0 -13
  47. data/spec/dummy/db/migrate/20160310164427_add_start_and_end_dates_to_spud_banners.tb_banners.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 4c5570408f1fd6f89b4ded74aaf55fbe28485c35
4
- data.tar.gz: c747224366ee66af3f347a8c569d8d66bdb51956
2
+ SHA256:
3
+ metadata.gz: e3a78e90e1242e80c10dfebdf922550e8883dc7f24c783a42b8b85c48cc67263
4
+ data.tar.gz: aa49eb68f74b9c070a83ba2be68110f00e904c5f10e7e9d02dc1c787ef9ed3e3
5
5
  SHA512:
6
- metadata.gz: 3f55b7a276d17e9215bb54c109fdda5d0fe1515bb41c01da8197f98daff23f192fc31dc9c47f5c9d633a3ccb11654fe818ce8cbb4a3b977283404fa7f617f824
7
- data.tar.gz: 10bef6d2c769966df3dd61b1543e2371a78c0a8e7ec2b541d8680109ce2614c5ef7fdd675f5e997d6c4f36b1f20531575cb836bdbf37d5bfdba863a4dffb99ed
6
+ metadata.gz: 36e529fa4ced38e9f632173d9bced428144a32e092836f09246f89e52d549da34a733569511175137665d0a5e0aea20b930543123dc47152959f9b413df07633
7
+ data.tar.gz: 1d2ab1f911dcaedc5ac572b216464f7d492c1354855d3bd3848d4c38aef7626be600b6cf972fb5ec92fb9721ee6aad0a85a37048e078e7a22bc3f468eb627328
@@ -156,4 +156,3 @@ Below is an example of integration with [SlidesJs][slidesjs], a jQuery plugin.
156
156
 
157
157
  [tb]:https://bitbucket.org/westlakedesign/tb_core
158
158
  [slidesjs]:http://www.slidesjs.com
159
- [liquid]:https://github.com/Shopify/liquid
data/Rakefile CHANGED
@@ -20,7 +20,7 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
21
21
  end
22
22
 
23
- APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
23
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
24
24
  load 'rails/tasks/engine.rake'
25
25
 
26
26
  Bundler::GemHelper.install_tasks
@@ -46,6 +46,9 @@ var clickedEditBannerSet = function(e){
46
46
 
47
47
  var clickedDeleteBannerSet = function(e){
48
48
  e.preventDefault();
49
+ $.ajaxSetup({
50
+ headers: { 'X-CSRF-TOKEN': Rails.csrfToken() }
51
+ });
49
52
  if(window.confirm('Are you sure?')){
50
53
  var el = $(this);
51
54
  $.ajax({
@@ -14,21 +14,14 @@ spud.admin.banners = {
14
14
  $('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-edit', clickedEditBanner);
15
15
  $('.admin-banner-set-items-container').on('click', '.admin-banner-set-item-delete', clickedDeleteBanner);
16
16
  $('.modal-body').on('submit', '.admin-banner-form', submittedBannerForm);
17
- $('.admin-banner-set-items-container').sortable({
18
- stop: sortedBanners,
19
- helper: fixHelper
17
+ Sortable.create(document.querySelector('.admin-banner-set-items-container'), {
18
+ onUpdate: sortedBanners,
19
+ dragClass: 'banner-dragging',
20
+ handle: '.glyphicon-sort'
20
21
  });
21
22
  }
22
23
  };
23
24
 
24
- // http://www.foliotek.com/devblog/make-table-rows-sortable-using-jquery-ui-sortable/
25
- var fixHelper = function(e, ui) {
26
- ui.children().each(function() {
27
- $(this).width($(this).width());
28
- });
29
- return ui;
30
- };
31
-
32
25
  var clickedAddNewBanner = function(e){
33
26
  e.preventDefault();
34
27
  bannerEditId = false;
@@ -65,6 +58,9 @@ var clickedEditBanner = function(e){
65
58
 
66
59
  var clickedDeleteBanner = function(e){
67
60
  e.preventDefault();
61
+ $.ajaxSetup({
62
+ headers: { 'X-CSRF-TOKEN': Rails.csrfToken() }
63
+ });
68
64
  var el = $(this);
69
65
  $.ajax({
70
66
  url: el.attr('href'),
@@ -172,9 +168,10 @@ var sortedBanners = function(e, ui){
172
168
  ids.push($(this).attr('data-id'));
173
169
  });
174
170
  $.ajax({
171
+ headers: { 'X-CSRF-TOKEN': Rails.csrfToken() },
175
172
  url: '/admin/banners/sort',
176
173
  type: 'post',
177
- data: {spud_banner_ids:ids, _method:'put'}
174
+ data: { spud_banner_ids: ids, _method: 'put' }
178
175
  });
179
176
  };
180
177
 
@@ -2,7 +2,7 @@
2
2
  .admin-banner-set-items-container{
3
3
 
4
4
  }
5
- .admin-banner-set-item{
5
+ .admin-banner-set-item .glyphicon-sort{
6
6
  cursor: move;
7
7
  }
8
8
  .admin-banner-set-item.ui-sortable-helper{
@@ -12,6 +12,11 @@
12
12
  .admin-banner-set-item img{
13
13
  display: block;
14
14
  }
15
+ tr.banner-dragging {
16
+ display: block;
17
+ width: 300px;
18
+ height: 100px;
19
+ }
15
20
 
16
21
  // Banner Form
17
22
  .admin-banner-upload-progress{
@@ -1,6 +1,6 @@
1
1
  class Admin::BannerSetsController < Admin::ApplicationController
2
2
 
3
- before_action :get_record, only: [:show, :edit, :update, :destroy]
3
+ before_action :load_record, only: [:show, :edit, :update, :destroy]
4
4
  respond_to :html
5
5
  belongs_to_app :banner_sets
6
6
  add_breadcrumb 'Banner Sets', :admin_banner_sets_path
@@ -23,10 +23,10 @@ class Admin::BannerSetsController < Admin::ApplicationController
23
23
  def create
24
24
  @banner_set = SpudBannerSet.new(banner_set_params)
25
25
  if @banner_set.save
26
- flash.now[:notice] = 'BannerSet created successfully'
26
+ flash.now[:notice] = 'Banner Set created successfully'
27
27
  render 'create'
28
28
  else
29
- render 'new', status: 422
29
+ render 'new', status: :unprocessable_entity
30
30
  end
31
31
  end
32
32
 
@@ -35,27 +35,23 @@ class Admin::BannerSetsController < Admin::ApplicationController
35
35
  end
36
36
 
37
37
  def update
38
- if @banner_set.update_attributes(banner_set_params)
39
- flash.now[:notice] = 'BannerSet updated successfully'
38
+ if @banner_set.update(banner_set_params)
39
+ flash.now[:notice] = 'Banner Set updated successfully'
40
40
  render 'create'
41
41
  else
42
- render 'edit', status: 422
42
+ render 'edit', status: :unprocessable_entity
43
43
  end
44
44
  end
45
45
 
46
46
  def destroy
47
- flash.now[:notice] = 'BannerSet deleted successfully' if @banner_set.destroy
47
+ flash.now[:notice] = 'Banner Set deleted successfully' if @banner_set.destroy
48
48
  head :ok
49
49
  end
50
50
 
51
51
  private
52
52
 
53
- def get_record
54
- @banner_set = SpudBannerSet.find(params[:id])
55
- rescue ActiveRecord::RecordNotFound => e
56
- flash.now[:error] = 'Could not find the requested BannerSet'
57
- redirect_to admin_banner_sets_path
58
- return false
53
+ def load_record
54
+ @banner_set = SpudBannerSet.find_by!(id: params[:id])
59
55
  end
60
56
 
61
57
  def banner_set_params
@@ -1,12 +1,12 @@
1
1
  class Admin::BannersController < Admin::ApplicationController
2
2
 
3
- before_action :get_set, only: [:new, :create]
4
- before_action :get_record, only: [:edit, :update, :destroy]
3
+ before_action :load_set, only: [:new, :create]
4
+ before_action :load_record, only: [:edit, :update, :destroy]
5
5
  respond_to :html
6
6
  layout false
7
7
 
8
8
  def new
9
- @banner = @banner_set.banners.new(start_date: Date.today)
9
+ @banner = @banner_set.banners.new(start_date: Time.zone.today)
10
10
  respond_with @banner
11
11
  end
12
12
 
@@ -14,14 +14,16 @@ class Admin::BannersController < Admin::ApplicationController
14
14
  @banner = @banner_set.banners.build
15
15
  @banner.attributes = banner_params
16
16
 
17
- last_banner = SpudBanner.select('sort_order').where(spud_banner_set_id: @banner_set.id).order('sort_order desc').first
17
+ last_banner = SpudBanner.select(:sort_order)
18
+ .where(spud_banner_set_id: @banner_set.id)
19
+ .order(sort_order: :desc).first
18
20
  @banner.sort_order = last_banner.sort_order + 1 if last_banner
19
21
 
20
22
  if @banner.save
21
- flash.now[:notice] = 'SpudBanner created successfully'
23
+ flash.now[:notice] = 'Banner created successfully'
22
24
  render 'show'
23
25
  else
24
- render 'new', status: 422
26
+ render 'new', status: :unprocessable_entity
25
27
  end
26
28
  end
27
29
 
@@ -30,24 +32,20 @@ class Admin::BannersController < Admin::ApplicationController
30
32
  end
31
33
 
32
34
  def update
33
- if @banner.update_attributes(banner_params)
34
- flash.now[:notice] = 'SpudBanner created successfully'
35
+ if @banner.update(banner_params)
36
+ flash.now[:notice] = 'Banner created successfully'
35
37
  render 'show'
36
38
  else
37
- render 'edit', status: 422
39
+ render 'edit', status: :unprocessable_entity
38
40
  end
39
41
  end
40
42
 
41
43
  def destroy
42
- if @banner.destroy
43
- flash.now[:notice] = 'SpudBanner deleted successfully'
44
- status = 200
45
- else
46
- status = 422
47
- end
48
- render blank: true, status: status
44
+ @banner.destroy
45
+ head :ok
49
46
  end
50
47
 
48
+ # rubocop:disable Rails/SkipsModelValidations
51
49
  def sort
52
50
  banner_ids = params[:spud_banner_ids]
53
51
  banners = SpudBanner.where(id: banner_ids).to_a
@@ -56,31 +54,26 @@ class Admin::BannersController < Admin::ApplicationController
56
54
  banner = banners.select { |b| b.id == id.to_i }.first
57
55
  banner.update_column(:sort_order, index)
58
56
  end
59
- banners.last.owner.touch()
57
+ banners.last.owner.touch
60
58
  end
61
59
  head :ok
62
60
  end
61
+ # rubocop:enable Rails/SkipsModelValidations
63
62
 
64
63
  private
65
64
 
66
- def get_set
67
- @banner_set = SpudBannerSet.find(params[:banner_set_id])
68
- rescue ActiveRecord::RecordNotFound => e
69
- flash.now[:error] = 'Could not find the requested SpudBannerSet'
70
- render blank: true, status: 404
71
- return false
65
+ def load_set
66
+ @banner_set = SpudBannerSet.find_by!(id: params[:banner_set_id])
72
67
  end
73
68
 
74
- def get_record
75
- @banner = SpudBanner.find(params[:id])
76
- rescue ActiveRecord::RecordNotFound => e
77
- flash.now[:error] = 'Could not find the requested SpudBanner'
78
- redirect_to admin_banner_sets_path
79
- return false
69
+ def load_record
70
+ @banner = SpudBanner.find_by!(id: params[:id])
80
71
  end
81
72
 
82
73
  def banner_params
83
- params.require(:spud_banner).permit(:banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text, :start_date, :end_date)
74
+ params.require(:spud_banner).permit(
75
+ :banner, :link_to, :link_target, :title, :alt, :sort_order, :rich_text, :start_date, :end_date
76
+ )
84
77
  end
85
78
 
86
79
  end
@@ -1,9 +1,10 @@
1
1
  module SpudBannersHelper
2
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
2
3
 
3
4
  # Returns banner html for a given identifier
4
- # Generated HTML will be cached if your application uses fragment caching
5
5
  #
6
- # * set_or_identifier: A reference to a SpudBannerSet, or the name of a known banner set passed as a symbol (ie, :home)
6
+ # * set_or_identifier: A reference to a SpudBannerSet,
7
+ # or the name of a known banner set passed as a symbol (ie, :home)
7
8
  # * options:
8
9
  # - limit: Max number of banners to return
9
10
  # - background_image: Pass true to return the banners as CSS background-image properties rather than <img/> tags
@@ -14,10 +15,10 @@ module SpudBannersHelper
14
15
  else
15
16
  SpudBannerSet.find_with_identifier(set_or_identifier)
16
17
  end
18
+
17
19
  return '' if banner_set.blank?
18
- cache(banner_set) do
19
- concat spud_banners_set_tag(banner_set, options)
20
- end
20
+
21
+ spud_banners_set_tag(banner_set, options)
21
22
  end
22
23
 
23
24
  # Returns banner html for a given banner_set
@@ -39,13 +40,16 @@ module SpudBannersHelper
39
40
  content_tag(:div, :class => "spud-banner-set #{options[:wrapper_class]}", 'data-id' => banner_set.id) do
40
41
  banners_query.map do |banner|
41
42
  if background_image
42
- concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id, :style => "background-image:url('#{banner.banner.url(:banner)}');") do
43
- if banner.rich_text
44
- content_tag :div, raw(banner.rich_text), class: 'spud-banner-rich-text'
45
- end
46
- end)
43
+ concat(content_tag(:div,
44
+ class: "spud-banner #{options[:banner_class]}",
45
+ style: "background-image:url('#{banner.banner.url(:banner)}');",
46
+ 'data-id' => banner.id) do
47
+ content_tag :div, raw(banner.rich_text), class: 'spud-banner-rich-text' if banner.rich_text
48
+ end)
47
49
  else
48
- concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id) { spud_banner_tag(banner, options) })
50
+ concat(content_tag(:div, :class => "spud-banner #{options[:banner_class]}", 'data-id' => banner.id) do
51
+ spud_banner_tag(banner, options)
52
+ end)
49
53
  end
50
54
  end
51
55
  end
@@ -71,4 +75,5 @@ module SpudBannersHelper
71
75
  image_tag(banner.banner.url(:banner), alt: banner.alt, title: banner.title)
72
76
  end
73
77
 
78
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
74
79
  end
@@ -1,8 +1,20 @@
1
1
  class SpudBanner < ActiveRecord::Base
2
- belongs_to :owner, class_name: 'SpudBannerSet', foreign_key: 'spud_banner_set_id', inverse_of: :banners, touch: true
2
+ belongs_to :owner,
3
+ class_name: SpudBannerSet.to_s,
4
+ foreign_key: :spud_banner_set_id,
5
+ inverse_of: :banners,
6
+ touch: true
3
7
 
4
- scope :active, -> {
5
- where('(start_date IS NULL OR start_date <= ?) AND (end_date IS NULL OR end_date >= ?)', Date.today, Date.today)
8
+ scope :active, lambda {
9
+ t = Time.zone.today
10
+ start_date = arel_table[:start_date]
11
+ end_date = arel_table[:end_date]
12
+
13
+ where(
14
+ start_date.eq(nil).or(start_date.lteq(t)).and(
15
+ end_date.eq(nil).or(end_date.gteq(t))
16
+ )
17
+ )
6
18
  }
7
19
 
8
20
  has_attached_file :banner,
@@ -38,8 +50,8 @@ class SpudBanner < ActiveRecord::Base
38
50
  return owner.name
39
51
  end
40
52
 
41
- def is_expired?
42
- return end_date.present? && end_date < Date.today
53
+ def expired?
54
+ return end_date.present? && end_date < Time.zone.today
43
55
  end
44
56
 
45
57
  end
@@ -1,12 +1,11 @@
1
1
  class SpudBannerSet < ActiveRecord::Base
2
- has_many :banners, -> { order('sort_order asc') }, class_name: 'SpudBanner', dependent: :destroy, inverse_of: :owner
2
+ has_many :banners, -> { order(sort_order: :asc) },
3
+ class_name: SpudBanner.to_s, dependent: :destroy, inverse_of: :owner
3
4
 
4
5
  validates :name, presence: true
5
6
  validates :name, uniqueness: true
6
7
  validates :width, :height, numericality: true
7
8
 
8
- acts_as_tb_liquid_tag :spud_banner_set, :name
9
-
10
9
  after_update :check_for_dimension_change
11
10
 
12
11
  def self.find_with_identifier(identifier)
@@ -33,7 +32,7 @@ class SpudBannerSet < ActiveRecord::Base
33
32
  private
34
33
 
35
34
  def check_for_dimension_change
36
- reprocess_banners! if height_changed? || width_changed? || cropped_changed?
35
+ reprocess_banners! if saved_change_to_height? || saved_change_to_width? || saved_change_to_cropped?
37
36
  end
38
37
 
39
38
  end
@@ -6,6 +6,7 @@
6
6
  <table class="table table-striped table-hover">
7
7
  <thead>
8
8
  <tr>
9
+ <th>&nbsp</th>
9
10
  <th>Banner</th>
10
11
  <th>Start Date</th>
11
12
  <th>End Date</th>
@@ -1,4 +1,7 @@
1
1
  <%= content_tag :tr, 'data-id' => banner.id, :class => 'admin-banner-set-item' do %>
2
+ <td>
3
+ <span class="glyphicon glyphicon-sort" aria-hidden="true"></span>
4
+ </td>
2
5
  <td width="200">
3
6
  <%= link_to banner.banner.url(:banner), :target => :blank do %>
4
7
  <%= image_tag banner.banner.url(:tiny) %>
@@ -7,7 +10,7 @@
7
10
  <td><%= banner.start_date.try(:strftime, '%m/%d/%Y') %></td>
8
11
  <td class="table-actions">
9
12
  <%= banner.end_date.try(:strftime, '%m/%d/%Y') %>
10
- <% if banner.is_expired? %>
13
+ <% if banner.expired? %>
11
14
  <span class="label">Expired</span>
12
15
  <% end %>
13
16
  </td>
@@ -47,13 +47,13 @@
47
47
  <div class="form-group">
48
48
  <%= f.label :start_date, 'Start Date', :class => 'control-label' %>
49
49
  <div class="controls controls-banner-date-selects">
50
- <%= f.date_select :start_date, :start_year => Date.today.year %>
50
+ <%= f.date_select :start_date, :start_year => Time.zone.today.year %>
51
51
  </div>
52
52
  </div>
53
53
  <div class="form-group">
54
54
  <%= f.label :end_date, 'End Date', :class => 'control-label' %>
55
55
  <div class="controls controls-banner-date-selects">
56
- <%= f.date_select :end_date, :include_blank => true, :start_year => Date.today.year %>
56
+ <%= f.date_select :end_date, :include_blank => true, :start_year => Time.zone.today.year %>
57
57
  <span class="help-block">Leave blank to never expire</span>
58
58
  </div>
59
59
  </div>
@@ -1,4 +1,4 @@
1
- class CreateSpudBanners < ActiveRecord::Migration
1
+ class CreateSpudBanners < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :spud_banners do |t|
4
4
  t.integer :spud_banner_set_id, :null => false
@@ -1,4 +1,4 @@
1
- class CreateSpudBannerSets < ActiveRecord::Migration
1
+ class CreateSpudBannerSets < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  create_table :spud_banner_sets do |t|
4
4
  t.string :name, :null => false
@@ -1,4 +1,4 @@
1
- class AddRichTextToSpudBanners < ActiveRecord::Migration
1
+ class AddRichTextToSpudBanners < ActiveRecord::Migration[4.2]
2
2
  def change
3
3
  add_column :spud_banner_sets, :has_rich_text, :boolean, :default => false
4
4
  add_column :spud_banners, :rich_text, :text