Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/split/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Dashboard < Sinatra::Base
get '/' do
# Display experiments without a winner at the top of the dashboard
@experiments = Split::ExperimentCatalog.all_active_first
@unintialized_experiments = Split.configuration.experiments.keys - @experiments.map(&:name)

@metrics = Split::Metric.all

Expand All @@ -33,6 +34,11 @@ class Dashboard < Sinatra::Base
erb :index
end

post '/initialize_experiment' do
Split::ExperimentCatalog.find_or_create(params[:experiment]) unless params[:experiment].nil? || params[:experiment].empty?
redirect url('/')
end

post '/force_alternative' do
experiment = Split::ExperimentCatalog.find(params[:experiment])
alternative = Split::Alternative.new(params[:alternative], experiment.name)
Expand Down
7 changes: 5 additions & 2 deletions lib/split/dashboard/public/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ body {
color: #408C48;
}

a.button, button, input[type="submit"] {
.experiment a.button, .experiment button, .experiment input[type="submit"] {
padding: 4px 10px;
overflow: hidden;
background: #d8dae0;
Expand Down Expand Up @@ -312,10 +312,13 @@ a.button.green:focus, button.green:focus, input[type="submit"].green:focus {
background:#768E7A;
}

#filter, #clear-filter {
.dashboard-controls input, .dashboard-controls select {
padding: 10px;
}

.dashboard-controls-bottom {
margin-top: 10px;
}

.pagination {
text-align: center;
Expand Down
23 changes: 19 additions & 4 deletions lib/split/dashboard/views/index.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<% if @experiments.any? %>
<p class="intro">The list below contains all the registered experiments along with the number of test participants, completed and conversion rate currently in the system.</p>

<input type="text" placeholder="Begin typing to filter" id="filter" />
<input type="button" id="toggle-completed" value="Hide completed" />
<input type="button" id="toggle-active" value="Hide active" />
<input type="button" id="clear-filter" value="Clear filters" />
<div class="dashboard-controls">
<input type="text" placeholder="Begin typing to filter" id="filter" />
<input type="button" id="toggle-completed" value="Hide completed" />
<input type="button" id="toggle-active" value="Hide active" />
<input type="button" id="clear-filter" value="Clear filters" />
</div>

<% paginated(@experiments).each do |experiment| %>
<% if experiment.goals.empty? %>
Expand All @@ -24,3 +26,16 @@
<p class="intro">No experiments have started yet, you need to define them in your code and introduce them to your users.</p>
<p class="intro">Check out the <a href='https://github.com/splitrb/split#readme'>Readme</a> for more help getting started.</p>
<% end %>

<div class="dashboard-controls dashboard-controls-bottom">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be hidden from the UI if @unintialized_experiments is empty?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will address this later, not an issue for merging this right now.

<form action="<%= url "/initialize_experiment" %>" method='post'>
<label>Add unregistered experiment: </label>
<select name="experiment" id="experiment-select">
<option selected disabled>experiment</option>
<% @unintialized_experiments.sort.each do |experiment_name| %>
<option value="<%= experiment_name %>"><%= experiment_name %></option>
<% end %>
</select>
<input type="submit" id="register-experiment-btn" value="register experiment"/>
</form>
<div>
31 changes: 31 additions & 0 deletions spec/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,37 @@ def link(color)
end
end

describe "initialize experiment" do
before do
Split.configuration.experiments = {
:my_experiment => {
:alternatives => [ "control", "alternative" ],
}
}
end

it "initializes the experiment when the experiment is given" do
expect(Split::ExperimentCatalog.find("my_experiment")).to be nil

post "/initialize_experiment", { experiment: "my_experiment"}

experiment = Split::ExperimentCatalog.find("my_experiment")
expect(experiment).to be_a(Split::Experiment)
end

it "does not attempt to intialize the experiment when empty experiment is given" do
post "/initialize_experiment", { experiment: ""}

expect(Split::ExperimentCatalog).to_not receive(:find_or_create)
end

it "does not attempt to intialize the experiment when no experiment is given" do
post "/initialize_experiment"

expect(Split::ExperimentCatalog).to_not receive(:find_or_create)
end
end

it "should reset an experiment" do
red_link.participant_count = 5
blue_link.participant_count = 7
Expand Down