tramway-admin 1.32.0.1 → 1.32.1.4
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 +65 -12
- data/Rakefile +6 -30
- data/app/assets/stylesheets/tramway/admin/application.sass +4 -0
- data/app/controllers/tramway/admin/application_controller.rb +4 -2
- data/app/controllers/tramway/admin/records_controller.rb +9 -2
- data/app/views/tramway/admin/records/_form.html.haml +3 -0
- data/app/views/tramway/admin/records/_search.html.haml +20 -13
- 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: 12f18ece55fa0e66275d0ace0972d67490dc5396d7003f0ea0f24ab89d3e1be8
|
4
|
+
data.tar.gz: 4288cb1d7368b94747ddb238ece0024fca1e6f306a45aaf7c38a8e097b37ecf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65a7acba188612cc40301ff7949a4ecd5087154e7ecab8e4d8c9f366a56d2e9d043f3ad17d6e1cb9ac252e60615975a5c71b68f146bdf62edd9ef742d329baf1
|
7
|
+
data.tar.gz: 4cd7656172be3b226933b5fc81bb995aef736ba49488398f9680723ebe905954b73bd185765b40b0151cfce42817faac6e8c81f7a03d878e27761fdf9f26ea2f
|
data/README.md
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
# Tramway::Admin
|
2
|
-
Short description and motivation.
|
1
|
+
#  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.
|
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
|
@@ -41,11 +41,13 @@ module Tramway
|
|
41
41
|
begin_date = params[:list_filters][filter.to_sym][:begin_date]
|
42
42
|
end_date = params[:list_filters][filter.to_sym][:end_date]
|
43
43
|
if begin_date.present? && end_date.present?
|
44
|
-
|
44
|
+
if value.present?
|
45
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, begin_date, end_date)
|
46
|
+
end
|
45
47
|
end
|
46
48
|
end
|
47
49
|
end
|
48
|
-
hash.merge! collection => records.count
|
50
|
+
hash.merge! collection => records.send("#{current_admin.role}_scope", current_admin.id).count
|
49
51
|
end
|
50
52
|
end
|
51
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,7 +19,9 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
14
19
|
begin_date = params[:list_filters][filter.to_sym][:begin_date]
|
15
20
|
end_date = params[:list_filters][filter.to_sym][:end_date]
|
16
21
|
if begin_date.present? && end_date.present?
|
17
|
-
|
22
|
+
if value.present?
|
23
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, begin_date, end_date)
|
24
|
+
end
|
18
25
|
end
|
19
26
|
end
|
20
27
|
end
|
@@ -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,23 +6,30 @@
|
|
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|
|
13
|
-
|
14
|
-
|
15
|
-
-
|
16
|
-
|
13
|
+
- case filter[1][:type]
|
14
|
+
- when :select
|
15
|
+
.col-md-4
|
16
|
+
= label_tag t("admin.filters.#{model_class.to_s.underscore}.#{filter[0]}")
|
17
17
|
= select_tag "list_filters[#{filter[0]}]", build_options_for_select(filter[0], filter[1][:select_collection]), include_blank: true, class: 'form-control'
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
- when :dates
|
19
|
+
.col-md-8.dates_filter
|
20
|
+
.begin_date
|
21
|
+
= label_tag t("admin.filters.#{model_class.to_s.underscore}.#{filter[0]}.begin_date")
|
22
|
+
= text_field_tag "list_filters[#{filter[0]}][begin_date]", '', class: 'form-control', id: 'filter_datepicker_begin_date', value: params.dig(:list_filters, filter[0], :begin_date)
|
23
|
+
%span
|
24
|
+
\ -
|
25
|
+
.end_date
|
26
|
+
= label_tag t("admin.filters.#{model_class.to_s.underscore}.#{filter[0]}.end_date")
|
27
|
+
= text_field_tag "list_filters[#{filter[0]}][end_date]", '', class: 'form-control', id: 'filter_datepicker_end_date', value: params.dig(:list_filters, filter[0], :end_date)
|
28
|
+
:javascript
|
29
|
+
$(function () {
|
30
|
+
$('#filter_datepicker_begin_date').datepicker();
|
31
|
+
$('#filter_datepicker_end_date').datepicker();
|
32
|
+
});
|
26
33
|
.row-fluid.filters
|
27
34
|
.col-md-4.offset-md-8.submit
|
28
35
|
= submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
|
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.1.4
|
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-01 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
|