mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 07:19:41 +02:00
- code cleanup by converting functions to error funcs (remove this bindings) (#5595)
- remove redundant checked variable - detect readyState of websocket when closing to prevent redundant error
This commit is contained in:
parent
9f179fe3ec
commit
79ca51c92e
2 changed files with 23 additions and 23 deletions
|
@ -13,13 +13,14 @@ export default class KubectlShellController {
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
this.state.checked = false;
|
if (this.state.shell.connected) {
|
||||||
this.state.icon = 'fas fa-window-minimize';
|
this.state.shell.connected = false;
|
||||||
this.state.shell.socket.close();
|
this.state.icon = 'fas fa-window-minimize';
|
||||||
this.state.shell.term.dispose();
|
this.state.shell.socket.close();
|
||||||
this.state.shell.connected = false;
|
this.state.shell.term.dispose();
|
||||||
this.TerminalWindow.terminalclose();
|
this.TerminalWindow.terminalclose();
|
||||||
this.$window.onresize = null;
|
this.$window.onresize = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
screenClear() {
|
screenClear() {
|
||||||
|
@ -39,8 +40,7 @@ export default class KubectlShellController {
|
||||||
}
|
}
|
||||||
|
|
||||||
configureSocketAndTerminal(socket, term) {
|
configureSocketAndTerminal(socket, term) {
|
||||||
var vm = this;
|
socket.onopen = () => {
|
||||||
socket.onopen = function () {
|
|
||||||
const terminal_container = document.getElementById('terminal-container');
|
const terminal_container = document.getElementById('terminal-container');
|
||||||
term.open(terminal_container);
|
term.open(terminal_container);
|
||||||
term.setOption('cursorBlink', true);
|
term.setOption('cursorBlink', true);
|
||||||
|
@ -51,31 +51,32 @@ export default class KubectlShellController {
|
||||||
term.writeln('');
|
term.writeln('');
|
||||||
};
|
};
|
||||||
|
|
||||||
term.on('data', function (data) {
|
term.on('data', (data) => {
|
||||||
socket.send(data);
|
socket.send(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$window.onresize = function () {
|
socket.onmessage = (msg) => {
|
||||||
vm.TerminalWindow.terminalresize();
|
|
||||||
};
|
|
||||||
|
|
||||||
socket.onmessage = function (msg) {
|
|
||||||
term.write(msg.data);
|
term.write(msg.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
socket.onerror = function (err) {
|
socket.onerror = (err) => {
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
this.Notifications.error('Failure', err, 'Websocket connection error');
|
if (err.target.readyState !== WebSocket.CLOSED) {
|
||||||
}.bind(this);
|
this.Notifications.error('Failure', err, 'Websocket connection error');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.state.shell.socket.onclose = this.disconnect.bind(this);
|
this.$window.onresize = () => {
|
||||||
|
this.TerminalWindow.terminalresize();
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.onclose = this.disconnect.bind(this);
|
||||||
|
|
||||||
this.state.shell.connected = true;
|
this.state.shell.connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
connectConsole() {
|
connectConsole() {
|
||||||
this.TerminalWindow.terminalopen();
|
this.TerminalWindow.terminalopen();
|
||||||
this.state.checked = true;
|
|
||||||
this.state.css = 'normal';
|
this.state.css = 'normal';
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
|
@ -101,7 +102,6 @@ export default class KubectlShellController {
|
||||||
return this.$async(async () => {
|
return this.$async(async () => {
|
||||||
this.state = {
|
this.state = {
|
||||||
css: 'normal',
|
css: 'normal',
|
||||||
checked: false,
|
|
||||||
icon: 'fa-window-minimize',
|
icon: 'fa-window-minimize',
|
||||||
shell: {
|
shell: {
|
||||||
connected: false,
|
connected: false,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
<kube-config-download-button></kube-config-download-button>
|
<kube-config-download-button></kube-config-download-button>
|
||||||
|
|
||||||
<div ng-if="$ctrl.state.checked" class="{{ $ctrl.state.css }}-kubectl-shell">
|
<div ng-if="$ctrl.state.shell.connected" class="{{ $ctrl.state.css }}-kubectl-shell">
|
||||||
<div class="shell-container">
|
<div class="shell-container">
|
||||||
<div class="shell-item"><i class="fas fa-terminal" style="margin-right: 5px;"></i>kubectl shell</div>
|
<div class="shell-item"><i class="fas fa-terminal" style="margin-right: 5px;"></i>kubectl shell</div>
|
||||||
<div class="shell-item-right">
|
<div class="shell-item-right">
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div style="padding: 0px;">
|
<div class="nopadding">
|
||||||
<div>
|
<div>
|
||||||
<div id="terminal-container" class="terminal-container">
|
<div id="terminal-container" class="terminal-container">
|
||||||
<div style="position: fixed; color: #fff;">Loading Terminal...</div>
|
<div style="position: fixed; color: #fff;">Loading Terminal...</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue