2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-02-28 06:19:28 +00:00
|
|
|
.controller('ServiceLogsController', ['$scope', '$transition$', '$interval', 'ServiceService', 'Notifications',
|
|
|
|
function ($scope, $transition$, $interval, ServiceService, Notifications) {
|
|
|
|
$scope.state = {
|
|
|
|
refreshRate: 3,
|
2018-10-29 04:49:35 +00:00
|
|
|
lineCount: 100,
|
|
|
|
sinceTimestamp: '',
|
2018-03-25 00:36:13 +00:00
|
|
|
displayTimestamps: false
|
2018-02-28 06:19:28 +00:00
|
|
|
};
|
2017-07-08 09:34:21 +00:00
|
|
|
|
2018-02-28 06:19:28 +00:00
|
|
|
$scope.changeLogCollection = function(logCollectionStatus) {
|
|
|
|
if (!logCollectionStatus) {
|
|
|
|
stopRepeater();
|
|
|
|
} else {
|
|
|
|
setUpdateRepeater();
|
|
|
|
}
|
|
|
|
};
|
2017-07-08 09:34:21 +00:00
|
|
|
|
2018-02-28 06:19:28 +00:00
|
|
|
$scope.$on('$destroy', function() {
|
|
|
|
stopRepeater();
|
|
|
|
});
|
|
|
|
|
|
|
|
function stopRepeater() {
|
|
|
|
var repeater = $scope.repeater;
|
|
|
|
if (angular.isDefined(repeater)) {
|
|
|
|
$interval.cancel(repeater);
|
|
|
|
repeater = null;
|
|
|
|
}
|
2017-07-08 09:34:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 06:19:28 +00:00
|
|
|
function setUpdateRepeater() {
|
|
|
|
var refreshRate = $scope.state.refreshRate;
|
|
|
|
$scope.repeater = $interval(function() {
|
2018-10-29 04:49:35 +00:00
|
|
|
ServiceService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount)
|
2018-02-28 06:19:28 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.logs = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
stopRepeater();
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve service logs');
|
|
|
|
});
|
|
|
|
}, refreshRate * 1000);
|
2017-07-08 09:34:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-28 06:19:28 +00:00
|
|
|
function startLogPolling() {
|
2018-10-29 04:49:35 +00:00
|
|
|
ServiceService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount)
|
2018-02-28 06:19:28 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.logs = data;
|
|
|
|
setUpdateRepeater();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
stopRepeater();
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve service logs');
|
2017-07-08 09:34:21 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initView() {
|
2018-02-28 06:19:28 +00:00
|
|
|
ServiceService.service($transition$.params().id)
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.service = data;
|
|
|
|
startLogPolling();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve service information');
|
2017-07-08 09:34:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
initView();
|
|
|
|
}]);
|