logs: remove dep on refreshInstalledApps
This commit is contained in:
+27
-21
@@ -11,17 +11,11 @@ app.controller('LogsController', ['$scope', '$timeout', '$location', 'Client', f
|
||||
$scope.initialized = false;
|
||||
$scope.installedApps = Client.getInstalledApps();
|
||||
$scope.client = Client;
|
||||
$scope.logs = [];
|
||||
$scope.selected = '';
|
||||
$scope.activeEventSource = null;
|
||||
$scope.lines = 100;
|
||||
$scope.selectedAppInfo = null;
|
||||
|
||||
// Add built-in log types for now
|
||||
$scope.logs.push({ name: 'Box', type: 'platform', value: 'box', url: Client.makeURL('/api/v1/cloudron/logs/box') });
|
||||
$scope.logs.push({ name: 'Mail', type: 'platform', value: 'mail', url: Client.makeURL('/api/v1/cloudron/logs/mail') });
|
||||
$scope.logs.push({ name: 'Backup', type: 'platform', value: 'backup', url: Client.makeURL('/api/v1/cloudron/logs/backup') });
|
||||
|
||||
$scope.error = function (error) {
|
||||
console.error(error);
|
||||
window.location.href = '/error.html';
|
||||
@@ -79,6 +73,32 @@ app.controller('LogsController', ['$scope', '$timeout', '$location', 'Client', f
|
||||
});
|
||||
});
|
||||
|
||||
function loadId(id, callback) {
|
||||
// Add built-in log types for now
|
||||
var BUILT_IN_LOGS = [
|
||||
{ name: 'Box', type: 'platform', value: 'box', url: Client.makeURL('/api/v1/cloudron/logs/box') },
|
||||
{ name: 'Mail', type: 'platform', value: 'mail', url: Client.makeURL('/api/v1/cloudron/logs/mail') },
|
||||
{ name: 'Backup', type: 'platform', value: 'backup', url: Client.makeURL('/api/v1/cloudron/logs/backup') }
|
||||
];
|
||||
|
||||
$scope.selected = BUILT_IN_LOGS.find(function (e) { return e.value === id; });
|
||||
if ($scope.selected) return callback();
|
||||
|
||||
Client.getApp(id, function (error, app) {
|
||||
if (error) return callback(error);
|
||||
|
||||
$scope.selected = {
|
||||
type: 'app',
|
||||
value: app.id,
|
||||
name: app.fqdn + ' (' + app.manifest.title + ')',
|
||||
url: Client.makeURL('/api/v1/apps/' + app.id + '/logs'),
|
||||
addons: app.manifest.addons
|
||||
};
|
||||
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
Client.getStatus(function (error, status) {
|
||||
if (error) return $scope.error(error);
|
||||
|
||||
@@ -105,23 +125,9 @@ app.controller('LogsController', ['$scope', '$timeout', '$location', 'Client', f
|
||||
Client.refreshConfig(function (error) {
|
||||
if (error) return $scope.error(error);
|
||||
|
||||
Client.refreshInstalledApps(function (error) {
|
||||
loadId(search.id, function (error) {
|
||||
if (error) return $scope.error(error);
|
||||
|
||||
Client.getInstalledApps().forEach(function (app) {
|
||||
$scope.logs.push({
|
||||
type: 'app',
|
||||
value: app.id,
|
||||
name: app.fqdn + ' (' + app.manifest.title + ')',
|
||||
url: Client.makeURL('/api/v1/apps/' + app.id + '/logs'),
|
||||
addons: app.manifest.addons
|
||||
});
|
||||
});
|
||||
|
||||
// activate pre-selected log from query otherwise choose the first one
|
||||
$scope.selected = $scope.logs.find(function (e) { return e.value === search.id; });
|
||||
if (!$scope.selected) $scope.selected = $scope.logs[0];
|
||||
|
||||
// now mark the Client to be ready
|
||||
Client.setReady();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user