tramway-core 1.16.1.7 → 1.17
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/assets/javascripts/tramway/core/application.js +51 -0
- data/app/decorators/tramway/core/application_decorator.rb +3 -35
- data/app/decorators/tramway/core/associations/class_helper.rb +40 -0
- data/app/decorators/tramway/core/associations/object_helper.rb +13 -0
- data/app/forms/tramway/core/application_form.rb +10 -0
- data/app/helpers/tramway/core/copy_to_clipboard_helper.rb +6 -4
- data/app/uploaders/photo_uploader.rb +2 -1
- data/config/locales/en/helpers.yml +1 -0
- data/lib/tramway/core/version.rb +1 -1
- metadata +24 -22
- data/app/assets/javascripts/tramway/core/application.js.coffee +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 794b0a09c09fa7b4ba63ed246ebe1dc1809f3744cd53acc4d9d58c4eebd690f3
|
4
|
+
data.tar.gz: c834a2ab88aac405a344945a5411034aea8ed952dd4f616dcceb22ea853de091
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e38836d55bed1db9f83e23f5c7705a0c98977fb845cffe18728ca30584d2659b153986b48f5c95c7d134ea08211caa3e9941ad09d9397adc7ea273a7e4388a94
|
7
|
+
data.tar.gz: 1a8d9e9a054b9f42a93e88f3d506c1d489e7a7a139dd0eaa0595bdc47642b6fc3f6b6b77f074e81803c4d0edce7114bd5b054d2ee2dafc2442778676abfe1396
|
@@ -0,0 +1,51 @@
|
|
1
|
+
//= require jquery
|
2
|
+
//= require jquery_ujs
|
3
|
+
//= require jquery3
|
4
|
+
//= require popper
|
5
|
+
//= require bootstrap
|
6
|
+
//= require bootstrap-datepicker-1.8.0
|
7
|
+
//= require bootstrap-datepicker-1.8.0.ru.min
|
8
|
+
//= require font_awesome5
|
9
|
+
//= require clipboard
|
10
|
+
//= require_tree .
|
11
|
+
|
12
|
+
window.i18n_locale = function(locale) {
|
13
|
+
switch (locale) {
|
14
|
+
case 'en':
|
15
|
+
return({ date_format: 'yyyy-mm-dd', locale: locale });
|
16
|
+
break;
|
17
|
+
case 'ru':
|
18
|
+
return({ date_format: 'dd.mm.yyyy', locale: locale });
|
19
|
+
break;
|
20
|
+
default:
|
21
|
+
return({ date_format: 'yyyy-mm-dd', locale: locale });
|
22
|
+
break;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
|
26
|
+
$(document).ready(function() {
|
27
|
+
if (!(window.current_locale)) {
|
28
|
+
console.log('You should set `window.current_locale` before all Javascript code');
|
29
|
+
}
|
30
|
+
|
31
|
+
if ($('.date_picker').length == 0) {
|
32
|
+
$('.date_picker').datepicker({
|
33
|
+
format: window.current_locale.date_format,
|
34
|
+
language: window.current_locale.locale
|
35
|
+
});
|
36
|
+
}
|
37
|
+
|
38
|
+
$('.link').click(function() {
|
39
|
+
const href = $(this).data('href');
|
40
|
+
if (href) {
|
41
|
+
location.href = href;
|
42
|
+
} else {
|
43
|
+
const anchor = $(this).data('anchor');
|
44
|
+
if (!$(anchor).offset() == undefined) {
|
45
|
+
$(window).scrollTop($(anchor).offset().top);
|
46
|
+
}
|
47
|
+
};
|
48
|
+
});
|
49
|
+
|
50
|
+
let clipboard = new Clipboard('.clipboard-btn');
|
51
|
+
});
|
@@ -7,6 +7,7 @@ class Tramway::Core::ApplicationDecorator
|
|
7
7
|
include ActionView::Context
|
8
8
|
include ::FontAwesome5::Rails::IconHelper
|
9
9
|
include ::Tramway::Core::CopyToClipboardHelper
|
10
|
+
include ::Tramway::Core::Associations::ObjectHelper
|
10
11
|
|
11
12
|
def initialize(object)
|
12
13
|
@object = object
|
@@ -22,6 +23,8 @@ class Tramway::Core::ApplicationDecorator
|
|
22
23
|
end
|
23
24
|
|
24
25
|
class << self
|
26
|
+
include ::Tramway::Core::Associations::ClassHelper
|
27
|
+
|
25
28
|
def collections
|
26
29
|
[:all]
|
27
30
|
end
|
@@ -49,41 +52,6 @@ class Tramway::Core::ApplicationDecorator
|
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
|
-
def decorate_association(association_name, decorator: nil, as: nil)
|
53
|
-
@@decorated_associations ||= []
|
54
|
-
@@decorated_associations << association_name
|
55
|
-
|
56
|
-
define_method association_name do
|
57
|
-
association = object.class.reflect_on_association(association_name)
|
58
|
-
if association.nil?
|
59
|
-
error = Tramway::Error.new(plugin: :core, method: :decorate_association, message: "Model #{object.class} does not have association named `#{association_name}`")
|
60
|
-
raise error.message
|
61
|
-
end
|
62
|
-
class_name = if association.polymorphic?
|
63
|
-
object.send(association_name).class
|
64
|
-
else
|
65
|
-
unless association.options[:class_name]
|
66
|
-
error = Tramway::Error.new(plugin: :core, method: :decorate_association, message: "Please, specify `#{association_name}` association class_name in #{object.class} model. For example: `has_many :#{association_name}, class_name: '#{association_name.to_s.singularize.camelize}'`")
|
67
|
-
raise error.message
|
68
|
-
end
|
69
|
-
association.options[:class_name]
|
70
|
-
end
|
71
|
-
decorator_class_name = decorator || "#{class_name.to_s.singularize}Decorator".constantize
|
72
|
-
if association.class == ActiveRecord::Reflection::HasManyReflection
|
73
|
-
return object.send(association_name).active.map do |association_object|
|
74
|
-
decorator_class_name.decorate association_object
|
75
|
-
end
|
76
|
-
end
|
77
|
-
if association.class == ActiveRecord::Reflection::BelongsToReflection
|
78
|
-
return decorator_class_name.decorate object.send association_name
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
define_method "#{association_name}_as" do
|
83
|
-
as
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
55
|
def model_class
|
88
56
|
to_s.sub(/Decorator$/, '').constantize
|
89
57
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Tramway::Core::Associations::ClassHelper
|
2
|
+
def decorate_association(association_name, decorator: nil, as: nil, state_machines: [])
|
3
|
+
@@decorated_associations ||= []
|
4
|
+
@@decorated_associations << association_name
|
5
|
+
|
6
|
+
define_main_association_method association_name, decorator
|
7
|
+
|
8
|
+
define_method "#{association_name}_as" do
|
9
|
+
as
|
10
|
+
end
|
11
|
+
|
12
|
+
define_method "#{association_name}_state_machines" do
|
13
|
+
state_machines
|
14
|
+
end
|
15
|
+
|
16
|
+
define_method "add_#{association_name}_form" do
|
17
|
+
"Admin::#{object.class.to_s.pluralize}::Add#{association_name.to_s.camelize.singularize}Form".constantize.new object
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def define_main_association_method(association_name, decorator)
|
23
|
+
define_method association_name do
|
24
|
+
association = object.class.reflect_on_association(association_name)
|
25
|
+
if association.nil?
|
26
|
+
error = Tramway::Error.new(plugin: :core, method: :decorate_association, message: "Model #{object.class} does not have association named `#{association_name}`")
|
27
|
+
raise error.message
|
28
|
+
end
|
29
|
+
decorator_class_name = decorator || "#{class_name(association).to_s.singularize}Decorator".constantize
|
30
|
+
if association.class.in? [ ActiveRecord::Reflection::HasManyReflection, ActiveRecord::Reflection::HasAndBelongsToManyReflection ]
|
31
|
+
return object.send(association_name).active.map do |association_object|
|
32
|
+
decorator_class_name.decorate association_object
|
33
|
+
end
|
34
|
+
end
|
35
|
+
if association.class == ActiveRecord::Reflection::BelongsToReflection
|
36
|
+
return decorator_class_name.decorate object.send association_name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Tramway::Core::Associations::ObjectHelper
|
2
|
+
def class_name(association)
|
3
|
+
if association.polymorphic?
|
4
|
+
object.send(association_name).class
|
5
|
+
else
|
6
|
+
unless association.options[:class_name]
|
7
|
+
error = Tramway::Error.new(plugin: :core, method: :decorate_association, message: "Please, specify `#{association_name}` association class_name in #{object.class} model. For example: `has_many :#{association_name}, class_name: '#{association_name.to_s.singularize.camelize}'`")
|
8
|
+
raise error.message
|
9
|
+
end
|
10
|
+
association.options[:class_name]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -65,6 +65,10 @@ module Tramway::Core
|
|
65
65
|
@@model_class.model_name
|
66
66
|
end
|
67
67
|
|
68
|
+
def associations
|
69
|
+
@@associations
|
70
|
+
end
|
71
|
+
|
68
72
|
def form_properties(**args)
|
69
73
|
@form_properties = args
|
70
74
|
end
|
@@ -97,6 +101,12 @@ module Tramway::Core
|
|
97
101
|
end
|
98
102
|
end
|
99
103
|
|
104
|
+
def attributes
|
105
|
+
properties.reduce({}) do |hash, property|
|
106
|
+
hash.merge! property.first => model.values[property.first.to_s]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
100
110
|
class << self
|
101
111
|
delegate :defined_enums, to: :model_class
|
102
112
|
|
@@ -1,12 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Tramway
|
2
4
|
module Core
|
3
5
|
module CopyToClipboardHelper
|
4
6
|
def copy_to_clipboard(id)
|
5
7
|
button_tag class: 'btn btn-info clipboard-btn',
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
data: { clipboard_action: 'copy', clipboard_target: "##{id}" },
|
9
|
+
style: 'margin-left: 15px' do
|
10
|
+
fa_icon 'copy'
|
11
|
+
end
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -11,7 +11,8 @@ class PhotoUploader < ApplicationUploader
|
|
11
11
|
if file.present? && File.exist?(file.file)
|
12
12
|
file.file.match(%r{/system/uploads/.*}).to_s
|
13
13
|
else
|
14
|
-
'/assets/tramway/core/mona_lisa_from_prado_square.jpg'
|
14
|
+
default_url = '/assets/tramway/core/mona_lisa_from_prado_square.jpg'
|
15
|
+
File.exist?(default_url) ? default_url : ''
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
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.17'
|
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-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: audited
|
@@ -118,22 +118,22 @@ dependencies:
|
|
118
118
|
name: haml-rails
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- - ">="
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
version: 1.0.0
|
124
121
|
- - "~>"
|
125
122
|
- !ruby/object:Gem::Version
|
126
123
|
version: '1.0'
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.0.0
|
127
127
|
type: :runtime
|
128
128
|
prerelease: false
|
129
129
|
version_requirements: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- - ">="
|
132
|
-
- !ruby/object:Gem::Version
|
133
|
-
version: 1.0.0
|
134
131
|
- - "~>"
|
135
132
|
- !ruby/object:Gem::Version
|
136
133
|
version: '1.0'
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.0.0
|
137
137
|
- !ruby/object:Gem::Dependency
|
138
138
|
name: kaminari
|
139
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,22 +166,22 @@ dependencies:
|
|
166
166
|
name: mini_magick
|
167
167
|
requirement: !ruby/object:Gem::Requirement
|
168
168
|
requirements:
|
169
|
-
- - ">="
|
170
|
-
- !ruby/object:Gem::Version
|
171
|
-
version: 4.8.0
|
172
169
|
- - "~>"
|
173
170
|
- !ruby/object:Gem::Version
|
174
171
|
version: '4.8'
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: 4.8.0
|
175
175
|
type: :runtime
|
176
176
|
prerelease: false
|
177
177
|
version_requirements: !ruby/object:Gem::Requirement
|
178
178
|
requirements:
|
179
|
-
- - ">="
|
180
|
-
- !ruby/object:Gem::Version
|
181
|
-
version: 4.8.0
|
182
179
|
- - "~>"
|
183
180
|
- !ruby/object:Gem::Version
|
184
181
|
version: '4.8'
|
182
|
+
- - ">="
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: 4.8.0
|
185
185
|
- !ruby/object:Gem::Dependency
|
186
186
|
name: pg_search
|
187
187
|
requirement: !ruby/object:Gem::Requirement
|
@@ -228,22 +228,22 @@ dependencies:
|
|
228
228
|
name: rmagick
|
229
229
|
requirement: !ruby/object:Gem::Requirement
|
230
230
|
requirements:
|
231
|
-
- - ">="
|
232
|
-
- !ruby/object:Gem::Version
|
233
|
-
version: 2.16.0
|
234
231
|
- - "~>"
|
235
232
|
- !ruby/object:Gem::Version
|
236
233
|
version: '2.16'
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: 2.16.0
|
237
237
|
type: :runtime
|
238
238
|
prerelease: false
|
239
239
|
version_requirements: !ruby/object:Gem::Requirement
|
240
240
|
requirements:
|
241
|
-
- - ">="
|
242
|
-
- !ruby/object:Gem::Version
|
243
|
-
version: 2.16.0
|
244
241
|
- - "~>"
|
245
242
|
- !ruby/object:Gem::Version
|
246
243
|
version: '2.16'
|
244
|
+
- - ">="
|
245
|
+
- !ruby/object:Gem::Version
|
246
|
+
version: 2.16.0
|
247
247
|
- !ruby/object:Gem::Dependency
|
248
248
|
name: sass-rails
|
249
249
|
requirement: !ruby/object:Gem::Requirement
|
@@ -349,12 +349,14 @@ files:
|
|
349
349
|
- app/assets/images/tramway/core/mona_lisa_from_prado_square.jpg
|
350
350
|
- app/assets/javascripts/bootstrap-datepicker-1.8.0.js
|
351
351
|
- app/assets/javascripts/bootstrap-datepicker-1.8.0.ru.min.js
|
352
|
-
- app/assets/javascripts/tramway/core/application.js
|
352
|
+
- app/assets/javascripts/tramway/core/application.js
|
353
353
|
- app/assets/stylesheets/bootstrap-datepicker-1.8.0.css
|
354
354
|
- app/assets/stylesheets/tramway/core/application.sass
|
355
355
|
- app/controllers/tramway/core/application_controller.rb
|
356
356
|
- app/decorators/tramway/core/application_decorated_collection.rb
|
357
357
|
- app/decorators/tramway/core/application_decorator.rb
|
358
|
+
- app/decorators/tramway/core/associations/class_helper.rb
|
359
|
+
- app/decorators/tramway/core/associations/object_helper.rb
|
358
360
|
- app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
|
359
361
|
- app/forms/tramway/core/application_form.rb
|
360
362
|
- app/forms/tramway/core/extendable_form.rb
|
@@ -424,7 +426,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
424
426
|
- !ruby/object:Gem::Version
|
425
427
|
version: '0'
|
426
428
|
requirements: []
|
427
|
-
rubygems_version: 3.
|
429
|
+
rubygems_version: 3.1.2
|
428
430
|
signing_key:
|
429
431
|
specification_version: 4
|
430
432
|
summary: Core for all Tramway Rails Engines
|
@@ -1,35 +0,0 @@
|
|
1
|
-
#= require jquery
|
2
|
-
#= require jquery_ujs
|
3
|
-
#= require jquery3
|
4
|
-
#= require popper
|
5
|
-
#= require bootstrap
|
6
|
-
#= require bootstrap-datepicker-1.8.0
|
7
|
-
#= require bootstrap-datepicker-1.8.0.ru.min
|
8
|
-
#= require font_awesome5
|
9
|
-
#= require clipboard
|
10
|
-
#= require_tree .
|
11
|
-
|
12
|
-
window.i18n_locale = (locale) ->
|
13
|
-
switch locale
|
14
|
-
when 'en' then { date_format: 'yyyy-mm-dd', locale: locale }
|
15
|
-
when 'ru' then { date_format: 'dd.mm.yyyy', locale: locale }
|
16
|
-
|
17
|
-
$(document).ready ->
|
18
|
-
unless window.current_locale
|
19
|
-
console.log 'You should set `window.current_locale` before all Javascript code'
|
20
|
-
unless $('.date_picker').length == 0
|
21
|
-
$('.date_picker').datepicker({
|
22
|
-
format: window.current_locale.date_format,
|
23
|
-
language: window.current_locale.locale
|
24
|
-
})
|
25
|
-
|
26
|
-
$('.link').click ->
|
27
|
-
href = $(this).data('href')
|
28
|
-
if href
|
29
|
-
location.href = href
|
30
|
-
else
|
31
|
-
anchor = $(this).data('anchor')
|
32
|
-
unless $(anchor).offset() == undefined
|
33
|
-
$(window).scrollTop $(anchor).offset().top
|
34
|
-
|
35
|
-
clipboard = new Clipboard '.clipboard-btn'
|