Skip to content

Commit 034e759

Browse files
committed
Show a spinner on the console when loading the contents initially
1 parent 71d2a64 commit 034e759

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

resources/assets/scripts/components/server/Server.vue

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</div>
2626
</div>
2727
<div class="sidenav">
28-
<router-link :to="{ name: '', params: { id: this.$route.params.id } }">
28+
<router-link :to="{ name: 'server', params: { id: this.$route.params.id } }">
2929
<terminal-icon style="height: 1em;"></terminal-icon>
3030
Console
3131
</router-link>
@@ -67,13 +67,12 @@
6767
import Navigation from '../core/Navigation';
6868
import ProgressBar from './components/ProgressBar';
6969
import {mapState} from 'vuex';
70-
import { ConsolePage } from './subpages/ConsolePage';
7170
7271
import io from 'socket.io-client';
7372
7473
export default {
7574
components: {
76-
ProgressBar, Navigation, ConsolePage, TerminalIcon, FolderIcon, UsersIcon,
75+
ProgressBar, Navigation, TerminalIcon, FolderIcon, UsersIcon,
7776
CalendarIcon, DatabaseIcon, GlobeIcon, SettingsIcon
7877
},
7978
@@ -87,6 +86,10 @@
8786
this.$on('send-command', data => {
8887
this.socket.emit('send command', data);
8988
});
89+
90+
this.$on('send-initial-log', () => {
91+
this.socket.emit('send server log');
92+
})
9093
},
9194
9295
data: function () {
@@ -126,14 +129,15 @@
126129
},
127130
128131
_socket_error: function (err) {
129-
console.error('there was a socket error:', err);
132+
this.$emit('socket-error', {err});
130133
},
131134
132135
_socket_connect: function () {
133-
this.socket.emit('send server log');
136+
this.$emit('socket-connected');
134137
},
135138
136139
_socket_status: function (data) {
140+
this.$emit('socket-status', {data});
137141
},
138142
139143
_socket_serverLog: function (data) {

resources/assets/scripts/components/server/subpages/ConsolePage.vue

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<div>
33
<div class="text-xs font-mono">
44
<div class="rounded-t p-2 bg-black overflow-scroll w-full" style="min-height: 16rem;max-height:64rem;">
5+
<div v-if="loadingConsole">
6+
<div class="spinner spinner-xl mt-24"></div>
7+
</div>
58
<div class="mb-2 text-grey-light" ref="terminal"></div>
69
</div>
710
<div class="rounded-b bg-grey-darkest text-white flex">
@@ -24,19 +27,36 @@
2427
<script>
2528
import { Terminal } from 'xterm';
2629
import * as TerminalFit from 'xterm/lib/addons/fit/fit';
30+
import Status from './../../../helpers/statuses';
2731
2832
Terminal.applyAddon(TerminalFit);
2933
3034
export default {
3135
name: 'console-page',
3236
37+
/**
38+
* Mount the component and setup all of the terminal actions. Also fetches the initial
39+
* logs from the server to populate into the terminal.
40+
*/
3341
mounted: function () {
34-
this.terminal.open(this.$refs.terminal);
35-
this.terminal.fit();
42+
this.$parent.$on('socket-connected', () => {
43+
this.terminal.open(this.$refs.terminal);
44+
this.terminal.fit();
45+
this.terminal.clear();
46+
47+
this.$parent.$emit('send-initial-log');
48+
});
3649
3750
this.$parent.$on('console', data => {
51+
this.loadingConsole = false;
3852
this.terminal.writeln(data);
3953
});
54+
55+
this.$parent.$on('socket-status', s => {
56+
if (s === Status.STATUS_OFF) {
57+
this.loadingConsole = false;
58+
}
59+
});
4060
},
4161
4262
data: function () {
@@ -56,10 +76,14 @@
5676
command: '',
5777
commandHistory: [],
5878
commandHistoryIndex: -1,
79+
loadingConsole: true,
5980
};
6081
},
6182
6283
methods: {
84+
/**
85+
* Send a command to the server using the configured websocket.
86+
*/
6387
sendCommand: function () {
6488
this.commandHistoryIndex = -1;
6589
this.commandHistory.unshift(this.command);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
STATUS_OFF: 0,
3+
STATUS_ON: 1,
4+
STATUS_STARTING: 2,
5+
STATUS_STOPPING: 3,
6+
};

0 commit comments

Comments
 (0)