anoubis 1.0.0 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/app/controllers/anoubis/application_controller.rb +22 -6
  4. data/app/controllers/anoubis/core/application_controller.rb +6 -6
  5. data/app/controllers/anoubis/core/index/actions.rb +3 -3
  6. data/app/controllers/anoubis/core/index/callbacks.rb +1 -1
  7. data/app/controllers/anoubis/core/index_controller.rb +7 -7
  8. data/app/controllers/anoubis/data/actions.rb +956 -0
  9. data/app/controllers/anoubis/data/callbacks.rb +66 -0
  10. data/app/controllers/anoubis/data/convert.rb +405 -0
  11. data/app/controllers/anoubis/data/defaults.rb +215 -0
  12. data/app/controllers/anoubis/data/get.rb +529 -0
  13. data/app/controllers/anoubis/data/load.rb +87 -0
  14. data/app/controllers/anoubis/data/set.rb +47 -0
  15. data/app/controllers/anoubis/data/setup.rb +102 -0
  16. data/app/controllers/anoubis/data_controller.rb +21 -0
  17. data/app/controllers/anoubis/etc/base.rb +16 -11
  18. data/app/controllers/anoubis/etc/data.rb +1 -1
  19. data/app/controllers/anoubis/etc/field.rb +10 -10
  20. data/app/controllers/anoubis/etc/field_options.rb +1 -1
  21. data/app/controllers/anoubis/etc/field_order.rb +1 -1
  22. data/app/controllers/anoubis/etc/filter.rb +2 -2
  23. data/app/controllers/anoubis/etc/menu.rb +2 -2
  24. data/app/controllers/anoubis/etc/model.rb +1 -1
  25. data/app/controllers/anoubis/etc/tab_item.rb +1 -1
  26. data/app/controllers/anoubis/etc.rb +1 -1
  27. data/app/controllers/anoubis/export.rb +1 -1
  28. data/app/controllers/anoubis/output/autocomplete.rb +1 -1
  29. data/app/controllers/anoubis/output/basic.rb +2 -2
  30. data/app/controllers/anoubis/output/data.rb +1 -1
  31. data/app/controllers/anoubis/output/delete.rb +1 -1
  32. data/app/controllers/anoubis/output/edit.rb +1 -1
  33. data/app/controllers/anoubis/output/frame.rb +5 -5
  34. data/app/controllers/anoubis/output/login.rb +1 -1
  35. data/app/controllers/anoubis/output/menu.rb +3 -3
  36. data/app/controllers/anoubis/output/update.rb +1 -1
  37. data/app/controllers/anoubis/sso/client/application_controller.rb +2 -2
  38. data/app/controllers/anoubis/sso/client/index/actions.rb +6 -6
  39. data/app/controllers/anoubis/sso/client/index/callbacks.rb +1 -1
  40. data/app/controllers/anoubis/sso/client/index_controller.rb +5 -5
  41. data/app/controllers/anoubis/sso/server/application_controller.rb +2 -2
  42. data/app/controllers/anoubis/sso/server/login_controller.rb +6 -6
  43. data/app/controllers/anoubis/sso/server/user_controller.rb +3 -3
  44. data/app/controllers/anoubis/tenant/application_controller.rb +4 -4
  45. data/app/controllers/anoubis/tenant/index/actions.rb +15 -15
  46. data/app/controllers/anoubis/tenant/index/callbacks.rb +2 -2
  47. data/app/controllers/anoubis/tenant/index_controller.rb +7 -7
  48. data/app/models/anoubis/application_record.rb +90 -2
  49. data/app/models/anoubis/core/application_record.rb +3 -3
  50. data/app/models/anoubis/sso/client/group_menu.rb +6 -6
  51. data/app/models/anoubis/sso/client/menu.rb +8 -8
  52. data/app/models/anoubis/sso/client/user.rb +3 -3
  53. data/app/models/anoubis/sso/server/user.rb +1 -1
  54. data/app/models/anoubis/tenant/group_menu.rb +5 -5
  55. data/app/models/anoubis/tenant/menu.rb +13 -13
  56. data/app/models/anoubis/tenant/system.rb +5 -5
  57. data/app/models/anoubis/tenant/user.rb +4 -4
  58. data/app/services/anoubis/log_service.rb +97 -0
  59. data/app/services/anoubis/request_service.rb +134 -0
  60. data/app/services/anoubis/session_service.rb +1 -1
  61. data/config/locales/en.yml +31 -2
  62. data/config/locales/ru.yml +32 -5
  63. data/config/routes.rb +19 -19
  64. data/db/seeds.rb +30 -30
  65. data/lib/anoubis/version.rb +1 -1
  66. data/lib/anoubis.rb +1 -1
  67. data/spec/controllers/anoubis/index_controller_spec.rb +1 -1
  68. data/spec/dummy/log/development.log +0 -0
  69. data/spec/dummy/log/test.log +0 -0
  70. data/spec/dummy/tmp/development_secret.txt +1 -0
  71. data/spec/models/anoubis/group_locale_spec.rb +1 -1
  72. data/spec/models/anoubis/group_menu_spec.rb +6 -6
  73. data/spec/models/anoubis/group_spec.rb +3 -3
  74. data/spec/models/anoubis/menu_locale_spec.rb +1 -1
  75. data/spec/models/anoubis/menu_spec.rb +1 -1
  76. data/spec/models/anoubis/system_locale_spec.rb +1 -1
  77. data/spec/models/anoubis/system_menu_spec.rb +5 -5
  78. data/spec/models/anoubis/system_spec.rb +4 -4
  79. data/spec/models/anoubis/tenant_spec.rb +4 -4
  80. data/spec/models/anoubis/user_spec.rb +2 -2
  81. metadata +92 -87
  82. data/app/controllers/anoubis/core/data/actions.rb +0 -962
  83. data/app/controllers/anoubis/core/data/callbacks.rb +0 -68
  84. data/app/controllers/anoubis/core/data/convert.rb +0 -407
  85. data/app/controllers/anoubis/core/data/defaults.rb +0 -217
  86. data/app/controllers/anoubis/core/data/get.rb +0 -531
  87. data/app/controllers/anoubis/core/data/load.rb +0 -89
  88. data/app/controllers/anoubis/core/data/set.rb +0 -49
  89. data/app/controllers/anoubis/core/data/setup.rb +0 -104
  90. data/app/controllers/anoubis/core/data_controller.rb +0 -28
  91. data/app/controllers/anoubis/sso/client/data/actions.rb +0 -5
  92. data/app/controllers/anoubis/sso/client/data/callbacks.rb +0 -5
  93. data/app/controllers/anoubis/sso/client/data/convert.rb +0 -5
  94. data/app/controllers/anoubis/sso/client/data/defaults.rb +0 -5
  95. data/app/controllers/anoubis/sso/client/data/get.rb +0 -5
  96. data/app/controllers/anoubis/sso/client/data/load.rb +0 -26
  97. data/app/controllers/anoubis/sso/client/data/set.rb +0 -5
  98. data/app/controllers/anoubis/sso/client/data/setup.rb +0 -5
  99. data/app/controllers/anoubis/sso/client/data_controller.rb +0 -21
  100. data/app/controllers/anoubis/tenant/data/actions.rb +0 -11
  101. data/app/controllers/anoubis/tenant/data/callbacks.rb +0 -11
  102. data/app/controllers/anoubis/tenant/data/convert.rb +0 -11
  103. data/app/controllers/anoubis/tenant/data/defaults.rb +0 -11
  104. data/app/controllers/anoubis/tenant/data/get.rb +0 -11
  105. data/app/controllers/anoubis/tenant/data/load.rb +0 -52
  106. data/app/controllers/anoubis/tenant/data/set.rb +0 -11
  107. data/app/controllers/anoubis/tenant/data/setup.rb +0 -11
  108. data/app/controllers/anoubis/tenant/data_controller.rb +0 -28
  109. data/app/controllers/anoubis/tenants_controller.rb +0 -7
  110. data/app/controllers/anoubis/users_controller.rb +0 -7
  111. data/app/mailers/anoubis/application_mailer.rb +0 -8
@@ -1,962 +0,0 @@
1
- module Anubis
2
- module Core
3
- module Data
4
- ##
5
- # Module presents all default actions for for {DataController}.
6
- module Actions
7
- ##
8
- # Default action of {DataController}. Procedure outputs data loaded from database table.
9
- # Authorization bearer is required.
10
- #
11
- # <b>API request:</b>
12
- # GET /api/<version>/<controller>
13
- #
14
- # <b>Request Header:</b>
15
- # {
16
- # "Authorization": "Bearer <Session token>"
17
- # }
18
- #
19
- # <b>Parameters:</b>
20
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
21
- # - <b>offset</b> (String) --- starting number for selection <i>(optional value, default: 0)</i>
22
- # - <b>limit</b> (String) --- number of selected rows <i>(optional value, default: 10)</i>
23
- # - <b>tab</b> (String) --- the tab, is used for selected data <i>(optional value, default: first defined tab)</i>
24
- #
25
- # <b>Request example:</b>
26
- # curl --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/<controller>?offset=0&limit=10
27
- #
28
- # <b>Results:</b>
29
- #
30
- # Resulting data returns in JSON format.
31
- #
32
- # <b>Examples:</b>
33
- #
34
- # <b>Success:</b> HTTP response code 200
35
- # {
36
- # "result": 0,
37
- # "message": "Successful",
38
- # "count": 5,
39
- # "tab": "inner",
40
- # "offset": "0",
41
- # "limit": "10",
42
- # "timestamp": 1563169525,
43
- # "fields": [
44
- # {
45
- # "prop": "title",
46
- # "title": "Soldier Ttitle"
47
- # "type": "string",
48
- # "sortable": true
49
- # },
50
- # {
51
- # "prop": "name",
52
- # "title": "Soldier Name"
53
- # "type": "string",
54
- # "sortable": true
55
- # },
56
- # {
57
- # "prop": "age",
58
- # "title": "Girl Age"
59
- # "type": "string",
60
- # "sortable": true
61
- # }
62
- # ],
63
- # "data": [
64
- # {
65
- # "id": 1,
66
- # "sys_title": "Sailor Moon",
67
- # "actions": {
68
- # "edit": "Edit: Sailor Moon",
69
- # "delete": "Delete: Sailor Moon"
70
- # },
71
- # "title": "Sailor Moon",
72
- # "name": "Banny Tsukino",
73
- # "age": 16,
74
- # "state": "inner"
75
- # },
76
- # {
77
- # "id": 2,
78
- # "sys_title": "Sailor Mercury",
79
- # "actions": {
80
- # "edit": "Edit: Sailor Mercury",
81
- # "delete": "Delete: Sailor Mercury"
82
- # },
83
- # "title": "Sailor Mercury",
84
- # "name": "Amy Mitsuno",
85
- # "age": 16,
86
- # "state": "inner"
87
- # }
88
- # ]
89
- # }
90
- def index
91
- self.etc.data = Anubis::Etc::Data.new
92
- self.set_parent_model 'index'
93
- self.output = Anubis::Output::Data.new
94
- self.output.count = self.get_table_data_count
95
- self.setup_fields
96
- self.output.limit = self.etc.data.limit
97
- self.output.offset = self.etc.data.offset
98
- self.output.fields = self.get_fields_properties if self.etc.time == 0
99
- self.output.filter = self.get_filter_properties if self.etc.time == 0
100
- self.output.data = self.get_table_data
101
- self.output.tab = self.etc.tab.tab
102
- self.output.sortable = self.is_sortable
103
- self.output.order = self.etc.tab.order if self.etc.tab.order != ''
104
- self.output.sort = self.etc.tab.sort if self.etc.tab.sort != nil
105
- self.after_get_table_data
106
- self.before_output
107
- respond_to do |format|
108
- format.json { render json: around_output(self.output.to_h) }
109
- end
110
- end
111
-
112
- ##
113
- # <i>Frame</i> action of {DataController}. Procedure outputs frame data information (title, tabs, frame buttons)
114
- # Authorization bearer is required.
115
- #
116
- # <b>API request:</b>
117
- # GET /api/<version>/<controller>/frame
118
- #
119
- # <b>Request Header:</b>
120
- # {
121
- # "Authorization": "Bearer <Session token>"
122
- # }
123
- #
124
- # <b>Parameters:</b>
125
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
126
- # - <b>offset</b> (String) --- starting number for selection <i>(optional value, default: 0)</i>
127
- # - <b>limit</b> (String) --- number of selected rows <i>(optional value, default: 10)</i>
128
- # - <b>tab</b> (String) --- the tab, is used for selected data <i>(optional value, default: first defined tab)</i>
129
- #
130
- # <b>Request example:</b>
131
- # curl --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/<controller>/frame
132
- #
133
- # <b>Results:</b>
134
- #
135
- # Resulting data returns in JSON format.
136
- #
137
- # <b>Examples:</b>
138
- #
139
- # <b>Success:</b> HTTP response code 200
140
- # {
141
- # "result": 0,
142
- # "message": "Successful",
143
- # "timestamp": 1563271417,
144
- # "title": "Sailor soldiers",
145
- # "short": "Soldiers",
146
- # "mode": "soldiers",
147
- # "access": "write",
148
- # "tabs": [
149
- # {
150
- # "tab": "inner",
151
- # "title": "Inner Senshi",
152
- # "buttons": [
153
- # {
154
- # "key": "new",
155
- # "mode": "single",
156
- # "type": "primary"
157
- # }
158
- # ],
159
- # "hint": "Shows only inner soldiers"
160
- # },
161
- # {
162
- # "tab": "outer",
163
- # "title": "Outer Senshi",
164
- # "buttons": [
165
- # {
166
- # "key": "new",
167
- # "mode": "single",
168
- # "type": "primary"
169
- # },
170
- # {
171
- # "key": "delete",
172
- # "mode": "multiple",
173
- # "type": "danger"
174
- # }
175
- # ]
176
- # }
177
- # ]
178
- # }
179
- #
180
- #
181
- # <b>Error (session expired):</b> HTTP response code 422
182
- # {
183
- # "result": -1,
184
- # "message": "Session expired",
185
- # "timestamp": 1563271417,
186
- # "tab": "inner"
187
- # }
188
- def frame
189
- self.output = Anubis::Output::Frame.new
190
- self.etc.data = Anubis::Etc::Data.new if !self.etc.data
191
- self.etc.action = 'frame'
192
- if self.parent_model
193
- if !self.get_parent_data
194
- self.output.result = -2
195
- end
196
- end
197
- self.setup_frame
198
- self.before_output
199
- respond_to do |format|
200
- format.json { render json: self.output.to_h }
201
- end
202
- end
203
-
204
- ##
205
- # <i>Show</i> action of {DataController}. Procedure outputs values for view form.
206
- # Authorization bearer is required.
207
- #
208
- # <b>API request:</b>
209
- # GET /api/<version>/<controller>/<id>
210
- #
211
- # <b>Request Header:</b>
212
- # {
213
- # "Authorization": "Bearer <Session token>"
214
- # }
215
- #
216
- # <b>Parameters:</b>
217
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
218
- # - <b>tab</b> (String) --- the tab, is used for action <i>(optional value, default: first defined tab)</i>
219
- #
220
- # Resulting output title is took from translation file <lang>.yml at path:
221
- # <lang>:
222
- # <controller name divided by level>:
223
- # edit:
224
- # form:
225
- # title: "Edit soldier %{title}"
226
- #
227
- # If this path isn't defined in translation file, then value is took from path:
228
- # <lang>:
229
- # anubis:
230
- # form:
231
- # titles:
232
- # edit: "Edit element: %{title}"
233
- #
234
- # <b>Request example:</b>
235
- # curl --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/<controller>/<id>?tab=<tab>
236
- #
237
- # <b>Results:</b>
238
- #
239
- # Resulting data returns in JSON format.
240
- #
241
- # <b>Examples:</b>
242
- #
243
- # <b>Success:</b> HTTP response code 200
244
- # {
245
- # "result": 0,
246
- # "message": "Successful",
247
- # "timestamp": 1563271417,
248
- # "tab": "inner",
249
- # "title": "Edit soldier Sailor Mars",
250
- # "values": {
251
- # "id": 3,
252
- # "title": "Sailor Mars",
253
- # "name": "Rey Hino",
254
- # "state_view": "Inner Senshi",
255
- # "state": "inner"
256
- # },
257
- # "options": {
258
- # "state": {
259
- # "inner": "Inner Senshi",
260
- # "outer": "Outer Senshi",
261
- # "star": "Sailor Star"
262
- # }
263
- # }
264
- # }
265
- #
266
- #
267
- # <b>Error (incorrect request id):</b> HTTP response code 200
268
- # {
269
- # "result": -2,
270
- # "message": "Incorrect request parameters",
271
- # "timestamp": 1563271417,
272
- # "tab": "inner"
273
- # }
274
- #
275
- #
276
- # <b>Error (session expired):</b> HTTP response code 422
277
- # {
278
- # "result": -1,
279
- # "message": "Session expired",
280
- # "timestamp": 1563271417,
281
- # "tab": "inner"
282
- # }
283
- def show
284
- self.output = Anubis::Output::Edit.new
285
- self.set_parent_model 'show'
286
- self.output.tab = self.etc.tab.tab
287
- if params.key?(:value) && params.key?(:field)
288
- self.load_data_by_title params[:field], params[:value]
289
- params[:id] = self.etc.data.data.id if self.etc.data.data
290
- end
291
- if params.key? :id
292
- self.load_data_by_id params[:id] if !self.etc.data.data
293
- if self.etc.data.data
294
- self.output.values = self.get_data_row self.etc.data.data
295
- if params.key? :time
296
- self.output.options = self.get_data_options params[:time]
297
- else
298
- self.output.options = self.get_data_options 0
299
- end
300
- self.output.fields = self.get_fields_properties if self.etc.time == 0
301
- else
302
- self.output.result = -2
303
- end
304
- else
305
- self.output.result = -2
306
- end
307
- if self.output.result == 0
308
- self.output.title = I18n.t(format('%s.show.form.title', params[:controller].sub('/', '.')), title: self.output.values[:sys_title],
309
- default: I18n.t('anubis.form.titles.show', title: self.output.values[:sys_title]))
310
- end
311
- self.before_output
312
- respond_to do |format|
313
- format.json { render json: self.output.to_h }
314
- end
315
- end
316
-
317
- ##
318
- # <i>New</i> action of {DataController}. Procedure outputs default values for create form.
319
- # Authorization bearer is required.
320
- #
321
- # <b>API request:</b>
322
- # GET /api/<version>/<controller>/new
323
- #
324
- # <b>Request Header:</b>
325
- # {
326
- # "Authorization": "Bearer <Session token>"
327
- # }
328
- #
329
- # <b>Parameters:</b>
330
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
331
- # - <b>tab</b> (String) --- the tab, is used for action <i>(optional value, default: first defined tab)</i>
332
- #
333
- # Resulting output title is took from translation file <lang>.yml at path:
334
- # <lang>:
335
- # <controller name divided by level>:
336
- # new:
337
- # form:
338
- # title: "Add new soldier"
339
- #
340
- # If this path isn't defined in translation file, then value is took from path:
341
- # <lang>:
342
- # anubis:
343
- # form:
344
- # titles:
345
- # new: "Add new element"
346
- #
347
- # <b>Request example:</b>
348
- # curl --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/<controller>/new?tab=<tab>
349
- #
350
- # <b>Results:</b>
351
- #
352
- # Resulting data returns in JSON format.
353
- #
354
- # <b>Examples:</b>
355
- #
356
- # <b>Success:</b> HTTP response code 200
357
- # {
358
- # "result": 0,
359
- # "message": "Successful",
360
- # "timestamp": 1563271417,
361
- # "tab": "inner",
362
- # "title": "Add new soldier",
363
- # "values": {
364
- # "title": "",
365
- # "name": "",
366
- # "state_view": "Inner Senshi",
367
- # "state": "inner"
368
- # },
369
- # "options": {
370
- # "state": {
371
- # "inner": "Inner Senshi",
372
- # "outer": "Outer Senshi",
373
- # "star": "Sailor Star"
374
- # }
375
- # }
376
- # }
377
- #
378
- #
379
- # <b>Error (session expired):</b> HTTP response code 422
380
- # {
381
- # "result": -1,
382
- # "message": "Session expired",
383
- # "timestamp": 1563271417,
384
- # "tab": "inner"
385
- # }
386
- def new
387
- new_action_skeleton 'new'
388
- end
389
-
390
- def new_action_skeleton(action)
391
- self.output = Anubis::Output::Edit.new
392
- self.set_parent_model action
393
- self.output.tab = self.etc.tab.tab
394
- if self.etc.tab.buttons.key? action.to_sym
395
- self.load_new_data action
396
- if etc.data.data
397
- self.output.values = get_data_row etc.data.data
398
- if params.key? :time
399
- self.output.options = get_data_options params[:time]
400
- else
401
- self.output.options = self.get_data_options 0
402
- end
403
- etc.action = 'new'
404
- self.output.fields = self.get_fields_properties if self.etc.time == 0
405
- etc.action = action
406
- else
407
- self.output.result = -2
408
- end
409
- else
410
- self.output.result = -1
411
- end
412
- if self.output.result == 0
413
- self.output.title = I18n.t(format('%s.%s.form.title', params[:controller].sub('/', '.'), action), default: I18n.t('anubis.form.titles.new'))
414
- end
415
- self.before_output
416
-
417
-
418
- respond_to do |format|
419
- format.json { render json: self.output.to_h }
420
- end
421
- end
422
-
423
- ##
424
- # <i>Create</i> action of {DataController}. Procedure inserts data into database.
425
- # Authorization bearer is required.
426
- #
427
- # <b>API request:</b>
428
- # POST /api/<version>/<controller>/new
429
- #
430
- # <b>Request Header:</b>
431
- # {
432
- # "Authorization": "Bearer <Session token>"
433
- # }
434
- #
435
- # <b>Parameters:</b>
436
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
437
- # - <b>tab</b> (String) --- the tab, is used for action <i>(optional value, default: first defined tab)</i>
438
- # - <b>data</b> (String) --- inserted data <i>(required value)</i>
439
- #
440
- # <b>Request example:</b>
441
- # curl --request POST --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' --data='{"title": "Sailor Mars", "name": "Rey Hino", "state": "inner"}' http://<server>:<port>/api/<api-version>/<controller>/?tab=<tab>
442
- #
443
- # <b>Results:</b>
444
- #
445
- # Resulting data returns in JSON format.
446
- #
447
- # <b>Examples:</b>
448
- #
449
- # <b>Success:</b> HTTP response code 200
450
- # {
451
- # "result": 0,
452
- # "message": "Successful",
453
- # "timestamp": 1563271417,
454
- # "tab": "inner",
455
- # "values": {
456
- # "id": 3,
457
- # "sys_title": "Sailor Mars",
458
- # "actions": {
459
- # "edit": "Edit: Sailor Mars",
460
- # "delete": "Delete: Sailor Mars"
461
- # },
462
- # "title": "Sailor Mars",
463
- # "name": "Rey Hino",
464
- # "state": "Inner Senshi",
465
- # "raw_state": "inner"
466
- # },
467
- # "action": ""
468
- # }
469
- #
470
- #
471
- # <b>Error (data presents):</b> HTTP response code 200
472
- # {
473
- # "result": -3,
474
- # "message": "Error update data",
475
- # "timestamp": 1563271417,
476
- # "tab": "inner",
477
- # "errors": [
478
- # "Title already presents"
479
- # ]
480
- # }
481
- #
482
- #
483
- # <b>Error (session expired):</b> HTTP response code 422
484
- # {
485
- # "result": -1,
486
- # "message": "Session expired",
487
- # "timestamp": 1563271417,
488
- # "tab": "inner"
489
- # }
490
- def create
491
- self.output = Anubis::Output::Update.new
492
- self.set_parent_model 'create'
493
- self.output.tab = self.etc.tab.tab
494
- if params.key? :data
495
- if self.etc.tab.buttons.key? :new
496
- self.load_new_data
497
- if self.etc.data.data
498
- self.setup_fields
499
- data = get_permited_params
500
-
501
- data = self.before_create_data data
502
-
503
- if data
504
- data.each_key do |key|
505
- self.convert_view_to_db_value key, data[key]
506
- end
507
-
508
- if self.etc.data.data.respond_to? :tenant_id
509
- if self.current_user.respond_to? :tenant_id
510
- self.etc.data.data.tenant_id = self.current_user.tenant_id if !self.etc.data.data.tenant_id
511
- end
512
- end
513
-
514
- if self.etc.data.data.save
515
- else
516
- self.output.errors.concat self.etc.data.data.errors.full_messages
517
- end
518
- else
519
- self.output.result = -4
520
- end
521
-
522
- if self.output.errors.length == 0
523
- self.etc.data.fields = nil
524
- self.set_new_action 'index'
525
- self.output.values = self.get_data_row self.etc.data.data
526
- self.set_new_action 'create'
527
- self.after_create_data
528
- else
529
- self.output.result = -3
530
- end
531
- else
532
- self.output.result = -2
533
- end
534
- else
535
- self.output.result = -1
536
- end
537
- else
538
- self.output.result = -2
539
- end
540
- self.before_output
541
- respond_to do |format|
542
- format.json { render json: self.output.to_h }
543
- end
544
- end
545
-
546
- ##
547
- # <i>Edit</i> action of {DataController}. Procedure outputs values for edit form.
548
- # Authorization bearer is required.
549
- #
550
- # <b>API request:</b>
551
- # GET /api/<version>/<controller>/<id>/edit
552
- #
553
- # <b>Request Header:</b>
554
- # {
555
- # "Authorization": "Bearer <Session token>"
556
- # }
557
- #
558
- # <b>Parameters:</b>
559
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
560
- # - <b>tab</b> (String) --- the tab, is used for action <i>(optional value, default: first defined tab)</i>
561
- #
562
- # Resulting output title is took from translation file <lang>.yml at path:
563
- # <lang>:
564
- # <controller name divided by level>:
565
- # edit:
566
- # form:
567
- # title: "Edit soldier %{title}"
568
- #
569
- # If this path isn't defined in translation file, then value is took from path:
570
- # <lang>:
571
- # anubis:
572
- # form:
573
- # titles:
574
- # edit: "Edit element: %{title}"
575
- #
576
- # <b>Request example:</b>
577
- # curl --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/<controller>/<id>/edit?tab=<tab>
578
- #
579
- # <b>Results:</b>
580
- #
581
- # Resulting data returns in JSON format.
582
- #
583
- # <b>Examples:</b>
584
- #
585
- # <b>Success:</b> HTTP response code 200
586
- # {
587
- # "result": 0,
588
- # "message": "Successful",
589
- # "timestamp": 1563271417,
590
- # "tab": "inner",
591
- # "title": "Edit soldier Sailor Mars",
592
- # "values": {
593
- # "id": 3,
594
- # "title": "Sailor Mars",
595
- # "name": "Rey Hino",
596
- # "state_view": "Inner Senshi",
597
- # "state": "inner"
598
- # },
599
- # "options": {
600
- # "state": {
601
- # "inner": "Inner Senshi",
602
- # "outer": "Outer Senshi",
603
- # "star": "Sailor Star"
604
- # }
605
- # }
606
- # }
607
- #
608
- #
609
- # <b>Error (incorrect request id):</b> HTTP response code 200
610
- # {
611
- # "result": -2,
612
- # "message": "Incorrect request parameters",
613
- # "timestamp": 1563271417,
614
- # "tab": "inner"
615
- # }
616
- #
617
- #
618
- # <b>Error (session expired):</b> HTTP response code 422
619
- # {
620
- # "result": -1,
621
- # "message": "Session expired",
622
- # "timestamp": 1563271417,
623
- # "tab": "inner"
624
- # }
625
- def edit
626
- self.output = Anubis::Output::Edit.new
627
- self.set_parent_model 'edit'
628
- self.output.tab = self.etc.tab.tab
629
- if self.table_actions.include?('edit')
630
- if params.key?(:value) && params.key?(:field)
631
- self.load_data_by_title params[:field], params[:value]
632
- params[:id] = self.etc.data.data.id if self.etc.data.data
633
- end
634
- if params.key? :id
635
- self.load_data_by_id params[:id] if !self.etc.data.data
636
- if self.etc.data.data
637
- self.output.values = self.get_data_row self.etc.data.data
638
- if params.key? :time
639
- self.output.options = self.get_data_options params[:time]
640
- else
641
- self.output.options = self.get_data_options 0
642
- end
643
- self.output.fields = self.get_fields_properties if self.etc.time == 0
644
- else
645
- self.output.result = -2
646
- end
647
- else
648
- self.output.result = -2
649
- end
650
- else
651
- self.output.result = -1
652
- end
653
- if self.output.result == 0
654
- self.output.title = I18n.t(format('%s.edit.form.title', params[:controller].sub('/', '.')), title: self.output.values[:sys_title],
655
- default: I18n.t('anubis.form.titles.edit', title: self.output.values[:sys_title]))
656
- end
657
- self.before_output
658
- respond_to do |format|
659
- format.json { render json: self.output.to_h }
660
- end
661
- end
662
-
663
- ##
664
- # <i>Update</i> action of {DataController}. Procedure updates data in database.
665
- # Authorization bearer is required.
666
- #
667
- # <b>API request:</b>
668
- # PUT /api/<version>/<controller>/<id>/
669
- #
670
- # <b>Request Header:</b>
671
- # {
672
- # "Authorization": "Bearer <Session token>"
673
- # }
674
- #
675
- # <b>Parameters:</b>
676
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
677
- # - <b>tab</b> (String) --- the tab, is used for action <i>(optional value, default: first defined tab)</i>
678
- # - <b>data</b> (String) --- inserted data <i>(required value)</i>
679
- #
680
- # <b>Request example:</b>
681
- # curl --request PUT --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' --data='{"title": "Sailor Mars", "name": "Rey Hino", "state": "inner"}' http://<server>:<port>/api/<api-version>/<controller>/<id>/?tab=<tab>
682
- #
683
- # <b>Results:</b>
684
- #
685
- # Resulting data returns in JSON format.
686
- #
687
- # <b>Examples:</b>
688
- #
689
- # <b>Success:</b> HTTP response code 200
690
- # {
691
- # "result": 0,
692
- # "message": "Successful",
693
- # "timestamp": 1563271417,
694
- # "tab": "inner",
695
- # "values": {
696
- # "id": 3,
697
- # "sys_title": "Sailor Mars",
698
- # "actions": {
699
- # "edit": "Edit: Sailor Mars",
700
- # "delete": "Delete: Sailor Mars"
701
- # },
702
- # "title": "Sailor Mars",
703
- # "name": "Rey Hino",
704
- # "state": "Inner Senshi",
705
- # "raw_state": "inner"
706
- # },
707
- # "action": ""
708
- # }
709
- #
710
- #
711
- # <b>Error (data presents):</b> HTTP response code 200
712
- # {
713
- # "result": -3,
714
- # "message": "Error update data",
715
- # "timestamp": 1563271417,
716
- # "tab": "inner",
717
- # "errors": [
718
- # "Title already presents"
719
- # ]
720
- # }
721
- #
722
- #
723
- # <b>Error (session expired):</b> HTTP response code 422
724
- # {
725
- # "result": -1,
726
- # "message": "Session expired",
727
- # "timestamp": 1563271417,
728
- # "tab": "inner"
729
- # }
730
- def update
731
- self.output = Anubis::Output::Update.new
732
- self.set_parent_model 'update'
733
- self.output.tab = self.etc.tab.tab
734
- if self.table_actions.include?('edit')
735
- if params.key?(:id) && params.key?(:data)
736
- self.load_data_by_id params[:id]
737
- if self.etc.data.data
738
- self.setup_fields
739
- data = get_permited_params
740
-
741
- data = self.before_update_data data
742
-
743
- if data
744
- data.each_key do |key|
745
- self.convert_view_to_db_value key, data[key]
746
- end
747
-
748
- if self.etc.data.data.save
749
- else
750
- self.output.errors.concat self.etc.data.data.errors.full_messages
751
- end
752
-
753
- if self.output.errors.length == 0
754
- self.etc.data.fields = nil
755
- self.set_new_action 'index'
756
- self.output.values = self.get_data_row self.etc.data.data
757
- self.output.action = 'refresh' if self.etc.data.data.need_refresh
758
- self.set_new_action 'update'
759
- self.after_update_data
760
- else
761
- self.output.result = -3
762
- end
763
- end
764
- else
765
- self.output.result = -4
766
- end
767
- else
768
- self.output.result = -2
769
- end
770
- else
771
- self.output.result = -1
772
- end
773
- self.before_output
774
- respond_to do |format|
775
- format.json { render json: self.output.to_h }
776
- end
777
- end
778
-
779
- ##
780
- # <i>Destroy</i> action of {DataController}. Procedure deletes data from database.
781
- # Authorization bearer is required.
782
- #
783
- # <b>API request:</b>
784
- # DELETE /api/<version>/<controller>/<id>/
785
- #
786
- # <b>Request Header:</b>
787
- # {
788
- # "Authorization": "Bearer <Session token>"
789
- # }
790
- #
791
- # <b>Parameters:</b>
792
- # - <b>locale</b> (String) --- the output language locale <i>(optional value)</i>
793
- # - <b>tab</b> (String) --- the tab, is used for action <i>(optional value, default: first defined tab)</i>
794
- #
795
- # <b>Request example:</b>
796
- # curl --request DELETE --header "Content-Type: application/json" --header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/<controller>/<id>/?tab=<tab>
797
- #
798
- # <b>Results:</b>
799
- #
800
- # Resulting data returns in JSON format.
801
- #
802
- # <b>Examples:</b>
803
- #
804
- # <b>Success:</b> HTTP response code 200
805
- # {
806
- # "result": 0,
807
- # "message": "Successful",
808
- # "timestamp": 1563271417,
809
- # "tab": "inner"
810
- # }
811
- #
812
- #
813
- # <b>Error (incorrect request id):</b> HTTP response code 200
814
- # {
815
- # "result": -2,
816
- # "message": "Incorrect request parameters",
817
- # "timestamp": 1563271417,
818
- # "tab": "inner"
819
- # }
820
- #
821
- #
822
- # <b>Error (session expired):</b> HTTP response code 422
823
- # {
824
- # "result": -1,
825
- # "message": "Session expired",
826
- # "timestamp": 1563271417,
827
- # "tab": "inner"
828
- # }
829
- def destroy
830
- self.output = Anubis::Output::Delete.new
831
- self.set_parent_model 'destroy'
832
- self.output.tab = self.etc.tab.tab
833
- if self.etc.tab.buttons.key? :delete
834
- if params.key?(:value) && params.key?(:field)
835
- self.load_data_by_title params[:field], params[:value]
836
- params[:id] = self.etc.data.data.id if self.etc.data.data
837
- end
838
- if params.key?(:id)
839
- self.load_data_by_id params[:id] if !self.etc.data.data
840
- if self.etc.data.data
841
- self.output.id = self.etc.data.data.id
842
- if self.etc.data.data.can_delete( { tab: self.etc.tab } )
843
- self.destroy_data
844
- else
845
- self.output.result = -1
846
- end
847
- else
848
- self.output.result = -2
849
- end
850
- else
851
- self.output.result = -2
852
- end
853
- else
854
- self.output.result = -1
855
- end
856
- self.before_output
857
- respond_to do |format|
858
- format.json { render json: self.output.to_h }
859
- end
860
- end
861
-
862
- ##
863
- # Returns autocomplete data
864
- def autocomplete
865
- self.output = Anubis::Output::Autocomplete.new
866
- self.output.result = -1
867
- self.set_parent_model 'autocomplete'
868
- self.output.tab = self.etc.tab.tab
869
- if params.key?(:field) && params.key?(:value)
870
- self.setup_fields
871
- if self.etc.data.fields
872
- if self.etc.data.fields.key? params[:field].to_s.to_sym
873
- field = self.etc.data.fields[params[:field].to_s.to_sym]
874
- #puts 'autocomplete'
875
- #puts field.to_h
876
- if field.autocomplete
877
- self.output.result = 0
878
- self.get_autocomplete_data field, params[:value]
879
- #puts field.to_h
880
- end
881
- end
882
- end
883
- end
884
- self.before_output
885
- respond_to do |format|
886
- format.json { render json: self.output.to_h }
887
- end
888
- end
889
-
890
- ##
891
- # Export data from database
892
- def export
893
- self.etc.data = Anubis::Etc::Data.new
894
- self.set_parent_model 'export'
895
- self.output = Anubis::Output::Data.new
896
- if self.etc.tab.export
897
- self.output.count = self.get_table_data_count
898
- count = (self.output.count / 40).to_i + 1
899
- self.setup_fields
900
-
901
- self.exports = Anubis::Export.new format: self.export_format, fields: self.get_fields_properties
902
-
903
- case self.exports.format
904
- when 'xls'
905
- headers['Content-Disposition'] = 'attachment; filename="export.xlsx" filename*="export.xlsx"'
906
- end
907
-
908
- self.etc.data.limit = 40
909
- self.etc.data.offset = 0
910
- self.output.data = self.get_table_data
911
- self.after_get_table_data
912
- self.before_output
913
- self.exports.add self.output.data
914
-
915
- if count > 1
916
- for i in 2..count
917
- self.etc.data.offset = (i-1)*40
918
- self.output.data = self.get_table_data
919
- self.after_get_table_data
920
- self.before_output
921
- self.exports.add self.output.data
922
- end
923
- end
924
-
925
- respond_to do |format|
926
- case self.exports.format
927
- when 'xls'
928
- format.xlsx {
929
- send_data self.render_xls_file, type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
930
- }
931
- end
932
- end
933
- else
934
- respond_to do |format|
935
- format.any { render json: {result: -1}, status: :unprocessable_entity }
936
- end
937
-
938
- end
939
- end
940
-
941
- ##
942
- # Returns rendered xlsx data
943
- def render_xls_file
944
- Axlsx::Package.new do |p|
945
- wb = p.workbook
946
- wb.styles do |s|
947
- default = s.add_style :sz => 11, :font_name => "Calibri", :alignment => {:vertical => :center}
948
- default_bold = s.add_style :sz => 11, :font_name => "Calibri", :alignment => {:vertical => :center}, :b => true
949
- wb.add_worksheet(name: 'Data') do |sheet|
950
- sheet.add_row self.exports.title, :style => default_bold
951
- self.exports.data.each do |data|
952
- sheet.add_row data, :style => default
953
- end
954
- end
955
- end
956
- return p.to_stream().read
957
- end
958
- end
959
- end
960
- end
961
- end
962
- end