anoubis 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +38 -0
  5. data/app/controllers/anoubis/application_controller.rb +78 -0
  6. data/app/controllers/anoubis/core/application_controller.rb +343 -0
  7. data/app/controllers/anoubis/core/data/actions.rb +962 -0
  8. data/app/controllers/anoubis/core/data/callbacks.rb +68 -0
  9. data/app/controllers/anoubis/core/data/convert.rb +407 -0
  10. data/app/controllers/anoubis/core/data/defaults.rb +217 -0
  11. data/app/controllers/anoubis/core/data/get.rb +531 -0
  12. data/app/controllers/anoubis/core/data/load.rb +89 -0
  13. data/app/controllers/anoubis/core/data/set.rb +49 -0
  14. data/app/controllers/anoubis/core/data/setup.rb +104 -0
  15. data/app/controllers/anoubis/core/data_controller.rb +28 -0
  16. data/app/controllers/anoubis/core/index/actions.rb +53 -0
  17. data/app/controllers/anoubis/core/index/callbacks.rb +23 -0
  18. data/app/controllers/anoubis/core/index_controller.rb +36 -0
  19. data/app/controllers/anoubis/etc/base.rb +52 -0
  20. data/app/controllers/anoubis/etc/data.rb +89 -0
  21. data/app/controllers/anoubis/etc/field.rb +468 -0
  22. data/app/controllers/anoubis/etc/field_options.rb +83 -0
  23. data/app/controllers/anoubis/etc/field_order.rb +51 -0
  24. data/app/controllers/anoubis/etc/filter.rb +251 -0
  25. data/app/controllers/anoubis/etc/menu.rb +101 -0
  26. data/app/controllers/anoubis/etc/model.rb +67 -0
  27. data/app/controllers/anoubis/etc/tab_item.rb +91 -0
  28. data/app/controllers/anoubis/etc.rb +8 -0
  29. data/app/controllers/anoubis/export.rb +47 -0
  30. data/app/controllers/anoubis/output/autocomplete.rb +30 -0
  31. data/app/controllers/anoubis/output/basic.rb +86 -0
  32. data/app/controllers/anoubis/output/data.rb +101 -0
  33. data/app/controllers/anoubis/output/delete.rb +41 -0
  34. data/app/controllers/anoubis/output/edit.rb +55 -0
  35. data/app/controllers/anoubis/output/frame.rb +227 -0
  36. data/app/controllers/anoubis/output/login.rb +71 -0
  37. data/app/controllers/anoubis/output/menu.rb +220 -0
  38. data/app/controllers/anoubis/output/update.rb +43 -0
  39. data/app/controllers/anoubis/sso/client/application_controller.rb +139 -0
  40. data/app/controllers/anoubis/sso/client/data/actions.rb +5 -0
  41. data/app/controllers/anoubis/sso/client/data/callbacks.rb +5 -0
  42. data/app/controllers/anoubis/sso/client/data/convert.rb +5 -0
  43. data/app/controllers/anoubis/sso/client/data/defaults.rb +5 -0
  44. data/app/controllers/anoubis/sso/client/data/get.rb +5 -0
  45. data/app/controllers/anoubis/sso/client/data/load.rb +26 -0
  46. data/app/controllers/anoubis/sso/client/data/set.rb +5 -0
  47. data/app/controllers/anoubis/sso/client/data/setup.rb +5 -0
  48. data/app/controllers/anoubis/sso/client/data_controller.rb +21 -0
  49. data/app/controllers/anoubis/sso/client/index/actions.rb +79 -0
  50. data/app/controllers/anoubis/sso/client/index/callbacks.rb +13 -0
  51. data/app/controllers/anoubis/sso/client/index_controller.rb +18 -0
  52. data/app/controllers/anoubis/sso/server/application_controller.rb +49 -0
  53. data/app/controllers/anoubis/sso/server/login_controller.rb +342 -0
  54. data/app/controllers/anoubis/sso/server/user_controller.rb +142 -0
  55. data/app/controllers/anoubis/tenant/application_controller.rb +54 -0
  56. data/app/controllers/anoubis/tenant/data/actions.rb +11 -0
  57. data/app/controllers/anoubis/tenant/data/callbacks.rb +11 -0
  58. data/app/controllers/anoubis/tenant/data/convert.rb +11 -0
  59. data/app/controllers/anoubis/tenant/data/defaults.rb +11 -0
  60. data/app/controllers/anoubis/tenant/data/get.rb +11 -0
  61. data/app/controllers/anoubis/tenant/data/load.rb +52 -0
  62. data/app/controllers/anoubis/tenant/data/set.rb +11 -0
  63. data/app/controllers/anoubis/tenant/data/setup.rb +11 -0
  64. data/app/controllers/anoubis/tenant/data_controller.rb +28 -0
  65. data/app/controllers/anoubis/tenant/index/actions.rb +191 -0
  66. data/app/controllers/anoubis/tenant/index/callbacks.rb +11 -0
  67. data/app/controllers/anoubis/tenant/index_controller.rb +38 -0
  68. data/app/controllers/anoubis/tenants_controller.rb +7 -0
  69. data/app/controllers/anoubis/users_controller.rb +7 -0
  70. data/app/jobs/anoubis/application_job.rb +6 -0
  71. data/app/mailers/anoubis/application_mailer.rb +8 -0
  72. data/app/models/anoubis/application_record.rb +45 -0
  73. data/app/models/anoubis/core/application_record.rb +250 -0
  74. data/app/models/anoubis/core/locales.rb +27 -0
  75. data/app/models/anoubis/sso/client/application_record.rb +3 -0
  76. data/app/models/anoubis/sso/client/group.rb +19 -0
  77. data/app/models/anoubis/sso/client/group_menu.rb +109 -0
  78. data/app/models/anoubis/sso/client/menu.rb +145 -0
  79. data/app/models/anoubis/sso/client/user.rb +81 -0
  80. data/app/models/anoubis/sso/client/user_group.rb +32 -0
  81. data/app/models/anoubis/sso/server/system.rb +36 -0
  82. data/app/models/anoubis/sso/server/user.rb +79 -0
  83. data/app/models/anoubis/tenant/application_record.rb +41 -0
  84. data/app/models/anoubis/tenant/group.rb +95 -0
  85. data/app/models/anoubis/tenant/group_locale.rb +19 -0
  86. data/app/models/anoubis/tenant/group_menu.rb +84 -0
  87. data/app/models/anoubis/tenant/menu.rb +156 -0
  88. data/app/models/anoubis/tenant/menu_locale.rb +27 -0
  89. data/app/models/anoubis/tenant/system.rb +127 -0
  90. data/app/models/anoubis/tenant/system_locale.rb +19 -0
  91. data/app/models/anoubis/tenant/system_menu.rb +51 -0
  92. data/app/models/anoubis/tenant/tenant.rb +107 -0
  93. data/app/models/anoubis/tenant/tenant_system.rb +19 -0
  94. data/app/models/anoubis/tenant/user.rb +225 -0
  95. data/app/models/anoubis/tenant/user_group.rb +32 -0
  96. data/app/services/anoubis/core_service.rb +16 -0
  97. data/app/services/anoubis/session_service.rb +17 -0
  98. data/app/validators/presence_in_tenant_validator.rb +20 -0
  99. data/config/initializers/mime_type.rb +1 -0
  100. data/config/locales/en.yml +120 -0
  101. data/config/locales/ru.yml +245 -0
  102. data/config/routes.rb +74 -0
  103. data/db/migrate/20181018085843_create_tenants.rb +13 -0
  104. data/db/migrate/20181018111217_create_systems.rb +10 -0
  105. data/db/migrate/20181018111713_create_tenant_systems.rb +11 -0
  106. data/db/migrate/20181018111925_create_groups.rb +13 -0
  107. data/db/migrate/20181018112151_create_users.rb +25 -0
  108. data/db/migrate/20181018115737_add_title_to_users.rb +10 -0
  109. data/db/migrate/20181022060211_create_menus.rb +18 -0
  110. data/db/migrate/20181115055245_create_group_menus.rb +12 -0
  111. data/db/migrate/20181115060830_create_system_menus.rb +11 -0
  112. data/db/migrate/20181122062131_create_user_groups.rb +11 -0
  113. data/db/migrate/20181221060727_create_menu_locales.rb +14 -0
  114. data/db/migrate/20181225062303_create_system_locales.rb +11 -0
  115. data/db/migrate/20181225062339_create_group_locales.rb +11 -0
  116. data/db/seeds.rb +268 -0
  117. data/lib/anoubis/engine.rb +13 -0
  118. data/lib/anoubis/version.rb +5 -0
  119. data/lib/anoubis.rb +213 -0
  120. data/lib/tasks/anubis_tasks.rake +10 -0
  121. data/lib/tasks/sessions/clear_sessions.rake +10 -0
  122. data/spec/anubis_spec.rb +5 -0
  123. data/spec/controllers/anoubis/index_controller_spec.rb +77 -0
  124. data/spec/dummy/Rakefile +3 -0
  125. data/spec/dummy/app/assets/config/manifest.js +2 -0
  126. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  127. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  128. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  129. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  130. data/spec/dummy/app/controllers/application_controller.rb +2 -0
  131. data/spec/dummy/app/jobs/application_job.rb +2 -0
  132. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  133. data/spec/dummy/app/models/application_record.rb +3 -0
  134. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  135. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  136. data/spec/dummy/bin/bundle +3 -0
  137. data/spec/dummy/bin/rails +4 -0
  138. data/spec/dummy/bin/rake +4 -0
  139. data/spec/dummy/bin/setup +33 -0
  140. data/spec/dummy/bin/update +28 -0
  141. data/spec/dummy/config/application.rb +14 -0
  142. data/spec/dummy/config/boot.rb +5 -0
  143. data/spec/dummy/config/cable.yml +10 -0
  144. data/spec/dummy/config/database.yml +54 -0
  145. data/spec/dummy/config/environment.rb +5 -0
  146. data/spec/dummy/config/environments/development.rb +54 -0
  147. data/spec/dummy/config/environments/production.rb +85 -0
  148. data/spec/dummy/config/environments/test.rb +46 -0
  149. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  150. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  151. data/spec/dummy/config/initializers/cors.rb +16 -0
  152. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  153. data/spec/dummy/config/initializers/inflections.rb +16 -0
  154. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  155. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  156. data/spec/dummy/config/locales/en.yml +33 -0
  157. data/spec/dummy/config/puma.rb +34 -0
  158. data/spec/dummy/config/routes.rb +3 -0
  159. data/spec/dummy/config/spring.rb +6 -0
  160. data/spec/dummy/config/storage.yml +34 -0
  161. data/spec/dummy/config.ru +5 -0
  162. data/spec/dummy/db/schema.rb +167 -0
  163. data/spec/dummy/db/seeds.rb +1 -0
  164. data/spec/factories/anubis_group_locales.rb +7 -0
  165. data/spec/factories/anubis_group_menus.rb +7 -0
  166. data/spec/factories/anubis_groups.rb +6 -0
  167. data/spec/factories/anubis_menu_locales.rb +9 -0
  168. data/spec/factories/anubis_menus.rb +6 -0
  169. data/spec/factories/anubis_system_locales.rb +7 -0
  170. data/spec/factories/anubis_system_menus.rb +6 -0
  171. data/spec/factories/anubis_systems.rb +5 -0
  172. data/spec/factories/anubis_tenants.rb +7 -0
  173. data/spec/factories/anubis_users.rb +10 -0
  174. data/spec/integration/navigation_test.rb +7 -0
  175. data/spec/models/anoubis/group_locale_spec.rb +25 -0
  176. data/spec/models/anoubis/group_menu_spec.rb +50 -0
  177. data/spec/models/anoubis/group_spec.rb +52 -0
  178. data/spec/models/anoubis/menu_locale_spec.rb +31 -0
  179. data/spec/models/anoubis/menu_spec.rb +48 -0
  180. data/spec/models/anoubis/system_locale_spec.rb +20 -0
  181. data/spec/models/anoubis/system_menu_spec.rb +49 -0
  182. data/spec/models/anoubis/system_spec.rb +53 -0
  183. data/spec/models/anoubis/tenant_spec.rb +67 -0
  184. data/spec/models/anoubis/user_spec.rb +57 -0
  185. data/spec/rails_helper.rb +32 -0
  186. data/spec/requests/anoubis/users_request_spec.rb +5 -0
  187. data/spec/spec_helper.rb +13 -0
  188. metadata +408 -0
@@ -0,0 +1,251 @@
1
+ module Anubis
2
+ module Etc
3
+ ##
4
+ # Definitions of filter options for data.
5
+ class Filter
6
+ # @!attribute [rw]
7
+ # Defines row filter data
8
+ # @return [Hash,nil] row filter data.
9
+ class_attribute :data, default: nil
10
+
11
+ # @!attribute [rw]
12
+ # Defines ActiveRecord hash representation of where.
13
+ # @return [FieldOrder] hash representation of where
14
+ class_attribute :hash, default: {}
15
+
16
+ # @!attribute [rw]
17
+ # Defines ActiveRecord array representation of where.
18
+ # @return [FieldOrder] array representation of where
19
+ class_attribute :array, default: []
20
+
21
+ # @!attribute [rw]
22
+ # Defines reference for fields
23
+ # @return [Hash<Anubis::Etc::Field>] hash of fields
24
+ class_attribute :fields, default: nil
25
+
26
+ ##
27
+ # Sets default parameters for filter
28
+ def initialize(options = {})
29
+ self.fields = if options.key? :fields then options[:fields] else {} end
30
+ self.hash = {}
31
+ self.array = []
32
+ if options.key? :data then self.init_data(options[:data]) else self.data end
33
+ end
34
+
35
+ ##
36
+ # Generates hash representation of all class parameters,
37
+ # @return [Hash] hash representation of all data
38
+ def to_h
39
+ result = {
40
+ data: self.data,
41
+ hash: self.hash,
42
+ array: self.array,
43
+ fields: {}
44
+ }
45
+ self.fields.each_key do |key|
46
+ result[:fields][key] = self.fields[key].to_h
47
+ end
48
+ result
49
+ end
50
+
51
+ ##
52
+ # Initializes all where parameters according by data and fields.
53
+ # @param data [Hash] Collection of filter parameters in format <i>field: value</i>
54
+ def init_data(data = nil)
55
+ self.data = if data then data else {} end
56
+
57
+ if self.fields
58
+ self.fields.each do |key, field|
59
+ if self.data.key? key.to_s
60
+ proc = format('init_data_%s', field.type)
61
+ result = self.send proc, key, self.data[key.to_s]
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ ##
68
+ # Initializes where parameters for filed with type string.
69
+ # @param key [Symbol] Filed identifier
70
+ # @param value [String] Filter parameters
71
+ def init_data_string(key, value)
72
+ words = value.split(' ')
73
+
74
+ words.each do |word|
75
+ self.attach_to_array self.fields[key].table_field.to_s+' LIKE ?'
76
+ self.array.push("%#{word}%")
77
+ end
78
+ end
79
+
80
+ ##
81
+ # Initializes where parameters for filed with type text.
82
+ # @param key [Symbol] Filed identifier
83
+ # @param value [String] Filter parameters
84
+ def init_data_text(key, value)
85
+ words = value.split(' ')
86
+
87
+ words.each do |word|
88
+ self.attach_to_array self.fields[key].table_field.to_s+' LIKE ?'
89
+ self.array.push("%#{word}%")
90
+ end
91
+ end
92
+
93
+ ##
94
+ # Initializes where parameters for filed with type number.
95
+ # @param key [Symbol] Filed identifier
96
+ # @param value [String] Filter parameters
97
+ def init_data_number(key, value)
98
+ if value.index ','
99
+ if self.fields[key].table_field.to_s.include? '.'
100
+ self.attach_to_array self.fields[key].table_field.to_s + ' IN (?)'
101
+ self.array.push(value.split ',')
102
+ else
103
+ self.hash[key] = value.split ','
104
+ end
105
+ return
106
+ end
107
+
108
+ if value.index '>'
109
+ if value.to_s.include? '.'
110
+ result_value = value.to_s[1..100].to_f
111
+ else
112
+ result_value = value.to_s[1..100].to_i
113
+ end
114
+ if self.fields[key].table_field.to_s.include? '.'
115
+ self.attach_to_array self.fields[key].table_field.to_s + ' > ?'
116
+
117
+ self.array.push(result_value)
118
+ else
119
+ self.hash[key] = [result_value..Float::INFINITY]
120
+ end
121
+ return
122
+ end
123
+
124
+ if value.index '<'
125
+ if value.to_s.include? '.'
126
+ result_value = value.to_s[1..100].to_f
127
+ else
128
+ result_value = value.to_s[1..100].to_i
129
+ end
130
+ if self.fields[key].table_field.to_s.include? '.'
131
+ self.attach_to_array self.fields[key].table_field.to_s + ' < ?'
132
+ self.array.push(result_value)
133
+ else
134
+ self.hash[key] = [-Float::INFINITY..result_value]
135
+ end
136
+ return
137
+ end
138
+
139
+ if value.index '-'
140
+ data = value.split '-'
141
+ if data[0].include? '.'
142
+ min_value = data[0].to_f
143
+ else
144
+ min_value = data[0].to_i
145
+ end
146
+ if data[1].include? '.'
147
+ max_value = data[1].to_f
148
+ else
149
+ max_value = data[1].to_i
150
+ end
151
+ min_value, max_value = max_value, min_value if min_value > max_value
152
+ if self.fields[key].table_field.to_s.include? '.'
153
+ self.attach_to_array self.fields[key].table_field.to_s + ' > ? AND ' + self.fields[key].table_field.to_s + ' < ?'
154
+ self.array.push(min_value)
155
+ self.array.push(max_value)
156
+ else
157
+ self.hash[key] = [min_value..max_value]
158
+ end
159
+ return
160
+ end
161
+
162
+ if self.fields[key].table_field.to_s.include? '.'
163
+ self.attach_to_array self.fields[key].table_field.to_s + ' = ?'
164
+ self.array.push(value)
165
+ else
166
+ self.hash[key] = value
167
+ end
168
+ end
169
+
170
+ ##
171
+ # Initializes where parameters for filed with type listbox.
172
+ # @param key [Symbol] Filed identifier
173
+ # @param value [String] Filter parameters
174
+ def init_data_listbox(key, value)
175
+ values = []
176
+ if value.class == Array
177
+ value.each do |data|
178
+ if self.fields[key].options.enum
179
+ values.push self.fields[key].options.enum[data]
180
+ else
181
+ values.push data
182
+ end
183
+ end
184
+ end
185
+ if values.count > 0
186
+ if self.fields[key].table_field.to_s.include? '.'
187
+ self.attach_to_array self.fields[key].table_field.to_s + ' IN (?)'
188
+ self.array.push(values)
189
+ else
190
+ self.hash[self.fields[key].table_field] = values
191
+ end
192
+ end
193
+ end
194
+
195
+ ##
196
+ # Initializes where parameters for filed with type key.
197
+ # @param key [Symbol] Filed identifier
198
+ # @param value [String] Filter parameters
199
+ def init_data_key(key, value)
200
+ words = value.split(' ')
201
+
202
+ words.each do |word|
203
+ self.attach_to_array self.fields[key].table_field.to_s + ' LIKE ?'
204
+ self.array.push("%#{word}%")
205
+ end
206
+ end
207
+
208
+ ##
209
+ # Attach parameters to where
210
+ # @param str [String] attached parameters
211
+ def attach_to_array(str)
212
+ if self.array.count == 0
213
+ self.array.push(str)
214
+ else
215
+ self.array[0] += ' AND ' + str
216
+ end
217
+ end
218
+
219
+ ##
220
+ # Initializes where parameters for filed with type 'datetime'.
221
+ # @param key [Symbol] Filed identifier
222
+ # @param value [String] Filter parameters
223
+ def init_data_datetime(key, value)
224
+ if value.class == Array
225
+ if value.count == 2
226
+ begin
227
+ from = Time.parse value[0]
228
+ to = Time.parse value[1]
229
+ rescue
230
+ from = nil
231
+ to = nil
232
+ end
233
+ if from && to
234
+ self.hash[key] = [ from..to ]
235
+ end
236
+ end
237
+ end
238
+ #words = value.split(' ')
239
+
240
+ # words.each do |word|
241
+ # if self.array.count == 0
242
+ # self.array.push(self.fields[key].table_field.to_s + ' LIKE ?')
243
+ # else
244
+ # self.array[0] += ' AND '+self.fields[key].table_field.to_s+' LIKE ?'
245
+ # end
246
+ # self.array.push("%#{word}%")
247
+ # end
248
+ end
249
+ end
250
+ end
251
+ end
@@ -0,0 +1,101 @@
1
+ module Anubis
2
+ module Etc
3
+ ##
4
+ # Class stores main menu parameters and variables
5
+ class Menu
6
+ # @!attribute [rw] title
7
+ # @return [String] returns title of current menu element
8
+ class_attribute :title, default: ''
9
+
10
+ # @!attribute [rw] page_title
11
+ # @return [String] returns page title of current menu element
12
+ class_attribute :page_title, default: ''
13
+
14
+ # @!attribute [rw] short_title
15
+ # @return [String] returns short title of current menu element
16
+ class_attribute :short_title, default: ''
17
+
18
+ # @!attribute [rw] mode
19
+ # @return [String] returns mode of current menu element
20
+ class_attribute :mode, default: ''
21
+
22
+ # @!attribute [rw] parent_mode
23
+ # @return [String] returns mode of parent menu for current menu element
24
+ class_attribute :parent_mode, default: ''
25
+
26
+ # @!attribute [rw] menu_id
27
+ # @return [Integer] returns id of current menu element
28
+ class_attribute :menu_id, default: nil
29
+
30
+ # @!attribute [rw] parent_menu_id
31
+ # @return [Integer] returns id of parent menu for current menu element
32
+ class_attribute :parent_menu_id, default: nil
33
+
34
+ # @!attribute [rw] action
35
+ # @return [String] returns action of current menu element
36
+ class_attribute :action, default: ''
37
+
38
+ # @!attribute [rw] tab
39
+ # @return [Integer] returns level of current menu element
40
+ class_attribute :tab, default: 0
41
+
42
+ # @!attribute [rw] position
43
+ # @return [Integer] returns position in level of current menu element
44
+ class_attribute :position, default: 0
45
+
46
+ # @!attribute [rw] state
47
+ # @return [String] returns state of current menu element ('visible', 'hidden')
48
+ class_attribute :state, default: 'visible'
49
+
50
+ # @!attribute [rw] access
51
+ # @return [String] returns access state of current menu element ('read', 'write')
52
+ class_attribute :access, default: 'read'
53
+
54
+ ##
55
+ # Sets default parameters for menu element
56
+ # @param [Hash] options initial menu paramters
57
+ # @option options [String] :title menu title
58
+ # @option options [String] :page_title page title
59
+ # @option options [String] :short_title short page title
60
+ # @option options [String] :mode menu mode
61
+ # @option options [String] :parent_mode parent menu mode
62
+ # @option options [Integer] :menu_id id of menu (if <b>id</b> isn't defined)
63
+ # @option options [Integer] :id id of menu (if <b>menu_id</b> isn't defined)
64
+ # @option options [Integer] :parent_menu_id id of parent menu
65
+ # @option options [String] :action menu action
66
+ # @option options [Integer] :tab menu tab index
67
+ # @option options [Integer] :position position in current level
68
+ # @option options [String] :state state of the menu ('visible', 'hidden')
69
+ # @option options [String] :access access state of the menu ('read', 'write')
70
+ def initialize(options = {})
71
+ if options.class == Hash
72
+ self.title = options[:title] if options.has_key? :title
73
+ self.page_title = options[:page_title] if options.has_key? :page_title
74
+ self.short_title = options[:short_title] if options.has_key? :short_title
75
+ self.mode = options[:mode] if options.has_key? :mode
76
+ self.parent_mode = options[:parent_mode] if options.has_key? :parent_mode
77
+ self.menu_id = options[:menu_id] if options.has_key? :menu_id
78
+ self.menu_id = options[:id] if options.has_key? :id
79
+ self.parent_menu_id = options[:parent_menu_id] if options.has_key? :parent_menu_id
80
+ self.action = options[:action] if options.has_key? :action
81
+ self.tab = options[:tab] if options.has_key? :tab
82
+ self.position = options[:position] if options.has_key? :position
83
+ self.state = options[:state] if options.has_key? :state
84
+ self.access = options[:access] if options.has_key? :access
85
+ end
86
+ if options.class == Anubis::Sso::Client::Menu
87
+ self.title = options.title
88
+ self.page_title = options.page_title
89
+ self.short_title = options.short_title
90
+ self.mode = options.mode
91
+ self.menu_id = options.id
92
+ self.parent_menu_id = options.menu_id
93
+ self.action = options.action
94
+ self.tab = options.tab
95
+ self.position = options.position
96
+ self.state = options.state
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,67 @@
1
+ module Anubis
2
+ module Etc
3
+ ##
4
+ # Definitions of model options. Class is used for define attached model.
5
+ class Model
6
+ # @!attribute [rw]
7
+ # Defines model class. This field is required.
8
+ # @return [ActiveRecord] model's class.
9
+ class_attribute :model, default: nil
10
+
11
+ # @!attribute [rw]
12
+ # Field name is used for defines title when data selected from model.
13
+ # @return [Symbol] field's name
14
+ class_attribute :title, default: :title
15
+
16
+ # @!attribute [rw]
17
+ # Field name is used for defines order field when data selected from model. By default uses field daefined as
18
+ # (#title)
19
+ # @return [Boolean] field's name
20
+ class_attribute :order, default: :title
21
+
22
+ # @!attribute [rw]
23
+ # Where parameters are used when data selected from model.
24
+ # @return [Hash] hash of where's parameters
25
+ class_attribute :where, default: {}
26
+
27
+ # @!attribute [rw]
28
+ # Special select parameters.
29
+ # @return [String] string of special select or nil
30
+ class_attribute :select, default: nil
31
+
32
+ # @!attribute [rw]
33
+ # Timestamp of last changes in the model.
34
+ # @return [Number] timestamp of last changes in model.
35
+ class_attribute :updated_at, default: {}
36
+
37
+ ##
38
+ # Sets default parameters for field
39
+ # @param [Hash] options initial model options
40
+ # @option options [ActiveRecord] :model model class
41
+ # @option options [Symbol] :title field name is used for receive options titles
42
+ # @option options [Symbol] :order field name is used for order options
43
+ # @option options [Hash] :where where parameters for select data from model
44
+ def initialize(options = {})
45
+ self.model = options[:model]
46
+ self.title = if options.key? :title then options[:title] else :title end
47
+ self.order = if options.key? :order then options[:order] else self.title end
48
+ self.where = if options.key? :where then options[:where] else {} end
49
+ self.select = if options.key? :select then options[:select] else nil end
50
+ self.updated_at = 0
51
+ end
52
+
53
+ ##
54
+ # Generates hash representation of all class parameters,
55
+ # @return [Hash] hash representation of all data
56
+ def to_h
57
+ {
58
+ model: self.model,
59
+ title: self.title,
60
+ order: self.order,
61
+ where: self.where,
62
+ updated_at: self.updated_at
63
+ }
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,91 @@
1
+ module Anubis
2
+ module Etc
3
+ ##
4
+ # Definitions of tab options.
5
+ class TabItem
6
+ # @!attribute [rw]
7
+ # Returns tab identifier
8
+ # @return [String] tab's identifier.
9
+ class_attribute :tab, default: nil
10
+
11
+ # @!attribute [rw]
12
+ # Returns tab title
13
+ # @return [String] tab's title.
14
+ class_attribute :title, default: ''
15
+
16
+ # @!attribute [rw]
17
+ # Returns tab hint
18
+ # @return [String] tab's hint.
19
+ class_attribute :hint, default: ''
20
+
21
+ # @!attribute [rw]
22
+ # Returns tab where for selection from model.
23
+ # @return [Hash|Array] tab's where
24
+ class_attribute :where, default: []
25
+
26
+ # @!attribute [rw]
27
+ # Returns possibility for export data for this tab <i>(default: true)</i>
28
+ # @return [Boolean] tab's export possibility
29
+ class_attribute :export, default: true
30
+
31
+ # @!attribute [rw]
32
+ # Returns possibility for filter data for this tab <i>(default: true)</i>
33
+ # @return [Boolean] tab's filter possibility
34
+ class_attribute :filter, default: true
35
+
36
+ # @!attribute [rw]
37
+ # Returns possibility for filter data for this tab <i>(default: true)</i>
38
+ # @return [Hash] tab's filter possibility
39
+ class_attribute :buttons, default: {}
40
+
41
+ # @!attribute [rw]
42
+ # Returns order field for this tab <i>(default: nil)</i>
43
+ # @return [String] tab's order field
44
+ class_attribute :sort, default: nil
45
+
46
+ # @!attribute [rw]
47
+ # Returns order type for this tab ('asc' or 'desc') <i>(default: nil)</i>
48
+ # @return [String] tab's order type
49
+ class_attribute :order, default: nil
50
+
51
+ ##
52
+ # Sets default parameters for tab
53
+ # @param options [String] initial tab options
54
+ # @option options [String] :tab tab identifier
55
+ def initialize(options = {})
56
+ self.tab = if options.key?(:tab) then options[:tab] else nil end
57
+ self.sort = if options.key?(:sort) then options[:sort] else nil end
58
+ self.order = ''
59
+ if options.key? :order
60
+ self.order = options[:order] if %w[asc desc].include?(options[:order])
61
+ end
62
+ self.title = if options.key?(:title) then options[:title] else self.tab.humanize end
63
+ self.hint = if options.key?(:hint) then options[:hint] else '' end
64
+ self.where = if options.key?(:where) then options[:where] else [] end
65
+ self.export = if options.key?(:export) then options[:export] else true end
66
+ self.filter = if options.key?(:filter) then options[:filter] else true end
67
+ self.buttons = if options.key?(:buttons) then options[:buttons] else true end
68
+ end
69
+
70
+ ##
71
+ # Generates hash representation of all class parameters,
72
+ # @return [Hash] hash representation of all parameters
73
+ def to_h
74
+ result = {
75
+ tab: self.tab,
76
+ title: self.title,
77
+ hint: self.hint,
78
+ where: self.where,
79
+ export: self.export,
80
+ filter: self.filter,
81
+ buttons: self.buttons
82
+ }
83
+ if self.sort
84
+ result[:sort] = self.sort
85
+ result[:order] = self.order if self.order != ''
86
+ end
87
+ result
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,8 @@
1
+ module Anubis
2
+ ##
3
+ # Module stores systems variables and functions. Module consists of {Base}, {Data}, {Field}, {FieldOptions},
4
+ # {Menu}, {Model} and {TabItem} classes.
5
+ module Etc
6
+
7
+ end
8
+ end
@@ -0,0 +1,47 @@
1
+ module Anubis
2
+ class Export
3
+ class_attribute :data
4
+ class_attribute :title
5
+ class_attribute :format
6
+ class_attribute :fields
7
+
8
+ def initialize(options = {})
9
+ self.data = []
10
+ self.title = []
11
+ options[:format] = 'xls' if !options.key? :format
12
+ self.format = options[:format]
13
+ self.fields = if options.key?(:fields) then options[:fields] else nil end
14
+ if self.fields
15
+ self.fields.each do |field|
16
+ self.title.push field[:title]
17
+ end
18
+ end
19
+ end
20
+
21
+ def add (data)
22
+ data.each do |dat|
23
+ new_data = []
24
+ self.fields.each do |field|
25
+ if dat.key? field[:id].to_sym
26
+ new_data.push dat[field[:id].to_sym]
27
+ else
28
+ new_data.push ''
29
+ end
30
+ end
31
+ #new_data = dat.except :actions, :sys_title
32
+ self.data.push(new_data)
33
+ end
34
+ end
35
+
36
+ def to_h
37
+ {
38
+ data: self.data,
39
+ title: self.title,
40
+ fields: self.fields,
41
+ format: self.format
42
+ }
43
+ end
44
+
45
+ public :format
46
+ end
47
+ end
@@ -0,0 +1,30 @@
1
+ module Anubis
2
+ module Output
3
+ ##
4
+ # Output subclass that represents data for edit(new) action
5
+ class Autocomplete < Basic
6
+ # @!attribute [rw]
7
+ # @return [Hash] the hash of defined fields.
8
+ class_attribute :values, default: {}
9
+
10
+ ##
11
+ # Initializes menu output data. Generates default values.
12
+ def initialize
13
+ super
14
+ self.values = []
15
+ end
16
+
17
+ ##
18
+ # Generates hash representation of output class
19
+ # @return [Hash] hash representation of all data
20
+ def to_h
21
+ result = super.to_h
22
+ return result if self.result != 0
23
+ result.merge!({
24
+ values: self.values,
25
+ })
26
+ result
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,86 @@
1
+ module Anubis
2
+ ##
3
+ # Module contains all procedures and function for output data. Module consists from {Basic}, {Frame}, {Login} and
4
+ # {Menu} classes.
5
+ module Output
6
+ ##
7
+ # Output subclass that represents parametrs for basic requests
8
+ class Basic
9
+ # @!attribute [rw] title
10
+ # @return [string] the page title of current loaded frame.
11
+ class_attribute :title
12
+
13
+ # @!attribute [rw]
14
+ # @return [Hash<string>] hash of messages
15
+ class_attribute :messages
16
+
17
+ # @!attribute [rw]
18
+ # @return [Number] controller action output result code.
19
+ # @note Zero value means successful. Negative value means error.
20
+ class_attribute :result, default: 0
21
+
22
+ # @!attribute [rw]
23
+ # @return [String] current returned tab
24
+ class_attribute :tab, default: ''
25
+
26
+ ##
27
+ # Output class initialization. Sets default class parameters.
28
+ def initialize
29
+ self.title = nil
30
+ self.result = 0
31
+ self.tab = ''
32
+ self.messages = {
33
+ '0': I18n.t('success'),
34
+ '-1': I18n.t('errors.access_not_allowed'),
35
+ '-2': I18n.t('errors.incorrect_parameters')
36
+ }
37
+ end
38
+
39
+ ##
40
+ # Generates hash representation of output class
41
+ # @return [Hash] hash representation of all class data
42
+ def to_h
43
+ result = {
44
+ result: self.result,
45
+ timestamp: Time.now.to_i,
46
+ message: message
47
+ }
48
+ result[:title] = self.title if self.title
49
+ result[:tab] = self.tab if self.tab != ''
50
+ result
51
+ end
52
+
53
+ ##
54
+ # Generates output message based on result variable.
55
+ # @return [String] output message
56
+ def message
57
+ return messages[result.to_s.to_sym] if messages.key? result.to_s.to_sym
58
+ I18n.t('errors.internal_error')
59
+ end
60
+
61
+ ##
62
+ # Convert hash to array json output
63
+ # @param hash [Hash] hash representation
64
+ # @return [Array] array representation
65
+ def hash_to_json(hash)
66
+ result = []
67
+ hash.each_key do |key|
68
+ result.push({ key: key.to_s, value: hash[key] })
69
+ end
70
+ result
71
+ end
72
+
73
+ ##
74
+ # Convert options hash to array json output
75
+ # @param options [Hash<Hash>] options with hash representation
76
+ # @return [Hash<Array>] options with array representation
77
+ def options_to_json(options)
78
+ result = {}
79
+ options.each_key do |key|
80
+ result[key] = self.hash_to_json(options[key])
81
+ end
82
+ result
83
+ end
84
+ end
85
+ end
86
+ end