Fix review

Co-Authored-By: Antoine Nguyen <tonio@ngyn.org>
This commit is contained in:
Spitap
2023-03-03 11:25:02 +01:00
co-authored by Antoine Nguyen
parent 8807fcd94b
commit 5558dfba30
6 changed files with 44 additions and 22 deletions
+15 -4
View File
@@ -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)
}
}
}
+4 -3
View File
@@ -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()
})
+1
View File
@@ -0,0 +1 @@
{"ALARM_OPENED":1, "ALARM_CLOSED":2}
+1 -1
View File
@@ -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 => {