tramway-core 1.14.7.1 → 1.16.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: 342f7e0203c9760eb999b73aab0851970249cb4842b372f190e7b64f80072ba1
4
- data.tar.gz: 8d65b2c788927529f8c0e7202ada01fd18ffd26e3a8b16a1f0297c6ba04bbc92
3
+ metadata.gz: 90e0f6addfaa061388a54435ff519ba09544d1948dc8a2130f51457b23bef215
4
+ data.tar.gz: eb50727af2688a79eaa59b64320b1d127deb02658d2f0fc3587e7c6f43069217
5
5
  SHA512:
6
- metadata.gz: 3fa66055ce40a7e966fb66196243cb20e21f41be28c59682cce821b0d78473598da6d39e68837478d62ae66f15ed19382ca8b64748db00b67fd11b2701b39936
7
- data.tar.gz: db16cc89c4230e09804443baa8024b98ae0c50a827718ad366041821d19d26202cbd144a0ccc64d859258884793b6e58c5fcf59f7cf093e32f388417e28e921d
6
+ metadata.gz: 7a22b749b982662f6c9aace0e951d5d408107501311143312bd38240d0a8fe33d0f4bfa9c9c58c4766ff4362944b0fc74a402e2bfc228f5729606297ffea7268
7
+ data.tar.gz: 8cfa52bb4c944ec0fb3f60875eaa7be874905d58be07943ae93775556bf4e651e6207d91f7216df717af657fae1121e7771e611c2e88c65ddd0ba22eccc2fc8c
data/README.md CHANGED
@@ -31,6 +31,55 @@ Tramway::Core.initialize_application model_class: ::Tramway::Conference::Unity #
31
31
  ```ruby
32
32
  Rails.application.config.assets.precompile += %w( *.jpg *.png *.js )
33
33
  ```
34
+ # Usage
35
+ ## Decorators
36
+ ### Helper methods
37
+
38
+ #### date_view
39
+ Returns a date in the format depending on localization
40
+
41
+ *app/decorators/\*_decorator.rb*
42
+ ```ruby
43
+ def created_at
44
+ date_view object.created_at
45
+ end
46
+ ```
47
+ #### datetime_view
48
+ Returns a date and time in the format depending on localization
49
+
50
+ *app/decorators/*_decorator.rb*
51
+ ```ruby
52
+ def created_at
53
+ datetime_view object.created_at
54
+ end
55
+ ```
56
+ #### state_machine_view
57
+ Returns the state of an object according to a state machine
58
+
59
+ *app/decorators/*_decorator.rb*
60
+ ```ruby
61
+ def state
62
+ state_machine_view object, :state
63
+ end
64
+ ```
65
+ #### image_view
66
+ Returns an image in a particular format depending on the parameters of the original image file
67
+
68
+ *app/decorators/\*_decorator.rb*
69
+ ```ruby
70
+ def avatar
71
+ image_view object.avatar
72
+ end
73
+ ```
74
+ #### enumerize_view
75
+ Returns object enumerations as text
76
+
77
+ *app/decorators/\*_decorator.rb*
78
+ ```ruby
79
+ def field_type
80
+ enumerize_view object.field_type
81
+ end
82
+ ```
34
83
 
35
84
  # Базовые классы
36
85
 
@@ -1,8 +1,10 @@
1
1
  #= require jquery
2
2
  #= require jquery_ujs
3
+ #= require popper
3
4
  #= require bootstrap-datepicker-1.8.0
4
5
  #= require bootstrap-datepicker-1.8.0.ru.min
5
6
  #= require font_awesome5
7
+ #= require clipboard
6
8
  #= require_tree .
7
9
 
8
10
  window.i18n_locale = (locale) ->
@@ -27,3 +29,5 @@ $(document).ready ->
27
29
  anchor = $(this).data('anchor')
28
30
  unless $(anchor).offset() == undefined
29
31
  $(window).scrollTop $(anchor).offset().top
32
+
33
+ clipboard = new Clipboard '.clipboard-btn'
@@ -4,10 +4,15 @@ module Tramway
4
4
  module Core
5
5
  class ApplicationController < ActionController::Base
6
6
  before_action :application
7
+ before_action :load_extensions
7
8
 
8
9
  def application
9
10
  @application = ::Tramway::Core.application_object
10
11
  end
12
+
13
+ def load_extensions
14
+ ::Tramway::Extensions.load if defined? ::Tramway::Extensions
15
+ end
11
16
  end
12
17
  end
13
18
  end
@@ -6,6 +6,7 @@ class Tramway::Core::ApplicationDecorator
6
6
  include ActionView::Helpers
7
7
  include ActionView::Context
8
8
  include ::FontAwesome5::Rails::IconHelper
9
+ include ::Tramway::Core::CopyToClipboardHelper
9
10
 
10
11
  def initialize(object)
11
12
  @object = object
@@ -48,7 +49,7 @@ class Tramway::Core::ApplicationDecorator
48
49
  end
49
50
  end
50
51
 
51
- def decorate_association(association_name, decorator: nil)
52
+ def decorate_association(association_name, decorator: nil, as: nil)
52
53
  @@decorated_associations ||= []
53
54
  @@decorated_associations << association_name
54
55
 
@@ -77,6 +78,10 @@ class Tramway::Core::ApplicationDecorator
77
78
  return decorator_class_name.decorate object.send association_name
78
79
  end
79
80
  end
81
+
82
+ define_method "#{association_name}_as" do
83
+ as
84
+ end
80
85
  end
81
86
 
82
87
  def model_class
@@ -35,10 +35,10 @@ module Tramway::Core
35
35
  if validate params
36
36
  begin
37
37
  save.tap do
38
- #self.class.remove_validations_from_model!
38
+ # self.class.remove_validations_from_model!
39
39
  end
40
40
  rescue StandardError => e
41
- #self.class.remove_validations_from_model!
41
+ # self.class.remove_validations_from_model!
42
42
  error = Tramway::Error.new(plugin: :core, method: :submit, message: "Looks like you have method `#{e.name.to_s.gsub('=', '')}` in #{@@model_class}. You should rename it or rename property in #{self.class}")
43
43
  raise error.message
44
44
  end
@@ -51,11 +51,11 @@ module Tramway::Core
51
51
  end
52
52
  end
53
53
  (association_error && save).tap do
54
- #self.class.remove_validations_from_model!
54
+ # self.class.remove_validations_from_model!
55
55
  end
56
56
  end
57
57
  else
58
- #self.class.remove_validations_from_model!
58
+ # self.class.remove_validations_from_model!
59
59
  error = Tramway::Error.new(plugin: :core, method: :submit, message: 'ApplicationForm::Params should not be nil')
60
60
  raise error.message
61
61
  end
@@ -75,6 +75,7 @@ module Tramway::Core
75
75
 
76
76
  def properties
77
77
  return @form_properties if @form_properties
78
+
78
79
  yaml_config_file_path = Rails.root.join('app', 'forms', "#{self.class.name.underscore}.yml")
79
80
  if File.exist? yaml_config_file_path
80
81
  @form_properties = YAML.load_file(yaml_config_file_path).deep_symbolize_keys
@@ -165,17 +166,17 @@ module Tramway::Core
165
166
 
166
167
  def validates(attribute, **options)
167
168
  if !defined?(@@model_class) || @@model_class.nil?
168
- error = Tramway::Error.new(plugin: :core, method: :validates, message: "You need to set `model_class` name while using validations. Just write `self.model_class = YOUR_MODEL_NAME` in the class area.")
169
+ error = Tramway::Error.new(plugin: :core, method: :validates, message: 'You need to set `model_class` name while using validations. Just write `self.model_class = YOUR_MODEL_NAME` in the class area.')
169
170
  raise error.message
170
171
  end
171
172
  @@model_class.validates attribute, **options
172
- # @@validations ||= {}
173
- # @@validations.deep_merge! attribute => options
173
+ # @@validations ||= {}
174
+ # @@validations.deep_merge! attribute => options
174
175
  end
175
-
176
+
176
177
  # FIXME: Removes all validations in a field. We must implement own validations
177
-
178
- #def remove_validations_from_model!
178
+
179
+ # def remove_validations_from_model!
179
180
  # return unless defined? @@validations
180
181
  # @@validations&.each do |validation|
181
182
  # @@model_class.class_eval do
@@ -187,7 +188,7 @@ module Tramway::Core
187
188
  # end
188
189
  # end
189
190
  # end
190
- #end
191
+ # end
191
192
  end
192
193
  end
193
194
  end
@@ -40,7 +40,7 @@ class Tramway::Core::ExtendableForm
40
40
 
41
41
  case property[1][:object].field_type
42
42
  when 'file'
43
- field = property[1][:object]
43
+ field = property[1][:object]
44
44
  define_method "#{property[0]}=" do |value|
45
45
  file_instance = property[1][:association_model].find_or_create_by "#{model.class.name.underscore}_id" => model.id, "#{field.class.name.underscore}_id" => field.id
46
46
  file_instance.file = value
@@ -63,9 +63,7 @@ class Tramway::Core::ExtendableForm
63
63
 
64
64
  define_method :jsonb_ignored_properties do |properties|
65
65
  properties.map do |property|
66
- if property[1][:object].field_type == 'file'
67
- property[0].to_s
68
- end
66
+ property[0].to_s if property[1][:object].field_type == 'file'
69
67
  end.compact
70
68
  end
71
69
  end)
@@ -0,0 +1,13 @@
1
+ module Tramway
2
+ module Core
3
+ module CopyToClipboardHelper
4
+ def copy_to_clipboard(id)
5
+ button_tag class: 'btn btn-info clipboard-btn',
6
+ data: { clipboard_action: 'copy', clipboard_target: "##{id}" },
7
+ style: 'margin-left: 15px' do
8
+ fa_icon 'copy'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -8,7 +8,7 @@ module Tramway
8
8
  title_text = "#{page_title} | #{@application.try(:title) || @application.public_name}"
9
9
  content_for(:title) { title_text }
10
10
  else
11
- error = Tramway::Error.new(plugin: :core, method: :title, message: 'You should set Tramway::Core::Application class using `::Tramway::Core.initialize_application model_class: #{model_class_name}` in config/initializers/tramway.rb OR may be you don\'t have any records of application model')
11
+ error = Tramway::Error.new(plugin: :core, method: :title, message: 'You should set Tramway::Core::Application class using `::Tramway::Core.initialize_application model_class: #{model_class_name}` in config/initializers/tramway.rb OR maybe you don\'t have any records of application model')
12
12
  raise error.message
13
13
  end
14
14
  end
@@ -19,6 +19,8 @@ module Tramway
19
19
  end
20
20
 
21
21
  scope :active, -> { where state: :active }
22
+ scope :created_by_user, ->(user_id) { joins(:audits).where('audits.action = \'create\' AND audits.user_id = ?', user_id) }
23
+ scope :admin_scope, ->(_arg) { all }
22
24
 
23
25
  include ::PgSearch::Model
24
26
 
@@ -0,0 +1 @@
1
+ != @message
@@ -13,6 +13,7 @@ ru:
13
13
  search: Искать
14
14
  reset: Сбросить
15
15
  download: Скачать
16
+ add: Добавить
16
17
  scope:
17
18
  found: Найденные
18
19
  "yes": Да
@@ -4,7 +4,7 @@ module Tramway
4
4
  module Collections
5
5
  module Helper
6
6
  def collection_list_by(name:)
7
- begin
7
+ begin
8
8
  require name # needed to load class name with collection
9
9
  rescue LoadError
10
10
  raise "No such file #{name}. You should create file in the `lib/#{name}.rb` or elsewhere you want"
@@ -23,11 +23,11 @@ module Tramway
23
23
  if @application&.model_class.present?
24
24
  begin
25
25
  @application.model_class.first
26
- rescue
26
+ rescue StandardError
27
27
  nil
28
28
  end
29
29
  else
30
- @application
30
+ @application
31
31
  end
32
32
  end
33
33
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Tramway
4
4
  module Core
5
- VERSION = '1.14.7.1'
5
+ VERSION = '1.16.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.7.1
4
+ version: 1.16.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: 2020-01-13 00:00:00.000000000 Z
11
+ date: 2020-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: audited
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ckeditor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 4.2.4
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 4.2.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: clipboard-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: enumerize
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -332,6 +360,7 @@ files:
332
360
  - app/forms/tramway/core/extendable_form.rb
333
361
  - app/forms/tramway/core/extended_application_form.rb
334
362
  - app/forms/tramway/core/form_creator.rb
363
+ - app/helpers/tramway/core/copy_to_clipboard_helper.rb
335
364
  - app/helpers/tramway/core/title_helper.rb
336
365
  - app/inputs/date_picker_input.rb
337
366
  - app/models/tramway/core/application_record.rb
@@ -339,6 +368,7 @@ files:
339
368
  - app/uploaders/file_uploader.rb
340
369
  - app/uploaders/image_defaults.rb
341
370
  - app/uploaders/photo_uploader.rb
371
+ - app/views/tramway/core/404.haml
342
372
  - app/views/tramway/core/shared/_input_extended.html.haml
343
373
  - app/views/tramway/core/shared/_messages.html.haml
344
374
  - app/views/tramway/core/shared/input_extended_types/_checkbox.html.haml