system_settings 0.6.2 → 0.9.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 +11 -13
- data/app/assets/config/manifest.js +1 -0
- data/app/assets/stylesheets/system_settings/application.css +227 -0
- data/app/controllers/system_settings/application_controller.rb +3 -9
- data/app/controllers/system_settings/settings_controller.rb +25 -21
- data/app/helpers/system_settings/application_helper.rb +36 -0
- data/app/models/system_settings/application_record.rb +2 -4
- data/app/models/system_settings/boolean_setting.rb +3 -5
- data/app/models/system_settings/configurator.rb +103 -79
- data/app/models/system_settings/decimal_list_setting.rb +6 -0
- data/app/models/system_settings/decimal_setting.rb +6 -0
- data/app/models/system_settings/errors/error.rb +2 -4
- data/app/models/system_settings/errors/not_found_error.rb +2 -4
- data/app/models/system_settings/errors/not_loaded_error.rb +6 -0
- data/app/models/system_settings/errors/settings_read_error.rb +2 -4
- data/app/models/system_settings/integer_list_setting.rb +3 -5
- data/app/models/system_settings/integer_setting.rb +3 -5
- data/app/models/system_settings/list_of_decimals_validator.rb +35 -0
- data/app/models/system_settings/list_of_integers_validator.rb +23 -25
- data/app/models/system_settings/list_of_strings_validator.rb +23 -25
- data/app/models/system_settings/setting.rb +3 -5
- data/app/models/system_settings/string_list_setting.rb +3 -5
- data/app/models/system_settings/string_setting.rb +7 -4
- data/app/models/system_settings/type/decimal_list.rb +40 -0
- data/app/models/system_settings/type/integer_list.rb +24 -33
- data/app/models/system_settings/type/string_list.rb +19 -21
- data/app/views/layouts/system_settings/application.html.erb +21 -0
- data/app/views/system_settings/settings/_common_attributes.html.erb +14 -0
- data/app/views/system_settings/settings/_form.html.erb +18 -0
- data/app/views/system_settings/settings/edit.html.erb +2 -0
- data/app/views/system_settings/settings/index.html.erb +29 -0
- data/app/views/system_settings/settings/show.html.erb +9 -0
- data/config/locales/system_settings.en.yml +27 -1
- data/config/routes.rb +5 -4
- data/lib/system_settings.rb +3 -2
- data/lib/system_settings/engine.rb +3 -12
- data/lib/system_settings/version.rb +1 -1
- metadata +17 -14
- data/app/controllers/system_settings/root_controller.rb +0 -13
- data/app/models/system_settings/pagination.rb +0 -20
- data/frontend/build/asset-manifest.json +0 -11
- data/frontend/build/favicon.ico +0 -0
- data/frontend/build/index.html +0 -1
- data/frontend/build/precache-manifest.c31853abffc7c301755b0e5b8443e875.js +0 -22
- data/frontend/build/service-worker.js +0 -39
- data/frontend/build/static/css/main.879d159f.chunk.css +0 -1
- data/frontend/build/static/js/2.8729aa12.chunk.js +0 -1
- data/frontend/build/static/js/main.99494978.chunk.js +0 -1
- data/frontend/build/static/js/runtime~main.ea5ad98e.js +0 -1
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
validates :value, "system_settings/list_of_integers": true
|
7
|
-
end
|
3
|
+
class SystemSettings::IntegerListSetting < SystemSettings::Setting
|
4
|
+
attribute :value, SystemSettings::Type::IntegerList.new(limit: 8)
|
5
|
+
validates :value, "system_settings/list_of_integers": true
|
8
6
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
validates :value, numericality: { only_integer: true }
|
7
|
-
end
|
3
|
+
class SystemSettings::IntegerSetting < SystemSettings::Setting
|
4
|
+
attribute :value, :integer, limit: 8
|
5
|
+
validates :value, numericality: { only_integer: true }
|
8
6
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class SystemSettings::ListOfDecimalsValidator < ActiveModel::EachValidator
|
4
|
+
LIST_REGEXP = /\A[+-]?\d+(?:\.\d+){0,1}(?:; *[+-]?\d+(?:\.\d+){0,1})*\z/.freeze
|
5
|
+
SINGLE_REGEXP = /\A[+-]?\d+(?:\.\d+){0,1}\z/.freeze
|
6
|
+
|
7
|
+
def validate_each(record, attr_name, value)
|
8
|
+
came_from_user = :"#{attr_name}_came_from_user?"
|
9
|
+
|
10
|
+
raw_value = record.read_attribute_before_type_cast(attr_name) if record.respond_to?(came_from_user) && record.public_send(came_from_user)
|
11
|
+
raw_value ||= value
|
12
|
+
|
13
|
+
raw_value = value if record_attribute_changed_in_place?(record, attr_name)
|
14
|
+
|
15
|
+
record.errors.add(attr_name, :not_a_list_of_decimals) unless matches_list_of_decimals_regexp?(raw_value)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def record_attribute_changed_in_place?(record, attr_name)
|
21
|
+
record.respond_to?(:attribute_changed_in_place?) &&
|
22
|
+
record.attribute_changed_in_place?(attr_name.to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
def matches_list_of_decimals_regexp?(raw_value)
|
26
|
+
case raw_value
|
27
|
+
when String
|
28
|
+
LIST_REGEXP.match?(raw_value)
|
29
|
+
when Array
|
30
|
+
raw_value.all? { |v| SINGLE_REGEXP.match?(v.to_s) }
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,37 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
SINGLE_REGEXP = /\A[+-]?\d+\z/.freeze
|
3
|
+
class SystemSettings::ListOfIntegersValidator < ActiveModel::EachValidator
|
4
|
+
LIST_REGEXP = /\A[+-]?\d+(?:; *[+-]?\d+)*\z/.freeze
|
5
|
+
SINGLE_REGEXP = /\A[+-]?\d+\z/.freeze
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
def validate_each(record, attr_name, value)
|
8
|
+
came_from_user = :"#{attr_name}_came_from_user?"
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
raw_value = record.read_attribute_before_type_cast(attr_name) if record.respond_to?(came_from_user) && record.public_send(came_from_user)
|
11
|
+
raw_value ||= value
|
13
12
|
|
14
|
-
|
13
|
+
raw_value = value if record_attribute_changed_in_place?(record, attr_name)
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
record.errors.add(attr_name, :not_a_list_of_integers) unless matches_list_of_integers_regexp?(raw_value)
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
private
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def record_attribute_changed_in_place?(record, attr_name)
|
21
|
+
record.respond_to?(:attribute_changed_in_place?) &&
|
22
|
+
record.attribute_changed_in_place?(attr_name.to_s)
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
25
|
+
def matches_list_of_integers_regexp?(raw_value)
|
26
|
+
case raw_value
|
27
|
+
when String
|
28
|
+
LIST_REGEXP.match?(raw_value)
|
29
|
+
when Array
|
30
|
+
raw_value.all? { |v| SINGLE_REGEXP.match?(v.to_s) }
|
31
|
+
else
|
32
|
+
false
|
35
33
|
end
|
36
34
|
end
|
37
35
|
end
|
@@ -1,38 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
NON_WHITESPACE_REGEXP = /[^[:space:]]/.freeze
|
3
|
+
class SystemSettings::ListOfStringsValidator < ActiveModel::EachValidator
|
4
|
+
NON_WHITESPACE_REGEXP = /[^[:space:]]/.freeze
|
6
5
|
|
7
|
-
|
8
|
-
|
6
|
+
def validate_each(record, attr_name, value)
|
7
|
+
came_from_user = :"#{attr_name}_came_from_user?"
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
raw_value = record.read_attribute_before_type_cast(attr_name) if record.respond_to?(came_from_user) && record.public_send(came_from_user)
|
10
|
+
raw_value ||= value
|
12
11
|
|
13
|
-
|
12
|
+
raw_value = value if record_attribute_changed_in_place?(record, attr_name)
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
record.errors.add(attr_name, :not_a_list_of_strings) unless matches_list_of_strings_regexp?(raw_value)
|
15
|
+
end
|
17
16
|
|
18
|
-
|
17
|
+
private
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def record_attribute_changed_in_place?(record, attr_name)
|
20
|
+
record.respond_to?(:attribute_changed_in_place?) &&
|
21
|
+
record.attribute_changed_in_place?(attr_name.to_s)
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
when Array
|
32
|
-
raw_value.all? { |v| NON_WHITESPACE_REGEXP.match?(v.to_s) }
|
33
|
-
else
|
34
|
-
false
|
24
|
+
def matches_list_of_strings_regexp?(raw_value)
|
25
|
+
case raw_value
|
26
|
+
when String
|
27
|
+
raw_value.split(SystemSettings::Type::StringList::DELIMITER_REGEXP).all? do |value|
|
28
|
+
NON_WHITESPACE_REGEXP.match?(value)
|
35
29
|
end
|
30
|
+
when Array
|
31
|
+
raw_value.all? { |v| NON_WHITESPACE_REGEXP.match?(v.to_s) }
|
32
|
+
else
|
33
|
+
false
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
validates :name, presence: true, uniqueness: true
|
7
|
-
end
|
3
|
+
class SystemSettings::Setting < SystemSettings::ApplicationRecord
|
4
|
+
validates :type, presence: true
|
5
|
+
validates :name, presence: true, uniqueness: true
|
8
6
|
end
|
@@ -1,8 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
validates :value, "system_settings/list_of_strings": true
|
7
|
-
end
|
3
|
+
class SystemSettings::StringListSetting < SystemSettings::Setting
|
4
|
+
attribute :value, SystemSettings::Type::StringList.new
|
5
|
+
validates :value, "system_settings/list_of_strings": true
|
8
6
|
end
|
@@ -1,8 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
class SystemSettings::StringSetting < SystemSettings::Setting
|
4
|
+
attribute :value, :string
|
5
|
+
validates :value, presence: true
|
6
|
+
|
7
|
+
def value=(original_value)
|
8
|
+
next_value = original_value.to_s.blank? ? nil : original_value.to_s.strip
|
9
|
+
super(next_value)
|
7
10
|
end
|
8
11
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SystemSettings::Type
|
4
|
+
class DecimalList < ActiveModel::Type::Value
|
5
|
+
SEPARATOR = ";"
|
6
|
+
|
7
|
+
def initialize(precision: nil, limit: nil, scale: nil)
|
8
|
+
super
|
9
|
+
@single_type = ActiveModel::Type::Decimal.new(precision: precision, limit: limit, scale: scale)
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
:decimal_list
|
14
|
+
end
|
15
|
+
|
16
|
+
def deserialize(value)
|
17
|
+
result = value.presence && JSON.parse(value)
|
18
|
+
if result.is_a?(Array)
|
19
|
+
result.map { |v| @single_type.cast(v) }
|
20
|
+
else
|
21
|
+
result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def serialize(value)
|
26
|
+
JSON.dump(value) unless value.nil?
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def cast_value(value)
|
32
|
+
case value
|
33
|
+
when Array
|
34
|
+
value.map { |v| @single_type.cast(v) }
|
35
|
+
when String
|
36
|
+
value.split(SEPARATOR).map { |v| @single_type.cast(v) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,43 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module SystemSettings
|
4
|
-
|
5
|
-
|
6
|
-
SEPARATOR = ";"
|
3
|
+
module SystemSettings::Type
|
4
|
+
class IntegerList < ActiveModel::Type::Value
|
5
|
+
SEPARATOR = ";"
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def initialize(precision: nil, limit: nil, scale: nil)
|
8
|
+
super
|
9
|
+
@single_type = ActiveModel::Type::Integer.new(precision: precision, limit: limit, scale: scale)
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def type
|
13
|
+
:integer_list
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def deserialize(value)
|
17
|
+
value.presence && JSON.parse(value)
|
18
|
+
end
|
19
|
+
|
20
|
+
def serialize(value)
|
21
|
+
JSON.dump(value) unless value.nil?
|
22
|
+
end
|
19
23
|
|
20
|
-
|
24
|
+
private
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
rescue StandardError
|
29
|
-
nil
|
30
|
-
end
|
31
|
-
end
|
32
|
-
when String
|
33
|
-
value.split(SEPARATOR).map do |v|
|
34
|
-
begin
|
35
|
-
v.to_i
|
36
|
-
rescue StandardError
|
37
|
-
nil
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
26
|
+
def cast_value(value)
|
27
|
+
case value
|
28
|
+
when Array
|
29
|
+
value.map { |v| @single_type.cast(v) }
|
30
|
+
when String
|
31
|
+
value.split(SEPARATOR).map { |v| @single_type.cast(v) }
|
41
32
|
end
|
42
33
|
end
|
43
34
|
end
|
@@ -1,30 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module SystemSettings
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
3
|
+
module SystemSettings::Type
|
4
|
+
class StringList < ActiveModel::Type::Value
|
5
|
+
DELIMITER_REGEXP = /(?<=[^\\]);/.freeze
|
6
|
+
def type
|
7
|
+
:string_list
|
8
|
+
end
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
def deserialize(value)
|
11
|
+
value.presence && JSON.parse(value)
|
12
|
+
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def serialize(value)
|
15
|
+
JSON.dump(value) unless value.nil?
|
16
|
+
end
|
18
17
|
|
19
|
-
|
18
|
+
private
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
20
|
+
def cast_value(value)
|
21
|
+
case value
|
22
|
+
when Array
|
23
|
+
value.map { |v| String(v).strip }
|
24
|
+
when String
|
25
|
+
value.split(DELIMITER_REGEXP).map(&:strip).map { |str| str.gsub("\\;", ";") }
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|