Class: Matestack::Ui::VueJs::Components::Collection::CollectionConfig

Inherits:
Struct
  • Object
show all
Defined in:
lib/matestack/ui/vue_js/components/collection/helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_countObject

Returns the value of attribute base_count

Returns:

  • (Object)

    the current value of base_count



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def base_count
  @base_count
end

#dataObject

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def data
  @data
end

#filter_stateObject

Returns the value of attribute filter_state

Returns:

  • (Object)

    the current value of filter_state



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def filter_state
  @filter_state
end

#filtered_countObject

Returns the value of attribute filtered_count

Returns:

  • (Object)

    the current value of filtered_count



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def filtered_count
  @filtered_count
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def id
  @id
end

#init_limitObject

Returns the value of attribute init_limit

Returns:

  • (Object)

    the current value of init_limit



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def init_limit
  @init_limit
end

#init_offsetObject

Returns the value of attribute init_offset

Returns:

  • (Object)

    the current value of init_offset



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def init_offset
  @init_offset
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



66
67
68
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 66

def params
  @params
end

Instance Method Details

#configObject



123
124
125
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 123

def config
  self.to_h.except(:context)
end

#fromObject



97
98
99
100
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 97

def from
  return get_collection_offset + 1 if to > 0
  return 0 if to == 0
end

#get_collection_limitObject



80
81
82
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 80

def get_collection_limit
  (params["#{id}-limit".to_sym] ||= init_limit).to_i
end

#get_collection_offsetObject



76
77
78
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 76

def get_collection_offset
  (params["#{id}-offset".to_sym] ||= init_offset).to_i
end

#pagesObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 84

def pages
  offset = get_collection_offset
  limit = get_collection_limit
  if filtered_count.present?
    count = filtered_count
  else
    count = base_count
  end
  page_count = count/limit
  page_count += 1 if count%limit > 0
  return (1..page_count).to_a
end

#paginated_dataObject



68
69
70
71
72
73
74
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 68

def paginated_data
  resulting_data = data
  resulting_data = resulting_data.offset(get_collection_offset) unless get_collection_offset == 0
  resulting_data = resulting_data.limit(get_collection_limit) unless get_collection_limit == 0

  return resulting_data
end

#toObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 102

def to
  current_to = get_collection_offset + get_collection_limit
  if filtered_count.present?
    if current_to > filtered_count
      return filtered_count
    else
      return current_to
    end
  else
    if current_to > base_count
      return base_count
    else
      return current_to
    end
  end
end