tramway-admin 4.0 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0da53840f67044b77ccf8d8c37b2dd02d23fde702aa09550182062056032fc5f
4
- data.tar.gz: 50ae25d697d79b09e8aeb59b19d35a6be14b3b904dfaf0a47562cf5bc3e28401
3
+ metadata.gz: 78639584bbf4b055028b8d32816434c049812c9aa8711fdfcc4c988b22e4d28a
4
+ data.tar.gz: fd5f663efbceab4b1ac6aa2276488a2b7f5b287db196564b72419da25f1f2743
5
5
  SHA512:
6
- metadata.gz: f7f23e28049699b42619820d7c643dcaff51983aa3430da9b5b77d8424e484531fd19f09ba4b07e540ed416c0d3eeb0a12b8551c001fc437634110e0247b0432
7
- data.tar.gz: af55df2f1614906fd42ca0313e1acf463b08aa78dcb71f4ca1cca50aafe0de8f0f1af20995ea91910b3016d9e062bbdc06bc4dffa8e7f2d09062784a5e360f43
6
+ metadata.gz: d18a9fcb50694c039bfa5bcd702391260312cdc88eaa45922d35564b0a34cdda6049f55299d482a5dfb71ccbc4d3d38407a17156cdcf9705ab89fa6f89a35226
7
+ data.tar.gz: 1b8472ecb0adb65f49146cb5896d1757e82e96e07a3ede8c191bcc3f31ceaf0ab3444430b0a9e023dd8179032338b94ebfc975dae7529e81e4e665fe4c31e9a3
@@ -21,6 +21,16 @@ module Tramway::Admin::ActionsHelper
21
21
  )
22
22
  end
23
23
 
24
+ def create_is_available?(association_class)
25
+ ::Tramway::Admin.action_is_available?(
26
+ nil,
27
+ project: (@application_engine || @application.name),
28
+ model_name: association_class,
29
+ role: current_admin.role,
30
+ action: :create
31
+ )
32
+ end
33
+
24
34
  # delete_button is in smart-buttons gem
25
35
 
26
36
  def edit_button(url:, button_options:)
@@ -17,6 +17,7 @@ module Tramway
17
17
  include ::Tramway::Collections::Helper
18
18
  include ::Tramway::Core::CopyToClipboardHelper
19
19
  include ::Tramway::Admin::TramwayModelHelper
20
+ include ::Tramway::Admin::FrontendHelper
20
21
 
21
22
  def object_type(object)
22
23
  object_class_name = if object.class.ancestors.include? ::Tramway::Core::ApplicationDecorator
@@ -0,0 +1,21 @@
1
+ module Tramway::Admin::FrontendHelper
2
+ def react_params(form, action, method)
3
+ url = case action
4
+ when :create
5
+ Tramway::Admin::Engine.routes.url_helpers.records_path(model: form.model.class)
6
+ else
7
+ Tramway::Admin::Engine.routes.url_helpers.record_path(form.model.id, model: form.model.class)
8
+ end
9
+ form.properties.reduce({ action: url, method: method, authenticity_token: form_authenticity_token }) do |hash, property|
10
+ case property[1]
11
+ when :association
12
+ hash.merge!(
13
+ property[0] => {
14
+ collection: build_collection_for_association(form, property[0])
15
+ }
16
+ )
17
+ end
18
+ hash
19
+ end.merge model: form.model.attributes
20
+ end
21
+ end
@@ -4,10 +4,14 @@
4
4
  %meta{ content: "width=device-width, initial-scale=1, maximum-scale=0.8", name: "viewport" }
5
5
  %title
6
6
  = yield :title
7
- = stylesheet_link_tag 'tramway/admin/application', media: "all"
7
+ = stylesheet_link_tag 'tramway/admin/application', media: :all
8
8
  = javascript_include_tag 'tramway/admin/application'
9
9
  - if File.exists?("#{Rails.root}/app/assets/javascripts/admin/application.js") || File.exists?("#{Rails.root}/app/assets/javascripts/admin/application.js.coffee")
10
10
  = javascript_include_tag 'admin/application'
11
+ - if File.exists?("#{Rails.root}/app/assets/stylesheets/admin/application.css") || File.exists?("#{Rails.root}/app/assets/stylesheets/admin/application.scss")
12
+ = stylesheet_link_tag 'admin/application'
13
+ - if File.exists?("#{Rails.root}/app/javascript/packs/admin/application.js")
14
+ = javascript_pack_tag 'admin/application'
11
15
  = csrf_meta_tags
12
16
  - if @application.favicon.present?
13
17
  = favicon_link_tag @application.favicon
@@ -8,12 +8,15 @@
8
8
  = render 'tramway/core/shared/messages', object: @record_form
9
9
  .row
10
10
  .col-lg-12
11
- = simple_form_for @record_form, url: { controller: :records, action: action, model: @record_form.model.class }, method: method, input_html: { class: 'form-horizontal' } do |f|
12
- - @record_form.properties.each do |property, type|
13
- = render 'tramway/core/shared/input', property: property, object: :record, type: type, form: f, destination: :admin, value: value_from_params(model_class: model_class, property: property, type: type)
14
- = hidden_field_tag :redirect, params[:redirect]
15
- = f.button :submit, t('helpers.links.save'), class: 'btn btn-success'
16
- = link_to t('helpers.links.back'), current_model_records_path, class: 'btn btn-secondary'
11
+ - if @record_form.class.is_react_component?
12
+ = react_component "#{@record_form.class.name.gsub('::', '/')}", react_params(@record_form, action, method)
13
+ - else
14
+ = simple_form_for @record_form, url: { controller: :records, action: action, model: @record_form.model.class }, method: method, input_html: { class: 'form-horizontal' } do |f|
15
+ - @record_form.properties.each do |property, type|
16
+ = render 'tramway/core/shared/input', property: property, object: :record, type: type, form: f, destination: :admin, value: value_from_params(model_class: model_class, property: property, type: type)
17
+ = hidden_field_tag :redirect, params[:redirect]
18
+ = f.button :submit, t('helpers.links.save'), class: 'btn btn-success'
19
+ = link_to t('helpers.links.back'), current_model_records_path, class: 'btn btn-secondary'
17
20
 
18
21
  -# NOTES
19
22
  -# * value_from_params helper is in tramway-core gem app/helpers/inputs_helpers.rb
@@ -7,7 +7,7 @@
7
7
  %td
8
8
  = model_class.human_attribute_name association.name
9
9
  %hr
10
- - if association_type != :has_one || !object.send(association.name).present?
10
+ - if create_is_available?(association.class_name) && (association_type != :has_one || !object.send(association.name).present?)
11
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
12
  %td{ colspan: 2 }
13
13
  - if association_type.in? [ :has_one, :belongs_to ]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Admin
5
- VERSION = '4.0'
5
+ VERSION = '4.1'
6
6
  end
7
7
  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: '4.0'
4
+ version: '4.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: 2022-02-07 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tramway-core
@@ -180,16 +180,16 @@ dependencies:
180
180
  name: trap
181
181
  requirement: !ruby/object:Gem::Requirement
182
182
  requirements:
183
- - - '='
183
+ - - "~>"
184
184
  - !ruby/object:Gem::Version
185
- version: '3.0'
185
+ version: '4.0'
186
186
  type: :runtime
187
187
  prerelease: false
188
188
  version_requirements: !ruby/object:Gem::Requirement
189
189
  requirements:
190
- - - '='
190
+ - - "~>"
191
191
  - !ruby/object:Gem::Version
192
- version: '3.0'
192
+ version: '4.0'
193
193
  - !ruby/object:Gem::Dependency
194
194
  name: aasm
195
195
  requirement: !ruby/object:Gem::Requirement
@@ -256,6 +256,7 @@ files:
256
256
  - app/helpers/tramway/admin/application_helper.rb
257
257
  - app/helpers/tramway/admin/cases_helper.rb
258
258
  - app/helpers/tramway/admin/focus_generator_helper.rb
259
+ - app/helpers/tramway/admin/frontend_helper.rb
259
260
  - app/helpers/tramway/admin/navbar_helper.rb
260
261
  - app/helpers/tramway/admin/records_helper.rb
261
262
  - app/helpers/tramway/admin/russian_cases_helper.rb