uptime-kuma/src/pages/ManageMaintenance.vue

261 lines
7.1 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>
<div>{{ item.description }}</div>
</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
2022-10-10 17:45:30 +00:00
<button v-if="item.active" class="btn btn-normal" @click="pauseDialog">
2022-10-10 12:48:11 +00:00
<font-awesome-icon icon="pause" /> {{ $t("Pause") }}
</button>
<button v-if="!item.active" class="btn btn-primary" @click="resumeMaintenance">
<font-awesome-icon icon="play" /> {{ $t("Resume") }}
</button>
2022-10-10 17:45:30 +00:00
<router-link :to="'/maintenance/edit/' + item.id" class="btn btn-normal">
2022-09-17 18:02:18 +00:00
<font-awesome-icon icon="edit" /> {{ $t("Edit") }}
</router-link>
2022-10-10 12:48:11 +00:00
2022-09-17 18:02:18 +00:00
<button class="btn btn-danger" @click="deleteDialog(item.id)">
<font-awesome-icon icon="trash" /> {{ $t("Delete") }}
</button>
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,
2022-09-17 14:00:11 +00:00
};
},
computed: {
sortedMaintenanceList() {
let result = Object.values(this.$root.maintenanceList);
result.sort((m1, m2) => {
return m1.title.localeCompare(m2.title);
});
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
*/
pauseDialog() {
this.$refs.confirmPause.show();
},
/**
* Pause maintenance
*/
2022-10-10 17:45:30 +00:00
pauseMaintenance() {
2022-10-10 12:48:11 +00:00
return;
this.$root.getSocket().emit("pauseMaintenance", selectedMaintenanceID, (res) => {
this.$root.toastRes(res);
});
},
/**
* Resume maintenance
*/
resumeMaintenance() {
return;
this.$root.getSocket().emit("resumeMaintenance", selectedMaintenanceID, (res) => {
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;
&: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;
}
.slug {
font-size: 14px;
}
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>