Sync data with server

This commit is contained in:
Douglas Barone 2022-06-07 19:10:39 +00:00
parent 4429c84b1c
commit ec88f85b72
5 changed files with 70 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import prisma from '../../prisma' import prisma from '../../prisma'
export async function wifiDevices(parent, { take = 50, skip = 0, search }) { export async function wifiDevices(parent, { take = 50, skip = 0, search, sortBy, sortDesc }) {
const mode = 'insensitive' const mode = 'insensitive'
if (!search) if (!search)
@ -26,7 +26,7 @@ export async function wifiDevices(parent, { take = 50, skip = 0, search }) {
}), }),
data: prisma.wifiDevice.findMany({ data: prisma.wifiDevice.findMany({
where, where,
orderBy: [{ lastSeen: 'desc' }, { ip: 'asc' }], orderBy: [{ [sortBy || 'hostname']: sortDesc ? 'desc' : 'asc' }, { ip: 'asc' }],
include: { user: true, accessPoint: true }, include: { user: true, accessPoint: true },
take, take,
skip skip

View File

@ -36,6 +36,8 @@ const typeDefs = gql`
search: String = "" search: String = ""
take: Int take: Int
skip: Int skip: Int
sortBy: WifiDevicesResultSortBy = "signalStrength"
sortDesc: Boolean = false
): WifiDevicesResult! @auth(roles: ["superAdmin"]) ): WifiDevicesResult! @auth(roles: ["superAdmin"])
"Users that uses the Wi-Fi" "Users that uses the Wi-Fi"
@ -397,6 +399,24 @@ const typeDefs = gql`
local: String local: String
notes: String notes: String
} }
enum WifiDevicesResultSortBy{
mac
hostname
firstSeen
lastSeen
essid
ip
uptime
apName
status
signalStrength
frequency
protocol
speed
usage
}
` `
export { typeDefs } export { typeDefs }

View File

@ -1,13 +1,17 @@
<template> <template>
<div> <div>
<v-data-table <v-data-table
sort-by="signalStrength" v-bind="$attrs"
:items="wifiDevices" :items="wifiDevices"
:headers="headers" :headers="headers"
:search="filter" :search="filter"
:hide-default-footer="!paginate" :hide-default-footer="!paginate"
:disable-pagination="!paginate" :disable-pagination="!paginate"
no-data-text="Nenhum cliente conectado à este AP" no-data-text="Nenhum cliente conectado à este AP"
calculate-widths
:loading="loading"
@update:sort-by="$emit('update:sort-by', $event)"
@update:sort-desc="$emit('update:sort-desc', $event)"
> >
<template #[`item.user`]="{ item: { user } }"> <template #[`item.user`]="{ item: { user } }">
<div v-if="user" class="d-flex"> <div v-if="user" class="d-flex">
@ -38,7 +42,7 @@
</template> </template>
<template #[`item.uptime`]="{ item: { uptime } }"> <template #[`item.uptime`]="{ item: { uptime } }">
<small class="text-no-wrap"> {{ uptime | durationFromSeconds }}</small> <small> {{ uptime | durationFromSeconds }}</small>
</template> </template>
<template #[`item.signalStrength`]="{ item: { signalStrength } }"> <template #[`item.signalStrength`]="{ item: { signalStrength } }">
@ -50,7 +54,7 @@
</template> </template>
<template #[`item.usage`]="{ item: { usage } }"> <template #[`item.usage`]="{ item: { usage } }">
<span class="text-no-wrap"> {{ usage | bytes }}</span> <span> {{ usage | bytes }}</span>
</template> </template>
<template #[`item.protocol`]="{ item: { protocol } }"> <template #[`item.protocol`]="{ item: { protocol } }">
@ -69,7 +73,7 @@
params: { id: item.accessPoint.id } params: { id: item.accessPoint.id }
}" }"
> >
<small class="text-no-wrap"> <small>
{{ item.accessPoint.name || item.accessPoint.hostname }} {{ item.accessPoint.name || item.accessPoint.hostname }}
</small> </small>
</router-link> </router-link>
@ -99,29 +103,30 @@ export default {
paginate: { paginate: {
type: Boolean, type: Boolean,
default: false default: false
},
loading: {
type: Boolean,
default: false
} }
}, },
data: () => ({ data: () => ({
availableHeaders: [ headers: [
{ text: 'Hostname', value: 'hostname' }, { text: 'Hostname', value: 'hostname' },
{ text: 'MAC', value: 'mac' }, { text: 'MAC', value: 'mac' },
{ text: 'IP', value: 'ip' }, { text: 'IP', value: 'ip' },
{ text: 'ESSID', value: 'essid' }, { text: 'ESSID', value: 'essid' },
{ text: 'Uptime', value: 'uptime' }, { text: 'Uptime', value: 'uptime' },
{ text: 'Usuário', value: 'user' }, { text: 'Usuário', value: 'user', sortable: false },
{ text: 'Sinal', value: 'signalStrength' }, { text: 'Sinal', value: 'signalStrength' },
{ text: 'Frequência', value: 'frequency', align: 'end' }, { text: 'Frequência', value: 'frequency', align: 'end' },
{ text: 'Protocolo', value: 'protocol' }, { text: 'Protocolo', value: 'protocol' },
{ text: 'Velocidade', value: 'speed', align: 'end' }, { text: 'Velocidade', value: 'speed', align: 'end' },
{ text: 'Uso', value: 'usage', align: 'end' }, { text: 'Uso', value: 'usage', align: 'end' },
{ text: 'Access Point', value: 'apName' } { text: 'Access Point', value: 'apName' }
] ],
sortBy: 'hostname',
sortDesc: false
}), }),
computed: {
headers() {
return this.availableHeaders
}
},
methods: { methods: {
setClipboard(text) { setClipboard(text) {
navigator.clipboard.writeText(text) navigator.clipboard.writeText(text)

View File

@ -7,8 +7,9 @@
prepend-icon="mdi-devices" prepend-icon="mdi-devices"
clearable clearable
hide-details hide-details
:loading="$apollo.queries.wifiDevices.loading" :loading="$apollo.queries.wifiDevices.loading && !!search"
/> />
<v-spacer /> <v-spacer />
<v-select <v-select
@ -58,9 +59,12 @@
no total. no total.
</div> </div>
<v-progress-linear :indeterminate="$apollo.queries.wifiDevices.loading" /> <WifiDevicesDataTable
:wifi-devices="computedWifiDevices"
<WifiDevicesDataTable :wifi-devices="computedWifiDevices" /> :loading="$apollo.queries.wifiDevices.loading"
:sort-by.sync="sortBy"
:sort-desc.sync="sortDesc"
/>
<v-pagination <v-pagination
v-model="page" v-model="page"
@ -81,7 +85,9 @@ export default {
data: () => ({ data: () => ({
search: '', search: '',
page: 1, page: 1,
itemsPerPage: 10 itemsPerPage: 10,
sortBy: 'signalStrength',
sortDesc: false
}), }),
computed: { computed: {
computedWifiDevices() { computedWifiDevices() {
@ -118,8 +124,20 @@ export default {
fetchPolicy: 'cache-and-network', fetchPolicy: 'cache-and-network',
pollInterval: 10000, pollInterval: 10000,
query: gql` query: gql`
query wifiDevices($search: String, $skip: Int, $take: Int) { query wifiDevices(
wifiDevices(search: $search, skip: $skip, take: $take) { $search: String
$skip: Int
$take: Int
$sortBy: WifiDevicesResultSortBy
$sortDesc: Boolean
) {
wifiDevices(
search: $search
skip: $skip
take: $take
sortBy: $sortBy
sortDesc: $sortDesc
) {
total total
data { data {
accessPoint { accessPoint {
@ -153,7 +171,9 @@ export default {
return { return {
search: this.search, search: this.search,
skip: this.page * this.itemsPerPage - this.itemsPerPage, skip: this.page * this.itemsPerPage - this.itemsPerPage,
take: this.itemsPerPage take: this.itemsPerPage,
sortBy: this.sortBy,
sortDesc: this.sortDesc
} }
} }
}, },

View File

@ -7,8 +7,9 @@
prepend-icon="mdi-devices" prepend-icon="mdi-devices"
clearable clearable
hide-details hide-details
:loading="$apollo.queries.wifiUsers.loading" :loading="$apollo.queries.wifiUsers.loading && !!search"
/> />
<v-spacer /> <v-spacer />
<v-select <v-select
@ -97,7 +98,7 @@
}} }}
</small> </small>
</template> </template>
<avatar left size="28" :src="user.thumbnailPhoto" /> <Avatar left size="32" :src="user.thumbnailPhoto" />
</v-badge> </v-badge>
</v-badge> </v-badge>
{{ user.displayName }} ({{ user.sAMAccountName }}) {{ user.displayName }} ({{ user.sAMAccountName }})