From e9735d239b4605d65ca5c39c15fff993edd938d4 Mon Sep 17 00:00:00 2001 From: zsxeee Date: Fri, 17 Sep 2021 16:07:03 +0800 Subject: [PATCH 1/6] Convert notification form to separate component --- src/components/NotificationDialog.vue | 398 +------------------- src/components/notifications/Apprise.vue | 30 ++ src/components/notifications/Discord.vue | 30 ++ src/components/notifications/Gotify.vue | 32 ++ src/components/notifications/Line.vue | 34 ++ src/components/notifications/LunaSea.vue | 19 + src/components/notifications/Mattermost.vue | 42 +++ src/components/notifications/Octopush.vue | 45 +++ src/components/notifications/Pushbullet.vue | 25 ++ src/components/notifications/Pushover.vue | 72 ++++ src/components/notifications/Pushy.vue | 31 ++ src/components/notifications/RocketChat.vue | 39 ++ src/components/notifications/Signal.vue | 42 +++ src/components/notifications/Slack.vue | 39 ++ src/components/notifications/Webhook.vue | 37 ++ src/components/notifications/index.js | 44 +++ src/languages/en.js | 17 + 17 files changed, 594 insertions(+), 382 deletions(-) create mode 100644 src/components/notifications/Apprise.vue create mode 100644 src/components/notifications/Discord.vue create mode 100644 src/components/notifications/Gotify.vue create mode 100644 src/components/notifications/Line.vue create mode 100644 src/components/notifications/LunaSea.vue create mode 100644 src/components/notifications/Mattermost.vue create mode 100644 src/components/notifications/Octopush.vue create mode 100644 src/components/notifications/Pushbullet.vue create mode 100644 src/components/notifications/Pushover.vue create mode 100644 src/components/notifications/Pushy.vue create mode 100644 src/components/notifications/RocketChat.vue create mode 100644 src/components/notifications/Signal.vue create mode 100644 src/components/notifications/Slack.vue create mode 100644 src/components/notifications/Webhook.vue create mode 100644 src/components/notifications/index.js diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 220ff8d71..c26990f89 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -13,23 +13,7 @@
@@ -38,370 +22,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
@@ -454,6 +76,7 @@ import HiddenInput from "./HiddenInput.vue"; import Telegram from "./notifications/Telegram.vue"; import Teams from "./notifications/Teams.vue"; import SMTP from "./notifications/SMTP.vue"; +import NotificationForm from "./notifications" export default { components: { @@ -470,8 +93,10 @@ export default { model: null, processing: false, id: null, + notificationTypes: Object.keys(NotificationForm), notification: { name: "", + /** @type { null | keyof NotificationForm } */ type: null, isDefault: false, // Do not set default value here, please scroll to show() @@ -480,6 +105,15 @@ export default { } }, + computed: { + currentForm() { + if (!this.notification.type) { + return null + } + return NotificationForm[this.notification.type] + } + }, + watch: { "notification.type"(to, from) { let oldName; @@ -528,7 +162,7 @@ export default { } // Set Default value here - this.notification.type = "telegram"; + this.notification.type = this.notificationTypes[0]; this.notification.gotifyPriority = 8; this.notification.smtpSecure = false; } diff --git a/src/components/notifications/Apprise.vue b/src/components/notifications/Apprise.vue new file mode 100644 index 000000000..b9d2a94b5 --- /dev/null +++ b/src/components/notifications/Apprise.vue @@ -0,0 +1,30 @@ + + + diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue new file mode 100644 index 000000000..3d4869edd --- /dev/null +++ b/src/components/notifications/Discord.vue @@ -0,0 +1,30 @@ + + + diff --git a/src/components/notifications/Gotify.vue b/src/components/notifications/Gotify.vue new file mode 100644 index 000000000..600b5e48a --- /dev/null +++ b/src/components/notifications/Gotify.vue @@ -0,0 +1,32 @@ + + + diff --git a/src/components/notifications/Line.vue b/src/components/notifications/Line.vue new file mode 100644 index 000000000..2468875b7 --- /dev/null +++ b/src/components/notifications/Line.vue @@ -0,0 +1,34 @@ + + + diff --git a/src/components/notifications/LunaSea.vue b/src/components/notifications/LunaSea.vue new file mode 100644 index 000000000..efa103fb7 --- /dev/null +++ b/src/components/notifications/LunaSea.vue @@ -0,0 +1,19 @@ + + + diff --git a/src/components/notifications/Mattermost.vue b/src/components/notifications/Mattermost.vue new file mode 100644 index 000000000..79ff23bb2 --- /dev/null +++ b/src/components/notifications/Mattermost.vue @@ -0,0 +1,42 @@ + + + diff --git a/src/components/notifications/Octopush.vue b/src/components/notifications/Octopush.vue new file mode 100644 index 000000000..94c5783b4 --- /dev/null +++ b/src/components/notifications/Octopush.vue @@ -0,0 +1,45 @@ + + + diff --git a/src/components/notifications/Pushbullet.vue b/src/components/notifications/Pushbullet.vue new file mode 100644 index 000000000..8eddb9fb7 --- /dev/null +++ b/src/components/notifications/Pushbullet.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/components/notifications/Pushover.vue b/src/components/notifications/Pushover.vue new file mode 100644 index 000000000..ff29a4066 --- /dev/null +++ b/src/components/notifications/Pushover.vue @@ -0,0 +1,72 @@ + + + diff --git a/src/components/notifications/Pushy.vue b/src/components/notifications/Pushy.vue new file mode 100644 index 000000000..752f16952 --- /dev/null +++ b/src/components/notifications/Pushy.vue @@ -0,0 +1,31 @@ + + + diff --git a/src/components/notifications/RocketChat.vue b/src/components/notifications/RocketChat.vue new file mode 100644 index 000000000..50c21b20e --- /dev/null +++ b/src/components/notifications/RocketChat.vue @@ -0,0 +1,39 @@ + + + diff --git a/src/components/notifications/Signal.vue b/src/components/notifications/Signal.vue new file mode 100644 index 000000000..f68b6dfed --- /dev/null +++ b/src/components/notifications/Signal.vue @@ -0,0 +1,42 @@ + + + diff --git a/src/components/notifications/Slack.vue b/src/components/notifications/Slack.vue new file mode 100644 index 000000000..c1b4f7c01 --- /dev/null +++ b/src/components/notifications/Slack.vue @@ -0,0 +1,39 @@ + + + diff --git a/src/components/notifications/Webhook.vue b/src/components/notifications/Webhook.vue new file mode 100644 index 000000000..002a2d507 --- /dev/null +++ b/src/components/notifications/Webhook.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js new file mode 100644 index 000000000..50716f14b --- /dev/null +++ b/src/components/notifications/index.js @@ -0,0 +1,44 @@ +import STMP from "./SMTP.vue" +import Telegram from "./Telegram.vue"; +import Discord from "./Discord.vue"; +import Webhook from "./Webhook.vue"; +import Signal from "./Signal.vue"; +import Gotify from "./Gotify.vue"; +import Slack from "./Slack.vue"; +import RocketChat from "./RocketChat.vue"; +import Teams from "./Teams.vue"; +import Pushover from "./Pushover.vue"; +import Pushy from "./Pushy.vue"; +import Octopush from "./Octopush.vue"; +import LunaSea from "./LunaSea.vue"; +import Apprise from "./Apprise.vue"; +import Pushbullet from "./Pushbullet.vue"; +import Line from "./Line.vue"; +import Mattermost from "./Mattermost.vue"; + +/** + * manage all notification form. + * + * @type { Record } + */ +const NotificationForm = { + "telegram": Telegram, + "webhook": Webhook, + "smtp": STMP, + "discord": Discord, + "teams": Teams, + "signal": Signal, + "gotify": Gotify, + "slack": Slack, + "rocket.chat": RocketChat, + "pushover": Pushover, + "pushy": Pushy, + "octopush": Octopush, + "lunasea": LunaSea, + "apprise": Apprise, + "pushbullet": Pushbullet, + "line": Line, + "mattermost": Mattermost +} + +export default NotificationForm diff --git a/src/languages/en.js b/src/languages/en.js index 1971f6f6d..bb0f50b9b 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -167,4 +167,21 @@ export default { Purple: "Purple", Pink: "Pink", "Search...": "Search...", + "telegram": "Telegram", + "webhook": "Webhook", + "smtp": "Email (SMTP)", + "discord": "Discord", + "teams": "Microsoft Teams", + "signal": "Signal", + "gotify": "Gotify", + "slack": "Slack", + "rocket.chat": "Rocket.chat", + "pushover": "Pushover", + "pushy": "Pushy", + "octopush": "Octopush", + "lunasea": "LunaSea", + "apprise": "Apprise (Support 50+ Notification services)", + "pushbullet": "Pushbullet", + "line": "Line Messenger", + "mattermost": "Mattermost", } From 534ac4b720dff8a4368666e2ceab8f66326ea4f0 Mon Sep 17 00:00:00 2001 From: zsxeee Date: Fri, 17 Sep 2021 16:54:50 +0800 Subject: [PATCH 2/6] Move Apprise check to child component --- src/components/NotificationDialog.vue | 7 +------ src/components/notifications/Apprise.vue | 9 +++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index c26990f89..f2549829c 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -100,8 +100,7 @@ export default { type: null, isDefault: false, // Do not set default value here, please scroll to show() - }, - appriseInstalled: false, + } } }, @@ -131,10 +130,6 @@ export default { }, mounted() { this.modal = new Modal(this.$refs.modal) - - this.$root.getSocket().emit("checkApprise", (installed) => { - this.appriseInstalled = installed; - }) }, methods: { diff --git a/src/components/notifications/Apprise.vue b/src/components/notifications/Apprise.vue index b9d2a94b5..000ce9162 100644 --- a/src/components/notifications/Apprise.vue +++ b/src/components/notifications/Apprise.vue @@ -12,8 +12,7 @@

Status: - - Apprise is installed + Apprise is installed Apprise is not installed. Read more

@@ -24,7 +23,13 @@ export default { data() { return { name: "apprise", + appriseInstalled: false } }, + mounted() { + this.$root.getSocket().emit("checkApprise", (installed) => { + this.appriseInstalled = installed; + }) + }, } From de8b61ef2bc325d9510de5ae1970704862b7de55 Mon Sep 17 00:00:00 2001 From: zsxeee Date: Fri, 17 Sep 2021 17:16:52 +0800 Subject: [PATCH 3/6] Remove unused imports --- src/components/NotificationDialog.vue | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index f2549829c..707adfc09 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -72,19 +72,11 @@ import { Modal } from "bootstrap" import { ucfirst } from "../util.ts" import Confirm from "./Confirm.vue"; -import HiddenInput from "./HiddenInput.vue"; -import Telegram from "./notifications/Telegram.vue"; -import Teams from "./notifications/Teams.vue"; -import SMTP from "./notifications/SMTP.vue"; import NotificationForm from "./notifications" export default { components: { Confirm, - HiddenInput, - Telegram, - Teams, - SMTP, }, props: {}, emits: ["added"], From 66e40d9fcb9ba87a4eb864489930dcdc578d615b Mon Sep 17 00:00:00 2001 From: zsxeee Date: Fri, 17 Sep 2021 20:20:44 +0800 Subject: [PATCH 4/6] Edit comment and remove unused variable --- src/components/notifications/Apprise.vue | 1 - src/components/notifications/Discord.vue | 10 ---------- src/components/notifications/Gotify.vue | 5 ----- src/components/notifications/Line.vue | 5 ----- src/components/notifications/LunaSea.vue | 10 ---------- src/components/notifications/Mattermost.vue | 10 ---------- src/components/notifications/Octopush.vue | 5 ----- src/components/notifications/Pushbullet.vue | 5 ----- src/components/notifications/Pushover.vue | 5 ----- src/components/notifications/Pushy.vue | 5 ----- src/components/notifications/RocketChat.vue | 10 ---------- src/components/notifications/SMTP.vue | 5 ----- src/components/notifications/Signal.vue | 10 ---------- src/components/notifications/Slack.vue | 10 ---------- src/components/notifications/Teams.vue | 10 ---------- src/components/notifications/Telegram.vue | 8 -------- src/components/notifications/Webhook.vue | 14 -------------- src/components/notifications/index.js | 2 +- 18 files changed, 1 insertion(+), 129 deletions(-) diff --git a/src/components/notifications/Apprise.vue b/src/components/notifications/Apprise.vue index 000ce9162..de3fe52b3 100644 --- a/src/components/notifications/Apprise.vue +++ b/src/components/notifications/Apprise.vue @@ -22,7 +22,6 @@ export default { data() { return { - name: "apprise", appriseInstalled: false } }, diff --git a/src/components/notifications/Discord.vue b/src/components/notifications/Discord.vue index 3d4869edd..c45a5262a 100644 --- a/src/components/notifications/Discord.vue +++ b/src/components/notifications/Discord.vue @@ -18,13 +18,3 @@
- - diff --git a/src/components/notifications/Gotify.vue b/src/components/notifications/Gotify.vue index 600b5e48a..737a297a8 100644 --- a/src/components/notifications/Gotify.vue +++ b/src/components/notifications/Gotify.vue @@ -23,10 +23,5 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "gotify", - } - }, } diff --git a/src/components/notifications/Line.vue b/src/components/notifications/Line.vue index 2468875b7..7d5312c37 100644 --- a/src/components/notifications/Line.vue +++ b/src/components/notifications/Line.vue @@ -25,10 +25,5 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "line", - } - }, } diff --git a/src/components/notifications/LunaSea.vue b/src/components/notifications/LunaSea.vue index efa103fb7..1511f411c 100644 --- a/src/components/notifications/LunaSea.vue +++ b/src/components/notifications/LunaSea.vue @@ -7,13 +7,3 @@ - - diff --git a/src/components/notifications/Mattermost.vue b/src/components/notifications/Mattermost.vue index 79ff23bb2..3e1a7bdc6 100644 --- a/src/components/notifications/Mattermost.vue +++ b/src/components/notifications/Mattermost.vue @@ -30,13 +30,3 @@ - - diff --git a/src/components/notifications/Octopush.vue b/src/components/notifications/Octopush.vue index 94c5783b4..10fb6df75 100644 --- a/src/components/notifications/Octopush.vue +++ b/src/components/notifications/Octopush.vue @@ -36,10 +36,5 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "octopush", - } - }, } diff --git a/src/components/notifications/Pushbullet.vue b/src/components/notifications/Pushbullet.vue index 8eddb9fb7..2c805e0ae 100644 --- a/src/components/notifications/Pushbullet.vue +++ b/src/components/notifications/Pushbullet.vue @@ -16,10 +16,5 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "pushbullet", - } - }, } diff --git a/src/components/notifications/Pushover.vue b/src/components/notifications/Pushover.vue index ff29a4066..ae836b5cb 100644 --- a/src/components/notifications/Pushover.vue +++ b/src/components/notifications/Pushover.vue @@ -63,10 +63,5 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "pushover", - } - }, } diff --git a/src/components/notifications/Pushy.vue b/src/components/notifications/Pushy.vue index 752f16952..64e4ef9c5 100644 --- a/src/components/notifications/Pushy.vue +++ b/src/components/notifications/Pushy.vue @@ -22,10 +22,5 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "pushy", - } - }, } diff --git a/src/components/notifications/RocketChat.vue b/src/components/notifications/RocketChat.vue index 50c21b20e..0776a1544 100644 --- a/src/components/notifications/RocketChat.vue +++ b/src/components/notifications/RocketChat.vue @@ -27,13 +27,3 @@ - - diff --git a/src/components/notifications/SMTP.vue b/src/components/notifications/SMTP.vue index 47661aa5b..d2d1e9df1 100644 --- a/src/components/notifications/SMTP.vue +++ b/src/components/notifications/SMTP.vue @@ -66,10 +66,5 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "smtp", - } - }, } diff --git a/src/components/notifications/Signal.vue b/src/components/notifications/Signal.vue index f68b6dfed..8598d07fa 100644 --- a/src/components/notifications/Signal.vue +++ b/src/components/notifications/Signal.vue @@ -30,13 +30,3 @@ - - diff --git a/src/components/notifications/Slack.vue b/src/components/notifications/Slack.vue index c1b4f7c01..1ec2cdfc1 100644 --- a/src/components/notifications/Slack.vue +++ b/src/components/notifications/Slack.vue @@ -27,13 +27,3 @@ - - diff --git a/src/components/notifications/Teams.vue b/src/components/notifications/Teams.vue index 748bf7ad6..45ba26c84 100644 --- a/src/components/notifications/Teams.vue +++ b/src/components/notifications/Teams.vue @@ -17,13 +17,3 @@ - - diff --git a/src/components/notifications/Telegram.vue b/src/components/notifications/Telegram.vue index 9be1e004f..a59c804a2 100644 --- a/src/components/notifications/Telegram.vue +++ b/src/components/notifications/Telegram.vue @@ -47,11 +47,6 @@ export default { components: { HiddenInput, }, - data() { - return { - name: "telegram", - } - }, computed: { telegramGetUpdatesURL() { let token = "" @@ -62,9 +57,6 @@ export default { return `https://api.telegram.org/bot${token}/getUpdates`; }, - }, - mounted() { - }, methods: { async autoGetTelegramChatID() { diff --git a/src/components/notifications/Webhook.vue b/src/components/notifications/Webhook.vue index 002a2d507..1554a83d7 100644 --- a/src/components/notifications/Webhook.vue +++ b/src/components/notifications/Webhook.vue @@ -21,17 +21,3 @@ - - - - diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 50716f14b..52d4d44d5 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -17,7 +17,7 @@ import Line from "./Line.vue"; import Mattermost from "./Mattermost.vue"; /** - * manage all notification form. + * Manage all notification form. * * @type { Record } */ From 2fb3c40307c6f113578582c24f68dd2c43bf615c Mon Sep 17 00:00:00 2001 From: zsxeee Date: Fri, 17 Sep 2021 20:40:57 +0800 Subject: [PATCH 5/6] Variable name and key binding --- src/components/NotificationDialog.vue | 10 +++++----- src/components/notifications/index.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 707adfc09..4b1b0cc40 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -13,7 +13,7 @@
@@ -72,7 +72,7 @@ import { Modal } from "bootstrap" import { ucfirst } from "../util.ts" import Confirm from "./Confirm.vue"; -import NotificationForm from "./notifications" +import NotificationFormList from "./notifications" export default { components: { @@ -85,10 +85,10 @@ export default { model: null, processing: false, id: null, - notificationTypes: Object.keys(NotificationForm), + notificationTypes: Object.keys(NotificationFormList), notification: { name: "", - /** @type { null | keyof NotificationForm } */ + /** @type { null | keyof NotificationFormList } */ type: null, isDefault: false, // Do not set default value here, please scroll to show() @@ -101,7 +101,7 @@ export default { if (!this.notification.type) { return null } - return NotificationForm[this.notification.type] + return NotificationFormList[this.notification.type] } }, diff --git a/src/components/notifications/index.js b/src/components/notifications/index.js index 52d4d44d5..e377803e6 100644 --- a/src/components/notifications/index.js +++ b/src/components/notifications/index.js @@ -21,7 +21,7 @@ import Mattermost from "./Mattermost.vue"; * * @type { Record } */ -const NotificationForm = { +const NotificationFormList = { "telegram": Telegram, "webhook": Webhook, "smtp": STMP, @@ -41,4 +41,4 @@ const NotificationForm = { "mattermost": Mattermost } -export default NotificationForm +export default NotificationFormList From ffbc25722d8fe086b83046ae94913aa5f6051d1b Mon Sep 17 00:00:00 2001 From: zsxeee Date: Sun, 19 Sep 2021 18:05:22 +0800 Subject: [PATCH 6/6] Move default setting to child component --- src/components/NotificationDialog.vue | 2 -- src/components/notifications/Gotify.vue | 5 +++++ src/components/notifications/SMTP.vue | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/NotificationDialog.vue b/src/components/NotificationDialog.vue index 4b1b0cc40..78d890919 100644 --- a/src/components/NotificationDialog.vue +++ b/src/components/NotificationDialog.vue @@ -150,8 +150,6 @@ export default { // Set Default value here this.notification.type = this.notificationTypes[0]; - this.notification.gotifyPriority = 8; - this.notification.smtpSecure = false; } this.modal.show() diff --git a/src/components/notifications/Gotify.vue b/src/components/notifications/Gotify.vue index 737a297a8..f8039d58a 100644 --- a/src/components/notifications/Gotify.vue +++ b/src/components/notifications/Gotify.vue @@ -23,5 +23,10 @@ export default { components: { HiddenInput, }, + mounted() { + if (typeof this.$parent.notification.gotifyPriority === "undefined") { + this.$parent.notification.gotifyPriority = 8; + } + }, } diff --git a/src/components/notifications/SMTP.vue b/src/components/notifications/SMTP.vue index d2d1e9df1..b86a62608 100644 --- a/src/components/notifications/SMTP.vue +++ b/src/components/notifications/SMTP.vue @@ -66,5 +66,10 @@ export default { components: { HiddenInput, }, + mounted() { + if (typeof this.$parent.notification.smtpSecure === "undefined") { + this.$parent.notification.smtpSecure = false; + } + }, }