tramway-admin 2.0.0.4 → 2.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 +23 -0
- data/app/helpers/tramway/admin/additional_buttons_builder.rb +6 -12
- data/app/views/tramway/admin/shared/_show.html.haml +2 -7
- data/app/views/tramway/admin/shared/show/associations/_row.html.haml +19 -16
- data/lib/tramway/admin.rb +0 -2
- data/lib/tramway/admin/version.rb +1 -1
- metadata +4 -5
- data/lib/tramway/admin/additional_buttons.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efe8998e6d28614e1a7bf88a24ac91cd9635c807db0b1f14c912df66c94bf663
|
4
|
+
data.tar.gz: 4f142c6de6479a892b88b60a29017c7cf791e0c2943e1c8fbb0b038ff279e93c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1187272662360971342253d641daf9b8ab27e218bea93f68b7dda3505bd791ad1d38872c18aea7fa607e8bf1be9d2b1bb4fe1ea4d8fdce96834d4262d66df46
|
7
|
+
data.tar.gz: 53b6d3b617ebbf6b53747d6e56b523fe252466654847902b2735a05969a4a23ff95af6ae08537426ccd46c3471ecaf95fd889ea34e8146b3eb57a7c1a6bb417b
|
data/README.md
CHANGED
@@ -526,6 +526,29 @@ en:
|
|
526
526
|
my_dropdown: Very important dropdown
|
527
527
|
```
|
528
528
|
|
529
|
+
## Additional buttons to the show view
|
530
|
+
|
531
|
+
You can additional buttons to the header of show view of your model. Just add its configuration to the decorator
|
532
|
+
|
533
|
+
*app/decorators/your_model_decorator.rb*
|
534
|
+
```ruby
|
535
|
+
class YourModelDecorator < Tramway::Core::ApplicationDecorator
|
536
|
+
def additional_buttons
|
537
|
+
{
|
538
|
+
show: [ # means that this buttons will be shown on show view only
|
539
|
+
{
|
540
|
+
url: ::Tramway::Export::Engine.routes.url_helpers.export_path(object.id, model: object.class, collection: :tasks),
|
541
|
+
inner: lambda do # inner HTML you want to see in the button
|
542
|
+
fa_icon 'file-excel'
|
543
|
+
end,
|
544
|
+
color: :success # bootstrap button color
|
545
|
+
}
|
546
|
+
]
|
547
|
+
}
|
548
|
+
end
|
549
|
+
end
|
550
|
+
```
|
551
|
+
|
529
552
|
## Errors
|
530
553
|
|
531
554
|
* **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]`
|
@@ -1,17 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Tramway::Admin::AdditionalButtonsBuilder
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
button[:url], method: button[:method], class: "btn btn-#{button[:color]} btn-xs", **options
|
11
|
-
) do
|
12
|
-
button[:text]
|
13
|
-
end
|
14
|
-
)
|
15
|
-
end
|
4
|
+
def build_button(button)
|
5
|
+
options = button[:options] || {}
|
6
|
+
style = 'margin-right: 8px'
|
7
|
+
concat(link_to(button[:url], method: button[:method], class: "btn btn-#{button[:color]} btn-xs", style: style, **options) do
|
8
|
+
button[:inner]&.call
|
9
|
+
end)
|
16
10
|
end
|
17
11
|
end
|
@@ -1,11 +1,6 @@
|
|
1
1
|
- default_page_title ||= nil; on_site_link ||= nil
|
2
2
|
- current_title = default_page_title || "#{object.name} | #{model_class.model_name.human.pluralize(:ru)}"
|
3
3
|
- title current_title
|
4
|
-
-#= content_for :sidebar do
|
5
|
-
-# - buttons = ::Tramway::Admin.additional_buttons(record: object.model.class, view: :show, project: @application.name)
|
6
|
-
-# .btn-group-vertical
|
7
|
-
-# - buttons.each do |button|
|
8
|
-
-# - build_buttons button.call object
|
9
4
|
.page-header
|
10
5
|
.row
|
11
6
|
.col-md-12
|
@@ -15,9 +10,9 @@
|
|
15
10
|
= link_to fa_icon('pencil-alt'), edit_path, class: 'btn btn-warning btn-xs'
|
16
11
|
- if public_path(object)
|
17
12
|
= link_to fa_icon(:share), public_path(object), class: 'btn btn-primary btn-xs'
|
18
|
-
- buttons =
|
13
|
+
- buttons = object.additional_buttons[:show]
|
19
14
|
- buttons&.each do |button|
|
20
|
-
-
|
15
|
+
- build_button button
|
21
16
|
%hr
|
22
17
|
.row
|
23
18
|
%table.table.table-striped.table-bordered
|
@@ -1,16 +1,19 @@
|
|
1
|
-
- if object.class.show_associations.
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
=
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
- if object.class.show_associations.nil?
|
2
|
+
= "Please, fill show associations method in decorator"
|
3
|
+
- else
|
4
|
+
- if object.class.show_associations.map(&:to_s).include? association.name.to_s
|
5
|
+
- association_type = association.class.to_s.split('::').last.sub(/Reflection$/, '').underscore.to_sym
|
6
|
+
%tr
|
7
|
+
%td
|
8
|
+
= model_class.human_attribute_name association.name
|
9
|
+
%hr
|
10
|
+
- if association_type != :has_one || !object.send(association.name).present?
|
11
|
+
= 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'
|
12
|
+
%td{ colspan: 2 }
|
13
|
+
- if association_type.in? [ :has_one, :belongs_to ]
|
14
|
+
%table.table.table-striped.table-bordered
|
15
|
+
= render 'tramway/admin/shared/show/associations/table_row', object: object, association: association, association_object: object.send(association.name)
|
16
|
+
- else
|
17
|
+
%table.table.table-striped.table-bordered
|
18
|
+
- object.send(association.name)&.each do |association_object|
|
19
|
+
= render 'tramway/admin/shared/show/associations/table_row', object: object, association: association, association_object: association_object
|
data/lib/tramway/admin.rb
CHANGED
@@ -5,7 +5,6 @@ require 'tramway/admin/engine'
|
|
5
5
|
require 'tramway/admin/singleton_models'
|
6
6
|
require 'tramway/admin/records_models'
|
7
7
|
require 'tramway/admin/forms'
|
8
|
-
require 'tramway/admin/additional_buttons'
|
9
8
|
require 'tramway/admin/notifications'
|
10
9
|
require 'tramway/admin/welcome_page_actions'
|
11
10
|
require 'tramway/admin/navbar'
|
@@ -20,7 +19,6 @@ module Tramway
|
|
20
19
|
class << self
|
21
20
|
include ::Tramway::Admin::RecordsModels
|
22
21
|
include ::Tramway::Admin::SingletonModels
|
23
|
-
include ::Tramway::Admin::AdditionalButtons
|
24
22
|
include ::Tramway::Admin::Forms
|
25
23
|
include ::Tramway::Admin::Notifications
|
26
24
|
include ::Tramway::Admin::WelcomePageActions
|
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: 2.
|
4
|
+
version: 2.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: 2021-
|
11
|
+
date: 2021-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tramway-core
|
@@ -296,7 +296,6 @@ files:
|
|
296
296
|
- config/routes.rb
|
297
297
|
- lib/tasks/tramway/admin_tasks.rake
|
298
298
|
- lib/tramway/admin.rb
|
299
|
-
- lib/tramway/admin/additional_buttons.rb
|
300
299
|
- lib/tramway/admin/engine.rb
|
301
300
|
- lib/tramway/admin/forms.rb
|
302
301
|
- lib/tramway/admin/generators/install_generator.rb
|
@@ -311,7 +310,7 @@ files:
|
|
311
310
|
- lib/tramway/admin/tramway_model_helper.rb
|
312
311
|
- lib/tramway/admin/version.rb
|
313
312
|
- lib/tramway/admin/welcome_page_actions.rb
|
314
|
-
homepage: https://github.com/
|
313
|
+
homepage: https://github.com/purple-magic/tramway-admin
|
315
314
|
licenses:
|
316
315
|
- MIT
|
317
316
|
metadata: {}
|
@@ -330,7 +329,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
330
329
|
- !ruby/object:Gem::Version
|
331
330
|
version: '0'
|
332
331
|
requirements: []
|
333
|
-
rubygems_version: 3.
|
332
|
+
rubygems_version: 3.2.3
|
334
333
|
signing_key:
|
335
334
|
specification_version: 4
|
336
335
|
summary: Engine for admin
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Tramway::Admin::AdditionalButtons
|
4
|
-
def set_additional_buttons(buttons, project:)
|
5
|
-
@additional_buttons ||= {}
|
6
|
-
@additional_buttons[project] ||= {}
|
7
|
-
@additional_buttons[project].merge! buttons
|
8
|
-
end
|
9
|
-
|
10
|
-
def additional_buttons(view: nil, record: nil, project: nil)
|
11
|
-
@additional_buttons&.with_indifferent_access&.dig project, record, view
|
12
|
-
end
|
13
|
-
end
|