uptime-kuma/src/pages/Settings.vue

146 lines
5 KiB
Vue
Raw Normal View History

2021-06-25 13:55:49 +00:00
<template>
<h1 class="mb-3">Settings</h1>
<div class="shadow-box">
<div class="row">
<div class="col-md-6">
<h2>General</h2>
2021-07-01 13:47:14 +00:00
<form class="mb-3" @submit.prevent="saveGeneral">
2021-06-25 13:55:49 +00:00
<div class="mb-3">
<label for="timezone" class="form-label">Timezone</label>
2021-07-01 13:47:14 +00:00
<select class="form-select" id="timezone" v-model="$root.userTimezone">
<option value="auto">Auto: {{ guessTimezone }}</option>
<option v-for="(timezone, index) in timezoneList" :value="timezone.value" :key="index">{{ timezone.name }}</option>
2021-06-25 13:55:49 +00:00
</select>
</div>
<div>
<button class="btn btn-primary" type="submit">Save</button>
</div>
</form>
<h2>Change Password</h2>
<form class="mb-3" @submit.prevent="savePassword">
<div class="mb-3">
<label for="current-password" class="form-label">Current Password</label>
<input type="password" class="form-control" id="current-password" required v-model="password.currentPassword">
</div>
<div class="mb-3">
<label for="new-password" class="form-label">New Password</label>
<input type="password" class="form-control" id="new-password" required v-model="password.newPassword">
</div>
<div class="mb-3">
<label for="repeat-new-password" class="form-label">Repeat New Password</label>
<input type="password" class="form-control" :class="{ 'is-invalid' : invalidPassword }" id="repeat-new-password" required v-model="password.repeatNewPassword">
<div class="invalid-feedback">
The repeat password does not match.
2021-06-25 13:55:49 +00:00
</div>
</div>
<div>
<button class="btn btn-primary" type="submit">Update Password</button>
</div>
</form>
<div>
<button class="btn btn-danger" @click="$root.logout">Logout</button>
</div>
</div>
<div class="col-md-6">
2021-07-11 07:23:28 +00:00
<div class="mt-3" v-if="$root.isMobile"></div>
2021-06-25 13:55:49 +00:00
<h2>Notifications</h2>
<p v-if="$root.notificationList.length === 0">Not available, please setup.</p>
<p v-else>Please assign a notification to monitor(s) to get it to work.</p>
2021-07-10 04:04:40 +00:00
<ul class="list-group mb-3" style="border-radius: 1rem;">
<li class="list-group-item" v-for="(notification, index) in $root.notificationList" :key="index">
2021-07-10 04:04:40 +00:00
{{ notification.name }}<br />
<a href="#" @click="$refs.notificationDialog.show(notification.id)">Edit</a>
</li>
</ul>
<button class="btn btn-primary me-2" @click="$refs.notificationDialog.show()" type="button">Setup Notification</button>
2021-06-25 13:55:49 +00:00
</div>
2021-06-25 13:55:49 +00:00
</div>
</div>
<NotificationDialog ref="notificationDialog" />
2021-06-25 13:55:49 +00:00
</template>
<script>
import dayjs from "dayjs";
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
import NotificationDialog from "../components/NotificationDialog.vue";
dayjs.extend(utc)
dayjs.extend(timezone)
2021-07-01 13:47:14 +00:00
import {timezoneList} from "../util-frontend";
import { useToast } from 'vue-toastification'
const toast = useToast()
2021-06-25 13:55:49 +00:00
export default {
components: {
NotificationDialog
2021-06-25 13:55:49 +00:00
},
data() {
return {
timezoneList: timezoneList(),
guessTimezone: dayjs.tz.guess(),
2021-07-01 13:47:14 +00:00
2021-06-25 13:55:49 +00:00
invalidPassword: false,
password: {
currentPassword: "",
newPassword: "",
repeatNewPassword: "",
}
}
},
2021-07-01 13:47:14 +00:00
mounted() {
},
2021-06-25 13:55:49 +00:00
methods: {
2021-07-01 13:47:14 +00:00
saveGeneral() {
localStorage.timezone = this.$root.userTimezone;
toast.success("Saved.")
},
2021-06-25 13:55:49 +00:00
savePassword() {
if (this.password.newPassword !== this.password.repeatNewPassword) {
this.invalidPassword = true;
} else {
this.$root.getSocket().emit("changePassword", this.password, (res) => {
this.$root.toastRes(res)
if (res.ok) {
this.password.currentPassword = ""
this.password.newPassword = ""
this.password.repeatNewPassword = ""
}
})
}
},
},
watch: {
"password.repeatNewPassword"() {
this.invalidPassword = false;
}
}
}
</script>
<style scoped>
.shadow-box {
padding: 20px;
}
</style>