diff --git a/client/components/cards/NotificationCard.vue b/client/components/cards/NotificationCard.vue new file mode 100644 index 00000000..57db9b47 --- /dev/null +++ b/client/components/cards/NotificationCard.vue @@ -0,0 +1,118 @@ + + + \ No newline at end of file diff --git a/client/components/modals/notification/NotificationEditModal.vue b/client/components/modals/notification/NotificationEditModal.vue index a0b8ea69..dd36b607 100644 --- a/client/components/modals/notification/NotificationEditModal.vue +++ b/client/components/modals/notification/NotificationEditModal.vue @@ -201,7 +201,28 @@ export default { this.submitUpdate() } }, - submitUpdate() {}, + submitUpdate() { + this.processing = true + + const payload = { + ...this.newNotification + } + console.log('Sending update notification', payload) + this.$axios + .$patch(`/api/notifications/${payload.id}`, payload) + .then((updatedSettings) => { + this.$emit('update', updatedSettings) + this.$toast.success('Notification updated') + this.show = false + }) + .catch((error) => { + console.error('Failed to update notification', error) + this.$toast.error('Failed to update notification') + }) + .finally(() => { + this.processing = false + }) + }, submitCreate() { this.processing = true @@ -211,8 +232,10 @@ export default { console.log('Sending create notification', payload) this.$axios .$post('/api/notifications', payload) - .then(() => { + .then((updatedSettings) => { + this.$emit('update', updatedSettings) this.$toast.success('Notification created') + this.show = false }) .catch((error) => { console.error('Failed to create notification', error) diff --git a/client/components/prompt/Confirm.vue b/client/components/prompt/Confirm.vue index 639d5ddf..700cf168 100644 --- a/client/components/prompt/Confirm.vue +++ b/client/components/prompt/Confirm.vue @@ -3,7 +3,7 @@
-

{{ message }}

+

{{ message }}

Cancel
diff --git a/client/components/ui/IconBtn.vue b/client/components/ui/IconBtn.vue index c98dbd97..38f195b8 100644 --- a/client/components/ui/IconBtn.vue +++ b/client/components/ui/IconBtn.vue @@ -54,7 +54,7 @@ export default { return } e.preventDefault() - this.$emit('click') + this.$emit('click', e) e.stopPropagation() } }, diff --git a/client/pages/config/notifications.vue b/client/pages/config/notifications.vue index c62bd48d..aed7df90 100644 --- a/client/pages/config/notifications.vue +++ b/client/pages/config/notifications.vue @@ -5,9 +5,9 @@

Insert some text here describing this feature

- +
- Save + Save
@@ -22,23 +22,11 @@

No notifications

- +
@@ -47,6 +35,7 @@ export default { data() { return { loading: false, + savingSettings: false, appriseApiUrl: null, notifications: [], notificationSettings: null, @@ -58,33 +47,13 @@ export default { }, computed: {}, methods: { - deleteNotification(notification) { - this.$axios - .$delete(`/api/notifications/${notification.id}`) - .then(() => { - this.$toast.success('Deleted notification') - this.notificationSettings.notifications = this.notificationSettings.notifications.filter((n) => n.id !== notification.id) - this.notifications = this.notificationSettings.notifications - }) - .catch((error) => { - console.error('Failed', error) - this.$toast.error('Failed to delete notification') - }) + updateSettings(settings) { + this.notificationSettings = settings + this.notifications = settings.notifications }, - sendTest(notification) { - this.sendingTest = true - this.$axios - .$get(`/api/notifications/${notification.id}/test`) - .then(() => { - this.$toast.success('Triggered test notification') - }) - .catch((error) => { - console.error('Failed', error) - this.$toast.error('Failed to trigger test notification') - }) - .finally(() => { - this.sendingTest = false - }) + editNotification(notification) { + this.selectedNotification = notification + this.showEditModal = true }, clickCreate() { this.selectedNotification = null @@ -92,15 +61,20 @@ export default { }, submitForm() { if (this.notificationSettings && this.notificationSettings.appriseApiUrl == this.appriseApiUrl) { + this.$toast.info('No update necessary') return } + if (this.$refs.apiUrlInput) { + this.$refs.apiUrlInput.blur() + } + // TODO: Validate apprise api url const updatePayload = { appriseApiUrl: this.appriseApiUrl || null } - this.loading = true + this.savingSettings = true this.$axios .$patch('/api/notifications', updatePayload) .then(() => { @@ -111,7 +85,7 @@ export default { this.$toast.error('Failed to update notification settings') }) .finally(() => { - this.loading = false + this.savingSettings = false }) }, async init() { @@ -127,7 +101,6 @@ export default { } this.notificationSettings = notificationResponse.settings this.notificationData = notificationResponse.data - console.log('Notification response', notificationResponse) this.appriseApiUrl = this.notificationSettings.appriseApiUrl this.notifications = this.notificationSettings.notifications || [] } diff --git a/server/controllers/NotificationController.js b/server/controllers/NotificationController.js index 0accd683..a51f3538 100644 --- a/server/controllers/NotificationController.js +++ b/server/controllers/NotificationController.js @@ -18,36 +18,37 @@ class NotificationController { res.sendStatus(200) } + getData(req, res) { + res.json(this.notificationManager.getData()) + } + async createNotification(req, res) { const success = this.db.notificationSettings.createNotification(req.body) if (success) { await this.db.updateEntity('settings', this.db.notificationSettings) } - res.sendStatus(200) - } - - getData(req, res) { - res.json(this.notificationManager.getData()) + res.json(this.db.notificationSettings) } async deleteNotification(req, res) { if (this.db.notificationSettings.removeNotification(req.notification.id)) { await this.db.updateEntity('settings', this.db.notificationSettings) } - res.sendStatus(200) + res.json(this.db.notificationSettings) } async updateNotification(req, res) { const success = this.db.notificationSettings.updateNotification(req.body) - + console.log('Update notification', success, req.body) if (success) { await this.db.updateEntity('settings', this.db.notificationSettings) } - res.sendStatus(200) + res.json(this.db.notificationSettings) } sendNotificationTest(req, res) { + if (!this.db.notificationSettings.isUsable) return res.status(500).send('Apprise is not configured') this.notificationManager.onTest() res.sendStatus(200) } diff --git a/server/objects/Notification.js b/server/objects/Notification.js index 9c64bb28..202e4c7e 100644 --- a/server/objects/Notification.js +++ b/server/objects/Notification.js @@ -60,7 +60,7 @@ class Notification { const keysToUpdate = ['libraryId', 'eventName', 'urls', 'titleTemplate', 'bodyTemplate', 'enabled', 'type'] var hasUpdated = false for (const key of keysToUpdate) { - if (payload[key]) { + if (payload[key] !== undefined) { if (key === 'urls') { if (payload[key].join(',') !== this.urls.join(',')) { this.urls = [...payload[key]] diff --git a/server/objects/settings/NotificationSettings.js b/server/objects/settings/NotificationSettings.js index a78b56f7..b14e5eb9 100644 --- a/server/objects/settings/NotificationSettings.js +++ b/server/objects/settings/NotificationSettings.js @@ -1,3 +1,4 @@ +const Logger = require('../../Logger') const Notification = require('../Notification') class NotificationSettings { @@ -58,7 +59,7 @@ class NotificationSettings { createNotification(payload) { if (!payload) return false - // TODO: validate + if (!payload.eventName || !payload.urls.length) return false const notification = new Notification() notification.setData(payload) @@ -69,7 +70,10 @@ class NotificationSettings { updateNotification(payload) { if (!payload) return false const notification = this.notifications.find(n => n.id === payload.id) - if (!notification) return false + if (!notification) { + Logger.error(`[NotificationSettings] updateNotification: Notification not found ${payload.id}`) + return false + } return notification.update(payload) }