mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-22 06:28:41 +02:00
+15
-4
@@ -52,7 +52,7 @@ export default {
|
||||
created () {
|
||||
// this.$store.dispatch('auth/initialize')
|
||||
bus.$on('notification', this.showNotification)
|
||||
bus.$on('logged', this.checkAlarms)
|
||||
bus.$on('loggedIn', this.checkAlarms)
|
||||
},
|
||||
mounted () {
|
||||
this.checkAlarms()
|
||||
@@ -66,7 +66,9 @@ export default {
|
||||
notificationColor: 'success',
|
||||
notificationTimeout: 2000,
|
||||
alarmNotified: [],
|
||||
alarmChecker: null
|
||||
alarmChecker: null,
|
||||
lastAlarmDate: '',
|
||||
alarmSleepTime: 10000
|
||||
}),
|
||||
methods: {
|
||||
showNotification (options) {
|
||||
@@ -79,10 +81,19 @@ export default {
|
||||
checkAlarms () {
|
||||
if (this.isAuthenticated) {
|
||||
this.alarmChecker = window.setInterval(() => {
|
||||
alarms.getAll({}).then(resp => {
|
||||
const params = {}
|
||||
if (this.lastAlarmDate instanceof Date) {
|
||||
params.min_date = this.lastAlarmDate
|
||||
}
|
||||
alarms.getAll(params).then(resp => {
|
||||
let count = 0
|
||||
for (const alarm of resp.data) {
|
||||
if (alarm.status === 1 && !this.alarmNotified.includes(alarm.id)) {
|
||||
if (this.lastAlarmDate instanceof Date && new Date(alarm.created) > this.lastAlarmDate) {
|
||||
this.lastAlarmDate = new Date(alarm.created)
|
||||
} else if (!(this.lastAlarmDate instanceof Date)) {
|
||||
this.lastAlarmDate = new Date(alarm.created)
|
||||
}
|
||||
count++
|
||||
this.alarmNotified.push(alarm.id)
|
||||
}
|
||||
@@ -91,7 +102,7 @@ export default {
|
||||
bus.$emit('notification', { msg: this.$gettext('You have one or more opened alarms'), type: 'error' })
|
||||
}
|
||||
})
|
||||
}, 10000)
|
||||
}, this.alarmSleepTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ import { bus } from '@/main'
|
||||
import alarms from '@/api/alarms'
|
||||
import debounce from 'debounce'
|
||||
import MenuItems from '@/components/tools/MenuItems'
|
||||
import constants from '@/constants.json'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
@@ -121,7 +122,7 @@ export default {
|
||||
}
|
||||
this.loading = true
|
||||
alarms.getAll(params).then(resp => {
|
||||
this.alarms = resp.data.results
|
||||
this.alarms = resp.data
|
||||
this.totalAlarms = resp.data.count
|
||||
this.loading = false
|
||||
})
|
||||
@@ -135,13 +136,13 @@ export default {
|
||||
})
|
||||
},
|
||||
async closeAlarm (alarm) {
|
||||
alarms.switchStatus(alarm.id, { status: 2 }).then(() => {
|
||||
alarms.switchStatus(alarm.id, { status: constants.ALARM_CLOSED }).then(() => {
|
||||
bus.$emit('notification', { msg: this.$gettext('Alarm closed') })
|
||||
this.fetchAlarms()
|
||||
})
|
||||
},
|
||||
async openAlarm (alarm) {
|
||||
alarms.switchStatus(alarm.id, { status: 1 }).then(() => {
|
||||
alarms.switchStatus(alarm.id, { status: constants.ALARM_OPENED }).then(() => {
|
||||
bus.$emit('notification', { msg: this.$gettext('Alarm re-opened') })
|
||||
this.fetchAlarms()
|
||||
})
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"ALARM_OPENED":1, "ALARM_CLOSED":2}
|
||||
@@ -87,7 +87,7 @@ export default {
|
||||
Cookies.set('token', resp.data.access, { sameSite: 'strict' })
|
||||
Cookies.set('refreshToken', resp.data.refresh, { sameSite: 'strict' })
|
||||
this.$store.dispatch('auth/initialize').then(() => {
|
||||
bus.$emit('logged')
|
||||
bus.$emit('loggedIn')
|
||||
this.$router.push({ name: 'DomainList' })
|
||||
})
|
||||
}).catch(err => {
|
||||
|
||||
Reference in New Issue
Block a user