Sha256: 479993f581a8b054fe92d4c10abe6e860ac8c8503c16a69c91ce199fdbfb07b3

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

class SetupController < ApplicationController
  include FeatureGetterHelper

  layout 'setup'

  before_filter :redirect_to_root_if_invalid_env
  skip_before_filter :show_setup_wizard_if_uninstalled

  def step
    step_id = params[:step_id] || 0

    case step_id
    when "1"
      @settings = OpenStruct.new Cartoset::Config.settings
    when "2"
      Cartoset::Config.set_cartodb_credentials current_user
      @settings = OpenStruct.new Cartoset::Config.settings
    when "3"
      Cartoset::Config.update params[:settings]

      result = CartoDB::Connection.tables || []
      @tables = result.tables
    when "4"
      @table = CartoDB::Connection.table params[:features_table]
      Cartoset::Config.update :features_table => @table.name
    end

    render "step#{step_id}"
  end

  def cartodb
      Cartoset::Config.update params[:settings]

      Cartoset::Config.setup_cartodb

      session[:return_to] = setup_path(:step_id => 2)

      redirect_to '/auth/cartodb' and return
  end

  def features_table_data
    table_name = params[:table_name]
    if table_name
      @table  = CartoDB::Connection.table table_name
      records = CartoDB::Connection.records table_name, {}
      @rows = records.rows if records
    end
    render :layout => false
  end

  def create_features_table
    table = {}

    if params[:qqfile] && request.body.present?
      table = FeaturesDataImporter.start request.body
    end

    render :json => table.to_json
  end

  def redirect_to_root_if_invalid_env
    unless Rails.env.development? || Rails.env.test? || logged_in?
      if application_installed? && !logged_in?
        session[:return_to] = setup_path
        redirect_to login_required_path
      else
        redirect_to root_path
      end
    end
  end
  private :redirect_to_root_if_invalid_env
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cartoset-0.0.2 app/controllers/setup_controller.rb
cartoset-0.0.1 app/controllers/setup_controller.rb