tramway-core 1.15.1 → 1.16.1.3
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/README.md +75 -0
- data/app/assets/javascripts/tramway/core/application.js.coffee +4 -1
- data/app/controllers/tramway/core/application_controller.rb +1 -3
- data/app/decorators/tramway/core/application_decorator.rb +6 -1
- data/app/decorators/tramway/core/concerns/attributes_decorator_helper.rb +6 -6
- data/app/forms/tramway/core/application_form.rb +12 -11
- data/app/forms/tramway/core/extendable_form.rb +2 -4
- data/app/helpers/tramway/core/copy_to_clipboard_helper.rb +13 -0
- data/app/models/tramway/core/application_record.rb +6 -2
- data/app/uploaders/file_uploader.rb +1 -1
- data/app/views/tramway/core/404.haml +1 -0
- data/config/locales/ru/helpers.yml +1 -0
- data/lib/tramway/collections/helper.rb +1 -1
- data/lib/tramway/core.rb +2 -2
- data/lib/tramway/core/version.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce1a0b7cdeee547346146b94f4562a717b1b1fd20f4d8708a75e1304b5ad212b
|
4
|
+
data.tar.gz: eb75b3c797f5d7637ed7a343731d73ed35151e50d4146447497632693929e5e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cabfde795da437d015c64c257de6ac2bc025002032bb95aa5b01324ca4e4c6b963e30e4c364a1d9b2938bec996cafc47912ecc7381e5bdf0a6e670c905770657
|
7
|
+
data.tar.gz: ff5a52deb2ff392ffd217562e6dc40da8a91ca33f0dd704f0a293521da71067e87c029b351e6bd2f8b1dc6424aaff734214382ed34b193986e199b6de45ce686
|
data/README.md
CHANGED
@@ -12,6 +12,7 @@ tramway-core - это ядро проекта [tramway](https://github.com/ulmic
|
|
12
12
|
```ruby
|
13
13
|
gem 'tramway-core'
|
14
14
|
gem 'audited'
|
15
|
+
gem 'clipboard-rails'
|
15
16
|
```
|
16
17
|
|
17
18
|
```shell
|
@@ -31,6 +32,80 @@ Tramway::Core.initialize_application model_class: ::Tramway::Conference::Unity #
|
|
31
32
|
```ruby
|
32
33
|
Rails.application.config.assets.precompile += %w( *.jpg *.png *.js )
|
33
34
|
```
|
35
|
+
# Usage
|
36
|
+
## Decorators
|
37
|
+
### Helper methods
|
38
|
+
|
39
|
+
#### date_view
|
40
|
+
Returns a date in the format depending on localization
|
41
|
+
|
42
|
+
*app/decorators/\*_decorator.rb*
|
43
|
+
```ruby
|
44
|
+
def created_at
|
45
|
+
date_view object.created_at
|
46
|
+
end
|
47
|
+
```
|
48
|
+
#### datetime_view
|
49
|
+
Returns a date and time in the format depending on localization
|
50
|
+
|
51
|
+
*app/decorators/*_decorator.rb*
|
52
|
+
```ruby
|
53
|
+
def created_at
|
54
|
+
datetime_view object.created_at
|
55
|
+
end
|
56
|
+
```
|
57
|
+
#### state_machine_view
|
58
|
+
Returns the state of an object according to a state machine
|
59
|
+
|
60
|
+
*app/decorators/*_decorator.rb*
|
61
|
+
```ruby
|
62
|
+
def state
|
63
|
+
state_machine_view object, :state
|
64
|
+
end
|
65
|
+
```
|
66
|
+
#### image_view
|
67
|
+
Returns an image in a particular format depending on the parameters of the original image file
|
68
|
+
|
69
|
+
*app/decorators/\*_decorator.rb*
|
70
|
+
```ruby
|
71
|
+
def avatar
|
72
|
+
image_view object.avatar
|
73
|
+
end
|
74
|
+
```
|
75
|
+
#### enumerize_view
|
76
|
+
Returns object enumerations as text
|
77
|
+
|
78
|
+
*app/decorators/\*_decorator.rb*
|
79
|
+
```ruby
|
80
|
+
def field_type
|
81
|
+
enumerize_view object.field_type
|
82
|
+
end
|
83
|
+
```
|
84
|
+
|
85
|
+
## Other helpers
|
86
|
+
|
87
|
+
### CopyToClipboardHelper
|
88
|
+
|
89
|
+
[app/helpers/tramway/core/copy_to_clipboard_helper.rb](https://github.com/ulmic/tramway-dev/blob/develop/tramway-core/app/helpers/tramway/core/copy_to_clipboard_helper.rb)
|
90
|
+
|
91
|
+
#### Install
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
include ::Tramway::Core::CopyToClipboardHelper
|
95
|
+
```
|
96
|
+
|
97
|
+
#### How to use it
|
98
|
+
|
99
|
+
It will show you in the view in bootstrap styles with font-awesome `copy` icon.
|
100
|
+
|
101
|
+
Something like this:
|
102
|
+
|
103
|
+

|
104
|
+
|
105
|
+
```ruby
|
106
|
+
copy_to_clipboard "some_id" # some_id is HTML id of element. Content of this element will be copied to the clipboard after pressing the button
|
107
|
+
```
|
108
|
+
|
34
109
|
|
35
110
|
# Базовые классы
|
36
111
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
#= require jquery
|
2
2
|
#= require jquery_ujs
|
3
|
-
#= require
|
3
|
+
#= require bootstrap
|
4
4
|
#= require bootstrap-datepicker-1.8.0
|
5
5
|
#= require bootstrap-datepicker-1.8.0.ru.min
|
6
6
|
#= require font_awesome5
|
7
|
+
#= require clipboard
|
7
8
|
#= require_tree .
|
8
9
|
|
9
10
|
window.i18n_locale = (locale) ->
|
@@ -28,3 +29,5 @@ $(document).ready ->
|
|
28
29
|
anchor = $(this).data('anchor')
|
29
30
|
unless $(anchor).offset() == undefined
|
30
31
|
$(window).scrollTop $(anchor).offset().top
|
32
|
+
|
33
|
+
clipboard = new Clipboard '.clipboard-btn'
|
@@ -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
|
@@ -15,11 +15,11 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
|
|
15
15
|
|
16
16
|
def image_view(original, thumb: nil, filename: nil)
|
17
17
|
if original.present?
|
18
|
-
thumb ||= original.small
|
19
|
-
filename ||= original.path.split('/').last
|
20
|
-
src_thumb = if thumb
|
18
|
+
thumb ||= original.is_a?(CarrierWave::Uploader::Base) ? original.small : nil
|
19
|
+
filename ||= original.is_a?(CarrierWave::Uploader::Base) ? original.path.split('/').last : nil
|
20
|
+
src_thumb = if thumb&.is_a?(CarrierWave::Uploader::Base)
|
21
21
|
thumb.url
|
22
|
-
elsif thumb
|
22
|
+
elsif thumb&.match(%r{^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|(?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))$})
|
23
23
|
"data:image/jpeg;base64,#{thumb}"
|
24
24
|
else
|
25
25
|
thumb
|
@@ -33,12 +33,12 @@ module Tramway::Core::Concerns::AttributesDecoratorHelper
|
|
33
33
|
end
|
34
34
|
content_tag(:div) do
|
35
35
|
begin
|
36
|
-
concat image_tag src_thumb
|
36
|
+
concat image_tag src_thumb || src_original
|
37
37
|
rescue NoMethodError => e
|
38
38
|
error = Tramway::Error.new plugin: :core, method: :image_view, message: "You should mount PhotoUploader to your model. Just add `mount_uploader \#{attribute_name}, PhotoUploader` to your model. #{e.message}"
|
39
39
|
raise error.message
|
40
40
|
end
|
41
|
-
concat link_to(fa_icon(:download), src_original, class: 'btn btn-success', download: filename)
|
41
|
+
concat link_to(fa_icon(:download), src_original, class: 'btn btn-success', download: filename) if filename
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
@@ -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:
|
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
|
-
|
173
|
-
|
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
|
@@ -19,11 +19,15 @@ module Tramway
|
|
19
19
|
end
|
20
20
|
|
21
21
|
scope :active, -> { where state: :active }
|
22
|
-
scope :created_by_user, ->
|
23
|
-
scope :admin_scope, ->
|
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 }
|
24
24
|
|
25
25
|
include ::PgSearch::Model
|
26
26
|
|
27
|
+
def creator
|
28
|
+
audits.where(action: :create).first.user
|
29
|
+
end
|
30
|
+
|
27
31
|
# FIXME: detect inhertited locales
|
28
32
|
class << self
|
29
33
|
def human_attribute_name(attribute_name, *_args)
|
@@ -0,0 +1 @@
|
|
1
|
+
!= @message
|
@@ -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"
|
data/lib/tramway/core.rb
CHANGED
data/lib/tramway/core/version.rb
CHANGED
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.
|
4
|
+
version: 1.16.1.3
|
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-
|
11
|
+
date: 2020-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: audited
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
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'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: enumerize
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -346,6 +360,7 @@ files:
|
|
346
360
|
- app/forms/tramway/core/extendable_form.rb
|
347
361
|
- app/forms/tramway/core/extended_application_form.rb
|
348
362
|
- app/forms/tramway/core/form_creator.rb
|
363
|
+
- app/helpers/tramway/core/copy_to_clipboard_helper.rb
|
349
364
|
- app/helpers/tramway/core/title_helper.rb
|
350
365
|
- app/inputs/date_picker_input.rb
|
351
366
|
- app/models/tramway/core/application_record.rb
|
@@ -353,6 +368,7 @@ files:
|
|
353
368
|
- app/uploaders/file_uploader.rb
|
354
369
|
- app/uploaders/image_defaults.rb
|
355
370
|
- app/uploaders/photo_uploader.rb
|
371
|
+
- app/views/tramway/core/404.haml
|
356
372
|
- app/views/tramway/core/shared/_input_extended.html.haml
|
357
373
|
- app/views/tramway/core/shared/_messages.html.haml
|
358
374
|
- app/views/tramway/core/shared/input_extended_types/_checkbox.html.haml
|