anoubis 1.0.1 → 1.0.10

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