Skip to content
Browse files

Conditions select working

  • Loading branch information...
1 parent 89c721e commit 81fd76df29a614ee4b981f410e3635de74fbec52 @winton committed Oct 3, 2010
Showing with 56 additions and 6 deletions.
  1. +20 −2 lib/a_b_front_end/view/dashboard.haml
  2. +1 −1 public/js/a_b.js
  3. +35 −3 public/js/dashboard.js
View
22 lib/a_b_front_end/view/dashboard.haml
@@ -59,6 +59,7 @@
%th Suggested Visits
%th Confidence
<%
+ var condition_keys = [];
var odd;
$.each(test.variants, function(i, variant) {
odd = (i % 2 == 0); %>
@@ -72,14 +73,23 @@
var found = false;
$.each(variant.for_dashboard, function(e, item) {
if (e == env) {
- found = true; %>
+ condition_keys = condition_keys.concat(item.condition_keys);
+ found = true;
+ if (typeof(condition) != "undefined") {
+ if (item.conditions[condition])
+ item = item.conditions[condition];
+ else
+ found = false;
+ }
+ if (found) { %>
%td <%= item.visits %>
%td <%= item.conversions %>
%td <%= item.conversion_rate %>
%td <%= item.suggested_visits %>
%td <%= item.confidence %>
<%
}
+ }
});
if (!found) { %>
%td 0
@@ -91,8 +101,16 @@
<% }); %>
%tr{ :class => '<% if (!odd) { %>odd<% } %>'}
%td{ :colspan => 6 }
+ <%
+ condition_keys = window.dashboard.uniqArray(condition_keys).sort();
+ if (condition_keys.length) { %>
%select.conditions
- %option Conditions
+ %option All data
+ <%
+ $.each(condition_keys, function(i, c) { %>
+ <option <%= typeof(condition) != "undefined" && c == condition ? "selected" : "" %>><%= c %></option>
+ <% }); %>
+ <% } %>
.right
.edit
%a{ :href => '#' }
View
2 public/js/a_b.js
@@ -206,7 +206,7 @@ window.A_B = new function() {
u[array[i]] = 1;
}
return a;
- };
+ }
};
};
View
38 public/js/dashboard.js
@@ -135,7 +135,7 @@ window.Dashboard = function(sites) {
$('#tests .remove a').live('click', function() {
if (!confirm('Are you sure?'))
- return;
+ return false;
var site = byName(sites, $('#sites .selected').text());
var category = byName(site.categories, $('#categories .selected').text());
@@ -155,6 +155,8 @@ window.Dashboard = function(sites) {
'json'
);
});
+
+ return false;
});
$('.selectable:not(.new)').live('click', function() {
@@ -204,7 +206,7 @@ window.Dashboard = function(sites) {
$('.header > .remove').live('click', function() {
if (!confirm('Are you sure?'))
- return;
+ return false;
var filter = $(this).parents('.filter');
var id = filter.attr('id');
@@ -230,6 +232,25 @@ window.Dashboard = function(sites) {
'json'
);
});
+
+ return false;
+ });
+
+ $('select.conditions').live('change', function() {
+ var env = $('#envs .selected').text();
+ var site = byName(sites, $('#sites .selected').text());
+ var category = byName(site.categories, $('#categories .selected').text());
+ var table = $(this).parents('table');
+ var id = table.attr('id').match(/\d+/)[0];
+ var condition = $("option:selected", this).html();
+ var test = byId(category.tests, id);
+ table.replaceWith(
+ $('#test_template').tmpl({
+ condition: (condition == 'All data' ? undefined : condition),
+ test: test,
+ env: env
+ })
+ );
});
$(document).keyup(function(e) {
@@ -281,13 +302,24 @@ window.Dashboard = function(sites) {
})[0];
}
+ function uniqArray(array) {
+ var u = {}, a = [];
+ for(var i = 0, l = array.length; i < l; i++) {
+ if (u[array[i]]) continue;
+ a.push(array[i]);
+ u[array[i]] = 1;
+ }
+ return a;
+ }
+
function withoutName(records, name) {
return $.grep(records, function(item) {
return (item.name != name);
});
}
$.extend(this, {
- sites: function() { return sites; }
+ sites: function() { return sites; },
+ uniqArray: uniqArray
});
};

0 comments on commit 81fd76d

Please sign in to comment.
Something went wrong with that request. Please try again.