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,531 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Core
|
3
|
+
module Data
|
4
|
+
##
|
5
|
+
# Module gets system data for {DataController}
|
6
|
+
module Get
|
7
|
+
##
|
8
|
+
# Get frame buttons data based on passed arguments.
|
9
|
+
# @param [Hash] args additional parameters are used for define frame buttons.
|
10
|
+
# @option args [String] :tab tab is used for generation buttons
|
11
|
+
# @return [Hash] returns resulting button hash
|
12
|
+
def get_frame_buttons(args = {})
|
13
|
+
buttons = self.frame_buttons(args)
|
14
|
+
buttons.each do |key, button|
|
15
|
+
buttons[key] = self.get_frame_button key, button
|
16
|
+
end
|
17
|
+
buttons
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# Get frame button
|
22
|
+
# @param [String] key button identificator
|
23
|
+
# @param [Hash] button initial button options
|
24
|
+
# @option button [String] :type ('default') type of the button ('primary', 'danger', 'default')
|
25
|
+
# @option button [String] :mode ('single') button action object ('single', 'multiple')
|
26
|
+
# @option button [String] :title title of the frame. If title isn't defined then system is trying to take
|
27
|
+
# value from yml translation file at path <i>[<b><language>.<controller with dot>.frame.buttons.<key>.title</b>]</i> (eg.
|
28
|
+
# *en.anubis.tenants.frame.buttons.new.title* for english language 'anubis/tenants' controller 'new' button).
|
29
|
+
# If path absents then value isn't set.
|
30
|
+
# @option button [String] :hint hint of the frame. If hint isn't defined then system is trying to take
|
31
|
+
# value from yml translation file at path <i>[<b><language>.<controller with dot>.frame.buttons.<key>.hint</b>]</i> (eg.
|
32
|
+
# *en.anubis.tenants.frame.buttons.new.hint* for english language 'anubis/tenants' controller 'new' button).
|
33
|
+
# If path absents then value isn't set.
|
34
|
+
# @return [Hash] resulting button options
|
35
|
+
def get_frame_button(key, button)
|
36
|
+
button[:key] = key.to_s
|
37
|
+
button[:type] = 'default' unless button.has_key? :type
|
38
|
+
button[:mode] = 'single' unless button.has_key? :mode
|
39
|
+
button[:decoration] = 'none' unless button.has_key? :decoration
|
40
|
+
text = I18n.t('.buttons.'+button[:key]+'.title', default: '')
|
41
|
+
button[:title] = text if text != ''
|
42
|
+
text = I18n.t('.buttons.'+button[:key]+'.hint', default: '')
|
43
|
+
button[:hint] = text if text != ''
|
44
|
+
button
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Get tab parameters
|
49
|
+
# @param [String] tab identifier
|
50
|
+
# @param [Hash] options initial tab options
|
51
|
+
# @option options [String] :title title of the frame. If title isn't defined then value is taken from yml
|
52
|
+
# translation file at path <i>[<b><language>.<controller with dot>.frame.tabs.<tab>.title</b>]</i> (eg.
|
53
|
+
# *en.anubis.tenants.frame.tabs.all.title* for english language 'anubis/tenants' controller 'all' tab).
|
54
|
+
# If path absents then value is set into humanized form of tab identifier (eg. 'All' for 'all' tab).
|
55
|
+
# @option options [String] :hint hint of the frame. If hint isn't defined then system is trying to take
|
56
|
+
# value from yml translation file at path <i>[<b><language>.<controller with dot>.frame.tabs.<tab>.hint</b>]</i> (eg.
|
57
|
+
# *en.anubis.tenants.frame.tabs.all.hint* for english language 'anubis/tenants' controller 'all' tab).
|
58
|
+
# If path absents then value isn't set.
|
59
|
+
def get_tab(tab, options = {})
|
60
|
+
options[:tab] = tab.to_s
|
61
|
+
options[:title] = I18n.t('.tabs.'+options[:tab]+'.title', default: options[:tab].humanize) if !options.key? :title
|
62
|
+
if !options.has_key? :hint
|
63
|
+
hint = I18n.t('.tabs.'+options[:tab]+'.hint', default: '')
|
64
|
+
options[:hint] = hint if hint != ''
|
65
|
+
end
|
66
|
+
|
67
|
+
if options.key? :export
|
68
|
+
options[:export] = true if options[:export].class != FalseClass
|
69
|
+
else
|
70
|
+
options[:export] = self.is_export({ tab: tab.to_s })
|
71
|
+
end
|
72
|
+
|
73
|
+
if options.key? :filter
|
74
|
+
options[:filter] = true if options[:filter].class != FalseClass
|
75
|
+
else
|
76
|
+
options[:filter] = self.is_filter({ tab: tab.to_s })
|
77
|
+
end
|
78
|
+
options[:buttons] = self.get_frame_buttons({ tab: options[:tab] })
|
79
|
+
#options[:where] = self.where if !options.key? :where
|
80
|
+
options
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Get model that is used for controller action
|
85
|
+
def get_model
|
86
|
+
return self.etc.data.model if self.etc.data.model
|
87
|
+
if defined? self.model
|
88
|
+
self.etc.data.model = self.model
|
89
|
+
self.etc.data.eager_load = self.eager_load
|
90
|
+
end
|
91
|
+
return self.etc.data.model
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Get default eager load definition for controller action
|
96
|
+
def get_eager_load
|
97
|
+
return self.etc.data.eager_load if self.etc.data.model
|
98
|
+
self.get_model
|
99
|
+
return self.etc.data.eager_load
|
100
|
+
end
|
101
|
+
|
102
|
+
##
|
103
|
+
# Get where for controller action fro defined tab
|
104
|
+
def get_tab_where
|
105
|
+
return self.etc.tab.where if self.etc.tab.where
|
106
|
+
[]
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Get where for controller action
|
111
|
+
def get_where
|
112
|
+
self.where
|
113
|
+
end
|
114
|
+
|
115
|
+
def get_tenant_where(model)
|
116
|
+
return { tenant_id: self.current_user.tenant_id } if model.new.respond_to? :tenant_id
|
117
|
+
return {}
|
118
|
+
end
|
119
|
+
|
120
|
+
def get_filter_where
|
121
|
+
#puts 'get_filter_where!'
|
122
|
+
#puts self.etc.data.filter.to_h
|
123
|
+
return if self.etc.data.filter
|
124
|
+
filter = {}
|
125
|
+
if params.key? :filter
|
126
|
+
begin
|
127
|
+
filter = JSON.parse(params[:filter]).with_indifferent_access.to_h
|
128
|
+
rescue
|
129
|
+
filter = {}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
self.setup_fields
|
133
|
+
#puts 'get_filter_where'
|
134
|
+
#puts self.etc.data.fields
|
135
|
+
self.etc.data.filter = Anubis::Etc::Filter.new({ data: filter, fields: self.etc.data.fields })
|
136
|
+
|
137
|
+
#puts self.etc.data.filter.to_h
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_filter_where_hash
|
141
|
+
self.get_filter_where
|
142
|
+
return self.etc.data.filter.hash
|
143
|
+
end
|
144
|
+
|
145
|
+
def get_filter_where_array
|
146
|
+
self.get_filter_where
|
147
|
+
return self.etc.data.filter.array
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# @!group Block of table data getters
|
152
|
+
|
153
|
+
##
|
154
|
+
# Get total number of rows in defined model. Also sets additional system properties {Etc::Data#limit self.etc.data.limit},
|
155
|
+
# {Etc::Data#offset self.etc.data.offset} and {Etc::Data#count self.etc.data.count}
|
156
|
+
# @return [Integer] the total number of rows.
|
157
|
+
def get_table_data_count
|
158
|
+
self.load_table_data_count
|
159
|
+
self.etc.data.limit = params[:limit] if params.has_key? :limit
|
160
|
+
self.etc.data.offset = params[:offset] if params.has_key? :offset
|
161
|
+
if self.etc.data.offset >= self.etc.data.count
|
162
|
+
if self.etc.data.count > 0
|
163
|
+
self.etc.data.offset = ((self.etc.data.count-1) / self.etc.data.limit).truncate * self.etc.data.limit
|
164
|
+
else
|
165
|
+
self.etc.data.offset = 0
|
166
|
+
end
|
167
|
+
end
|
168
|
+
self.etc.data.count
|
169
|
+
end
|
170
|
+
|
171
|
+
##
|
172
|
+
# Returns fields for table output.
|
173
|
+
# @return [Hash] calculated hash for fields properties for current action
|
174
|
+
def get_fields_properties(fields = nil)
|
175
|
+
fields = fields_order if !fields
|
176
|
+
result = []
|
177
|
+
fields.each do |value|
|
178
|
+
if self.etc.data.fields
|
179
|
+
if self.etc.data.fields.key? value.to_sym
|
180
|
+
result.push self.etc.data.fields[value.to_sym].properties(self.etc.data.model, self.etc.action) if self.etc.data.fields[value.to_sym].visible
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
result
|
185
|
+
end
|
186
|
+
|
187
|
+
##
|
188
|
+
# Returns fields for filter form.
|
189
|
+
# @return [Hash] calculated hash for fields properties for current action
|
190
|
+
def get_filter_properties
|
191
|
+
fields = filter_order
|
192
|
+
self.get_fields_properties fields
|
193
|
+
end
|
194
|
+
|
195
|
+
##
|
196
|
+
# Load data into the system variable {Etc::Data#data self.etc.data.data} and return fields defined in controller.
|
197
|
+
def get_table_data
|
198
|
+
self.load_table_data self.etc.data.limit, self.etc.data.offset
|
199
|
+
data = []
|
200
|
+
if self.etc.data.data
|
201
|
+
self.etc.data.data.each do |row|
|
202
|
+
data.push get_data_row row
|
203
|
+
end
|
204
|
+
end
|
205
|
+
data
|
206
|
+
end
|
207
|
+
|
208
|
+
##
|
209
|
+
# Get data fields defined in custom controller for single row
|
210
|
+
# @param row [ActiveRecord] single row of model data
|
211
|
+
# @return [Hash] calculated hash of model row
|
212
|
+
def get_data_row(row)
|
213
|
+
fields = self.get_fields
|
214
|
+
|
215
|
+
new_row = {}
|
216
|
+
|
217
|
+
case self.etc.action
|
218
|
+
when 'show'
|
219
|
+
new_row = { id: row.id, sys_title: row.sys_title }
|
220
|
+
when 'index', 'export'
|
221
|
+
new_row = { id: row.id, sys_title: row.sys_title, actions: self.get_table_actions(row) }
|
222
|
+
when 'new', 'create'
|
223
|
+
new_row = {}
|
224
|
+
when 'edit', 'update'
|
225
|
+
new_row = { id: row.id, sys_title: row.sys_title }
|
226
|
+
end
|
227
|
+
|
228
|
+
fields.each_key do |key|
|
229
|
+
begin
|
230
|
+
value = eval 'row.' + fields[key].field
|
231
|
+
error = false
|
232
|
+
rescue
|
233
|
+
new_row[key] = fields[key].error_text
|
234
|
+
error = true
|
235
|
+
if fields[key].type == 'key'
|
236
|
+
error = false
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
new_row = new_row.merge(self.convert_db_to_view_value(key, value)) if !error
|
241
|
+
end
|
242
|
+
|
243
|
+
return new_row
|
244
|
+
end
|
245
|
+
|
246
|
+
##
|
247
|
+
# Returns current table actions for selected row
|
248
|
+
# @param row [ActiveRecord] single row of model data
|
249
|
+
# @return [Hash] resulting has of buttons
|
250
|
+
def get_table_actions(row)
|
251
|
+
self.etc.data.actions = self.table_actions if !self.etc.data.actions
|
252
|
+
result = {}
|
253
|
+
self.etc.data.actions.each do |value|
|
254
|
+
if self.get_table_action value, row
|
255
|
+
result[value.to_sym] = I18n.t(params[:controller].sub('/', '.')+'.table.actions.'+value, title: row.sys_title, default: I18n.t('actions.'+value, title: row.sys_title))
|
256
|
+
end
|
257
|
+
end
|
258
|
+
result
|
259
|
+
end
|
260
|
+
|
261
|
+
##
|
262
|
+
# Returns posibility of using action for table data
|
263
|
+
# @param action [String] desired action
|
264
|
+
# @param row [ActiveRecord] single active record row
|
265
|
+
# @return [Boolean] is action present or not
|
266
|
+
def get_table_action(action, row)
|
267
|
+
result = false
|
268
|
+
if self.respond_to?(('table_action_'+action).to_sym)
|
269
|
+
result = send 'table_action_'+action, row
|
270
|
+
else
|
271
|
+
result = true
|
272
|
+
end
|
273
|
+
result
|
274
|
+
end
|
275
|
+
# @!endgroup
|
276
|
+
|
277
|
+
##
|
278
|
+
# @!group Block of {Anubis::Data::Actions#edit edit} and {Anubis::Data::Actions#update update} getters
|
279
|
+
|
280
|
+
##
|
281
|
+
# Get model that is used for {Anubis::Data::Actions#edit edit} or {Anubis::Data::Actions#update update} actions.
|
282
|
+
def get_edit_model
|
283
|
+
return self.etc.data.model if self.etc.data.model
|
284
|
+
self.etc.data.model = self.edit_model
|
285
|
+
self.etc.data.eager_load = self.edit_eager_load
|
286
|
+
return self.etc.data.model
|
287
|
+
end
|
288
|
+
|
289
|
+
##
|
290
|
+
# Get default eager load definition for {Anubis::Data::Actions#edit edit} or
|
291
|
+
# {Anubis::Data::Actions#update update} actions.
|
292
|
+
def get_edit_eager_load
|
293
|
+
return self.etc.data.eager_load if self.etc.data.model
|
294
|
+
self.get_edit_model
|
295
|
+
return self.etc.data.eager_load
|
296
|
+
end
|
297
|
+
|
298
|
+
##
|
299
|
+
# Return current table fields hash for {Anubis::Data::Actions#edit edit} or
|
300
|
+
# {Anubis::Data::Actions#update update} actions.
|
301
|
+
# @return [Hash] current defined table fields
|
302
|
+
def get_edit_fields
|
303
|
+
self.setup_edit_fields
|
304
|
+
self.etc.data.fields
|
305
|
+
end
|
306
|
+
|
307
|
+
##
|
308
|
+
# Get table data for single row for {Anubis::Data::Actions#edit edit} or {Anubis::Data::Actions#update update}
|
309
|
+
# actions.
|
310
|
+
# @param row [ActiveRecord] single row of model data
|
311
|
+
# @return [Hash] calculated hash of model row
|
312
|
+
def get_edit_data_row(row)
|
313
|
+
self.setup_edit_fields
|
314
|
+
new_row = { id: row.id, sys_title: row.sys_title }
|
315
|
+
self.etc.data.fields.each do |key, field|
|
316
|
+
if row.respond_to? field.field
|
317
|
+
value = row.send field.field
|
318
|
+
error = false
|
319
|
+
else
|
320
|
+
new_row[key] = field.error_text
|
321
|
+
error = true
|
322
|
+
end
|
323
|
+
new_row = new_row.merge(self.convert_db_to_edit_value(key, value)) if !error
|
324
|
+
end
|
325
|
+
return new_row
|
326
|
+
end
|
327
|
+
|
328
|
+
# @!endgroup
|
329
|
+
|
330
|
+
##
|
331
|
+
# @!group Block of {Anubis::Data::Actions#new new} or {Anubis::Data::Actions#create create} getters
|
332
|
+
|
333
|
+
##
|
334
|
+
# Return current table fields hash for {Anubis::Data::Actions#new new} or {Anubis::Data::Actions#create create}
|
335
|
+
# actions
|
336
|
+
# @return [Hash] current defined table fields
|
337
|
+
def get_new_fields
|
338
|
+
self.setup_new_fields
|
339
|
+
self.etc.data.fields
|
340
|
+
end
|
341
|
+
|
342
|
+
##
|
343
|
+
# Get table data for single row for {Anubis::Data::Actions#new new} or {Anubis::Data::Actions#create create}
|
344
|
+
# actions.
|
345
|
+
# @param row [ActiveRecord] single row of model data
|
346
|
+
# @return [Hash] calculated hash of model row
|
347
|
+
def get_new_data_row1(row)
|
348
|
+
self.setup_new_fields
|
349
|
+
new_row = {}
|
350
|
+
self.etc.data.fields.each do |key, field|
|
351
|
+
if row.respond_to? field.field
|
352
|
+
value = row.send field.field
|
353
|
+
error = false
|
354
|
+
else
|
355
|
+
new_row[key] = field.error_text
|
356
|
+
error = true
|
357
|
+
end
|
358
|
+
new_row = new_row.merge(self.convert_db_to_new_value(key, value)) if !error
|
359
|
+
end
|
360
|
+
return new_row
|
361
|
+
end
|
362
|
+
|
363
|
+
# @!endgroup
|
364
|
+
|
365
|
+
##
|
366
|
+
# Get defined fields options
|
367
|
+
# @param time [Number] last execution time of action
|
368
|
+
# @return [Hash] hash of fields options
|
369
|
+
def get_data_options(time)
|
370
|
+
time = time.to_s.to_i
|
371
|
+
self.setup_fields
|
372
|
+
result = {}
|
373
|
+
self.etc.data.fields.each do |key, field|
|
374
|
+
if field.options
|
375
|
+
if field.options.list
|
376
|
+
if time == 0
|
377
|
+
result[key] = field.options.list if field.options.show != 'never'
|
378
|
+
else
|
379
|
+
if field.model
|
380
|
+
if field.options.show == 'always'
|
381
|
+
result[key] = field.options.list
|
382
|
+
else
|
383
|
+
if field.options.show == 'update' && field.model.updated_at > time
|
384
|
+
result[key] = field.options.list
|
385
|
+
end
|
386
|
+
end
|
387
|
+
else
|
388
|
+
result[key] = field.options.list if field.options.show == 'update' || field.options.show == 'always'
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
result
|
395
|
+
end
|
396
|
+
|
397
|
+
##
|
398
|
+
# Returns order for current tab
|
399
|
+
# @return [Hash, String] order fore current tab
|
400
|
+
def get_order
|
401
|
+
return {id: :desc} if self.etc.tab.sort == nil
|
402
|
+
|
403
|
+
result = {}
|
404
|
+
|
405
|
+
field = self.etc.data.fields[self.etc.tab.sort.to_sym].order
|
406
|
+
if field.field.class == Symbol
|
407
|
+
result[field.field] = self.etc.tab.order
|
408
|
+
else
|
409
|
+
if field.field.class == String
|
410
|
+
if field.field.index(',')
|
411
|
+
result = field.field.gsub(',', ' ' + self.etc.tab.order.to_s.upcase + ',') + ' ' + self.etc.tab.order.to_s.upcase
|
412
|
+
else
|
413
|
+
result = field.field + ' ' + self.etc.tab.order.to_s.upcase
|
414
|
+
end
|
415
|
+
else
|
416
|
+
if field.field.class == Array
|
417
|
+
field.field.each do |item|
|
418
|
+
if item.class == Symbol
|
419
|
+
result[item] = self.etc.tab.order
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
result
|
426
|
+
end
|
427
|
+
|
428
|
+
##
|
429
|
+
# Return current fields hash for defined action.
|
430
|
+
# @return [Hash] current defined table fields
|
431
|
+
def get_fields
|
432
|
+
self.setup_fields
|
433
|
+
self.etc.data.fields
|
434
|
+
end
|
435
|
+
|
436
|
+
##
|
437
|
+
# Returns permitted parameters. Parameters is got from standard parameters output and checks according
|
438
|
+
# by described {Anubis::Etc::Data#fields self.etc.data.fields}.
|
439
|
+
# @return [Hash<Symbol, string>] permitted paramters' collection
|
440
|
+
def get_permited_params
|
441
|
+
permit = []
|
442
|
+
allowed = self.fields_order
|
443
|
+
self.etc.data.fields.each_key do | key |
|
444
|
+
single = true
|
445
|
+
if self.etc.data.fields[key].type == 'listbox'
|
446
|
+
single = false if self.etc.data.fields[key].format == 'multiple'
|
447
|
+
end
|
448
|
+
if single
|
449
|
+
permit.push key
|
450
|
+
else
|
451
|
+
data = {}
|
452
|
+
data[key] = []
|
453
|
+
permit.push data
|
454
|
+
end
|
455
|
+
end
|
456
|
+
params[:data].permit(permit).to_h.symbolize_keys
|
457
|
+
end
|
458
|
+
|
459
|
+
##
|
460
|
+
# Returns formatted field hash for field type 'string'
|
461
|
+
# @param [Hash] options initial filed options
|
462
|
+
# @option options [String] :min defines minimum string length <i>(default: 0)</i>
|
463
|
+
# @option options [String] :max defines maximum string length <i>(default: 0)</i>
|
464
|
+
# @return [Hash] resulting hash for field type 'string'
|
465
|
+
def get_formatted_string_field(options)
|
466
|
+
field = {}
|
467
|
+
return field
|
468
|
+
end
|
469
|
+
|
470
|
+
##
|
471
|
+
# Get autocomplete data for field
|
472
|
+
# @param field [Anubis::Etc::Field] - field for loading data
|
473
|
+
# @param value [String] - search value for load data
|
474
|
+
# @return [Hash] resulting hash for selected data
|
475
|
+
def get_autocomplete_data(field, value)
|
476
|
+
value = value.to_s
|
477
|
+
if value.index(' ')
|
478
|
+
words = value.split(' ')
|
479
|
+
|
480
|
+
max_count = 0;
|
481
|
+
words.each do |word|
|
482
|
+
max_count = word.length if word.length > max_count
|
483
|
+
if field.autocomplete[:where].count == 0
|
484
|
+
field.autocomplete[:where].push field.table_field+' LIKE ?'
|
485
|
+
else
|
486
|
+
field.autocomplete[:where][0] += ' AND '+field.table_field+' LIKE ?'
|
487
|
+
end
|
488
|
+
field.autocomplete[:where].push("%#{word}%")
|
489
|
+
end
|
490
|
+
if max_count < field.autocomplete[:count]
|
491
|
+
field.autocomplete[:where] = []
|
492
|
+
end
|
493
|
+
else
|
494
|
+
if value.length >= field.autocomplete[:count]
|
495
|
+
field.autocomplete[:where] = [field.table_field+' LIKE ?', '%'+value+'%']
|
496
|
+
end
|
497
|
+
end
|
498
|
+
if field.autocomplete[:where].count > 0
|
499
|
+
self.load_autocomplete_data field
|
500
|
+
end
|
501
|
+
if self.etc.data.data
|
502
|
+
self.etc.data.data.each do |item|
|
503
|
+
if item.respond_to? field.model.title
|
504
|
+
self.output.values.push(
|
505
|
+
#id: item.id,
|
506
|
+
value: item.send(field.model.title)
|
507
|
+
)
|
508
|
+
else
|
509
|
+
self.output.values.push(
|
510
|
+
#id: item.id,
|
511
|
+
value: item.id
|
512
|
+
)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
516
|
+
return self.output.values
|
517
|
+
end
|
518
|
+
|
519
|
+
##
|
520
|
+
# Returns current parent data. If data not loaded then load it.
|
521
|
+
# @return [ActiveRecord] resulting parent data
|
522
|
+
def get_parent_data
|
523
|
+
if !self.etc.data.parent
|
524
|
+
self.load_parent_data
|
525
|
+
end
|
526
|
+
self.etc.data.parent
|
527
|
+
end
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Core
|
3
|
+
module Data
|
4
|
+
##
|
5
|
+
# Module loads data from external sources for {DataController}
|
6
|
+
module Load
|
7
|
+
##
|
8
|
+
# Loads current menu data. Procedure loads menu data from MySQL database or from Redis cache and places it in
|
9
|
+
# self.etc.menu {Anubis::Etc#menu}
|
10
|
+
def load_menu_data
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Load total number of rows of defined model in {Etc::Data#count}.
|
16
|
+
def load_table_data_count
|
17
|
+
#self.get_table_model.eager_load(self.get_table_eager_load).where(self.get_current_tab_where).where(self.get_table_where).where(self.etc.filter[:h]).where(self.etc.filter[:a]).count
|
18
|
+
self.etc.data.count = self.get_model.eager_load(self.get_eager_load).where(self.get_tenant_where(self.get_model)).where(self.get_where).where(self.get_tab_where).where(self.get_filter_where_hash).where(self.get_filter_where_array).count
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Load model data into {Etc::Data#data}
|
23
|
+
# @param limit [Integer] Specifies the maximum number of rows to return.
|
24
|
+
# @param offset [Integer] Specifies the offset of the first row to return.
|
25
|
+
def load_table_data(limit = 10, offset = 0)
|
26
|
+
#self.etc.data.data = self.get_table_model.eager_load(self.get_table_eager_load).where(self.get_current_tab_where).where(self.get_table_where).where(self.etc.filter[:h]).where(self.etc.filter[:a]).order(self.get_current_order).limit(limit).offset(offset)
|
27
|
+
if self.select
|
28
|
+
self.etc.data.data = self.get_model.select(self.select).eager_load(self.get_eager_load).where(self.get_tenant_where(self.get_model)).where(self.get_where).where(self.get_tab_where).where(self.get_filter_where_hash).where(self.get_filter_where_array).order(self.get_order).limit(limit).offset(offset)
|
29
|
+
else
|
30
|
+
self.etc.data.data = self.get_model.eager_load(self.get_eager_load).where(self.get_tenant_where(self.get_model)).where(self.get_where).where(self.get_tab_where).where(self.get_filter_where_hash).where(self.get_filter_where_array).order(self.get_order).limit(limit).offset(offset)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
# Load single row of data into {Etc::Data#data}
|
36
|
+
# @param id [Integer] Data's identifier.
|
37
|
+
# @return [ActiveRecord|nil] Returns table data or nil if data absent
|
38
|
+
def load_data_by_id(id)
|
39
|
+
begin
|
40
|
+
self.etc.data.data = self.get_model.eager_load(self.get_eager_load).where(self.get_tenant_where(self.get_model)).where(self.get_where).where(self.get_tab_where).find(id)
|
41
|
+
rescue => error
|
42
|
+
puts error
|
43
|
+
self.etc.data.data = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
##
|
48
|
+
# Load single row of data into {Etc::Data#data}
|
49
|
+
# @param field [String] Field's identifier.
|
50
|
+
# @param value [String] Field's value.
|
51
|
+
# @return [ActiveRecord|nil] Returns table data or nil if data absent
|
52
|
+
def load_data_by_title(field, value)
|
53
|
+
where = {}
|
54
|
+
where[field.to_s.to_sym] = value
|
55
|
+
begin
|
56
|
+
self.etc.data.data = self.get_model.eager_load(self.get_eager_load).where(self.get_tenant_where(self.get_model)).where(self.get_where).where(self.get_tab_where).where(where).first
|
57
|
+
rescue => error
|
58
|
+
puts error
|
59
|
+
self.etc.data.data = nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
# Load predefined model data into {Etc::Data#data}
|
65
|
+
# @return [ActiveRecord] Returns predefined data
|
66
|
+
def load_new_data(action = 'new')
|
67
|
+
self.etc.data.data = self.get_model.eager_load(self.get_eager_load).new
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Load data for autocomplete action from database
|
72
|
+
# @param field [Anubis::Etc::Field] - field for loading data
|
73
|
+
def load_autocomplete_data(field)
|
74
|
+
self.etc.data.data = field.model.model.where(field.model.where).where(field.autocomplete[:where]).where(get_tenant_where(field.model.model)).order(field.model.order).limit(field.autocomplete[:limit])
|
75
|
+
end
|
76
|
+
|
77
|
+
##
|
78
|
+
# Loads parent data from database
|
79
|
+
def load_parent_data
|
80
|
+
begin
|
81
|
+
self.etc.data.parent = self.parent_model.where(self.get_tenant_where(self.parent_model)).find(self.parent_id)
|
82
|
+
rescue
|
83
|
+
self.etc.data.parent = nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Anubis
|
2
|
+
module Core
|
3
|
+
module Data
|
4
|
+
##
|
5
|
+
# Module sets system data for {DataController}
|
6
|
+
module Set
|
7
|
+
##
|
8
|
+
# Sets parent model according by type. Resulting data placed in {Etc::Data#parent self.etc.data.parent}
|
9
|
+
# @param action [String] type of used action in controller.
|
10
|
+
# - 'index' - for index action
|
11
|
+
# - 'new' - for new action
|
12
|
+
# - 'create' - for create action
|
13
|
+
# - 'edit' - for edit action
|
14
|
+
# - 'update' - for update action
|
15
|
+
# - 'destroy' - for defstroy action
|
16
|
+
def set_parent_model(action = '')
|
17
|
+
self.etc.data = Anubis::Etc::Data.new if !self.etc.data
|
18
|
+
self.etc.action = action if action != ''
|
19
|
+
self.set_current_tab
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Gets tab for current controller and place it into {Etc::Base#tab self.etc.tab} system variable.
|
24
|
+
# If params[:tab] absent or incorrect then {Etc::Base#tab self.etc.tab} is set as first value of {Data::Defaults#tabs} hash.
|
25
|
+
def set_current_tab
|
26
|
+
if !self.etc.tab
|
27
|
+
tabs = self.tabs
|
28
|
+
if params.key? :tab
|
29
|
+
if params[:tab].to_s != ''
|
30
|
+
if tabs.key? params[:tab].to_s.to_sym
|
31
|
+
self.etc.tab = Etc::TabItem.new(self.get_tab(params[:tab].to_s, tabs[params[:tab].to_s.to_sym]))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
self.etc.tab = Etc::TabItem.new(self.get_tab(tabs.keys[0].to_s, tabs.values[0])) if !self.etc.tab
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# Defines new action and clears defined for old action variables
|
41
|
+
# @param action [String] type of used action in controller.
|
42
|
+
def set_new_action(action)
|
43
|
+
self.etc.action = action
|
44
|
+
self.etc.data.model = nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|