anoubis 1.0.0
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 +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,468 @@
|
|
|
1
|
+
module Anubis
|
|
2
|
+
module Etc
|
|
3
|
+
##
|
|
4
|
+
# Definitions of field options for table column or new (edit) form field.
|
|
5
|
+
class Field
|
|
6
|
+
# @!attribute [rw]
|
|
7
|
+
# Defines field title.
|
|
8
|
+
# @return [String] field's title
|
|
9
|
+
class_attribute :title, default: nil
|
|
10
|
+
|
|
11
|
+
# @!attribute [rw]
|
|
12
|
+
# Defines field type
|
|
13
|
+
#
|
|
14
|
+
# Possible values of field's type are 'string', 'integer', 'float', 'listbox', 'checkbox', 'longlistbox'
|
|
15
|
+
# and 'datetime'
|
|
16
|
+
# @return [String] field's type.
|
|
17
|
+
class_attribute :type, default: ''
|
|
18
|
+
|
|
19
|
+
# Defines date format for field type 'datetime'
|
|
20
|
+
# Possible values of field's format are 'date', 'full', 'datetime', 'month', 'year'.
|
|
21
|
+
# @return [String] field's type.
|
|
22
|
+
class_attribute :format, default: ''
|
|
23
|
+
|
|
24
|
+
# Defines precision for field type 'number'
|
|
25
|
+
# Possible values of this field is integer numbers between 0 and 6. If precision is 0 then number is integer.
|
|
26
|
+
# @return [String] field's type.
|
|
27
|
+
class_attribute :precision, default: 0
|
|
28
|
+
|
|
29
|
+
# @!attribute [rw]
|
|
30
|
+
# Defines field order options.
|
|
31
|
+
# @return [FieldOrder] field's order options
|
|
32
|
+
class_attribute :order, default: nil
|
|
33
|
+
|
|
34
|
+
# @!attribute [rw]
|
|
35
|
+
# Defines field's visibility for table representation data
|
|
36
|
+
# @return [Boolean] field's visibility
|
|
37
|
+
class_attribute :visible, default: true
|
|
38
|
+
|
|
39
|
+
# @!attribute [rw]
|
|
40
|
+
# Field's identifier
|
|
41
|
+
# @return [String] field's identifier
|
|
42
|
+
class_attribute :key, default: nil
|
|
43
|
+
|
|
44
|
+
# @!attribute [rw] field
|
|
45
|
+
# Field's name is used for access field value in model
|
|
46
|
+
# @return [String] field's name
|
|
47
|
+
class_attribute :field, default: nil
|
|
48
|
+
|
|
49
|
+
# @!attribute [rw] table_field
|
|
50
|
+
# Field's name is used for operation with table data (like 'where', 'order' and etc.)
|
|
51
|
+
# @return [String] field's name in the table
|
|
52
|
+
class_attribute :table_field, default: nil
|
|
53
|
+
|
|
54
|
+
# @!attribute [rw] error_text
|
|
55
|
+
# Text is shown when system can't access to data with presented {#field} name
|
|
56
|
+
# @return [String] field's error_text
|
|
57
|
+
class_attribute :error_text, default: ''
|
|
58
|
+
|
|
59
|
+
# @!attribute [rw]
|
|
60
|
+
# Describes additional field's options for type 'checkbox', 'listbox'.
|
|
61
|
+
# @return [FieldOptions] field's options.
|
|
62
|
+
class_attribute :options, default: nil
|
|
63
|
+
|
|
64
|
+
# @!attribute [rw]
|
|
65
|
+
# Describes if this field could return data for {Anubis::Data::Actions#autocomplete autocomplete} action.
|
|
66
|
+
# @return [Boolean] possibility for return data on autocomplete action.
|
|
67
|
+
#
|
|
68
|
+
# <b>Options:</b>
|
|
69
|
+
# - <b>:limit</b> (Integer) -- maximum number of elements <i>(defaults to: 10)</i>
|
|
70
|
+
# - <b>:count</b> (Integer) -- Minimum symbols count for output <i>(defaults to: 3)</i>
|
|
71
|
+
# @return [Hash] autocomplete definitions for field
|
|
72
|
+
class_attribute :autocomplete, default: false
|
|
73
|
+
|
|
74
|
+
# @!attribute [rw]
|
|
75
|
+
# Defines model's description for complex field
|
|
76
|
+
#
|
|
77
|
+
# <b>Options:</b>
|
|
78
|
+
# - <b>:model</b> (ActiveRecord) -- model class
|
|
79
|
+
# - <b>:title</b> (Symbol) -- field name is used for receive options titles <i>(defaults to: :title)</i>
|
|
80
|
+
# - <b>:order</b> (Symbol) -- field name is used for order options <i>(defaults to: :title option)</i>
|
|
81
|
+
# - <b>:where</b> (Hash) -- where parameters for select data from model <i>(defaults to: {})</i>
|
|
82
|
+
# @return [Model] model's description for complex field
|
|
83
|
+
class_attribute :model, default: nil
|
|
84
|
+
|
|
85
|
+
# @!attribute [rw] editable
|
|
86
|
+
# Defines if key of this field can be edited
|
|
87
|
+
# @return [String] returns path for edit field options
|
|
88
|
+
class_attribute :editable, default: nil
|
|
89
|
+
|
|
90
|
+
##
|
|
91
|
+
# Sets default parameters for field
|
|
92
|
+
# @param key [Symbol] field's identifier
|
|
93
|
+
# @param model [ActiveRecord] field's model
|
|
94
|
+
# @param options [Hash] field's initial options
|
|
95
|
+
def initialize(key, model, options = {})
|
|
96
|
+
#puts key
|
|
97
|
+
#puts options
|
|
98
|
+
self.field = nil
|
|
99
|
+
self.key = key.to_s
|
|
100
|
+
self.format = ''
|
|
101
|
+
self.precision = 0
|
|
102
|
+
self.title = options[:title] if options.key? :title
|
|
103
|
+
self.type = if options.key? :type then options[:type] else 'string' end
|
|
104
|
+
self.visible = if options.key? :visible then options[:visible] else true end
|
|
105
|
+
self.options = if options.key? :options then FieldOptions.new(options[:options]) else nil end
|
|
106
|
+
if options.key? :order
|
|
107
|
+
if options[:order].class == Hash
|
|
108
|
+
options[:order][:field] = Kernel.format('%s.%s', model.table_name, self.key.to_s) if !options[:order].key? :field
|
|
109
|
+
end
|
|
110
|
+
self.order = if options.key? :order then FieldOrder.new(options[:order]) else nil end
|
|
111
|
+
end
|
|
112
|
+
self.model = if options.key? :model then Model.new(options[:model]) else nil end
|
|
113
|
+
self.editable = if options.key? :editable then options[:editable] else nil end
|
|
114
|
+
self.autocomplete = if options.key? :autocomplete then options[:autocomplete] else nil end
|
|
115
|
+
self.error_text = if options.key? :error_text then options[:error_text] else I18n.t('errors.field_error') end
|
|
116
|
+
|
|
117
|
+
self.send Kernel.format('initialize_%s', self.type), options
|
|
118
|
+
|
|
119
|
+
if !options.key? :table_field
|
|
120
|
+
if !options.key? :field
|
|
121
|
+
if self.order
|
|
122
|
+
options[:table_field] = self.order.field if self.order.field
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
if !self.field
|
|
128
|
+
self.field = if options.key? :field then options[:field] else self.key end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
self.table_field = if options.key?(:table_field) then options[:table_field] else Kernel.format('%s.%s', model.table_name, self.field) end
|
|
132
|
+
|
|
133
|
+
if self.autocomplete
|
|
134
|
+
self.autocomplete[:limit] = 10 if !autocomplete.key? :limit
|
|
135
|
+
self.autocomplete[:count] = 3 if !autocomplete.key? :count
|
|
136
|
+
self.autocomplete[:where] = []
|
|
137
|
+
end
|
|
138
|
+
#puts self.to_h
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
##
|
|
142
|
+
# Initialize additional parameters for {Anubis::Etc::Field#type 'string' field type} for controller actions.
|
|
143
|
+
# @param options [Hash] field's initial options
|
|
144
|
+
def initialize_string (options)
|
|
145
|
+
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
##
|
|
149
|
+
# Initialize additional parameters for {Anubis::Etc::Field#type 'boolean' field type} for controller actions.
|
|
150
|
+
# @param options [Hash] field's initial options
|
|
151
|
+
def initialize_boolean (options)
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
##
|
|
156
|
+
# Initialize additional parameters for {Anubis::Etc::Field#type 'number' field type} for controller actions.
|
|
157
|
+
# @param options [Hash] field's initial options
|
|
158
|
+
def initialize_number (options)
|
|
159
|
+
if options.key? :error_text
|
|
160
|
+
self.error_text = options[:error_text]
|
|
161
|
+
else
|
|
162
|
+
self.error_text = ''
|
|
163
|
+
end
|
|
164
|
+
self.precision = options[:precision].to_s.to_i if options.key? :precision
|
|
165
|
+
self.precision = 0 if self.precision < 0
|
|
166
|
+
self.precision = 16 if self.precision > 16
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
##
|
|
170
|
+
# Initialize additional parameters for {Anubis::Etc::Field#type 'text' field type} for controller actions.
|
|
171
|
+
# @param options [Hash] field's initial options
|
|
172
|
+
def initialize_text (options)
|
|
173
|
+
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
##
|
|
177
|
+
# Initialize additional parameters for {Anubis::Etc::Field#type 'html' field type} for controller actions.
|
|
178
|
+
# @param options [Hash] field's initial options
|
|
179
|
+
def initialize_html (options)
|
|
180
|
+
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
##
|
|
184
|
+
# Initialize additional parameters for {Anubis::Etc::Field#type 'datetime' field type} for controller actions.
|
|
185
|
+
# @param options [Hash] field's initial options
|
|
186
|
+
def initialize_datetime (options)
|
|
187
|
+
options[:format] = 'datetime' if !options.key? :format
|
|
188
|
+
options[:format] = 'datetime' if !%w[date datetime full year month].include? options[:format]
|
|
189
|
+
self.format = options[:format]
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
##
|
|
193
|
+
# Setups additional parameters for {Anubis::Etc::Field#type 'listbox' field type} for controller actions.
|
|
194
|
+
# @param options [Hash] field's initial options
|
|
195
|
+
def initialize_listbox (options)
|
|
196
|
+
self.options = FieldOptions.new if !self.options
|
|
197
|
+
if !self.options.list
|
|
198
|
+
if self.model
|
|
199
|
+
if !(%w[update create].include?(options[:action]))
|
|
200
|
+
self.options.show = 'update'
|
|
201
|
+
if self.options.line
|
|
202
|
+
self.options.list = self.options.line
|
|
203
|
+
else
|
|
204
|
+
self.options.list = {}
|
|
205
|
+
end
|
|
206
|
+
self.model.model.select(self.model.select).where(self.model.where).order(self.model.order).each do |dat|
|
|
207
|
+
self.options.list[dat.id.to_s.to_sym] = dat.send(self.model.title)
|
|
208
|
+
if dat.respond_to? :updated_at
|
|
209
|
+
if self.model.updated_at < dat.updated_at.to_time.utc.to_i
|
|
210
|
+
self.model.updated_at = dat.updated_at.to_time.utc.to_i
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
options[:format] = 'single' unless options.key? :format
|
|
218
|
+
options[:format] = 'single' unless %w[single multiple].include? options[:format]
|
|
219
|
+
self.format = options[:format]
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
##
|
|
223
|
+
# Initialize additional parameters for {Anubis::Etc::Field#type 'key' field type} for controller actions.
|
|
224
|
+
# @param options [Hash] field's initial options
|
|
225
|
+
def initialize_key (options)
|
|
226
|
+
if self.model
|
|
227
|
+
self.error_text = '' if options[:action] == 'new'
|
|
228
|
+
self.field = Kernel.format('%s.%s', self.key, self.model.title) if !options.key? :field
|
|
229
|
+
self.table_field = Kernel.format('%s.%s', self.model.model.table_name, self.model.title) if !self.table_field
|
|
230
|
+
self.autocomplete = {} if !options.key? :autocomplete
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
##
|
|
235
|
+
# Return field properties for frontend application
|
|
236
|
+
# @param model [ActiveRecord] field's model
|
|
237
|
+
# @param action [Srting] current field action
|
|
238
|
+
# @return [Hash] field's properties for defined action
|
|
239
|
+
def properties (model, action)
|
|
240
|
+
if %w[new edit].include? action
|
|
241
|
+
return self.properties_forms model, action
|
|
242
|
+
end
|
|
243
|
+
self.properties_index model, action
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
##
|
|
247
|
+
# Return field properties for frontend application for action 'index'
|
|
248
|
+
# @param model [ActiveRecord] field's model
|
|
249
|
+
# @param action [Srting] current field action
|
|
250
|
+
# @return [Hash] field's properties for defined action
|
|
251
|
+
def properties_index (model, action)
|
|
252
|
+
result = {
|
|
253
|
+
id: self.key,
|
|
254
|
+
type: self.type,
|
|
255
|
+
sortable: self.order != nil
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if self.title
|
|
259
|
+
result[:title] = self.title
|
|
260
|
+
else
|
|
261
|
+
result[:title] = model.human_attribute_name(self.key)
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
result[:editable] = self.editable if self.editable != nil
|
|
265
|
+
result[:editable] = false if self.type == 'key'
|
|
266
|
+
result[:format] = self.format if self.type == 'datetime'
|
|
267
|
+
result[:precision] = self.precision if self.type == 'number'
|
|
268
|
+
result[:options] = self.hash_to_json(self.options.list) if self.options
|
|
269
|
+
result
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
##
|
|
273
|
+
# Return field properties for frontend application for actions 'edit', 'new'
|
|
274
|
+
# @param model [ActiveRecord] field's model
|
|
275
|
+
# @param action [Srting] current field action
|
|
276
|
+
# @return [Hash] field's properties for defined action
|
|
277
|
+
def properties_forms (model, action)
|
|
278
|
+
mod = model.new
|
|
279
|
+
result = {
|
|
280
|
+
id: self.key,
|
|
281
|
+
title: model.human_attribute_name(self.key),
|
|
282
|
+
type: self.type
|
|
283
|
+
}
|
|
284
|
+
result.merge!(self.send(Kernel.format('properties_forms_%s', self.type), model, action, mod))
|
|
285
|
+
result
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
##
|
|
289
|
+
# Return field properties for frontend application for actions 'edit', 'new' and type 'string'
|
|
290
|
+
# @param model [ActiveRecord] field's model
|
|
291
|
+
# @param action [Srting] current field action
|
|
292
|
+
# @param mod [ActiveRecord] initialized new model element
|
|
293
|
+
# @return [Hash] field's properties for defined action
|
|
294
|
+
def properties_forms_string (model, action, mod)
|
|
295
|
+
result = {}
|
|
296
|
+
errors = {}
|
|
297
|
+
res = model.validators_on(self.key.to_sym).detect { |v| v.is_a?(ActiveModel::Validations::LengthValidator) }
|
|
298
|
+
if res
|
|
299
|
+
if res.options.key? :minimum
|
|
300
|
+
result[:min] = res.options[:minimum]
|
|
301
|
+
errors[:min] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :too_short, { count: result[:min] })
|
|
302
|
+
end
|
|
303
|
+
if res.options.key? :maximum
|
|
304
|
+
result[:max] = res.options[:maximum]
|
|
305
|
+
errors[:max] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :too_long, { count: result[:max] })
|
|
306
|
+
end
|
|
307
|
+
end
|
|
308
|
+
res = model.validators_on(self.key.to_sym).detect { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
|
309
|
+
if res
|
|
310
|
+
result[:required] = true
|
|
311
|
+
errors[:required] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :blank)
|
|
312
|
+
end
|
|
313
|
+
result[:errors] = errors if errors.length > 0
|
|
314
|
+
result
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
##
|
|
318
|
+
# Return field properties for frontend application for actions 'edit', 'new' and type 'number'
|
|
319
|
+
# @param model [ActiveRecord] field's model
|
|
320
|
+
# @param action [Srting] current field action
|
|
321
|
+
# @param mod [ActiveRecord] initialized new model element
|
|
322
|
+
# @return [Hash] field's properties for defined action
|
|
323
|
+
def properties_forms_number (model, action, mod)
|
|
324
|
+
result = {}
|
|
325
|
+
errors = {}
|
|
326
|
+
res = model.validators_on(self.key.to_sym).detect { |v| v.is_a?(ActiveModel::Validations::NumericalityValidator) }
|
|
327
|
+
if res
|
|
328
|
+
if res.options.key? :greater_than_or_equal_to
|
|
329
|
+
result[:min] = res.options[:greater_than_or_equal_to]
|
|
330
|
+
errors[:min] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :greater_than_or_equal_to, { count: result[:min] })
|
|
331
|
+
end
|
|
332
|
+
if res.options.key? :maximum
|
|
333
|
+
result[:max] = res.options[:maximum]
|
|
334
|
+
errors[:max] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :too_long, { count: result[:max] })
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
res = model.validators_on(self.key.to_sym).detect { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
|
338
|
+
if res
|
|
339
|
+
result[:required] = true
|
|
340
|
+
errors[:required] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :blank)
|
|
341
|
+
end
|
|
342
|
+
result[:errors] = errors if errors.length > 0
|
|
343
|
+
result
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
##
|
|
347
|
+
# Return field properties for frontend application for actions 'edit', 'new' and type 'text'.
|
|
348
|
+
# @param model [ActiveRecord] field's model
|
|
349
|
+
# @param action [Srting] current field action
|
|
350
|
+
# @param mod [ActiveRecord] initialized new model element
|
|
351
|
+
# @return [Hash] field's properties for defined action
|
|
352
|
+
def properties_forms_text (model, action, mod)
|
|
353
|
+
self.properties_forms_string model, action, mod
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
##
|
|
357
|
+
# Return field properties for frontend application for actions 'edit', 'new' and type 'html'.
|
|
358
|
+
# @param model [ActiveRecord] field's model
|
|
359
|
+
# @param action [Srting] current field action
|
|
360
|
+
# @param mod [ActiveRecord] initialized new model element
|
|
361
|
+
# @return [Hash] field's properties for defined action
|
|
362
|
+
def properties_forms_html (model, action, mod)
|
|
363
|
+
self.properties_forms_text model, action, mod
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
##
|
|
367
|
+
# Return field properties for frontend application for actions 'edit', 'new' and type 'listbox'
|
|
368
|
+
# @param model [ActiveRecord] field's model
|
|
369
|
+
# @param action [Srting] current field action
|
|
370
|
+
# @param mod [ActiveRecord] initialized new model element
|
|
371
|
+
# @return [Hash] field's properties for defined action
|
|
372
|
+
def properties_forms_listbox (model, action, mod)
|
|
373
|
+
result = {}
|
|
374
|
+
result[:format] = self.format if self.format == 'multiple'
|
|
375
|
+
result[:options] = self.hash_to_json(self.options.list) if self.options
|
|
376
|
+
result
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
##
|
|
380
|
+
# Return field properties for frontend application for actions 'edit', 'new' and type 'key'
|
|
381
|
+
# @param model [ActiveRecord] field's model
|
|
382
|
+
# @param action [Srting] current field action
|
|
383
|
+
# @param mod [ActiveRecord] initialized new model element
|
|
384
|
+
# @return [Hash] field's properties for defined action
|
|
385
|
+
def properties_forms_key (model, action, mod)
|
|
386
|
+
result = {
|
|
387
|
+
type: 'string',
|
|
388
|
+
autocomplete: true,
|
|
389
|
+
editable: self.editable
|
|
390
|
+
}
|
|
391
|
+
errors = {}
|
|
392
|
+
result[:field] = self.model.title if self.editable
|
|
393
|
+
res = model.validators_on(self.key.to_sym).detect { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
|
394
|
+
if res
|
|
395
|
+
result[:required] = true
|
|
396
|
+
errors[:required] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :blank)
|
|
397
|
+
end
|
|
398
|
+
result[:errors] = errors if errors.length > 0
|
|
399
|
+
result
|
|
400
|
+
end
|
|
401
|
+
|
|
402
|
+
##
|
|
403
|
+
# Return field properties for frontend application for actions 'edit', 'new' and type 'datetime'
|
|
404
|
+
# @param model [ActiveRecord] field's model
|
|
405
|
+
# @param action [Srting] current field action
|
|
406
|
+
# @param mod [ActiveRecord] initialized new model element
|
|
407
|
+
# @return [Hash] field's properties for defined action
|
|
408
|
+
def properties_forms_datetime (model, action, mod)
|
|
409
|
+
result = {}
|
|
410
|
+
errors = {}
|
|
411
|
+
res = model.validators_on(self.key.to_sym).detect { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
|
|
412
|
+
if res
|
|
413
|
+
result[:required] = true
|
|
414
|
+
errors[:required] = model.human_attribute_name(self.key) + ' ' + mod.errors.generate_message(self.key.to_sym, :blank)
|
|
415
|
+
end
|
|
416
|
+
result[:format] = self.format
|
|
417
|
+
result[:errors] = errors if errors.length > 0
|
|
418
|
+
result
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
##
|
|
422
|
+
# Generates hash representation of all class parameters,
|
|
423
|
+
# @return [Hash] hash representation of all data
|
|
424
|
+
def to_h
|
|
425
|
+
result = {
|
|
426
|
+
key: self.key,
|
|
427
|
+
type: self.type,
|
|
428
|
+
visible: self.visible,
|
|
429
|
+
field: self.field,
|
|
430
|
+
table_field: self.table_field,
|
|
431
|
+
error_text: self.error_text,
|
|
432
|
+
autocomplete: self.autocomplete
|
|
433
|
+
}
|
|
434
|
+
result[:format] = self.format if self.type == 'datetime'
|
|
435
|
+
if self.editable
|
|
436
|
+
result[:editable] = self.editable
|
|
437
|
+
result[:field] = self.model.title if self.model
|
|
438
|
+
else
|
|
439
|
+
result[:editable] = self.editable if self.editable != nil
|
|
440
|
+
end
|
|
441
|
+
if self.model
|
|
442
|
+
result[:model] = self.model.to_h
|
|
443
|
+
end
|
|
444
|
+
if self.options
|
|
445
|
+
result[:options] = self.options.to_h
|
|
446
|
+
end
|
|
447
|
+
if self.order
|
|
448
|
+
result[:order] = self.order.to_h
|
|
449
|
+
end
|
|
450
|
+
result
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
##
|
|
454
|
+
# Convert hash to array json output
|
|
455
|
+
# @param hash [Hash] hash representation
|
|
456
|
+
# @return [Array] array representation
|
|
457
|
+
def hash_to_json(hash)
|
|
458
|
+
result = []
|
|
459
|
+
hash.each_key do |key|
|
|
460
|
+
result.push({ key: key.to_s, value: hash[key] })
|
|
461
|
+
end
|
|
462
|
+
result
|
|
463
|
+
end
|
|
464
|
+
|
|
465
|
+
public :format
|
|
466
|
+
end
|
|
467
|
+
end
|
|
468
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Anubis
|
|
2
|
+
module Etc
|
|
3
|
+
##
|
|
4
|
+
# Definitions of fields options list for 'checkbox' and 'listbox' type.
|
|
5
|
+
class FieldOptions
|
|
6
|
+
# @!attribute [rw]
|
|
7
|
+
# Describes when options shown in output for 'edit' and 'new' actions. Possible values of fields are:
|
|
8
|
+
# - 'init' -- Options shown only when time set to 0 in action
|
|
9
|
+
# - 'never' -- Options newer shown
|
|
10
|
+
# - 'always' -- Options always shown
|
|
11
|
+
# - 'update' -- Options shown when time less then updated_at time of options model
|
|
12
|
+
# @return [String] options' show type.
|
|
13
|
+
class_attribute :show, default: 'init'
|
|
14
|
+
|
|
15
|
+
# @!attribute [rw]
|
|
16
|
+
# Options list.
|
|
17
|
+
# @return [Hash<Symbol, Sring>] options list
|
|
18
|
+
class_attribute :list, default: nil
|
|
19
|
+
|
|
20
|
+
# @!attribute [rw]
|
|
21
|
+
# Enum list from ActiveRecord. Is defined for correct filtering.
|
|
22
|
+
# @return [Hash<Symbol, Sring>] enum options list
|
|
23
|
+
class_attribute :enum, default: nil
|
|
24
|
+
|
|
25
|
+
# @!attribute [rw]
|
|
26
|
+
# Defines selected line. Default nil
|
|
27
|
+
# @return [Hash] presence of select line
|
|
28
|
+
class_attribute :line, default: nil
|
|
29
|
+
|
|
30
|
+
# @!attribute [rw]
|
|
31
|
+
# Defines model's description for complex field
|
|
32
|
+
#
|
|
33
|
+
# <b>Options:</b>
|
|
34
|
+
# - <b>:model</b> (ActiveRecord) -- model class
|
|
35
|
+
# - <b>:title</b> (Symbol) -- field name is used for receive options titles <i>(defaults to: :title)</i>
|
|
36
|
+
# - <b>:order</b> (Symbol) -- field name is used for order options <i>(defaults to: :title option)</i>
|
|
37
|
+
# - <b>:select</b> (Symbol) -- special select statement <i>(defaults to: nil)</i>
|
|
38
|
+
# - <b>:where</b> (Hash) -- where parameters for select data from model <i>(defaults to: {})</i>
|
|
39
|
+
# @return [Model] model's description for complex field
|
|
40
|
+
class_attribute :model, default: nil
|
|
41
|
+
|
|
42
|
+
##
|
|
43
|
+
# Sets default parameters for field options
|
|
44
|
+
# @param [Hash] options initial model options
|
|
45
|
+
# @option options [String] :show describes options shoe type
|
|
46
|
+
# @option options [Hash<Symbol, String>] :list options list
|
|
47
|
+
def initialize(options = {})
|
|
48
|
+
if options.key? :show
|
|
49
|
+
self.show = options[:show] if %w[init never always update].include? options[:show]
|
|
50
|
+
end
|
|
51
|
+
self.show = 'init' if !self.show || self.show == 'init'
|
|
52
|
+
self.line = if options.key? :line then options[:line] else nil end
|
|
53
|
+
self.list = if options.key? :list then options[:list] else nil end
|
|
54
|
+
self.enum = if options.key? :enum then options[:enum] else nil end
|
|
55
|
+
self.model = if options.key? :model then Model.new(options[:model]) else nil end
|
|
56
|
+
self.generate_list if !self.list && self.model
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
##
|
|
60
|
+
# Generate options list based on model
|
|
61
|
+
def generate_list
|
|
62
|
+
self.list = {}
|
|
63
|
+
self.model.model.where(self.model.where).order(self.model.order).each do |data|
|
|
64
|
+
proc = format('%s', self.model.title)
|
|
65
|
+
self.list[data.id.to_s.to_sym] = data.send proc
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
##
|
|
70
|
+
# Generates hash representation of all class parameters,
|
|
71
|
+
# @return [Hash] hash representation of all data
|
|
72
|
+
def to_h
|
|
73
|
+
{
|
|
74
|
+
show: self.show,
|
|
75
|
+
enum: self.enum,
|
|
76
|
+
list: self.list
|
|
77
|
+
}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
public :select
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Anubis
|
|
2
|
+
module Etc
|
|
3
|
+
##
|
|
4
|
+
# Definitions of fields order.
|
|
5
|
+
class FieldOrder
|
|
6
|
+
# @!attribute [rw]
|
|
7
|
+
# Returns order field (or array of fields)
|
|
8
|
+
# @return [String, Array, Symbol] field or field list.
|
|
9
|
+
class_attribute :field, default: nil
|
|
10
|
+
|
|
11
|
+
# @!attribute [rw]
|
|
12
|
+
# Field default order.
|
|
13
|
+
# @return [Symbol] default order
|
|
14
|
+
class_attribute :order, default: :asc
|
|
15
|
+
|
|
16
|
+
# @!attribute [rw]
|
|
17
|
+
# Defines if this field order by default.
|
|
18
|
+
# @return [Boolean] Defines if this field order by default
|
|
19
|
+
class_attribute :default, default: false
|
|
20
|
+
|
|
21
|
+
##
|
|
22
|
+
# Sets default parameters for field order
|
|
23
|
+
# @param [Hash] options initial model options
|
|
24
|
+
# @option options [String, Array, Symbol] :field describes field or fields name for order
|
|
25
|
+
# @option options [Symbol] :order default order type (:asc or :desc)
|
|
26
|
+
# @option options [Boolean] :default if this field default in order list
|
|
27
|
+
def initialize(options = {})
|
|
28
|
+
self.default = false
|
|
29
|
+
if options.key? :default
|
|
30
|
+
self.default = true if options[:default].class == TrueClass
|
|
31
|
+
end
|
|
32
|
+
self.order = :asc
|
|
33
|
+
if options.key? :order
|
|
34
|
+
self.order = :desc if options[:order] == :desc || options[:order].to_s.downcase == 'desc'
|
|
35
|
+
end
|
|
36
|
+
self.field = if options.key? :field then options[:field] else nil end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
##
|
|
40
|
+
# Generates hash representation of all class parameters,
|
|
41
|
+
# @return [Hash] hash representation of all data
|
|
42
|
+
def to_h
|
|
43
|
+
{
|
|
44
|
+
field: self.field,
|
|
45
|
+
order: self.order,
|
|
46
|
+
default: self.default
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|