Sha256: f38846893b2fd21d40a7356b075aa42c3a1e63420af567759845a383bb8a5576

Contents?: true

Size: 1.91 KB

Versions: 3

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true
require 'sinatra/base'
require 'split'
require 'bigdecimal'
require 'split/dashboard/helpers'
require 'split/dashboard/pagination_helpers'

module Split
  class Dashboard < Sinatra::Base
    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/dashboard/views"
    set :public_folder, "#{dir}/dashboard/public"
    set :static, true
    set :method_override, true

    helpers Split::DashboardHelpers
    helpers Split::DashboardPaginationHelpers

    get '/' do
      # Display experiments without a winner at the top of the dashboard
      @experiments = Split::ExperimentCatalog.all_active_first

      @metrics = Split::Metric.all

      # Display Rails Environment mode (or Rack version if not using Rails)
      if Object.const_defined?('Rails')
        @current_env = Rails.env.titlecase
      else
        @current_env = "Rack: #{Rack.version}"
      end
      erb :index
    end

    post '/force_alternative' do
      Split::User.new(self)[params[:experiment]] = params[:alternative]
      redirect url('/')
    end

    post '/experiment' do
      @experiment = Split::ExperimentCatalog.find(params[:experiment])
      @alternative = Split::Alternative.new(params[:alternative], params[:experiment])
      @experiment.winner = @alternative.name
      redirect url('/')
    end

    post '/start' do
      @experiment = Split::ExperimentCatalog.find(params[:experiment])
      @experiment.start
      redirect url('/')
    end

    post '/reset' do
      @experiment = Split::ExperimentCatalog.find(params[:experiment])
      @experiment.reset
      redirect url('/')
    end

    post '/reopen' do
      @experiment = Split::ExperimentCatalog.find(params[:experiment])
      @experiment.reset_winner
      redirect url('/')
    end

    delete '/experiment' do
      @experiment = Split::ExperimentCatalog.find(params[:experiment])
      @experiment.delete
      redirect url('/')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
split-3.3.2 lib/split/dashboard.rb
split-3.3.1 lib/split/dashboard.rb
split-3.3.0 lib/split/dashboard.rb