mirror of
https://github.com/portainer/portainer.git
synced 2025-08-05 05:45:22 +02:00
feat(log-viewer): introduce the log viewer component (#1666)
This commit is contained in:
parent
81de2a5afb
commit
0c5152fb5f
36 changed files with 458 additions and 304 deletions
|
@ -44,6 +44,9 @@
|
|||
<td>Container ID</td>
|
||||
<td>{{ task.Status.ContainerStatus.ContainerID }}</td>
|
||||
</tr>
|
||||
<tr ng-if="applicationState.endpoint.apiVersion >= 1.30" >
|
||||
<td colspan="2"><a class="btn btn-primary btn-sm" type="button" ui-sref="docker.tasks.task.logs({id: task.Id})"><i class="fa fa-file-text-o space-right" aria-hidden="true"></i>Task logs</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</rd-widget-body>
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
angular.module('portainer.docker')
|
||||
.controller('TaskController', ['$scope', '$transition$', 'TaskService', 'Service', 'Notifications',
|
||||
function ($scope, $transition$, TaskService, Service, Notifications) {
|
||||
.controller('TaskController', ['$scope', '$transition$', 'TaskService', 'ServiceService', 'Notifications',
|
||||
function ($scope, $transition$, TaskService, ServiceService, Notifications) {
|
||||
|
||||
function initView() {
|
||||
TaskService.task($transition$.params().id)
|
||||
.then(function success(data) {
|
||||
var task = data;
|
||||
$scope.task = task;
|
||||
return Service.get({ id: task.ServiceId }).$promise;
|
||||
return ServiceService.service(task.ServiceId);
|
||||
})
|
||||
.then(function success(data) {
|
||||
var service = new ServiceViewModel(data);
|
||||
var service = data;
|
||||
$scope.service = service;
|
||||
})
|
||||
.catch(function error(err) {
|
||||
|
|
73
app/docker/views/tasks/logs/taskLogsController.js
Normal file
73
app/docker/views/tasks/logs/taskLogsController.js
Normal file
|
@ -0,0 +1,73 @@
|
|||
angular.module('portainer.docker')
|
||||
.controller('TaskLogsController', ['$scope', '$transition$', '$interval', 'TaskService', 'ServiceService', 'Notifications',
|
||||
function ($scope, $transition$, $interval, TaskService, ServiceService, Notifications) {
|
||||
$scope.state = {
|
||||
refreshRate: 3,
|
||||
lineCount: 2000
|
||||
};
|
||||
|
||||
$scope.changeLogCollection = function(logCollectionStatus) {
|
||||
if (!logCollectionStatus) {
|
||||
stopRepeater();
|
||||
} else {
|
||||
setUpdateRepeater();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.$on('$destroy', function() {
|
||||
stopRepeater();
|
||||
});
|
||||
|
||||
function stopRepeater() {
|
||||
var repeater = $scope.repeater;
|
||||
if (angular.isDefined(repeater)) {
|
||||
$interval.cancel(repeater);
|
||||
repeater = null;
|
||||
}
|
||||
}
|
||||
|
||||
function setUpdateRepeater() {
|
||||
var refreshRate = $scope.state.refreshRate;
|
||||
$scope.repeater = $interval(function() {
|
||||
TaskService.logs($transition$.params().id, 1, 1, 0, $scope.state.lineCount)
|
||||
.then(function success(data) {
|
||||
$scope.logs = data;
|
||||
})
|
||||
.catch(function error(err) {
|
||||
stopRepeater();
|
||||
Notifications.error('Failure', err, 'Unable to retrieve task logs');
|
||||
});
|
||||
}, refreshRate * 1000);
|
||||
}
|
||||
|
||||
function startLogPolling() {
|
||||
TaskService.logs($transition$.params().id, 1, 1, 0, $scope.state.lineCount)
|
||||
.then(function success(data) {
|
||||
$scope.logs = data;
|
||||
setUpdateRepeater();
|
||||
})
|
||||
.catch(function error(err) {
|
||||
stopRepeater();
|
||||
Notifications.error('Failure', err, 'Unable to retrieve task logs');
|
||||
});
|
||||
}
|
||||
|
||||
function initView() {
|
||||
TaskService.task($transition$.params().id)
|
||||
.then(function success(data) {
|
||||
var task = data;
|
||||
$scope.task = task;
|
||||
return ServiceService.service(task.ServiceId);
|
||||
})
|
||||
.then(function success(data) {
|
||||
var service = data;
|
||||
$scope.service = service;
|
||||
startLogPolling();
|
||||
})
|
||||
.catch(function error(err) {
|
||||
Notifications.error('Failure', err, 'Unable to retrieve task details');
|
||||
});
|
||||
}
|
||||
|
||||
initView();
|
||||
}]);
|
10
app/docker/views/tasks/logs/tasklogs.html
Normal file
10
app/docker/views/tasks/logs/tasklogs.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
<rd-header>
|
||||
<rd-header-title title="Task details"></rd-header-title>
|
||||
<rd-header-content ng-if="task && service">
|
||||
<a ui-sref="docker.services">Services</a> > <a ui-sref="docker.services.service({id: service.Id })">{{ service.Name }}</a> > <a ui-sref="docker.tasks.task({id: task.Id })">{{ task.Id }}</a> > Logs
|
||||
</rd-header-content>
|
||||
</rd-header>
|
||||
|
||||
<log-viewer
|
||||
data="logs" ng-if="logs" log-collection-change="changeLogCollection"
|
||||
></log-viewer>
|
Loading…
Add table
Add a link
Reference in a new issue