/** bait.coffee **/ (function() { window.Bait = { subscribe: function(handlers) { var source; source = new EventSource('/events'); return source.addEventListener("message", function(e) { var data, handler; data = JSON.parse(e.data); handler = handlers[data[0]][data[1]]; return handler.apply(this, data.slice(2)); }); } }; }).call(this); /** build.coffee **/ (function() { window.Build = { find: function(id) { return $("#" + id); }, all: function(cb) { return $.getJSON('/build', function(data) { return cb(data); }); }, DOM: { UIHelper: { expand_toggle: function(el) { return el.on("click", function(e) { if (el.css("max-height") === "100px") { return el.css("max-height", "100%"); } else { return el.css("max-height", "100px"); } }); }, enable_links: function(element) { element.find('a.remove').click(function() { $.ajax({ type: "DELETE", url: $(this).data('url') }); return false; }); return element.find('a.retest').click(function() { $(this).parents('.build').find('pre').html(""); $.post($(this).data('url')); return false; }); } }, init: function(build_id) { var build, output, pre; build = Build.find(build_id); pre = build.find(".output pre"); output = pre.html(); if ((output != null) && output.size > 0) { pre.html(ansi2html(output)); } Build.DOM.UIHelper.expand_toggle(pre); return Build.DOM.UIHelper.enable_links(build); } }, List: { add: function(build) { var html; html = Build.to_html(build); if ($('.build').length > 0) { $('.build').first().before(html); } else { $('ul#builds').append(html); } return Build.DOM.init(build.id); } }, to_html: function(build) { return "
  • \n
    \n
    " + build.status + "
    \n " + build.name + "\n
    " + (build.ref != null ? build.ref : build.ref = '') + "
    \n
    \n
    \n
    " + build.output + "
    \n
    \n
    \n Remove\n |\n Retest\n
    \n
  • "; } }; }).call(this); /** main.coffee **/ (function() { Zepto(function($) { ManualClone.init(); Build.all(function(builds) { $.each(builds, function(i, d) { return Build.List.add(d.build); }); return $("#loading").remove(); }); return Bait.subscribe({ global: { new_build: function(data) { return Build.List.add(data.build); } }, build: { output: function(id, text) { var pre; pre = Build.find(id).find('pre'); return pre.append(ansi2html(text)); }, status: function(id, text) { var header; header = Build.find(id).find(".header"); header.find(".status").html(text); return header.attr("class", "header " + text); }, remove: function(id) { return Build.find(id).remove(); } } }); }); }).call(this); /** manual_clone.coffee **/ (function() { window.ManualClone = { init: function() { var button, field, form, manual_clone; form = $('.manual_clone'); field = form.find('input'); button = form.find('button'); manual_clone = function() { var input; input = field.val(); if (input.length > 0) { if (!button.attr('disabled')) { button.attr('disabled', 'disabled'); return $.post('/build/create', { clone_url: input }, function(response) { console.log(response); return button.removeAttr('disabled'); }); } } else { return alert("Enter a local path or remote url to a git repo, e.g.:\n Local: /Users/your/project\n Remote: https://github.com/your/project"); } }; field.keypress(function(e) { if (e.keyCode === 13) { return manual_clone(); } }); return button.on('click', function() { return manual_clone(); }); } }; }).call(this);