Added servant filter
This commit is contained in:
parent
71eb64c5e1
commit
3d7cdbf6dc
|
@ -1,10 +1,10 @@
|
|||
import prisma from '../../prisma'
|
||||
import { getSubnetInfo } from '../../utils/subnetInfo'
|
||||
|
||||
export async function userPresence(_, { search }) {
|
||||
export async function userPresence(_, { search, onlyServants }) {
|
||||
if (!search) search = ''
|
||||
|
||||
const usersWithWifiDevices = await prisma.user.findMany({
|
||||
let usersWithWifiDevices = await prisma.user.findMany({
|
||||
where: {
|
||||
wifiDevices: { some: { lastSeen: { not: null } } }
|
||||
},
|
||||
|
@ -16,6 +16,11 @@ export async function userPresence(_, { search }) {
|
|||
}
|
||||
})
|
||||
|
||||
if (onlyServants)
|
||||
usersWithWifiDevices = usersWithWifiDevices.filter(
|
||||
({ extensionAttribute2 }) => extensionAttribute2 == 'Técnico-administrativo' || extensionAttribute2 == 'Docente'
|
||||
)
|
||||
|
||||
search = search.toLowerCase().trim()
|
||||
|
||||
const filteredUsers = search
|
||||
|
@ -60,7 +65,7 @@ export async function userPresence(_, { search }) {
|
|||
return 0
|
||||
})
|
||||
|
||||
return sortedUsers
|
||||
const userPresence = sortedUsers
|
||||
.map(userPresence => ({
|
||||
id: userPresence.id,
|
||||
displayName: userPresence.displayName,
|
||||
|
@ -72,4 +77,6 @@ export async function userPresence(_, { search }) {
|
|||
campus: getSubnetInfo(userPresence.wifiDevices[0].accessPoint?.ip).shortName
|
||||
}))
|
||||
.slice(0, 200)
|
||||
|
||||
return userPresence
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ const typeDefs = gql`
|
|||
stats: Stats!
|
||||
|
||||
"Users who has some device currently connected to Wi-Fi"
|
||||
userPresence(search: String = ""): [UserPresence!] @auth(roles: ["watcher"])
|
||||
userPresence(search: String = "", onlyServants: Boolean = false): [UserPresence!] @auth(roles: ["watcher"])
|
||||
|
||||
"Devices that uses the Wi-Fi"
|
||||
wifiDevices(
|
||||
|
|
|
@ -1,57 +1,25 @@
|
|||
<template>
|
||||
<v-container fluid class="mb-12">
|
||||
<v-toolbar class="mb-2" flat outlined max-width="400px">
|
||||
<v-toolbar class="mb-2" flat outlined max-width="600px">
|
||||
<v-text-field
|
||||
v-model="search"
|
||||
class="mr-4"
|
||||
label="Pesquisar"
|
||||
prepend-icon="mdi-account-search"
|
||||
clearable
|
||||
hide-details
|
||||
:loading="$apollo.queries.userPresence.loading"
|
||||
/>
|
||||
<v-dialog v-model="helpDialog" width="500px">
|
||||
<template #activator="{ on, attrs }">
|
||||
<v-btn class="ml-1" color="info" dark v-bind="attrs" icon v-on="on">
|
||||
<v-icon>mdi-help</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
|
||||
<v-card>
|
||||
<v-card-title class="headline primary white--text">
|
||||
Como pesquisar
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
Você pode pesquisar usuários pelo nome, SIAPE, CPF, setor do SUAP,
|
||||
nome do Access Point, função do servidor, endereço IP dentre
|
||||
outros.<br />
|
||||
Exemplos:
|
||||
<ul>
|
||||
<li>
|
||||
<code>jose</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>pp</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>sala 102</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>10.7</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>PP-CEREL</code>
|
||||
</li>
|
||||
</ul>
|
||||
</v-card-text>
|
||||
|
||||
<v-divider></v-divider>
|
||||
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="primary" text @click="helpDialog = false">OK</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
<v-checkbox
|
||||
v-model="onlyServants"
|
||||
class="mt-5 ml-4"
|
||||
hint="Somente servidores"
|
||||
label="Somente servidores"
|
||||
v-bind="attrs"
|
||||
v-on="on"
|
||||
>
|
||||
</v-checkbox>
|
||||
</v-toolbar>
|
||||
|
||||
<div v-if="stats" class="text-center my-4">
|
||||
|
@ -209,6 +177,49 @@
|
|||
Ordenando por <em>"visto por último"</em>
|
||||
</span>
|
||||
<v-spacer />
|
||||
<v-dialog v-model="helpDialog" width="500px">
|
||||
<template #activator="{ on, attrs }">
|
||||
<v-btn color="info" dark icon v-bind="attrs" v-on="on">
|
||||
<v-icon>mdi-help</v-icon>
|
||||
</v-btn>
|
||||
</template>
|
||||
|
||||
<v-card>
|
||||
<v-card-title class="headline primary white--text">
|
||||
Como pesquisar
|
||||
</v-card-title>
|
||||
<v-card-text>
|
||||
Você pode pesquisar usuários pelo nome, SIAPE, CPF, setor do SUAP,
|
||||
nome do Access Point, função do servidor, endereço IP dentre
|
||||
outros.<br />
|
||||
Exemplos:
|
||||
<ul>
|
||||
<li>
|
||||
<code>jose</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>pp</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>sala 102</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>10.7</code>
|
||||
</li>
|
||||
<li>
|
||||
<code>PP-CEREL</code>
|
||||
</li>
|
||||
</ul>
|
||||
</v-card-text>
|
||||
|
||||
<v-divider></v-divider>
|
||||
|
||||
<v-card-actions>
|
||||
<v-spacer></v-spacer>
|
||||
<v-btn color="primary" text @click="helpDialog = false">OK</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
<v-btn
|
||||
:elevation="0"
|
||||
:disabled="
|
||||
|
@ -268,11 +279,13 @@ export default {
|
|||
components: { Avatar },
|
||||
data: () => {
|
||||
const pageSize = 12
|
||||
|
||||
return {
|
||||
pageSize,
|
||||
search: '',
|
||||
resultSize: pageSize,
|
||||
helpDialog: false
|
||||
helpDialog: false,
|
||||
onlyServants: false
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -295,8 +308,8 @@ export default {
|
|||
userPresence: {
|
||||
// fetchPolicy: 'cache-and-network',
|
||||
query: gql`
|
||||
query ($search: String = "") {
|
||||
userPresence(search: $search) {
|
||||
query ($search: String = "", $onlyServants: Boolean = false) {
|
||||
userPresence(search: $search, onlyServants: $onlyServants) {
|
||||
id
|
||||
displayName
|
||||
thumbnailPhoto
|
||||
|
@ -310,7 +323,8 @@ export default {
|
|||
`,
|
||||
variables() {
|
||||
return {
|
||||
search: this.search?.trim()
|
||||
search: this.search?.trim(),
|
||||
onlyServants: this.onlyServants
|
||||
}
|
||||
},
|
||||
debounce: 250
|
||||
|
|
Loading…
Reference in New Issue
Block a user