brightcontent-core 2.1.5 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -15
- data/app/controllers/brightcontent/sessions_controller.rb +2 -0
- data/app/helpers/brightcontent/base_helper.rb +16 -2
- data/app/views/brightcontent/base/_list_filters.html.erb +2 -4
- data/brightcontent-core.gemspec +3 -3
- data/lib/brightcontent/core.rb +5 -0
- data/lib/brightcontent/view_lookup/base.rb +1 -1
- data/lib/brightcontent/view_lookup/filter_field.rb +84 -16
- data/spec/dummy/app/controllers/brightcontent/blogs_controller.rb +1 -1
- data/spec/dummy/app/models/author.rb +0 -4
- data/spec/dummy/app/models/blog.rb +6 -0
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/environments/test.rb +1 -1
- data/spec/dummy/db/migrate/20150219130156_add_active_to_blogs.rb +5 -0
- data/spec/factories.rb +5 -0
- data/spec/features/resources_index_spec.rb +41 -0
- data/spec/lib/brightcontent/model_extensions_spec.rb +1 -1
- metadata +17 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca3785050aa8c2db2a8007bb9a8a648b0f6cb13b
|
4
|
+
data.tar.gz: e8e2b8ffa1d5f558461b91b095b442bb6f9d860c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e29b0764abbb6d0032b59b0884a1555964db4fb686745febb4ffff0319c8b9afc1612f976dd939988f25f8ac2cbdb96b3ef7f74195135519cc3c2f9e4abd3614
|
7
|
+
data.tar.gz: 4537fa305e9fde2652e29e51ea08e0a4e2e2816d6c74e17fb5d5e9f6984cc1920952cdd7231589ddc8080eb59f5eaa61719b9989716c3aa508949ecebe98b4e9
|
data/Gemfile
CHANGED
@@ -1,17 +1,3 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
|
-
# Declare your gem's dependencies in brightcontent.gemspec.
|
4
|
-
# Bundler will treat runtime dependencies like base dependencies, and
|
5
|
-
# development dependencies will be added by default to the :development group.
|
6
3
|
gemspec
|
7
|
-
|
8
|
-
# jquery-rails is used by the dummy application
|
9
|
-
# gem "jquery-rails"
|
10
|
-
|
11
|
-
# Declare any dependencies that are still in development here instead of in
|
12
|
-
# your gemspec. These might include edge Rails or gems from your path or
|
13
|
-
# Git. Remember to move these dependencies to your gemspec before releasing
|
14
|
-
# your gem to rubygems.org.
|
15
|
-
|
16
|
-
# To use debugger
|
17
|
-
# gem 'debugger'
|
@@ -4,8 +4,8 @@ module Brightcontent
|
|
4
4
|
ViewLookup::ListField.new(self, item: item, field: field).call
|
5
5
|
end
|
6
6
|
|
7
|
-
def render_filter_field(form, field)
|
8
|
-
ViewLookup::FilterField.new(self, field: field, form: form).call
|
7
|
+
def render_filter_field(form, field, options)
|
8
|
+
ViewLookup::FilterField.new(self, field: field, form: form, options: options).call
|
9
9
|
end
|
10
10
|
|
11
11
|
def render_form_field(form, field)
|
@@ -17,5 +17,19 @@ module Brightcontent
|
|
17
17
|
rescue ActionView::MissingTemplate
|
18
18
|
nil
|
19
19
|
end
|
20
|
+
|
21
|
+
# Returns filter field definitions as a nested array.
|
22
|
+
#
|
23
|
+
# [:foo, { bar: { as: :select }, qux: { as: :string } }]
|
24
|
+
#
|
25
|
+
# Becomes:
|
26
|
+
#
|
27
|
+
# [[:foo], [:bar, { as: :select }], [:qux, { as: :string }]]
|
28
|
+
#
|
29
|
+
def normalized_filter_fields
|
30
|
+
filter_fields.flat_map do |field|
|
31
|
+
field.is_a?(Hash) ? field.to_a : [[field]]
|
32
|
+
end
|
33
|
+
end
|
20
34
|
end
|
21
35
|
end
|
@@ -1,10 +1,8 @@
|
|
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
|
-
<%
|
5
|
-
|
6
|
-
<%= render_filter_field form, field %>
|
7
|
-
</div>
|
4
|
+
<% normalized_filter_fields.each do |field, options| %>
|
5
|
+
<%= render_filter_field form, field, options %>
|
8
6
|
<% end %>
|
9
7
|
<%= form.submit class: "btn btn-default btn-sm" %>
|
10
8
|
<% end %>
|
data/brightcontent-core.gemspec
CHANGED
@@ -15,18 +15,18 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
|
18
|
-
s.add_dependency "rails", ">= 4.
|
18
|
+
s.add_dependency "rails", ">= 4.2.0"
|
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
23
|
s.add_dependency "coffee-rails"
|
23
|
-
s.add_dependency "inherited_resources", "~> 1.4.1"
|
24
24
|
s.add_dependency "jquery-rails"
|
25
25
|
s.add_dependency "sass-rails", ">= 4.0.2"
|
26
26
|
s.add_dependency "simple_form"
|
27
27
|
s.add_dependency "will_paginate"
|
28
28
|
s.add_dependency "will_paginate-bootstrap"
|
29
|
-
s.add_dependency "ransack", "
|
29
|
+
s.add_dependency "ransack", ">= 1.1"
|
30
30
|
|
31
31
|
s.add_development_dependency "rake"
|
32
32
|
s.add_development_dependency "sqlite3"
|
data/lib/brightcontent/core.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# Make SimpleForm helpers available in Ransack's search form:
|
2
|
+
# https://github.com/activerecord-hackery/ransack#using-simpleform
|
3
|
+
#
|
4
|
+
ENV['RANSACK_FORM_BUILDER'] ||= '::SimpleForm::FormBuilder'
|
5
|
+
|
1
6
|
require "coffee_script"
|
2
7
|
require "bootstrap-sass"
|
3
8
|
require "bootstrap-wysihtml5-rails"
|
@@ -2,42 +2,110 @@ module Brightcontent
|
|
2
2
|
module ViewLookup
|
3
3
|
class FilterField < Base
|
4
4
|
def render_default
|
5
|
-
|
6
|
-
[
|
7
|
-
options[:form].label(:"#{field_name}_eq", options[:field].humanize),
|
8
|
-
options[:form].select(:"#{field_name}_eq", select_options, {include_blank: true}, class: "form-control input-sm")
|
9
|
-
].join(" ").html_safe
|
5
|
+
options[:form].input(input_name, input_options.merge(collection: collection))
|
10
6
|
end
|
11
7
|
|
12
8
|
private
|
13
9
|
|
14
|
-
def
|
10
|
+
def controller
|
11
|
+
view_context.controller
|
12
|
+
end
|
13
|
+
|
14
|
+
def column?
|
15
15
|
resource_class.column_names.include? options[:field].to_s
|
16
16
|
end
|
17
17
|
|
18
|
+
def scope?
|
19
|
+
resource_class.ransackable_scopes.include?(options[:field].to_sym)
|
20
|
+
end
|
21
|
+
|
18
22
|
def belongs_to_association?
|
19
23
|
association.try :belongs_to?
|
20
24
|
end
|
21
25
|
|
22
26
|
def field_name
|
23
|
-
if
|
24
|
-
options[:field]
|
25
|
-
elsif belongs_to_association?
|
27
|
+
if belongs_to_association?
|
26
28
|
association.foreign_key
|
29
|
+
else
|
30
|
+
options[:field]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def input_name
|
35
|
+
if predicate
|
36
|
+
"#{field_name}_#{predicate}"
|
37
|
+
else
|
38
|
+
field_name.to_s
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
42
|
+
def filter_options
|
43
|
+
options[:options] || {}
|
44
|
+
end
|
45
|
+
|
46
|
+
def predicate
|
47
|
+
filter_options.fetch(:predicate) { default_predicate }
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_predicate
|
51
|
+
if scope?
|
52
|
+
false
|
53
|
+
elsif as_string?
|
54
|
+
"cont"
|
55
|
+
else
|
56
|
+
"eq"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def input_options
|
61
|
+
default_input_options.merge(filter_options.except(:predicate))
|
62
|
+
end
|
63
|
+
|
64
|
+
def collection
|
65
|
+
collection = filter_options[:collection]
|
66
|
+
|
67
|
+
if collection.respond_to?(:call)
|
68
|
+
collection.call
|
69
|
+
elsif collection.is_a?(Symbol) && controller.respond_to?(collection, true)
|
70
|
+
controller.send(collection)
|
71
|
+
elsif collection
|
72
|
+
collection
|
73
|
+
elsif as_collection?
|
74
|
+
default_collection
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def as_collection?
|
79
|
+
%i(select radio_buttons check_boxes).include?(input_options[:as].to_sym)
|
80
|
+
end
|
81
|
+
|
82
|
+
def as_string?
|
83
|
+
%i(string search).include?(input_options[:as].to_sym)
|
84
|
+
end
|
85
|
+
|
86
|
+
def default_input_options
|
87
|
+
{
|
88
|
+
label: options[:field].to_s.humanize,
|
89
|
+
input_html: { class: "form-control input-sm" },
|
90
|
+
required: false,
|
91
|
+
as: default_type,
|
92
|
+
include_blank: true
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def default_type
|
97
|
+
(column? || belongs_to_association?) ? :select : :string
|
98
|
+
end
|
99
|
+
|
100
|
+
def default_collection
|
101
|
+
if column?
|
102
|
+
field_type == :boolean ? raw_collection : raw_collection.sort
|
33
103
|
elsif belongs_to_association?
|
34
|
-
association.klass.where(association.association_primary_key =>
|
35
|
-
[record, record[association.association_primary_key]]
|
36
|
-
end
|
104
|
+
association.klass.where(association.association_primary_key => raw_collection)
|
37
105
|
end
|
38
106
|
end
|
39
107
|
|
40
|
-
def
|
108
|
+
def raw_collection
|
41
109
|
resource_class.uniq.pluck(field_name)
|
42
110
|
end
|
43
111
|
end
|
@@ -47,6 +47,7 @@ module Dummy
|
|
47
47
|
config.assets.enabled = true
|
48
48
|
|
49
49
|
# config.i18n.enforce_available_locales = true
|
50
|
+
config.active_record.raise_in_transactional_callbacks = true
|
50
51
|
|
51
52
|
# Version of your assets, change this if you want to expire all your assets
|
52
53
|
config.assets.version = '1.0'
|
@@ -9,7 +9,7 @@ Dummy::Application.configure do
|
|
9
9
|
config.action_controller.perform_caching = true
|
10
10
|
|
11
11
|
# Disable Rails's static asset server (Apache or nginx will already do this)
|
12
|
-
config.
|
12
|
+
config.serve_static_files = false
|
13
13
|
|
14
14
|
# Compress JavaScripts and CSS
|
15
15
|
config.assets.compress = true
|
@@ -10,7 +10,7 @@ Dummy::Application.configure do
|
|
10
10
|
config.cache_classes = true
|
11
11
|
|
12
12
|
# Configure static asset server for tests with Cache-Control for performance
|
13
|
-
config.
|
13
|
+
config.serve_static_files = true
|
14
14
|
config.static_cache_control = "public, max-age=3600"
|
15
15
|
|
16
16
|
# Show full error reports and disable caching
|
data/spec/factories.rb
CHANGED
@@ -41,6 +41,31 @@ feature "Resources index" do
|
|
41
41
|
page_should_have_n_rows 9
|
42
42
|
end
|
43
43
|
|
44
|
+
scenario "Filter by name" do
|
45
|
+
given_2_blog_items_with_different_names
|
46
|
+
visit_blogs_page
|
47
|
+
fill_in "Name", with: "oo"
|
48
|
+
click_button "Search"
|
49
|
+
page_should_have_n_rows 1
|
50
|
+
end
|
51
|
+
|
52
|
+
scenario "Filter by name or comments text" do
|
53
|
+
given_3_blog_items_and_a_comment
|
54
|
+
visit_blogs_page
|
55
|
+
fill_in "Find", with: "oo"
|
56
|
+
click_button "Search"
|
57
|
+
page_should_have_n_rows 2
|
58
|
+
end
|
59
|
+
|
60
|
+
scenario "Filter by exclude_inactive scope" do
|
61
|
+
given_an_active_and_inactive_blog
|
62
|
+
visit_blogs_page
|
63
|
+
page_should_have_n_rows 2
|
64
|
+
check "Exclude inactive"
|
65
|
+
click_button "Search"
|
66
|
+
page_should_have_n_rows 1
|
67
|
+
end
|
68
|
+
|
44
69
|
def visit_blogs_page
|
45
70
|
click_link "Blogs"
|
46
71
|
end
|
@@ -71,4 +96,20 @@ feature "Resources index" do
|
|
71
96
|
def given_10_per_page
|
72
97
|
Brightcontent::BlogsController.class_eval { per_page 10 }
|
73
98
|
end
|
99
|
+
|
100
|
+
def given_2_blog_items_with_different_names
|
101
|
+
create :blog, name: "Foo"
|
102
|
+
create :blog, name: "Bar"
|
103
|
+
end
|
104
|
+
|
105
|
+
def given_3_blog_items_and_a_comment
|
106
|
+
create :blog, name: "Foo"
|
107
|
+
create :blog, name: "Bar"
|
108
|
+
create :comment, text: "Doodles"
|
109
|
+
end
|
110
|
+
|
111
|
+
def given_an_active_and_inactive_blog
|
112
|
+
create :blog, name: "Foo", active: false
|
113
|
+
create :blog, name: "Bar", active: true
|
114
|
+
end
|
74
115
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Brightcontent
|
4
4
|
describe ModelExtensions do
|
5
|
-
let(:columns) { ["id", "name", "body", "created_at", "updated_at", "featured", "author_id"] }
|
5
|
+
let(:columns) { ["id", "name", "body", "created_at", "updated_at", "featured", "author_id", "active"] }
|
6
6
|
subject(:blog) { Blog }
|
7
7
|
its(:brightcontent_columns) { should eq columns }
|
8
8
|
|
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.
|
4
|
+
version: 2.2.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:
|
11
|
+
date: 2015-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: 4.2.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.
|
26
|
+
version: 4.2.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bcrypt
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,33 +67,33 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.3.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: inherited_resources
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.6.0
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.6.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: coffee-rails
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: jquery-rails
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,14 +168,14 @@ dependencies:
|
|
168
168
|
name: ransack
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
170
170
|
requirements:
|
171
|
-
- - "
|
171
|
+
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '1.1'
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
|
-
- - "
|
178
|
+
- - ">="
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '1.1'
|
181
181
|
- !ruby/object:Gem::Dependency
|
@@ -396,6 +396,7 @@ files:
|
|
396
396
|
- spec/dummy/db/migrate/20130720211920_create_comments.rb
|
397
397
|
- spec/dummy/db/migrate/20140512085432_add_author_id_to_blogs.rb
|
398
398
|
- spec/dummy/db/migrate/20140512090832_create_authors.rb
|
399
|
+
- spec/dummy/db/migrate/20150219130156_add_active_to_blogs.rb
|
399
400
|
- spec/dummy/lib/assets/.gitkeep
|
400
401
|
- spec/dummy/public/404.html
|
401
402
|
- spec/dummy/public/422.html
|
@@ -438,7 +439,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
438
439
|
version: '0'
|
439
440
|
requirements: []
|
440
441
|
rubyforge_project:
|
441
|
-
rubygems_version: 2.
|
442
|
+
rubygems_version: 2.4.5
|
442
443
|
signing_key:
|
443
444
|
specification_version: 4
|
444
445
|
summary: Brightcontent core
|
@@ -484,6 +485,7 @@ test_files:
|
|
484
485
|
- spec/dummy/db/migrate/20130720211920_create_comments.rb
|
485
486
|
- spec/dummy/db/migrate/20140512085432_add_author_id_to_blogs.rb
|
486
487
|
- spec/dummy/db/migrate/20140512090832_create_authors.rb
|
488
|
+
- spec/dummy/db/migrate/20150219130156_add_active_to_blogs.rb
|
487
489
|
- spec/dummy/lib/assets/.gitkeep
|
488
490
|
- spec/dummy/public/404.html
|
489
491
|
- spec/dummy/public/422.html
|