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

Instance Method Summary collapse

Instance Method Details

#eager_loadObject

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_formatObject

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

#fieldsHash

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.

Returns:

  • (Hash)

    returns defined fields for current model



104
105
106
107
108
# File 'app/controllers/anoubis/data/defaults.rb', line 104

def fields
  {
    id: { type: 'number', precision: 0 }
  }
end

#fields_orderObject

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_orderObject

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)

Examples:

Sets no buttons

def frame_buttons(args = {})
  {
  }
end

Sets only ‘New’ button

def frame_buttons(args = {})
  {
      new: { type: 'primary' }
  }
end

Parameters:

  • args (Hash) (defaults to: {})

    additional parameters are used for define frame buttons.

Options Hash (args):

  • :tab (String)

    current tab is used for generation

Returns:

  • (Hash)

    returns hash of assigned buttons.



69
70
71
72
73
74
# File 'app/controllers/anoubis/data/defaults.rb', line 69

def frame_buttons(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.

Parameters:

  • args (Hash) (defaults to: {})

    additional parameters.

Options Hash (args):

  • :tab (String)

    current tab is used for generation

Returns:

  • (Boolean)

    Possibility of export table data. Default: true



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.

Parameters:

  • args (Hash) (defaults to: {})

    additional parameters.

Options Hash (args):

  • :tab (String)

    current tab is used for generation

Returns:

  • (Boolean)

    Possibility of filter table data. Default: true



194
195
196
# File 'app/controllers/anoubis/data/defaults.rb', line 194

def is_filter(args = {})
  true
end

#is_sortableString

Returns field name for manual table order or nil if table can’t be sorted manually.

Returns:

  • (String)

    Field name for manual table order



210
211
212
# File 'app/controllers/anoubis/data/defaults.rb', line 210

def is_sortable
  nil
end

#modelAnoubis::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.

Returns:



81
82
83
# File 'app/controllers/anoubis/data/defaults.rb', line 81

def model
  nil
end

#parent_eager_loadObject

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_idObject

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_modelAnoubis::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.

Returns:



131
132
133
# File 'app/controllers/anoubis/data/defaults.rb', line 131

def parent_model
  nil
end

#selectObject

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

Parameters:

  • row (ActiveRecord)

    single model’s data 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

Parameters:

  • row (ActiveRecord)

    single model’s data 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_actionsArray

Sets default table actions for every row

Returns:

  • (Array)

    return string array of action identifiers



156
157
158
# File 'app/controllers/anoubis/data/defaults.rb', line 156

def table_actions
  %w[edit delete]
end

#tabsHash

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

Examples:

Sets custom tabs

def tabs
  {
      :all => {
          title: 'All IDs'
      },
      :id_1 => {
          title: 'Only ID 1',
          where: { id: 1 }
      },
      :other_id => {
          title: 'Other IDs',
          where: ['id > ?', 1]
      }
  }
end

Returns:

  • (Hash)

    returns hash of assigned tabs.



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

#whereHash, Array

Returns default where condition

Returns:

  • (Hash, Array)

    default where condition



177
178
179
# File 'app/controllers/anoubis/data/defaults.rb', line 177

def where
  []
end