anoubis 1.0.0

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 (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,104 @@
1
+ module Anubis
2
+ ##
3
+ # Module consists all procedures and functons of {DataController}
4
+ module Core
5
+ module Data
6
+ ##
7
+ # Module setups system parameters for {DataController}
8
+ module Setup
9
+ ##
10
+ # Setups frame data information. It loads menu data, sets titles and tabs of the frame.
11
+ def setup_frame
12
+ self.load_menu_data
13
+ if self.etc.menu
14
+ self.get_parent_data
15
+ if self.etc.data.parent
16
+ self.output.title = self.etc.menu.page_title.sub '%{title}', self.etc.data.parent.sys_title.to_s
17
+ else
18
+ self.output.title = self.etc.menu.page_title
19
+ end
20
+ self.output.short = self.etc.menu.short_title
21
+ self.output.mode = self.etc.menu.mode
22
+ self.output.access = self.etc.menu.access
23
+ end
24
+ tabs = self.tabs
25
+ tabs.each do |key, item|
26
+ item = self.get_tab key, item
27
+ self.output.addTab(item)
28
+ end
29
+ end
30
+
31
+ ##
32
+ # Setups order for current tab. Parameters is set into {Anubis::Etc::TabItem#sort self.etc.tab.sort} and
33
+ # {Anubis::Etc::TabItem#order self.etc.tab.order} attributes.
34
+ def setup_order
35
+ sort = nil
36
+ first = nil
37
+ self.etc.data.fields.each do |key, field|
38
+ if field.order
39
+ first = key if !first
40
+ first = key if field.order.default
41
+ if params.key? :sort
42
+ sort = key if params[:sort] == key.to_s
43
+ end
44
+ end
45
+ end
46
+ sort = first if !sort
47
+ if sort
48
+ self.etc.tab.sort = sort.to_s
49
+ self.etc.tab.order = self.etc.data.fields[sort].order.order
50
+ if params.key? :order
51
+ self.etc.tab.order = :desc if params[:order] == 'desc'
52
+ self.etc.tab.order = :asc if params[:order] == 'asc'
53
+ end
54
+ end
55
+ end
56
+
57
+ ##
58
+ # @!group Block of fields setup functions
59
+
60
+ ##
61
+ # Setups defined fields and places it into attribute {Anubis::Etc::Data#fields self.etc.data.fields}
62
+ def setup_fields
63
+ if !self.etc.data.fields
64
+ self.etc.data.fields = {}
65
+
66
+ fields = self.fields
67
+
68
+ fields.each_key do |key|
69
+ if fields[key].key? :edit
70
+ if self.menu_access fields[key][:edit], false
71
+ fields[key][:editable] = fields[key][:edit]
72
+ end
73
+ end
74
+ self.etc.data.fields[key] = Anubis::Etc::Field.new(key, self.get_model, fields[key].merge(action: self.etc.action))
75
+ end
76
+ self.setup_order if %w[index export].include? self.etc.action
77
+ end
78
+ end
79
+
80
+ ##
81
+ # Setups additional parameters for table field with type 'datetime'
82
+ # Resulting data placed in {Etc::Data#fields self.etc.data.fields} (Hash)
83
+ # @param key [Symbol] key of table field.
84
+ def setup_fields_datetime (key)
85
+ self.etc.data.fields[key][:format] = 'full' if !self.etc.data.fields[key].has_key? :format
86
+ self.etc.data.fields[key][:format] = 'full' if !['full', 'month', 'date', 'datetime'].include? self.etc.data.fields[key][:format]
87
+ end
88
+
89
+
90
+
91
+ ##
92
+ # Setups additional parameters for table field with type 'float'
93
+ # Resulting data placed in {Etc::Data#fields self.etc.data.fields} (Hash)
94
+ # @param key [Symbol] key of table field.
95
+ def setup_fields_float (key)
96
+ self.etc.data.fields[key][:precision] = 2 if !self.etc.data.fields[key][:precision]
97
+ self.etc.data.fields[key][:point] = ',' if !self.etc.data.fields[key][:point]
98
+ self.etc.data.fields[key][:separator] = '' if !self.etc.data.fields[key][:separator]
99
+ end
100
+ # @!endgroup
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,28 @@
1
+ require_dependency "anubis/core/application_controller"
2
+ require_dependency "anubis/core/data/actions"
3
+ require_dependency "anubis/core/data/load"
4
+ require_dependency "anubis/core/data/get"
5
+ require_dependency "anubis/core/data/set"
6
+ require_dependency "anubis/core/data/setup"
7
+ require_dependency "anubis/core/data/defaults"
8
+ require_dependency "anubis/core/data/convert"
9
+ require_dependency "anubis/core/data/callbacks"
10
+
11
+ module Anubis
12
+ ##
13
+ # Module presents all core functions for Anubis Library
14
+ module Core
15
+ ##
16
+ # Controller consists all procedures and function for presents and modify models data.
17
+ class DataController < Anubis::Core::ApplicationController
18
+ include Anubis::Core::Data::Actions
19
+ include Anubis::Core::Data::Load
20
+ include Anubis::Core::Data::Get
21
+ include Anubis::Core::Data::Set
22
+ include Anubis::Core::Data::Setup
23
+ include Anubis::Core::Data::Defaults
24
+ include Anubis::Core::Data::Convert
25
+ include Anubis::Core::Data::Callbacks
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,53 @@
1
+ require_dependency "anubis/output/login"
2
+
3
+ module Anubis
4
+ module Core
5
+ ##
6
+ # Module contains all procedures and function for {IndexController}. Consists of {Actions} and {Callbacks} module.
7
+ module Index
8
+ ##
9
+ # Module contains all basic actions for {IndexController}.
10
+ module Actions
11
+ ##
12
+ # <i>Logout</i> action of index controller. Procedure logouts user out of the system and deletes active sessions.
13
+ # Authorization bearer is required. Procedure no need additional parameters.
14
+ #
15
+ # <b>API request:</b>
16
+ # POST /api/<version>/logout
17
+ # <b>Request Header:</b>
18
+ # {
19
+ # "Authorization": "Bearer <Session token>"
20
+ # }
21
+ # <b>Request example:</b>
22
+ # curl --header "Content-Type: application/json" -header 'Authorization: Bearer <session-token>' http://<server>:<port>/api/<api-version>/logout
23
+ #
24
+ # <b>Results:</b><br>
25
+ #
26
+ # Resulting data returns in JSON format.
27
+ #
28
+ # <b>Examples:</b>
29
+ #
30
+ # <b>Success:</b> HTTP response code 200
31
+ # {
32
+ # "result": 0,
33
+ # "message": "Successful"
34
+ # }
35
+ #
36
+ # <b>Error:</b> HTTP response code 422
37
+ # {
38
+ # "result": -1,
39
+ # "message": "Session expired"
40
+ # }
41
+ def logout
42
+ self.output = Anubis::Output::Basic.new
43
+ self.redis.del(self.redis_prefix + 'ses_'+self.token)
44
+ respond_to do |format|
45
+ format.json { render json: self.output.to_h }
46
+ end
47
+ end
48
+
49
+
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,23 @@
1
+ module Anubis
2
+ module Core
3
+ ##
4
+ # Module contains all procedures and function for {IndexController}. Consists of {Actions} and {Callbacks} module.
5
+ module Index
6
+ ##
7
+ # Module contains all callbacks {IndexController}.
8
+ module Callbacks
9
+ ##
10
+ # Calls before menu output data.
11
+ def before_menu_output
12
+
13
+ end
14
+
15
+ ##
16
+ # Calls when menu data is being output
17
+ def around_menu_output(data)
18
+ data
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ require_dependency "anubis/core/application_controller"
2
+ require_dependency "anubis/core/index/actions"
3
+ require_dependency "anubis/core/index/callbacks"
4
+
5
+ module Anubis
6
+ module Core
7
+ ##
8
+ # Controller processes main system functions. Authenticates user, checks user access, outputs main menu and etc.
9
+ class IndexController < Anubis::Core::ApplicationController
10
+ include Anubis::Core::Index::Actions
11
+ include Anubis::Core::Index::Callbacks
12
+
13
+ ##
14
+ # Check if authentication required
15
+ def authenticate?
16
+ if controller_name == 'index'
17
+ if action_name == 'login'
18
+ return false
19
+ end
20
+ end
21
+ return true
22
+ end
23
+
24
+ ##
25
+ # Check if authentication required
26
+ def check_menu_access?
27
+ if controller_name == 'index'
28
+ if action_name == 'login' || action_name == 'menu' || action_name == 'logout'
29
+ return false
30
+ end
31
+ end
32
+ return true
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,52 @@
1
+ module Anubis
2
+ module Etc
3
+ ##
4
+ # Basic system variables class
5
+ class Base
6
+ # @!attribute [rw]
7
+ # @return [Data, nil] current loaded data or nil if data not loaded.
8
+ # @note In this attribute placed data when loaded from the model by actions 'table', 'edit', 'update', 'create' etc.
9
+ class_attribute :data
10
+
11
+ # @!attribute [rw]
12
+ # @return [Menu, nil] menu information for current controller
13
+ # Returns menu information for current controller. By default sets to <i>nil</i>.
14
+ class_attribute :menu, default: nil
15
+
16
+ # @!attribute [rw]
17
+ # @return [TabItem, nil] tab information for current controller
18
+ # Returns tab information for current controller. By default sets to <i>nil</i>.
19
+ class_attribute :tab, default: nil
20
+
21
+ # @!attribute [rw]
22
+ # @return [String] current controller action.
23
+ # Returns current controller action. By default sets to controller action or ''.
24
+ class_attribute :action, default: ''
25
+
26
+ # @!attribute [rw]
27
+ # @return [Number] time of request.
28
+ # Returns time that was requested from client. By default sets to <i>0</i>.
29
+ class_attribute :time, default: 0
30
+
31
+ ##
32
+ # Sets default system parameters
33
+ # @param [Hash] options initial class options
34
+ # @option options [ActionController::Parameters] :params initial controller parameters
35
+ def initialize(options = {})
36
+ self.data = nil
37
+ self.menu = nil
38
+ self.tab = nil
39
+ self.action = ''
40
+
41
+ if options.key? :params
42
+ self.action = options[:params][:action] if options[:params].key? :action
43
+ if options[:params].key? :time
44
+ self.time = options[:params][:time].to_s.to_i
45
+ else
46
+ self.time = 0
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,89 @@
1
+ module Anubis
2
+ module Etc
3
+ ##
4
+ # Class stores data information for current controller
5
+ class Data
6
+ # @!attribute [rw] data
7
+ # @return [ActiveRecord, nil] current loaded data from the defined model or nil if data not loaded.
8
+ # @note Data is placed in this attribute when loaded from the model by actions 'index', 'edit', 'update', 'create' etc.
9
+ class_attribute :data
10
+
11
+ # @!attribute [rw] fields
12
+ # @return [Hash<Symbol, Field>, nil] current defined hash of model represented fields or nil if fields aren't defined
13
+ # @note Field's options are placed in this attribute for actions 'index', 'edit', 'update', 'create' etc.
14
+ class_attribute :fields, default: nil
15
+
16
+ # @!attribute [rw] actions
17
+ # @return [Array, nil] current defined string array of table actions.
18
+ class_attribute :actions, default: nil
19
+
20
+ #@!attribute [rw] parent
21
+ # @return [ActiveRecord] <i>(defaults to: nil)</i> Specify the parent ActiveRecord for controller (if exists)
22
+ class_attribute :parent, default: nil
23
+
24
+ #@!attribute [rw] model
25
+ # @return [ActiveRecord] <i>(defaults to: nil)</i> Specify the current ActiveRecord for controller (if exists)
26
+ class_attribute :model, default: nil
27
+
28
+ #@!attribute [rw] eager_load
29
+ # @return [Array] <i>(defaults to: [])</i> Specify the current eager loaded models
30
+ class_attribute :eager_load, default: []
31
+
32
+ #@!attribute [rw] limit
33
+ # @return [Integer] <i>(defaults to: 10)</i> Specify the total number of returned rows
34
+ class_attribute :limit, default: 10
35
+
36
+ #@!attribute [rw] offset
37
+ # @return [Integer] <i>(defaults to: 0)</i> Specify the default offset for rows were returned
38
+ class_attribute :offset, default: 0
39
+
40
+ #@!attribute [rw] count
41
+ # @return [Integer] <i>(defaults to: 0)</i> Specify the count of rows for defined data model
42
+ class_attribute :count, default: 0
43
+
44
+ #@!attribute [rw]
45
+ class_attribute :filter, default: nil
46
+
47
+ ##
48
+ # Sets default basic system parameters
49
+ def initialize(options = {})
50
+ self.data = nil
51
+ self.fields = nil
52
+ self.actions = nil
53
+ self.parent = nil
54
+ self.model = nil
55
+ self.count = 0
56
+ self.eager_load = []
57
+ self.limit = 10
58
+ self.offset = 0
59
+ self.filter = nil
60
+ end
61
+
62
+ def limit=(value)
63
+ value = value.to_s.to_i
64
+ value = 10 if value < 1
65
+ @limit = value
66
+ end
67
+
68
+ def offset=(value)
69
+ value = value.to_s.to_i
70
+ value = 0 if value < 0
71
+ value = 0 if value > self.count
72
+ @offset = value
73
+ end
74
+
75
+ def to_h
76
+ {
77
+ fields: self.fields,
78
+ model: self.model,
79
+ eager_load: self.eager_load,
80
+ count: self.count,
81
+ limit: self.limit,
82
+ offset: self.offset,
83
+ actions: self.actions,
84
+ parent: self.parent
85
+ }
86
+ end
87
+ end
88
+ end
89
+ end