Skip to content

Commit

Permalink
Prettified Code!
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ2LS authored and actions-user committed Aug 2, 2024
1 parent c883f93 commit 169e637
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 102 deletions.
5 changes: 5 additions & 0 deletions freedata_gui/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
# freedata_gui

## Project setup

```
npm install
```

### Compiles and hot-reloads for development

```
npm run serve
```

### Compiles and minifies for production

```
npm run build
```

### Lints and fixes files

```
npm run lint
```

### Customize configuration

See [Configuration Reference](https://cli.vuejs.org/config/).
6 changes: 2 additions & 4 deletions freedata_gui/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}
presets: ["@vue/cli-plugin-babel/preset"],
};
47 changes: 33 additions & 14 deletions freedata_gui/public/index.html
Original file line number Diff line number Diff line change
@@ -1,31 +1,50 @@
<!DOCTYPE html>
<!doctype html>
<html lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0, viewport-fit=cover">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width,initial-scale=1.0, viewport-fit=cover"
/>
<link rel="icon" href="<%= BASE_URL %>favicon.ico" />
<title><%= htmlWebpackPlugin.options.title %></title>

<!-- Favicon for browsers -->
<link rel="icon" type="image/png" sizes="32x32" href="<%= BASE_URL %>favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="<%= BASE_URL %>favicon-16x16.png">
<link
rel="icon"
type="image/png"
sizes="32x32"
href="<%= BASE_URL %>favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="<%= BASE_URL %>favicon-16x16.png"
/>

<!-- Apple touch icon -->
<link rel="apple-touch-icon" href="<%= BASE_URL %>apple-touch-icon.png">
<link rel="apple-touch-icon" href="<%= BASE_URL %>apple-touch-icon.png" />

<!-- Android icons -->
<link rel="manifest" href="<%= BASE_URL %>manifest.json">
<link rel="manifest" href="<%= BASE_URL %>manifest.json" />

<!-- prevent status bar from showing on iOS -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
</head>

<meta name="apple-mobile-web-app-capable" content="yes" />
<meta
name="apple-mobile-web-app-status-bar-style"
content="black-translucent"
/>
</head>

<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
<strong
>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work
properly without JavaScript enabled. Please enable it to
continue.</strong
>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
Expand Down
12 changes: 6 additions & 6 deletions freedata_gui/src/js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import { processFreedataMessages } from "./messagesHandler";
import { useStateStore } from "../store/stateStore.js";
const state = useStateStore(pinia);



// Build URL with adjusted port if needed
function buildURL(endpoint) {
const { protocol, hostname, port } = window.location;
const adjustedPort = port === '8080' ? '5000' : port;
const adjustedPort = port === "8080" ? "5000" : port;
return `${protocol}//${hostname}:${adjustedPort}${endpoint}`;
}

// Check network connectivity
const isNetworkConnected = computed(() => state.modem_connection !== "disconnected");
const isNetworkConnected = computed(
() => state.modem_connection !== "disconnected",
);
function checkNetworkConnectivity() {
if (!isNetworkConnected.value) {
console.warn("Network is disconnected. API call aborted.");
Expand Down Expand Up @@ -145,7 +145,7 @@ export async function getSysInfo() {
implementation: data?.python_info?.implementation || "N/A",
revision: data?.python_info?.revision || "N/A",
version: data?.python_info?.version || "N/A",
}
},
};
}

Expand Down Expand Up @@ -275,4 +275,4 @@ export async function getStationInfo(callsign) {

export async function setStationInfo(callsign, info) {
return await apiPost(`/freedata/station/${callsign}`, info);
}
}
29 changes: 12 additions & 17 deletions freedata_gui/src/js/eventHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { toRaw } from "vue";
import { displayToast } from "./popupHandler";
import {
Expand All @@ -10,8 +9,6 @@ import {
import { processFreedataMessages } from "./messagesHandler";
import { processRadioStatus } from "./radioHandler";



// ----------------- init pinia stores -------------
import { setActivePinia } from "pinia";
import pinia from "../store/index";
Expand All @@ -22,9 +19,7 @@ import { useAudioStore } from "../store/audioStore";
const audioStore = useAudioStore(pinia);
import { useSerialStore } from "../store/serialStore";
const serialStore = useSerialStore(pinia);
import {
getRemote,
} from "../store/settingsStore";
import { getRemote } from "../store/settingsStore";

export async function loadAllData() {
let stateData = await getModemState();
Expand All @@ -39,7 +34,7 @@ export async function loadAllData() {
});
audioStore.loadAudioDevices();
serialStore.loadSerialDevices();
console.log(audioStore.audioInputs)
console.log(audioStore.audioInputs);
await getRadioStatus();
getRemote();
getOverallHealth();
Expand All @@ -49,7 +44,7 @@ export async function loadAllData() {
}

export function connectionFailed(endpoint, event) {
console.log(event)
console.log(event);
stateStore.modem_connection = "disconnected";
}

Expand All @@ -64,7 +59,7 @@ export function stateDispatcher(data) {
stateStore.is_modem_running = data.is_modem_running;
stateStore.dbfs_level = Math.round(data.audio_dbfs);
stateStore.dbfs_level_percent = Math.round(
Math.pow(10, data.audio_dbfs / 20) * 100
Math.pow(10, data.audio_dbfs / 20) * 100,
);
stateStore.radio_status = data.radio_status;
stateStore.channel_busy_slot = data.channel_busy_slot;
Expand All @@ -78,7 +73,7 @@ export function stateDispatcher(data) {
if (data.type === "radio-change" || data.type === "radio") {
stateStore.s_meter_strength_raw = Math.round(data.s_meter_strength);
stateStore.s_meter_strength_percent = Math.round(
Math.pow(10, data.s_meter_strength / 20) * 100
Math.pow(10, data.s_meter_strength / 20) * 100,
);
stateStore.radio_status = data.radio_status;
stateStore.frequency = data.radio_frequency;
Expand Down Expand Up @@ -141,7 +136,7 @@ export function eventDispatcher(data) {
"danger",
"bi-bootstrap-reboot",
"Modem startup failed | bad config?",
5000
5000,
);
return;
}
Expand Down Expand Up @@ -186,13 +181,13 @@ export function eventDispatcher(data) {
stateStore.arq_total_bytes =
data["arq-transfer-outbound"].received_bytes;
stateStore.arq_speed_list_timestamp.value = toRaw(
data["arq-transfer-outbound"].statistics.time_histogram
data["arq-transfer-outbound"].statistics.time_histogram,
);
stateStore.arq_speed_list_bpm.value = toRaw(
data["arq-transfer-outbound"].statistics.bpm_histogram
data["arq-transfer-outbound"].statistics.bpm_histogram,
);
stateStore.arq_speed_list_snr.value = toRaw(
data["arq-transfer-outbound"].statistics.snr_histogram
data["arq-transfer-outbound"].statistics.snr_histogram,
);
stateStore.speed_level = data["arq-transfer-outbound"].speed_level;
return;
Expand Down Expand Up @@ -256,13 +251,13 @@ export function eventDispatcher(data) {
stateStore.arq_total_bytes =
data["arq-transfer-inbound"].received_bytes;
stateStore.arq_speed_list_timestamp.value = toRaw(
data["arq-transfer-inbound"].statistics.time_histogram
data["arq-transfer-inbound"].statistics.time_histogram,
);
stateStore.arq_speed_list_bpm.value = toRaw(
data["arq-transfer-inbound"].statistics.bpm_histogram
data["arq-transfer-inbound"].statistics.bpm_histogram,
);
stateStore.arq_speed_list_snr.value = toRaw(
data["arq-transfer-inbound"].statistics.snr_histogram
data["arq-transfer-inbound"].statistics.snr_histogram,
);
stateStore.speed_level = data["arq-transfer-inbound"].speed_level;
return;
Expand Down
6 changes: 3 additions & 3 deletions freedata_gui/src/js/event_sock.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ const state = useStateStore(pinia);
function connect(endpoint, dispatcher) {
const { protocol, hostname, port } = window.location;
const wsProtocol = protocol === "https:" ? "wss:" : "ws:";
const adjustedPort = port === '8080' ? '5000' : port;
const adjustedPort = port === "8080" ? "5000" : port;
const socket = new WebSocket(
`${wsProtocol}//${hostname}:${adjustedPort}/${endpoint}`
`${wsProtocol}//${hostname}:${adjustedPort}/${endpoint}`,
);

// handle opening
socket.addEventListener("open", function () {
console.log(`Connected to the WebSocket server: ${endpoint}`);
// when connected again, initially load all data from server
loadAllData();
state.modem_connection = 'connected';
state.modem_connection = "connected";
});

// handle data
Expand Down
10 changes: 6 additions & 4 deletions freedata_gui/src/js/freedata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Binary to ASCII replacement
* @param {string} data in normal/usual utf-8 format
Expand Down Expand Up @@ -64,7 +63,9 @@ export function sortByPropertyDesc(property) {
export function validateCallsignWithSSID(callsign) {
const patt = new RegExp("^[A-Za-z0-9]{1,7}-[0-9]{1,3}$");
if (!callsign || !patt.test(callsign)) {
console.error(`Call sign given is not in correct format or missing; callsign passed is: ${callsign}`);
console.error(
`Call sign given is not in correct format or missing; callsign passed is: ${callsign}`,
);
return false;
}
return true;
Expand All @@ -78,13 +79,14 @@ export function validateCallsignWithSSID(callsign) {
export function validateCallsignWithoutSSID(callsign) {
const patt = new RegExp("^[A-Za-z0-9]{1,7}$");
if (!callsign || !patt.test(callsign)) {
console.error(`Call sign given is not in correct format or missing; callsign passed is: ${callsign}`);
console.error(
`Call sign given is not in correct format or missing; callsign passed is: ${callsign}`,
);
return false;
}
return true;
}


/**
* Get application data path based on the environment.
* In a browser environment, this function now returns a fixed path or directory name.
Expand Down
5 changes: 1 addition & 4 deletions freedata_gui/src/js/messagesHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import {
* @param {Object} data - The data object containing messages.
*/
export async function processFreedataMessages(data) {
if (
data &&
Array.isArray(data.messages)
) {
if (data && Array.isArray(data.messages)) {
chatStore.callsign_list = createCallsignListFromAPI(data);
chatStore.sorted_chat_list = createSortedMessagesList(data);

Expand Down
22 changes: 14 additions & 8 deletions freedata_gui/src/js/popupHandler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { v4 as uuidv4 } from 'uuid';
import * as bootstrap from 'bootstrap';
import { v4 as uuidv4 } from "uuid";
import * as bootstrap from "bootstrap";

export function displayToast(type, icon, content, duration) {
const mainToastContainer = document.getElementById('mainToastContainer');
const mainToastContainer = document.getElementById("mainToastContainer");

const randomID = uuidv4();
const toastCode = `
Expand All @@ -24,7 +24,7 @@ export function displayToast(type, icon, content, duration) {
`;

// Insert toast to toast container
mainToastContainer.insertAdjacentHTML('beforeend', toastCode);
mainToastContainer.insertAdjacentHTML("beforeend", toastCode);

// Register toast
const toastHTMLElement = document.getElementById(randomID);
Expand All @@ -35,8 +35,14 @@ export function displayToast(type, icon, content, duration) {
toast.show();

// Register event listener to remove toast when hidden
toastHTMLElement.addEventListener('hidden.bs.toast', function handleToastHidden() {
toastHTMLElement.removeEventListener('hidden.bs.toast', handleToastHidden);
toastHTMLElement.remove();
});
toastHTMLElement.addEventListener(
"hidden.bs.toast",
function handleToastHidden() {
toastHTMLElement.removeEventListener(
"hidden.bs.toast",
handleToastHidden,
);
toastHTMLElement.remove();
},
);
}
10 changes: 5 additions & 5 deletions freedata_gui/src/js/radioHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ export async function processRadioStatus() {
try {
let result = await getRadioStatus();

if (!result || typeof result !== 'object') {
throw new Error('Invalid radio status');
if (!result || typeof result !== "object") {
throw new Error("Invalid radio status");
}

stateStore.mode = result.radio_mode;
stateStore.frequency = result.radio_frequency;
stateStore.rf_level = Math.round(result.radio_rf_level / 5) * 5; // round to 5er steps
stateStore.tuner = result.radio_tuner;
} catch (error) {
console.error('Error fetching radio status:', error);
console.error("Error fetching radio status:", error);
// Handle the error appropriately
// For example, you can set default values or update the UI to indicate an error
stateStore.mode = 'unknown';
stateStore.mode = "unknown";
stateStore.frequency = 0;
stateStore.rf_level = 0;
stateStore.tuner = 'unknown';
stateStore.tuner = "unknown";
}
}
4 changes: 1 addition & 3 deletions freedata_gui/src/js/settingsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ setActivePinia(pinia);

import { settingsStore as settings } from "../store/settingsStore.js";



/*
// create config file if not exists with defaults
const configDefaultSettings = `{
Expand Down Expand Up @@ -97,4 +95,4 @@ export function processModemConfig(data) {
}
}
}
}
}
Loading

0 comments on commit 169e637

Please sign in to comment.