Added graphical statistics to domain detail page.

This commit is contained in:
Antoine Nguyen
2021-03-12 15:52:54 +01:00
parent a9ed6b0fcb
commit 841442ca4c
15 changed files with 461 additions and 30 deletions
+17
View File
@@ -0,0 +1,17 @@
import repository from './repository'
const resource = 'statistics'
export default {
getStatistics ({ graphSet, period, graphicName, searchQuery, start, end }) {
const args = {
gset: graphSet,
period,
graphic: graphicName,
searchquery: searchQuery,
start: start,
end: end
}
return repository.get(`${resource}/`, { params: args })
}
}
@@ -1,5 +1,8 @@
<template>
<v-card>
<v-card-title>
<translate class="headline">General information</translate>
</v-card-title>
<v-card-text>
<v-row>
<v-col cols="6"><translate>Creation date</translate></v-col>
@@ -0,0 +1,43 @@
<template>
<v-menu
v-model="menu"
:close-on-content-click="false"
transition="scale-transition"
offset-y
min-width="auto"
>
<template v-slot:activator="{ on, attrs }">
<v-text-field
:value="value"
:label="label"
prepend-icon="mdi-calendar"
readonly
v-bind="attrs"
v-on="on"
></v-text-field>
</template>
<v-date-picker
:value="value"
@input="update"
no-title
>
</v-date-picker>
</v-menu>
</template>
<script>
export default {
props: ['value', 'label'],
data () {
return {
menu: false
}
},
methods: {
update (value) {
this.$emit('input', value)
this.menu = false
}
}
}
</script>
@@ -0,0 +1,162 @@
<template>
<v-card>
<v-toolbar dense elevation="0">
<v-toolbar-title>{{ title }}</v-toolbar-title>
<v-spacer />
<v-menu
v-model="menu"
:nudge-width="200"
offset-y
>
<template v-slot:activator="{ on, attrs }">
<v-btn
small
v-bind="attrs"
v-on="on"
>
<v-icon small>mdi-calendar</v-icon>
<translate>Period</translate>
<span v-if="period">: {{ period }}</span>
</v-btn>
</template>
<v-layout>
<v-row>
<v-col cols="6" class="d-flex flex-column align-start py-3 px-6">
<translate class="subtitle">Absolute time range</translate>
<date-field v-model="start" :label="'From'|translate" />
<date-field v-model="end" :label="'To'|translate" />
<v-btn color="primary" @click="setCustomPeriod"><translate>Apply</translate></v-btn>
</v-col>
<v-col cols="6">
<translate class="subtitle">Relative time ranges</translate>
<v-list>
<v-list-item
v-for="period in periods"
:key="period.value"
@click="setPeriod(period.value)"
>
<v-list-item-title>{{ period.name }}</v-list-item-title>
</v-list-item>
</v-list>
</v-col>
</v-row>
</v-layout>
</v-menu>
</v-toolbar>
<v-card-text>
<apexchart
v-if="statistics"
type="area"
height="350"
:options="options"
:series="statistics.series"
/>
</v-card-text>
</v-card>
</template>
<script>
import VueApexCharts from 'vue-apexcharts'
import statistics from '@/api/statistics'
import DateField from './DateField'
export default {
components: {
apexchart: VueApexCharts,
DateField
},
props: ['domain', 'graphicSet', 'graphicName'],
computed: {
title () {
if (this.statistics) {
return this.statistics.title
}
return ''
},
colors () {
if (this.graphicName === 'averagetraffic') {
return ['#ff6347', '#ffff00', '#4682B4', '#7cfc00', '#ffa500', '#d3d3d3']
}
return ['#ffa500', '#41d1cc']
}
},
data () {
return {
dateMenu: false,
menu: false,
options: {
colors: this.colors,
chart: {
type: 'area',
stacked: false,
zoom: {
type: 'x',
enabled: true,
autoScaleYaxis: true
},
toolbar: {
autoSelected: 'zoom'
}
},
dataLabels: {
enabled: false
},
yaxis: {
},
xaxis: {
type: 'datetime'
}
},
end: null,
start: null,
statistics: null,
period: 'day',
periods: [
{ value: 'day', name: this.$gettext('Day') },
{ value: 'week', name: this.$gettext('Week') },
{ value: 'month', name: this.$gettext('Month') },
{ value: 'year', name: this.$gettext('Year') }
]
}
},
methods: {
setCustomPeriod () {
this.period = 'custom'
this.fetchStatistics()
},
setPeriod (period) {
if (period !== this.period) {
this.period = period
this.fetchStatistics()
}
},
fetchStatistics () {
const args = {
graphSet: this.graphicSet,
period: this.period,
graphicName: this.graphicName,
searchQuery: this.domain.name
}
if (this.period === 'custom') {
args.start = this.start
args.end = this.end
}
statistics.getStatistics(args).then(resp => {
this.statistics = resp.data.graphs[this.graphicName]
})
}
},
mounted () {
this.fetchStatistics()
}
}
</script>
<style scoped>
.v-card {
z-index: 5;
}
.v-menu__content {
background-color: white !important;
}
</style>
+17 -2
View File
@@ -11,11 +11,22 @@
<v-row>
<v-col cols="6">
<domain-summary :domain="domain" />
<div class="mt-4" />
</v-col>
<v-col cols="6">
<domain-dns-summary :domain="domain" />
</v-col>
</v-row>
</v-layout>
<v-layout>
<v-row>
<v-col cols="12">
<time-serie-chart :domain="domain" graphic-set="mailtraffic" graphic-name="averagetraffic" />
</v-col>
<v-col cols="12">
<time-serie-chart :domain="domain" graphic-set="mailtraffic" graphic-name="averagetrafficsize" />
</v-col>
</v-row>
</v-layout>
<v-dialog v-model="showEditForm"
persistent
max-width="800px"
@@ -40,13 +51,15 @@ import AdministratorList from '@/components/domains/AdministratorList'
import DomainForm from '@/components/domains/DomainForm'
import DomainDNSSummary from '@/components/domains/DomainDNSSummary'
import DomainSummary from '@/components/domains/DomainSummary'
import TimeSerieChart from '@/components/tools/TimeSerieChart'
export default {
components: {
AdministratorList,
DomainForm,
'domain-dns-summary': DomainDNSSummary,
DomainSummary
DomainSummary,
TimeSerieChart
},
data () {
return {
@@ -55,6 +68,8 @@ export default {
showAdminList: false
}
},
methods: {
},
mounted () {
domains.getDomain(this.$route.params.id).then(resp => {
this.domain = resp.data
+2 -1
View File
@@ -12,7 +12,8 @@
<v-menu offset-y>
<template v-slot:activator="{ on, attrs }">
<v-btn color="primary" v-bind="attrs" v-on="on">
<v-icon left>mdi-plus</v-icon> <translate>New</translate>
<v-icon left>mdi-plus</v-icon>
<translate>New</translate>
</v-btn>
</template>
<v-list dense>