|
| 1 | +import Vue from 'vue'; |
| 2 | +import Navigation from '../core/Navigation'; |
| 3 | +import ProgressBar from './components/ProgressBar'; |
| 4 | +import { mapState } from 'vuex'; |
| 5 | +import * as io from 'socket.io-client'; |
| 6 | + |
| 7 | +export default Vue.component('server', { |
| 8 | + components: { ProgressBar, Navigation }, |
| 9 | + computed: { |
| 10 | + ...mapState('server', ['server', 'credentials']), |
| 11 | + ...mapState('socket', ['connected', 'connectionError']), |
| 12 | + }, |
| 13 | + |
| 14 | + // Watch for route changes that occur with different server parameters. This occurs when a user |
| 15 | + // uses the search bar. Because of the way vue-router works, it won't re-mount the server component |
| 16 | + // so we will end up seeing the wrong server data if we don't perform this watch. |
| 17 | + watch: { |
| 18 | + '$route': function (toRoute, fromRoute) { |
| 19 | + if (toRoute.params.id !== fromRoute.params.id) { |
| 20 | + this.loadingServerData = true; |
| 21 | + this.loadServer(); |
| 22 | + } |
| 23 | + } |
| 24 | + }, |
| 25 | + |
| 26 | + data: function () { |
| 27 | + return { |
| 28 | + loadingServerData: true, |
| 29 | + }; |
| 30 | + }, |
| 31 | + |
| 32 | + mounted: function () { |
| 33 | + this.loadServer(); |
| 34 | + }, |
| 35 | + |
| 36 | + beforeDestroy: function () { |
| 37 | + this.removeSocket(); |
| 38 | + }, |
| 39 | + |
| 40 | + methods: { |
| 41 | + /** |
| 42 | + * Load the core server information needed for these pages to be functional. |
| 43 | + */ |
| 44 | + loadServer: function () { |
| 45 | + Promise.all([ |
| 46 | + this.$store.dispatch('server/getServer', {server: this.$route.params.id}), |
| 47 | + this.$store.dispatch('server/getCredentials', {server: this.$route.params.id}) |
| 48 | + ]) |
| 49 | + .then(() => { |
| 50 | + // Configure the socket.io implementation. This is a really ghetto way of handling things |
| 51 | + // but all of these plugins assume you have some constant connection, which we don't. |
| 52 | + const socket = io(`${this.credentials.node}/v1/ws/${this.server.uuid}`, { |
| 53 | + query: `token=${this.credentials.key}`, |
| 54 | + }); |
| 55 | + |
| 56 | + this.$socket().connect(socket); |
| 57 | + this.loadingServerData = false; |
| 58 | + }) |
| 59 | + .catch(err => { |
| 60 | + console.error('There was an error performing Server::loadServer', { err }); |
| 61 | + }); |
| 62 | + }, |
| 63 | + }, |
| 64 | + |
| 65 | + template: ` |
| 66 | + <div> |
| 67 | + <navigation></navigation> |
| 68 | + <flash class="m-6"/> |
| 69 | + <div v-if="loadingServerData"> |
| 70 | + <div class="mt-6 h-16"> |
| 71 | + <div class="spinner spinner-xl spinner-thick blue"></div> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + <div v-else> |
| 75 | + <div class="m-6 flex flex-no-shrink rounded animate fadein"> |
| 76 | + <div class="sidebar border-grey-lighter flex-no-shrink w-1/3 max-w-xs"> |
| 77 | + <div class="mr-6"> |
| 78 | + <div class="p-6 text-center bg-white border rounded"> |
| 79 | + <h3 class="mb-2 text-blue font-medium">{{server.name}}</h3> |
| 80 | + <span class="text-grey-dark text-sm">{{server.node}}</span> |
| 81 | + <power-buttons class="mt-6 pt-6 text-center border-t border-grey-lighter"/> |
| 82 | + </div> |
| 83 | + </div> |
| 84 | + <div class="mt-6 sidenav mr-6 bg-white border rounded"> |
| 85 | + <router-link :to="{ name: 'server', params: { id: $route.params.id } }"> |
| 86 | + <terminal-icon class="h-4"></terminal-icon> Console |
| 87 | + </router-link> |
| 88 | + <router-link :to="{ name: 'server-files' }"> |
| 89 | + <folder-icon class="h-4"></folder-icon> Files |
| 90 | + </router-link> |
| 91 | + <router-link :to="{ name: 'server-subusers' }"> |
| 92 | + <users-icon class="h-4"></users-icon> Subusers |
| 93 | + </router-link> |
| 94 | + <router-link :to="{ name: 'server-schedules' }"> |
| 95 | + <calendar-icon class="h-4"></calendar-icon> Schedules |
| 96 | + </router-link> |
| 97 | + <router-link :to="{ name: 'server-databases' }"> |
| 98 | + <database-icon class="h-4"></database-icon> Databases |
| 99 | + </router-link> |
| 100 | + <router-link :to="{ name: 'server-allocations' }"> |
| 101 | + <globe-icon class="h-4"></globe-icon> Allocations |
| 102 | + </router-link> |
| 103 | + <router-link :to="{ name: 'server-settings' }"> |
| 104 | + <settings-icon class="h-4"></settings-icon> Settings |
| 105 | + </router-link> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + <div class="h-full w-full"> |
| 109 | + <router-view :key="server.identifier"></router-view> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | + <div class="fixed pin-r pin-b m-6 max-w-sm" v-show="connectionError"> |
| 114 | + <div class="alert error"> |
| 115 | + There was an error while attempting to connect to the Daemon websocket. Error reported was: "{{connectionError.message}}" |
| 116 | + </div> |
| 117 | + </div> |
| 118 | + </div> |
| 119 | + `, |
| 120 | +}); |
0 commit comments