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