uptime-kuma/src/pages/DashboardHome.vue

222 lines
7 KiB
Vue
Raw Normal View History

2021-06-25 13:55:49 +00:00
<template>
<transition ref="tableContainer" name="slide-fade" appear>
2021-08-19 18:37:59 +00:00
<div v-if="$route.name === 'DashboardHome'">
<h1 class="mb-3">
{{ $t("Quick Stats") }}
2021-08-19 18:37:59 +00:00
</h1>
2021-06-25 13:55:49 +00:00
2021-08-29 18:22:49 +00:00
<div class="shadow-box big-padding text-center mb-4">
2021-08-19 18:37:59 +00:00
<div class="row">
<div class="col">
<h3>{{ $t("Up") }}</h3>
2022-03-12 07:10:45 +00:00
<span class="num">{{ $root.stats.up }}</span>
2021-08-19 18:37:59 +00:00
</div>
<div class="col">
<h3>{{ $t("Down") }}</h3>
2022-03-12 07:10:45 +00:00
<span class="num text-danger">{{ $root.stats.down }}</span>
2021-08-19 18:37:59 +00:00
</div>
<div class="col">
<h3>{{ $t("Maintenance") }}</h3>
2022-04-30 12:33:54 +00:00
<span class="num text-maintenance">{{ $root.stats.maintenance }}</span>
</div>
2021-08-19 18:37:59 +00:00
<div class="col">
<h3>{{ $t("Unknown") }}</h3>
2022-03-12 07:10:45 +00:00
<span class="num text-secondary">{{ $root.stats.unknown }}</span>
2021-08-19 18:37:59 +00:00
</div>
<div class="col">
2021-08-26 00:43:26 +00:00
<h3>{{ $t("pauseDashboardHome") }}</h3>
2022-03-12 07:10:45 +00:00
<span class="num text-secondary">{{ $root.stats.pause }}</span>
2021-08-19 18:37:59 +00:00
</div>
2021-06-25 13:55:49 +00:00
</div>
</div>
2021-09-11 10:56:27 +00:00
<div class="shadow-box table-shadow-box" style="overflow-x: hidden;">
2021-08-19 18:37:59 +00:00
<table class="table table-borderless table-hover">
<thead>
<tr>
<th>{{ $t("Name") }}</th>
<th>{{ $t("Status") }}</th>
<th>{{ $t("DateTime") }}</th>
<th>{{ $t("Message") }}</th>
2021-08-19 18:37:59 +00:00
</tr>
</thead>
<tbody>
<tr v-for="(beat, index) in displayedRecords" :key="index" :class="{ 'shadow-box': $root.windowWidth <= 550}">
<td><router-link :to="`/dashboard/${beat.monitorID}`">{{ $root.monitorList[beat.monitorID]?.name }}</router-link></td>
2021-08-19 18:37:59 +00:00
<td><Status :status="beat.status" /></td>
<td :class="{ 'border-0':! beat.msg}"><Datetime :value="beat.time" /></td>
<td class="border-0">{{ beat.msg }}</td>
2021-08-19 18:37:59 +00:00
</tr>
2021-07-27 17:47:13 +00:00
<tr v-if="importantHeartBeatListLength === 0">
2021-08-19 18:37:59 +00:00
<td colspan="4">
{{ $t("No important events") }}
2021-08-19 18:37:59 +00:00
</td>
</tr>
</tbody>
</table>
2021-07-18 01:04:40 +00:00
2021-08-19 18:37:59 +00:00
<div class="d-flex justify-content-center kuma_pagination">
<pagination
v-model="page"
:records="importantHeartBeatListLength"
2021-08-19 18:37:59 +00:00
:per-page="perPage"
2021-09-26 15:20:12 +00:00
:options="paginationConfig"
2021-08-19 18:37:59 +00:00
/>
</div>
2021-07-18 01:04:40 +00:00
</div>
2021-06-25 13:55:49 +00:00
</div>
2021-08-19 18:37:59 +00:00
</transition>
2021-06-25 13:55:49 +00:00
<router-view ref="child" />
</template>
<script>
2021-07-01 09:00:23 +00:00
import Status from "../components/Status.vue";
import Datetime from "../components/Datetime.vue";
2021-07-18 01:04:40 +00:00
import Pagination from "v-pagination-3";
2021-06-25 13:55:49 +00:00
export default {
2021-07-18 01:04:40 +00:00
components: {
Datetime,
Status,
Pagination,
},
props: {
calculatedHeight: {
type: Number,
default: 0
}
},
2021-07-18 01:04:40 +00:00
data() {
return {
page: 1,
perPage: 25,
initialPerPage: 25,
2021-09-26 15:20:12 +00:00
paginationConfig: {
2021-10-29 11:37:38 +00:00
hideCount: true,
chunksNavigation: "scroll",
},
importantHeartBeatListLength: 0,
displayedRecords: [],
};
2021-07-18 01:04:40 +00:00
},
watch: {
perPage() {
this.$nextTick(() => {
this.getImportantHeartbeatListPaged();
});
},
page() {
this.getImportantHeartbeatListPaged();
},
},
mounted() {
this.getImportantHeartbeatListLength();
this.$root.emitter.on("newImportantHeartbeat", this.onNewImportantHeartbeat);
this.initialPerPage = this.perPage;
window.addEventListener("resize", this.updatePerPage);
this.updatePerPage();
},
beforeUnmount() {
this.$root.emitter.off("newImportantHeartbeat", this.onNewImportantHeartbeat);
window.removeEventListener("resize", this.updatePerPage);
},
methods: {
/**
* Updates the displayed records when a new important heartbeat arrives.
* @param {object} heartbeat - The heartbeat object received.
* @returns {void}
*/
onNewImportantHeartbeat(heartbeat) {
if (this.page === 1) {
this.displayedRecords.unshift(heartbeat);
if (this.displayedRecords.length > this.perPage) {
this.displayedRecords.pop();
}
this.importantHeartBeatListLength += 1;
}
},
/**
* Retrieves the length of the important heartbeat list for all monitors.
* @returns {void}
*/
getImportantHeartbeatListLength() {
this.$root.getSocket().emit("monitorImportantHeartbeatListCount", null, (res) => {
if (res.ok) {
this.importantHeartBeatListLength = res.count;
this.getImportantHeartbeatListPaged();
}
});
},
/**
* Retrieves the important heartbeat list for the current page.
* @returns {void}
*/
getImportantHeartbeatListPaged() {
const offset = (this.page - 1) * this.perPage;
this.$root.getSocket().emit("monitorImportantHeartbeatListPaged", null, offset, this.perPage, (res) => {
if (res.ok) {
this.displayedRecords = res.data;
}
});
},
/**
* Updates the number of items shown per page based on the available height.
* @returns {void}
*/
updatePerPage() {
const tableContainer = this.$refs.tableContainer;
const tableContainerHeight = tableContainer.offsetHeight;
const availableHeight = window.innerHeight - tableContainerHeight;
const additionalPerPage = Math.floor(availableHeight / 58);
if (additionalPerPage > 0) {
this.perPage = Math.max(this.initialPerPage, this.perPage + additionalPerPage);
} else {
this.perPage = this.initialPerPage;
}
},
},
};
2021-06-25 13:55:49 +00:00
</script>
<style lang="scss" scoped>
2021-06-25 13:55:49 +00:00
@import "../assets/vars";
.num {
font-size: 30px;
color: $primary;
font-weight: bold;
2021-07-01 09:00:23 +00:00
display: block;
}
.shadow-box {
padding: 20px;
}
table {
font-size: 14px;
tr {
transition: all ease-in-out 0.2ms;
}
2021-09-11 10:56:27 +00:00
@media (max-width: 550px) {
table-layout: fixed;
overflow-wrap: break-word;
}
2021-06-25 13:55:49 +00:00
}
</style>