2022-09-22 01:01:10 +02:00
|
|
|
<template>
|
|
|
|
<div>
|
2022-11-26 06:12:12 +01:00
|
|
|
<app-settings-content :header-text="$strings.HeaderAppriseNotificationSettings" :description="$strings.MessageAppriseDescription">
|
2022-09-22 01:01:10 +02:00
|
|
|
<form @submit.prevent="submitForm">
|
2022-09-25 17:42:26 +02:00
|
|
|
<ui-text-input-with-label ref="apiUrlInput" v-model="appriseApiUrl" :disabled="savingSettings" label="Apprise API Url" class="mb-2" />
|
|
|
|
|
|
|
|
<div class="flex items-center py-2">
|
|
|
|
<ui-text-input ref="maxNotificationQueueInput" type="number" v-model="maxNotificationQueue" no-spinner :disabled="savingSettings" :padding-x="1" text-center class="w-10" />
|
|
|
|
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-tooltip :text="$strings.LabelNotificationsMaxQueueSizeHelp" direction="right">
|
|
|
|
<p class="pl-2 md:pl-4 text-base md:text-lg">{{ $strings.LabelNotificationsMaxQueueSize }}<span class="material-icons icon-text ml-1">info_outlined</span></p>
|
2022-09-25 17:42:26 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex items-center py-2">
|
|
|
|
<ui-text-input ref="maxFailedAttemptsInput" type="number" v-model="maxFailedAttempts" no-spinner :disabled="savingSettings" :padding-x="1" text-center class="w-10" />
|
|
|
|
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-tooltip :text="$strings.LabelNotificationsMaxFailedAttemptsHelp" direction="right">
|
|
|
|
<p class="pl-2 md:pl-4 text-base md:text-lg">{{ $strings.LabelNotificationsMaxFailedAttempts }}<span class="material-icons icon-text ml-1">info_outlined</span></p>
|
2022-09-25 17:42:26 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</div>
|
|
|
|
|
2022-09-22 01:01:10 +02:00
|
|
|
<div class="flex items-center justify-end pt-4">
|
2022-11-08 01:27:17 +01:00
|
|
|
<ui-btn :loading="savingSettings" type="submit">{{ $strings.ButtonSave }}</ui-btn>
|
2022-09-22 01:01:10 +02:00
|
|
|
</div>
|
|
|
|
</form>
|
2022-09-23 01:12:48 +02:00
|
|
|
|
|
|
|
<div class="w-full h-px bg-white bg-opacity-10 my-6" />
|
|
|
|
|
|
|
|
<div class="flex items-center justify-between mb-6">
|
2022-11-08 01:27:17 +01:00
|
|
|
<h2 class="text-xl font-semibold">{{ $strings.HeaderNotifications }}</h2>
|
|
|
|
<ui-btn small color="success" class="flex items-center" @click="clickCreate">{{ $strings.ButtonCreate }} <span class="material-icons text-lg pl-2">add</span></ui-btn>
|
2022-09-23 01:12:48 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="!notifications.length" class="flex justify-center text-center">
|
2022-11-08 01:27:17 +01:00
|
|
|
<p class="text-lg text-gray-200">{{ $strings.MessageNoNotifications }}</p>
|
2022-09-23 01:12:48 +02:00
|
|
|
</div>
|
|
|
|
<template v-for="notification in notifications">
|
2022-09-24 21:03:14 +02:00
|
|
|
<cards-notification-card :key="notification.id" :notification="notification" @update="updateSettings" @edit="editNotification" />
|
2022-09-23 01:12:48 +02:00
|
|
|
</template>
|
2022-11-26 06:12:12 +01:00
|
|
|
</app-settings-content>
|
2022-09-23 01:12:48 +02:00
|
|
|
|
2022-09-24 21:03:14 +02:00
|
|
|
<modals-notification-edit-modal v-model="showEditModal" :notification="selectedNotification" :notification-data="notificationData" @update="updateSettings" />
|
2022-09-22 01:01:10 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
2023-06-16 00:41:27 +02:00
|
|
|
asyncData({ store, redirect }) {
|
|
|
|
if (!store.getters['user/getIsAdminOrUp']) {
|
|
|
|
redirect('/')
|
|
|
|
}
|
|
|
|
},
|
2022-09-22 01:01:10 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: false,
|
2022-09-24 21:03:14 +02:00
|
|
|
savingSettings: false,
|
2022-09-22 01:01:10 +02:00
|
|
|
appriseApiUrl: null,
|
2022-09-25 17:42:26 +02:00
|
|
|
maxNotificationQueue: 0,
|
|
|
|
maxFailedAttempts: 0,
|
2022-09-22 01:01:10 +02:00
|
|
|
notifications: [],
|
2022-09-23 01:12:48 +02:00
|
|
|
notificationSettings: null,
|
|
|
|
notificationData: null,
|
|
|
|
showEditModal: false,
|
2022-09-24 01:10:03 +02:00
|
|
|
selectedNotification: null,
|
|
|
|
sendingTest: false
|
2022-09-22 01:01:10 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {},
|
|
|
|
methods: {
|
2022-09-24 21:03:14 +02:00
|
|
|
updateSettings(settings) {
|
|
|
|
this.notificationSettings = settings
|
|
|
|
this.notifications = settings.notifications
|
2022-09-24 01:10:03 +02:00
|
|
|
},
|
2022-09-24 21:03:14 +02:00
|
|
|
editNotification(notification) {
|
|
|
|
this.selectedNotification = notification
|
|
|
|
this.showEditModal = true
|
2022-09-24 01:10:03 +02:00
|
|
|
},
|
2022-09-23 01:12:48 +02:00
|
|
|
clickCreate() {
|
|
|
|
this.selectedNotification = null
|
|
|
|
this.showEditModal = true
|
|
|
|
},
|
2022-09-24 23:15:16 +02:00
|
|
|
validateAppriseApiUrl() {
|
|
|
|
try {
|
|
|
|
return new URL(this.appriseApiUrl)
|
|
|
|
} catch (error) {
|
|
|
|
console.log('URL error', error)
|
|
|
|
this.$toast.error(error.message)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
},
|
2022-09-25 17:42:26 +02:00
|
|
|
validateForm() {
|
2022-09-24 21:03:14 +02:00
|
|
|
if (this.$refs.apiUrlInput) {
|
|
|
|
this.$refs.apiUrlInput.blur()
|
|
|
|
}
|
2022-09-25 17:42:26 +02:00
|
|
|
if (this.$refs.maxNotificationQueueInput) {
|
|
|
|
this.$refs.maxNotificationQueueInput.blur()
|
|
|
|
}
|
|
|
|
if (this.$refs.maxFailedAttemptsInput) {
|
|
|
|
this.$refs.maxFailedAttemptsInput.blur()
|
|
|
|
}
|
2022-09-24 21:03:14 +02:00
|
|
|
|
2022-09-25 17:42:26 +02:00
|
|
|
if (!this.validateAppriseApiUrl()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNaN(this.maxNotificationQueue) || this.maxNotificationQueue <= 0) {
|
|
|
|
this.$toast.error('Max notification queue must be >= 0')
|
|
|
|
return false
|
2022-09-24 23:15:16 +02:00
|
|
|
}
|
2022-09-22 01:01:10 +02:00
|
|
|
|
2022-09-25 17:42:26 +02:00
|
|
|
if (isNaN(this.maxFailedAttempts) || this.maxFailedAttempts <= 0) {
|
|
|
|
this.$toast.error('Max failed attempts must be >= 0')
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
submitForm() {
|
|
|
|
if (!this.validateForm()) return
|
|
|
|
|
2022-09-22 01:01:10 +02:00
|
|
|
const updatePayload = {
|
2022-09-25 17:42:26 +02:00
|
|
|
appriseApiUrl: this.appriseApiUrl || null,
|
|
|
|
maxNotificationQueue: Number(this.maxNotificationQueue),
|
|
|
|
maxFailedAttempts: Number(this.maxFailedAttempts)
|
2022-09-22 01:01:10 +02:00
|
|
|
}
|
2022-09-24 21:03:14 +02:00
|
|
|
this.savingSettings = true
|
2022-09-22 01:01:10 +02:00
|
|
|
this.$axios
|
|
|
|
.$patch('/api/notifications', updatePayload)
|
|
|
|
.then(() => {
|
|
|
|
this.$toast.success('Notification settings updated')
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update notification settings', error)
|
|
|
|
this.$toast.error('Failed to update notification settings')
|
|
|
|
})
|
|
|
|
.finally(() => {
|
2022-09-24 21:03:14 +02:00
|
|
|
this.savingSettings = false
|
2022-09-22 01:01:10 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
async init() {
|
|
|
|
this.loading = true
|
2022-09-23 01:12:48 +02:00
|
|
|
const notificationResponse = await this.$axios.$get('/api/notifications').catch((error) => {
|
2022-09-22 01:01:10 +02:00
|
|
|
console.error('Failed to get notification settings', error)
|
2024-05-13 23:58:41 +02:00
|
|
|
this.$toast.error(this.$strings.ToastFailedToLoadData)
|
2022-09-22 01:01:10 +02:00
|
|
|
return null
|
|
|
|
})
|
|
|
|
this.loading = false
|
2022-09-23 01:12:48 +02:00
|
|
|
if (!notificationResponse) {
|
2022-09-22 01:01:10 +02:00
|
|
|
return
|
|
|
|
}
|
2022-09-23 01:12:48 +02:00
|
|
|
this.notificationData = notificationResponse.data
|
2022-09-24 23:15:16 +02:00
|
|
|
this.setNotificationSettings(notificationResponse.settings)
|
|
|
|
},
|
|
|
|
setNotificationSettings(notificationSettings) {
|
|
|
|
this.notificationSettings = notificationSettings
|
|
|
|
this.appriseApiUrl = notificationSettings.appriseApiUrl
|
2022-09-25 17:42:26 +02:00
|
|
|
this.maxNotificationQueue = notificationSettings.maxNotificationQueue
|
|
|
|
this.maxFailedAttempts = notificationSettings.maxFailedAttempts
|
2022-09-24 23:15:16 +02:00
|
|
|
this.notifications = notificationSettings.notifications || []
|
|
|
|
},
|
|
|
|
notificationsUpdated(notificationSettings) {
|
|
|
|
console.log('Notifications updated', notificationSettings)
|
|
|
|
this.setNotificationSettings(notificationSettings)
|
2022-09-22 01:01:10 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init()
|
2022-09-24 23:15:16 +02:00
|
|
|
this.$root.socket.on('notifications_updated', this.notificationsUpdated)
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$root.socket.off('notifications_updated', this.notificationsUpdated)
|
2022-09-22 01:01:10 +02:00
|
|
|
}
|
|
|
|
}
|
2024-05-13 23:58:41 +02:00
|
|
|
</script>
|