From f3ac351d755ffa6ba9195a45db8bf7eea261c492 Mon Sep 17 00:00:00 2001 From: Peace Date: Sat, 28 Jan 2023 14:02:10 +0100 Subject: [PATCH] feat: set childs under maintenance if parent is too --- server/model/monitor.js | 12 ++++++- .../maintenance-socket-handler.js | 2 +- src/pages/EditMaintenance.vue | 34 +++++++++++++++---- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index e81c4ad38..17722f9fe 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -1322,7 +1322,17 @@ class Monitor extends BeanModel { ON maintenance_timeslot.maintenance_id = maintenance.id WHERE ${activeCondition} LIMIT 1`, [ monitorID ]); - return maintenance.count !== 0; + + if (maintenance.count !== 0) { + return true; + } + + // Check if parent is under maintenance + const parent = await Monitor.getParent(monitorID); + if (parent === null) { + return false; + } + return await Monitor.isUnderMaintenance(parent.id); } /** Make sure monitor interval is between bounds */ diff --git a/server/socket-handlers/maintenance-socket-handler.js b/server/socket-handlers/maintenance-socket-handler.js index 929150cdd..870f9a033 100644 --- a/server/socket-handlers/maintenance-socket-handler.js +++ b/server/socket-handlers/maintenance-socket-handler.js @@ -187,7 +187,7 @@ module.exports.maintenanceSocketHandler = (socket) => { log.debug("maintenance", `Get Monitors for Maintenance: ${maintenanceID} User ID: ${socket.userID}`); - let monitors = await R.getAll("SELECT monitor.id, monitor.name FROM monitor_maintenance mm JOIN monitor ON mm.monitor_id = monitor.id WHERE mm.maintenance_id = ? ", [ + let monitors = await R.getAll("SELECT monitor.id FROM monitor_maintenance mm JOIN monitor ON mm.monitor_id = monitor.id WHERE mm.maintenance_id = ? ", [ maintenanceID, ]); diff --git a/src/pages/EditMaintenance.vue b/src/pages/EditMaintenance.vue index f0d87fe5a..103506e35 100644 --- a/src/pages/EditMaintenance.vue +++ b/src/pages/EditMaintenance.vue @@ -33,7 +33,7 @@ v-model="affectedMonitors" :options="affectedMonitorsOptions" track-by="id" - label="name" + label="pathName" :multiple="true" :close-on-select="false" :clear-on-select="false" @@ -342,17 +342,39 @@ export default { }, }, mounted() { - this.init(); - this.$root.getMonitorList((res) => { if (res.ok) { - Object.values(this.$root.monitorList).map(monitor => { + Object.values(this.$root.monitorList).sort((m1, m2) => { + + if (m1.active !== m2.active) { + if (m1.active === 0) { + return 1; + } + + if (m2.active === 0) { + return -1; + } + } + + if (m1.weight !== m2.weight) { + if (m1.weight > m2.weight) { + return -1; + } + + if (m1.weight < m2.weight) { + return 1; + } + } + + return m1.pathName.localeCompare(m2.pathName); + }).map(monitor => { this.affectedMonitorsOptions.push({ id: monitor.id, - name: monitor.name, + pathName: monitor.pathName, }); }); } + this.init(); }); }, methods: { @@ -387,7 +409,7 @@ export default { this.$root.getSocket().emit("getMonitorMaintenance", this.$route.params.id, (res) => { if (res.ok) { Object.values(res.monitors).map(monitor => { - this.affectedMonitors.push(monitor); + this.affectedMonitors.push(this.affectedMonitorsOptions.find(item => item.id === monitor.id)); }); } else { toast.error(res.msg);