From 608e3f5582604e6a7079859bcf722d7c645a4245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Haugsb=C3=B8?= Date: Tue, 27 Dec 2022 23:26:05 +0100 Subject: [PATCH 1/7] Feature: Clone existing monitor Closes #565 Closes #2319 Adds the feature of cloning existing monitor, I have briefly tested it with ping and https and ensured that all properties was cloned including notifications. --- src/languages/en.js | 2 ++ src/pages/Details.vue | 3 +++ src/pages/EditMonitor.vue | 27 ++++++++++++++++++++++++--- src/router.js | 4 ++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index e760f92ea..59ea0570d 100644 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -57,6 +57,7 @@ export default { List: "List", Add: "Add", "Add New Monitor": "Add New Monitor", + "Clone Monitor": "Clone Monitor", "Quick Stats": "Quick Stats", Up: "Up", Down: "Down", @@ -70,6 +71,7 @@ export default { "No important events": "No important events", Resume: "Resume", Edit: "Edit", + Clone: "Clone", Delete: "Delete", Current: "Current", Uptime: "Uptime", diff --git a/src/pages/Details.vue b/src/pages/Details.vue index 6d6a8dd9c..40ed0358d 100644 --- a/src/pages/Details.vue +++ b/src/pages/Details.vue @@ -30,6 +30,9 @@ {{ $t("Edit") }} + + {{ $t("Clone") }} + diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index c9d5ad2f1..f0c99b5b5 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -620,13 +620,23 @@ export default { }, pageName() { - return this.$t((this.isAdd) ? "Add New Monitor" : "Edit"); + let name = "Add New Monitor"; + if (this.isClone) { + name = "Clone Monitor"; + } else if (this.isEdit) { + name = "Edit"; + } + return this.$t(name); }, isAdd() { return this.$route.path === "/add"; }, + isClone() { + return this.$route.path.startsWith("/clone"); + }, + isEdit() { return this.$route.path.startsWith("/edit"); }, @@ -804,11 +814,22 @@ message HealthCheckResponse { this.monitor.notificationIDList[this.$root.notificationList[i].id] = true; } } - } else if (this.isEdit) { + } else if (this.isEdit || this.isClone) { this.$root.getSocket().emit("getMonitor", this.$route.params.id, (res) => { if (res.ok) { this.monitor = res.monitor; + if (this.isClone) { + /** + * Cloning a monitor will include properties that can not be posted to backend + * as they are not valid columns in the SQLite table. + */ + this.monitor.id = undefined; // Remove id when cloning as we want a new id + this.monitor.includeSensitiveData = undefined; + this.monitor.maintenance = undefined; + this.monitor.tags = undefined; // FIXME: Cloning tags does not work yet + } + // Handling for monitors that are created before 1.7.0 if (this.monitor.retryInterval === 0) { this.monitor.retryInterval = this.monitor.interval; @@ -866,7 +887,7 @@ message HealthCheckResponse { this.monitor.headers = JSON.stringify(JSON.parse(this.monitor.headers), null, 4); } - if (this.isAdd) { + if (this.isAdd || this.isClone) { this.$root.add(this.monitor, async (res) => { if (res.ok) { diff --git a/src/router.js b/src/router.js index 380488264..a5938c22d 100644 --- a/src/router.js +++ b/src/router.js @@ -63,6 +63,10 @@ const routes = [ path: "/edit/:id", component: EditMonitor, }, + { + path: "/clone/:id", + component: EditMonitor, + }, ], }, { From 4d0bdae6bf4ead2617f9b9f71e97e5edf0466d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathias=20Haugsb=C3=B8?= Date: Tue, 27 Dec 2022 23:27:23 +0100 Subject: [PATCH 2/7] Add jsdoc for Tag type Does not work properly but is still useful --- src/components/Tag.vue | 10 ++++++++-- src/components/TagsManager.vue | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/Tag.vue b/src/components/Tag.vue index 0325d9900..705408b2d 100644 --- a/src/components/Tag.vue +++ b/src/components/Tag.vue @@ -18,9 +18,15 @@