2022-01-23 09:22:00 -05:00
|
|
|
<template>
|
|
|
|
<transition name="slide-fade" appear>
|
|
|
|
<div>
|
|
|
|
<h1 class="mb-3">{{ pageName }}</h1>
|
|
|
|
<form @submit.prevent="submit">
|
|
|
|
<div class="shadow-box">
|
|
|
|
<div class="row">
|
2022-09-18 10:34:05 -04:00
|
|
|
<div class="col-xl-7">
|
2022-01-23 09:22:00 -05:00
|
|
|
<!-- Title -->
|
|
|
|
<div class="my-3">
|
|
|
|
<label for="name" class="form-label">{{ $t("Title") }}</label>
|
2022-04-30 08:57:08 -04:00
|
|
|
<input
|
|
|
|
id="name" v-model="maintenance.title" type="text" class="form-control"
|
2022-09-17 10:00:11 -04:00
|
|
|
required
|
2022-04-30 08:57:08 -04:00
|
|
|
>
|
2022-01-23 09:22:00 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Description -->
|
|
|
|
<div class="my-3">
|
|
|
|
<label for="description" class="form-label">{{ $t("Description") }}</label>
|
2022-04-30 08:57:08 -04:00
|
|
|
<textarea
|
|
|
|
id="description" v-model="maintenance.description" class="form-control"
|
|
|
|
></textarea>
|
2022-01-23 09:22:00 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Affected Monitors -->
|
2022-09-18 10:34:05 -04:00
|
|
|
<h2 class="mt-5">{{ $t("Affected Monitors") }}</h2>
|
|
|
|
{{ $t("affectedMonitorsDescription") }}
|
2022-01-23 09:22:00 -05:00
|
|
|
|
2022-09-18 10:34:05 -04:00
|
|
|
<div class="my-3">
|
2022-01-23 09:22:00 -05:00
|
|
|
<VueMultiselect
|
|
|
|
id="affected_monitors"
|
|
|
|
v-model="affectedMonitors"
|
|
|
|
:options="affectedMonitorsOptions"
|
|
|
|
track-by="id"
|
|
|
|
label="name"
|
|
|
|
:multiple="true"
|
|
|
|
:allow-empty="false"
|
|
|
|
:close-on-select="false"
|
|
|
|
:clear-on-select="false"
|
|
|
|
:preserve-search="true"
|
|
|
|
:placeholder="$t('Pick Affected Monitors...')"
|
|
|
|
:preselect-first="false"
|
|
|
|
:max-height="600"
|
|
|
|
:taggable="false"
|
|
|
|
></VueMultiselect>
|
2022-09-18 10:34:05 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Status pages to display maintenance info on -->
|
|
|
|
<h2 class="mt-5">{{ $t("Status Pages") }}</h2>
|
|
|
|
{{ $t("affectedStatusPages") }}
|
|
|
|
|
|
|
|
<div class="my-3">
|
|
|
|
<!-- Show on all pages -->
|
|
|
|
<div class="form-check mb-2">
|
|
|
|
<input
|
|
|
|
id="show-on-all-pages" v-model="showOnAllPages" class="form-check-input"
|
|
|
|
type="checkbox"
|
|
|
|
>
|
|
|
|
<label class="form-check-label" for="show-powered-by">{{
|
|
|
|
$t("All Status Pages")
|
|
|
|
}}</label>
|
|
|
|
</div>
|
2022-01-23 09:22:00 -05:00
|
|
|
|
2022-09-18 10:34:05 -04:00
|
|
|
<div v-if="!showOnAllPages">
|
|
|
|
<VueMultiselect
|
|
|
|
id="selected_status_pages"
|
|
|
|
v-model="selectedStatusPages"
|
|
|
|
:options="selectedStatusPagesOptions"
|
|
|
|
track-by="id"
|
|
|
|
label="name"
|
|
|
|
:multiple="true"
|
|
|
|
:allow-empty="true"
|
|
|
|
:close-on-select="false"
|
|
|
|
:clear-on-select="false"
|
|
|
|
:preserve-search="true"
|
|
|
|
:placeholder="$t('Select status pages...')"
|
|
|
|
:preselect-first="false"
|
|
|
|
:max-height="600"
|
|
|
|
:taggable="false"
|
|
|
|
></VueMultiselect>
|
2022-01-23 09:22:00 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2022-09-18 10:34:05 -04:00
|
|
|
<h2 class="mt-5">{{ $t("Effective Date Range") }}</h2>
|
|
|
|
|
2022-01-23 09:22:00 -05:00
|
|
|
<!-- Start Date Time -->
|
|
|
|
<div class="my-3">
|
2022-09-17 10:00:11 -04:00
|
|
|
<label for="start_date" class="form-label">{{ $t("Start Date") }}</label>
|
2022-04-30 08:57:08 -04:00
|
|
|
<input
|
|
|
|
id="start_date" v-model="maintenance.start_date" :type="'datetime-local'"
|
2022-04-30 11:17:22 -04:00
|
|
|
class="form-control" :class="{'dark-calendar': dark }" required
|
2022-04-30 08:57:08 -04:00
|
|
|
>
|
2022-01-23 09:22:00 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- End Date Time -->
|
|
|
|
<div class="my-3">
|
2022-09-17 10:00:11 -04:00
|
|
|
<label for="end_date" class="form-label">{{ $t("End Date") }}</label>
|
2022-04-30 08:57:08 -04:00
|
|
|
<input
|
|
|
|
id="end_date" v-model="maintenance.end_date" :type="'datetime-local'"
|
2022-04-30 11:17:22 -04:00
|
|
|
class="form-control" :class="{'dark-calendar': dark }" required
|
2022-04-30 08:57:08 -04:00
|
|
|
>
|
2022-01-23 09:22:00 -05:00
|
|
|
</div>
|
|
|
|
|
2022-09-18 10:34:05 -04:00
|
|
|
<div class="mt-4 mb-1">
|
2022-04-30 08:57:08 -04:00
|
|
|
<button
|
|
|
|
id="monitor-submit-btn" class="btn btn-primary" type="submit"
|
|
|
|
:disabled="processing"
|
|
|
|
>
|
|
|
|
{{ $t("Save") }}
|
2022-01-23 09:22:00 -05:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2022-04-30 08:57:08 -04:00
|
|
|
import { useToast } from "vue-toastification";
|
2022-01-23 09:22:00 -05:00
|
|
|
import VueMultiselect from "vue-multiselect";
|
|
|
|
|
|
|
|
const toast = useToast();
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
VueMultiselect,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
processing: false,
|
|
|
|
maintenance: {},
|
|
|
|
affectedMonitors: [],
|
|
|
|
affectedMonitorsOptions: [],
|
2022-09-17 14:13:29 -04:00
|
|
|
showOnAllPages: false,
|
2022-04-30 11:17:22 -04:00
|
|
|
selectedStatusPages: [],
|
|
|
|
selectedStatusPagesOptions: [],
|
2022-01-23 09:22:00 -05:00
|
|
|
dark: (this.$root.theme === "dark"),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
|
|
|
|
pageName() {
|
2022-09-17 10:00:11 -04:00
|
|
|
return this.$t((this.isAdd) ? "Schedule Maintenance" : "Edit Maintenance");
|
2022-01-23 09:22:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
isAdd() {
|
2022-09-17 10:00:11 -04:00
|
|
|
return this.$route.path === "/add-maintenance";
|
2022-01-23 09:22:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
isEdit() {
|
2022-09-17 10:00:11 -04:00
|
|
|
return this.$route.path.startsWith("/maintenance/edit");
|
2022-01-23 09:22:00 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
"$route.fullPath"() {
|
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init();
|
|
|
|
|
|
|
|
this.$root.getMonitorList((res) => {
|
|
|
|
if (res.ok) {
|
|
|
|
Object.values(this.$root.monitorList).map(monitor => {
|
|
|
|
this.affectedMonitorsOptions.push({
|
|
|
|
id: monitor.id,
|
2022-01-23 14:33:39 -05:00
|
|
|
name: monitor.name,
|
2022-01-23 09:22:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-04-30 11:17:22 -04:00
|
|
|
|
|
|
|
Object.values(this.$root.statusPageList).map(statusPage => {
|
|
|
|
this.selectedStatusPagesOptions.push({
|
|
|
|
id: statusPage.id,
|
|
|
|
name: statusPage.title
|
|
|
|
});
|
|
|
|
});
|
2022-01-23 09:22:00 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
init() {
|
|
|
|
this.affectedMonitors = [];
|
2022-04-30 11:17:22 -04:00
|
|
|
this.selectedStatusPages = [];
|
2022-04-30 08:57:08 -04:00
|
|
|
|
2022-01-23 09:22:00 -05:00
|
|
|
if (this.isAdd) {
|
|
|
|
this.maintenance = {
|
|
|
|
title: "",
|
|
|
|
description: "",
|
|
|
|
start_date: "",
|
|
|
|
end_date: "",
|
|
|
|
};
|
|
|
|
} else if (this.isEdit) {
|
|
|
|
this.$root.getSocket().emit("getMaintenance", this.$route.params.id, (res) => {
|
|
|
|
if (res.ok) {
|
2022-01-24 16:33:15 -05:00
|
|
|
res.maintenance.start_date = this.$root.datetimeFormat(res.maintenance.start_date, "YYYY-MM-DDTHH:mm");
|
|
|
|
res.maintenance.end_date = this.$root.datetimeFormat(res.maintenance.end_date, "YYYY-MM-DDTHH:mm");
|
2022-01-23 09:22:00 -05:00
|
|
|
this.maintenance = res.maintenance;
|
|
|
|
|
|
|
|
this.$root.getSocket().emit("getMonitorMaintenance", this.$route.params.id, (res) => {
|
|
|
|
if (res.ok) {
|
|
|
|
Object.values(res.monitors).map(monitor => {
|
|
|
|
this.affectedMonitors.push(monitor);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
|
|
|
});
|
2022-04-30 11:17:22 -04:00
|
|
|
|
|
|
|
this.$root.getSocket().emit("getMaintenanceStatusPage", this.$route.params.id, (res) => {
|
|
|
|
if (res.ok) {
|
|
|
|
Object.values(res.statusPages).map(statusPage => {
|
|
|
|
this.selectedStatusPages.push({
|
|
|
|
id: statusPage.id,
|
|
|
|
name: statusPage.title
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.showOnAllPages = Object.values(res.statusPages).length === this.selectedStatusPagesOptions.length;
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
|
|
|
});
|
2022-01-23 09:22:00 -05:00
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
this.processing = true;
|
|
|
|
|
|
|
|
if (this.affectedMonitors.length === 0) {
|
2022-01-23 14:33:39 -05:00
|
|
|
toast.error(this.$t("atLeastOneMonitor"));
|
2022-01-23 09:22:00 -05:00
|
|
|
return this.processing = false;
|
2022-05-08 14:50:08 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maintenance.start_date >= this.maintenance.end_date) {
|
|
|
|
toast.error(this.$t("maintenanceInvalidDate"));
|
|
|
|
return this.processing = false;
|
2022-01-23 09:22:00 -05:00
|
|
|
}
|
|
|
|
|
2022-04-30 11:17:22 -04:00
|
|
|
if (!this.showOnAllPages && this.selectedStatusPages.length === 0) {
|
|
|
|
toast.error(this.$t("atLeastOneStatusPage"));
|
|
|
|
return this.processing = false;
|
|
|
|
}
|
|
|
|
|
2022-01-24 16:33:15 -05:00
|
|
|
this.maintenance.start_date = this.$root.toUTC(this.maintenance.start_date);
|
|
|
|
this.maintenance.end_date = this.$root.toUTC(this.maintenance.end_date);
|
|
|
|
|
2022-01-23 09:22:00 -05:00
|
|
|
if (this.isAdd) {
|
|
|
|
this.$root.addMaintenance(this.maintenance, async (res) => {
|
|
|
|
if (res.ok) {
|
2022-04-30 11:17:22 -04:00
|
|
|
await this.addMonitorMaintenance(res.maintenanceID, async () => {
|
|
|
|
await this.addMaintenanceStatusPage(res.maintenanceID, () => {
|
|
|
|
toast.success(res.msg);
|
|
|
|
this.processing = false;
|
|
|
|
this.$root.getMaintenanceList();
|
2022-09-17 14:02:18 -04:00
|
|
|
this.$router.push("/maintenance");
|
2022-04-30 11:17:22 -04:00
|
|
|
});
|
2022-01-23 09:22:00 -05:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
toast.error(res.msg);
|
|
|
|
this.processing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$root.getSocket().emit("editMaintenance", this.maintenance, async (res) => {
|
|
|
|
if (res.ok) {
|
2022-04-30 11:17:22 -04:00
|
|
|
await this.addMonitorMaintenance(res.maintenanceID, async () => {
|
|
|
|
await this.addMaintenanceStatusPage(res.maintenanceID, () => {
|
|
|
|
this.processing = false;
|
|
|
|
this.$root.toastRes(res);
|
|
|
|
this.init();
|
2022-09-17 14:02:18 -04:00
|
|
|
this.$router.push("/maintenance");
|
2022-04-30 11:17:22 -04:00
|
|
|
});
|
2022-01-23 09:22:00 -05:00
|
|
|
});
|
2022-01-24 16:33:15 -05:00
|
|
|
} else {
|
2022-01-23 09:22:00 -05:00
|
|
|
this.processing = false;
|
|
|
|
toast.error(res.msg);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
async addMonitorMaintenance(maintenanceID, callback) {
|
|
|
|
await this.$root.addMonitorMaintenance(maintenanceID, this.affectedMonitors, async (res) => {
|
|
|
|
if (!res.ok) {
|
|
|
|
toast.error(res.msg);
|
|
|
|
} else {
|
|
|
|
this.$root.getMonitorList();
|
|
|
|
}
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
},
|
2022-04-30 11:17:22 -04:00
|
|
|
|
|
|
|
async addMaintenanceStatusPage(maintenanceID, callback) {
|
|
|
|
await this.$root.addMaintenanceStatusPage(maintenanceID, (this.showOnAllPages) ? this.selectedStatusPagesOptions : this.selectedStatusPages, async (res) => {
|
|
|
|
if (!res.ok) {
|
|
|
|
toast.error(res.msg);
|
|
|
|
} else {
|
|
|
|
this.$root.getMaintenanceList();
|
|
|
|
}
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
},
|
2022-01-23 09:22:00 -05:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.shadow-box {
|
|
|
|
padding: 20px;
|
|
|
|
}
|
|
|
|
|
|
|
|
textarea {
|
2022-09-18 10:34:05 -04:00
|
|
|
min-height: 150px;
|
2022-01-23 09:22:00 -05:00
|
|
|
}
|
|
|
|
|
2022-04-30 11:17:22 -04:00
|
|
|
.dark-calendar::-webkit-calendar-picker-indicator {
|
2022-01-23 09:22:00 -05:00
|
|
|
filter: invert(1);
|
|
|
|
}
|
|
|
|
</style>
|