diff --git a/src/components/MonitorList.vue b/src/components/MonitorList.vue index be59553c0..127a50928 100644 --- a/src/components/MonitorList.vue +++ b/src/components/MonitorList.vue @@ -23,36 +23,6 @@ -
- -
-
@@ -71,8 +41,44 @@
this.$root.monitorList[id].active).length; - Object.keys(this.selectedMonitors) - .filter((id) => this.$root.monitorList[id].active) - .forEach((id) => this.$root.getSocket().emit("pauseMonitor", id, () => {})); - - if (count > 0) { - this.$root.toastSuccess(this.$t("pausedMonitorsMsg", [count])); + const activeMonitors = Object.keys(this.selectedMonitors).filter((id) => this.$root.monitorList[id].active); + + if (activeMonitors.length === 0) { + this.$root.toastError(this.$t("noMonitorsPausedMsg")); + return; } + + this.bulkActionInProgress = true; + activeMonitors.forEach((id) => this.$root.getSocket().emit("pauseMonitor", id, () => {})); + this.$root.toastSuccess(this.$tc("pausedMonitorsMsg", activeMonitors.length)); + this.bulkActionInProgress = false; this.cancelSelectMode(); }, /** @@ -349,48 +359,57 @@ export default { * @returns {void} */ resumeSelected() { - const count = Object.keys(this.selectedMonitors).filter(id => !this.$root.monitorList[id].active).length; - Object.keys(this.selectedMonitors) - .filter(id => !this.$root.monitorList[id].active) - .forEach(id => this.$root.getSocket().emit("resumeMonitor", id, () => {})); - - if (count > 0) { - this.$root.toastSuccess(this.$t("resumedMonitorsMsg", [count])); + const inactiveMonitors = Object.keys(this.selectedMonitors).filter((id) => !this.$root.monitorList[id].active); + + if (inactiveMonitors.length === 0) { + this.$root.toastError(this.$t("noMonitorsResumedMsg")); + return; } + + this.bulkActionInProgress = true; + inactiveMonitors.forEach((id) => this.$root.getSocket().emit("resumeMonitor", id, () => {})); + this.$root.toastSuccess(this.$tc("resumedMonitorsMsg", inactiveMonitors.length)); + this.bulkActionInProgress = false; this.cancelSelectMode(); }, - /** - * Show dialog to confirm deletion - * @returns {void} - */ - deleteDialog() { - this.$refs.confirmDelete.show(); - }, /** * Delete each selected monitor - * @returns {void} + * @returns {Promise} */ - deleteSelected() { - const count = Object.keys(this.selectedMonitors).length; + async deleteSelected() { + const monitorIds = Object.keys(this.selectedMonitors); + + this.bulkActionInProgress = true; let successCount = 0; let errorCount = 0; - Object.keys(this.selectedMonitors).forEach(id => { - this.$root.getSocket().emit("deleteMonitor", id, false, (res) => { - if (res.ok) { - successCount++; - } else { - errorCount++; - this.$root.toastError(res.msg); - } + for (const id of monitorIds) { + try { + await new Promise((resolve, reject) => { + this.$root.getSocket().emit("deleteMonitor", id, false, (res) => { + if (res.ok) { + successCount++; + resolve(); + } else { + errorCount++; + reject(); + } + }); + }); + } catch (error) { + // Error already counted + } + } - // Show succes message after all deletions completed - if (successCount + errorCount === count && successCount > 0) { - this.$root.toastSuccess(this.$t("deletedMonitorsMsg", [successCount])); - } - }); - }); + this.bulkActionInProgress = false; + if (successCount > 0) { + this.$root.toastSuccess(this.$tc("deletedMonitorsMsg", successCount)); + } + if (errorCount > 0) { + this.$root.toastError(this.$t("bulkDeleteErrorMsg", [errorCount])); + } + this.cancelSelectMode(); }, /**