|
1 | 1 | <template> |
2 | 2 | <div> |
| 3 | + <flash container="mt-4"/> |
3 | 4 | <div class="server-search animate fadein"> |
4 | | - <input type="text" placeholder="search for servers..." |
| 5 | + <input type="text" |
| 6 | + :placeholder="$t('dashboard.index.search')" |
5 | 7 | @input="onChange" |
6 | 8 | v-model="search" |
7 | 9 | ref="search" |
8 | 10 | /> |
9 | 11 | </div> |
10 | | - <transition-group class="w-full m-auto mt-4 animate fadein sm:flex flex-wrap content-start"><div class="server-box" :key="index" v-for="(server, index) in servers.models"> |
| 12 | + <div v-if="this.loading" class="my-4 animate fadein"> |
| 13 | + <div class="text-center h-16"> |
| 14 | + <span class="spinner spinner-xl"></span> |
| 15 | + </div> |
| 16 | + </div> |
| 17 | + <transition-group class="w-full m-auto mt-4 animate fadein sm:flex flex-wrap content-start" v-else> |
| 18 | + <div class="server-box animate fadein" :key="index" v-for="(server, index) in servers.models"> |
11 | 19 | <router-link :to="{ name: 'server', params: { id: server.identifier }}" class="content"> |
12 | 20 | <div class="float-right"> |
13 | 21 | <div class="indicator"></div> |
|
19 | 27 | </div> |
20 | 28 | <div class="mb-0 flex"> |
21 | 29 | <div class="usage"> |
22 | | - <div class="indicator-title">CPU</div> |
| 30 | + <div class="indicator-title">{{ $t('dashboard.index.cpu_title') }}</div> |
23 | 31 | </div> |
24 | | - <div class="mb-4"> |
25 | | - <div class="text-black font-bold text-xl">{{ server.name }}</div> |
| 32 | + <div class="usage"> |
| 33 | + <div class="indicator-title">{{ $t('dashboard.index.memory_title') }}</div> |
26 | 34 | </div> |
27 | 35 | <div class="mb-0 flex"> |
28 | 36 | <div class="usage"> |
|
58 | 66 | <script> |
59 | 67 | import { ServerCollection } from '../../models/server'; |
60 | 68 | import _ from 'lodash'; |
| 69 | + import Flash from '../Flash'; |
61 | 70 |
|
62 | 71 | export default { |
63 | 72 | name: 'dashboard', |
| 73 | + components: { Flash }, |
64 | 74 | data: function () { |
65 | 75 | return { |
| 76 | + loading: true, |
66 | 77 | search: '', |
67 | 78 | servers: new ServerCollection, |
68 | 79 | } |
|
79 | 90 | * @param {string} query |
80 | 91 | */ |
81 | 92 | loadServers: function (query = '') { |
| 93 | + this.loading = true; |
82 | 94 | window.axios.get(this.route('api.client.index'), { |
83 | 95 | params: { query }, |
84 | 96 | }) |
| 97 | + .finally(() => { |
| 98 | + this.clearFlashes(); |
| 99 | + }) |
85 | 100 | .then(response => { |
86 | 101 | this.servers = new ServerCollection; |
87 | 102 | response.data.data.forEach(obj => { |
88 | 103 | this.servers.add(obj.attributes); |
89 | 104 | }); |
| 105 | +
|
| 106 | + if (this.servers.models.length === 0) { |
| 107 | + this.info(this.$t('dashboard.index.no_matches')); |
| 108 | + } |
| 109 | + }) |
| 110 | + .catch(err => { |
| 111 | + console.error(err); |
| 112 | + const response = err.response; |
| 113 | + if (response.data && _.isObject(response.data.errors)) { |
| 114 | + response.data.errors.forEach(function (error) { |
| 115 | + this.error(error.detail); |
| 116 | + }); |
| 117 | + } |
90 | 118 | }) |
91 | | - .catch(error => { |
92 | | - console.error(error); |
| 119 | + .finally(() => { |
| 120 | + this.loading = false; |
93 | 121 | }); |
94 | 122 | }, |
95 | 123 |
|
|
0 commit comments