diff --git a/server/src/lib/wifiDevices.js b/server/src/lib/wifiDevices.js index f6ef6ca..058db3a 100644 --- a/server/src/lib/wifiDevices.js +++ b/server/src/lib/wifiDevices.js @@ -7,7 +7,7 @@ import prisma from '../prisma' import { pubsub, USER_PRESENCE_UPDATED } from '../pubsub' const DEBOUNCE_TIME_MS = 10000 -const RECENT_THRESHOLD_IN_MINUTES = 5 +const RECENT_THRESHOLD_IN_MINUTES = 3 let working = false diff --git a/server/src/resolvers/Query.js b/server/src/resolvers/Query.js index bede4f3..574b081 100755 --- a/server/src/resolvers/Query.js +++ b/server/src/resolvers/Query.js @@ -116,31 +116,33 @@ const Query = { search = search.toLowerCase().trim() - const userPresences = usersWithWifiDevices - .filter( - user => - user.displayName.toLowerCase().includes(search) || - user.sAMAccountName.toLowerCase().includes(search) || - user.wifiDevices.some( - device => - device.apName.toLowerCase().includes(search) || - device.ip.startsWith(search) - ) - ) - .map(user => ({ - user: { - id: user.id, - displayName: user.displayName, - thumbnailPhoto: user.thumbnailPhoto - }, - wifiDevices: user.wifiDevices - })) + const filteredUsers = search + ? usersWithWifiDevices.filter( + user => + user.displayName.toLowerCase().includes(search) || + user.sAMAccountName.toLowerCase().includes(search) || + user.wifiDevices.some( + device => + device.apName.toLowerCase().includes(search) || + device.ip.startsWith(search) + ) + ) + : usersWithWifiDevices - const sortedUserPresences = userPresences.sort((a, b) => + const sortedUsers = filteredUsers.sort((a, b) => a.wifiDevices[0].lastSeen > b.wifiDevices[0].lastSeen ? -1 : 1 ) - return sortedUserPresences.slice(0, 200) + return sortedUsers + .map(userPresence => ({ + id: userPresence.id, + displayName: userPresence.displayName, + thumbnailPhoto: userPresence.thumbnailPhoto, + lastSeen: userPresence.wifiDevices[0].lastSeen, + status: userPresence.wifiDevices[0].status, + apName: userPresence.wifiDevices[0].apName + })) + .slice(0, 200) } } diff --git a/server/src/resolvers/UserPresence.js b/server/src/resolvers/UserPresence.js new file mode 100644 index 0000000..2ada692 --- /dev/null +++ b/server/src/resolvers/UserPresence.js @@ -0,0 +1,6 @@ +const UserPresence = { + displayName: _ => (_.displayName ? _.displayName.capitalize() : ''), + lastSeen: _ => _.lastSeen?.toISOString() +} + +export { UserPresence } diff --git a/server/src/resolvers/WifiDevice.js b/server/src/resolvers/WifiDevice.js index a1da188..f670d92 100644 --- a/server/src/resolvers/WifiDevice.js +++ b/server/src/resolvers/WifiDevice.js @@ -1,9 +1,6 @@ const WifiDevice = { lastSeen: _ => _.lastSeen?.toISOString(), - firstSeen: _ => _.firstSeen?.toISOString(), - isOnline: _ => _.status == 'ONLINE', - isRecent: _ => _.status == 'RECENT', - isOffline: _ => _.status == 'OFFLINE' + firstSeen: _ => _.firstSeen?.toISOString() } export { WifiDevice } diff --git a/server/src/resolvers/index.js b/server/src/resolvers/index.js index 051dff9..e84437f 100755 --- a/server/src/resolvers/index.js +++ b/server/src/resolvers/index.js @@ -3,6 +3,7 @@ import { Mutation } from './Mutation' import { Subscription } from './Subscriptions' import { User } from './User' +import { UserPresence } from './UserPresence' import { Group } from './Group' import { ResetToken } from './ResetToken' import { WifiDevice } from './WifiDevice' @@ -13,6 +14,7 @@ const resolvers = { Mutation, Subscription, User, + UserPresence, Group, ResetToken, WifiDevice, diff --git a/server/src/typeDefs.js b/server/src/typeDefs.js index 3a42f61..c1f7521 100644 --- a/server/src/typeDefs.js +++ b/server/src/typeDefs.js @@ -167,14 +167,15 @@ const typeDefs = gql` uptime: String apName: String status: Status - isOnline: Boolean - isRecent: Boolean - isOffline: Boolean } type UserPresence { - user: User! - wifiDevices: [WifiDevice!]! + id: ID! + displayName: String! + thumbnailPhoto: String + lastSeen: String! + status: Status! + apName: String! } enum Status { diff --git a/web/src/components/UserPresenceStatusList.vue b/web/src/components/UserPresenceStatusList.vue deleted file mode 100644 index 93e8013..0000000 --- a/web/src/components/UserPresenceStatusList.vue +++ /dev/null @@ -1,139 +0,0 @@ - - - - - diff --git a/web/src/components/WifiDevice.vue b/web/src/components/WifiDevice.vue index d167299..cc62278 100644 --- a/web/src/components/WifiDevice.vue +++ b/web/src/components/WifiDevice.vue @@ -3,7 +3,9 @@ mdi-cellphone-link @@ -13,7 +15,7 @@ - + mdi-wifi diff --git a/web/src/components/widgets/DevicesWidget.vue b/web/src/components/widgets/DevicesWidget.vue index 1fd1212..f74eda3 100755 --- a/web/src/components/widgets/DevicesWidget.vue +++ b/web/src/components/widgets/DevicesWidget.vue @@ -42,8 +42,8 @@ export default { lastSeen mac oui - isOnline uptime + status } } } diff --git a/web/src/views/UserPresence.vue b/web/src/views/UserPresence.vue index f7fe9f2..10af053 100644 --- a/web/src/views/UserPresence.vue +++ b/web/src/views/UserPresence.vue @@ -51,12 +51,113 @@ - + name="scale-transition" + tag="div" + class="layout row row--dense wrap" + mode="out-in" + > + + + + + + + + + + + + + {{ userPresence.displayName }} + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + +
+
+ import gql from 'graphql-tag' -import UserPresenceStatusList from '../components/UserPresenceStatusList' +import Avatar from '../components/Avatar' export default { name: 'UserPresence', - components: { UserPresenceStatusList }, + components: { Avatar }, data: () => { const pageSize = 12 return { @@ -143,20 +244,12 @@ export default { query: gql` query($search: String = "") { userPresence(search: $search) { - user { - id - displayName - thumbnailPhoto - } - wifiDevices { - apName - id - lastSeen - isOnline - isRecent - isOffline - controller - } + id + displayName + thumbnailPhoto + lastSeen + status + apName } } `, @@ -194,8 +287,27 @@ export default { pagedUserPresences() { return this.userPresence?.slice(0, this.resultSize) || [] } + }, + methods: { + color(status) { + return { + ONLINE: 'green darken-2', + RECENT: 'orange darken-1', + OFFLINE: 'grey darken-1' + }[status] + } } } - + diff --git a/web/src/views/WifiDevices.vue b/web/src/views/WifiDevices.vue index 93a740a..eff688f 100644 --- a/web/src/views/WifiDevices.vue +++ b/web/src/views/WifiDevices.vue @@ -33,7 +33,8 @@
{{ - wifiDevices && wifiDevices.filter(device => device.isOnline).length + wifiDevices && + wifiDevices.filter(device => device.status == 'ONLINE').length }} online de @@ -56,7 +57,7 @@ - + mdi-wifi @@ -234,7 +235,7 @@ export default { ip uptime apName - isOnline + status } } ` diff --git a/web/src/views/WifiUsers.vue b/web/src/views/WifiUsers.vue index 2801e95..d75f491 100644 --- a/web/src/views/WifiUsers.vue +++ b/web/src/views/WifiUsers.vue @@ -60,7 +60,7 @@ offset-y="10" :content=" user.wifiDevices - .filter(wifiDevice => !wifiDevice.isOnline) + .filter(wifiDevice => !wifiDevice.status == 'ONLINE') .length.toString() " > @@ -70,7 +70,7 @@ offset-y="10" :content=" user.wifiDevices - .filter(wifiDevice => wifiDevice.isOnline) + .filter(wifiDevice => wifiDevice.status == 'ONLINE') .length.toString() " > @@ -87,7 +87,10 @@ >
- + mdi-cellphone-wireless {{ device.hostname || device.mac }} {{ device.oui }} @@ -95,7 +98,7 @@ - + mdi-wifi @@ -214,7 +217,7 @@ export default { return this.wifiUsers?.map(user => ({ ...user, ips: user.wifiDevices.reduce((ips, device) => ` ${device.ip}`, ''), - wifiDevices: user.wifiDevices.sort(a => (a.isOnline ? -1 : 1)) + wifiDevices: user.wifiDevices.sort(a => (a.status == 'ONLINE' ? -1 : 1)) })) } }, @@ -234,7 +237,7 @@ export default { hostname firstSeen lastSeen - isOnline + status apName essid ip