anoubis 1.0.1 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,531 +0,0 @@
1
- module Anoubis
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 = Anoubis::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 {Anoubis::Data::Actions#edit edit} and {Anoubis::Data::Actions#update update} getters
279
-
280
- ##
281
- # Get model that is used for {Anoubis::Data::Actions#edit edit} or {Anoubis::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 {Anoubis::Data::Actions#edit edit} or
291
- # {Anoubis::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 {Anoubis::Data::Actions#edit edit} or
300
- # {Anoubis::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 {Anoubis::Data::Actions#edit edit} or {Anoubis::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 {Anoubis::Data::Actions#new new} or {Anoubis::Data::Actions#create create} getters
332
-
333
- ##
334
- # Return current table fields hash for {Anoubis::Data::Actions#new new} or {Anoubis::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 {Anoubis::Data::Actions#new new} or {Anoubis::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 {Anoubis::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 [Anoubis::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
@@ -1,89 +0,0 @@
1
- module Anoubis
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 {Anoubis::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 [Anoubis::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
@@ -1,49 +0,0 @@
1
- module Anoubis
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 = Anoubis::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