From 58240aceefb4990b62292c4ee702f4dfd2da1546 Mon Sep 17 00:00:00 2001 From: Ponkhy Date: Sun, 5 Sep 2021 23:23:06 +0200 Subject: [PATCH 1/9] Added the option for default notifications --- db/patch9.sql | 7 +++++++ server/database.js | 2 +- server/notification.js | 27 ++++++++++++++++++++++++++- src/components/NotificationDialog.vue | 19 +++++++++++++++++++ src/languages/de-DE.js | 5 ++++- src/languages/en.js | 5 ++++- src/pages/EditMonitor.vue | 8 ++++++++ 7 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 db/patch9.sql diff --git a/db/patch9.sql b/db/patch9.sql new file mode 100644 index 00000000..3f631ff8 --- /dev/null +++ b/db/patch9.sql @@ -0,0 +1,7 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE notification + ADD is_default BOOLEAN; + +COMMIT; diff --git a/server/database.js b/server/database.js index 77c4da75..832166d2 100644 --- a/server/database.js +++ b/server/database.js @@ -7,7 +7,7 @@ class Database { static templatePath = "./db/kuma.db" static dataDir; static path; - static latestVersion = 8; + static latestVersion = 9; static noReject = true; static sqliteInstance = null; diff --git a/server/notification.js b/server/notification.js index 472012af..d3a55c84 100644 --- a/server/notification.js +++ b/server/notification.js @@ -617,8 +617,13 @@ class Notification { bean.name = notification.name; bean.user_id = userID; - bean.config = JSON.stringify(notification) + bean.config = JSON.stringify(notification); + bean.is_default = notification.isDefault; await R.store(bean) + + if (notification.applyExisting) { + await applyNotificationEveryMonitor(bean.id, userID); + } } static async delete(notificationID, userID) { @@ -702,6 +707,26 @@ function throwGeneralAxiosError(error) { throw new Error(msg) } +async function applyNotificationEveryMonitor(notificationID, userID) { + let monitors = await R.getAll("SELECT id FROM monitor WHERE user_id = ?", [ + userID + ]); + + for (let i = 0; i < monitors.length; i++) { + let checkNotification = await R.findOne("monitor_notification", " monitor_id = ? AND notification_id = ? ", [ + monitors[i].id, + notificationID, + ]) + + if (! checkNotification) { + let relation = R.dispense("monitor_notification"); + relation.monitor_id = monitors[i].id; + relation.notification_id = notificationID; + await R.store(relation) + } + } +} + module.exports = { Notification, } diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 2fdb8fe1..fa63a376 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -469,6 +469,25 @@ First access the Line Developers Console, create a provider and channel (Messaging API), then you can get the channel access token and user id from the above mentioned menu items. + +
+ + +
+ + +
+
+ {{ $t("enableDefaultNotificationDescription") }} +
+ +
+ +
+ + +
+
From f7562e00c193a27d3bb6e5dbbf7b707d090ae06e Mon Sep 17 00:00:00 2001 From: LouisLam Date: Wed, 8 Sep 2021 10:25:03 +0800 Subject: [PATCH 7/9] improve notification component, no double template --- src/components/NotificationDialog.vue | 2 +- src/components/notifications/Telegram.vue | 68 +++++++++++------------ 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 8a05d66e..ebc8eec3 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -37,7 +37,7 @@ - + diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue index 537b7fd3..9be1e004 100644 --- a/src/components/notifications/Telegram.vue +++ b/src/components/notifications/Telegram.vue @@ -1,42 +1,40 @@