Add filtering

This commit is contained in:
Douglas Barone 2022-04-06 08:04:52 -04:00
parent 51b275b655
commit e6a62c1360
3 changed files with 35 additions and 21 deletions

View File

@ -1,17 +1,28 @@
import prisma from '../../prisma' import prisma from '../../prisma'
// TODO: Add filtering export async function wifiDevices(_, { take = 100, skip = 0, search }) {
export async function wifiDevices(_, { identifiedOnly, nonIdentifiedOnly }) { const mode = 'insensitive'
if (identifiedOnly && nonIdentifiedOnly)
throw new Error('Invalid combination of filters') if (search === null)
search = undefined
return prisma.wifiDevice.findMany({ return prisma.wifiDevice.findMany({
where: {
OR: [
{ hostname: { contains: search, mode } },
{ mac: { contains: search, mode } },
{ ip: { contains: search, mode } },
{ apName: { contains: search, mode } },
{ essid: { contains: search, mode } },
{ oui: { contains: search, mode } },
{ controller: { contains: search, mode } },
{ user: { displayName: { contains: search, mode } } },
{ user: { sAMAccountName: { contains: search, mode } } }
]
},
orderBy: [{ lastSeen: 'desc' }, { hostname: 'asc' }], orderBy: [{ lastSeen: 'desc' }, { hostname: 'asc' }],
where: identifiedOnly include: { user: true },
? { NOT: { userId: null } } take,
: nonIdentifiedOnly skip
? { userId: null }
: {},
include: { user: true }
}) })
} }

View File

@ -35,9 +35,9 @@ const typeDefs = gql`
"Devices that uses the Wi-Fi" "Devices that uses the Wi-Fi"
wifiDevices( wifiDevices(
search: String = "" search: String = ""
identifiedOnly: Boolean = false take: Int
nonIdentifiedOnly: Boolean = false skip: Int
): [WifiDevice]! @auth(roles: ["superAdmin"]) ): [WifiDevice]! @auth(roles: ["superAdmin"])
"Users that uses the Wi-Fi" "Users that uses the Wi-Fi"

View File

@ -32,10 +32,7 @@
<v-container fluid> <v-container fluid>
<div v-if="wifiDevices && stats" class="text-center my-4"> <div v-if="wifiDevices && stats" class="text-center my-4">
<v-chip color="primary" class="mr-1" dark> <v-chip color="primary" class="mr-1" dark>
{{ {{ stats.onlineWifiDevices }}
wifiDevices &&
wifiDevices.filter(device => device.status == 'ONLINE').length
}}
</v-chip> </v-chip>
online de online de
<v-chip class="mx-1"> <v-chip class="mx-1">
@ -48,7 +45,6 @@
:items-per-page.sync="itemsPerPage" :items-per-page.sync="itemsPerPage"
:page="page" :page="page"
:loading="$apollo.queries.wifiDevices.loading" :loading="$apollo.queries.wifiDevices.loading"
:search="search"
> >
<template #default="{ items }"> <template #default="{ items }">
<v-expansion-panels multiple> <v-expansion-panels multiple>
@ -217,9 +213,10 @@ export default {
apollo: { apollo: {
wifiDevices: { wifiDevices: {
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
pollInterval: 10000,
query: gql` query: gql`
query { query wifiDevices($search: String) {
wifiDevices { wifiDevices(search: $search) {
user { user {
displayName displayName
sAMAccountName sAMAccountName
@ -238,13 +235,19 @@ export default {
status status
} }
} }
` `,
variables() {
return {
search: this.search
}
}
}, },
stats: { stats: {
query: gql` query: gql`
query { query {
stats { stats {
totalWifiDevices totalWifiDevices
onlineWifiDevices
} }
} }
` `