tramway-admin 1.31.0.1 → 1.32.1.1
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 +68 -9
- data/Rakefile +6 -30
- data/app/assets/stylesheets/tramway/admin/application.sass +15 -0
- data/app/controllers/tramway/admin/application_controller.rb +14 -3
- data/app/controllers/tramway/admin/records_controller.rb +11 -2
- data/app/views/tramway/admin/records/_search.html.haml +33 -13
- data/app/views/tramway/admin/records/index.html.haml +2 -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: 8a1bea8f2efa7d5814d01ecbc9b1be1e0ce806a23e4d30468efed48977da8a39
|
4
|
+
data.tar.gz: 521deb526b82adb0bf8e12e637bd5110f43319e226647cead7782e3fff2690b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8af70fa074a7859b0f393b47c0e256a16d02f3b33146a9cd61220d2fe3a7b33d811debcc7aa1b066f46ef027e7497d758359dc9d1b558a3036852ff6b0eb0e48
|
7
|
+
data.tar.gz: 14debf20343bd4b96d7e157c93bd40f7a633fd6cadf674b4b9c712bf821dc9659db61e4121cd018b0ca0570626d7b892ad37ff23cf592540253a710e35b0a420
|
data/README.md
CHANGED
@@ -1,13 +1,6 @@
|
|
1
1
|
# Tramway::Admin
|
2
|
-
Short description and motivation.
|
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.
|
@@ -106,13 +99,61 @@ class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
|
106
99
|
def collections
|
107
100
|
[ :all, :scope1, :scope2 ]
|
108
101
|
end
|
102
|
+
|
103
|
+
def list_filters
|
104
|
+
{
|
105
|
+
filter_name: {
|
106
|
+
type: :select,
|
107
|
+
select_collection: filter_collection,
|
108
|
+
query: lambda do |list, value|
|
109
|
+
list.where some_attribute: value
|
110
|
+
end
|
111
|
+
},
|
112
|
+
date_filter_name: {
|
113
|
+
type: :dates,
|
114
|
+
query: lambda do |list, begin_date, end_date|
|
115
|
+
list.where 'created_at > ? AND created_at < ?', begin_date, end_date
|
116
|
+
end
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
109
120
|
end
|
110
121
|
|
111
122
|
delegate :title, to: :object
|
112
123
|
end
|
113
124
|
```
|
114
125
|
|
115
|
-
**
|
126
|
+
**NOTES:**
|
127
|
+
* `collections` method must return array of scopes of `YourModel`. Every collection will be a tab in a list of your model in admin panel
|
128
|
+
* `list_filters` method returns hash of filters where:
|
129
|
+
* 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
|
+
* query - some Active Record query which be used as a filter of records
|
131
|
+
|
132
|
+
Filters naming:
|
133
|
+
|
134
|
+
*Select filters*
|
135
|
+
|
136
|
+
```yaml
|
137
|
+
en:
|
138
|
+
tramway:
|
139
|
+
admin:
|
140
|
+
filters:
|
141
|
+
model_name:
|
142
|
+
filter_name: Your Filter
|
143
|
+
```
|
144
|
+
|
145
|
+
*Date filters*
|
146
|
+
|
147
|
+
```yaml
|
148
|
+
en:
|
149
|
+
tramway:
|
150
|
+
admin:
|
151
|
+
filters:
|
152
|
+
model_name:
|
153
|
+
date_filter_name:
|
154
|
+
begin_date: Your Begin date filter
|
155
|
+
end_date Your end date filter
|
156
|
+
```
|
116
157
|
|
117
158
|
#### 10. Add inheritance to YourModel
|
118
159
|
|
@@ -140,6 +181,24 @@ class Admin::YourModelForm < Tramway::Core::ApplicationForm
|
|
140
181
|
end
|
141
182
|
end
|
142
183
|
```
|
184
|
+
|
185
|
+
### 12. You can add search to your index page
|
186
|
+
|
187
|
+
Tramway use gem [PgSearch](https://github.com/Casecommons/pg_search`) as search engine
|
188
|
+
|
189
|
+
Just add `search` method to `YourModel` like this
|
190
|
+
|
191
|
+
```ruby
|
192
|
+
search_by *attributes, **associations # `attributes` and `associations` should be the same syntax as in PgSearch
|
193
|
+
```
|
194
|
+
|
195
|
+
Example:
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
class YourModel < Tramway::Core::ApplicationRecord
|
199
|
+
search_by :my_attribute, :another_attribute, my_association: [ :my_association_attribute, :another_my_association_attribute ]
|
200
|
+
```
|
201
|
+
|
143
202
|
#### 12. Run server `rails s`
|
144
203
|
#### 13. Launch `localhost:3000/admin`
|
145
204
|
|
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
|
@@ -31,3 +31,18 @@ td.actions
|
|
31
31
|
height: auto
|
32
32
|
max-height: 30em
|
33
33
|
overflow-x: hidden
|
34
|
+
|
35
|
+
.row-fluid.filters
|
36
|
+
width: 100%
|
37
|
+
display: flex
|
38
|
+
|
39
|
+
select
|
40
|
+
width: 100%
|
41
|
+
|
42
|
+
.submit
|
43
|
+
display: flex
|
44
|
+
flex-direction: row-reverse
|
45
|
+
|
46
|
+
.dates_filter
|
47
|
+
display: flex
|
48
|
+
flex-direction: row
|
@@ -34,8 +34,17 @@ module Tramway
|
|
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
36
|
params[:list_filters]&.each do |filter, value|
|
37
|
-
|
38
|
-
|
37
|
+
case decorator_class.list_filters[filter.to_sym][:type]
|
38
|
+
when :select
|
39
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, value) if value.present?
|
40
|
+
when :dates
|
41
|
+
begin_date = params[:list_filters][filter.to_sym][:begin_date]
|
42
|
+
end_date = params[:list_filters][filter.to_sym][:end_date]
|
43
|
+
if begin_date.present? && end_date.present?
|
44
|
+
if value.present?
|
45
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, begin_date, end_date)
|
46
|
+
end
|
47
|
+
end
|
39
48
|
end
|
40
49
|
end
|
41
50
|
hash.merge! collection => records.count
|
@@ -97,7 +106,9 @@ module Tramway
|
|
97
106
|
# model: params[:model]
|
98
107
|
# )
|
99
108
|
# 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]})`"
|
100
|
-
|
109
|
+
if params[:form].present?
|
110
|
+
Tramway::Admin.forms.include? params[:form].underscore.sub(%r{^admin/}, '').sub(/_form$/, '')
|
111
|
+
end
|
101
112
|
end
|
102
113
|
|
103
114
|
def available_scope_given?
|
@@ -7,8 +7,17 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
|
|
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
9
|
params[:list_filters]&.each do |filter, value|
|
10
|
-
|
11
|
-
|
10
|
+
case decorator_class.list_filters[filter.to_sym][:type]
|
11
|
+
when :select
|
12
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, value) if value.present?
|
13
|
+
when :dates
|
14
|
+
begin_date = params[:list_filters][filter.to_sym][:begin_date]
|
15
|
+
end_date = params[:list_filters][filter.to_sym][:end_date]
|
16
|
+
if begin_date.present? && end_date.present?
|
17
|
+
if value.present?
|
18
|
+
records = decorator_class.list_filters[filter.to_sym][:query].call(records, begin_date, end_date)
|
19
|
+
end
|
20
|
+
end
|
12
21
|
end
|
13
22
|
end
|
14
23
|
records = records.send "#{current_admin.role}_scope", current_admin.id
|
@@ -1,15 +1,35 @@
|
|
1
1
|
- if searchable_model?(model_class) || decorator_class(model_class).list_filters.any?
|
2
|
-
.col-md-
|
2
|
+
.col-md-8
|
3
3
|
.search
|
4
|
-
= form_tag records_path, method: :get do |f|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
-
|
13
|
-
|
14
|
-
|
15
|
-
|
4
|
+
= form_tag records_path, class: 'form-inline', method: :get do |f|
|
5
|
+
- if searchable_model?(model_class)
|
6
|
+
= text_field_tag :search, params[:search], class: 'text form-control'
|
7
|
+
= hidden_field_tag :model, params[:model]
|
8
|
+
= hidden_field_tag :scope, params[:scope]
|
9
|
+
= hidden_field_tag :filter, params[:filter]
|
10
|
+
- decorator_class(model_class).list_filters.each_slice(3) do |slice|
|
11
|
+
.row-fluid.filters
|
12
|
+
- slice.each do |filter|
|
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
|
+
= select_tag "list_filters[#{filter[0]}]", build_options_for_select(filter[0], filter[1][:select_collection]), include_blank: true, class: 'form-control'
|
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
|
+
});
|
33
|
+
.row-fluid.filters
|
34
|
+
.col-md-4.offset-md-8.submit
|
35
|
+
= submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
|
@@ -5,7 +5,8 @@
|
|
5
5
|
- tabs = get_collection
|
6
6
|
.page-header
|
7
7
|
.row
|
8
|
-
.
|
8
|
+
- search_render_show = searchable_model?(model_class) || decorator_class(model_class).list_filters.any?
|
9
|
+
%div{ class: "col-md-#{search_render_show ? 4 : 12}" }
|
9
10
|
%h1
|
10
11
|
= current_title
|
11
12
|
= link_to fa_icon(:plus), new_current_model_record_path, 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.
|
4
|
+
version: 1.32.1.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-
|
11
|
+
date: 2020-08-26 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.4
|
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.4
|
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
|