nci/static/js/app/app.js

44 lines
1.1 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 projects = connect.resource('projects');
var builds = connect.resource('builds');
var projectsTemplate = _($('#projects-template').html()).template();
$('#content').on('click', '.js-projects .js-run', function() {
var projectName = $(this).parent('.js-project').data('name');
projects.sync('run', {projectName: projectName}, function(err, result) {
$('#content').append(
(err && err.message)
);
});
});
2015-04-12 22:41:09 +00:00
projects.sync('read', function(err, projects) {
2015-04-30 15:15:23 +00:00
$('#content').html(
(err && err.message) ||
projectsTemplate({projects: projects})
);
2015-04-12 22:41:09 +00:00
});
builds.subscribe(function(data, action) {
2015-05-03 22:58:04 +00:00
$('#content').append(
action.action + ': ' + JSON.stringify(data) + '<br>'
);
if (action.action === 'create') {
var name = 'build' + data.id;
connect.resource(name).subscribe(function(data, action) {
$('#content').append(
'<br>' + name + ': ' + data + '<br>'
);
});
}
});
2015-04-10 20:17:03 +00:00
});