tramway-admin 1.30.0.1 → 1.31

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdea27f5059ea05e7dbe882c13f0c2e1a668a4c088e9969e0d90987ac76520bb
4
- data.tar.gz: 37c7087ffb2c9bbfc67b24852a757883a3fd98b3403eacabcef80f2a771cfa03
3
+ metadata.gz: ddd6a8db1b87be8858fe60fc985278bb7089df3b5ffcc464c54f92959eafb6a5
4
+ data.tar.gz: 1d6e819e1964d4e44f4b74698c6083374a33a87144297ea684dfee658a06b614
5
5
  SHA512:
6
- metadata.gz: 30d2265f4664079d95170d9f00d391f2b9be0a32f47c1e5494f1a1f87d83374dc359b5fc14a1351e932fbaa5b7fa9c9d02ee87329bb1985de0009864590bb440
7
- data.tar.gz: 4083cd8b26c5503f520d4b38a810b24134ecde85e1d1e3e816162ee6503694e4df0a50c43435a39f8f00e817cfa7da4b4fbd48b66009ebf42915631de13cc674
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
- redirect_to '/admin/session/new' if !current_admin && !request.path.in?(['/admin/session/new', '/admin/session'])
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
@@ -29,6 +29,7 @@ module Tramway
29
29
  def current_admin
30
30
  user = Tramway::User::User.find_by id: session[:admin_id]
31
31
  return false unless user
32
+
32
33
  Tramway::User::UserDecorator.decorate user
33
34
  end
34
35
  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
- = text_field_tag :search, params[:search], class: 'text form-control'
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'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Admin
5
- VERSION = '1.30.0.1'
5
+ VERSION = '1.31'
6
6
  end
7
7
  end
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.30.0.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-05-07 00:00:00.000000000 Z
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