Module: Anoubis::Data::Defaults
- Included in:
- Anoubis::DataController
- Defined in:
- app/controllers/anoubis/data/defaults.rb
Overview
Module sets default parameters for Anoubis::DataController.
Block of default controller table actions collapse
-
#table_action_delete(row) ⇒ Object
Returns possibility of ‘delete’ action for current row.
-
#table_action_edit(row) ⇒ Object
Returns possibility of ‘edit’ action for current row.
-
#table_actions ⇒ Array
Sets default table actions for every row.
-
#where ⇒ Hash, Array
Returns default where condition.
Instance Method Summary collapse
-
#eager_load ⇒ Object
Returns eager load parameters that are used for controller actions.
-
#export_format ⇒ Object
Returns export format for current action.
-
#fields ⇒ Hash
Returns fields that is used for controller actions in defined #model.
-
#fields_order ⇒ Object
Get array of field’s identifiers in desired order.
-
#filter_order ⇒ Object
Get array of field’s identifiers in desired order for filter form.
-
#frame_buttons(args = {}) ⇒ Hash
Sets frame buttons for every using tab.
-
#is_export(args = {}) ⇒ Boolean
Returns export possibility for defined options.
-
#is_filter(args = {}) ⇒ Boolean
Returns filter possibility for defined options.
-
#is_sortable ⇒ String
Returns field name for manual table order or nil if table can’t be sorted manually.
-
#model ⇒ Anoubis::ApplicationRecord, ...
Returns model that is used for controller actions.
-
#parent_eager_load ⇒ Object
Returns eager load parameters for parent model that are used for controller actions.
-
#parent_id ⇒ Object
Returns parent model id.
-
#parent_model ⇒ Anoubis::ApplicationRecord?
Returns parent model that is used for controller actions.
-
#select ⇒ Object
Returns defined select fields.
-
#tabs ⇒ Hash
Sets hash of defined tabs.
Instance Method Details
#eager_load ⇒ Object
Returns eager load parameters that are used for controller actions. By default it’s set to []. This procedure could be redefined in cusomer controller. Different eager loads may be defined according by self.etc.action attribute.
95 96 97 |
# File 'app/controllers/anoubis/data/defaults.rb', line 95 def eager_load [] end |
#export_format ⇒ Object
Returns export format for current action. Procedure is rewrote for change default export format.
185 186 187 |
# File 'app/controllers/anoubis/data/defaults.rb', line 185 def export_format 'xls' end |
#fields ⇒ Hash
Returns fields that is used for controller actions in defined #model. By default it’s defined for id field. This is primary definition and it must be defined in customer conroller. Different fields may be defined according by self.etc.action attribute.
104 105 106 107 108 |
# File 'app/controllers/anoubis/data/defaults.rb', line 104 def fields { id: { type: 'number', precision: 0 } } end |
#fields_order ⇒ Object
Get array of field’s identifiers in desired order. By default it’s current defined order of all fields.
112 113 114 115 116 117 118 |
# File 'app/controllers/anoubis/data/defaults.rb', line 112 def fields_order result = [] self.etc.data.fields.each_key do |key| result.push key.to_s end result end |
#filter_order ⇒ Object
Get array of field’s identifiers in desired order for filter form. By default it’s current defined order of all fields.
122 123 124 |
# File 'app/controllers/anoubis/data/defaults.rb', line 122 def filter_order self.fields_order end |
#frame_buttons(args = {}) ⇒ Hash
Sets frame buttons for every using tab. Key of the button is an action for frontend application. Every button consists of next attributes:
Attributes:
-
:type (String) (defaults to: ‘default’) — type of the button (‘primary’, ‘danger’, ‘default’)
-
:mode (String) (defaults to: ‘single’) — button action object (‘single’, ‘multiple’)
By default system defines two buttons: ‘New’ (for create new element in table) and ‘Delete’ (for delete multiple element)
69 70 71 72 73 74 |
# File 'app/controllers/anoubis/data/defaults.rb', line 69 def (args = {}) { new: { type: 'primary' }, delete: { mode: 'multiple', type: 'danger' } } end |
#is_export(args = {}) ⇒ Boolean
Returns export possibility for defined options. It’s rewrote for custom controllers.
203 204 205 |
# File 'app/controllers/anoubis/data/defaults.rb', line 203 def is_export(args = {}) true end |
#is_filter(args = {}) ⇒ Boolean
Returns filter possibility for defined options. It’s rewrote for custom controllers.
194 195 196 |
# File 'app/controllers/anoubis/data/defaults.rb', line 194 def is_filter(args = {}) true end |
#is_sortable ⇒ String
Returns field name for manual table order or nil if table can’t be sorted manually.
210 211 212 |
# File 'app/controllers/anoubis/data/defaults.rb', line 210 def is_sortable nil end |
#model ⇒ Anoubis::ApplicationRecord, ...
Returns model that is used for controller actions. By default it’s not defined. This is primary model and it must be defined in customer conroller. Different models may be defined according by self.etc.action attribute.
81 82 83 |
# File 'app/controllers/anoubis/data/defaults.rb', line 81 def model nil end |
#parent_eager_load ⇒ Object
Returns eager load parameters for parent model that are used for controller actions. By default it’s set to []. This procedure could be redefined in customer controller. Different eager loads may be defined according by self.etc.action attribute.
139 140 141 |
# File 'app/controllers/anoubis/data/defaults.rb', line 139 def parent_eager_load [] end |
#parent_id ⇒ Object
Returns parent model id. By default it’s set to 0. This procedure could be rewrote in customer controller.
146 147 148 |
# File 'app/controllers/anoubis/data/defaults.rb', line 146 def parent_id return 0 end |
#parent_model ⇒ Anoubis::ApplicationRecord?
Returns parent model that is used for controller actions. By default it’s defined as nil. This procedure could be redefined in customer controller. Different models may be defined according by self.etc.action attribute.
131 132 133 |
# File 'app/controllers/anoubis/data/defaults.rb', line 131 def parent_model nil end |
#select ⇒ Object
Returns defined select fields. If returns nil, then return default select fields
87 88 89 |
# File 'app/controllers/anoubis/data/defaults.rb', line 87 def select nil end |
#table_action_delete(row) ⇒ Object
Returns possibility of ‘delete’ action for current row
170 171 172 |
# File 'app/controllers/anoubis/data/defaults.rb', line 170 def table_action_delete(row) row.can_delete({ controller: params[:controller], tab: self.etc.tab }) end |
#table_action_edit(row) ⇒ Object
Returns possibility of ‘edit’ action for current row
163 164 165 |
# File 'app/controllers/anoubis/data/defaults.rb', line 163 def table_action_edit(row) row.can_edit({ controller: params[:controller], tab: self.etc.tab }) end |
#table_actions ⇒ Array
Sets default table actions for every row
156 157 158 |
# File 'app/controllers/anoubis/data/defaults.rb', line 156 def table_actions %w[edit delete] end |
#tabs ⇒ Hash
Sets hash of defined tabs. Every tab consists of next attributes:
Attributes:
-
:title (String) — title of the tab
-
:where (Hash | Array) — hash or array of where parameters for ActiveRecord request. If doesn’t present then there are no additional where statements for current tab
32 33 34 35 36 37 38 39 |
# File 'app/controllers/anoubis/data/defaults.rb', line 32 def tabs { :default => { title: I18n.t('anoubis.default_tab'), tips: I18n.t('anoubis.default_tab_hint') } } end |
#where ⇒ Hash, Array
Returns default where condition
177 178 179 |
# File 'app/controllers/anoubis/data/defaults.rb', line 177 def where [] end |