From c16c1297d1dd194d7c2c7a00faaa88c82a1d0ce6 Mon Sep 17 00:00:00 2001 From: Douglas Barone Date: Thu, 9 Jun 2022 13:29:14 +0000 Subject: [PATCH] Minor UI changes --- server/src/lib/wifiDevices.js | 32 +++++++++++++++++-- server/src/resolvers/Query/wifiDevices.js | 6 ++-- .../AccessPointClientsDataTable.vue | 21 ++++++------ .../DataTables/UserWifiDevicesDataTable.vue | 20 ++++++------ .../DataTables/WifiDevicesDataTable.vue | 26 +++++++++------ web/src/scss/style.scss | 5 +++ web/src/views/WifiDevices.vue | 2 +- 7 files changed, 78 insertions(+), 34 deletions(-) diff --git a/server/src/lib/wifiDevices.js b/server/src/lib/wifiDevices.js index 0d5a0f1..dc08335 100644 --- a/server/src/lib/wifiDevices.js +++ b/server/src/lib/wifiDevices.js @@ -5,12 +5,14 @@ import * as ciscoController from './ciscoController' import prisma from '../prisma' import { pubsub, USER_PRESENCE_UPDATED, ACCESS_POINTS_UPDATED } from '../pubsub' -import { logError, logSuccess } from './logger' +import { logError, logInfo, logLow, logSuccess } from './logger' import { performance } from 'perf_hooks' const RECENT_THRESHOLD_IN_MINUTES = 2 +const OLD_DEVICES_THRESHOLD_IN_DAYS = 90 + const TIMEOUT_IN_MILLISECONDS = process.env.TASK_TIMEOUT || 120000 let working = false @@ -225,4 +227,30 @@ function updateDevicesInfo() { }) } -export { updateDevicesInfo } +// Delete devices that are offline for more than OLD_DEVICES_THRESHOLD_IN_DAYS days +async function deleteOldDevices() { + const oldDevicesThresholdInMilliseconds = OLD_DEVICES_THRESHOLD_IN_DAYS * 24 * 60 * 60 * 1000 + + const oldDevices = await prisma.wifiDevice.deleteMany({ + where: { + lastSeen: { + lt: new Date(Date.now() - oldDevicesThresholdInMilliseconds) + }, + status: 'OFFLINE' + } + }) + + if (oldDevices.count > 0) + logInfo({ + tags: ['wifiDevices', 'deleteOldDevices'], + message: `${oldDevices.count} dispositivos Wi-Fi não vistos há mais de ${OLD_DEVICES_THRESHOLD_IN_DAYS} dias foram excluídos.`, + data: { oldDevices } + }) + else + logInfo({ + tags: ['wifiDevices', 'deleteOldDevices'], + message: `Nenhum dispositivo Wi-Fi não visto há mais de ${OLD_DEVICES_THRESHOLD_IN_DAYS} dias foi encontrado.` + }) +} + +export { updateDevicesInfo, deleteOldDevices } diff --git a/server/src/resolvers/Query/wifiDevices.js b/server/src/resolvers/Query/wifiDevices.js index a413484..bea42a5 100644 --- a/server/src/resolvers/Query/wifiDevices.js +++ b/server/src/resolvers/Query/wifiDevices.js @@ -7,6 +7,8 @@ export async function wifiDevices(parent, { take = 50, skip = 0, search, sortBy, if (!onlineOnly) onlineOnly = undefined + console.log(sortBy, sortDesc); + const where = { OR: [ { hostname: { contains: search, mode } }, @@ -29,8 +31,8 @@ export async function wifiDevices(parent, { take = 50, skip = 0, search, sortBy, data: prisma.wifiDevice.findMany({ where, orderBy: [ - { status: 'asc' }, - { [sortBy || 'hostname']: sortDesc ? 'desc' : 'asc' }], + { [sortBy || 'hostname']: sortDesc ? 'desc' : 'asc' }, + ], include: { user: true, accessPoint: true }, take, skip diff --git a/web/src/components/DataTables/AccessPointClientsDataTable.vue b/web/src/components/DataTables/AccessPointClientsDataTable.vue index c70f5d9..9a05315 100644 --- a/web/src/components/DataTables/AccessPointClientsDataTable.vue +++ b/web/src/components/DataTables/AccessPointClientsDataTable.vue @@ -13,12 +13,12 @@ - - -