Module: Anubis::Core::Data::Defaults

Included in:
Anubis::Core::DataController, Sso::Client::Data::Defaults, Tenant::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

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.



96
97
98
# File 'app/controllers/anoubis/core/data/defaults.rb', line 96

def eager_load
  []
end

#export_formatObject

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

#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



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

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.



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_orderObject

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)

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.



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

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



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.

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



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

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



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

def is_sortable
  nil
end

#modelAnubis::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:

  • (Anubis::ApplicationRecord, nil, any)

    returns model



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

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.



140
141
142
# File 'app/controllers/anoubis/core/data/defaults.rb', line 140

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.



147
148
149
# File 'app/controllers/anoubis/core/data/defaults.rb', line 147

def parent_id
  return 0
end

#parent_modelAnubis::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:

  • (Anubis::ApplicationRecord, nil)

    returns model



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

def parent_model
  nil
end

#selectObject

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

Parameters:

  • row (ActiveRecord)

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

Parameters:

  • row (ActiveRecord)

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

Sets default table actions for every row

Returns:

  • (Array)

    return string array of action identifiers



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

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.



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

#whereHash, Array

Returns default where condition

Returns:

  • (Hash, Array)

    default where condition



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

def where
  []
end