Sha256: 2de66da144254c9f165be4d34b49be657adee43466f6d03e470d354733668457

Contents?: true

Size: 689 Bytes

Versions: 2

Compression:

Stored size: 689 Bytes

Contents

# -*- encoding : utf-8 -*-
class RademadeAdmin::SortableService

  def initialize(model_info, params)
    @model_info = model_info
    @params = params
  end

  def re_sort_items
    min = @params[:minimum].to_i
    @params[:sorted].each do |k, v|
      item = @model_info.model.find(v[0])
      item.position = k.to_i + 1 + min
      item.save
    end
  end

  def can_reset?
    @params[:sort].present?
  end

  def sorting_sign(name)
    if name.to_s == @params[:sort]
      case @params[:direction]
        when 'asc'
          return '⬇'
        when 'desc'
          return '⬆'
      end
    end
    ''
  end

  def has_position?
    @model_info.has_field? 'position'
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rademade_admin-0.0.3 app/services/sortable_service.rb
rademade_admin-0.0.2 app/services/sortable_service.rb