tramway-admin 1.32.2.4 → 1.33.1.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 +89 -1
- data/app/controllers/tramway/admin/application_controller.rb +0 -9
- data/app/helpers/tramway/admin/application_helper.rb +1 -0
- data/app/helpers/tramway/admin/records_helper.rb +4 -0
- data/app/views/tramway/admin/records/_list.html.haml +7 -6
- data/app/views/tramway/admin/records/_search.html.haml +1 -1
- data/app/views/tramway/admin/records/index.html.haml +1 -1
- data/app/views/tramway/admin/shared/show/_attribute_tr.html.haml +3 -2
- data/lib/tramway/admin.rb +1 -0
- data/lib/tramway/admin/generators/model_generator.rb +2 -2
- data/lib/tramway/admin/generators/templates/decorator.rb.erb +7 -3
- data/lib/tramway/admin/records_models.rb +1 -1
- data/lib/tramway/admin/tramway_model_helper.rb +5 -0
- data/lib/tramway/admin/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fb4fb3d9ec6d2f5bb4f56e65806cb737bf0898ee1186e2ada89498b4ce6fcdc
|
4
|
+
data.tar.gz: bd03f075aed1aa8fdd5b20af8c2c6e97be419f23a88369fcb0276c48a5e896b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0936fb8b540e95c62e6c9e981a4c674b6a18f3e9732ccb82797df43c2b2090775fcbb8bd884cb7d5249ba8705e58b36ab69425beba5a2cdab809bc4a0391c39d'
|
7
|
+
data.tar.gz: 9c583df3d9be61ee6db2abe021ed717b422a0f8c93afd4a2764ca68931e8c9f454a5b2d8a9033e1dfdb51fd490ae0525d6ef00927593d9dea23e219e96e111f6
|
data/README.md
CHANGED
@@ -239,7 +239,6 @@ class YourModel < Tramway::Core::ApplicationRecord
|
|
239
239
|
#### 12. Run server `rails s`
|
240
240
|
#### 13. Launch `localhost:3000/admin`
|
241
241
|
|
242
|
-
|
243
242
|
### CRUDs for models
|
244
243
|
|
245
244
|
By default users with role `admin` have access to all models used as arguments in method `::Tramway::Admin.set_available_models`. If you want specify models by roles, use them as keys
|
@@ -393,6 +392,64 @@ window.current_locale = window.i18n_locale 'en'
|
|
393
392
|
```
|
394
393
|
to the `app/assets/javascripts/admin/application.js.coffee` file
|
395
394
|
|
395
|
+
### Decorator Helper methods
|
396
|
+
|
397
|
+
#### date_view
|
398
|
+
Returns a date in the format depending on localization
|
399
|
+
|
400
|
+
*app/decorators/\*_decorator.rb*
|
401
|
+
```ruby
|
402
|
+
def created_at
|
403
|
+
date_view object.created_at
|
404
|
+
end
|
405
|
+
```
|
406
|
+
#### datetime_view
|
407
|
+
Returns a date and time in the format depending on localization
|
408
|
+
|
409
|
+
*app/decorators/*_decorator.rb*
|
410
|
+
```ruby
|
411
|
+
def created_at
|
412
|
+
datetime_view object.created_at
|
413
|
+
end
|
414
|
+
```
|
415
|
+
#### state_machine_view
|
416
|
+
Returns the state of an object according to a state machine
|
417
|
+
|
418
|
+
*app/decorators/*_decorator.rb*
|
419
|
+
```ruby
|
420
|
+
def state
|
421
|
+
state_machine_view object, :state
|
422
|
+
end
|
423
|
+
```
|
424
|
+
#### image_view
|
425
|
+
Returns an image in a particular format depending on the parameters of the original image file
|
426
|
+
|
427
|
+
*app/decorators/\*_decorator.rb*
|
428
|
+
```ruby
|
429
|
+
def avatar
|
430
|
+
image_view object.avatar
|
431
|
+
end
|
432
|
+
```
|
433
|
+
#### enumerize_view
|
434
|
+
Returns object enumerations as text
|
435
|
+
|
436
|
+
*app/decorators/\*_decorator.rb*
|
437
|
+
```ruby
|
438
|
+
def field_type
|
439
|
+
enumerize_view object.field_type
|
440
|
+
end
|
441
|
+
```
|
442
|
+
|
443
|
+
#### file_view
|
444
|
+
Returns file name and button to download it
|
445
|
+
|
446
|
+
*app/decorators/\*_decorator.rb*
|
447
|
+
```ruby
|
448
|
+
def file_download
|
449
|
+
file_view object.file
|
450
|
+
end
|
451
|
+
```
|
452
|
+
|
396
453
|
## Notifications
|
397
454
|
|
398
455
|
You can add notification to your admin panel to the navbar.
|
@@ -471,5 +528,36 @@ en:
|
|
471
528
|
|
472
529
|
* **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]`
|
473
530
|
|
531
|
+
## Good features
|
532
|
+
|
533
|
+
### Get actions log in admin panel
|
534
|
+
|
535
|
+
Tramway uses [audited](https://github.com/collectiveidea/audited) to log actions of models. That's why all we need it's creating view for model `Audited::Audit`
|
536
|
+
|
537
|
+
#### 1. Add Audited::Audit model to available models
|
538
|
+
|
539
|
+
*config/initializers/tramway.rb*
|
540
|
+
```
|
541
|
+
Tramway::Admin.set_available_models(
|
542
|
+
Audited::Audit,
|
543
|
+
project: :your_project_name
|
544
|
+
)
|
545
|
+
```
|
546
|
+
|
547
|
+
#### 2. Add this model to navbar
|
548
|
+
|
549
|
+
```
|
550
|
+
Tramway::Admin.set_navbar_structure(
|
551
|
+
Audited::Audit,
|
552
|
+
project: :your_project_name
|
553
|
+
)
|
554
|
+
```
|
555
|
+
|
556
|
+
#### 3. Generate decorator for Audited::Audit
|
557
|
+
|
558
|
+
```
|
559
|
+
rails g tramway:admin:model Audited::Audit
|
560
|
+
```
|
561
|
+
|
474
562
|
## License
|
475
563
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -72,15 +72,6 @@ module Tramway
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
if Rails.env.production?
|
76
|
-
rescue_from StandardError do |exception|
|
77
|
-
Rails.logger.warn "ERROR MESSAGE: #{exception.message}"
|
78
|
-
Rails.logger.warn "BACKTRACE: #{exception.backtrace.first(30).join("\n")}"
|
79
|
-
@exception = exception
|
80
|
-
render 'tramway/admin/shared/errors/server_error', status: 500, layout: false
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
75
|
include Tramway::ClassNameHelpers
|
85
76
|
|
86
77
|
def model_class
|
@@ -16,6 +16,7 @@ module Tramway
|
|
16
16
|
include ::Tramway::Admin::ActionsHelper
|
17
17
|
include ::Tramway::Collections::Helper
|
18
18
|
include ::Tramway::Core::CopyToClipboardHelper
|
19
|
+
include ::Tramway::Admin::TramwayModelHelper
|
19
20
|
|
20
21
|
def object_type(object)
|
21
22
|
object_class_name = if object.class.ancestors.include? ::Tramway::Core::ApplicationDecorator
|
@@ -24,10 +24,11 @@
|
|
24
24
|
|
25
25
|
= delete_button url: current_model_record_path(record.id), form_options: { class: :smart_button }, button_options: { class: 'btn btn-xs btn-danger' } do
|
26
26
|
= fa_icon 'trash-alt'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
-
|
32
|
-
|
27
|
+
- if tramway_model?(model_class)
|
28
|
+
%br
|
29
|
+
%br
|
30
|
+
.btn-group{ data: { toggle: :buttons } }
|
31
|
+
- record.model.class.state_machines.keys.each do |state_method|
|
32
|
+
- unless state_method == :state
|
33
|
+
= state_events_buttons record, state_method: state_method, model_param_name: :record, controller: 'tramway/admin/records', action: :update, parameters: { redirect: current_model_records_path(page: params[:page], scope: params[:scope], filter: params[:filter], focus: focus_selector(index)), model: record.class.model_name }, button_options: { class: :smart_button }
|
33
34
|
= paginate @records, theme: 'twitter-bootstrap-4'
|
@@ -5,7 +5,7 @@
|
|
5
5
|
- tabs = get_collection
|
6
6
|
.page-header
|
7
7
|
.row
|
8
|
-
- search_render_show = searchable_model?(model_class) ||
|
8
|
+
- search_render_show = searchable_model?(model_class) || is_there_any_filters?(model_class)
|
9
9
|
%div{ class: "col-md-#{search_render_show ? 4 : 12}" }
|
10
10
|
%h1
|
11
11
|
= current_title
|
@@ -4,5 +4,6 @@
|
|
4
4
|
%td
|
5
5
|
= value
|
6
6
|
%td
|
7
|
-
- if
|
8
|
-
|
7
|
+
- if tramway_model?(model_class)
|
8
|
+
- if attribute_name.to_s != 'state' && object.model.class.state_machines.keys.include?(attribute_name.to_sym)
|
9
|
+
= state_events_buttons object, state_method: attribute_name, model_param_name: :record, controller: 'tramway/admin/records', action: :update, parameters: { model: object.class.model_name }, button_options: { class: :smart_button }
|
data/lib/tramway/admin.rb
CHANGED
@@ -11,6 +11,7 @@ require 'tramway/admin/welcome_page_actions'
|
|
11
11
|
require 'tramway/admin/navbar'
|
12
12
|
require 'tramway/error'
|
13
13
|
require 'tramway/admin/generators/install_generator'
|
14
|
+
require 'tramway/admin/tramway_model_helper'
|
14
15
|
|
15
16
|
module Tramway
|
16
17
|
Auth.layout_path = 'tramway/admin/application'
|
@@ -25,14 +25,14 @@ module Tramway
|
|
25
25
|
def run_decorator_generator
|
26
26
|
template(
|
27
27
|
'decorator.rb.erb',
|
28
|
-
Rails.root.join("app/decorators/#{
|
28
|
+
Rails.root.join("app/decorators/#{file_path}_decorator.rb"),
|
29
29
|
)
|
30
30
|
end
|
31
31
|
|
32
32
|
def run_forms_generator
|
33
33
|
template(
|
34
34
|
'form.rb.erb',
|
35
|
-
Rails.root.join("app/forms/#{user_role}/#{
|
35
|
+
Rails.root.join("app/forms/#{user_role}/#{file_path}_form.rb"),
|
36
36
|
)
|
37
37
|
end
|
38
38
|
|
@@ -2,6 +2,12 @@ class <%= class_name %>Decorator < Tramway::Core::ApplicationDecorator
|
|
2
2
|
# Associations you want to show in admin dashboard
|
3
3
|
# decorate_associations :messages, :posts
|
4
4
|
|
5
|
+
delegate_attributes(
|
6
|
+
<% attributes.each do |attr| -%>
|
7
|
+
:<%= attr %>,
|
8
|
+
<% end -%>
|
9
|
+
)
|
10
|
+
|
5
11
|
class << self
|
6
12
|
def collections
|
7
13
|
# [ :all, :scope1, :scope2 ]
|
@@ -47,6 +53,4 @@ class <%= class_name %>Decorator < Tramway::Core::ApplicationDecorator
|
|
47
53
|
# }
|
48
54
|
end
|
49
55
|
end
|
50
|
-
|
51
|
-
# delegate_attributes :title
|
52
|
-
end
|
56
|
+
end
|
@@ -9,7 +9,7 @@ module Tramway::Admin::RecordsModels
|
|
9
9
|
if model.class == Class || model.class == String
|
10
10
|
@available_models[project][role].merge! model.to_s => %i[index show update create destroy]
|
11
11
|
elsif model.class == Hash
|
12
|
-
@available_models[project][role].merge! model
|
12
|
+
@available_models[project][role].merge! model
|
13
13
|
end
|
14
14
|
end
|
15
15
|
@available_models = @available_models.with_indifferent_access
|
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.
|
4
|
+
version: 1.33.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:
|
11
|
+
date: 2021-01-25 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.
|
19
|
+
version: 1.18.6
|
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.
|
26
|
+
version: 1.18.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: tramway-auth
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -300,6 +300,7 @@ files:
|
|
300
300
|
- lib/tramway/admin/record_routes_helper.rb
|
301
301
|
- lib/tramway/admin/records_models.rb
|
302
302
|
- lib/tramway/admin/singleton_models.rb
|
303
|
+
- lib/tramway/admin/tramway_model_helper.rb
|
303
304
|
- lib/tramway/admin/version.rb
|
304
305
|
- lib/tramway/admin/welcome_page_actions.rb
|
305
306
|
homepage: https://github.com/kalashnikovisme/tramway-dev
|