tramway-admin 1.32.2.5 → 1.33.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38545a69081961dbceae8db18e98f49405462bf332aeb852d001bf5332e0b127
4
- data.tar.gz: 7f5e3942cba417767b231005efeddb6ea042ba8b91728946a286f4a97079d00e
3
+ metadata.gz: 4ff2e7ee2cba522a3d021f94ecfbe9da4cf66abc29daf4b2fab2e9d4bf47b0de
4
+ data.tar.gz: 89457c61c7d88cab5a9a49f38f6bfb6e83c2b43f520425961b164cde14996b25
5
5
  SHA512:
6
- metadata.gz: d1e1eaf40a6b789dd0d9c368fa193152c484791397a259222d89a06f623332501e0b3af3d3d8a63d5785b6e8b9eed610bb091e632406b3a8b025cc2535878bfd
7
- data.tar.gz: 14acb2b150a1dd2c5e0ecee95668c73ec93fab2805095d0918a95b36d21534e5afdd640a9f4afd3c02671231ebca72dc5d9e789e3fd534377eafe5d94e766cd8
6
+ metadata.gz: 329435596809bfae8589f002c23d7372f1ae5a67eb3be42e892272bf64ccbd217466ce55aa1cf50c0cd086157ba329bb7987f9171eb2507aa9a8ef2174029dc9
7
+ data.tar.gz: '084403024d287e9c02a93f5bcbcb382ba9ad57932cd0fa0d2d90ec5e6d8bd30685f2e82a03b934e04bd3fddfa0d242d2c02ced387349425e4db4c469925d6063'
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
+ ```ruby
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
+ ```ruby
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
@@ -99,5 +99,9 @@ module Tramway::Admin
99
99
  }
100
100
  end
101
101
  end
102
+
103
+ def is_there_any_filters?(model_class)
104
+ decorator_class(model_class).list_filters&.any?
105
+ end
102
106
  end
103
107
  end
@@ -24,10 +24,11 @@
24
24
  &nbsp;&nbsp;
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
- %br
28
- %br
29
- .btn-group{ data: { toggle: :buttons } }
30
- - record.model.class.state_machines.keys.each do |state_method|
31
- - unless state_method == :state
32
- = 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 }
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'
@@ -1,9 +1,10 @@
1
- - if searchable_model?(model_class) || decorator_class(model_class).list_filters.any?
2
- .col-md-8
3
- .search
1
+ - if searchable_model?(model_class) || is_there_any_filters?(model_class)
2
+ .search
3
+ .d-flex.flex-row-reverse.filters
4
4
  = form_tag records_path, class: 'form-inline', method: :get do |f|
5
5
  - if searchable_model?(model_class)
6
- = text_field_tag :search, params[:search], class: 'text form-control'
6
+ .col-md-8
7
+ = text_field_tag :search, params[:search], class: 'text form-control'
7
8
  = hidden_field_tag :model, params[:model]
8
9
  = hidden_field_tag :scope, params[:scope]
9
10
  = hidden_field_tag :filter, (params[:filter].is_a?(ActionController::Parameters) ? params[:filter].permit!.to_h.to_json : params[:filter])
@@ -30,6 +31,5 @@
30
31
  $('#filter_datepicker_begin_date').datepicker();
31
32
  $('#filter_datepicker_end_date').datepicker();
32
33
  });
33
- .row-fluid.filters
34
- .col-md-4.offset-md-8.submit
35
- = submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
34
+ .col-md-4.submit
35
+ = submit_tag t('helpers.actions.search'), class: 'btn btn-primary'
@@ -5,14 +5,15 @@
5
5
  - tabs = get_collection
6
6
  .page-header
7
7
  .row
8
- - search_render_show = searchable_model?(model_class) || decorator_class(model_class).list_filters.any?
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
12
12
  = link_to fa_icon(:plus), new_current_model_record_path, class: 'btn btn-primary'
13
13
  - if defined? Tramway::Export::Engine
14
14
  = render 'tramway/export/button'
15
- = render 'search', model_class: model_class
15
+ .col
16
+ = render 'search', model_class: model_class
16
17
  %hr
17
18
  %ul.nav.nav-tabs
18
19
  - if params[:search].present?
@@ -4,5 +4,6 @@
4
4
  %td
5
5
  = value
6
6
  %td
7
- - if attribute_name.to_s != 'state' && object.model.class.state_machines.keys.include?(attribute_name.to_sym)
8
- = 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 }
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'
@@ -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.to_s
12
+ @available_models[project][role].merge! model
13
13
  end
14
14
  end
15
15
  @available_models = @available_models.with_indifferent_access
@@ -0,0 +1,5 @@
1
+ module Tramway::Admin::TramwayModelHelper
2
+ def tramway_model?(model_class)
3
+ model_class.ancestors.include? Tramway::Core::ApplicationRecord
4
+ end
5
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Admin
5
- VERSION = '1.32.2.5'
5
+ VERSION = '1.33.1.2'
6
6
  end
7
7
  end
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.2.5
4
+ version: 1.33.1.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-12-23 00:00:00.000000000 Z
11
+ date: 2021-02-02 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.3.5
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.3.5
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