tramway-admin 1.32.1.2 → 1.32.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -6
- data/app/controllers/tramway/admin/application_controller.rb +8 -3
- data/app/controllers/tramway/admin/records_controller.rb +6 -1
- data/app/views/layouts/tramway/admin/shared/_navbar.html.haml +3 -0
- 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 +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54810b97b5d2f0fd856461953a58e2b36dcae76ad116f408ccff7bec841ba498
|
4
|
+
data.tar.gz: b802cfb92fdf6c8b6153eb9ed308ddb8284756f6754072369f309266a0d540eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dac5f5fa0d8cb6b85c30ad9bf7c4c5b6779f93ddbdba2513ef8d351a7e316bfbec4140f87f356a8bf842b1c6a78182c92d335fe8dd0deff1bd8d46fdb18b6cc8
|
7
|
+
data.tar.gz: 963ad750519bba6a9863d365548d45ec008761363473071b9e6caf27e5f7a02ca88d02a8d943d28ed6aa657a223fad2e88c33027a05d3380dfff35706fdc7075
|
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
|
|
@@ -43,7 +43,7 @@ Rails.application.routes.draw do
|
|
43
43
|
end
|
44
44
|
```
|
45
45
|
|
46
|
-
#### 4. Then make `tramway-core` installation. [How-to](https://github.com/
|
46
|
+
#### 4. Then make `tramway-core` installation. [How-to](https://github.com/Purple-Magic/tramway-core/blob/develop/README.md#installation)
|
47
47
|
|
48
48
|
|
49
49
|
#### 5. And then execute:
|
@@ -94,11 +94,25 @@ Tramway::Admin.navbar_structure(
|
|
94
94
|
*app/decorators/your_model_decorator.rb*
|
95
95
|
```ruby
|
96
96
|
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
97
|
+
decorate_associations :messages, :posts
|
98
|
+
|
97
99
|
class << self
|
98
100
|
def collections
|
99
101
|
[ :all, :scope1, :scope2 ]
|
100
102
|
end
|
101
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
|
+
|
102
116
|
def list_filters
|
103
117
|
{
|
104
118
|
filter_name: {
|
@@ -118,7 +132,7 @@ class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
|
118
132
|
end
|
119
133
|
end
|
120
134
|
|
121
|
-
|
135
|
+
delegate_attributes :title
|
122
136
|
end
|
123
137
|
```
|
124
138
|
|
@@ -127,6 +141,9 @@ end
|
|
127
141
|
* `list_filters` method returns hash of filters where:
|
128
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
|
129
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
|
130
147
|
|
131
148
|
Filters naming:
|
132
149
|
|
@@ -175,7 +192,13 @@ class Admin::YourModelForm < Tramway::Core::ApplicationForm
|
|
175
192
|
logo: :file,
|
176
193
|
description: :ckeditor,
|
177
194
|
date: :date_picker,
|
178
|
-
text: :text
|
195
|
+
text: :text,
|
196
|
+
birth_date: {
|
197
|
+
type: :default,
|
198
|
+
input_options: {
|
199
|
+
hint: 'It should be more than 18'
|
200
|
+
}
|
201
|
+
}
|
179
202
|
end
|
180
203
|
end
|
181
204
|
end
|
@@ -238,6 +261,35 @@ Here docs about changing roles of `Tramway::User::User` model [Readme](https://g
|
|
238
261
|
|
239
262
|
## Associations management
|
240
263
|
|
264
|
+
### has_many
|
265
|
+
|
266
|
+
We have models Game and Packs.
|
267
|
+
|
268
|
+
*app/models/game.rb*
|
269
|
+
```ruby
|
270
|
+
class Game < Tramway::Core::ApplicationRecord
|
271
|
+
has_many :packs
|
272
|
+
end
|
273
|
+
```
|
274
|
+
|
275
|
+
*app/models/pack.rb*
|
276
|
+
```ruby
|
277
|
+
class Pack < Tramway::Core::ApplicationRecord
|
278
|
+
belongs_to :game
|
279
|
+
end
|
280
|
+
```
|
281
|
+
|
282
|
+
**You want to manage packs in the Game show admin page**
|
283
|
+
|
284
|
+
#### 1. Add association to PackDecorator
|
285
|
+
|
286
|
+
*app/decorators/pack_decorator.rb*
|
287
|
+
```ruby
|
288
|
+
class GameDecorator < Tramway::Core::ApplicationDecorator
|
289
|
+
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`
|
290
|
+
end
|
291
|
+
```
|
292
|
+
|
241
293
|
### has_and_belongs_to_many
|
242
294
|
|
243
295
|
We have models Game and Packs.
|
@@ -400,8 +452,9 @@ en:
|
|
400
452
|
my_dropdown: Very important dropdown
|
401
453
|
```
|
402
454
|
|
403
|
-
##
|
404
|
-
|
455
|
+
## Errors
|
456
|
+
|
457
|
+
* **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]`
|
405
458
|
|
406
459
|
## License
|
407
460
|
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
|
@@ -32,6 +32,9 @@
|
|
32
32
|
|
33
33
|
%ul.nav.navbar-nav.ml-auto
|
34
34
|
- if current_admin
|
35
|
+
%li.nav-item
|
36
|
+
%span.nav-link
|
37
|
+
= "#{current_admin.first_name} #{current_admin.last_name}"
|
35
38
|
- if @notifications_count.present?
|
36
39
|
- if @notifications_count > 0
|
37
40
|
%li.nav-item.dropdown.notifications
|
@@ -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.2
|
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-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tramway-core
|