tramway-admin 1.0.1 → 1.1
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/app/helpers/tramway/admin/additional_buttons_builder.rb +53 -0
- data/app/helpers/tramway/admin/application_helper.rb +1 -0
- data/app/helpers/tramway/admin/records_helper.rb +8 -8
- data/app/helpers/tramway/admin/singleton_helper.rb +4 -4
- data/app/views/layouts/tramway/admin/application.html.haml +5 -1
- data/app/views/tramway/admin/records/_form.html.haml +4 -3
- data/app/views/tramway/admin/records/_list.html.haml +5 -5
- data/app/views/tramway/admin/records/index.html.haml +1 -2
- data/app/views/tramway/admin/records/show.html.haml +1 -0
- data/app/views/tramway/admin/singletons/show.html.haml +6 -2
- data/lib/tramway/admin.rb +9 -0
- data/lib/tramway/admin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b509f3137e389c0d20cc54056cb16f683ef6077c3252b1573caf4e019f6f180
|
4
|
+
data.tar.gz: a352f3c1e83c8f44cd2f66f0ade79fa1a45f94294e623f8305209668215e7e4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d24fe1df7c7e20f1ccb33c2b69ff4b829306a555a917f37051e1700d9d7f6c5e5fba6729db5514af92cbfb0ad4c603c9bbe8a2d3330cf9083c57d20845a9392
|
7
|
+
data.tar.gz: 1fd49a015741a643f236c16969d6e0eeec79441a7dff0e269f8578a3ce353a138a13e28a42f71275bdf0a286e41d7e9cfd578da2006308b429d9a3b6df65b2bb
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Tramway::Admin::AdditionalButtonsBuilder
|
2
|
+
def build_buttons(additional_buttons)
|
3
|
+
additional_buttons = additional_buttons.is_a?(Hash) ? [ additional_buttons ] : additional_buttons
|
4
|
+
additional_buttons.each do |button|
|
5
|
+
concat(
|
6
|
+
link_to(
|
7
|
+
send(
|
8
|
+
"#{button[:action]}_record_path",
|
9
|
+
build_params(button[:params]).merge(model: button[:model_name])
|
10
|
+
),
|
11
|
+
class: "btn btn-#{button_color(button[:action])} btn-xs"
|
12
|
+
) do
|
13
|
+
button[:text] || button_icon(button[:action])
|
14
|
+
end
|
15
|
+
)
|
16
|
+
end
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
BUTTON_STYLES = {
|
23
|
+
new: { color: :success, icon: :plus },
|
24
|
+
create: { color: :success, icon: :plus },
|
25
|
+
edit: { color: :warning, icon: :pencil },
|
26
|
+
update: { color: :warning, icon: :pencil },
|
27
|
+
delete: { color: :danger, icon: :remove }
|
28
|
+
}
|
29
|
+
|
30
|
+
def button_color(action)
|
31
|
+
BUTTON_STYLES[action][:color]
|
32
|
+
end
|
33
|
+
|
34
|
+
def button_icon(action)
|
35
|
+
BUTTON_STYLES[action][:icon]
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_params(params)
|
39
|
+
param = {}
|
40
|
+
record = @record || @singleton
|
41
|
+
params.each do |model_name, model_attributes|
|
42
|
+
attributes = {}
|
43
|
+
model_attributes.each do |name, value|
|
44
|
+
if value.is_a? Proc
|
45
|
+
value = record.model.instance_exec(&value)
|
46
|
+
end
|
47
|
+
attributes.merge! name => value
|
48
|
+
end
|
49
|
+
param.merge! model_name => attributes
|
50
|
+
end
|
51
|
+
param
|
52
|
+
end
|
53
|
+
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
module Tramway::Admin
|
2
2
|
module RecordsHelper
|
3
3
|
# FIXME replace to module
|
4
|
-
def
|
5
|
-
|
4
|
+
def current_model_record_path(*args, **options)
|
5
|
+
record_path args, options.merge(model: params[:model])
|
6
6
|
end
|
7
7
|
|
8
|
-
def
|
9
|
-
|
8
|
+
def edit_current_model_record_path(*args, **options)
|
9
|
+
edit_record_path args, options.merge(model: params[:model])
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
12
|
+
def new_current_model_record_path(*args, **options)
|
13
|
+
new_record_path args, options.merge(model: params[:model])
|
14
14
|
end
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def current_model_records_path(*args, **options)
|
17
|
+
records_path args, options.merge(model: params[:model])
|
18
18
|
end
|
19
19
|
|
20
20
|
def model_class
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Tramway::Admin::SingletonHelper
|
2
2
|
# FIXME replace to module
|
3
|
-
def
|
4
|
-
|
3
|
+
def current_model_singleton_path(*args, **options)
|
4
|
+
singleton_path args, options.merge(model: params[:model])
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
7
|
+
def edit_current_model_singleton_path(*args, **options)
|
8
|
+
edit_singleton_path args, options.merge(model: params[:model])
|
9
9
|
end
|
10
10
|
end
|
@@ -10,9 +10,10 @@
|
|
10
10
|
.col-lg-12
|
11
11
|
= simple_form_for @record_form.model, url: { controller: :records, action: action, model: @record_form.model.class }, input_html: { class: 'form-horizontal' } do |f|
|
12
12
|
- @record_form.properties.each do |property, type|
|
13
|
+
- value = params.dig(model_class.to_s.underscore, property.to_s)
|
13
14
|
- if type == :default
|
14
|
-
= f.input property, input_html: { name: "record[#{property}]", id: "record_#{property}" }
|
15
|
+
= f.input property, input_html: { name: "record[#{property}]", id: "record_#{property}", value: value }, selected: value
|
15
16
|
- else
|
16
|
-
= f.input property, as: type, input_html: { name: "record[#{property}]", id: "record_#{property}" }
|
17
|
+
= f.input property, as: type, input_html: { name: "record[#{property}]", id: "record_#{property}", value: value }
|
17
18
|
= f.button :submit, t('helpers.links.save'), class: 'btn-success'
|
18
|
-
= link_to t('helpers.links.back'),
|
19
|
+
= link_to t('helpers.links.back'), current_model_records_path, class: 'btn btn-secondary'
|
@@ -11,9 +11,9 @@
|
|
11
11
|
- @records.each do |record|
|
12
12
|
%tr
|
13
13
|
%td
|
14
|
-
= link_to record.id,
|
14
|
+
= link_to record.id, current_model_record_path(record.id)
|
15
15
|
%td
|
16
|
-
= link_to record.name,
|
16
|
+
= link_to record.name, current_model_record_path(record.id)
|
17
17
|
- decorator_class.list_attributes.each do |attribute|
|
18
18
|
%td
|
19
19
|
= record.send attribute
|
@@ -21,7 +21,7 @@
|
|
21
21
|
.btn-group{ data: { toggle: :buttons } }
|
22
22
|
- record.model.class.state_machines.keys.each do |state_method|
|
23
23
|
- unless state_method == :state
|
24
|
-
= state_events_buttons record, state_method: state_method, model_param_name: :record, route_method: :
|
25
|
-
= link_to fa_icon(:pencil),
|
26
|
-
= link_to fa_icon(:remove),
|
24
|
+
= state_events_buttons record, state_method: state_method, model_param_name: :record, route_method: :current_model_record_path, parameters: { redirect: current_model_records_path }
|
25
|
+
= link_to fa_icon(:pencil), edit_current_model_record_path(record.id), class: 'btn btn-warning btn-xs'
|
26
|
+
= link_to fa_icon(:remove), current_model_record_path(record.id), method: :delete, class: 'btn btn-xs btn-danger'
|
27
27
|
= paginate @records, theme: 'twitter-bootstrap-4'
|
@@ -3,13 +3,12 @@
|
|
3
3
|
- title current_title
|
4
4
|
- state_method ||= :state
|
5
5
|
- tabs = get_collection model_class
|
6
|
-
- new_path = "new_admin_#{to_path(model_class)}_path"
|
7
6
|
.page-header
|
8
7
|
.row
|
9
8
|
.col-md-6
|
10
9
|
%h1
|
11
10
|
= current_title
|
12
|
-
= link_to fa_icon(:plus),
|
11
|
+
= link_to fa_icon(:plus), new_current_model_record_path, class: 'btn btn-primary'
|
13
12
|
= render 'search', model_class: model_class
|
14
13
|
%hr
|
15
14
|
%ul.nav.nav-tabs
|
@@ -1,12 +1,16 @@
|
|
1
1
|
- default_page_title ||= nil; on_site_link ||= nil
|
2
2
|
- current_title = default_page_title || model_class.model_name.human.pluralize(:ru)
|
3
3
|
- title current_title
|
4
|
+
|
5
|
+
= content_for :sidebar do
|
6
|
+
.btn-group-vertical
|
7
|
+
= build_buttons ::Tramway::Admin.additional_buttons(record: @singleton.model.class.to_s, view: :show)
|
4
8
|
.page-header
|
5
9
|
.row
|
6
10
|
.col-md-6
|
7
|
-
%
|
11
|
+
%h2
|
8
12
|
= current_title
|
9
|
-
= link_to fa_icon(:pencil),
|
13
|
+
= link_to fa_icon(:pencil), edit_current_model_singleton_path, class: 'btn btn-warning btn-xs'
|
10
14
|
%hr
|
11
15
|
.row
|
12
16
|
%table.table.table-striped.table-bordered
|
data/lib/tramway/admin.rb
CHANGED
@@ -25,6 +25,15 @@ module Tramway
|
|
25
25
|
def singleton_models
|
26
26
|
@singleton_models
|
27
27
|
end
|
28
|
+
|
29
|
+
def set_additional_buttons(buttons)
|
30
|
+
@additional_buttons ||= {}
|
31
|
+
@additional_buttons.merge! buttons
|
32
|
+
end
|
33
|
+
|
34
|
+
def additional_buttons(view: nil, record: nil)
|
35
|
+
@additional_buttons&.dig record, view
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
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.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: 2018-03-
|
11
|
+
date: 2018-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Engine for admin
|
14
14
|
email:
|
@@ -32,6 +32,7 @@ files:
|
|
32
32
|
- app/controllers/tramway/admin/records_controller.rb
|
33
33
|
- app/controllers/tramway/admin/singletons_controller.rb
|
34
34
|
- app/controllers/tramway/admin/welcome_controller.rb
|
35
|
+
- app/helpers/tramway/admin/additional_buttons_builder.rb
|
35
36
|
- app/helpers/tramway/admin/application_helper.rb
|
36
37
|
- app/helpers/tramway/admin/records_helper.rb
|
37
38
|
- app/helpers/tramway/admin/russian_cases_helper.rb
|