uptime-kuma/src/pages/ManageMaintenance.vue

303 lines
9 KiB
Vue
Raw Normal View History

2022-09-17 14:00:11 +00:00
<template>
<transition name="slide-fade" appear>
<div>
<h1 class="mb-3">
{{ $t("Maintenance") }}
</h1>
<div>
<router-link to="/add-maintenance" class="btn btn-primary mb-3">
<font-awesome-icon icon="plus" /> {{ $t("Schedule Maintenance") }}
</router-link>
</div>
<div class="shadow-box">
<span v-if="Object.keys(sortedMaintenanceList).length === 0" class="d-flex align-items-center justify-content-center my-3">
2022-10-10 12:48:11 +00:00
{{ $t("No Maintenance") }}
2022-09-17 14:00:11 +00:00
</span>
2022-09-17 18:02:18 +00:00
<div
2022-09-17 14:00:11 +00:00
v-for="(item, index) in sortedMaintenanceList"
:key="index"
class="item"
2022-10-10 17:45:30 +00:00
:class="item.status"
2022-09-17 14:00:11 +00:00
>
2022-09-17 18:02:18 +00:00
<div class="left-part">
<div
class="circle"
></div>
<div class="info">
<div class="title">{{ item.title }}</div>
2022-10-11 10:23:17 +00:00
<div v-if="false">{{ item.description }}</div>
<div class="status">
{{ $t("maintenanceStatus-" + item.status) }}
</div>
<div v-if="item.strategy === 'manual'" class="timeslot">
{{ $t("Manual") }}
</div>
<div v-else-if="item.timeslotList.length > 0" class="timeslot">
{{ item.timeslotList[0].startDateServerTimezone }} <span class="to">-</span> {{ item.timeslotList[0].endDateServerTimezone }}
(UTC{{ item.timeslotList[0].serverTimezoneOffset }})
</div>
2022-09-17 18:02:18 +00:00
</div>
2022-09-17 14:00:11 +00:00
</div>
2022-09-17 18:02:18 +00:00
<div class="buttons">
2022-09-18 14:34:05 +00:00
<router-link v-if="false" :to="maintenanceURL(item.id)" class="btn btn-light">{{ $t("Details") }}</router-link>
2022-10-10 12:48:11 +00:00
<div class="btn-group" role="group">
2022-10-11 10:23:17 +00:00
<button v-if="item.active" class="btn btn-normal" @click="pauseDialog(item.id)">
<font-awesome-icon icon="pause" /> {{ $t("Pause") }}
</button>
2022-10-11 10:23:17 +00:00
<button v-if="!item.active" class="btn btn-primary" @click="resumeMaintenance(item.id)">
<font-awesome-icon icon="play" /> {{ $t("Resume") }}
</button>
<router-link :to="'/maintenance/edit/' + item.id" class="btn btn-normal">
<font-awesome-icon icon="edit" /> {{ $t("Edit") }}
</router-link>
<button class="btn btn-danger" @click="deleteDialog(item.id)">
<font-awesome-icon icon="trash" /> {{ $t("Delete") }}
</button>
</div>
2022-09-17 14:00:11 +00:00
</div>
2022-09-17 18:02:18 +00:00
</div>
2022-09-17 14:00:11 +00:00
</div>
2022-09-17 18:02:18 +00:00
2022-09-23 18:33:29 +00:00
<div class="text-center mt-3" style="font-size: 13px;">
<a href="https://github.com/louislam/uptime-kuma/wiki/Maintenance" target="_blank">Learn More</a>
</div>
2022-10-10 12:48:11 +00:00
<Confirm ref="confirmPause" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="pauseMaintenance">
{{ $t("pauseMaintenanceMsg") }}
</Confirm>
2022-09-17 18:02:18 +00:00
<Confirm ref="confirmDelete" btn-style="btn-danger" :yes-text="$t('Yes')" :no-text="$t('No')" @yes="deleteMaintenance">
{{ $t("deleteMaintenanceMsg") }}
</Confirm>
2022-09-17 14:00:11 +00:00
</div>
</transition>
</template>
<script>
import { getResBaseURL } from "../util-frontend";
import { getMaintenanceRelativeURL } from "../util.ts";
2022-09-17 18:02:18 +00:00
import Confirm from "../components/Confirm.vue";
import { useToast } from "vue-toastification";
const toast = useToast();
2022-09-17 14:00:11 +00:00
export default {
components: {
2022-09-17 18:02:18 +00:00
Confirm,
2022-09-17 14:00:11 +00:00
},
data() {
return {
2022-09-17 18:02:18 +00:00
selectedMaintenanceID: undefined,
statusOrderList: {
"under-maintenance": 1000,
"scheduled": 900,
"inactive": 800,
"ended": 700,
"unknown": 0,
}
2022-09-17 14:00:11 +00:00
};
},
computed: {
sortedMaintenanceList() {
let result = Object.values(this.$root.maintenanceList);
result.sort((m1, m2) => {
if (this.statusOrderList[m1.status] === this.statusOrderList[m2.status]) {
return m1.title.localeCompare(m2.title);
} else {
return this.statusOrderList[m1.status] < this.statusOrderList[m2.status];
}
2022-09-17 14:00:11 +00:00
});
return result;
},
},
mounted() {
},
methods: {
/**
* Get the correct URL for the icon
* @param {string} icon Path for icon
* @returns {string} Correctly formatted path including port numbers
*/
icon(icon) {
if (icon === "/icon.svg") {
return icon;
} else {
return getResBaseURL() + icon;
}
},
maintenanceURL(id) {
return getMaintenanceRelativeURL(id);
},
2022-09-17 18:02:18 +00:00
deleteDialog(maintenanceID) {
this.selectedMaintenanceID = maintenanceID;
this.$refs.confirmDelete.show();
},
deleteMaintenance() {
this.$root.deleteMaintenance(this.selectedMaintenanceID, (res) => {
if (res.ok) {
toast.success(res.msg);
this.$router.push("/maintenance");
} else {
toast.error(res.msg);
}
});
},
2022-10-10 12:48:11 +00:00
/**
* Show dialog to confirm pause
*/
2022-10-11 10:23:17 +00:00
pauseDialog(maintenanceID) {
this.selectedMaintenanceID = maintenanceID;
2022-10-10 12:48:11 +00:00
this.$refs.confirmPause.show();
},
/**
* Pause maintenance
*/
2022-10-10 17:45:30 +00:00
pauseMaintenance() {
2022-10-11 10:23:17 +00:00
this.$root.getSocket().emit("pauseMaintenance", this.selectedMaintenanceID, (res) => {
2022-10-10 12:48:11 +00:00
this.$root.toastRes(res);
});
},
/**
* Resume maintenance
*/
2022-10-11 10:23:17 +00:00
resumeMaintenance(id) {
this.$root.getSocket().emit("resumeMaintenance", id, (res) => {
2022-10-10 12:48:11 +00:00
this.$root.toastRes(res);
});
},
2022-09-17 14:00:11 +00:00
},
};
</script>
<style lang="scss" scoped>
@import "../assets/vars.scss";
.item {
display: flex;
align-items: center;
gap: 10px;
text-decoration: none;
border-radius: 10px;
transition: all ease-in-out 0.15s;
2022-09-17 18:02:18 +00:00
justify-content: space-between;
2022-09-17 14:00:11 +00:00
padding: 10px;
min-height: 90px;
2022-10-11 10:23:17 +00:00
margin-bottom: 5px;
2022-09-17 14:00:11 +00:00
&:hover {
background-color: $highlight-white;
}
2022-10-10 17:45:30 +00:00
&.under-maintenance {
background-color: rgba(23, 71, 245, 0.16);
&:hover {
background-color: rgba(23, 71, 245, 0.3) !important;
}
.circle {
background-color: $maintenance;
}
}
&.scheduled {
.circle {
background-color: $primary;
}
}
&.inactive {
.circle {
background-color: $danger;
}
}
2022-09-17 18:02:18 +00:00
&.ended {
.left-part {
2022-10-10 17:45:30 +00:00
opacity: 0.3;
}
2022-09-17 18:07:32 +00:00
2022-10-10 17:45:30 +00:00
.circle {
background-color: $dark-font-color;
}
}
&.unknown {
.circle {
background-color: $dark-font-color;
2022-09-17 18:02:18 +00:00
}
2022-09-17 14:00:11 +00:00
}
2022-09-17 18:02:18 +00:00
.left-part {
display: flex;
gap: 12px;
align-items: center;
2022-09-17 14:00:11 +00:00
2022-09-17 18:02:18 +00:00
.circle {
width: 25px;
height: 25px;
border-radius: 50rem;
2022-09-17 14:00:11 +00:00
}
2022-09-17 18:02:18 +00:00
.info {
.title {
font-weight: bold;
font-size: 20px;
}
2022-10-11 10:23:17 +00:00
.status {
font-size: 14px;
}
.timeslot {
margin-top: 5px;
display: inline-block;
2022-09-17 18:02:18 +00:00
font-size: 14px;
2022-10-11 10:23:17 +00:00
background-color: rgba(255, 255, 255, 0.5);
border-radius: 20px;
padding: 0 10px;
.to {
margin: 0 6px;
}
.dark & {
color: white;
background-color: rgba(255, 255, 255, 0.1);
}
2022-09-17 18:02:18 +00:00
}
2022-09-17 14:00:11 +00:00
}
}
2022-09-17 18:02:18 +00:00
.buttons {
display: flex;
gap: 8px;
}
2022-09-17 14:00:11 +00:00
}
.dark {
.item {
&:hover {
background-color: $dark-bg2;
}
}
}
</style>