Add UI to download logs

Part of #304
This commit is contained in:
Girish Ramakrishnan
2017-04-18 15:34:32 -07:00
parent 0c706cffc0
commit 3cb4d4b1ab
3 changed files with 50 additions and 3 deletions

View File

@@ -396,6 +396,14 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
}).error(defaultErrorHandler(callback));
};
Client.prototype.makeURL = function (url) {
if (url.indexOf('?') === -1) {
return this.apiOrigin + url + '?access_token=' + token;
} else {
return this.apiOrigin + url + '&access_token=' + token;
}
};
Client.prototype.setBackupConfig = function (backupConfig, callback) {
post('/api/v1/settings/backup_config', backupConfig).success(function(data, status) {
if (status !== 200) return callback(new ClientError(status, data));
@@ -541,10 +549,10 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
}).error(defaultErrorHandler(callback));
};
Client.prototype.getAppBackups = function (callback) {
get('/api/v1/backups').success(function (data, status) {
Client.prototype.getAppLogs = function (appId, callback) {
get('/api/v1/apps/' + appId + '/logs').success(function (data, status) {
if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data));
callback(null, data.backups);
callback(null);
}).error(defaultErrorHandler(callback));
};

View File

@@ -24,6 +24,26 @@
<br/>
<div class="card card-large">
<div class="grid-item-top">
<div class="row animateMeOpacity">
<div class="col-lg-12">
<h3>Logs</h3>
<form name="logsForm">
<div class="form-group">
<select class="form-control" name="type" style="width: 50%;" ng-model="logs.selectedUrl" required>
<option ng-repeat="log in logs.types" ng-value="log.url">{{ log.name }}</option>
</select>
</div>
<a class="btn btn-primary" ng-href="{{logs.selectedUrl}}" target="_self"> Download </a>
</form>
</div>
</div>
</div>
</div>
<br/>
<div class="card card-large">
<div class="grid-item-top">
<div class="row animateMeOpacity">

View File

@@ -13,6 +13,11 @@ angular.module('Application').controller('SupportController', ['$scope', '$locat
description: ''
};
$scope.logs = {
types: null,
selectedUrl: '' // index into types
};
$scope.sshSupportEnabled = false;
function resetFeedback() {
@@ -58,6 +63,18 @@ angular.module('Application').controller('SupportController', ['$scope', '$locat
}
};
$scope.populateLogTypes = function () {
$scope.logs.types = [
{ id: 'system', name: 'System', url: Client.makeURL('/api/v1/cloudron/logs?unit=all') },
{ id: 'box', name: 'Box', url: Client.makeURL('/api/v1/cloudron/logs?unit=box') },
{ id: 'mail', name: 'Mail', url: Client.makeURL('/api/v1/cloudron/logs?unit=mail') }
];
Client.getInstalledApps().forEach(function (app) {
$scope.logs.types.push({ id: app.id, name: app.fqdn, url: Client.makeURL('/api/v1/apps/' + app.id + '/logs') });
});
};
Client.onReady(function () {
Client.getAuthorizedKeys(function (error, keys) {
if (error) return console.error(error);
@@ -66,5 +83,7 @@ angular.module('Application').controller('SupportController', ['$scope', '$locat
});
});
Client.onReady($scope.populateLogTypes);
$('.modal-backdrop').remove();
}]);