From e4ff3a87a77f79d60ce50b167e3675aaf8e5f8bf Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 9 Feb 2022 13:59:07 +0000 Subject: [PATCH] 2.5.43: download wifi scan button added to wifi scan modal --- package-lock.json | 4 +- package.json | 2 +- public/locales/de/translation.json | 2 +- public/locales/en/translation.json | 2 +- public/locales/es/translation.json | 2 +- public/locales/fr/translation.json | 2 +- public/locales/pt/translation.json | 2 +- src/components/WifiScanModal/index.js | 94 ++++++++++++++++----- src/components/WifiScanResultModal/index.js | 2 - 9 files changed, 83 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index a99a9dc..ca8a276 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ucentral-client", - "version": "2.5.42", + "version": "2.5.43", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "ucentral-client", - "version": "2.5.42", + "version": "2.5.43", "dependencies": { "@coreui/coreui": "^3.4.0", "@coreui/icons": "^2.0.1", diff --git a/package.json b/package.json index b50a619..a7d98d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucentral-client", - "version": "2.5.42", + "version": "2.5.43", "dependencies": { "@coreui/coreui": "^3.4.0", "@coreui/icons": "^2.0.1", diff --git a/public/locales/de/translation.json b/public/locales/de/translation.json index f8fc5a6..fd970b0 100644 --- a/public/locales/de/translation.json +++ b/public/locales/de/translation.json @@ -596,7 +596,7 @@ "channel": "Kanal", "directions": "Starten Sie einen WiFi-Scan dieses Geräts, der ungefähr 25 Sekunden dauern sollte.", "re_scan": "Erneut scannen", - "result_directions": "Bitte klicken Sie auf die Schaltfläche '$t(scan.re_scan)', wenn Sie einen Scan mit derselben Konfiguration wie beim letzten Scan durchführen möchten.", + "result_directions": "Sie können oben rechts auf die Schaltfläche „Scannen“ klicken, um $t(scan.re_scan)", "results": "Ergebnisse des WiFi-Scans", "scan": "Scan", "scanning": "Scannen... ", diff --git a/public/locales/en/translation.json b/public/locales/en/translation.json index 005b353..b747566 100644 --- a/public/locales/en/translation.json +++ b/public/locales/en/translation.json @@ -596,7 +596,7 @@ "channel": "Channel", "directions": "Launch a wifi scan of this device, which should take approximately 25 seconds.", "re_scan": "Re-Scan", - "result_directions": "Please click the '$t(scan.re_scan)' button if you would like to do a scan with the same configuration as the last.", + "result_directions": "You can click the 'Scan' button at the top right to $t(scan.re_scan)", "results": "Wi-Fi Scan Results", "scan": "Scan", "scanning": "Scanning... ", diff --git a/public/locales/es/translation.json b/public/locales/es/translation.json index b6964e5..4675e6a 100644 --- a/public/locales/es/translation.json +++ b/public/locales/es/translation.json @@ -596,7 +596,7 @@ "channel": "Canal", "directions": "Ejecute un escaneo wifi de este dispositivo, que debería tomar aproximadamente 25 segundos.", "re_scan": "Vuelva a escanear", - "result_directions": "Haga clic en el botón '$ t (scan.re_scan)' si desea realizar un escaneo con la misma configuración que el anterior.", + "result_directions": "Puede hacer clic en el botón 'Escanear' en la parte superior derecha para $t(scan.re_scan)", "results": "Resultados de escaneo Wi-Fi", "scan": "Escanear", "scanning": "Exploración... ", diff --git a/public/locales/fr/translation.json b/public/locales/fr/translation.json index 2a1643a..13682f7 100644 --- a/public/locales/fr/translation.json +++ b/public/locales/fr/translation.json @@ -596,7 +596,7 @@ "channel": "Canal", "directions": "Lancez une analyse wifi de cet appareil, ce qui devrait prendre environ 25 secondes.", "re_scan": "Nouvelle analyse", - "result_directions": "Veuillez cliquer sur le bouton '$t(scan.re_scan)' si vous souhaitez effectuer un scan avec la même configuration que le précédent.", + "result_directions": "Vous pouvez cliquer sur le bouton 'Scan' en haut à droite pour $t(scan.re_scan)", "results": "Résultats de l'analyse Wi-Fi", "scan": "Balayage", "scanning": "Balayage... ", diff --git a/public/locales/pt/translation.json b/public/locales/pt/translation.json index e84e905..2a5b000 100644 --- a/public/locales/pt/translation.json +++ b/public/locales/pt/translation.json @@ -596,7 +596,7 @@ "channel": "Canal", "directions": "Inicie uma verificação de wi-fi deste dispositivo, o que deve levar aproximadamente 25 segundos.", "re_scan": "Verificar novamente", - "result_directions": "Clique no botão '$ t (scan.re_scan)' se desejar fazer uma varredura com a mesma configuração da anterior.", + "result_directions": "Você pode clicar no botão 'Scan' no canto superior direito para $t(scan.re_scan)", "results": "Resultados da verificação de Wi-Fi", "scan": "Varredura", "scanning": "Scanning... ", diff --git a/src/components/WifiScanModal/index.js b/src/components/WifiScanModal/index.js index a992b2f..d684354 100644 --- a/src/components/WifiScanModal/index.js +++ b/src/components/WifiScanModal/index.js @@ -5,7 +5,6 @@ import { CModalHeader, CModalTitle, CModalBody, - CModalFooter, CRow, CForm, CSwitch, @@ -14,15 +13,17 @@ import { CPopover, } from '@coreui/react'; import CIcon from '@coreui/icons-react'; -import { cilX } from '@coreui/icons'; -import React, { useState, useEffect } from 'react'; +import { cilCloudDownload, cilMagnifyingGlass, cilX } from '@coreui/icons'; +import React, { useCallback, useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import PropTypes from 'prop-types'; import axiosInstance from 'utils/axiosInstance'; import eventBus from 'utils/eventBus'; -import { LoadingButton, useAuth, useDevice } from 'ucentral-libs'; +import { prettyDateForFile } from 'utils/helper'; +import { useAuth, useDevice } from 'ucentral-libs'; import WifiChannelTable from 'components/WifiScanResultModal/WifiChannelTable'; import 'react-widgets/styles.css'; +import { CSVLink } from 'react-csv'; const WifiScanModal = ({ show, toggleModal }) => { const { t } = useTranslation(); @@ -36,6 +37,7 @@ const WifiScanModal = ({ show, toggleModal }) => { const [activeScan, setActiveScan] = useState(false); const [hideOptions, setHideOptions] = useState(false); const [channelList, setChannelList] = useState([]); + const [csvData, setCsvData] = useState(null); const toggleDfs = () => { setDfs(!dfs); @@ -50,6 +52,7 @@ const WifiScanModal = ({ show, toggleModal }) => { setHadFailure(false); setWaiting(false); setChannelList([]); + setCsvData(null); setDfs(true); setActiveScan(false); setHideOptions(false); @@ -76,7 +79,10 @@ const WifiScanModal = ({ show, toggleModal }) => { scanList.forEach((device) => { if (device.channel === channelNumber) { const deviceToAdd = {}; - deviceToAdd.SSID = device.ssid ?? 'N/A'; + if (device.ssid && device.ssid.length > 0) deviceToAdd.SSID = device.ssid; + else { + deviceToAdd.SSID = device.meshid && device.meshid.length > 0 ? device.meshid : 'N/A'; + } deviceToAdd.Signal = (dbmNumber - device.signal) * -1; channel.devices.push(deviceToAdd); } @@ -87,6 +93,40 @@ const WifiScanModal = ({ show, toggleModal }) => { return finalList; }; + const getData = useCallback((scanResults) => { + if (scanResults === null || scanResults.length === 0) return []; + const dbmNumber = 4294967295; + const listOfChannels = []; + const listCsv = []; + + scanResults.forEach((scan) => { + if (!listOfChannels.includes(scan.channel)) { + listOfChannels.push(scan.channel); + } + }); + + listOfChannels.forEach((channelNumber) => { + const channel = { + channel: channelNumber, + devices: [], + }; + + scanResults.forEach((device) => { + if (device.channel === channelNumber) { + const deviceToAdd = {}; + if (device.ssid && device.ssid.length > 0) deviceToAdd.SSID = device.ssid; + else { + deviceToAdd.SSID = device.meshid && device.meshid.length > 0 ? device.meshid : 'N/A'; + } + deviceToAdd.Signal = (dbmNumber - device.signal) * -1; + channel.devices.push(deviceToAdd); + listCsv.push({ ...deviceToAdd, ...device }); + } + }); + }); + return listCsv; + }, []); + const doAction = () => { setHadFailure(false); setHadSuccess(false); @@ -113,6 +153,7 @@ const WifiScanModal = ({ show, toggleModal }) => { if (scanList) { setChannelList(parseThroughList(scanList)); + setCsvData(getData(scanList)); setErrorCode(response.data.errorCode ?? 0); setHideOptions(true); setHadSuccess(true); @@ -134,6 +175,35 @@ const WifiScanModal = ({ show, toggleModal }) => { {t('actions.wifi_scan')}
+ {csvData !== null ? ( + + + + + + + + ) : ( + + + + )} + + + + + @@ -205,20 +275,6 @@ const WifiScanModal = ({ show, toggleModal }) => {
- - - - {!hadSuccess && !hadFailure ? t('common.cancel') : t('common.exit')} - - ); }; diff --git a/src/components/WifiScanResultModal/index.js b/src/components/WifiScanResultModal/index.js index c5d0bce..d508d0c 100644 --- a/src/components/WifiScanResultModal/index.js +++ b/src/components/WifiScanResultModal/index.js @@ -51,7 +51,6 @@ const WifiScanResultModal = ({ show, toggle, scanResults, date }) => { const parseThroughList = useCallback(() => { const dbmNumber = 4294967295; const listOfChannels = []; - const listCsv = []; scanResults.forEach((scan) => { if (!listOfChannels.includes(scan.channel)) { @@ -75,7 +74,6 @@ const WifiScanResultModal = ({ show, toggle, scanResults, date }) => { } deviceToAdd.Signal = (dbmNumber - device.signal) * -1; channel.devices.push(deviceToAdd); - listCsv.push({ ...device, ...deviceToAdd }); } });