Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Added reset option, fixed template button, added flash message on suc…
Browse files Browse the repository at this point in the history
…cess
  • Loading branch information
davidguthu committed Jan 26, 2015
1 parent 3f74ee7 commit bd6d81b
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 20 deletions.
2 changes: 2 additions & 0 deletions config/locales/vanity.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ en:
converted_percentage: '%{alternative} converted at %{percentage}%.'
currently_shown: 'currently shown'
didnt_convert: '%{alternative} did not convert.'
experiment_has_been_reset: '%{name} experiment has been reset.'
experiment_participants:
one: 'There is one participant in this experiment.'
other: 'There are %{count} participants in this experiment.'
Expand All @@ -32,6 +33,7 @@ en:
participants:
one: '1 participant'
other: '%{count} participants'
reset: 'Reset'
report: 'Vanity Report: %{timestamp}'
result_isnt_significant: 'This result is not statistically significant, suggest you continue this experiment.'
selected_as_best: '%{alternative} selected as the best alternative.'
Expand Down
5 changes: 0 additions & 5 deletions lib/vanity/adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def self.rails_agnostic_find_or_create_by(method, value)
end
end

# Schema model
class VanitySchema < VanityRecord
self.table_name = :vanity_schema
end

# Metric model
class VanityMetric < VanityRecord
UPDATED_AT_GRACE_PERIOD = 1.minute
Expand Down
4 changes: 0 additions & 4 deletions lib/vanity/adapters/mock_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ def ab_set_outcome(experiment, alternative = 0)
def destroy_experiment(experiment)
@experiments.delete experiment
end

def reset_experiment(experiment)
@experiments[experiment] = {}
end
end
end
end
6 changes: 0 additions & 6 deletions lib/vanity/adapters/redis_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ def call_redis_with_failover(*arguments)
end
end
end

def reset_experiment(experiment)
@experiments.del "#{experiment}:outcome", "#{experiment}:completed_at"
alternatives = @experiments.keys("#{experiment}:alts:*")
@experiments.del *alternatives unless alternatives.empty?
end
end
end
end
3 changes: 2 additions & 1 deletion lib/vanity/frameworks/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ def chooses
def reset
exp = Vanity.playground.experiment(params[:e].to_sym)
exp.reset
redirect_to url_for(:action=>:index)
flash[:notice] = I18n.t 'vanity.experiment_has_been_reset', name: exp.name
render :file=>Vanity.template("_experiment"), :locals=>{:experiment=>exp}
end

# JS callback action used by vanity_js
Expand Down
10 changes: 8 additions & 2 deletions lib/vanity/templates/_experiment.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<h3><%=vanity_h experiment.name %> <span class="type">(<%= experiment.class.friendly_name %>)</span></h3>
<%= experiment.description.to_s.split(/\n\s*\n/).map { |para| vanity_html_safe(%{<p class="description">#{vanity_h para}</p>}) }.join.html_safe %>
<%= button_to "Reset", { :action => "reset", :e => experiment.id },
:onclick => "return confirm('Are you sure you want to reset the experiment? This cannot be undone.')", :method => :post %>
<% if respond_to?(:flash) && flash.notice %>
<p>
<%= flash.notice %>
</p>
<% end %>
<% if respond_to?(:url_for) %>
<a class="button reset" title="<%= I18n.t('vanity.reset') %>" href="#" data-id="<%= experiment.id %>" data-url="<%= url_for(:action=>:reset, :e=>experiment.id) %>"><%= I18n.t 'vanity.reset' %></a>
<% end %>
<%= render :file => Vanity.template("_" + experiment.type), :locals => {:experiment => experiment} %>
<p class="meta">
<%= I18n.t('vanity.started_at', :timestamp=>I18n.l(experiment.created_at, :format=>'%a, %b %d')) %>
Expand Down
2 changes: 1 addition & 1 deletion lib/vanity/templates/vanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ $(function() {
return false;
});

$(".experiment button.reset").live("click", function() {
$(".experiment a.button.reset").live("click", function() {
if (confirm('Are you sure you want to reset the experiment? This will clear all collected data so far and restart the experiment from scratch. This cannot be undone.')){
var link = $(this);
$.ajax({
Expand Down
2 changes: 1 addition & 1 deletion test/commands/report_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
end
end
end
end
end

0 comments on commit bd6d81b

Please sign in to comment.