tramway-admin 1.33 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd63c513ef46a0b0b80b96cc51f28c1ba69f1bc70c5e426da288887f4885cad7
4
- data.tar.gz: '03884d0741244a9d7d33b0716c351fa68c05f9df09eb8a6b16994315c2940cfc'
3
+ metadata.gz: 5390a8ac2ff22518ce7381eda5eec47f0ede410e0cdcbcbf2ad4577a2e6d7869
4
+ data.tar.gz: 1599e0b6a50ef1f67df55a47d22ce29dc7438bf35d19f127d373d3594de9248a
5
5
  SHA512:
6
- metadata.gz: 560e2d59668bfe3559a225dc03163bf2a61f032600e05568456d1c10ee97a7a6c0375c1ade4358fa5a536572582ed3c51c27a6f1cf144c433e3db3aaca254157
7
- data.tar.gz: 61e0eda22ab3383e748a451a997303d9bd9130e23a7bb6575c056598838994a598642ee5ebcbc748464e47208ef67ba79c26973bea16e50846ff198336cce507
6
+ metadata.gz: 296ebeca8c4c69f989c4240e3348f2ec47c77f29d8a2066eb9ce233479e78241f29da09619de0d228332d3cef79f299bc9229008bfa841ca7629d0d782b43cc7
7
+ data.tar.gz: 8fe4ca13d159e6953157ed082caf92a5b5aede82aca7ac609cc00a24be067d3e580c9b1c3625b5736414504bb3a53bd4667cd7704a880c11750155e501366306
data/README.md CHANGED
@@ -10,7 +10,6 @@ How to use my plugin.
10
10
  *Gemfile*
11
11
  ```ruby
12
12
  gem 'tramway-admin'
13
- gem 'tramway-auth'
14
13
  gem 'tramway-user'
15
14
  gem 'state_machine', github: 'seuros/state_machine'
16
15
  gem 'bcrypt'
@@ -239,7 +238,6 @@ class YourModel < Tramway::Core::ApplicationRecord
239
238
  #### 12. Run server `rails s`
240
239
  #### 13. Launch `localhost:3000/admin`
241
240
 
242
-
243
241
  ### CRUDs for models
244
242
 
245
243
  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 +391,64 @@ window.current_locale = window.i18n_locale 'en'
393
391
  ```
394
392
  to the `app/assets/javascripts/admin/application.js.coffee` file
395
393
 
394
+ ### Decorator Helper methods
395
+
396
+ #### date_view
397
+ Returns a date in the format depending on localization
398
+
399
+ *app/decorators/\*_decorator.rb*
400
+ ```ruby
401
+ def created_at
402
+ date_view object.created_at
403
+ end
404
+ ```
405
+ #### datetime_view
406
+ Returns a date and time in the format depending on localization
407
+
408
+ *app/decorators/*_decorator.rb*
409
+ ```ruby
410
+ def created_at
411
+ datetime_view object.created_at
412
+ end
413
+ ```
414
+ #### state_machine_view
415
+ Returns the state of an object according to a state machine
416
+
417
+ *app/decorators/*_decorator.rb*
418
+ ```ruby
419
+ def state
420
+ state_machine_view object, :state
421
+ end
422
+ ```
423
+ #### image_view
424
+ Returns an image in a particular format depending on the parameters of the original image file
425
+
426
+ *app/decorators/\*_decorator.rb*
427
+ ```ruby
428
+ def avatar
429
+ image_view object.avatar
430
+ end
431
+ ```
432
+ #### enumerize_view
433
+ Returns object enumerations as text
434
+
435
+ *app/decorators/\*_decorator.rb*
436
+ ```ruby
437
+ def field_type
438
+ enumerize_view object.field_type
439
+ end
440
+ ```
441
+
442
+ #### file_view
443
+ Returns file name and button to download it
444
+
445
+ *app/decorators/\*_decorator.rb*
446
+ ```ruby
447
+ def file_download
448
+ file_view object.file
449
+ end
450
+ ```
451
+
396
452
  ## Notifications
397
453
 
398
454
  You can add notification to your admin panel to the navbar.
@@ -480,7 +536,7 @@ Tramway uses [audited](https://github.com/collectiveidea/audited) to log actions
480
536
  #### 1. Add Audited::Audit model to available models
481
537
 
482
538
  *config/initializers/tramway.rb*
483
- ```
539
+ ```ruby
484
540
  Tramway::Admin.set_available_models(
485
541
  Audited::Audit,
486
542
  project: :your_project_name
@@ -489,7 +545,7 @@ Tramway::Admin.set_available_models(
489
545
 
490
546
  #### 2. Add this model to navbar
491
547
 
492
- ```
548
+ ```ruby
493
549
  Tramway::Admin.set_navbar_structure(
494
550
  Audited::Audit,
495
551
  project: :your_project_name
@@ -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
@@ -52,16 +52,22 @@ class Tramway::Admin::RecordsController < ::Tramway::Admin::ApplicationControlle
52
52
 
53
53
  def update
54
54
  @record_form = admin_form_class.new model_class.active.find params[:id]
55
- if @record_form.submit params[:record]
56
- redirect_to params[:redirect].present? ? params[:redirect] : record_path(@record_form.model)
55
+ if params[:record][:aasm_event].present?
56
+ if @record_form.model.send("may_#{params[:record][:aasm_event]}?")
57
+ @record_form.model.send("#{params[:record][:aasm_event]}!")
58
+ end
57
59
  else
58
- render :edit
60
+ if @record_form.submit params[:record]
61
+ redirect_to params[:redirect].present? ? params[:redirect] : record_path(@record_form.model)
62
+ else
63
+ render :edit
64
+ end
59
65
  end
60
66
  end
61
67
 
62
68
  def destroy
63
69
  record = model_class.active.find params[:id]
64
- record.remove
70
+ record.remove!
65
71
  redirect_to params[:redirect].present? ? params[:redirect] : records_path
66
72
  end
67
73
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  class Tramway::User::User < ::Tramway::Core::ApplicationRecord
4
4
  has_secure_password # FIXME: remove repeating from tramway-user
5
+ include ::AASM
5
6
 
6
7
  enumerize :role, in: %i[user admin], default: :admin
7
8
 
@@ -28,7 +28,7 @@
28
28
  %br
29
29
  %br
30
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 }
31
+ - record.model.class.state_machines_names.each do |state_machine_name|
32
+ - unless state_machine_name == 'default'
33
+ = state_events_buttons record, state_method: state_machine_name, 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 }
34
34
  = paginate @records, theme: 'twitter-bootstrap-4'
@@ -1,9 +1,10 @@
1
1
  - if searchable_model?(model_class) || is_there_any_filters?(model_class)
2
- .col-md-8
3
- .search
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'
@@ -12,7 +12,8 @@
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?
@@ -5,5 +5,5 @@
5
5
  = value
6
6
  %td
7
7
  - if tramway_model?(model_class)
8
- - if attribute_name.to_s != 'state' && object.model.class.state_machines.keys.include?(attribute_name.to_sym)
8
+ - if attribute_name.to_s != 'state' && object.model.class.aasm.states.map(&:name).include?(attribute_name.to_sym)
9
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 }
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Admin
5
- VERSION = '1.33'
5
+ VERSION = '2.0'
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.33'
4
+ version: '2.0'
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-04 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
@@ -196,6 +196,20 @@ dependencies:
196
196
  - - '='
197
197
  - !ruby/object:Gem::Version
198
198
  version: '3.0'
199
+ - !ruby/object:Gem::Dependency
200
+ name: aasm
201
+ requirement: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ type: :runtime
207
+ prerelease: false
208
+ version_requirements: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
199
213
  - !ruby/object:Gem::Dependency
200
214
  name: pg
201
215
  requirement: !ruby/object:Gem::Requirement