Skip to content

Commit

Permalink
Test creation
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Jun 21, 2010
1 parent 343db0d commit 89b5857
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 5 deletions.
19 changes: 19 additions & 0 deletions lib/a_b_front_end/controller/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,23 @@
:token => current_user.single_access_token
).to_json
end

post '/tests.json' do
ABPlugin::API.create_test(
:category => params[:category],
:include => params[:include],
:name => params[:name],
:only => params[:only],
:token => current_user.single_access_token,
:variants => params[:variants]
).to_json
end

delete '/tests.json' do
ABPlugin::API.delete_test(
:category => params[:category],
:name => params[:name],
:token => current_user.single_access_token
).to_json
end
end
2 changes: 1 addition & 1 deletion lib/a_b_front_end/controller/front.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
get '/' do
if current_user
@sites = ABPlugin::API.sites(
:include => [ :envs, :categories ],
:include => { :envs => true, :categories => { :include => :tests } },
:token => current_user.single_access_token
)
haml :dashboard
Expand Down
2 changes: 1 addition & 1 deletion lib/a_b_front_end/view/dashboard.haml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
.clear
.submit
%input{ :type => 'submit', :value => 'Submit' }
%input{ :class => 'cancel', :type => 'submit', :value => 'Cancel' }
%input{ :class => 'cancel', :type => 'reset', :value => 'Cancel' }

%textarea.hide#tests_form_variant_template
.span-2
Expand Down
39 changes: 36 additions & 3 deletions public/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,51 @@ window.Dashboard = function(sites) {
return false;
});
} else {
$('#tests .dialog').remove();
$('#tests').append($('#tests_form_template').val());

var dialog = $('#tests .dialog');

$('.submit', dialog).before($('#tests_form_variant_template').val());
$('input:first', dialog).focus();

$('.cancel', dialog).click(function() {
dialog.remove();
return false;
});

$('form', dialog).submit(function() {
var form = $(this);
var inputs = $('.submit input', form);
$(inputs[0]).attr({
'disabled': true,
'value': 'One moment...'
});
$(inputs[1]).remove();

var category = $('#categories .selected').text();
var site = $('#sites .selected').text();
var data = form.serialize() + '&category=' + category;

queue.queue(function() {
$.post(
'/tests.json',
data,
function(response) {
category = byName(byName(sites, site).categories, category);
category.tests.push(response);
queue.dequeue();
},
'json'
);
});
return false;
});
}
});

$('#tests .variants').live('focus', function() {
if ($('#tests .variants[value=]').length < 2)
$('#tests .variants').live('keyup', function() {
if ($('#tests .variants[value=]').length < 1)
$('#tests .dialog .submit').before($('#tests_form_variant_template').val());
});

Expand All @@ -111,7 +144,7 @@ window.Dashboard = function(sites) {
});
addLastClassToSelectables();
} else {
// tests display logic
$('.dialog', target).remove();
}
} else {
$('.remove', filter).addClass('hide');
Expand Down
20 changes: 20 additions & 0 deletions vendor/a_b_plugin/lib/a_b_plugin/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def self.create_site(attributes={})
))
end

def self.create_test(attributes={})
return unless Config.token && Config.url
base_uri Config.url
post('/tests.json', :query => compress(
:include => attributes.delete(:include),
:only => attributes.delete(:only),
:token => attributes.delete(:token) || Config.token,
:test => attributes
))
end

def self.create_user(attributes={})
return unless Config.token && Config.url
base_uri Config.url
Expand Down Expand Up @@ -68,6 +79,15 @@ def self.delete_site(attributes={})
))
end

def self.delete_test(attributes={})
return unless Config.token && Config.url
base_uri Config.url
delete('/sites.json', :query => compress(
:token => attributes.delete(:token) || Config.token,
:site => attributes
))
end

def self.sites(attributes={})
return unless Config.token && Config.url
base_uri Config.url
Expand Down

0 comments on commit 89b5857

Please sign in to comment.