1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
<template>
<section class="section is-fullheight dashboard">
<div class="container">
<div class="columns">
<div class="column is-narrow">
<Sidebar />
</div>
<div class="column">
<h2 class="subtitle">
Statistics
</h2>
<hr>
<template v-for="category in Object.keys(stats)">
<div :key="category"
class="stats-container">
<h2 class="title">
{{ category }} <span v-if="stats[category].meta" class="is-size-7 is-pulled-right is-family-monospace has-text-grey-light">
generated on {{ stats[category].meta.generatedOn }}
<b-icon class="is-pulled-right ml1 is-clickable"
size="is-small"
icon="reload"
@click.native="refresh(category)" />
</span>
</h2>
<template v-for="item in Object.keys(stats[category])">
<!-- If it's plain text or a number, just print it -->
<template v-if="typeof stats[category][item] === 'string' || typeof stats[category][item] === 'number'">
<generic :key="item"
:title="item"
:value="stats[category][item]" />
</template>
<!-- If it's an object then we need to do some magic -->
<template v-else-if="typeof stats[category][item] === 'object' && stats[category][item].type !== 'hidden'">
<byteUsage v-if="stats[category][item].type === 'byteUsage'"
:key="item"
:title="item"
:used="stats[category][item].value.used"
:total="stats[category][item].value.total" />
<byte v-else-if="stats[category][item].type === 'byte'"
:key="item"
:title="item"
:value="stats[category][item].value" />
<beat v-else-if="stats[category][item].type === 'time'"
:key="item"
:title="item"
:value="stats[category][item].value" />
<detailed v-else-if="stats[category][item].type === 'detailed'"
:key="item"
:title="item"
:data="stats[category][item].data" />
</template>
</template>
</div>
</template>
</div>
</div>
</div>
</section>
</template>
<script>
import { mapState } from 'vuex';
import Sidebar from '~/components/sidebar/Sidebar.vue';
import byteUsage from '~/components/statistics/byteUsage.vue';
import byte from '~/components/statistics/byte.vue';
import beat from '~/components/statistics/time.vue';
import detailed from '~/components/statistics/detailed.vue';
import generic from '~/components/statistics/generic.vue';
export default {
components: {
Sidebar,
byteUsage,
byte,
beat,
detailed,
generic
},
middleware: ['auth', 'admin', ({ store }) => {
try {
store.dispatch('admin/fetchStatistics');
} catch (e) {
console.error(e);
}
}],
computed: mapState({
stats: state => state.admin.statistics
}),
methods: {
refresh(category) {
try {
this.$store.dispatch('admin/fetchStatistics', category);
} catch (error) {
this.$notifier.error(error.message);
}
}
},
head() {
return {
title: 'Service statistics'
};
}
};
</script>
<style lang="scss" scoped>
@import '~/assets/styles/_colors.scss';
h2.title {
color: $defaultTextColor;
}
div.stats-container {
padding: 1rem;
background: #1c1e23;
box-shadow: rgba(15, 17, 21, 0.35) 0px 6px 9px 0px;
margin-bottom: 1rem;
}
</style>
|