tramway-core 1.16.1.9 → 1.17.1.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 +4 -4
- data/README.md +33 -0
- data/app/assets/javascripts/tramway/core/application.js +51 -0
- data/app/decorators/tramway/core/application_decorator.rb +3 -39
- 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 +5 -1
- data/app/forms/tramway/core/extendable_form.rb +13 -4
- data/app/helpers/tramway/core/copy_to_clipboard_helper.rb +6 -4
- data/app/uploaders/photo_uploader.rb +1 -1
- data/app/views/tramway/core/shared/input_extended_types/_checkbox.html.haml +1 -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: 4be07671b875ed3901b13904f9d54f3915ab5c4c42d637609a25bebee8b233a0
|
4
|
+
data.tar.gz: 77d1050db409315611f0fda8586c20cd15aa9b85e49d23f86ebc995556e420da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 875d00ccf2b6cdfa9bdb7fb64ab77b60b517be9f4ae24f856b5e79e2e90c068d97f074ea4df90b70f70457dbbbd955525d850f3f6a5939ba404eec020d144fc6
|
7
|
+
data.tar.gz: 3c0ffdef1b9dba8d41353908a82d2841879b9490d191e10ca017ed16d6b14bbabceeb5da27318dbf1939203820eed1d3227980e59f0410864e74785e48d85f68
|
data/README.md
CHANGED
@@ -106,6 +106,39 @@ Something like this:
|
|
106
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
107
|
```
|
108
108
|
|
109
|
+
## How to create model that will be an Application Model for the Tramway
|
110
|
+
|
111
|
+
#### 1. Generate model that you to use. We create Organization, for example
|
112
|
+
|
113
|
+
```shell
|
114
|
+
rails g model organization name:text public_name:text tagline:text address:text phone:text coordinates:point, state: text # remember! State field is required, if you use tramway-admin
|
115
|
+
rails db:migrate
|
116
|
+
```
|
117
|
+
|
118
|
+
#### 2. Add model_class to Initializer
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
Tramway::Core.initialize_application model_class: Organization
|
122
|
+
```
|
123
|
+
|
124
|
+
#### 3. Create 1 instance of Organization model
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
rails c
|
128
|
+
Organization.create! public_name: 'Tramway', name: :organization, tagline: 'Tramway is not buggy, LOL!'
|
129
|
+
```
|
130
|
+
|
131
|
+
#### 4. Add model to singleton to the `tramway-admin` admin panel to be able to change its data
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
Tramway::Admin.set_singleton_models Organization, project: :organization # now you should use organization.name here
|
135
|
+
```
|
136
|
+
|
137
|
+
#### 5. Then continue configuration of your model in admin panel with tramway-admin gem [instruction, starting from point 8](https://github.com/ulmic/tramway-dev/tree/develop/tramway-admin#8-configurate-navbar)
|
138
|
+
|
139
|
+
#### 6. Now you are able to change your application main info in admin panel
|
140
|
+
|
141
|
+
## In Russian
|
109
142
|
|
110
143
|
# Базовые классы
|
111
144
|
|
@@ -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,45 +52,6 @@ class Tramway::Core::ApplicationDecorator
|
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
|
-
def decorate_association(association_name, decorator: nil, as: nil, state_machines: [])
|
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
|
-
|
86
|
-
define_method "#{association_name}_state_machines" do
|
87
|
-
state_machines
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
55
|
def model_class
|
92
56
|
to_s.sub(/Decorator$/, '').constantize
|
93
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
|
@@ -99,7 +103,7 @@ module Tramway::Core
|
|
99
103
|
|
100
104
|
def attributes
|
101
105
|
properties.reduce({}) do |hash, property|
|
102
|
-
hash.merge! property =>
|
106
|
+
hash.merge! property.first => model.values[property.first.to_s]
|
103
107
|
end
|
104
108
|
end
|
105
109
|
|
@@ -51,10 +51,19 @@ class Tramway::Core::ExtendableForm
|
|
51
51
|
|
52
52
|
define_method "#{property[0]}=" do |value|
|
53
53
|
property[1][:validates].each do |pair|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
case pair[0].to_s
|
55
|
+
when 'presence'
|
56
|
+
validator_object = "#{pair[0].to_s.camelize}Validator".constantize.new(attributes: :not_blank)
|
57
|
+
if pair[1] == 'true' && !validator_object.send(:valid?, value)
|
58
|
+
model.errors.add property[0],
|
59
|
+
I18n.t("activerecord.errors.models.#{model.class.name.underscore}.attributes.default.#{pair[0]}", value: value)
|
60
|
+
end
|
61
|
+
when 'inclusion'
|
62
|
+
in_array = pair[1][:in]
|
63
|
+
unless value.in? in_array
|
64
|
+
model.errors.add property[0],
|
65
|
+
I18n.t("activerecord.errors.models.#{model.class.name.underscore}.attributes.default.#{pair[0]}", value: value)
|
66
|
+
end
|
58
67
|
end
|
59
68
|
end
|
60
69
|
end
|
@@ -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
|
@@ -12,7 +12,7 @@ class PhotoUploader < ApplicationUploader
|
|
12
12
|
file.file.match(%r{/system/uploads/.*}).to_s
|
13
13
|
else
|
14
14
|
default_url = '/assets/tramway/core/mona_lisa_from_prado_square.jpg'
|
15
|
-
File.
|
15
|
+
File.exist?(default_url) ? default_url : ''
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -1 +1 @@
|
|
1
|
-
= f.input field.title.to_sym, as: :boolean, input_html: { class: class_name, id: "#{class_name}_#{field.title.to_sym}", name: "#{class_name}[#{field.title}]" }, checked_value:
|
1
|
+
= f.input field.title.to_sym, as: :boolean, input_html: { class: class_name, id: "#{class_name}_#{field.title.to_sym}", name: "#{class_name}[#{field.title}]" }, checked_value: :true, unchecked_value: :false, required: field.required
|
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.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: 2020-03-
|
11
|
+
date: 2020-03-12 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'
|