tramway-admin 1.0.1 → 1.1

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: ede3dd0927c3ca2efff6c3099adc8feb5967bda5e7ec26e5c76a7ae38fd8507c
4
- data.tar.gz: 56c36d25bbfe1e535f0dd438470cb5f55bb49cc2b25a4b1d5401c280cfc67946
3
+ metadata.gz: 9b509f3137e389c0d20cc54056cb16f683ef6077c3252b1573caf4e019f6f180
4
+ data.tar.gz: a352f3c1e83c8f44cd2f66f0ade79fa1a45f94294e623f8305209668215e7e4e
5
5
  SHA512:
6
- metadata.gz: 57d3936c3fb37f8b2998f820b0533c9102996bd7d4bf2eb8ffaf685ac1a32b765fc98a679c288d1edb4365650d7c61635ea88ea50eed00326456bcdd5977ec16
7
- data.tar.gz: d11ece18b797fd1cf74b52dc8e76295c18c2b681d4678d08ea6b7de6d8397b3ec3d9aea7908602d500d5971477a6442784c847f2e3cae9e2a5deeef19950f7e6
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
@@ -3,6 +3,7 @@ module Tramway
3
3
  module ApplicationHelper
4
4
  include ::FontAwesome::Rails::IconHelper
5
5
  include AuthManagment
6
+ include AdditionalButtonsBuilder
6
7
 
7
8
  def title(page_title = default_title)
8
9
  title_text = "#{page_title} | #{t('application.name')}"
@@ -1,20 +1,20 @@
1
1
  module Tramway::Admin
2
2
  module RecordsHelper
3
3
  # FIXME replace to module
4
- def record_path(*args, **options)
5
- super args, options.merge(model: params[:model])
4
+ def current_model_record_path(*args, **options)
5
+ record_path args, options.merge(model: params[:model])
6
6
  end
7
7
 
8
- def edit_record_path(*args, **options)
9
- super args, options.merge(model: params[:model])
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 new_record_path(*args, **options)
13
- super args, options.merge(model: params[:model])
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 records_path(*args, **options)
17
- super args, options.merge(model: params[:model])
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 singleton_path(*args, **options)
4
- super args, options.merge(model: params[:model])
3
+ def current_model_singleton_path(*args, **options)
4
+ singleton_path args, options.merge(model: params[:model])
5
5
  end
6
6
 
7
- def edit_singleton_path(*args, **options)
8
- super args, options.merge(model: params[:model])
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
@@ -13,7 +13,11 @@
13
13
  %body
14
14
  = render 'layouts/tramway/admin/shared/navbar'
15
15
  %main.container{ role: :main }
16
- = yield
16
+ .row
17
+ .col-lg-9
18
+ = yield
19
+ .col-lg-3.sidebar-canvas
20
+ = yield :sidebar
17
21
  %footer
18
22
  .container
19
23
  = copyright '2017', 'Tramway'
@@ -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'), records_path, class: 'btn btn-secondary'
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, record_path(record.id)
14
+ = link_to record.id, current_model_record_path(record.id)
15
15
  %td
16
- = link_to record.name, record_path(record.id)
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: :record_path, parameters: { redirect: records_path }
25
- = link_to fa_icon(:pencil), edit_record_path(record.id), class: 'btn btn-warning btn-xs'
26
- = link_to fa_icon(:remove), record_path(record.id), method: :delete, class: 'btn btn-xs btn-danger'
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), new_record_path, class: 'btn btn-primary'
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
@@ -7,6 +7,7 @@
7
7
  %h1
8
8
  = current_title
9
9
  = link_to fa_icon(:pencil), edit_record_path(@record.id), class: 'btn btn-warning btn-xs'
10
+ = ::Tramway::Admin.additional_buttons(record: @record.model.model_name, view: :show)
10
11
  %hr
11
12
  .row
12
13
  %table.table.table-striped.table-bordered
@@ -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
- %h1
11
+ %h2
8
12
  = current_title
9
- = link_to fa_icon(:pencil), edit_singleton_path, class: 'btn btn-warning btn-xs'
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
@@ -1,5 +1,5 @@
1
1
  module Tramway
2
2
  module Admin
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1'
4
4
  end
5
5
  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.0.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-14 00:00:00.000000000 Z
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