2022-09-24 21:03:14 +02:00
|
|
|
<template>
|
2022-09-24 23:15:16 +02:00
|
|
|
<div class="w-full border border-white border-opacity-10 rounded-xl p-4 my-2" :class="notification.enabled ? 'bg-primary bg-opacity-25' : 'bg-error bg-opacity-5'">
|
2022-09-25 18:50:41 +02:00
|
|
|
<div class="flex flex-wrap items-center">
|
|
|
|
<p class="text-base md:text-lg font-semibold pr-4">{{ eventName }}</p>
|
2022-09-24 21:03:14 +02:00
|
|
|
<div class="flex-grow" />
|
|
|
|
|
2024-08-31 00:47:49 +02:00
|
|
|
<ui-btn v-if="eventName === 'onTest' && notification.enabled" :loading="testing" small class="mr-2" @click.stop="fireTestEventAndSucceed">{{ this.$strings.ButtonFireOnTest }}</ui-btn>
|
|
|
|
<ui-btn v-if="eventName === 'onTest' && notification.enabled" :loading="testing" small class="mr-2" color="red-600" @click.stop="fireTestEventAndFail">{{ this.$strings.ButtonFireAndFail }}</ui-btn>
|
2022-09-25 17:19:44 +02:00
|
|
|
<!-- <ui-btn v-if="eventName === 'onTest' && notification.enabled" :loading="testing" small class="mr-2" @click.stop="rapidFireTestEvents">Rapid Fire</ui-btn> -->
|
2024-08-31 00:47:49 +02:00
|
|
|
<ui-btn v-else-if="notification.enabled" :loading="sendingTest" small class="mr-2" @click.stop="sendTestClick">{{ this.$strings.ButtonTest }}</ui-btn>
|
|
|
|
<ui-btn v-else :loading="enabling" small color="success" class="mr-2" @click="enableNotification">{{ this.$strings.ButtonEnable }}</ui-btn>
|
2022-09-24 21:03:14 +02:00
|
|
|
|
2022-09-25 18:50:41 +02:00
|
|
|
<ui-icon-btn :size="7" icon-font-size="1.1rem" icon="edit" class="mr-2" @click="editNotification" />
|
2022-09-24 21:03:14 +02:00
|
|
|
<ui-icon-btn bg-color="error" :size="7" icon-font-size="1.2rem" icon="delete" @click="deleteNotificationClick" />
|
|
|
|
</div>
|
|
|
|
<div class="pt-4">
|
2022-09-25 18:50:41 +02:00
|
|
|
<p class="text-gray-300 text-xs md:text-sm mb-2">{{ notification.urls.join(', ') }}</p>
|
2022-09-24 23:15:16 +02:00
|
|
|
|
|
|
|
<p v-if="lastFiredAt && lastAttemptFailed" class="text-red-300 text-xs">Last attempt failed {{ $dateDistanceFromNow(lastFiredAt) }} ({{ numConsecutiveFailedAttempts }} attempt{{ numConsecutiveFailedAttempts === 1 ? '' : 's' }})</p>
|
|
|
|
<p v-else-if="lastFiredAt" class="text-gray-400 text-xs">Last fired {{ $dateDistanceFromNow(lastFiredAt) }}</p>
|
2022-09-24 21:03:14 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
notification: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
sendingTest: false,
|
|
|
|
enabling: false,
|
2022-09-24 23:15:16 +02:00
|
|
|
deleting: false,
|
|
|
|
testing: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
eventName() {
|
|
|
|
return this.notification ? this.notification.eventName : null
|
|
|
|
},
|
|
|
|
lastFiredAt() {
|
|
|
|
return this.notification ? this.notification.lastFiredAt : null
|
|
|
|
},
|
|
|
|
lastAttemptFailed() {
|
|
|
|
return this.notification ? this.notification.lastAttemptFailed : null
|
|
|
|
},
|
|
|
|
numConsecutiveFailedAttempts() {
|
|
|
|
return this.notification ? this.notification.numConsecutiveFailedAttempts : null
|
2022-09-24 21:03:14 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2022-09-25 17:19:44 +02:00
|
|
|
// For testing using the onTest event
|
2022-09-24 23:15:16 +02:00
|
|
|
fireTestEventAndFail() {
|
|
|
|
this.fireTestEvent(true)
|
|
|
|
},
|
|
|
|
fireTestEventAndSucceed() {
|
|
|
|
this.fireTestEvent(false)
|
|
|
|
},
|
|
|
|
fireTestEvent(intentionallyFail = false) {
|
|
|
|
this.testing = true
|
|
|
|
this.$axios
|
|
|
|
.$get(`/api/notifications/test?fail=${intentionallyFail ? 1 : 0}`)
|
|
|
|
.then(() => {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastNotificationTestTriggerSuccess)
|
2022-09-24 23:15:16 +02:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
const errorMsg = error.response ? error.response.data : null
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(`Failed: ${errorMsg}` || this.$strings.ToastNotificationTestTriggerFailed)
|
2022-09-24 23:15:16 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.testing = false
|
|
|
|
})
|
|
|
|
},
|
2022-09-25 17:19:44 +02:00
|
|
|
rapidFireTestEvents() {
|
|
|
|
this.testing = true
|
|
|
|
var numFired = 0
|
|
|
|
var interval = setInterval(() => {
|
|
|
|
this.fireTestEvent()
|
|
|
|
numFired++
|
|
|
|
if (numFired > 25) {
|
|
|
|
this.testing = false
|
|
|
|
clearInterval(interval)
|
|
|
|
}
|
|
|
|
}, 100)
|
|
|
|
},
|
|
|
|
// End testing functions
|
2022-09-24 21:03:14 +02:00
|
|
|
sendTestClick() {
|
|
|
|
const payload = {
|
2024-08-31 00:47:49 +02:00
|
|
|
message: this.$strings.MessageConfirmNotificationTestTrigger,
|
2022-09-24 21:03:14 +02:00
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.sendTest()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
},
|
|
|
|
sendTest() {
|
|
|
|
this.sendingTest = true
|
|
|
|
this.$axios
|
|
|
|
.$get(`/api/notifications/${this.notification.id}/test`)
|
|
|
|
.then(() => {
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.success(this.$strings.ToastNotificationTestTriggerSuccess)
|
2022-09-24 21:03:14 +02:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
|
|
|
const errorMsg = error.response ? error.response.data : null
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(`Failed: ${errorMsg}` || this.$strings.ToastNotificationTestTriggerFailed)
|
2022-09-24 21:03:14 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.sendingTest = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
enableNotification() {
|
|
|
|
this.enabling = true
|
|
|
|
const payload = {
|
|
|
|
id: this.notification.id,
|
|
|
|
enabled: true
|
|
|
|
}
|
|
|
|
this.$axios
|
|
|
|
.$patch(`/api/notifications/${this.notification.id}`, payload)
|
|
|
|
.then((updatedSettings) => {
|
|
|
|
this.$emit('update', updatedSettings)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update notification', error)
|
2024-09-30 00:53:52 +02:00
|
|
|
this.$toast.error(this.$strings.ToastFailedToUpdate)
|
2022-09-24 21:03:14 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.enabling = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
deleteNotificationClick() {
|
|
|
|
const payload = {
|
2024-08-31 00:47:49 +02:00
|
|
|
message: this.$strings.MessageConfirmDeleteNotification,
|
2022-09-24 21:03:14 +02:00
|
|
|
callback: (confirmed) => {
|
|
|
|
if (confirmed) {
|
|
|
|
this.deleteNotification()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
type: 'yesNo'
|
|
|
|
}
|
|
|
|
this.$store.commit('globals/setConfirmPrompt', payload)
|
|
|
|
},
|
|
|
|
deleteNotification() {
|
|
|
|
this.deleting = true
|
|
|
|
this.$axios
|
|
|
|
.$delete(`/api/notifications/${this.notification.id}`)
|
|
|
|
.then((updatedSettings) => {
|
|
|
|
this.$emit('update', updatedSettings)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed', error)
|
2024-08-31 00:47:49 +02:00
|
|
|
this.$toast.error(this.$strings.ToastNotificationDeleteFailed)
|
2022-09-24 21:03:14 +02:00
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.deleting = false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
editNotification() {
|
|
|
|
this.$emit('edit', this.notification)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted() {}
|
|
|
|
}
|
2024-08-31 00:47:49 +02:00
|
|
|
</script>
|