Skip to content

Commit 9831adb

Browse files
committed
Cleanup dashboard, make flash more customizable for pages
1 parent caa0d21 commit 9831adb

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

resources/assets/scripts/components/Flash.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
<template>
2-
<div v-if="notifications.length > 0">
3-
<transition-group tag="div" class="mb-2" name="fade">
4-
<div :class="item.class" class="lg:inline-flex mb-2" role="alert" :key="index" v-for="(item, index) in notifications">
2+
<div v-if="notifications.length > 0" :class="this.container">
3+
<transition-group tag="div" name="fade">
4+
<div class="lg:inline-flex" role="alert" v-for="(item, index) in notifications"
5+
:key="index"
6+
:class="[item.class, {
7+
'mb-2': index < notifications.length - 1
8+
}]"
9+
>
510
<span class="title" v-html="item.title" v-if="item.title.length > 0"></span>
611
<span class="message" v-html="item.message"></span>
712
</div>
@@ -13,6 +18,10 @@
1318
export default {
1419
name: 'flash',
1520
props: {
21+
container: {
22+
type: String,
23+
default: '',
24+
},
1625
timeout: {
1726
type: Number,
1827
default: 0,

resources/assets/scripts/components/dashboard/Dashboard.vue

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
<template>
22
<div>
3+
<flash container="mt-4"/>
34
<div class="server-search animate fadein">
4-
<input type="text" placeholder="search for servers..."
5+
<input type="text"
6+
:placeholder="$t('dashboard.index.search')"
57
@input="onChange"
68
v-model="search"
79
ref="search"
810
/>
911
</div>
10-
<transition-group class="w-full m-auto mt-4 animate fadein sm:flex flex-wrap content-start">
11-
<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">
1219
<router-link :to="{ name: 'server', params: { id: server.identifier }}" class="content">
1320
<div class="float-right">
1421
<div class="indicator"></div>
@@ -20,10 +27,10 @@
2027
</div>
2128
<div class="mb-0 flex">
2229
<div class="usage">
23-
<div class="indicator-title">CPU</div>
30+
<div class="indicator-title">{{ $t('dashboard.index.cpu_title') }}</div>
2431
</div>
2532
<div class="usage">
26-
<div class="indicator-title">Memory</div>
33+
<div class="indicator-title">{{ $t('dashboard.index.memory_title') }}</div>
2734
</div>
2835
</div>
2936
<div class="mb-4 flex text-center">
@@ -51,11 +58,14 @@
5158
<script>
5259
import { ServerCollection } from '../../models/server';
5360
import _ from 'lodash';
61+
import Flash from '../Flash';
5462
5563
export default {
5664
name: 'dashboard',
65+
components: { Flash },
5766
data: function () {
5867
return {
68+
loading: true,
5969
search: '',
6070
servers: new ServerCollection,
6171
}
@@ -72,17 +82,34 @@
7282
* @param {string} query
7383
*/
7484
loadServers: function (query = '') {
85+
this.loading = true;
7586
window.axios.get(this.route('api.client.index'), {
7687
params: { query },
7788
})
89+
.finally(() => {
90+
this.clearFlashes();
91+
})
7892
.then(response => {
7993
this.servers = new ServerCollection;
8094
response.data.data.forEach(obj => {
8195
this.servers.add(obj.attributes);
8296
});
97+
98+
if (this.servers.models.length === 0) {
99+
this.info(this.$t('dashboard.index.no_matches'));
100+
}
101+
})
102+
.catch(err => {
103+
console.error(err);
104+
const response = err.response;
105+
if (response.data && _.isObject(response.data.errors)) {
106+
response.data.errors.forEach(function (error) {
107+
this.error(error.detail);
108+
});
109+
}
83110
})
84-
.catch(error => {
85-
console.error(error);
111+
.finally(() => {
112+
this.loading = false;
86113
});
87114
},
88115

resources/assets/styles/components/spinners.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
position: relative;
55

66
&:after {
7+
@apply .border-2 .border-grey-light .absolute .block;
78
animation: spinners--spin 500ms infinite linear;
89
border-radius: 9999px;
9-
@apply .border-2 .border-grey-light;
1010
border-top-color: transparent !important;
1111
border-right-color: transparent !important;
1212
content: '';
13-
display: block;
1413
width: 1em;
1514
height: 1em;
1615
left: calc(50% - (1em / 2));
1716
top: calc(50% - (1em / 2));
18-
position: absolute !important;
17+
}
18+
19+
&.spinner-xl:after {
20+
@apply .h-16 .w-16;
21+
left: calc(50% - (4rem / 2));
1922
}
2023

2124
/**
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'search' => 'Search for servers...',
5+
'no_matches' => 'There were no servers found matching the search criteria provided.',
6+
'cpu_title' => 'CPU',
7+
'memory_title' => 'Memory',
8+
];

0 commit comments

Comments
 (0)