Add filtering
This commit is contained in:
parent
51b275b655
commit
e6a62c1360
|
@ -1,17 +1,28 @@
|
|||
import prisma from '../../prisma'
|
||||
|
||||
// TODO: Add filtering
|
||||
export async function wifiDevices(_, { identifiedOnly, nonIdentifiedOnly }) {
|
||||
if (identifiedOnly && nonIdentifiedOnly)
|
||||
throw new Error('Invalid combination of filters')
|
||||
export async function wifiDevices(_, { take = 100, skip = 0, search }) {
|
||||
const mode = 'insensitive'
|
||||
|
||||
if (search === null)
|
||||
search = undefined
|
||||
|
||||
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' }],
|
||||
where: identifiedOnly
|
||||
? { NOT: { userId: null } }
|
||||
: nonIdentifiedOnly
|
||||
? { userId: null }
|
||||
: {},
|
||||
include: { user: true }
|
||||
include: { user: true },
|
||||
take,
|
||||
skip
|
||||
})
|
||||
}
|
||||
|
|
|
@ -36,8 +36,8 @@ const typeDefs = gql`
|
|||
"Devices that uses the Wi-Fi"
|
||||
wifiDevices(
|
||||
search: String = ""
|
||||
identifiedOnly: Boolean = false
|
||||
nonIdentifiedOnly: Boolean = false
|
||||
take: Int
|
||||
skip: Int
|
||||
): [WifiDevice]! @auth(roles: ["superAdmin"])
|
||||
|
||||
"Users that uses the Wi-Fi"
|
||||
|
|
|
@ -32,10 +32,7 @@
|
|||
<v-container fluid>
|
||||
<div v-if="wifiDevices && stats" class="text-center my-4">
|
||||
<v-chip color="primary" class="mr-1" dark>
|
||||
{{
|
||||
wifiDevices &&
|
||||
wifiDevices.filter(device => device.status == 'ONLINE').length
|
||||
}}
|
||||
{{ stats.onlineWifiDevices }}
|
||||
</v-chip>
|
||||
online de
|
||||
<v-chip class="mx-1">
|
||||
|
@ -48,7 +45,6 @@
|
|||
:items-per-page.sync="itemsPerPage"
|
||||
:page="page"
|
||||
:loading="$apollo.queries.wifiDevices.loading"
|
||||
:search="search"
|
||||
>
|
||||
<template #default="{ items }">
|
||||
<v-expansion-panels multiple>
|
||||
|
@ -217,9 +213,10 @@ export default {
|
|||
apollo: {
|
||||
wifiDevices: {
|
||||
fetchPolicy: 'cache-and-network',
|
||||
pollInterval: 10000,
|
||||
query: gql`
|
||||
query {
|
||||
wifiDevices {
|
||||
query wifiDevices($search: String) {
|
||||
wifiDevices(search: $search) {
|
||||
user {
|
||||
displayName
|
||||
sAMAccountName
|
||||
|
@ -238,13 +235,19 @@ export default {
|
|||
status
|
||||
}
|
||||
}
|
||||
`
|
||||
`,
|
||||
variables() {
|
||||
return {
|
||||
search: this.search
|
||||
}
|
||||
}
|
||||
},
|
||||
stats: {
|
||||
query: gql`
|
||||
query {
|
||||
stats {
|
||||
totalWifiDevices
|
||||
onlineWifiDevices
|
||||
}
|
||||
}
|
||||
`
|
||||
|
|
Loading…
Reference in New Issue
Block a user