tramway-admin 1.30.0.1 → 1.31
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/README.md +4 -2
- data/app/controllers/tramway/admin/application_controller.rb +10 -2
- data/app/controllers/tramway/admin/records_controller.rb +5 -0
- data/app/helpers/tramway/admin/application_helper.rb +1 -0
- data/app/helpers/tramway/admin/records_helper.rb +5 -0
- data/app/views/tramway/admin/records/_search.html.haml +5 -2
- data/lib/tramway/admin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd6a8db1b87be8858fe60fc985278bb7089df3b5ffcc464c54f92959eafb6a5
|
4
|
+
data.tar.gz: 1d6e819e1964d4e44f4b74698c6083374a33a87144297ea684dfee658a06b614
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ef80f822c82bc6e4e16ea5d026ce7e41aa229d1133050f9f727083714c6e94ccf81fe699171ccc27640b343f4d8975481304c074c61c105bc06ea58f1267be
|
7
|
+
data.tar.gz: 1bec37b0cfb951204769eef233e32d1750ed32d28a4c6b1b629ae761736586dcc6740bc9fbbae9d0cd5d31302e1697ae4603bee40deea41eca772df029d250e0
|
data/README.md
CHANGED
@@ -99,12 +99,12 @@ Tramway::Admin.navbar_structure(
|
|
99
99
|
|
100
100
|
#### 9. Create decorator for models
|
101
101
|
|
102
|
-
*app/decorators/your_model_decorator.rb
|
102
|
+
*app/decorators/your_model_decorator.rb*
|
103
103
|
```ruby
|
104
104
|
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
105
105
|
class << self
|
106
106
|
def collections
|
107
|
-
[ :all ]
|
107
|
+
[ :all, :scope1, :scope2 ]
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
@@ -112,6 +112,8 @@ class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
|
112
112
|
end
|
113
113
|
```
|
114
114
|
|
115
|
+
**NOTE:** `collections` methods must return array of scopes of `YourModel`. Every collection will be a tab in a list of your model in admin panel.
|
116
|
+
|
115
117
|
#### 10. Add inheritance to YourModel
|
116
118
|
|
117
119
|
*app/models/your_model.rb*
|
@@ -33,6 +33,11 @@ module Tramway
|
|
33
33
|
records = model_class.active.send(collection)
|
34
34
|
records = records.send "#{current_admin.role}_scope", current_admin.id
|
35
35
|
records = records.ransack(params[:filter]).result if params[:filter].present?
|
36
|
+
params[:list_filters]&.each do |filter, value|
|
37
|
+
if value.present?
|
38
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, value)
|
39
|
+
end
|
40
|
+
end
|
36
41
|
hash.merge! collection => records.count
|
37
42
|
end
|
38
43
|
end
|
@@ -91,7 +96,7 @@ module Tramway
|
|
91
96
|
# :tramway, :admin, :application_controller, :form_given, :model_not_included_to_tramway_admin,
|
92
97
|
# model: params[:model]
|
93
98
|
# )
|
94
|
-
#raise "Looks like model #{params[:model]} is not included to tramway-admin for `#{current_admin.role}` role. Add it in the `config/initializers/tramway.rb`. This way `Tramway::Admin.set_available_models(#{params[:model]})`"
|
99
|
+
# raise "Looks like model #{params[:model]} is not included to tramway-admin for `#{current_admin.role}` role. Add it in the `config/initializers/tramway.rb`. This way `Tramway::Admin.set_available_models(#{params[:model]})`"
|
95
100
|
Tramway::Admin.forms.include? params[:form].underscore.sub(%r{^admin/}, '').sub(/_form$/, '')
|
96
101
|
end
|
97
102
|
|
@@ -110,6 +115,7 @@ module Tramway
|
|
110
115
|
def current_admin
|
111
116
|
user = Tramway::User::User.find_by id: session[:admin_id]
|
112
117
|
return false unless user
|
118
|
+
|
113
119
|
Tramway::User::UserDecorator.decorate user
|
114
120
|
end
|
115
121
|
|
@@ -121,7 +127,9 @@ module Tramway
|
|
121
127
|
end
|
122
128
|
|
123
129
|
def authenticate_admin!
|
124
|
-
|
130
|
+
if !current_admin && !request.path.in?(['/admin/session/new', '/admin/session'])
|
131
|
+
redirect_to '/admin/session/new'
|
132
|
+
end
|
125
133
|
end
|
126
134
|
end
|
127
135
|
end
|
@@ -6,6 +6,11 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
6
6
|
records = model_class.active.order(id: :desc).send scope
|
7
7
|
records = records.full_text_search params[:search] if params[:search].present?
|
8
8
|
records = records.ransack(params[:filter]).result if params[:filter].present?
|
9
|
+
params[:list_filters]&.each do |filter, value|
|
10
|
+
if value.present?
|
11
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, value)
|
12
|
+
end
|
13
|
+
end
|
9
14
|
records = records.send "#{current_admin.role}_scope", current_admin.id
|
10
15
|
@records = decorator_class.decorate records.page params[:page]
|
11
16
|
end
|
@@ -47,6 +47,11 @@ module Tramway::Admin
|
|
47
47
|
model_class.methods.include? :full_text_search
|
48
48
|
end
|
49
49
|
|
50
|
+
def build_options_for_select(name, collection)
|
51
|
+
selected_value = params[:list_filters].present? ? params[:list_filters][name] : nil
|
52
|
+
options_for_select(collection, selected_value)
|
53
|
+
end
|
54
|
+
|
50
55
|
def admin_index_path_of_model(model_class, tab, filter)
|
51
56
|
if tab
|
52
57
|
records_path model: model_class, filter: filter, scope: tab
|
@@ -1,12 +1,15 @@
|
|
1
|
-
- if searchable_model?(model_class)
|
1
|
+
- if searchable_model?(model_class) || decorator_class(model_class).list_filters.any?
|
2
2
|
.col-md-6
|
3
3
|
.search
|
4
4
|
= form_tag records_path, method: :get do |f|
|
5
5
|
.form-group.text
|
6
6
|
.input-group
|
7
|
-
|
7
|
+
- if searchable_model?(model_class)
|
8
|
+
= text_field_tag :search, params[:search], class: 'text form-control'
|
8
9
|
= hidden_field_tag :model, params[:model]
|
9
10
|
= hidden_field_tag :scope, params[:scope]
|
10
11
|
= hidden_field_tag :filter, params[:filter]
|
12
|
+
- decorator_class(model_class).list_filters.each do |filter|
|
13
|
+
= select_tag "list_filters[#{filter[0]}]", build_options_for_select(filter[0], filter[1][:select_collection]), include_blank: true, class: 'form-control'
|
11
14
|
.input-group-append
|
12
15
|
= submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tramway-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.31'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Kalashnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bootstrap-kaminari-views
|