rao-resources_controller 0.0.42.pre → 0.0.47.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/app/concerns/rao/resources_controller/aasm_concern.rb +30 -0
  3. data/app/concerns/rao/resources_controller/batch_actions_concern.rb +5 -1
  4. data/app/views/rao/resources_controller/base/{_after_show_table.haml → _after_show_table.html.haml} +0 -0
  5. data/app/views/rao/resources_controller/base/{_before_index_table.haml → _before_index_table.html.haml} +0 -0
  6. data/app/views/rao/resources_controller/base/{_before_show_table.haml → _before_show_table.html.haml} +0 -0
  7. data/app/views/rao/resources_controller/base/{_form.haml → _form.html.haml} +0 -0
  8. data/app/views/rao/resources_controller/base/_form_buttons.html.haml +5 -0
  9. data/app/views/rao/resources_controller/base/{_form_errors.haml → _form_errors.html.haml} +1 -1
  10. data/app/views/rao/resources_controller/base/{_pagination.haml → _pagination.html.haml} +0 -0
  11. data/app/views/rao/resources_controller/base/{_show.haml → _show.html.haml} +0 -0
  12. data/app/views/rao/resources_controller/base/_show_actions.html.haml +11 -0
  13. data/app/views/rao/resources_controller/base/{_table.haml → _table.html.haml} +0 -0
  14. data/app/views/rao/resources_controller/base/_table_actions.html.haml +12 -0
  15. data/app/views/rao/resources_controller/base/{edit.haml → edit.html.haml} +1 -1
  16. data/app/views/rao/resources_controller/base/{index.haml → index.html.haml} +2 -2
  17. data/app/views/rao/resources_controller/base/{new.haml → new.html.haml} +1 -1
  18. data/app/views/rao/resources_controller/base/{show.haml → show.html.haml} +1 -1
  19. data/config/locales/de.yml +9 -2
  20. data/config/locales/en.yml +9 -2
  21. data/lib/generators/rao/resources_controller/templates/initializer.rb +16 -0
  22. data/lib/rao/resources_controller.rb +3 -0
  23. data/lib/rao/resources_controller/configuration.rb +17 -3
  24. data/{app/concerns → lib}/rao/resources_controller/routing/acts_as_list_concern.rb +0 -0
  25. data/{app/concerns → lib}/rao/resources_controller/routing/acts_as_published_concern.rb +0 -0
  26. metadata +21 -20
  27. data/app/views/rao/resources_controller/base/_form_buttons.haml +0 -5
  28. data/app/views/rao/resources_controller/base/_show_actions.haml +0 -11
  29. data/app/views/rao/resources_controller/base/_table_actions.haml +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 225265f8be85ba6e2675e209908e36bc57e9dd1ccc1cfcd26c160f0cb55cd810
4
- data.tar.gz: 687cd0d960e38566ff3adcfe4ddebd840d7839f96cbea947a9d440c5c103803d
3
+ metadata.gz: 2371783ce441bfb7c74932bdff959429ebb65d251cde9ca97cc08af007a4a2e1
4
+ data.tar.gz: e2c107624566431ebe89eaa98e4233d3cdf43a77db53fa1ef99cf0bb6086990a
5
5
  SHA512:
6
- metadata.gz: 1f9c2cae5e41e3b96fa11da8d7ddaec198fb4afaa291e7da05a74286ee0fa6731cfac1dd3b4c1004f9cbe061bd0d91bed0d7286ceee782672ca0bc7c642a6511
7
- data.tar.gz: f10056f3297ce576e18a71525966d1804e126cbf04f0b2b1dcb0f7f7e0b5c3f404d12272e7a038f4f4ceb472648d514b9b7117afc0be611587bfcea984a3518e
6
+ metadata.gz: 3d76366e6030fd7f2e634a28b777d571af999ccde43dac26a63fb3269038d2c8d2cd90a1037809d6ddf00f9a2699ff5dbd6e1f17620206a5739b7d9bffaf3efd
7
+ data.tar.gz: c19cb5464ccba957c86c525bbda7bfcaa713fcd28a420a3968176e7e95e3e90f7c23b1efd6ab6bce5ad1c8a7362e275ca6ccfacd8ccffee63e2dfee4d5ea650c
@@ -0,0 +1,30 @@
1
+ module Rao
2
+ module ResourcesController
3
+ module AasmConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_action :load_resource_for_trigger_event, only: [:trigger_event]
8
+ end
9
+
10
+ def trigger_event
11
+ if @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).fire!(permitted_params_for_trigger_event[:event_name].to_sym)
12
+ flash[:notice] = t('rao.resources_controller.aasm_concern.trigger_event.success', state: @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).current_state, event: permitted_params_for_trigger_event[:event_name])
13
+ else
14
+ flash[:notice] = t('rao.resources_controller.aasm_concern.trigger_event.failure', state: @resource.aasm(permitted_params_for_trigger_event[:machine_name].to_sym).current_state, event: permitted_params_for_trigger_event[:event_name])
15
+ end
16
+ redirect_back(fallback_location: root_path)
17
+ end
18
+
19
+ private
20
+
21
+ def permitted_params_for_trigger_event
22
+ params.permit!
23
+ end
24
+
25
+ def load_resource_for_trigger_event
26
+ load_resource
27
+ end
28
+ end
29
+ end
30
+ end
@@ -9,9 +9,13 @@ module Rao
9
9
  module ResourcesController::BatchActionsConcern
10
10
  def destroy_many
11
11
  @collection = load_collection_scope.where(id: params[:ids])
12
+ count = @collection.count
12
13
  @collection.destroy_all
13
14
 
14
- respond_with @collection, location: after_destroy_many_location, notice: t('.success', count: @collection.count)
15
+ default_message = t('.success', inflections.merge(count: count))
16
+ respond_with @collection,
17
+ location: after_destroy_many_location,
18
+ notice: t('rao.resources_controller.batch_actions_concern.destroy_many.success', inflections.merge(count: count, default: default_message))
15
19
  end
16
20
 
17
21
  private
@@ -0,0 +1,5 @@
1
+ = form.button :submit, class: 'btn btn-success' do
2
+ = fa_icon :check
3
+ = t('.submit', model_name: form.object.model_name.human)
4
+ = link_to(((action_name == 'new' || form.object.new_record?) ? collection_path : resource_path(form.object)), class: 'btn btn-link') do
5
+ = t('.cancel')
@@ -1,5 +1,5 @@
1
1
  - if resource.errors.any?
2
- = bootstrap_alert(context: :danger, class: 'error-explanation') do
2
+ .alert.alert-danger.error-explanation
3
3
  .error-heading= t('errors.template.header', count: resource.errors.count, model: resource.class.model_name.human)
4
4
  %ul
5
5
  - resource.errors.full_messages.each do |msg|
@@ -0,0 +1,11 @@
1
+ .btn-group
2
+ = link_to(edit_resource_path(resource), class: 'btn btn-secondary') do
3
+ %i.fas.fa-edit
4
+ = t('.edit')
5
+
6
+ = link_to(resource_path(resource), class: 'btn btn-danger', method: :delete, data: { confirm: t('.destroy_confirmation') }) do
7
+ %i.fas.fa-trash
8
+ = t('.destroy')
9
+
10
+ = link_to(collection_path, class: 'btn btn-link') do
11
+ = t('.back')
@@ -0,0 +1,12 @@
1
+ = table.column :actions, title: '' do |resource|
2
+ - capture_haml do
3
+ .btn-group
4
+ = link_to(resource_path(resource), class: 'btn btn-sm btn-primary') do
5
+ %i.fas.fa-eye
6
+ = t('.show')
7
+ = link_to(edit_resource_path(resource), class: 'btn btn-sm btn-secondary') do
8
+ %i.fas.fa-edit
9
+ = t('.edit')
10
+ = link_to(resource_path(resource), class: 'btn btn-sm btn-danger', method: :delete, data: { confirm: t('.destroy_confirmation') }) do
11
+ %i.fas.fa-trash
12
+ = t('.destroy')
@@ -1,6 +1,6 @@
1
1
  %h1= t('.title', inflections)
2
2
 
3
- = bootstrap_form_for(@resource, url: resource_path(@resource)) do |f|
3
+ = simple_form_for(@resource, url: resource_path(@resource)) do |f|
4
4
  = render 'form_errors', resource: f.object
5
5
  = render 'form', form: f
6
6
  = render 'form_buttons', form: f
@@ -2,8 +2,8 @@
2
2
  %span
3
3
  = resource_class.model_name.human(count: :other)
4
4
  .pull-right
5
- = bootstrap_button(to: new_resource_path, context: :success) do
6
- = fa_icon(:plus)
5
+ = link_to(new_resource_path, class: 'btn btn-success') do
6
+ %i.fas.fa-plus
7
7
  = t('.new')
8
8
 
9
9
  = render 'before_index_table', collection: @collection
@@ -1,6 +1,6 @@
1
1
  %h1= t('.title', inflections)
2
2
 
3
- = bootstrap_form_for(@resource, url: collection_path) do |f|
3
+ = simple_form_for(@resource, url: collection_path) do |f|
4
4
  = render 'form_errors', resource: f.object
5
5
  = render 'form', form: f
6
6
  = render 'form_buttons', form: f
@@ -1,4 +1,4 @@
1
- %h1= @resource.try_all(:human, :title, :name, :to_s)
1
+ %h1= Rao::ResourcesController::Configuration.label_for_resource_proc.call(@resource)
2
2
 
3
3
  = render 'before_show_table', resource: @resource
4
4
 
@@ -32,6 +32,9 @@ de:
32
32
  alert: "%{resource_name} konnte nicht ausgeführt werden. Es traten folgende Fehler auf: %{errors}"
33
33
  rao:
34
34
  resources_controller:
35
+ aasm_concern:
36
+ trigger_event:
37
+ success: "Der Vorgang %{event} war erfolgreich. Der neue Status ist %{state}."
35
38
  base:
36
39
  form_buttons:
37
40
  cancel: "Abbrechen"
@@ -43,5 +46,9 @@ de:
43
46
  title: "%{resource_name} erstellen"
44
47
  show_actions:
45
48
  back: "Zurück"
46
- delete: "Löschen"
47
- edit: "Bearbeiten"
49
+ destroy: "Löschen"
50
+ destroy_confirmation: "Sind Sie sicher?"
51
+ edit: "Bearbeiten"
52
+ batch_actions_concern:
53
+ destroy_many:
54
+ success: "%{count} %{collection_name} wurden gelöscht."
@@ -32,6 +32,9 @@ en:
32
32
  alert: "%{resource_name} could not be executed. Errors: %{errors}"
33
33
  rao:
34
34
  resources_controller:
35
+ aasm_concern:
36
+ trigger_event:
37
+ success: "The event %{event} completed successfully. The new state is %{state}."
35
38
  base:
36
39
  form_buttons:
37
40
  cancel: "Cancel"
@@ -43,5 +46,9 @@ en:
43
46
  title: "New %{resource_name}"
44
47
  show_actions:
45
48
  back: "Back"
46
- delete: "Delete"
47
- edit: "Edit"
49
+ destroy: "Delete"
50
+ destroy_confirmation: "Are you sure?"
51
+ edit: "Edit"
52
+ batch_actions_concern:
53
+ destroy_many:
54
+ success: "Deleted %{count} %{collection_name}."
@@ -12,4 +12,20 @@ Rao::ResourcesController.configure do |config|
12
12
  # default: config.pagination_per_page_default = 25
13
13
  #
14
14
  config.pagination_per_page_default = 25
15
+
16
+ # Configures how a label will be created for resources.
17
+ #
18
+ # default: config.label_for_resource_proc = lambda do |resource|
19
+ # [:human, :title, :name, :to_s].each do |method_name|
20
+ # next unless resource.respond_to?(method_name)
21
+ # return resource.send(method_name)
22
+ # end
23
+ # end
24
+ #
25
+ config.label_for_resource_proc = lambda do |resource|
26
+ [:human, :title, :name, :to_s].each do |method_name|
27
+ next unless resource.respond_to?(method_name)
28
+ return resource.send(method_name)
29
+ end
30
+ end
15
31
  end
@@ -2,6 +2,9 @@ require "rao/resources_controller/configuration"
2
2
  require "rao/resources_controller/version"
3
3
  require "rao/resources_controller/engine"
4
4
 
5
+ require "rao/resources_controller/routing/acts_as_list_concern"
6
+ require "rao/resources_controller/routing/acts_as_published_concern"
7
+
5
8
  module Rao
6
9
  module ResourcesController
7
10
  extend Configuration
@@ -5,8 +5,22 @@ module Rao
5
5
  yield self
6
6
  end
7
7
 
8
- mattr_accessor(:resources_controller_base_class_name) { "::ApplicationController" }
9
- mattr_accessor(:pagination_per_page_default) { 25 }
8
+ mattr_accessor(:resources_controller_base_class_name) do
9
+ "::ApplicationController"
10
+ end
11
+
12
+ mattr_accessor(:pagination_per_page_default) do
13
+ 25
14
+ end
15
+
16
+ mattr_accessor(:label_for_resource_proc) do
17
+ lambda do |resource|
18
+ [:human, :title, :name, :to_s].each do |method_name|
19
+ next unless resource.respond_to?(method_name)
20
+ return resource.send(method_name)
21
+ end
22
+ end
23
+ end
10
24
  end
11
25
  end
12
- end
26
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rao-resources_controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.42.pre
4
+ version: 0.0.47.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-20 00:00:00.000000000 Z
11
+ date: 2020-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -147,6 +147,7 @@ files:
147
147
  - README.md
148
148
  - Rakefile
149
149
  - app/concerns/rao/controller/autosubmit_concern.rb
150
+ - app/concerns/rao/resources_controller/aasm_concern.rb
150
151
  - app/concerns/rao/resources_controller/acts_as_list_concern.rb
151
152
  - app/concerns/rao/resources_controller/acts_as_published_concern.rb
152
153
  - app/concerns/rao/resources_controller/awesome_nested_set_concern.rb
@@ -159,26 +160,24 @@ files:
159
160
  - app/concerns/rao/resources_controller/resources_concern.rb
160
161
  - app/concerns/rao/resources_controller/rest_actions_concern.rb
161
162
  - app/concerns/rao/resources_controller/rest_resource_urls_concern.rb
162
- - app/concerns/rao/resources_controller/routing/acts_as_list_concern.rb
163
- - app/concerns/rao/resources_controller/routing/acts_as_published_concern.rb
164
163
  - app/concerns/rao/resources_controller/sorting_concern.rb
165
164
  - app/concerns/rao/resources_controller/will_paginate_concern.rb
166
165
  - app/controllers/rao/resources_controller/base.rb
167
- - app/views/rao/resources_controller/base/_after_show_table.haml
168
- - app/views/rao/resources_controller/base/_before_index_table.haml
169
- - app/views/rao/resources_controller/base/_before_show_table.haml
170
- - app/views/rao/resources_controller/base/_form.haml
171
- - app/views/rao/resources_controller/base/_form_buttons.haml
172
- - app/views/rao/resources_controller/base/_form_errors.haml
173
- - app/views/rao/resources_controller/base/_pagination.haml
174
- - app/views/rao/resources_controller/base/_show.haml
175
- - app/views/rao/resources_controller/base/_show_actions.haml
176
- - app/views/rao/resources_controller/base/_table.haml
177
- - app/views/rao/resources_controller/base/_table_actions.haml
178
- - app/views/rao/resources_controller/base/edit.haml
179
- - app/views/rao/resources_controller/base/index.haml
180
- - app/views/rao/resources_controller/base/new.haml
181
- - app/views/rao/resources_controller/base/show.haml
166
+ - app/views/rao/resources_controller/base/_after_show_table.html.haml
167
+ - app/views/rao/resources_controller/base/_before_index_table.html.haml
168
+ - app/views/rao/resources_controller/base/_before_show_table.html.haml
169
+ - app/views/rao/resources_controller/base/_form.html.haml
170
+ - app/views/rao/resources_controller/base/_form_buttons.html.haml
171
+ - app/views/rao/resources_controller/base/_form_errors.html.haml
172
+ - app/views/rao/resources_controller/base/_pagination.html.haml
173
+ - app/views/rao/resources_controller/base/_show.html.haml
174
+ - app/views/rao/resources_controller/base/_show_actions.html.haml
175
+ - app/views/rao/resources_controller/base/_table.html.haml
176
+ - app/views/rao/resources_controller/base/_table_actions.html.haml
177
+ - app/views/rao/resources_controller/base/edit.html.haml
178
+ - app/views/rao/resources_controller/base/index.html.haml
179
+ - app/views/rao/resources_controller/base/new.html.haml
180
+ - app/views/rao/resources_controller/base/show.html.haml
182
181
  - config/initializers/include_routing_concerns.rb
183
182
  - config/locales/de.yml
184
183
  - config/locales/en.yml
@@ -188,6 +187,8 @@ files:
188
187
  - lib/rao/resources_controller.rb
189
188
  - lib/rao/resources_controller/configuration.rb
190
189
  - lib/rao/resources_controller/engine.rb
190
+ - lib/rao/resources_controller/routing/acts_as_list_concern.rb
191
+ - lib/rao/resources_controller/routing/acts_as_published_concern.rb
191
192
  - lib/rao/resources_controller/version.rb
192
193
  - lib/tasks/rao-resources_controller_tasks.rake
193
194
  homepage: https://github.com/rails-add_ons
@@ -209,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
210
  - !ruby/object:Gem::Version
210
211
  version: 1.3.1
211
212
  requirements: []
212
- rubygems_version: 3.1.3
213
+ rubygems_version: 3.1.4
213
214
  signing_key:
214
215
  specification_version: 4
215
216
  summary: Resources Controllers for Ruby on Rails.
@@ -1,5 +0,0 @@
1
- = form.button :submit, class: 'btn btn-success' do
2
- = fa_icon :check
3
- = t('.submit', model_name: form.object.model_name.human)
4
- = bootstrap_button(to: ((action_name == 'new' || form.object.new_record?) ? collection_path : resource_path(form.object)), context: :link) do
5
- = t('.cancel')
@@ -1,11 +0,0 @@
1
- = bootstrap_button_group do
2
- = bootstrap_button(to: edit_resource_path(resource), context: :secondary) do
3
- = fa_icon(:pencil)
4
- = t('.edit')
5
-
6
- = bootstrap_button(to: resource_path(resource), context: :danger, method: :delete, data: { confirm: 'Are you sure?' }) do
7
- = fa_icon :trash
8
- = t('.destroy')
9
-
10
- = bootstrap_button(to: collection_path, context: :link) do
11
- = t('.back')
@@ -1,12 +0,0 @@
1
- = table.column :actions do |resource|
2
- - capture_haml do
3
- = bootstrap_button_group do
4
- = bootstrap_button(to: resource_path(resource), context: :primary, size: :small) do
5
- = fa_icon :eye
6
- = t('.show')
7
- = bootstrap_button(to: edit_resource_path(resource), context: :secondary, size: :small) do
8
- = fa_icon :pencil
9
- = t('.edit')
10
- = bootstrap_button(to: resource_path(resource), context: :danger, size: :small, method: :delete, data: { confirm: 'Are you sure?' }) do
11
- = fa_icon :trash
12
- = t('.destroy')