Sha256: 3c43f483febb7af96bd380c08405acb217572ac9c2eb0c29dd866f85b4485f62

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

class Admin::DashboardController < Admin::AdminController

  def index
    @search           = OpenStruct.new params[:search]

    search_where      = generate_search_where(@search)

    @page             = (params[:page] || 1).to_i
    @features_columns = Feature.data_columns
    @features_count   = CartoDB::Connection.query("SELECT COUNT(cartodb_id) as features_count FROM #{Cartoset::Config['features_table']} #{search_where}").rows.first.features_count
    @features         = CartoDB::Connection.query(<<-SQL
      SELECT *
      FROM #{Cartoset::Config['features_table']}
      #{search_where}
      LIMIT 10
      OFFSET #{(@page - 1) * 10}
    SQL
    ).rows
    @pages            = (Cartoset::Config['pages'] || []).select{|p| p['id'].present? } || []
    @cartodb_host     = CartoDB::Settings['host']
    @table_id         = CartoDB::Connection.table(Cartoset::Config['features_table']).try(:id)
  end

  def generate_search_where(search_params)
    where = ''

    if search_params && search_params.q.present?
      where = []
      fields = Feature.non_common_fields.select{|f| f[:type] == 'string'}
      fields.each do |f|
        where << "#{f[:name]} ilike '%#{search_params.q.sanitize_sql!}%'"
      end
      where = "WHERE #{where.join(' OR ')}"
    end
    where
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cartoset-0.0.1 app/controllers/admin/dashboard_controller.rb