Class: Anoubis::Output::Data

Inherits:
Basic
  • Object
show all
Defined in:
app/controllers/anoubis/output/data.rb

Overview

Output subclass that represents data for default index action

Instance Attribute Summary collapse

Attributes inherited from Basic

#messages, #result, #tab, #title

Instance Method Summary collapse

Methods inherited from Basic

#hash_to_json, #message, #options_to_json

Constructor Details

#initializeData

Initializes output data. Generates default values.



50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/anoubis/output/data.rb', line 50

def initialize
  super
  self.data = nil
  self.fields = nil
  self.filter = nil
  self.count = 0
  self.offset = 0
  self.limit = 20
  self.sort = nil
  self.order = ''
  self.sortable = nil
end

Instance Attribute Details

#countString

Returns the model’s row count.

Returns:

  • (String)

    the model’s row count



11
# File 'app/controllers/anoubis/output/data.rb', line 11

class_attribute :count

#dataArray

Returns array of output data.

Returns:

  • (Array)

    array of output data



23
# File 'app/controllers/anoubis/output/data.rb', line 23

class_attribute :data

#fieldsArray

Returns array of output fields.

Returns:

  • (Array)

    array of output fields



27
# File 'app/controllers/anoubis/output/data.rb', line 27

class_attribute :fields

#filterArray

Returns array of filter fields.

Returns:

  • (Array)

    array of filter fields



31
# File 'app/controllers/anoubis/output/data.rb', line 31

class_attribute :filter

#limitInteger

Returns output limit fro returns rows.

Returns:

  • (Integer)

    output limit fro returns rows



19
# File 'app/controllers/anoubis/output/data.rb', line 19

class_attribute :limit

#offsetInteger

Returns output offset for rows were returned.

Returns:

  • (Integer)

    output offset for rows were returned



15
# File 'app/controllers/anoubis/output/data.rb', line 15

class_attribute :offset

#orderString

Returns order type current output data (‘asc’ or ‘desc’).

Returns:

  • (String)

    order filed type



41
# File 'app/controllers/anoubis/output/data.rb', line 41

class_attribute :order

#sortString

Returns order field for current output data.

Returns:

  • (String)

    order filed name



36
# File 'app/controllers/anoubis/output/data.rb', line 36

class_attribute :sort

#sortableString

Returns name for manual table order

Returns:

  • (String)

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



46
# File 'app/controllers/anoubis/output/data.rb', line 46

class_attribute :sortable

Instance Method Details

#message1String

Generates output message based on self.result variable.

Returns:

  • (String)

    output message



89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/anoubis/output/data.rb', line 89

def message1
  case self.result
  when -1
    return I18n.t('errors.invalid_login_parameters')
  when -2
    return I18n.t('errors.invalid_login_or_password')
  else
    return super
  end
end

#to_hHash

Generates hash representation of output class

Returns:

  • (Hash)

    hash representation of all data



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/controllers/anoubis/output/data.rb', line 66

def to_h
  result = super.to_h
  return result if self.result != 0
  result.merge!({
                    count: self.count,
                    offset: self.offset,
                    limit: self.limit
                })
  if self.sort
    result[:sort] = self.sort
    result[:order] = self.order
  end

  result.merge!({ fields: self.fields}) if self.fields
  result.merge!({ filter: self.filter}) if self.filter
  result.merge!({ data: self.data}) if self.data
  result[:sortable] = self.sortable if self.sortable
  result
end