brightcontent-core 2.3.4 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/brightcontent/brightcontent.js.erb +4 -0
  3. data/app/assets/javascripts/brightcontent/core.js +3 -0
  4. data/app/assets/stylesheets/brightcontent/brightcontent.css.erb +1 -0
  5. data/app/controllers/brightcontent/application_controller.rb +6 -2
  6. data/app/controllers/brightcontent/base_controller.rb +4 -27
  7. data/app/models/brightcontent/admin_user.rb +4 -0
  8. data/app/views/brightcontent/application/_user_menu.html.erb +1 -1
  9. data/app/views/brightcontent/base/_form.html.erb +2 -2
  10. data/app/views/brightcontent/base/_list_actions.html.erb +2 -2
  11. data/app/views/brightcontent/base/_list_filters.html.erb +1 -0
  12. data/app/views/brightcontent/base/_list_header.html.erb +1 -1
  13. data/app/views/brightcontent/base/_list_item.html.erb +1 -1
  14. data/app/views/brightcontent/base/_page_sizes.html.erb +9 -0
  15. data/app/views/brightcontent/base/form_fields/_date.html.erb +10 -0
  16. data/app/views/brightcontent/base/form_fields/_datetime.html.erb +10 -0
  17. data/app/views/brightcontent/base/index.html.erb +2 -1
  18. data/app/views/layouts/brightcontent/application.html.erb +0 -3
  19. data/brightcontent-core.gemspec +2 -1
  20. data/lib/brightcontent/base_controller_ext/default_actions.rb +95 -10
  21. data/lib/brightcontent/base_controller_ext/filtering.rb +2 -2
  22. data/lib/brightcontent/base_controller_ext/pagination.rb +54 -5
  23. data/lib/brightcontent/core.rb +2 -1
  24. data/lib/brightcontent/view_lookup/filter_field.rb +1 -1
  25. data/spec/dummy/app/controllers/brightcontent/comments_controller.rb +19 -1
  26. data/spec/dummy/app/controllers/brightcontent/grouped_blogs_controller.rb +5 -0
  27. data/spec/dummy/app/models/grouped_blog.rb +9 -0
  28. data/spec/dummy/config/routes.rb +2 -0
  29. data/spec/dummy/db/migrate/20160623142310_create_grouped_blogs.rb +12 -0
  30. data/spec/factories.rb +14 -0
  31. data/spec/features/grouped_resources_index_spec.rb +37 -0
  32. data/spec/features/resources_index_spec.rb +105 -0
  33. metadata +33 -9
  34. data/Gemfile +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a42674026bfb9c90c0e782375d93a9698c65f23
4
- data.tar.gz: a64e099fc087cd05afd971f0aea67cf30d073478
3
+ metadata.gz: a59c7387cca9c17d2cdd1a2172f14732fac39181
4
+ data.tar.gz: b35f502da97a126b6f1dd2d5553564bbcec67149
5
5
  SHA512:
6
- metadata.gz: e3a974a15c9753555c1c582e163324d0ed478980b7a6b015ed55bf570b34a57b1b49179a4d6111e0ccf2cbf1702aeca6f5979d384bafb13aaf3a7bf14ccb68e5
7
- data.tar.gz: 4a875f9257a6f88c8239318b57407d1cb52b8b6e9970f1690836bc89e6da7d6050514b27361d224cd8d48cc1a68c55406f0c5c093d421b8e0e058805382c3e96
6
+ metadata.gz: e51652e0b7c53f62e023f2c01fda8ddddf55d30e43feaa8ae2d29d710c703e3696deac162132dc18c7377762df3e6bcc46402d214a59edef3ec3698a054f7ca3
7
+ data.tar.gz: b4fa46b6fc1c9331ad112831e0ed4c2a00182c537b940fc5df6de05f4f1b56dc5fb5f04293913a953d67bb0df61a28f673a01fca08dafc30c79dc3f467c90cc5
@@ -1,6 +1,10 @@
1
1
  //= require jquery
2
2
  //= require jquery_ujs
3
3
  //= require bootstrap
4
+ //= require moment
5
+ //= require bootstrap-datetimepicker
6
+ //= require moment/nl
7
+ //= require locales/bootstrap-datetimepicker.nl.js
4
8
 
5
9
  <% (Brightcontent.extensions + ['custom']).each do |name|
6
10
  require_asset("brightcontent/#{name}")
@@ -16,4 +16,7 @@ $(function() {
16
16
  }
17
17
  }
18
18
  });
19
+
20
+ $('[data-behaviour~=datepicker]').datetimepicker(pickTime: false, language: 'nl')
21
+ $('[data-behaviour~=datetimepicker]').datetimepicker(language: 'nl')
19
22
  });
@@ -1,4 +1,5 @@
1
1
  /*
2
+ *= require bootstrap-datetimepicker
2
3
  *= require bootstrap-wysihtml5
3
4
  *= require brightcontent/signin
4
5
  */
@@ -10,10 +10,14 @@ module Brightcontent
10
10
  redirect_to polymorphic_url(user_resources.first.klass)
11
11
  end
12
12
 
13
+ def default_url_options(options = {})
14
+ { locale: I18n.locale }.merge options
15
+ end
16
+
13
17
  private
14
18
 
15
19
  def set_locale
16
- I18n.locale = Brightcontent.locale
20
+ I18n.locale = params[:locale] || Brightcontent.locale
17
21
  end
18
22
 
19
23
  def current_user
@@ -24,7 +28,7 @@ module Brightcontent
24
28
  helper_method :current_user
25
29
 
26
30
  def user_resources
27
- @user_resources ||= RoutesParser.new.resources
31
+ @user_resources ||= @current_user.resources
28
32
  end
29
33
  helper_method :user_resources
30
34
 
@@ -3,37 +3,14 @@ require_dependency "brightcontent/application_controller"
3
3
 
4
4
  module Brightcontent
5
5
  class BaseController < ApplicationController
6
- inherit_resources
7
- respond_to :all
8
-
9
6
  include BaseControllerExt::DefaultActions
7
+ include BaseControllerExt::Filtering
10
8
  include BaseControllerExt::Pagination
11
9
  include BaseControllerExt::Fields
12
- include BaseControllerExt::Filtering
13
-
14
- def permitted_params
15
- params.permit!
16
- end
17
-
18
- def resource_params
19
- [permitted_params[resource_instance_name]]
20
- end
21
-
22
- protected
23
-
24
- def parent
25
- super if parent?
26
- end
27
- helper_method :parent
28
-
29
- def resource_item_path
30
- [parent, resource]
31
- end
32
- helper_method :resource_item_path
33
10
 
34
- def resource_index_path
35
- [parent, resource_class]
11
+ # deprecated; included for compatibility with inherited_resources
12
+ def end_of_association_chain
13
+ base_collection
36
14
  end
37
- helper_method :resource_index_path
38
15
  end
39
16
  end
@@ -7,5 +7,9 @@ module Brightcontent
7
7
  def self.authenticate(email, password)
8
8
  find_by_email(email).try :authenticate, password
9
9
  end
10
+
11
+ def resources
12
+ Brightcontent::RoutesParser.new.resources
13
+ end
10
14
  end
11
15
  end
@@ -1,4 +1,4 @@
1
1
  <li><%= link_to "Homepage", "/" %></li>
2
- <li><%= link_to Brightcontent::AdminUser.model_name.human.pluralize, admin_users_path %></li>
2
+ <li><%= link_to nominative_plural(Brightcontent.user_model), admin_users_path %></li>
3
3
  <li class="divider"></li>
4
4
  <li><%= link_to t('brightcontent.logout'), logout_path %></li>
@@ -1,4 +1,4 @@
1
- <%= simple_form_for resource_item_path do |form| %>
1
+ <%= simple_form_for resource_path do |form| %>
2
2
  <%= form.error_notification %>
3
3
 
4
4
  <div class="page-header">
@@ -16,7 +16,7 @@
16
16
  <%= form.button :submit, t('brightcontent.save_and_continue'), class: "btn btn-default", name: "commit_and_continue" %>
17
17
 
18
18
  <% unless resource.new_record? %>
19
- <%= link_to t('brightcontent.delete'), resource_item_path, class: "btn btn-danger pull-right", method: :delete, data: { confirm: 'Are you sure?' } %>
19
+ <%= link_to t('brightcontent.delete'), resource_path, class: "btn btn-danger pull-right", method: :delete, data: { confirm: 'Are you sure?' } %>
20
20
  <% end %>
21
21
  </div>
22
22
  <% end %>
@@ -1,2 +1,2 @@
1
- <%= link_to t('brightcontent.edit'), [:edit, parent, item], class: "btn btn-xs btn-primary" %>
2
- <%= link_to t('brightcontent.delete'), [parent, item], class: "btn btn-xs btn-danger", data: {confirm: t('brightcontent.are_you_sure')}, method: :delete %>
1
+ <%= link_to t('brightcontent.edit'), resource_edit_path(item), class: "btn btn-xs btn-primary" %>
2
+ <%= link_to t('brightcontent.delete'), resource_path(item), class: "btn btn-xs btn-danger", data: {confirm: t('brightcontent.are_you_sure')}, method: :delete %>
@@ -1,6 +1,7 @@
1
1
  <% if filter_fields.present? %>
2
2
  <div class="panel-body">
3
3
  <%= search_form_for ransack_search, class: "form-inline" do |form| %>
4
+ <%= hidden_field_tag :per_page, items_per_page %>
4
5
  <% normalized_filter_fields.each do |field, options| %>
5
6
  <%= render_filter_field form, field, options %>
6
7
  <% end %>
@@ -1,5 +1,5 @@
1
1
  <div class="page-header">
2
- <%= link_to "#{I18n.t('brightcontent.create_new', model: resource_class.model_name.human).capitalize}", polymorphic_url(resource_index_path, action: :new), class: "btn btn-primary pull-right" %>
2
+ <%= link_to "#{I18n.t('brightcontent.create_new', model: resource_class.model_name.human).capitalize}", url_for(action: :new), class: "btn btn-primary pull-right" %>
3
3
  <h1><%= nominative_plural(resource_class).capitalize %></h1>
4
4
  </div>
5
5
 
@@ -1,4 +1,4 @@
1
- <%= content_tag_for :tr, item do %>
1
+ <%= content_tag :tr, id: dom_id(item), class: dom_class(item) do %>
2
2
  <% list_fields.each do |field| %>
3
3
  <td><%= render_list_field(item, field) %></td>
4
4
  <% end %>
@@ -0,0 +1,9 @@
1
+ <% if page_sizes_visible?(collection) %>
2
+ <ul class="pagination page-sizes pull-left">
3
+ <% page_sizes.each do |size| %>
4
+ <li class="<%= :active if size == items_per_page %>">
5
+ <%= link_to size, params.permit!.merge({ per_page: size, page: corrected_page(size) }) %>
6
+ </li>
7
+ <% end %>
8
+ </ul>
9
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <div class="form-group">
2
+ <%= form.label field %>
3
+ <div class="col-sm-10">
4
+ <%= form.text_field field, class: 'form-control', data: {behaviour: 'datepicker', format: "dd/MM/yyyy"} %>
5
+ <span class="add-on">
6
+ <i data-date-icon="icon-calendar">
7
+ </i>
8
+ </span>
9
+ </div>
10
+ </div>
@@ -0,0 +1,10 @@
1
+ <div class="form-group">
2
+ <%= form.label field %>
3
+ <div class="col-sm-10">
4
+ <%= form.text_field field, class: 'form-control', data: {behaviour: 'datetimepicker', format: "dd/MM/yyyy HH:mm"} %>
5
+ <span class="add-on">
6
+ <i data-time-icon="icon-clock" data-date-icon="icon-calendar">
7
+ </i>
8
+ </span>
9
+ </div>
10
+ </div>
@@ -19,5 +19,6 @@
19
19
  </div>
20
20
 
21
21
  <div class="panel-footer panel-footer-pagination">
22
- <%= will_paginate collection, renderer: BootstrapPagination::Rails %>
22
+ <%= render partial: "page_sizes" %>
23
+ <%= will_paginate collection, class: :pages, renderer: BootstrapPagination::Rails %>
23
24
  </div>
@@ -7,9 +7,6 @@
7
7
  <%= stylesheet_link_tag "brightcontent/brightcontent", :media => "all" %>
8
8
  <%= yield :head %>
9
9
  <%= csrf_meta_tags %>
10
- <!--[if lt IE 9]>
11
- <script src="https://html5shim.googlecode.com/svn/trunk/html5.js"></script>
12
- <![endif]-->
13
10
  </head>
14
11
 
15
12
  <body data-editor-locale="<%=t('brightcontent.editor_locale')%>">
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "bcrypt"
20
20
  s.add_dependency "bootstrap-sass", ">= 3.1"
21
21
  s.add_dependency "bootstrap-wysihtml5-rails", ">= 0.3.2"
22
- s.add_dependency "inherited_resources", ">= 1.6.0"
22
+ s.add_dependency "momentjs-rails", "~> 2.5.0"
23
+ s.add_dependency "bootstrap3-datetimepicker-rails", "~> 3.0.0"
23
24
  s.add_dependency "jquery-rails"
24
25
  s.add_dependency "sass-rails", ">= 4.0.2"
25
26
  s.add_dependency "simple_form"
@@ -1,35 +1,120 @@
1
+ require 'active_support/concern'
2
+
1
3
  module Brightcontent
2
4
  module BaseControllerExt
3
5
  module DefaultActions
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ before_action :set_collection
10
+ before_action :set_resource, only: [:show, :edit, :update, :destroy]
11
+ helper_method :resource, :resource_class, :resource_index_path, :resource_path, :collection, :resource_edit_path
12
+ end
13
+
14
+ def base_collection
15
+ instance_variable_get :"@#{resource_name.pluralize}"
16
+ end
17
+
18
+ def collection
19
+ base_collection
20
+ end
21
+
22
+ def collection=(val)
23
+ instance_variable_set :"@#{resource_name.pluralize}", val
24
+ end
25
+
26
+ def resource
27
+ instance_variable_get :"@#{resource_instance_name}"
28
+ end
29
+
30
+ def resource=(val)
31
+ instance_variable_set :"@#{resource_instance_name}", val
32
+ end
33
+
34
+ def resource_class
35
+ controller_name.classify.constantize
36
+ end
37
+
38
+ def resource_name
39
+ controller_name
40
+ end
41
+
42
+ def resource_instance_name
43
+ resource_name.singularize
44
+ end
45
+
46
+ def index
47
+ end
48
+
4
49
  def show
5
- if request.format == :html
6
- redirect_to action: :edit
7
- else
8
- show!
9
- end
50
+ redirect_to action: :edit
51
+ end
52
+
53
+ def new
54
+ self.resource = base_collection.new
55
+ end
56
+
57
+ def edit
10
58
  end
11
59
 
12
60
  def create
13
- create! { resource_redirect_path }
61
+ self.resource = base_collection.new(resource_params)
62
+ if resource.save
63
+ redirect_to resource_redirect_path, notice: t("flash.actions.create.notice", resource_name: resource_instance_name.capitalize)
64
+ else
65
+ render :new
66
+ end
14
67
  end
15
68
 
16
69
  def update
17
- update! { resource_redirect_path }
70
+ if resource.update(resource_params)
71
+ redirect_to resource_redirect_path, notice: t("flash.actions.update.notice", resource_name: resource_instance_name.capitalize)
72
+ else
73
+ render :edit
74
+ end
18
75
  end
19
76
 
20
77
  def destroy
21
- destroy! { resource_index_path }
78
+ if resource.destroy
79
+ redirect_to resource_index_path, notice: t("flash.actions.destroy.notice", resource_name: resource_instance_name.capitalize)
80
+ else
81
+ redirect_to resource_index_path, alert: t("flash.actions.destroy.alert", resource_name: resource_instance_name.capitalize)
82
+ end
22
83
  end
23
84
 
24
85
  private
25
86
 
87
+ def set_collection
88
+ self.collection = resource_class.all
89
+ end
90
+
91
+ def set_resource
92
+ self.resource = base_collection.find(params[:id])
93
+ end
94
+
95
+ def resource_params
96
+ params.require(resource_instance_name).permit!
97
+ end
98
+
99
+ def resource_index_path
100
+ [brightcontent, resource_class]
101
+ end
102
+
103
+ def resource_edit_path(res = resource)
104
+ [brightcontent, :edit, res]
105
+ end
106
+
26
107
  def resource_redirect_path
27
- if params["commit_and_continue"].present?
28
- resource_item_path
108
+ if params[:commit_and_continue].present?
109
+ resource_edit_path
29
110
  else
30
111
  resource_index_path
31
112
  end
32
113
  end
114
+
115
+ def resource_path(res = resource)
116
+ [brightcontent, res]
117
+ end
33
118
  end
34
119
  end
35
120
  end
@@ -10,11 +10,11 @@ module Brightcontent
10
10
  end
11
11
 
12
12
  def ransack_search
13
- @_ransack_search ||= end_of_association_chain.ransack(params[:q])
13
+ @_ransack_search ||= base_collection.ransack(params[:q])
14
14
  end
15
15
 
16
16
  def collection
17
- @_collection ||= ransack_search.result(distinct: true)
17
+ @_collection ||= ransack_search.result
18
18
  end
19
19
  end
20
20
  end
@@ -5,21 +5,70 @@ module Brightcontent
5
5
  module Pagination
6
6
  extend ActiveSupport::Concern
7
7
 
8
+ included do
9
+ helper_method :items_per_page
10
+ helper_method :current_page
11
+ helper_method :page_sizes
12
+ helper_method :corrected_page
13
+ helper_method :page_sizes_visible?
14
+ end
15
+
8
16
  module ClassMethods
9
17
  def per_page_count
10
- @per_page_count ||= 30
18
+ @page_size = page_sizes.min
11
19
  end
12
20
 
13
21
  def per_page(number)
14
- @per_page_count = number
22
+ @page_sizes = [number]
23
+ end
24
+
25
+ def page_size_options(sizes)
26
+ return unless sizes.is_a? Array
27
+ @page_sizes = sizes
28
+ end
29
+
30
+ def page_sizes
31
+ @page_sizes ||= [30]
15
32
  end
16
33
  end
17
34
 
18
35
  private
19
36
 
20
- def end_of_association_chain
21
- if action_name == "index" && self.class.per_page_count > 0
22
- super.paginate(page: params[:page], per_page: self.class.per_page_count)
37
+ def items_per_page
38
+ per_page = params[:per_page].try(:to_i)
39
+ @items_per_page =
40
+ if per_page && page_sizes.include?(per_page)
41
+ per_page.to_i
42
+ else
43
+ self.class.per_page_count
44
+ end
45
+ end
46
+
47
+ def page_sizes_visible?(collection)
48
+ total_entries = collection.count
49
+
50
+ if total_entries.respond_to?(:size) && !total_entries.is_a?(Integer)
51
+ total_entries = total_entries.size
52
+ end
53
+
54
+ page_sizes.length > 1 && total_entries > page_sizes.min
55
+ end
56
+
57
+ def current_page
58
+ params[:page].try(:to_i) || 1
59
+ end
60
+
61
+ def corrected_page(size)
62
+ (current_page - 1) * items_per_page / size + 1
63
+ end
64
+
65
+ def page_sizes
66
+ self.class.page_sizes
67
+ end
68
+
69
+ def collection
70
+ if action_name == "index" && items_per_page > 0
71
+ super.paginate(page: params[:page], per_page: items_per_page)
23
72
  else
24
73
  super
25
74
  end
@@ -5,7 +5,8 @@ ENV['RANSACK_FORM_BUILDER'] ||= '::SimpleForm::FormBuilder'
5
5
 
6
6
  require "bootstrap-sass"
7
7
  require "bootstrap-wysihtml5-rails"
8
- require "inherited_resources"
8
+ require "momentjs-rails"
9
+ require "bootstrap3-datetimepicker-rails"
9
10
  require "ransack"
10
11
  require "jquery-rails"
11
12
  require "simple_form"
@@ -106,7 +106,7 @@ module Brightcontent
106
106
  end
107
107
 
108
108
  def raw_collection
109
- resource_class.uniq.pluck(field_name)
109
+ resource_class.distinct.pluck(field_name)
110
110
  end
111
111
  end
112
112
  end
@@ -1,3 +1,21 @@
1
1
  class Brightcontent::CommentsController < Brightcontent::BaseController
2
- belongs_to :blog
2
+ def blog
3
+ Blog.find(params[:blog_id])
4
+ end
5
+
6
+ def base_collection
7
+ blog.comments
8
+ end
9
+
10
+ def resource_path(res = resource)
11
+ [brightcontent, blog, res]
12
+ end
13
+
14
+ def resource_index_path
15
+ [brightcontent, blog, resource_class]
16
+ end
17
+
18
+ def resource_edit_path(res = resource)
19
+ [brightcontent, :edit, blog, res]
20
+ end
3
21
  end
@@ -0,0 +1,5 @@
1
+ class Brightcontent::GroupedBlogsController < Brightcontent::BaseController
2
+ def collection
3
+ super.group(:author_id)
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class GroupedBlog < ActiveRecord::Base
2
+ belongs_to :author
3
+
4
+ scope :exclude_inactive, ->{ where(active: true) }
5
+
6
+ def self.ransackable_scopes(auth = nil)
7
+ [:exclude_inactive]
8
+ end
9
+ end
@@ -5,5 +5,7 @@ Rails.application.routes.draw do
5
5
  resources :blogs do
6
6
  resources :comments
7
7
  end
8
+
9
+ resources :grouped_blogs
8
10
  end
9
11
  end
@@ -0,0 +1,12 @@
1
+ class CreateGroupedBlogs < ActiveRecord::Migration
2
+ def change
3
+ create_table :grouped_blogs do |t|
4
+ t.string :name
5
+ t.text :body
6
+ t.boolean :active, default: true
7
+ t.column :author_id, :integer
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
data/spec/factories.rb CHANGED
@@ -19,6 +19,11 @@ FactoryGirl.define do
19
19
  end
20
20
  end
21
21
 
22
+ factory :grouped_blog do
23
+ name "Blogname"
24
+ body "Inhoud"
25
+ end
26
+
22
27
  factory :author do
23
28
  factory :author_with_blogs do
24
29
  transient do
@@ -27,6 +32,15 @@ FactoryGirl.define do
27
32
  after(:create) do |author, evaluator|
28
33
  create_list(:blog, evaluator.blogs_count, author: author)
29
34
  end
35
+
36
+ end
37
+ factory :author_with_grouped_blogs do
38
+ transient do
39
+ blogs_count 5
40
+ end
41
+ after(:create) do |author, evaluator|
42
+ create_list(:grouped_blog, evaluator.blogs_count, author: author)
43
+ end
30
44
  end
31
45
  end
32
46
 
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ feature "Grouped resources index" do
4
+ background do
5
+ sign_in
6
+ end
7
+
8
+ scenario "Visit the index view of resource" do
9
+ given_authors_with_blogs(authors: 3, blogs: 2)
10
+ given_page_sizes [2, 3]
11
+
12
+ visit_grouped_blogs_page
13
+
14
+ page_should_have_n_rows 2
15
+
16
+ # 2 numbered links and previous/next links
17
+ page.should have_css(".pagination.pages li", count: 4)
18
+ end
19
+
20
+ def visit_grouped_blogs_page
21
+ click_link "Grouped blogs"
22
+ end
23
+
24
+ def given_authors_with_blogs(authors: 2, blogs: 5)
25
+ authors.times do |num|
26
+ create(:author_with_grouped_blogs, blogs_count: blogs, name: "Blogger #{num}")
27
+ end
28
+ end
29
+
30
+ def given_page_sizes(sizes = [2, 6, 10])
31
+ Brightcontent::GroupedBlogsController.class_eval { page_size_options sizes }
32
+ end
33
+
34
+ def page_should_have_n_rows(n)
35
+ page.should have_css("tbody tr", :count => n)
36
+ end
37
+ end
@@ -66,6 +66,103 @@ feature "Resources index" do
66
66
  page_should_have_n_rows 1
67
67
  end
68
68
 
69
+ scenario "shows no page size options" do
70
+ given_blog_items
71
+ visit_blogs_page
72
+ page.should_not have_css(".pagination.page-sizes")
73
+ end
74
+
75
+ context "with adjustable pagination page size" do
76
+ scenario "shows pagination size options" do
77
+ given_page_sizes
78
+ given_blog_items
79
+ visit_blogs_page
80
+
81
+ page.should have_css(".pagination.page-sizes li", count: 3)
82
+ within ".pagination.page-sizes .active" do
83
+ page.should have_content "2"
84
+ end
85
+ end
86
+
87
+ scenario "shows 2 items" do
88
+ given_page_sizes
89
+ given_blog_items
90
+ visit_blogs_page
91
+ page_should_have_n_rows 2
92
+ end
93
+
94
+ scenario "can switch to different page size" do
95
+ given_page_sizes [3, 6, 9]
96
+ given_blog_items
97
+ visit_blogs_page
98
+ within ".pagination.page-sizes" do
99
+ click_link "6"
100
+ end
101
+
102
+ page_should_have_n_rows 6
103
+ end
104
+
105
+ scenario "adjusts active page to page size" do
106
+ given_page_sizes [2, 4, 8]
107
+ given_blog_items 16
108
+ visit_blogs_page
109
+
110
+ within ".pagination.pages" do
111
+ click_link "4"
112
+ end
113
+
114
+ within ".pagination.page-sizes" do
115
+ click_link "4"
116
+ end
117
+
118
+ within ".pagination.pages .active" do
119
+ page.should have_content "2"
120
+ end
121
+ end
122
+
123
+ scenario "retains page size after applying filter" do
124
+ given_page_sizes [2, 4, 8]
125
+ given_blog_items 9
126
+ visit_blogs_page
127
+ within ".pagination.page-sizes" do
128
+ click_link "4"
129
+ end
130
+
131
+ fill_in "Name", with: "Blog"
132
+ click_button "Search"
133
+
134
+ within ".pagination.page-sizes .active" do
135
+ page.should have_content "4"
136
+ end
137
+ end
138
+
139
+ scenario "retains filter after applying page size" do
140
+ given_page_sizes [2, 4, 8]
141
+ given_blog_items 14
142
+ visit_blogs_page
143
+ fill_in "Name", with: "Blog 1"
144
+ click_button "Search"
145
+
146
+ # 3 numbered links and previous/next links
147
+ page.should have_css(".pagination.pages li", count: 5)
148
+
149
+ within ".pagination.page-sizes" do
150
+ click_link "4"
151
+ end
152
+
153
+ # 2 numbered links and previous/next links
154
+ page.should have_css(".pagination.pages li", count: 4)
155
+ end
156
+
157
+ scenario "hides page size options when there is only a single page" do
158
+ given_page_sizes [5, 6, 7]
159
+ given_blog_items 4
160
+ visit_blogs_page
161
+
162
+ page.should_not have_css(".pagination.page-sizes")
163
+ end
164
+ end
165
+
69
166
  def visit_blogs_page
70
167
  click_link "Blogs"
71
168
  end
@@ -112,4 +209,12 @@ feature "Resources index" do
112
209
  create :blog, name: "Foo", active: false
113
210
  create :blog, name: "Bar", active: true
114
211
  end
212
+
213
+ def given_page_sizes(sizes = [2, 6, 10])
214
+ Brightcontent::BlogsController.class_eval { page_size_options sizes }
215
+ end
216
+
217
+ def given_blog_items(num = 10)
218
+ num.times { |num| create [:blog, :featured_blog].sample, name: "Blog #{num}" }
219
+ end
115
220
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brightcontent-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.4
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Developers at Brightin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-14 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -67,19 +67,33 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.3.2
69
69
  - !ruby/object:Gem::Dependency
70
- name: inherited_resources
70
+ name: momentjs-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.6.0
75
+ version: 2.5.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.5.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bootstrap3-datetimepicker-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 1.6.0
96
+ version: 3.0.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: jquery-rails
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -269,7 +283,6 @@ extensions: []
269
283
  extra_rdoc_files: []
270
284
  files:
271
285
  - ".gitignore"
272
- - Gemfile
273
286
  - Rakefile
274
287
  - app/assets/javascripts/brightcontent/brightcontent.js.erb
275
288
  - app/assets/javascripts/brightcontent/core.js
@@ -296,8 +309,11 @@ files:
296
309
  - app/views/brightcontent/base/_list_filters.html.erb
297
310
  - app/views/brightcontent/base/_list_header.html.erb
298
311
  - app/views/brightcontent/base/_list_item.html.erb
312
+ - app/views/brightcontent/base/_page_sizes.html.erb
299
313
  - app/views/brightcontent/base/edit.html.erb
300
314
  - app/views/brightcontent/base/form_fields/_belongs_to.html.erb
315
+ - app/views/brightcontent/base/form_fields/_date.html.erb
316
+ - app/views/brightcontent/base/form_fields/_datetime.html.erb
301
317
  - app/views/brightcontent/base/form_fields/_file.html.erb
302
318
  - app/views/brightcontent/base/form_fields/_has_and_belongs_to_many.html.erb
303
319
  - app/views/brightcontent/base/form_fields/_has_many.html.erb
@@ -350,6 +366,7 @@ files:
350
366
  - spec/dummy/app/controllers/application_controller.rb
351
367
  - spec/dummy/app/controllers/brightcontent/blogs_controller.rb
352
368
  - spec/dummy/app/controllers/brightcontent/comments_controller.rb
369
+ - spec/dummy/app/controllers/brightcontent/grouped_blogs_controller.rb
353
370
  - spec/dummy/app/controllers/pages_controller.rb
354
371
  - spec/dummy/app/helpers/application_helper.rb
355
372
  - spec/dummy/app/mailers/.gitkeep
@@ -357,6 +374,7 @@ files:
357
374
  - spec/dummy/app/models/author.rb
358
375
  - spec/dummy/app/models/blog.rb
359
376
  - spec/dummy/app/models/comment.rb
377
+ - spec/dummy/app/models/grouped_blog.rb
360
378
  - spec/dummy/app/views/layouts/application.html.erb
361
379
  - spec/dummy/app/views/pages/index.html.erb
362
380
  - spec/dummy/config.ru
@@ -383,6 +401,7 @@ files:
383
401
  - spec/dummy/db/migrate/20140512085432_add_author_id_to_blogs.rb
384
402
  - spec/dummy/db/migrate/20140512090832_create_authors.rb
385
403
  - spec/dummy/db/migrate/20150219130156_add_active_to_blogs.rb
404
+ - spec/dummy/db/migrate/20160623142310_create_grouped_blogs.rb
386
405
  - spec/dummy/lib/assets/.gitkeep
387
406
  - spec/dummy/public/404.html
388
407
  - spec/dummy/public/422.html
@@ -393,6 +412,7 @@ files:
393
412
  - spec/dummy/test/unit/comments_test.rb
394
413
  - spec/factories.rb
395
414
  - spec/features/export_spec.rb
415
+ - spec/features/grouped_resources_index_spec.rb
396
416
  - spec/features/login_spec.rb
397
417
  - spec/features/menu_spec.rb
398
418
  - spec/features/nested_resource_spec.rb
@@ -425,7 +445,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
425
445
  version: '0'
426
446
  requirements: []
427
447
  rubyforge_project:
428
- rubygems_version: 2.5.1
448
+ rubygems_version: 2.6.6
429
449
  signing_key:
430
450
  specification_version: 4
431
451
  summary: Brightcontent core
@@ -439,6 +459,7 @@ test_files:
439
459
  - spec/dummy/app/controllers/application_controller.rb
440
460
  - spec/dummy/app/controllers/brightcontent/blogs_controller.rb
441
461
  - spec/dummy/app/controllers/brightcontent/comments_controller.rb
462
+ - spec/dummy/app/controllers/brightcontent/grouped_blogs_controller.rb
442
463
  - spec/dummy/app/controllers/pages_controller.rb
443
464
  - spec/dummy/app/helpers/application_helper.rb
444
465
  - spec/dummy/app/mailers/.gitkeep
@@ -446,6 +467,7 @@ test_files:
446
467
  - spec/dummy/app/models/author.rb
447
468
  - spec/dummy/app/models/blog.rb
448
469
  - spec/dummy/app/models/comment.rb
470
+ - spec/dummy/app/models/grouped_blog.rb
449
471
  - spec/dummy/app/views/layouts/application.html.erb
450
472
  - spec/dummy/app/views/pages/index.html.erb
451
473
  - spec/dummy/config.ru
@@ -472,6 +494,7 @@ test_files:
472
494
  - spec/dummy/db/migrate/20140512085432_add_author_id_to_blogs.rb
473
495
  - spec/dummy/db/migrate/20140512090832_create_authors.rb
474
496
  - spec/dummy/db/migrate/20150219130156_add_active_to_blogs.rb
497
+ - spec/dummy/db/migrate/20160623142310_create_grouped_blogs.rb
475
498
  - spec/dummy/lib/assets/.gitkeep
476
499
  - spec/dummy/public/404.html
477
500
  - spec/dummy/public/422.html
@@ -482,6 +505,7 @@ test_files:
482
505
  - spec/dummy/test/unit/comments_test.rb
483
506
  - spec/factories.rb
484
507
  - spec/features/export_spec.rb
508
+ - spec/features/grouped_resources_index_spec.rb
485
509
  - spec/features/login_spec.rb
486
510
  - spec/features/menu_spec.rb
487
511
  - spec/features/nested_resource_spec.rb
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec