tramway-admin 1.32.1.1 → 1.32.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -5
- data/app/controllers/tramway/admin/application_controller.rb +8 -3
- data/app/controllers/tramway/admin/records_controller.rb +6 -1
- data/app/views/tramway/admin/records/_form.html.haml +3 -0
- data/app/views/tramway/admin/records/_search.html.haml +1 -1
- data/lib/tramway/admin/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f07d5b960569e1726907cbb62257174c49b3bbfcd56e3343b7bed2426a17bf5a
|
4
|
+
data.tar.gz: 5003ac7d1adec8c28af7413a2669ad305ca3b47b0a9cc8fd9c5b350da8ae2a81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864d6c1ee5998c3d90942bf7511c06d82a6f513900682e9c4a354895b92735a828e4ac0d65304b284c237db5e6edbea4c7658469a1111be3889c5b1fa4bc4332
|
7
|
+
data.tar.gz: cfce672ff7fd8fb5aaa0952040de2d7513e7216fc241c5795be142cfe8dab542857fd59f63ba7ba91b1f06915b91ae764c996d309f7851906a0af827eda86ef5
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Tramway::Admin
|
1
|
+
# ![tramway-ico](https://raw.githubusercontent.com/kalashnikovisme/kalashnikovisme/master/%D1%82%D1%80%D1%8D%D0%BC%D0%B2%D1%8D%D0%B9%D0%B1%D0%B5%D0%B7%D1%84%D0%BE%D0%BD%D0%B0-min.png) Tramway::Admin
|
2
2
|
|
3
3
|
Create admin panel for your application FAST!
|
4
4
|
|
@@ -11,7 +11,6 @@ How to use my plugin.
|
|
11
11
|
```ruby
|
12
12
|
gem 'tramway-admin'
|
13
13
|
gem 'tramway-auth'
|
14
|
-
gem 'tramway-core'
|
15
14
|
gem 'tramway-user'
|
16
15
|
gem 'state_machine', github: 'seuros/state_machine'
|
17
16
|
gem 'bcrypt'
|
@@ -95,11 +94,25 @@ Tramway::Admin.navbar_structure(
|
|
95
94
|
*app/decorators/your_model_decorator.rb*
|
96
95
|
```ruby
|
97
96
|
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
97
|
+
decorate_associations :messages, :posts
|
98
|
+
|
98
99
|
class << self
|
99
100
|
def collections
|
100
101
|
[ :all, :scope1, :scope2 ]
|
101
102
|
end
|
102
103
|
|
104
|
+
def list_attributes
|
105
|
+
[ :begin_date, :end_date ]
|
106
|
+
end
|
107
|
+
|
108
|
+
def show_attributes
|
109
|
+
[ :begin_date, :end_date ]
|
110
|
+
end
|
111
|
+
|
112
|
+
def show_associations
|
113
|
+
[ :messages ]
|
114
|
+
end
|
115
|
+
|
103
116
|
def list_filters
|
104
117
|
{
|
105
118
|
filter_name: {
|
@@ -119,7 +132,7 @@ class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
|
119
132
|
end
|
120
133
|
end
|
121
134
|
|
122
|
-
|
135
|
+
delegate_attributes :title
|
123
136
|
end
|
124
137
|
```
|
125
138
|
|
@@ -128,6 +141,9 @@ end
|
|
128
141
|
* `list_filters` method returns hash of filters where:
|
129
142
|
* select_collection - collection which will be in the select of filter. It must be compatible with [options_for_select](https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select) method
|
130
143
|
* query - some Active Record query which be used as a filter of records
|
144
|
+
* `list_attributes` method returns array of attributes which will be shown in index page. If empty only `name` will be shown
|
145
|
+
* `show_attributes` method returns array of attributes which will be shown in show page. If empty all attributes of the model will be shown
|
146
|
+
* `show_associations` method returns array of decorated associations which will be show in show page. If empty no associations will be shown
|
131
147
|
|
132
148
|
Filters naming:
|
133
149
|
|
@@ -239,6 +255,35 @@ Here docs about changing roles of `Tramway::User::User` model [Readme](https://g
|
|
239
255
|
|
240
256
|
## Associations management
|
241
257
|
|
258
|
+
### has_many
|
259
|
+
|
260
|
+
We have models Game and Packs.
|
261
|
+
|
262
|
+
*app/models/game.rb*
|
263
|
+
```ruby
|
264
|
+
class Game < Tramway::Core::ApplicationRecord
|
265
|
+
has_many :packs
|
266
|
+
end
|
267
|
+
```
|
268
|
+
|
269
|
+
*app/models/pack.rb*
|
270
|
+
```ruby
|
271
|
+
class Pack < Tramway::Core::ApplicationRecord
|
272
|
+
belongs_to :game
|
273
|
+
end
|
274
|
+
```
|
275
|
+
|
276
|
+
**You want to manage packs in the Game show admin page**
|
277
|
+
|
278
|
+
#### 1. Add association to PackDecorator
|
279
|
+
|
280
|
+
*app/decorators/pack_decorator.rb*
|
281
|
+
```ruby
|
282
|
+
class GameDecorator < Tramway::Core::ApplicationDecorator
|
283
|
+
decorate_association :packs, as: :game # we recommend you to add association name in Pack model. You need it if association name of Game in Pack is not `game`
|
284
|
+
end
|
285
|
+
```
|
286
|
+
|
242
287
|
### has_and_belongs_to_many
|
243
288
|
|
244
289
|
We have models Game and Packs.
|
@@ -401,8 +446,9 @@ en:
|
|
401
446
|
my_dropdown: Very important dropdown
|
402
447
|
```
|
403
448
|
|
404
|
-
##
|
405
|
-
|
449
|
+
## Errors
|
450
|
+
|
451
|
+
* **Model or Form is not available** - `params[:model]` or `params[:form]` is empty **OR** current user does not have access to model or form in `params[:model]` or `params[:form]`
|
406
452
|
|
407
453
|
## License
|
408
454
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -21,7 +21,7 @@ module Tramway
|
|
21
21
|
protected
|
22
22
|
|
23
23
|
def check_available!
|
24
|
-
raise 'Model or Form is not available' if !model_given? && !form_given?
|
24
|
+
raise 'Tramway::Admin - Model or Form is not available' if !model_given? && !form_given?
|
25
25
|
end
|
26
26
|
|
27
27
|
def check_available_scope!
|
@@ -47,7 +47,7 @@ module Tramway
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
-
hash.merge! collection => records.count
|
50
|
+
hash.merge! collection => records.send("#{current_admin.role}_scope", current_admin.id).count
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -92,7 +92,12 @@ module Tramway
|
|
92
92
|
end
|
93
93
|
|
94
94
|
def admin_form_class
|
95
|
-
"::#{current_admin.role.camelize}::#{model_class}Form"
|
95
|
+
class_name = "::#{current_admin.role.camelize}::#{model_class}Form"
|
96
|
+
if defined? class_name
|
97
|
+
class_name.constantize
|
98
|
+
else
|
99
|
+
raise "Tramway::Admin - you should create form for role `#{current_admin.role}` to edit #{model_class} model. It should be named #{class_name}"
|
100
|
+
end
|
96
101
|
end
|
97
102
|
|
98
103
|
def model_given?
|
@@ -5,7 +5,12 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
5
5
|
scope = params[:scope].present? ? params[:scope] : :all
|
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
|
+
if params[:filter].present?
|
9
|
+
if params[:filter].is_a? String
|
10
|
+
params[:filter] = JSON.parse params[:filter]
|
11
|
+
end
|
12
|
+
records = records.ransack(params[:filter]).result
|
13
|
+
end
|
9
14
|
params[:list_filters]&.each do |filter, value|
|
10
15
|
case decorator_class.list_filters[filter.to_sym][:type]
|
11
16
|
when :select
|
@@ -14,3 +14,6 @@
|
|
14
14
|
= hidden_field_tag :redirect, params[:redirect]
|
15
15
|
= f.button :submit, t('helpers.links.save'), class: 'btn-success'
|
16
16
|
= link_to t('helpers.links.back'), current_model_records_path, class: 'btn btn-secondary'
|
17
|
+
|
18
|
+
-# NOTES
|
19
|
+
-# * value_from_params helper is in tramway-core gem app/helpers/inputs_helpers.rb
|
@@ -6,7 +6,7 @@
|
|
6
6
|
= text_field_tag :search, params[:search], class: 'text form-control'
|
7
7
|
= hidden_field_tag :model, params[:model]
|
8
8
|
= hidden_field_tag :scope, params[:scope]
|
9
|
-
= hidden_field_tag :filter, params[:filter]
|
9
|
+
= hidden_field_tag :filter, (params[:filter].is_a?(ActionController::Parameters) ? params[:filter].permit!.to_h.to_json : params[:filter])
|
10
10
|
- decorator_class(model_class).list_filters.each_slice(3) do |slice|
|
11
11
|
.row-fluid.filters
|
12
12
|
- slice.each do |filter|
|
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.32.
|
4
|
+
version: 1.32.2.1
|
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-08
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tramway-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.18.3.
|
19
|
+
version: 1.18.3.5
|
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: 1.18.3.
|
26
|
+
version: 1.18.3.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tramway-auth
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|