anoubis 1.0.7 → 1.0.8

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