tramway-admin 1.26.1.3 → 1.27
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 +8 -0
- data/app/controllers/tramway/admin/application_controller.rb +6 -2
- data/app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb +21 -0
- data/app/controllers/tramway/admin/welcome_controller.rb +1 -1
- data/app/helpers/tramway/admin/actions_helper.rb +15 -0
- data/app/helpers/tramway/admin/application_helper.rb +1 -0
- data/app/views/tramway/admin/shared/_show.html.haml +4 -2
- data/app/views/tramway/admin/shared/show/associations/_habtm_row.html.haml +11 -0
- data/app/views/tramway/admin/shared/show/associations/_list.html.haml +18 -0
- data/app/views/tramway/admin/shared/show/associations/_row.html.haml +8 -0
- data/config/routes.rb +1 -0
- data/lib/tramway/admin.rb +3 -1
- data/lib/tramway/admin/forms.rb +3 -0
- data/lib/tramway/admin/navbar.rb +2 -0
- data/lib/tramway/admin/records_models.rb +1 -1
- data/lib/tramway/admin/singleton_models.rb +1 -1
- data/lib/tramway/admin/version.rb +1 -1
- data/lib/tramway/admin/welcome_page_actions.rb +2 -0
- metadata +8 -3
- data/app/views/tramway/admin/shared/show/_associations.html.haml +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 60b354696526340affbff03705102d68483b44d47961a4a8670b7c31e83fcb44
|
|
4
|
+
data.tar.gz: 5eb95f5f0ff81ebf58943bf158fd95b72d45bf92fb001a656db86bcb746d82a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ceb8b3016c5aa58f01e55841670dae17bb547ef05c4b82bf567ba624cc6a9221348fbc3542e61b02813a6beb5c7e9fc003cecd5ed1d5b0a3221f3b7d462470d8
|
|
7
|
+
data.tar.gz: b7783ff8430c982ae818c0bd8fb2e74ae91b90b3fab8d7bcfef083d6cd1c21b34731ec1be934aeb95fdb23c9e9cf2daa518b14a00eef2fbdd10998bf43cb3931
|
data/README.md
CHANGED
|
@@ -202,6 +202,14 @@ To add notification to application, you need just set queries in initializers.
|
|
|
202
202
|
end
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
+
**NOTE:** Proc with `current_user` argument is expecting. If you don't need `current_user`, just name do something like that:
|
|
206
|
+
|
|
207
|
+
```ruby
|
|
208
|
+
::Tramway::Admin.set_notificable_queries new_participants: -> (_current_user) do
|
|
209
|
+
# some code which does not need current_user
|
|
210
|
+
end
|
|
211
|
+
```
|
|
212
|
+
|
|
205
213
|
## Admin Main Page management
|
|
206
214
|
|
|
207
215
|
Start page of admin panel contains only `application.name` by default. To manage it just set `Tramway::Admin.welcome_page_actions` with some lambda and set `@content` variable with HTML.
|
|
@@ -21,7 +21,7 @@ module Tramway
|
|
|
21
21
|
protected
|
|
22
22
|
|
|
23
23
|
def check_available!
|
|
24
|
-
raise 'Model is not available'
|
|
24
|
+
raise 'Model or Form is not available' if !model_given? && !form_given?
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def check_available_scope!
|
|
@@ -68,7 +68,7 @@ module Tramway
|
|
|
68
68
|
include Tramway::ClassNameHelpers
|
|
69
69
|
|
|
70
70
|
def model_class
|
|
71
|
-
model_class_name(params[:model])
|
|
71
|
+
model_class_name(params[:model] || params[:form])
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
def decorator_class
|
|
@@ -83,6 +83,10 @@ module Tramway
|
|
|
83
83
|
available_models_given? || singleton_models_given?
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
+
def form_given?
|
|
87
|
+
Tramway::Admin.forms.include? params[:form].underscore.sub(/^admin\//, '').sub(/_form$/, '')
|
|
88
|
+
end
|
|
89
|
+
|
|
86
90
|
def available_scope_given?
|
|
87
91
|
params[:scope].present? && params[:scope].in?(decorator_class.collections.map(&:to_s))
|
|
88
92
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class Tramway::Admin::HasAndBelongsToManyRecordsController < ::Tramway::Admin::ApplicationController
|
|
2
|
+
def create
|
|
3
|
+
base_object = params[:model_class].constantize.find params[:object_id]
|
|
4
|
+
record_form = params[:form].constantize.new base_object
|
|
5
|
+
if record_form.submit params[params[:model_class].underscore]
|
|
6
|
+
redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
|
|
7
|
+
else
|
|
8
|
+
redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def destroy
|
|
13
|
+
base_object = params[:model_class].constantize.find params[:object_id]
|
|
14
|
+
record_form = params[:form].constantize.new base_object
|
|
15
|
+
if record_form.submit params[:id]
|
|
16
|
+
redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
|
|
17
|
+
else
|
|
18
|
+
redirect_to params[:redirect].present? ? params[:redirect] : record_path(base_object, model: base_object.class)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -4,6 +4,6 @@ class Tramway::Admin::WelcomeController < Tramway::Admin::ApplicationController
|
|
|
4
4
|
skip_before_action :check_available!
|
|
5
5
|
|
|
6
6
|
def index
|
|
7
|
-
|
|
7
|
+
instance_exec(&::Tramway::Admin.welcome_page_actions) if ::Tramway::Admin.welcome_page_actions.present?
|
|
8
8
|
end
|
|
9
9
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Tramway::Admin::ActionsHelper
|
|
2
|
+
def destroy_is_available?(association_object, main_object)
|
|
3
|
+
::Tramway::Admin.action_is_available?(
|
|
4
|
+
association_object,
|
|
5
|
+
project: (@application_engine || @application.name),
|
|
6
|
+
model: association_object.model.class,
|
|
7
|
+
role: current_user.role,
|
|
8
|
+
action: :destroy
|
|
9
|
+
)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def habtm_destroy_is_available?(association_object, main_object)
|
|
13
|
+
::Tramway::Admin.forms.include?("#{main_object.model.class.to_s.underscore.pluralize}/remove_#{association_object.model.class.to_s.underscore}")
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -14,6 +14,7 @@ module Tramway
|
|
|
14
14
|
include ::Tramway::Admin::NavbarHelper
|
|
15
15
|
include ::Tramway::Admin::InputsHelper
|
|
16
16
|
include ::Tramway::Admin::FocusGeneratorHelper
|
|
17
|
+
include ::Tramway::Admin::ActionsHelper
|
|
17
18
|
include ::Tramway::Collections::Helper
|
|
18
19
|
include ::Tramway::Core::CopyToClipboardHelper
|
|
19
20
|
|
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
- object.attributes.each do |attribute_name, value|
|
|
27
27
|
= render 'tramway/admin/shared/show/attribute_tr', attribute_name: attribute_name, value: value, object: object
|
|
28
28
|
- object.associations(:has_one).each do |association|
|
|
29
|
-
= render 'tramway/admin/shared/show/associations', object: object, association: association
|
|
29
|
+
= render 'tramway/admin/shared/show/associations/row', object: object, association: association
|
|
30
30
|
- object.associations(:has_many).each do |association|
|
|
31
|
-
= render 'tramway/admin/shared/show/associations', object: object, association: association
|
|
31
|
+
= render 'tramway/admin/shared/show/associations/row', object: object, association: association
|
|
32
|
+
- object.associations(:has_and_belongs_to_many).each do |association|
|
|
33
|
+
= render 'tramway/admin/shared/show/associations/habtm_row', object: object, association: association
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
- if object.class.show_associations.map(&:to_s).include? association.name.to_s
|
|
2
|
+
%tr
|
|
3
|
+
%td
|
|
4
|
+
= model_class.human_attribute_name association.name
|
|
5
|
+
%hr
|
|
6
|
+
- association_form = object.send("add_#{association.name}_form")
|
|
7
|
+
= simple_form_for association_form, url: { controller: :has_and_belongs_to_many_records, action: :create, form: association_form.class, model_class: model_class, object_id: object.id }, method: :post do |f|
|
|
8
|
+
= f.association association_form.associations.first, label: false
|
|
9
|
+
= f.button :submit, "#{I18n.t('helpers.actions.add')} #{model_class.human_attribute_name(association.name).singularize.downcase}", class: 'btn-success'
|
|
10
|
+
%td{ colspan: 2 }
|
|
11
|
+
= render 'tramway/admin/shared/show/associations/list', object: object, association: association
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
- association_state_machines = object.send("#{association.name}_state_machines")
|
|
2
|
+
%table.table.table-striped.table-bordered
|
|
3
|
+
- object.send(association.name)&.each do |association_object|
|
|
4
|
+
%tr{ id: "#{association.name}_#{association_object.id}" }
|
|
5
|
+
%td
|
|
6
|
+
= association_object.id
|
|
7
|
+
%td
|
|
8
|
+
= link_to association_object.name, record_path(association_object.id, model: association.options[:class_name])
|
|
9
|
+
%td
|
|
10
|
+
- association_state_machines.each do |state_method|
|
|
11
|
+
= state_events_buttons association_object, state_method: state_method, model_param_name: :record, controller: 'tramway/admin/records', action: :update, parameters: { redirect: current_model_record_path(object.id), model: association_object.class.model_name }, button_options: { class: :smart_button }
|
|
12
|
+
%td
|
|
13
|
+
- if destroy_is_available? association_object, object
|
|
14
|
+
= delete_button url: record_path(association_object.id, model: association.options[:class_name], redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-danger delete' } do
|
|
15
|
+
= fa_icon 'trash-alt'
|
|
16
|
+
- if habtm_destroy_is_available? association_object, object
|
|
17
|
+
= delete_button url: has_and_belongs_to_many_record_path(association_object.id, model_class: object.model.class, object_id: object.id, form: "Admin::#{object.model.class.to_s.pluralize}::Remove#{association_object.model.class.to_s}Form", redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-danger delete' } do
|
|
18
|
+
= fa_icon 'trash-alt'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
- if object.class.show_associations.map(&:to_s).include? association.name.to_s
|
|
2
|
+
%tr
|
|
3
|
+
%td
|
|
4
|
+
= model_class.human_attribute_name association.name
|
|
5
|
+
%hr
|
|
6
|
+
= link_to "#{I18n.t('helpers.actions.add')} #{model_class.human_attribute_name(association.name).singularize.downcase}", new_associated_record_path(association: association, object: object, as: object.send("#{association.name}_as")), class: 'btn btn-primary'
|
|
7
|
+
%td{ colspan: 2 }
|
|
8
|
+
= render 'tramway/admin/shared/show/associations/list', object: object, association: association
|
data/config/routes.rb
CHANGED
data/lib/tramway/admin.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require 'tramway/admin/engine'
|
|
4
4
|
require 'tramway/admin/singleton_models'
|
|
5
5
|
require 'tramway/admin/records_models'
|
|
6
|
+
require 'tramway/admin/forms'
|
|
6
7
|
require 'tramway/admin/additional_buttons'
|
|
7
8
|
require 'tramway/admin/notifications'
|
|
8
9
|
require 'tramway/admin/welcome_page_actions'
|
|
@@ -17,6 +18,7 @@ module Tramway
|
|
|
17
18
|
include ::Tramway::Admin::RecordsModels
|
|
18
19
|
include ::Tramway::Admin::SingletonModels
|
|
19
20
|
include ::Tramway::Admin::AdditionalButtons
|
|
21
|
+
include ::Tramway::Admin::Forms
|
|
20
22
|
include ::Tramway::Admin::Notifications
|
|
21
23
|
include ::Tramway::Admin::WelcomePageActions
|
|
22
24
|
include ::Tramway::Admin::Navbar
|
|
@@ -55,7 +57,7 @@ module Tramway
|
|
|
55
57
|
return false unless availability.present?
|
|
56
58
|
return true if availability.is_a? Symbol
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
availability.values.first.call record
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
def select_actions(project:, role:, model:)
|
data/lib/tramway/admin/navbar.rb
CHANGED
|
@@ -7,7 +7,7 @@ module Tramway::Admin::RecordsModels
|
|
|
7
7
|
@available_models[project][role] ||= {}
|
|
8
8
|
models.each do |model|
|
|
9
9
|
if model.class == Class
|
|
10
|
-
@available_models[project][role].merge! model => [
|
|
10
|
+
@available_models[project][role].merge! model => %i[index show update create destroy]
|
|
11
11
|
elsif model.class == Hash
|
|
12
12
|
@available_models[project][role].merge! model
|
|
13
13
|
end
|
|
@@ -7,7 +7,7 @@ module Tramway::Admin::SingletonModels
|
|
|
7
7
|
@singleton_models[project][role] ||= {}
|
|
8
8
|
models.each do |model|
|
|
9
9
|
if model.class == Class
|
|
10
|
-
@singleton_models[project][role].merge! model => [
|
|
10
|
+
@singleton_models[project][role].merge! model => %i[index show update create destroy]
|
|
11
11
|
elsif model.class == Hash
|
|
12
12
|
@singleton_models[project][role].merge! model
|
|
13
13
|
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.
|
|
4
|
+
version: '1.27'
|
|
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-03-
|
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bootstrap-kaminari-views
|
|
@@ -181,10 +181,12 @@ files:
|
|
|
181
181
|
- app/assets/javascripts/tramway/admin/focus.js
|
|
182
182
|
- app/assets/stylesheets/tramway/admin/application.sass
|
|
183
183
|
- app/controllers/tramway/admin/application_controller.rb
|
|
184
|
+
- app/controllers/tramway/admin/has_and_belongs_to_many_records_controller.rb
|
|
184
185
|
- app/controllers/tramway/admin/records_controller.rb
|
|
185
186
|
- app/controllers/tramway/admin/singletons_controller.rb
|
|
186
187
|
- app/controllers/tramway/admin/welcome_controller.rb
|
|
187
188
|
- app/controllers/tramway/export/application_controller.rb
|
|
189
|
+
- app/helpers/tramway/admin/actions_helper.rb
|
|
188
190
|
- app/helpers/tramway/admin/additional_buttons_builder.rb
|
|
189
191
|
- app/helpers/tramway/admin/application_helper.rb
|
|
190
192
|
- app/helpers/tramway/admin/cases_helper.rb
|
|
@@ -209,8 +211,10 @@ files:
|
|
|
209
211
|
- app/views/tramway/admin/shared/_input.html.haml
|
|
210
212
|
- app/views/tramway/admin/shared/_show.html.haml
|
|
211
213
|
- app/views/tramway/admin/shared/errors/server_error.html.haml
|
|
212
|
-
- app/views/tramway/admin/shared/show/_associations.html.haml
|
|
213
214
|
- app/views/tramway/admin/shared/show/_attribute_tr.html.haml
|
|
215
|
+
- app/views/tramway/admin/shared/show/associations/_habtm_row.html.haml
|
|
216
|
+
- app/views/tramway/admin/shared/show/associations/_list.html.haml
|
|
217
|
+
- app/views/tramway/admin/shared/show/associations/_row.html.haml
|
|
214
218
|
- app/views/tramway/admin/singletons/_form.html.haml
|
|
215
219
|
- app/views/tramway/admin/singletons/edit.html.haml
|
|
216
220
|
- app/views/tramway/admin/singletons/new.html.haml
|
|
@@ -229,6 +233,7 @@ files:
|
|
|
229
233
|
- lib/tramway/admin.rb
|
|
230
234
|
- lib/tramway/admin/additional_buttons.rb
|
|
231
235
|
- lib/tramway/admin/engine.rb
|
|
236
|
+
- lib/tramway/admin/forms.rb
|
|
232
237
|
- lib/tramway/admin/navbar.rb
|
|
233
238
|
- lib/tramway/admin/notifications.rb
|
|
234
239
|
- lib/tramway/admin/record_routes_helper.rb
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
- if object.class.show_associations.map(&:to_s).include? association.name.to_s
|
|
2
|
-
%tr
|
|
3
|
-
%td
|
|
4
|
-
= model_class.human_attribute_name association.name
|
|
5
|
-
%hr
|
|
6
|
-
= link_to "#{I18n.t('helpers.actions.add')} #{model_class.human_attribute_name(association.name).singularize.downcase}", new_associated_record_path(association: association, object: object, as: object.send("#{association.name}_as")), class: 'btn btn-primary'
|
|
7
|
-
- association_state_machines = object.send("#{association.name}_state_machines")
|
|
8
|
-
%td{ colspan: 2 }
|
|
9
|
-
%table.table.table-striped.table-bordered
|
|
10
|
-
- object.send(association.name)&.each do |association_object|
|
|
11
|
-
%tr{ id: "#{association.name}_#{association_object.id}" }
|
|
12
|
-
%td
|
|
13
|
-
= association_object.id
|
|
14
|
-
%td
|
|
15
|
-
= link_to association_object.name, record_path(association_object.id, model: association.options[:class_name])
|
|
16
|
-
%td
|
|
17
|
-
- association_state_machines.each do |state_method|
|
|
18
|
-
= state_events_buttons association_object, state_method: state_method, model_param_name: :record, controller: 'tramway/admin/records', action: :update, parameters: { redirect: current_model_record_path(object.id), model: association_object.class.model_name }, button_options: { class: :smart_button }
|
|
19
|
-
%td
|
|
20
|
-
- if ::Tramway::Admin.action_is_available?(association_object, project: (@application_engine || @application.name), model: association_object.model.class, role: current_user.role, action: :destroy)
|
|
21
|
-
= delete_button url: record_path(association_object.id, model: association.options[:class_name], redirect: current_model_record_path(object.id)), button_options: { class: 'btn btn-xs btn-danger delete' } do
|
|
22
|
-
= fa_icon 'trash-alt'
|