nci/static/js/app/app.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-04-10 20:17:03 +00:00
'use strict';
2015-04-12 22:41:09 +00:00
define([
2015-04-30 15:15:23 +00:00
'underscore', 'react', 'socketio', 'dataio', 'jquery'
2015-04-12 22:41:09 +00:00
], function(
2015-04-30 15:15:23 +00:00
_, React, socketio, dataio, $
2015-04-12 22:41:09 +00:00
) {
var connect = dataio(socketio.connect());
var projectsResource = connect.resource('projects'),
projectsTemplate = _($('#projects-template').html()).template();
$('#projects').on('click', '.js-projects .js-run', function() {
var projectName = $(this).parent('.js-project').data('name');
projectsResource.sync('run', {projectName: projectName}, function(err, result) {
$('#content').append(err && err.message);
});
});
projectsResource.sync('read', function(err, projects) {
$('#projects').html(
(err && err.message) ||
projectsTemplate({projects: projects})
);
2015-04-12 22:41:09 +00:00
});
var buildsResource = connect.resource('builds'),
buildsTemplate = _($('#builds-template').html()).template(),
builds = [];
$('#builds').on('click', '.js-builds .js-show-console', function() {
var buildId = $(this).parent('.js-build').data('id'),
resourceName = 'build' + buildId;
$('#build-console').prev('h2').html('Build #' + buildId + ' console');
$('#build-console').html('');
connect.resource(resourceName).subscribe(function(data) {
$('#build-console').append('<div>' + data + '</div>');
});
});
buildsResource.subscribe(function(build, action) {
var oldBuild = _(builds).findWhere({id: build.id});
if (oldBuild) {
_(oldBuild).extend(build);
} else {
builds.unshift(build);
}
$('#builds').html(buildsTemplate({builds: builds}));
});
2015-04-10 20:17:03 +00:00
});