uptime-kuma/src/pages/StatusPage.vue

225 lines
6.2 KiB
Vue
Raw Normal View History

<template>
2021-09-11 07:40:03 -04:00
<div class="container mt-3">
2021-09-14 11:27:11 -04:00
<h1>
<img src="/icon.svg" alt class="me-2" />
<Editable v-model="config.title" tag="span" :contenteditable="editMode" />
</h1>
2021-09-11 07:40:03 -04:00
2021-09-13 07:21:39 -04:00
<div v-if="hasToken" class="mt-3" style="height: 38px;">
<div v-if="!enableEditMode">
<button class="btn btn-info me-2" @click="edit">
<font-awesome-icon icon="edit" />
Edit Status Page
</button>
<router-link to="/dashboard" class="btn btn-info">
<font-awesome-icon icon="tachometer-alt" />
Go to Dashboard
</router-link>
</div>
<div v-else>
<button class="btn btn-success me-2" @click="leaveEditMode">
<font-awesome-icon icon="save" />
{{ $t("Save") }}
</button>
2021-09-14 02:12:27 -04:00
<button class="btn btn-danger me-2" @click="discard">
2021-09-13 07:21:39 -04:00
<font-awesome-icon icon="save" />
{{ $t("Discard") }}
</button>
<!-- Set Default Language -->
<!-- Set theme -->
</div>
2021-09-11 07:40:03 -04:00
</div>
2021-09-12 14:26:45 -04:00
<div class="shadow-box list p-4 overall-status mt-4">
2021-09-14 02:12:27 -04:00
<div v-if="false">
<font-awesome-icon icon="check-circle" class="ok" />
All Systems Operational
</div>
<div>
<font-awesome-icon icon="exclamation-circle" class="warning" />
Partially Degraded Service
</div>
</div>
2021-09-14 11:27:11 -04:00
<div class="mt-4">
<Editable v-model="config.description" :contenteditable="editMode" tag="span" />
</div>
2021-09-14 02:12:27 -04:00
<div class="shadow-box alert alert-success mt-4 p-4" role="alert">
<h4 class="alert-heading">Well done!</h4>
<p>Aww yeah, you successfully read this important alert message. This example text is going to run a bit longer so that you can see how spacing within an alert works with this kind of content.</p>
<hr>
<p class="mb-0">Whenever you need to, be sure to use margin utilities to keep things nice and tidy.</p>
2021-09-14 11:27:11 -04:00
<div class="mt-3">
<button v-if="editMode" class="btn btn-light me-2">Unpin</button>
<button v-if="editMode" class="btn btn-light">Edit</button>
</div>
2021-09-11 07:40:03 -04:00
</div>
2021-09-14 11:27:11 -04:00
<div v-if="editMode" class="row mt-4" style="height: 43px;">
<div>
2021-09-13 07:21:39 -04:00
<button class="btn btn-primary btn-add-group" @click="addGroup">Add Group</button>
2021-09-11 07:40:03 -04:00
</div>
2021-09-14 11:27:11 -04:00
<div class="mt-5">
<VueMultiselect
v-model="selectedMonitor"
:options="allMonitorList"
:custom-label="monitorSelectorLabel"
:searchable="true"
placeholder="Add a monitor"
></VueMultiselect>
2021-09-11 11:43:07 -04:00
</div>
2021-09-11 07:40:03 -04:00
</div>
2021-09-13 07:21:39 -04:00
<div>
<GroupList :edit-mode="enableEditMode" />
</div>
<footer class="my-4">
2021-09-11 07:40:03 -04:00
Powered by <a target="_blank" href="https://github.com/louislam/uptime-kuma">Uptime Kuma</a>
</footer>
</div>
</template>
<script>
2021-09-12 14:26:45 -04:00
import VueMultiselect from "vue-multiselect"
2021-09-11 11:43:07 -04:00
import axios from "axios";
2021-09-13 07:21:39 -04:00
import GroupList from "../components/GroupList.vue";
2021-09-11 11:43:07 -04:00
2021-09-11 07:40:03 -04:00
const env = process.env.NODE_ENV || "production";
// change the axios base url for development
if (env === "development" || localStorage.dev === "dev") {
axios.defaults.baseURL = location.protocol + "//" + location.hostname + ":3001";
}
export default {
2021-09-11 11:43:07 -04:00
components: {
2021-09-13 07:21:39 -04:00
GroupList,
2021-09-12 14:26:45 -04:00
VueMultiselect,
2021-09-11 11:43:07 -04:00
},
data() {
return {
2021-09-12 14:26:45 -04:00
enableEditMode: false,
hasToken: false,
2021-09-11 07:40:03 -04:00
config: {},
2021-09-12 14:26:45 -04:00
selectedMonitor: null,
}
},
computed: {
2021-09-13 07:21:39 -04:00
2021-09-14 02:12:27 -04:00
/**
* If the monitor is added to public list, which will not be in this list.
*/
2021-09-12 14:26:45 -04:00
allMonitorList() {
2021-09-13 07:21:39 -04:00
let result = [];
for (let id in this.$root.monitorList) {
2021-09-14 02:12:27 -04:00
if (this.$root.monitorList[id] && ! (id in this.$root.publicMonitorList)) {
2021-09-13 07:21:39 -04:00
let monitor = this.$root.monitorList[id];
result.push(monitor);
}
}
return result;
2021-09-12 14:26:45 -04:00
},
2021-09-14 11:27:11 -04:00
editMode() {
2021-09-12 14:26:45 -04:00
return this.enableEditMode && this.$root.socket.connected;
}
},
watch: {
2021-09-13 07:21:39 -04:00
/**
* Selected a monitor and add to the list.
*/
selectedMonitor(monitor) {
if (monitor) {
if (this.$root.publicGroupList.length === 0) {
this.addGroup();
}
const firstGroup = this.$root.publicGroupList[0];
firstGroup.monitorList.push(monitor);
this.selectedMonitor = null;
}
}
},
2021-09-11 07:40:03 -04:00
async created() {
this.hasToken = ("token" in localStorage);
2021-09-11 11:43:07 -04:00
this.config = (await axios.get("/api/status-page/config")).data;
2021-09-11 07:40:03 -04:00
// Set Theme
this.$root.statusPageTheme = this.config.statusPageTheme;
},
2021-09-11 11:43:07 -04:00
async mounted() {
this.monitorList = (await axios.get("/api/status-page/monitor-list")).data;
},
methods: {
2021-09-12 14:26:45 -04:00
edit() {
this.$root.initSocketIO(true);
2021-09-12 14:26:45 -04:00
this.enableEditMode = true;
},
leaveEditMode() {
this.enableEditMode = false;
},
monitorSelectorLabel(monitor) {
return `${monitor.name}`;
},
2021-09-13 07:21:39 -04:00
addGroup() {
this.$root.publicGroupList.push({
name: "Untitled Group",
monitorList: [],
})
2021-09-14 02:12:27 -04:00
},
discard() {
location.reload();
}
},
}
</script>
2021-09-11 07:40:03 -04:00
<style lang="scss" scoped>
@import "../assets/vars.scss";
.overall-status {
font-weight: bold;
2021-09-14 02:12:27 -04:00
font-size: 25px;
2021-09-11 07:40:03 -04:00
.ok {
color: $primary;
}
2021-09-14 02:12:27 -04:00
.warning {
color: $warning;
}
2021-09-11 07:40:03 -04:00
}
h1 {
font-size: 30px;
img {
vertical-align: middle;
height: 60px;
width: 60px;
}
}
footer {
text-align: center;
font-size: 14px;
}
2021-09-13 07:21:39 -04:00
2021-09-11 07:40:03 -04:00
</style>