2015-04-08 22:43:59 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
(function () {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The LogService provides access to build
|
|
|
|
* log data using REST API calls.
|
|
|
|
*/
|
|
|
|
function LogService($http, $window) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a task logs.
|
|
|
|
*
|
|
|
|
* @param {string} Name of the repository.
|
|
|
|
* @param {number} Number of the build.
|
|
|
|
* @param {number} Number of the task.
|
|
|
|
*/
|
|
|
|
this.get = function(repoName, number, step) {
|
2015-04-16 21:45:05 +00:00
|
|
|
return $http.get('/api/repos/'+repoName+'/logs/'+number+'/'+step);
|
2015-04-08 22:43:59 +00:00
|
|
|
};
|
2015-04-30 02:57:43 +00:00
|
|
|
|
|
|
|
var callback,
|
2015-05-18 06:07:10 +00:00
|
|
|
events,
|
2015-04-30 02:57:43 +00:00
|
|
|
token = localStorage.getItem('access_token');
|
|
|
|
|
|
|
|
this.subscribe = function (repoName, number, step, _callback) {
|
|
|
|
callback = _callback;
|
|
|
|
|
2015-05-18 06:07:10 +00:00
|
|
|
var route = ['/api/stream/', repoName, '/', number, '/', step, '?access_token=', token].join('')
|
|
|
|
events = new EventSource(route, { withCredentials: true });
|
|
|
|
events.onmessage = function (event) {
|
2015-04-30 02:57:43 +00:00
|
|
|
if (callback !== undefined) {
|
|
|
|
callback(event.data);
|
|
|
|
}
|
|
|
|
};
|
2015-05-18 06:07:10 +00:00
|
|
|
events.onerror = function (event) {
|
|
|
|
callback = undefined;
|
|
|
|
if (events !== undefined) {
|
|
|
|
events.close();
|
|
|
|
events = undefined;
|
|
|
|
}
|
|
|
|
console.log('user event stream closed due to error.', event);
|
2015-04-30 02:57:43 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
this.unsubscribe = function () {
|
|
|
|
callback = undefined;
|
2015-05-18 06:07:10 +00:00
|
|
|
if (events !== undefined) {
|
|
|
|
events.close();
|
|
|
|
events = undefined;
|
2015-04-30 02:57:43 +00:00
|
|
|
}
|
|
|
|
};
|
2015-04-08 22:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('drone')
|
|
|
|
.service('logs', LogService);
|
2015-04-15 05:04:38 +00:00
|
|
|
})();
|