Browse Source

add duplicate monitor button

See #565
thomasleveil/feature/565-duplicate-monitor
Thomas LEVEIL 3 years ago
parent
commit
86d3d99c3b
  1. 10
      src/pages/Details.vue
  2. 29
      src/pages/EditMonitor.vue

10
src/pages/Details.vue

@ -32,6 +32,9 @@
<button class="btn btn-danger" @click="deleteDialog">
<font-awesome-icon icon="trash" /> {{ $t("Delete") }}
</button>
<button class="btn btn-secondary" @click="duplicate">
<font-awesome-icon icon="copy" /> {{ $t("Duplicate") }}
</button>
</div>
<div class="shadow-box">
@ -314,6 +317,13 @@ export default {
this.$refs.confirmDelete.show();
},
duplicate() {
this.$router.push({
path: "/add",
query: { monitor: JSON.stringify(Object.assign({}, this.monitor, { id: undefined })) }
});
},
clearEventsDialog() {
this.$refs.confirmClearEvents.show();
},

29
src/pages/EditMonitor.vue

@ -351,6 +351,22 @@ export default {
{
"HeaderName": "HeaderValue"
}`;
},
model() {
// parse monitor model eventually found in querystring
let model = null;
try {
model = JSON.parse(this.$route.query.monitor);
model.name = `${model.name} (duplicate)`;
delete model.id;
model.tags = model.tags.map(tag => {
tag.new = true;
delete tag.monitor_id;
return tag;
});
} catch {}
return model;
}
},
@ -410,8 +426,7 @@ export default {
methods: {
init() {
if (this.isAdd) {
this.monitor = {
const monitorDefaults = {
type: "http",
name: "",
url: "https://",
@ -428,15 +443,25 @@ export default {
dns_resolve_server: "1.1.1.1",
};
if (this.model) {
this.$refs.tagsManager.$data.newTags = this.model.tags;
}
this.monitor = Object.assign({}, monitorDefaults, this.model, { tags: undefined });
if (this.model && this.model.notificationIDList) {
this.monitor.notificationIDList = this.model.notificationIDList;
} else {
for (let i = 0; i < this.$root.notificationList.length; i++) {
if (this.$root.notificationList[i].isDefault == true) {
this.monitor.notificationIDList[this.$root.notificationList[i].id] = true;
}
}
}
} else if (this.isEdit) {
this.$root.getSocket().emit("getMonitor", this.$route.params.id, (res) => {
if (res.ok) {
this.monitor = res.monitor;
this.preselectedTags = res.monitor.tags;
// Handling for monitors that are created before 1.7.0
if (this.monitor.retryInterval === 0) {

Loading…
Cancel
Save