Module: Anubis::Core::Data::Defaults
- Defined in:
- app/controllers/anoubis/core/data/defaults.rb
Overview
Module sets default parameters for Anubis::Core::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 ⇒ Anubis::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 ⇒ Anubis::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.
96 97 98 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 96 def eager_load [] end |
#export_format ⇒ Object
Returns export format for current action. Procedure is rewrote for change default export format.
186 187 188 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 186 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.
105 106 107 108 109 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 105 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.
113 114 115 116 117 118 119 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 113 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.
123 124 125 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 123 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)
70 71 72 73 74 75 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 70 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.
204 205 206 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 204 def is_export(args = {}) true end |
#is_filter(args = {}) ⇒ Boolean
Returns filter possibility for defined options. It's rewrote for custom controllers.
195 196 197 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 195 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.
211 212 213 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 211 def is_sortable nil end |
#model ⇒ Anubis::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.
82 83 84 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 82 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.
140 141 142 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 140 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.
147 148 149 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 147 def parent_id return 0 end |
#parent_model ⇒ Anubis::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.
132 133 134 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 132 def parent_model nil end |
#select ⇒ Object
Returns defined select fields. If returns nil, then return default select fields
88 89 90 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 88 def select nil end |
#table_action_delete(row) ⇒ Object
Returns possibility of 'delete' action for current row
171 172 173 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 171 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
164 165 166 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 164 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
157 158 159 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 157 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
33 34 35 36 37 38 39 40 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 33 def tabs { :default => { title: I18n.t('anubis.default_tab'), tips: I18n.t('anubis.default_tab_hint') } } end |
#where ⇒ Hash, Array
Returns default where condition
178 179 180 |
# File 'app/controllers/anoubis/core/data/defaults.rb', line 178 def where [] end |