diff --git a/client/pages/config/notifications.vue b/client/pages/config/notifications.vue index 6fd6d575..4f2577f8 100644 --- a/client/pages/config/notifications.vue +++ b/client/pages/config/notifications.vue @@ -8,7 +8,24 @@

- + + +
+ + + +

Max queue size for notification eventsinfo_outlined

+
+
+ +
+ + + +

Max failed attemptsinfo_outlined

+
+
+
Save
@@ -40,6 +57,8 @@ export default { loading: false, savingSettings: false, appriseApiUrl: null, + maxNotificationQueue: 0, + maxFailedAttempts: 0, notifications: [], notificationSettings: null, notificationData: null, @@ -71,23 +90,40 @@ export default { return false } }, - submitForm() { - if (this.notificationSettings && this.notificationSettings.appriseApiUrl == this.appriseApiUrl) { - this.$toast.info('No update necessary') - return - } - + validateForm() { if (this.$refs.apiUrlInput) { this.$refs.apiUrlInput.blur() } - - const isValid = this.validateAppriseApiUrl() - if (!isValid) { - return + if (this.$refs.maxNotificationQueueInput) { + this.$refs.maxNotificationQueueInput.blur() + } + if (this.$refs.maxFailedAttemptsInput) { + this.$refs.maxFailedAttemptsInput.blur() } + if (!this.validateAppriseApiUrl()) { + return false + } + + if (isNaN(this.maxNotificationQueue) || this.maxNotificationQueue <= 0) { + this.$toast.error('Max notification queue must be >= 0') + return false + } + + 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 + const updatePayload = { - appriseApiUrl: this.appriseApiUrl || null + appriseApiUrl: this.appriseApiUrl || null, + maxNotificationQueue: Number(this.maxNotificationQueue), + maxFailedAttempts: Number(this.maxFailedAttempts) } this.savingSettings = true this.$axios @@ -120,6 +156,8 @@ export default { setNotificationSettings(notificationSettings) { this.notificationSettings = notificationSettings this.appriseApiUrl = notificationSettings.appriseApiUrl + this.maxNotificationQueue = notificationSettings.maxNotificationQueue + this.maxFailedAttempts = notificationSettings.maxFailedAttempts this.notifications = notificationSettings.notifications || [] }, notificationsUpdated(notificationSettings) { diff --git a/server/objects/settings/NotificationSettings.js b/server/objects/settings/NotificationSettings.js index 838256f6..04907f3c 100644 --- a/server/objects/settings/NotificationSettings.js +++ b/server/objects/settings/NotificationSettings.js @@ -1,5 +1,6 @@ const Logger = require('../../Logger') const Notification = require('../Notification') +const { isNullOrNaN } = require('../../utils') class NotificationSettings { constructor(settings = null) { @@ -59,11 +60,26 @@ class NotificationSettings { update(payload) { if (!payload) return false + + var hasUpdates = false if (payload.appriseApiUrl !== this.appriseApiUrl) { this.appriseApiUrl = payload.appriseApiUrl || null - return true + hasUpdates = true } - return false + + const _maxFailedAttempts = isNullOrNaN(payload.maxFailedAttempts) ? 5 : Number(payload.maxFailedAttempts) + if (_maxFailedAttempts !== this.maxFailedAttempts) { + this.maxFailedAttempts = _maxFailedAttempts + hasUpdates = true + } + + const _maxNotificationQueue = isNullOrNaN(payload.maxNotificationQueue) ? 20 : Number(payload.maxNotificationQueue) + if (_maxNotificationQueue !== this.maxNotificationQueue) { + this.maxNotificationQueue = _maxNotificationQueue + hasUpdates = true + } + + return hasUpdates } createNotification(payload) {