adminos 1.0.0.pre.rc.2 → 1.0.0.pre.rc.3
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -3
- data/README.md +26 -0
- data/adminos.gemspec +2 -2
- data/app/inputs/cropp_input.rb +13 -1
- data/app/inputs/filter_inputs/boolean_input.rb +18 -0
- data/app/inputs/filter_inputs/date_range_input.rb +36 -0
- data/app/inputs/filter_inputs/numeric_input.rb +40 -0
- data/app/inputs/filter_inputs/string_input.rb +40 -0
- data/lib/adminos.rb +23 -3
- data/lib/adminos/configuration.rb +9 -0
- data/lib/adminos/controllers/filters.rb +20 -0
- data/lib/adminos/controllers/resource.rb +18 -11
- data/lib/adminos/extensions/simple_form.rb +12 -0
- data/lib/adminos/features/search/elastic.rb +46 -0
- data/lib/adminos/features/search/pg_search.rb +49 -0
- data/lib/adminos/filters/forms.rb +55 -0
- data/lib/adminos/form_builder.rb +11 -0
- data/lib/adminos/helpers/models/searchable.rb +9 -0
- data/lib/adminos/helpers/view.rb +35 -0
- data/lib/generators/adminos/adminos_generator.rb +10 -7
- data/lib/generators/adminos/feedback_generator.rb +39 -0
- data/lib/generators/adminos/i18n_generator.rb +16 -4
- data/lib/generators/adminos/install_generator.rb +22 -0
- data/lib/generators/adminos/profile_generator.rb +34 -0
- data/lib/generators/adminos/search_generator.rb +38 -0
- data/lib/generators/adminos/two_factor_auth_generator.rb +81 -0
- data/lib/generators/templates/adminos/fields.slim +1 -1
- data/lib/generators/templates/adminos/locales/locale_fields.slim +7 -4
- data/lib/generators/templates/adminos/locales/model.rb.erb +2 -3
- data/lib/generators/templates/ci/.gitlab-ci.yml +1 -1
- data/lib/generators/templates/feedback/auto/app/controllers/admin/feedbacks_controller.rb +17 -0
- data/lib/generators/templates/feedback/auto/app/controllers/feedbacks_controller.rb +11 -0
- data/lib/generators/templates/feedback/auto/app/models/feedback.rb +6 -0
- data/lib/generators/templates/feedback/auto/app/views/admin/feedbacks/_fields.slim +5 -0
- data/lib/generators/templates/feedback/auto/app/views/admin/feedbacks/index.slim +28 -0
- data/lib/generators/templates/feedback/feedbacks_migration.rb +13 -0
- data/lib/generators/templates/field/locales/locale_fields.slim +1 -1
- data/lib/generators/templates/field/locales/model.rb.erb +2 -3
- data/lib/generators/templates/i18n/Gemfile +6 -1
- data/lib/generators/templates/i18n/auto/app/validators/locale_validator.rb +5 -1
- data/lib/generators/templates/i18n/auto/app/views/admin/base/_pills.slim +1 -5
- data/lib/generators/templates/i18n/auto/app/views/admin/pages/_locale_fields.slim +5 -5
- data/lib/generators/templates/i18n/auto/config/initializers/mobility.rb +92 -0
- data/lib/generators/templates/i18n/page.rb +2 -2
- data/lib/generators/templates/install/Gemfile +3 -5
- data/lib/generators/templates/install/README.md +22 -0
- data/lib/generators/templates/install/auto/Capfile +12 -2
- data/lib/generators/templates/install/auto/app/views/admin/base/_form.slim +1 -1
- data/lib/generators/templates/install/auto/app/views/shared/helpers/admin/_collection_header.slim +2 -0
- data/lib/generators/templates/install/auto/app/views/shared/helpers/admin/_object_link_new.slim +1 -1
- data/lib/generators/templates/install/auto/config/deploy/staging.rb +15 -10
- data/lib/generators/templates/install/auto/config/deploy/{shared → templates}/database.yml.erb +1 -1
- data/lib/generators/templates/install/auto/config/deploy/templates/nginx_conf.erb +96 -0
- data/lib/generators/templates/install/auto/config/deploy/templates/puma.rb.erb +52 -0
- data/lib/generators/templates/install/auto/config/environments/staging.rb +1 -1
- data/lib/generators/templates/install/auto/config/initializers/adminos.rb +3 -0
- data/lib/generators/templates/install/auto/config/locales/adminos.ru.yml +18 -0
- data/lib/generators/templates/install/auto/config/schedule.rb +0 -0
- data/lib/generators/templates/install/auto/config/systemd/puma.service.erb +19 -0
- data/lib/generators/templates/install/auto/config/systemd/sidekiq.service.erb +21 -0
- data/lib/generators/templates/install/auto/lib/capistrano/{template.rb → smart_templates.rb} +17 -3
- data/lib/generators/templates/install/auto/lib/capistrano/tasks/setup_config.cap +27 -20
- data/lib/generators/templates/install/deploy.rb.erb +13 -12
- data/lib/generators/templates/profile/auto/app/controllers/admin/profiles_controller.rb +26 -0
- data/lib/generators/templates/profile/auto/app/views/admin/profiles/edit.slim +17 -0
- data/lib/generators/templates/two_facto_auth/Gemfile +1 -0
- data/lib/generators/templates/two_facto_auth/auto/app/controllers/concerns/authenticates_with_two_factor.rb +36 -0
- data/lib/generators/templates/two_facto_auth/auto/app/controllers/users/sessions_controller.rb +5 -0
- data/lib/generators/templates/two_facto_auth/auto/app/views/admin/profiles/_2fa.slim +24 -0
- data/lib/generators/templates/two_facto_auth/auto/app/views/devise/sessions/two_factor.slim +15 -0
- data/spec/lib/generators/adminos/feedback_generator_rspec.rb +50 -0
- data/spec/lib/generators/adminos/install_generator_rspec.rb +6 -7
- data/spec/lib/generators/adminos/profile_generator_rspec.rb +33 -0
- data/spec/lib/generators/adminos/search_generator.rb +20 -0
- data/spec/lib/generators/adminos/two_factor_auth_generator_rspec.rb +61 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/shared/generator.rb +1 -1
- metadata +55 -22
- data/bin/rspec +0 -29
- data/lib/adminos/extensions/globalize_actiontext.rb +0 -28
- data/lib/adminos/extensions/globalize_fields.rb +0 -19
- data/lib/generators/templates/adminos/locales/migration.rb.erb +0 -18
- data/lib/generators/templates/field/locales/migration.rb.erb +0 -13
- data/lib/generators/templates/i18n/add_translation_table_to_page.rb +0 -15
- data/lib/generators/templates/i18n/auto/config/initializers/globalize_fields.rb +0 -1
- data/lib/generators/templates/install/auto/config/deploy/shared/nginx.conf.erb +0 -28
- data/lib/generators/templates/install/auto/config/deploy/shared/unicorn.rb.erb +0 -35
- data/lib/generators/templates/install/auto/lib/capistrano/substitute_strings.rb +0 -12
- data/package-lock.json +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b5e4c3f3ca3f62630cea3a1f944cdbfc825974f295b1e056ad9e27fc571b59f
|
|
4
|
+
data.tar.gz: 58829a898a9194f9d3836e5743716f581e0be4cd61c7425da5942b3ffa94d461
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c2fbcdb16cc34d96aa89f42e1b8bc8d15bebacfcbdbd88821560317f6682f694baa360597f3b1f3858b277d2e5b2c59415aa33722fc9e6218ff7dce3d10fc728
|
|
7
|
+
data.tar.gz: c7b3733876ea14ee809f01b64d94781c8f239830f4261ea3cc83d096f5e0ca7eefd84ca6ea1a43fd04eeb9ff4d4d60fa039141954cd44141ad8d3cfb148a6a17
|
data/Gemfile
CHANGED
|
@@ -18,8 +18,7 @@ group :development do
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
gem 'guard-minitest', '~> 2.4'
|
|
21
|
-
gem 'globalize'
|
|
22
21
|
gem 'friendly_id'
|
|
23
22
|
gem 'activerecord-nulldb-adapter', git: 'git://github.com/nulldb/nulldb.git'
|
|
24
|
-
gem 'sqlite3'
|
|
25
|
-
gem 'database_cleaner'
|
|
23
|
+
gem 'sqlite3', '~> 1.3.6'
|
|
24
|
+
gem 'database_cleaner'
|
data/README.md
CHANGED
|
@@ -51,6 +51,32 @@ If no need in SEO fields, switch it off using `--no-seo`.
|
|
|
51
51
|
$ rails g adminos Model --no-seo
|
|
52
52
|
|
|
53
53
|
## Features
|
|
54
|
+
### Filters
|
|
55
|
+
|
|
56
|
+
To add filtering by any attributes you need to add the required filters in the controller. Below is an example.
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
class Admin::ProductsController < Admin::BaseController
|
|
60
|
+
add_filter :name
|
|
61
|
+
add_filter :price
|
|
62
|
+
add_filter :published
|
|
63
|
+
|
|
64
|
+
#some code
|
|
65
|
+
end
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Search
|
|
69
|
+
|
|
70
|
+
By default, search is enabled only on user models.
|
|
71
|
+
|
|
72
|
+
To add a search, run the following generator.
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
rails generate adminos:search ModelName
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
You can use search engines such as ElasticSearch or PgSearch. By default, PgSearch is used if you did not specify the --search = elastic flag when installing adminos.
|
|
79
|
+
|
|
54
80
|
### Cropped
|
|
55
81
|
model
|
|
56
82
|
```ruby
|
data/adminos.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |gem|
|
|
2
2
|
gem.name = 'adminos'
|
|
3
|
-
gem.version = '1.0.0-rc.
|
|
3
|
+
gem.version = '1.0.0-rc.3'
|
|
4
4
|
gem.authors = ['RavWar', 'milushov', 'abuhtoyarov', 'SiebenSieben']
|
|
5
5
|
gem.email = ['studio@molinos.ru']
|
|
6
6
|
gem.homepage = 'https://gitlab.molinos.ru/global/adminos'
|
|
@@ -22,11 +22,11 @@ Gem::Specification.new do |gem|
|
|
|
22
22
|
gem.add_dependency 'babosa'
|
|
23
23
|
gem.add_dependency 'simple_form'
|
|
24
24
|
gem.add_dependency 'kaminari'
|
|
25
|
-
gem.add_dependency 'russian'
|
|
26
25
|
gem.add_dependency 'devise'
|
|
27
26
|
gem.add_dependency 'cancancan'
|
|
28
27
|
gem.add_dependency 'cocoon'
|
|
29
28
|
gem.add_dependency 'awesome_nested_set'
|
|
29
|
+
gem.add_dependency 'ransack'
|
|
30
30
|
|
|
31
31
|
gem.add_development_dependency 'bundler', '~> 1.3'
|
|
32
32
|
gem.add_development_dependency 'm'
|
data/app/inputs/cropp_input.rb
CHANGED
|
@@ -23,13 +23,25 @@ class CroppInput < SimpleForm::Inputs::Base
|
|
|
23
23
|
|
|
24
24
|
aspect_ratio = input_html_options.delete(:aspect_ratio) || '16/9'
|
|
25
25
|
aspect_ratio = aspect_ratio.split('/').map(&:to_f)
|
|
26
|
-
aspect_ratio = aspect_ratio[0]/aspect_ratio[1]
|
|
26
|
+
aspect_ratio = aspect_ratio[0] / aspect_ratio[1]
|
|
27
27
|
|
|
28
28
|
out << %{<div class="row"><div class="col-md-8"><div class="img-container">}
|
|
29
29
|
|
|
30
30
|
out << template.image_tag(object.send(attribute_name), data: { aspect_ratio: aspect_ratio, preview: ".#{@version}_#{attribute_name}_preview", toggle: 'cropp', coord: @coord_attribute })
|
|
31
31
|
|
|
32
32
|
out << %{</div></div><div class="col-md-4">}
|
|
33
|
+
out << %{<div class="cropper-dimensions">}
|
|
34
|
+
out << %{<div class="field">}
|
|
35
|
+
out << template.label_tag(:width, 'Ширина', class: 'control-label')
|
|
36
|
+
out << template.number_field_tag(:width, nil, class: 'form-control')
|
|
37
|
+
out << %{</div>}
|
|
38
|
+
out << %{<div class="field">}
|
|
39
|
+
|
|
40
|
+
out << template.label_tag(:height, 'Высота', class: 'control-label')
|
|
41
|
+
out << template.number_field_tag(:height, nil, class: 'form-control')
|
|
42
|
+
out << %{</div>}
|
|
43
|
+
|
|
44
|
+
out << %{</div>}
|
|
33
45
|
out << %{<div class="docs-preview clearfix">}
|
|
34
46
|
out << %{<div class="img-preview preview-lg #{@version}_#{attribute_name}_preview"></div>}
|
|
35
47
|
out << cropped
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module FilterInputs
|
|
2
|
+
class BooleanInput < SimpleForm::Inputs::CollectionSelectInput
|
|
3
|
+
def input(wrapper_options = nil)
|
|
4
|
+
label_method, value_method = detect_collection_methods
|
|
5
|
+
|
|
6
|
+
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
|
|
7
|
+
|
|
8
|
+
@builder.collection_select(
|
|
9
|
+
filter_attribute_name, collection, value_method, label_method,
|
|
10
|
+
input_options, merged_input_options
|
|
11
|
+
)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def filter_attribute_name
|
|
15
|
+
"#{attribute_name}_eq"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module FilterInputs
|
|
2
|
+
class DateRangeInput < SimpleForm::Inputs::StringInput
|
|
3
|
+
def input(wrapper_options = nil)
|
|
4
|
+
@wrapper_options = wrapper_options
|
|
5
|
+
out = []
|
|
6
|
+
|
|
7
|
+
out << input_html
|
|
8
|
+
out.join.html_safe
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def input_html
|
|
12
|
+
merged_input_options = merge_wrapper_options(input_html_options, @wrapper_options)
|
|
13
|
+
[
|
|
14
|
+
@builder.text_field(gt_input_name, merged_input_options.merge(placeholder: gt_input_placeholder, class: 'date-picker form-control')),
|
|
15
|
+
@builder.text_field(lt_input_name, merged_input_options.merge(placeholder: lt_input_placeholder, class: 'date-picker form-control'))
|
|
16
|
+
].join("\n").html_safe
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def gt_input_name
|
|
20
|
+
"#{attribute_name}_gteq"
|
|
21
|
+
end
|
|
22
|
+
alias :input_name :gt_input_name
|
|
23
|
+
|
|
24
|
+
def lt_input_name
|
|
25
|
+
"#{attribute_name}_lteq"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def gt_input_placeholder
|
|
29
|
+
'От'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def lt_input_placeholder
|
|
33
|
+
'До'
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module FilterInputs
|
|
2
|
+
class NumericInput < SimpleForm::Inputs::StringInput
|
|
3
|
+
def input(wrapper_options = nil)
|
|
4
|
+
@wrapper_options = wrapper_options
|
|
5
|
+
out = []
|
|
6
|
+
out << select_html
|
|
7
|
+
out << input_html
|
|
8
|
+
out.join.html_safe
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def select_html
|
|
12
|
+
template.select_tag '', template.options_for_select(filter_options, current_filter), class: 'select_filter form-control'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def input_html
|
|
16
|
+
merged_input_options = merge_wrapper_options(input_html_options, @wrapper_options)
|
|
17
|
+
@builder.text_field current_filter, merged_input_options.merge(class: 'form-control')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def current_filter
|
|
21
|
+
@current_filter ||= begin
|
|
22
|
+
attributes = filters.map { |f| "#{attribute_name}_#{f}" }
|
|
23
|
+
attributes.detect { |m| object.public_send m } || attributes.first
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def label_html
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def filter_options
|
|
31
|
+
filters.map do |filter|
|
|
32
|
+
[filter, "#{attribute_name}_#{filter}"]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def filters
|
|
37
|
+
%w(eq gt lt)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module FilterInputs
|
|
2
|
+
class StringInput < SimpleForm::Inputs::StringInput
|
|
3
|
+
def input(wrapper_options = nil)
|
|
4
|
+
@wrapper_options = wrapper_options
|
|
5
|
+
out = []
|
|
6
|
+
out << select_html
|
|
7
|
+
out << input_html
|
|
8
|
+
out.join.html_safe
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def select_html
|
|
12
|
+
template.select_tag '', template.options_for_select(filter_options, current_filter), class: 'select_filter form-control'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def input_html
|
|
16
|
+
merged_input_options = merge_wrapper_options(input_html_options, @wrapper_options)
|
|
17
|
+
@builder.text_field current_filter, merged_input_options.merge(class: 'form-control')
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def current_filter
|
|
21
|
+
@current_filter ||= begin
|
|
22
|
+
attributes = filters.map { |f| "#{attribute_name}_#{f}" }
|
|
23
|
+
attributes.detect { |m| object.public_send m } || attributes.first
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def label_html
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def filter_options
|
|
31
|
+
filters.map do |filter|
|
|
32
|
+
[filter, "#{attribute_name}_#{filter}"]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def filters
|
|
37
|
+
%w(cont eq start end)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
data/lib/adminos.rb
CHANGED
|
@@ -3,17 +3,38 @@ require 'rails'
|
|
|
3
3
|
require 'jquery-fileupload-rails'
|
|
4
4
|
require 'dotenv-rails'
|
|
5
5
|
require 'babosa'
|
|
6
|
-
require 'russian'
|
|
7
6
|
require 'devise'
|
|
8
7
|
require 'cancancan'
|
|
8
|
+
require 'ransack'
|
|
9
9
|
require 'cocoon'
|
|
10
|
+
require 'simple_form'
|
|
10
11
|
|
|
11
12
|
module Adminos
|
|
13
|
+
|
|
14
|
+
autoload :FormBuilder, 'adminos/form_builder'
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
attr_writer :configuration
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.configuration
|
|
21
|
+
@configuration ||= Configuration.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.reset
|
|
25
|
+
@configuration = Configuration.new
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.configure
|
|
29
|
+
yield(configuration)
|
|
30
|
+
end
|
|
31
|
+
|
|
12
32
|
Helpers = Module.new
|
|
13
33
|
NestedSet = Module.new
|
|
14
34
|
Controllers = Module.new
|
|
15
35
|
StatefulLink = Module.new
|
|
16
36
|
|
|
37
|
+
|
|
17
38
|
Path.require_tree 'adminos', except: %w[generators operations]
|
|
18
39
|
|
|
19
40
|
class Engine < ::Rails::Engine
|
|
@@ -26,6 +47,7 @@ module Adminos
|
|
|
26
47
|
initializer 'adminos.controller_helpers' do
|
|
27
48
|
ActionController::Base.send :include, Controllers::Helpers
|
|
28
49
|
ActionController::Base.send :include, Controllers::Resource
|
|
50
|
+
ActionController::Base.send :include, Controllers::Filters
|
|
29
51
|
end
|
|
30
52
|
|
|
31
53
|
initializer 'adminos.stateful_link' do
|
|
@@ -38,5 +60,3 @@ module Adminos
|
|
|
38
60
|
end
|
|
39
61
|
end
|
|
40
62
|
end
|
|
41
|
-
|
|
42
|
-
require 'adminos/extensions/nested_set'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Adminos::Controllers::Filters
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
helper_method :filters
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class_methods do
|
|
9
|
+
attr_reader :filters
|
|
10
|
+
|
|
11
|
+
def add_filter(attribute, *args)
|
|
12
|
+
options = args.extract_options!
|
|
13
|
+
(@filters ||= {})[attribute.to_sym] = options
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def filters
|
|
18
|
+
self.class.filters
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -19,7 +19,7 @@ module Adminos::Controllers::Resource
|
|
|
19
19
|
with_move_to = options.delete(:with_move_to)
|
|
20
20
|
with_apply_sortable_order = options.delete(:with_apply_sortable_order)
|
|
21
21
|
|
|
22
|
-
helper_method :resource, :collection, :resource_class, :resource_params
|
|
22
|
+
helper_method :resource, :collection, :resource_class, :resource_params, :filter
|
|
23
23
|
helper_method(:parent_resource) if with_parent_resource
|
|
24
24
|
|
|
25
25
|
define_method :create do
|
|
@@ -80,11 +80,15 @@ module Adminos::Controllers::Resource
|
|
|
80
80
|
if with_parent_resource
|
|
81
81
|
parent_resource.send(self.resource_as_association)
|
|
82
82
|
elsif filter_by_locale
|
|
83
|
-
|
|
83
|
+
Mobility.with_locale(I18n.locale) do
|
|
84
|
+
resource_class
|
|
85
|
+
end
|
|
84
86
|
else
|
|
85
87
|
resource_class
|
|
86
88
|
end
|
|
87
89
|
|
|
90
|
+
collection = collection.search_by(params[:query]) if params[:query].present?
|
|
91
|
+
|
|
88
92
|
@collection =
|
|
89
93
|
if collection_scope.is_a?(Array)
|
|
90
94
|
collection_scope.inject(collection) do |collection, method|
|
|
@@ -93,12 +97,19 @@ module Adminos::Controllers::Resource
|
|
|
93
97
|
else
|
|
94
98
|
collection.send(collection_scope)
|
|
95
99
|
end
|
|
100
|
+
|
|
101
|
+
@collection = @collection.ransack(params[:q]).result if params[:q].present?
|
|
102
|
+
@collection
|
|
96
103
|
end
|
|
97
104
|
|
|
98
105
|
define_method :build_resource do
|
|
99
106
|
self.resource_class_scope.new(parameters)
|
|
100
107
|
end
|
|
101
108
|
|
|
109
|
+
define_method :filter do
|
|
110
|
+
@collection.ransack(params[:q])
|
|
111
|
+
end
|
|
112
|
+
|
|
102
113
|
define_method :parameters do
|
|
103
114
|
if action_name == ('create') || action_name == ('update')
|
|
104
115
|
strong_params
|
|
@@ -121,17 +132,13 @@ module Adminos::Controllers::Resource
|
|
|
121
132
|
|
|
122
133
|
_attribute_names = self.resource_class_scope.attribute_names + ids_attributes + rich_text_attributes
|
|
123
134
|
|
|
124
|
-
if
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
result = params.require(resource_params).permit(attrs)
|
|
130
|
-
else
|
|
131
|
-
result = params.require(resource_params).permit(*_attribute_names)
|
|
135
|
+
if resource_class.respond_to?(:translated_attribute_names)
|
|
136
|
+
_attribute_names += resource_class.translated_attribute_names.map do |attr|
|
|
137
|
+
I18n.available_locales.map { |locale| "#{attr}_#{Mobility.normalize_locale(locale)}" }
|
|
138
|
+
end.flatten
|
|
132
139
|
end
|
|
133
140
|
|
|
134
|
-
|
|
141
|
+
params.require(resource_params).permit(*_attribute_names)
|
|
135
142
|
end
|
|
136
143
|
|
|
137
144
|
define_method :find_resource do
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module Adminos
|
|
2
|
+
module SimpleFormExtraBase
|
|
3
|
+
# Find reflection name when available, otherwise use attribute
|
|
4
|
+
def reflection_or_attribute_name
|
|
5
|
+
@reflection_or_attribute_name ||= reflection ? reflection.name : attribute_name
|
|
6
|
+
@reflection_or_attribute_name.to_s.gsub(/_(#{I18n.available_locales.join('|')})/, '')
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
SimpleForm::Inputs::Base.prepend(Adminos::SimpleFormExtraBase)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module Adminos
|
|
2
|
+
module Search
|
|
3
|
+
module Elastic
|
|
4
|
+
extend ActiveSupport::Concern
|
|
5
|
+
|
|
6
|
+
included do
|
|
7
|
+
searchkick **searchkick_options
|
|
8
|
+
|
|
9
|
+
def search_data
|
|
10
|
+
data = respond_to?(:to_hash) ? to_hash : serializable_hash
|
|
11
|
+
data.delete("id")
|
|
12
|
+
data.delete("_id")
|
|
13
|
+
data.delete("_type")
|
|
14
|
+
data.merge!(actiontext_attributes)
|
|
15
|
+
|
|
16
|
+
data
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def actiontext_attributes
|
|
20
|
+
reflect_has_one = self.class.reflect_on_all_associations(:has_one)
|
|
21
|
+
rich_text_attributes = reflect_has_one.map(&:name).map { |name| name if name.to_s.include?('rich_text_') }.compact
|
|
22
|
+
|
|
23
|
+
rich_text_attributes.inject({}) do |memo, attr|
|
|
24
|
+
memo[attr] = public_send(attr).to_plain_text
|
|
25
|
+
memo
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class_methods do
|
|
31
|
+
def search_by(q = nil, *args)
|
|
32
|
+
options = args.extract_options!
|
|
33
|
+
options.merge!(load: false)
|
|
34
|
+
|
|
35
|
+
result_ids = self.search(q, options).results.map(&:id)
|
|
36
|
+
|
|
37
|
+
where(id: result_ids)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def searchkick_options
|
|
41
|
+
{}
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|