anoubis 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +38 -0
- data/app/controllers/anoubis/application_controller.rb +78 -0
- data/app/controllers/anoubis/core/application_controller.rb +343 -0
- data/app/controllers/anoubis/core/data/actions.rb +962 -0
- data/app/controllers/anoubis/core/data/callbacks.rb +68 -0
- data/app/controllers/anoubis/core/data/convert.rb +407 -0
- data/app/controllers/anoubis/core/data/defaults.rb +217 -0
- data/app/controllers/anoubis/core/data/get.rb +531 -0
- data/app/controllers/anoubis/core/data/load.rb +89 -0
- data/app/controllers/anoubis/core/data/set.rb +49 -0
- data/app/controllers/anoubis/core/data/setup.rb +104 -0
- data/app/controllers/anoubis/core/data_controller.rb +28 -0
- data/app/controllers/anoubis/core/index/actions.rb +53 -0
- data/app/controllers/anoubis/core/index/callbacks.rb +23 -0
- data/app/controllers/anoubis/core/index_controller.rb +36 -0
- data/app/controllers/anoubis/etc/base.rb +52 -0
- data/app/controllers/anoubis/etc/data.rb +89 -0
- data/app/controllers/anoubis/etc/field.rb +468 -0
- data/app/controllers/anoubis/etc/field_options.rb +83 -0
- data/app/controllers/anoubis/etc/field_order.rb +51 -0
- data/app/controllers/anoubis/etc/filter.rb +251 -0
- data/app/controllers/anoubis/etc/menu.rb +101 -0
- data/app/controllers/anoubis/etc/model.rb +67 -0
- data/app/controllers/anoubis/etc/tab_item.rb +91 -0
- data/app/controllers/anoubis/etc.rb +8 -0
- data/app/controllers/anoubis/export.rb +47 -0
- data/app/controllers/anoubis/output/autocomplete.rb +30 -0
- data/app/controllers/anoubis/output/basic.rb +86 -0
- data/app/controllers/anoubis/output/data.rb +101 -0
- data/app/controllers/anoubis/output/delete.rb +41 -0
- data/app/controllers/anoubis/output/edit.rb +55 -0
- data/app/controllers/anoubis/output/frame.rb +227 -0
- data/app/controllers/anoubis/output/login.rb +71 -0
- data/app/controllers/anoubis/output/menu.rb +220 -0
- data/app/controllers/anoubis/output/update.rb +43 -0
- data/app/controllers/anoubis/sso/client/application_controller.rb +139 -0
- data/app/controllers/anoubis/sso/client/data/actions.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/callbacks.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/convert.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/defaults.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/get.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/load.rb +26 -0
- data/app/controllers/anoubis/sso/client/data/set.rb +5 -0
- data/app/controllers/anoubis/sso/client/data/setup.rb +5 -0
- data/app/controllers/anoubis/sso/client/data_controller.rb +21 -0
- data/app/controllers/anoubis/sso/client/index/actions.rb +79 -0
- data/app/controllers/anoubis/sso/client/index/callbacks.rb +13 -0
- data/app/controllers/anoubis/sso/client/index_controller.rb +18 -0
- data/app/controllers/anoubis/sso/server/application_controller.rb +49 -0
- data/app/controllers/anoubis/sso/server/login_controller.rb +342 -0
- data/app/controllers/anoubis/sso/server/user_controller.rb +142 -0
- data/app/controllers/anoubis/tenant/application_controller.rb +54 -0
- data/app/controllers/anoubis/tenant/data/actions.rb +11 -0
- data/app/controllers/anoubis/tenant/data/callbacks.rb +11 -0
- data/app/controllers/anoubis/tenant/data/convert.rb +11 -0
- data/app/controllers/anoubis/tenant/data/defaults.rb +11 -0
- data/app/controllers/anoubis/tenant/data/get.rb +11 -0
- data/app/controllers/anoubis/tenant/data/load.rb +52 -0
- data/app/controllers/anoubis/tenant/data/set.rb +11 -0
- data/app/controllers/anoubis/tenant/data/setup.rb +11 -0
- data/app/controllers/anoubis/tenant/data_controller.rb +28 -0
- data/app/controllers/anoubis/tenant/index/actions.rb +191 -0
- data/app/controllers/anoubis/tenant/index/callbacks.rb +11 -0
- data/app/controllers/anoubis/tenant/index_controller.rb +38 -0
- data/app/controllers/anoubis/tenants_controller.rb +7 -0
- data/app/controllers/anoubis/users_controller.rb +7 -0
- data/app/jobs/anoubis/application_job.rb +6 -0
- data/app/mailers/anoubis/application_mailer.rb +8 -0
- data/app/models/anoubis/application_record.rb +45 -0
- data/app/models/anoubis/core/application_record.rb +250 -0
- data/app/models/anoubis/core/locales.rb +27 -0
- data/app/models/anoubis/sso/client/application_record.rb +3 -0
- data/app/models/anoubis/sso/client/group.rb +19 -0
- data/app/models/anoubis/sso/client/group_menu.rb +109 -0
- data/app/models/anoubis/sso/client/menu.rb +145 -0
- data/app/models/anoubis/sso/client/user.rb +81 -0
- data/app/models/anoubis/sso/client/user_group.rb +32 -0
- data/app/models/anoubis/sso/server/system.rb +36 -0
- data/app/models/anoubis/sso/server/user.rb +79 -0
- data/app/models/anoubis/tenant/application_record.rb +41 -0
- data/app/models/anoubis/tenant/group.rb +95 -0
- data/app/models/anoubis/tenant/group_locale.rb +19 -0
- data/app/models/anoubis/tenant/group_menu.rb +84 -0
- data/app/models/anoubis/tenant/menu.rb +156 -0
- data/app/models/anoubis/tenant/menu_locale.rb +27 -0
- data/app/models/anoubis/tenant/system.rb +127 -0
- data/app/models/anoubis/tenant/system_locale.rb +19 -0
- data/app/models/anoubis/tenant/system_menu.rb +51 -0
- data/app/models/anoubis/tenant/tenant.rb +107 -0
- data/app/models/anoubis/tenant/tenant_system.rb +19 -0
- data/app/models/anoubis/tenant/user.rb +225 -0
- data/app/models/anoubis/tenant/user_group.rb +32 -0
- data/app/services/anoubis/core_service.rb +16 -0
- data/app/services/anoubis/session_service.rb +17 -0
- data/app/validators/presence_in_tenant_validator.rb +20 -0
- data/config/initializers/mime_type.rb +1 -0
- data/config/locales/en.yml +120 -0
- data/config/locales/ru.yml +245 -0
- data/config/routes.rb +74 -0
- data/db/migrate/20181018085843_create_tenants.rb +13 -0
- data/db/migrate/20181018111217_create_systems.rb +10 -0
- data/db/migrate/20181018111713_create_tenant_systems.rb +11 -0
- data/db/migrate/20181018111925_create_groups.rb +13 -0
- data/db/migrate/20181018112151_create_users.rb +25 -0
- data/db/migrate/20181018115737_add_title_to_users.rb +10 -0
- data/db/migrate/20181022060211_create_menus.rb +18 -0
- data/db/migrate/20181115055245_create_group_menus.rb +12 -0
- data/db/migrate/20181115060830_create_system_menus.rb +11 -0
- data/db/migrate/20181122062131_create_user_groups.rb +11 -0
- data/db/migrate/20181221060727_create_menu_locales.rb +14 -0
- data/db/migrate/20181225062303_create_system_locales.rb +11 -0
- data/db/migrate/20181225062339_create_group_locales.rb +11 -0
- data/db/seeds.rb +268 -0
- data/lib/anoubis/engine.rb +13 -0
- data/lib/anoubis/version.rb +5 -0
- data/lib/anoubis.rb +213 -0
- data/lib/tasks/anubis_tasks.rake +10 -0
- data/lib/tasks/sessions/clear_sessions.rake +10 -0
- data/spec/anubis_spec.rb +5 -0
- data/spec/controllers/anoubis/index_controller_spec.rb +77 -0
- data/spec/dummy/Rakefile +3 -0
- data/spec/dummy/app/assets/config/manifest.js +2 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy/app/controllers/application_controller.rb +2 -0
- data/spec/dummy/app/jobs/application_job.rb +2 -0
- data/spec/dummy/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +33 -0
- data/spec/dummy/bin/update +28 -0
- data/spec/dummy/config/application.rb +14 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +54 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +54 -0
- data/spec/dummy/config/environments/production.rb +85 -0
- data/spec/dummy/config/environments/test.rb +46 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cors.rb +16 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +34 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/spring.rb +6 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +5 -0
- data/spec/dummy/db/schema.rb +167 -0
- data/spec/dummy/db/seeds.rb +1 -0
- data/spec/factories/anubis_group_locales.rb +7 -0
- data/spec/factories/anubis_group_menus.rb +7 -0
- data/spec/factories/anubis_groups.rb +6 -0
- data/spec/factories/anubis_menu_locales.rb +9 -0
- data/spec/factories/anubis_menus.rb +6 -0
- data/spec/factories/anubis_system_locales.rb +7 -0
- data/spec/factories/anubis_system_menus.rb +6 -0
- data/spec/factories/anubis_systems.rb +5 -0
- data/spec/factories/anubis_tenants.rb +7 -0
- data/spec/factories/anubis_users.rb +10 -0
- data/spec/integration/navigation_test.rb +7 -0
- data/spec/models/anoubis/group_locale_spec.rb +25 -0
- data/spec/models/anoubis/group_menu_spec.rb +50 -0
- data/spec/models/anoubis/group_spec.rb +52 -0
- data/spec/models/anoubis/menu_locale_spec.rb +31 -0
- data/spec/models/anoubis/menu_spec.rb +48 -0
- data/spec/models/anoubis/system_locale_spec.rb +20 -0
- data/spec/models/anoubis/system_menu_spec.rb +49 -0
- data/spec/models/anoubis/system_spec.rb +53 -0
- data/spec/models/anoubis/tenant_spec.rb +67 -0
- data/spec/models/anoubis/user_spec.rb +57 -0
- data/spec/rails_helper.rb +32 -0
- data/spec/requests/anoubis/users_request_spec.rb +5 -0
- data/spec/spec_helper.rb +13 -0
- metadata +408 -0
@@ -0,0 +1,68 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Core
|
3
|
+
module Data
|
4
|
+
##
|
5
|
+
# Module presents all callbacks called in actions.
|
6
|
+
module Callbacks
|
7
|
+
##
|
8
|
+
# Fires after data was received from server and placed in {Anubis::Output::Data#data self.output.data} array.
|
9
|
+
# It's rewrote for change data before output.
|
10
|
+
def after_get_table_data
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Fires before data will be verified and converted.
|
16
|
+
# @param data [Hash] Data for update
|
17
|
+
# @return [Hash] Processed data. If returned nil then update is terminated.
|
18
|
+
def before_update_data(data)
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Fires after data was was updated on the server and placed in {Anubis::Output::Data#data self.output.data} array.
|
24
|
+
# It's rewrote for change data before output.
|
25
|
+
def after_update_data
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Fires after data was was created in {Anubis::Output::Data#data self.output.data} array and before it saved to server.
|
31
|
+
# It's rewrote for change data before output.
|
32
|
+
# @param data [Hash] Data for create
|
33
|
+
# @return [Hash] Processed data. If returned nil then update is terminated.
|
34
|
+
def before_create_data(data)
|
35
|
+
data
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Fires after data was was created on the server and placed in {Anubis::Output::Data#data self.output.data} array.
|
40
|
+
# It's rewrote for change data before output.
|
41
|
+
def after_create_data
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Fires right before output data to screen
|
47
|
+
def before_output
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Fires when data output to json value
|
53
|
+
def around_output(data)
|
54
|
+
data
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Fires when data is destroyed
|
59
|
+
def destroy_data
|
60
|
+
if !self.etc.data.data.destroy
|
61
|
+
self.output.errors.concat self.etc.data.data.errors.full_messages
|
62
|
+
self.output.result = -4
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,407 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Core
|
3
|
+
module Data
|
4
|
+
##
|
5
|
+
# Data conversion moule between database and human representation
|
6
|
+
module Convert
|
7
|
+
##
|
8
|
+
# Format a number with grouped thousands
|
9
|
+
# @param number [Float] The number being formatted.
|
10
|
+
# @param precision [Integer] Sets the number of decimal points.
|
11
|
+
# @param point [Char] Sets the separator for the decimal point.
|
12
|
+
# @param separator [Char] Sets the thousands separator.
|
13
|
+
# @return [String] A formatted version of number.
|
14
|
+
def number_format(number, precision = 2, point = ',', separator = '')
|
15
|
+
val = sprintf('%.'+precision.to_s+'f', number.round(precision)).to_s
|
16
|
+
if separator != '' && number >= 1000
|
17
|
+
whole_part, decimal_part = val.split('.')
|
18
|
+
val = [whole_part.gsub(/(\d)(?=\d{3}+$)/, '\1'+separator), decimal_part].compact.join(point)
|
19
|
+
else
|
20
|
+
val = val.gsub('.', point)
|
21
|
+
end
|
22
|
+
val
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
##
|
27
|
+
# @!group Block of conversion database value into human view format
|
28
|
+
|
29
|
+
##
|
30
|
+
# Convert value from database to view format according by defining field type and {Anubis::Etc::Base#action action}
|
31
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
32
|
+
# @param value [String] value from database
|
33
|
+
def convert_db_to_view_value(key, value)
|
34
|
+
field = self.etc.data.fields[key]
|
35
|
+
return { key => value } if !field.type
|
36
|
+
proc = format('convert_db_to_view_value_%s', field.type)
|
37
|
+
result = self.send proc, key, value
|
38
|
+
result
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Convert value from database to view format for 'string' type
|
43
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
44
|
+
# @param value [String] value from database
|
45
|
+
def convert_db_to_view_value_string(key, value)
|
46
|
+
return { key => '' } if !value
|
47
|
+
return { key => value }
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Convert value from database to view format for 'boolean' type
|
52
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
53
|
+
# @param value [Boolean] value from database
|
54
|
+
def convert_db_to_view_value_boolean(key, value)
|
55
|
+
return { key => '' } if !value
|
56
|
+
return { key => value }
|
57
|
+
end
|
58
|
+
|
59
|
+
##
|
60
|
+
# Convert value from database to view format for 'integer' type
|
61
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
62
|
+
# @param value [String] value from database
|
63
|
+
def convert_db_to_view_value_number(key, value)
|
64
|
+
return { key => self.etc.data.fields[key].error_text } if !value
|
65
|
+
return { key => value.to_s.to_i } if self.etc.data.fields[key].precision == 0
|
66
|
+
return { key => format('%.' + self.etc.data.fields[key].precision.to_s + 'f', value) }
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Convert value from database to view format for 'text' type
|
71
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
72
|
+
# @param value [String] value from database
|
73
|
+
def convert_db_to_view_value_text(key, value)
|
74
|
+
return { key => '' } if !value
|
75
|
+
return { key => value }
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Convert value from database to view format for 'html' type
|
80
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
81
|
+
# @param value [String] value from database
|
82
|
+
def convert_db_to_view_value_html(key, value)
|
83
|
+
return { key => '' } if !value
|
84
|
+
return { key => value }
|
85
|
+
end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Convert value from database to table format for 'listbox' type
|
89
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
90
|
+
# @param value [String] value from database
|
91
|
+
def convert_db_to_view_value_listbox(key, value)
|
92
|
+
field = self.etc.data.fields[key]
|
93
|
+
new_value = ''
|
94
|
+
if field.options
|
95
|
+
if field.format == 'single'
|
96
|
+
new_value = field.options.list[value.to_s.to_sym] if field.options.list
|
97
|
+
else
|
98
|
+
new_value = []
|
99
|
+
if value
|
100
|
+
if field.options.list
|
101
|
+
value.each do |key|
|
102
|
+
new_value.push field.options.list[key.to_s.to_sym]
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
case self.etc.action
|
109
|
+
when 'index', 'show', 'export'
|
110
|
+
if field.format == 'single'
|
111
|
+
return { key => new_value, format('%s_raw', key).to_sym => value }
|
112
|
+
else
|
113
|
+
return { key => new_value.join(', '), format('%s_raw', key).to_sym => new_value }
|
114
|
+
end
|
115
|
+
when 'new', 'edit'
|
116
|
+
if field.format == 'single'
|
117
|
+
return { key => value.to_s, format('%s_view', key).to_sym => new_value }
|
118
|
+
else
|
119
|
+
return { key => value, format('%s_view', key).to_sym => new_value.join(', ') }
|
120
|
+
end
|
121
|
+
else
|
122
|
+
if field.format == 'single'
|
123
|
+
return { key => value.to_s, format('%s_view', key).to_sym => new_value }
|
124
|
+
else
|
125
|
+
return { key => value, format('%s_view', key).to_sym => new_value.join(', ') }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
##
|
131
|
+
# Convert value from database to view format for 'key' type
|
132
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
133
|
+
# @param value [String] value from database
|
134
|
+
def convert_db_to_view_value_key(key, value)
|
135
|
+
return { key => '' } if !value
|
136
|
+
return { key => value }
|
137
|
+
end
|
138
|
+
|
139
|
+
##
|
140
|
+
# Convert value from database to table view for datetime type
|
141
|
+
def convert_db_to_view_value_datetime(key, value)
|
142
|
+
field = self.etc.data.fields[key]
|
143
|
+
#puts key
|
144
|
+
#puts value.class
|
145
|
+
if (value.class == Date) || (value.class == ActiveSupport::TimeWithZone)
|
146
|
+
begin
|
147
|
+
new_value = case field.format
|
148
|
+
when 'month' then I18n.t('anubis.months.main')[value.month-1]+' '+value.year.to_s
|
149
|
+
when 'date' then value.day.to_s+' '+ I18n.t('anubis.months.second')[value.month-1]+' '+value.year.to_s
|
150
|
+
when 'datetime' then value.day.to_s+' '+ I18n.t('anubis.months.second')[value.month-1]+' '+value.year.to_s+', '+value.hour.to_s+':'+('%02d' % value.min)
|
151
|
+
else value.day.to_s+' '+ I18n.t('anubis.months.second')[value.month-1]+' '+value.year.to_s+', '+value.hour.to_s+':'+('%02d' % value.min)+':'+('%02d' % value.sec)
|
152
|
+
end
|
153
|
+
if %w[month date].include? field.format
|
154
|
+
raw_value = value.year.to_s + '-' + ('%02d' % value.month) + '-' + ('%02d' % value.day)
|
155
|
+
else
|
156
|
+
#raw_value = value.year.to_s + '-' + ('%02d' % value.month) + '-' + ('%02d' % value.day) + ' ' + ('%02d' % value.hour) + ':' + ('%02d' % value.min)
|
157
|
+
raw_value = value.iso8601(2)[0..18]
|
158
|
+
end
|
159
|
+
rescue StandardError => e
|
160
|
+
#puts e
|
161
|
+
new_value = field.error_text
|
162
|
+
end
|
163
|
+
else
|
164
|
+
new_value = '';
|
165
|
+
end
|
166
|
+
|
167
|
+
case self.etc.action
|
168
|
+
when 'new', 'edit'
|
169
|
+
return { key => raw_value, format('%s_view', key).to_sym => new_value }
|
170
|
+
end
|
171
|
+
return { key => new_value, format('%s_raw', key).to_sym => value }
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
##
|
190
|
+
# Convert value from database to table view for text type
|
191
|
+
def convert_db_to_table_value_text1(key, field, value)
|
192
|
+
return { key => '', ('raw_'+key.to_s).to_sym => '' } if !value
|
193
|
+
new_value = ERB::Util.html_escape(value).to_s.gsub(/(?:\n\r?|\r\n?)/, '<br/>')
|
194
|
+
return { key => new_value, ('raw_'+key.to_s).to_sym => value }
|
195
|
+
end
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
##
|
202
|
+
# Convert value from database to table view for string type
|
203
|
+
def convert_db_to_table_value_integer1(key, field, value)
|
204
|
+
return { key => '' } if !value
|
205
|
+
return { key => value }
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
##
|
212
|
+
# Convert value from database to table view for longlistbox type
|
213
|
+
def convert_db_to_table_value_longlistbox1(key, field, value)
|
214
|
+
return { key => '' } if !value
|
215
|
+
return { key => value }
|
216
|
+
end
|
217
|
+
|
218
|
+
##
|
219
|
+
# Convert value from database to table view for datetime type
|
220
|
+
def convert_db_to_table_value_datetime1(key, field, value)
|
221
|
+
begin
|
222
|
+
value = case field[:format]
|
223
|
+
when 'month' then I18n.t('months.main')[value.month-1]+' '+value.year.to_s
|
224
|
+
when 'date' then value.day.to_s+' '+ I18n.t('months.second')[value.month-1]+' '+value.year.to_s
|
225
|
+
when 'datetime' then value.day.to_s+' '+ I18n.t('months.second')[value.month-1]+' '+value.year.to_s+', '+value.hour.to_s+':'+('%02d' % value.min)
|
226
|
+
else value.day.to_s+' '+ I18n.t('months.second')[value.month-1]+' '+value.year.to_s+', '+value.hour.to_s+':'+('%02d' % value.min)+':'+('%02d' % value.sec)
|
227
|
+
end
|
228
|
+
rescue
|
229
|
+
value = I18n.t('incorrect_field_format')
|
230
|
+
end
|
231
|
+
return { key => value }
|
232
|
+
end
|
233
|
+
|
234
|
+
##
|
235
|
+
# Convert value from database to table view for float type
|
236
|
+
# @param key [Symbol] key of table field
|
237
|
+
# @param field [Tims::Etc::Table#fields] set of options of field by <b>key</b>
|
238
|
+
# @param value [Float] value from database before processing
|
239
|
+
# @return [Hash] return resulting value at format <b>{ key: processed_value, 'raw_'+key: value }</b>
|
240
|
+
def convert_db_to_table_value_float1(key, field, value)
|
241
|
+
return { key => number_format(value, field[:precision], field[:point], field[:separator]), ('raw_'+key.to_s).to_sym => value}
|
242
|
+
end
|
243
|
+
|
244
|
+
##
|
245
|
+
# Convert value from database to edit form for datetime type
|
246
|
+
# @param key [Symbol] field's identifier
|
247
|
+
# @param field [Hash] field's options
|
248
|
+
# @param value [Any] value from database before processing
|
249
|
+
# @return [Hash] resulting value in format <b>{ key: processed_value }</b>
|
250
|
+
def convert_db_to_table_value_datetime(key, field, value)
|
251
|
+
begin
|
252
|
+
value = case field[:format]
|
253
|
+
when 'month' then I18n.t('months.main')[value.month-1]+' '+value.year.to_s
|
254
|
+
when 'date' then value.day.to_s+' '+ I18n.t('months.second')[value.month-1]+' '+value.year.to_s
|
255
|
+
when 'datetime' then value.day.to_s+' '+ I18n.t('months.second')[value.month-1]+' '+value.year.to_s+', '+value.hour.to_s+':'+('%02d' % value.min)
|
256
|
+
else value.day.to_s+' '+ I18n.t('months.second')[value.month-1]+' '+value.year.to_s+', '+value.hour.to_s+':'+('%02d' % value.min)+':'+('%02d' % value.sec)
|
257
|
+
end
|
258
|
+
rescue
|
259
|
+
value = I18n.t('incorrect_field_format')
|
260
|
+
end
|
261
|
+
return { key => value }
|
262
|
+
end
|
263
|
+
|
264
|
+
##
|
265
|
+
# Convert value from database to edit form for float type
|
266
|
+
# @param key [Symbol] field's identifier
|
267
|
+
# @param field [Anubis::Etc::Data#fields] field's options
|
268
|
+
# @param value [Float] value from database before processing
|
269
|
+
# @return [Hash] return resulting value at format <b>{ key+'_view': processed_value, key: value }</b>
|
270
|
+
def convert_db_to_table_value_float(key, field, value)
|
271
|
+
return { (key.to_s+'_view').to_sym => number_format(value, field[:precision], field[:point], field[:separator]), key => value}
|
272
|
+
end
|
273
|
+
# @!endgroup
|
274
|
+
|
275
|
+
|
276
|
+
##
|
277
|
+
# @!group Block of conversion human view values to database format
|
278
|
+
|
279
|
+
##
|
280
|
+
# Converts inputted value to database format.
|
281
|
+
# Field type is got from {Anubis::Etc::Data#fields self.etc.data.fields} according by key.
|
282
|
+
# Resulting data is placed into {Anubis::Etc::Data#data self.etc.data.data} attribute according by key.
|
283
|
+
# Errors are placed in {Anubis::Output::Update#errors self.output.errors} array according by key.
|
284
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
285
|
+
# @param value [String] value from user input
|
286
|
+
def convert_view_to_db_value(key, value)
|
287
|
+
field = self.etc.data.fields[key]
|
288
|
+
return { key => value } unless field
|
289
|
+
return { key => value } unless field.type
|
290
|
+
proc = format('convert_view_to_db_value_%s', field.type)
|
291
|
+
self.send proc, key, value
|
292
|
+
end
|
293
|
+
|
294
|
+
##
|
295
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'string' field type}.
|
296
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
297
|
+
# @param value [String] inputted value
|
298
|
+
def convert_view_to_db_value_string(key, value)
|
299
|
+
proc = format('self.etc.data.data.%s = value', key)
|
300
|
+
#self.etc.data.data[key] = value
|
301
|
+
eval proc
|
302
|
+
end
|
303
|
+
|
304
|
+
##
|
305
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'boolean' field type}.
|
306
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
307
|
+
# @param value [Boolean] inputted value
|
308
|
+
def convert_view_to_db_value_boolean(key, value)
|
309
|
+
proc = format('self.etc.data.data.%s = value', key)
|
310
|
+
#self.etc.data.data[key] = value
|
311
|
+
eval proc
|
312
|
+
end
|
313
|
+
|
314
|
+
##
|
315
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'number' field type}.
|
316
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
317
|
+
# @param value [String] inputted value
|
318
|
+
def convert_view_to_db_value_number(key, value)
|
319
|
+
field = self.etc.data.fields[key]
|
320
|
+
if field.precision == 0
|
321
|
+
value = value.to_s.to_i
|
322
|
+
else
|
323
|
+
value = value.to_s.to_f
|
324
|
+
end
|
325
|
+
proc = format('self.etc.data.data.%s = value', key)
|
326
|
+
#self.etc.data.data[key] = value
|
327
|
+
eval proc
|
328
|
+
end
|
329
|
+
|
330
|
+
##
|
331
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'text' field type}.
|
332
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
333
|
+
# @param value [String] inputted value
|
334
|
+
def convert_view_to_db_value_text(key, value)
|
335
|
+
proc = format('self.etc.data.data.%s = value', key)
|
336
|
+
#self.etc.data.data[key] = value
|
337
|
+
eval proc
|
338
|
+
end
|
339
|
+
|
340
|
+
##
|
341
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'html' field type}.
|
342
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
343
|
+
# @param value [String] inputted value
|
344
|
+
def convert_view_to_db_value_html(key, value)
|
345
|
+
proc = format('self.etc.data.data.%s = value', key)
|
346
|
+
#self.etc.data.data[key] = value
|
347
|
+
eval proc
|
348
|
+
end
|
349
|
+
|
350
|
+
##
|
351
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'listbox' field type}
|
352
|
+
# for {Anubis::Data::Actions#create 'create'} action
|
353
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
354
|
+
# @param value [String] inputted value
|
355
|
+
def convert_view_to_db_value_listbox(key, value)
|
356
|
+
field = self.etc.data.fields[key]
|
357
|
+
begin
|
358
|
+
proc = format('self.etc.data.data.%s = value', field.field)
|
359
|
+
#self.etc.data.data[field.field] = value
|
360
|
+
eval proc
|
361
|
+
rescue
|
362
|
+
self.etc.data.data[field.field] = nil
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
##
|
367
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'key' field type}
|
368
|
+
# for {Anubis::Data::Actions#create 'create'} action
|
369
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
370
|
+
# @param value [String] inputted value
|
371
|
+
def convert_view_to_db_value_key(key, value)
|
372
|
+
field = self.etc.data.fields[key]
|
373
|
+
where = {}
|
374
|
+
where[field.model.title.to_s.to_sym] = value
|
375
|
+
value = field.model.model.where(where).first
|
376
|
+
proc = format('self.etc.data.data.%s = value', field.key)
|
377
|
+
eval(proc)
|
378
|
+
#begin
|
379
|
+
# self.etc.data.data[key] = value
|
380
|
+
# rescue
|
381
|
+
# self.etc.data.data[key] = nil
|
382
|
+
# end
|
383
|
+
end
|
384
|
+
|
385
|
+
##
|
386
|
+
# Converts inputted value to database format for {Anubis::Etc::Field#type 'datetime' field type}.
|
387
|
+
# @param key [Symbol] field's identifier in {Anubis::Etc::Data#fields self.etc.data.fields} structure
|
388
|
+
# @param value [String] inputted value
|
389
|
+
def convert_view_to_db_value_datetime(key, value)
|
390
|
+
zone = ActiveSupport::TimeZone[self.current_user.timezone]
|
391
|
+
offset = if zone.utc_offset/3600 < 0 then (zone.utc_offset/3600).to_s else '+'+(zone.utc_offset/3600).to_s end
|
392
|
+
#puts 'convert_view_to_db_value_datetime'
|
393
|
+
#puts value
|
394
|
+
value = Time.zone.parse value
|
395
|
+
#puts value
|
396
|
+
#puts zone
|
397
|
+
#puts offset
|
398
|
+
#puts value.utc_offset if value
|
399
|
+
proc = format('self.etc.data.data.%s = value', key)
|
400
|
+
#self.etc.data.data[key] = value
|
401
|
+
eval proc
|
402
|
+
end
|
403
|
+
# @!endgroup
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Core
|
3
|
+
module Data
|
4
|
+
##
|
5
|
+
# Module sets default parameters for {DataController}.
|
6
|
+
module Defaults
|
7
|
+
##
|
8
|
+
# Sets hash of defined tabs. Every tab consists of next attributes:
|
9
|
+
#
|
10
|
+
# *Attributes:*
|
11
|
+
# - *:title* (String) --- title of the tab
|
12
|
+
# - *:where* (Hash | Array) --- hash or array of where parameters for ActiveRecord request. If doesn't present
|
13
|
+
# then there are no additional where statements for current tab
|
14
|
+
#
|
15
|
+
# @return [Hash] returns hash of assigned tabs.
|
16
|
+
#
|
17
|
+
# @example Sets custom tabs
|
18
|
+
# def tabs
|
19
|
+
# {
|
20
|
+
# :all => {
|
21
|
+
# title: 'All IDs'
|
22
|
+
# },
|
23
|
+
# :id_1 => {
|
24
|
+
# title: 'Only ID 1',
|
25
|
+
# where: { id: 1 }
|
26
|
+
# },
|
27
|
+
# :other_id => {
|
28
|
+
# title: 'Other IDs',
|
29
|
+
# where: ['id > ?', 1]
|
30
|
+
# }
|
31
|
+
# }
|
32
|
+
# end
|
33
|
+
def tabs
|
34
|
+
{
|
35
|
+
:default => {
|
36
|
+
title: I18n.t('anubis.default_tab'),
|
37
|
+
tips: I18n.t('anubis.default_tab_hint')
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Sets frame buttons for every using tab.
|
44
|
+
# Key of the button is an action for frontend application. Every button consists of next attributes:
|
45
|
+
#
|
46
|
+
# *Attributes:*
|
47
|
+
# - *:type* (String) <i>(defaults to: 'default')</i> --- type of the button ('primary', 'danger', 'default')
|
48
|
+
# - *:mode* (String) <i>(defaults to: 'single')</i> --- button action object ('single', 'multiple')
|
49
|
+
#
|
50
|
+
# By default system defines two buttons: 'New' (for create new element in table) and 'Delete' (for
|
51
|
+
# delete multiple element)
|
52
|
+
#
|
53
|
+
# @param [Hash] args additional parameters are used for define frame buttons.
|
54
|
+
# @option args [String] :tab current tab is used for generation
|
55
|
+
#
|
56
|
+
# @return [Hash] returns hash of assigned buttons.
|
57
|
+
#
|
58
|
+
# @example Sets no buttons
|
59
|
+
# def frame_buttons(args = {})
|
60
|
+
# {
|
61
|
+
# }
|
62
|
+
# end
|
63
|
+
#
|
64
|
+
# @example Sets only 'New' button
|
65
|
+
# def frame_buttons(args = {})
|
66
|
+
# {
|
67
|
+
# new: { type: 'primary' }
|
68
|
+
# }
|
69
|
+
# end
|
70
|
+
def frame_buttons(args = {})
|
71
|
+
{
|
72
|
+
new: { type: 'primary' },
|
73
|
+
delete: { mode: 'multiple', type: 'danger' }
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Returns model that is used for controller actions. By default it's not defined.
|
79
|
+
# This is primary model and it must be defined in customer conroller. Different models may be defined according
|
80
|
+
# by {Anubis::Etc::Base#action self.etc.action} attribute.
|
81
|
+
# @return [Anubis::ApplicationRecord, nil, any] returns model
|
82
|
+
def model
|
83
|
+
nil
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Returns defined select fields. If returns nil, then return default select fields
|
88
|
+
def select
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# Returns eager load parameters that are used for controller actions. By default it's set to \[\].
|
94
|
+
# This procedure could be redefined in cusomer controller. Different eager loads may be defined according
|
95
|
+
# by {Anubis::Etc::Base#action self.etc.action} attribute.
|
96
|
+
def eager_load
|
97
|
+
[]
|
98
|
+
end
|
99
|
+
|
100
|
+
##
|
101
|
+
# Returns fields that is used for controller actions in defined {#model}. By default it's defined for id field.
|
102
|
+
# This is primary definition and it must be defined in customer conroller. Different fields may be defined according
|
103
|
+
# by {Anubis::Etc::Base#action self.etc.action} attribute.
|
104
|
+
# @return [Hash] returns defined fields for current model
|
105
|
+
def fields
|
106
|
+
{
|
107
|
+
id: { type: 'number', precision: 0 }
|
108
|
+
}
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Get array of field's identifiers in desired order. By default it's current defined order of all fields.
|
113
|
+
def fields_order
|
114
|
+
result = []
|
115
|
+
self.etc.data.fields.each_key do |key|
|
116
|
+
result.push key.to_s
|
117
|
+
end
|
118
|
+
result
|
119
|
+
end
|
120
|
+
|
121
|
+
##
|
122
|
+
# Get array of field's identifiers in desired order for filter form. By default it's current defined order of all fields.
|
123
|
+
def filter_order
|
124
|
+
self.fields_order
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# Returns parent model that is used for controller actions. By default it's defined as <i>nil</i>.
|
129
|
+
# This procedure could be redefined in customer controller. Different models may be defined according
|
130
|
+
# by {Anubis::Etc::Base#action self.etc.action} attribute.
|
131
|
+
# @return [Anubis::ApplicationRecord, nil] returns model
|
132
|
+
def parent_model
|
133
|
+
nil
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Returns eager load parameters for parent model that are used for controller actions. By default it's set to \[\].
|
138
|
+
# This procedure could be redefined in customer controller. Different eager loads may be defined according
|
139
|
+
# by {Anubis::Etc::Base#action self.etc.action} attribute.
|
140
|
+
def parent_eager_load
|
141
|
+
[]
|
142
|
+
end
|
143
|
+
|
144
|
+
##
|
145
|
+
# Returns parent model id. By default it's set to 0.
|
146
|
+
# This procedure could be rewrote in customer controller.
|
147
|
+
def parent_id
|
148
|
+
return 0
|
149
|
+
end
|
150
|
+
|
151
|
+
##
|
152
|
+
# @!group Block of default controller table actions
|
153
|
+
|
154
|
+
##
|
155
|
+
# Sets default table actions for every row
|
156
|
+
# @return [Array] return string array of action identifiers
|
157
|
+
def table_actions
|
158
|
+
%w[edit delete]
|
159
|
+
end
|
160
|
+
|
161
|
+
##
|
162
|
+
# Returns possibility of 'edit' action for current row
|
163
|
+
# @param row [ActiveRecord] single model's data row
|
164
|
+
def table_action_edit(row)
|
165
|
+
row.can_edit({ controller: params[:controller], tab: self.etc.tab })
|
166
|
+
end
|
167
|
+
|
168
|
+
##
|
169
|
+
# Returns possibility of 'delete' action for current row
|
170
|
+
# @param row [ActiveRecord] single model's data row
|
171
|
+
def table_action_delete(row)
|
172
|
+
row.can_delete({ controller: params[:controller], tab: self.etc.tab })
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Returns default where condition
|
177
|
+
# @return [Hash, Array] default where condition
|
178
|
+
def where
|
179
|
+
[]
|
180
|
+
end
|
181
|
+
|
182
|
+
#@!endgroup
|
183
|
+
|
184
|
+
##
|
185
|
+
# Returns export format for current action. Procedure is rewrote for change default export format.
|
186
|
+
def export_format
|
187
|
+
'xls'
|
188
|
+
end
|
189
|
+
|
190
|
+
##
|
191
|
+
# Returns filter possibility for defined options. It's rewrote for custom controllers.
|
192
|
+
# @param [Hash] args additional parameters.
|
193
|
+
# @option args [String] :tab current tab is used for generation
|
194
|
+
# @return [Boolean] Possibility of filter table data. Default: true
|
195
|
+
def is_filter(args = {})
|
196
|
+
true
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Returns export possibility for defined options. It's rewrote for custom controllers.
|
201
|
+
# @param [Hash] args additional parameters.
|
202
|
+
# @option args [String] :tab current tab is used for generation
|
203
|
+
# @return [Boolean] Possibility of export table data. Default: true
|
204
|
+
def is_export(args = {})
|
205
|
+
true
|
206
|
+
end
|
207
|
+
|
208
|
+
##
|
209
|
+
# Returns field name for manual table order or nil if table can't be sorted manually.
|
210
|
+
# @return [String] Field name for manual table order
|
211
|
+
def is_sortable
|
212
|
+
nil
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|