diff --git a/webadmin/src/theme.scss b/webadmin/src/theme.scss index 010914c02..589076f61 100644 --- a/webadmin/src/theme.scss +++ b/webadmin/src/theme.scss @@ -1141,16 +1141,6 @@ footer { width: 250px; margin-left: 20px; } - - .uib-tab.active { - a { - background-color: white; - - &:hover, &:focus { - background-color: white; - } - } - } } .logs-container { @@ -1177,7 +1167,33 @@ footer { } } -.logs-and-term-container { + +// ---------------------------- +// Terminal +// ---------------------------- + +.terminal-controls { + margin-top: 25px; + margin-bottom: 10px; + + .ng-isolate-scope { + float: left; + } + + h3 { + display: inline-block; + margin-top: 6px; + margin-bottom: 0; + } + + select { + display: inline-block; + width: 250px; + margin-left: 20px; + } +} + +.terminal-container { flex-grow: 1; margin-left: calc(8.33% + 15px); margin-right: calc(8.33% + 15px); @@ -1188,22 +1204,6 @@ footer { padding: 5px; font-family: monospace; - .log-line { - line-height: 1.2; - - &:hover { - background-color: #333333; - } - - .time { - color: #00FFFF; - } - } - - .dont-overflow { - overflow: hidden; - } - &.placeholder { display: flex; justify-content: center; diff --git a/webadmin/src/views/debug.html b/webadmin/src/views/debug.html index b814f6b10..0bd11e55f 100644 --- a/webadmin/src/views/debug.html +++ b/webadmin/src/views/debug.html @@ -65,41 +65,37 @@ -
+
- - - - - - - - Download Logs +

Terminal

+
- + - - + +
- - - - + + + +
-
-
+
+

  Restarting app for repair... App is being reconfigured... diff --git a/webadmin/src/views/debug.js b/webadmin/src/views/debug.js index 01fa0dd2b..25bbcc899 100644 --- a/webadmin/src/views/debug.js +++ b/webadmin/src/views/debug.js @@ -1,30 +1,21 @@ 'use strict'; -/* global moment */ /* global Terminal */ - angular.module('Application').controller('DebugController', ['$scope', '$location', 'Client', function ($scope, $location, Client) { Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); }); $scope.config = Client.getConfig(); $scope.user = Client.getUserInfo(); - $scope.terminalVisible = true; - $scope.logs = []; + $scope.apps = []; $scope.selected = ''; - $scope.activeEventSource = null; $scope.terminal = null; $scope.terminalSocket = null; - $scope.lines = 10; $scope.restartAppBusy = false; $scope.appBusy = false; $scope.selectedAppInfo = null; - function ab2str(buf) { - return String.fromCharCode.apply(null, new Uint16Array(buf)); - } - $scope.downloadFile = { error: '', filePath: '', @@ -105,22 +96,17 @@ angular.module('Application').controller('DebugController', ['$scope', '$locatio fileUpload.click(); }; - $scope.populateLogTypes = function () { - $scope.logs.push({ name: 'System (All)', type: 'platform', value: 'all', url: Client.makeURL('/api/v1/cloudron/logs?units=all') }); - $scope.logs.push({ name: 'Box', type: 'platform', value: 'box', url: Client.makeURL('/api/v1/cloudron/logs?units=box') }); - $scope.logs.push({ name: 'Mail', type: 'platform', value: 'mail', url: Client.makeURL('/api/v1/cloudron/logs?units=mail') }); - + $scope.populateDropdown = function () { Client.getInstalledApps().sort(function (app1, app2) { return app1.fqdn.localeCompare(app2.fqdn); }).forEach(function (app) { - $scope.logs.push({ + $scope.apps.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 }); }); - $scope.selected = $scope.logs[0]; + // $scope.selected = $scope.apps[0]; }; $scope.usesAddon = function (addon) { @@ -129,15 +115,6 @@ angular.module('Application').controller('DebugController', ['$scope', '$locatio }; function reset() { - // close the old event source so we wont receive any new logs - if ($scope.activeEventSource) { - $scope.activeEventSource.close(); - $scope.activeEventSource = null; - } - - var logViewer = $('#logsAndTerminalContainer'); - logViewer.empty(); - if ($scope.terminal) { $scope.terminal.destroy(); $scope.terminal = null; @@ -212,63 +189,17 @@ angular.module('Application').controller('DebugController', ['$scope', '$locatio }); }; - $scope.showLogs = function () { - $scope.terminalVisible = false; - - reset(); - - if (!$scope.selected) return; - - var func = $scope.selected.type === 'platform' ? Client.getPlatformLogs : Client.getAppLogs; - func($scope.selected.value, true, $scope.lines, function handleLogs(error, result) { - if (error) return console.error(error); - - $scope.activeEventSource = result; - result.onmessage = function handleMessage(message) { - var data; - - try { - data = JSON.parse(message.data); - } catch (e) { - return console.error(e); - } - - // check if we want to auto scroll (this is before the appending, as that skews the check) - var tmp = $('#logsAndTerminalContainer'); - var autoScroll = tmp[0].scrollTop > (tmp[0].scrollTopMax - 24); - - var logLine = $('
'); - var timeString = moment.utc(data.realtimeTimestamp/1000).format('MMM DD HH:mm:ss'); - logLine.html('' + timeString + ' ' + window.ansiToHTML(typeof data.message === 'string' ? data.message : ab2str(data.message))); - tmp.append(logLine); - - if (autoScroll) tmp[0].lastChild.scrollIntoView({ behavior: 'instant', block: 'end' }); - }; - }); - }; - $scope.showTerminal = function (retry) { - $scope.terminalVisible = true; - reset(); if (!$scope.selected) return; - // we can only connect to apps here - if ($scope.selected.type !== 'app') { - var tmp = $('#logsAndTerminalContainer'); - var logLine = $('
'); - logLine.html('Terminal is only supported for apps, not for ' + $scope.selected.name); - tmp.append(logLine); - return; - } - // fetch current app state Client.refreshInstalledApps(function (error) { if (error) console.error(error); $scope.terminal = new Terminal(); - $scope.terminal.open(document.querySelector('#logsAndTerminalContainer')); + $scope.terminal.open(document.querySelector('#terminalContainer')); $scope.terminal.fit(); try { @@ -282,7 +213,7 @@ angular.module('Application').controller('DebugController', ['$scope', '$locatio $scope.terminalReconnectTimeout = setTimeout(function () { // if the scope was already destroyed, do not reconnect if ($scope.$$destroyed) return; - if ($scope.terminalVisible) $scope.showTerminal(true); + $scope.showTerminal(true); }, 1000); }; @@ -319,11 +250,10 @@ angular.module('Application').controller('DebugController', ['$scope', '$locatio $scope.$watch('selected', function (newVal) { if (!newVal) return; - if ($scope.terminalVisible) $scope.showTerminal(); - else $scope.showLogs(); + $scope.showTerminal(); }); - Client.onReady($scope.populateLogTypes); + Client.onReady($scope.populateDropdown); Client.onApps(function () { if ($scope.$$destroyed) return; @@ -346,12 +276,6 @@ angular.module('Application').controller('DebugController', ['$scope', '$locatio }); $scope.$on('$destroy', function () { - if ($scope.activeEventSource) { - $scope.activeEventSource.onmessage = function () {}; - $scope.activeEventSource.close(); - $scope.activeEventSource = null; - } - if ($scope.terminal) { $scope.terminal.destroy(); } @@ -381,7 +305,7 @@ angular.module('Application').controller('DebugController', ['$scope', '$locatio $scope.terminal.focus(); }); - $('#logsAndTerminalContainer').on('contextmenu', function (e) { + $('#terminalContainer').on('contextmenu', function (e) { if (!$scope.terminal) return true; e.preventDefault(); diff --git a/webadmin/src/views/logs.js b/webadmin/src/views/logs.js index 164d5aaa9..128a0510b 100644 --- a/webadmin/src/views/logs.js +++ b/webadmin/src/views/logs.js @@ -1,7 +1,6 @@ 'use strict'; /* global moment */ -/* global Terminal */ angular.module('Application').controller('LogsController', ['$scope', '$location', '$route', '$routeParams', 'Client', function ($scope, $location, $route, $routeParams, Client) { Client.onReady(function () { if (!Client.getUserInfo().admin) $location.path('/'); });