tramway-admin 1.32.1 → 1.32.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 +68 -14
- data/Rakefile +6 -30
- data/app/controllers/tramway/admin/application_controller.rb +2 -2
- 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.rb +1 -0
- data/lib/tramway/admin/version.rb +1 -1
- metadata +58 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f29f2296ff326aa4bcdeb569ba6f9c0e8f9afd9a307b53d9c79860bf1a98b9ea
|
4
|
+
data.tar.gz: cfb493f04f4240ff6234c2a94d927c5a5f8e8a8b458e7204d4d814bcd00b2ea1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8bb82d5139135bbbf8608105d3ba4bcf3a75ad53a24ac653e76f7bcbad62f683fcadf5a86d0f350fb9a6e20fe545751f8cfbd46dbfd2039a82bb778a3fb8724
|
7
|
+
data.tar.gz: 7515b06e5c9534eb2c6099b32287b0e6e3ea2efd232af314eccb29b59a1c55907585c29281624fbd9a275ae381542406add206af599103cfc4b0b2287f48be89
|
data/README.md
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
# Tramway::Admin
|
2
|
-
Short description and motivation.
|
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
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
*If you need translation of this Readme, please message us kalashnikov@ulmic.ru. We'll translate for you and post to this page*
|
7
|
-
|
8
|
-
## Russian readme
|
9
|
-
|
10
|
-
Готовая админка для проекта. Она подготовлена для работы со всеми tramway плагинами, а также поддерживает и ваши модели тоже.
|
3
|
+
Create admin panel for your application FAST!
|
11
4
|
|
12
5
|
## Usage
|
13
6
|
How to use my plugin.
|
@@ -18,7 +11,6 @@ How to use my plugin.
|
|
18
11
|
```ruby
|
19
12
|
gem 'tramway-admin'
|
20
13
|
gem 'tramway-auth'
|
21
|
-
gem 'tramway-core'
|
22
14
|
gem 'tramway-user'
|
23
15
|
gem 'state_machine', github: 'seuros/state_machine'
|
24
16
|
gem 'bcrypt'
|
@@ -102,11 +94,25 @@ Tramway::Admin.navbar_structure(
|
|
102
94
|
*app/decorators/your_model_decorator.rb*
|
103
95
|
```ruby
|
104
96
|
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
97
|
+
decorate_associations :messages, :posts
|
98
|
+
|
105
99
|
class << self
|
106
100
|
def collections
|
107
101
|
[ :all, :scope1, :scope2 ]
|
108
102
|
end
|
109
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
|
+
|
110
116
|
def list_filters
|
111
117
|
{
|
112
118
|
filter_name: {
|
@@ -126,7 +132,7 @@ class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
|
126
132
|
end
|
127
133
|
end
|
128
134
|
|
129
|
-
|
135
|
+
delegate_attributes :title
|
130
136
|
end
|
131
137
|
```
|
132
138
|
|
@@ -135,16 +141,34 @@ end
|
|
135
141
|
* `list_filters` method returns hash of filters where:
|
136
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
|
137
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
|
138
147
|
|
139
148
|
Filters naming:
|
140
149
|
|
150
|
+
*Select filters*
|
151
|
+
|
141
152
|
```yaml
|
142
153
|
en:
|
143
154
|
tramway:
|
144
155
|
admin:
|
145
156
|
filters:
|
146
157
|
model_name:
|
147
|
-
filter_name:
|
158
|
+
filter_name: Your Filter
|
159
|
+
```
|
160
|
+
|
161
|
+
*Date filters*
|
162
|
+
|
163
|
+
```yaml
|
164
|
+
en:
|
165
|
+
tramway:
|
166
|
+
admin:
|
167
|
+
filters:
|
168
|
+
model_name:
|
169
|
+
date_filter_name:
|
170
|
+
begin_date: Your Begin date filter
|
171
|
+
end_date Your end date filter
|
148
172
|
```
|
149
173
|
|
150
174
|
#### 10. Add inheritance to YourModel
|
@@ -231,6 +255,35 @@ Here docs about changing roles of `Tramway::User::User` model [Readme](https://g
|
|
231
255
|
|
232
256
|
## Associations management
|
233
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
|
+
|
234
287
|
### has_and_belongs_to_many
|
235
288
|
|
236
289
|
We have models Game and Packs.
|
@@ -393,8 +446,9 @@ en:
|
|
393
446
|
my_dropdown: Very important dropdown
|
394
447
|
```
|
395
448
|
|
396
|
-
##
|
397
|
-
|
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]`
|
398
452
|
|
399
453
|
## License
|
400
454
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,34 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
rescue LoadError
|
6
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
-
end
|
8
|
-
|
9
|
-
require 'rdoc/task'
|
3
|
+
require 'rake'
|
4
|
+
require 'rspec/core/rake_task'
|
10
5
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rdoc.options << '--line-numbers'
|
15
|
-
rdoc.rdoc_files.include('README.md')
|
16
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
7
|
+
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
8
|
+
t.rspec_opts = '--format documentation'
|
17
9
|
end
|
18
|
-
|
19
|
-
APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
|
20
|
-
load 'rails/tasks/engine.rake'
|
21
|
-
|
22
|
-
load 'rails/tasks/statistics.rake'
|
23
|
-
|
24
|
-
require 'bundler/gem_tasks'
|
25
|
-
|
26
|
-
require 'rake/testtask'
|
27
|
-
|
28
|
-
Rake::TestTask.new(:test) do |t|
|
29
|
-
t.libs << 'test'
|
30
|
-
t.pattern = 'test/**/*_test.rb'
|
31
|
-
t.verbose = false
|
32
|
-
end
|
33
|
-
|
34
|
-
task default: :test
|
10
|
+
task default: :spec
|
@@ -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
|
|
@@ -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|
|
data/lib/tramway/admin.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
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
|
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-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tramway-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.18.3.5
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.18.3.5
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: tramway-auth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tramway-user
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.1.3.2
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.1.3.2
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: bootstrap-kaminari-views
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,6 +196,20 @@ dependencies:
|
|
154
196
|
- - '='
|
155
197
|
- !ruby/object:Gem::Version
|
156
198
|
version: '3.0'
|
199
|
+
- !ruby/object:Gem::Dependency
|
200
|
+
name: pg
|
201
|
+
requirement: !ruby/object:Gem::Requirement
|
202
|
+
requirements:
|
203
|
+
- - ">="
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: '0'
|
206
|
+
type: :development
|
207
|
+
prerelease: false
|
208
|
+
version_requirements: !ruby/object:Gem::Requirement
|
209
|
+
requirements:
|
210
|
+
- - ">="
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
157
213
|
description: Engine for admin
|
158
214
|
email:
|
159
215
|
- kalashnikovisme@gmail.com
|