Refactor: Apply consistent formatting and improve code style across all modules
Signed-off-by: YoungSoo Shin <shinys000114@gmail.com>
This commit is contained in:
@@ -25,8 +25,8 @@ export async function fetchWifiScan() {
|
|||||||
export async function postWifiConnect(ssid, password) {
|
export async function postWifiConnect(ssid, password) {
|
||||||
const response = await fetch('/api/setting', { // Updated URL
|
const response = await fetch('/api/setting', { // Updated URL
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({ ssid, password }),
|
body: JSON.stringify({ssid, password}),
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
@@ -44,7 +44,7 @@ export async function postWifiConnect(ssid, password) {
|
|||||||
export async function postNetworkSettings(payload) {
|
export async function postNetworkSettings(payload) {
|
||||||
const response = await fetch('/api/setting', { // Updated URL
|
const response = await fetch('/api/setting', { // Updated URL
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -63,8 +63,8 @@ export async function postNetworkSettings(payload) {
|
|||||||
export async function postBaudRateSetting(baudrate) {
|
export async function postBaudRateSetting(baudrate) {
|
||||||
const response = await fetch('/api/setting', {
|
const response = await fetch('/api/setting', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: {'Content-Type': 'application/json'},
|
||||||
body: JSON.stringify({ baudrate }),
|
body: JSON.stringify({baudrate}),
|
||||||
});
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorText = await response.text();
|
const errorText = await response.text();
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
* It handles initialization, theme updates, data updates, and resizing for the three separate charts.
|
* It handles initialization, theme updates, data updates, and resizing for the three separate charts.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Chart, registerables } from 'chart.js';
|
import {Chart, registerables} from 'chart.js';
|
||||||
import { powerChartCtx, voltageChartCtx, currentChartCtx, htmlEl, graphTabPane } from './dom.js';
|
import {currentChartCtx, graphTabPane, htmlEl, powerChartCtx, voltageChartCtx} from './dom.js';
|
||||||
|
|
||||||
// Register all necessary Chart.js components
|
// Register all necessary Chart.js components
|
||||||
Chart.register(...registerables);
|
Chart.register(...registerables);
|
||||||
@@ -47,13 +47,13 @@ function createChartOptions(title, minValue, maxValue) {
|
|||||||
return {
|
return {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
maintainAspectRatio: false,
|
maintainAspectRatio: false,
|
||||||
interaction: { mode: 'index', intersect: false },
|
interaction: {mode: 'index', intersect: false},
|
||||||
plugins: {
|
plugins: {
|
||||||
legend: { position: 'top' },
|
legend: {position: 'top'},
|
||||||
title: { display: true, text: title }
|
title: {display: true, text: title}
|
||||||
},
|
},
|
||||||
scales: {
|
scales: {
|
||||||
x: { ticks: { autoSkipPadding: 10, maxRotation: 0, minRotation: 0 } },
|
x: {ticks: {autoSkipPadding: 10, maxRotation: 0, minRotation: 0}},
|
||||||
y: {
|
y: {
|
||||||
min: minValue,
|
min: minValue,
|
||||||
max: maxValue,
|
max: maxValue,
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
import * as dom from './dom.js';
|
import * as dom from './dom.js';
|
||||||
import * as api from './api.js';
|
import * as api from './api.js';
|
||||||
import * as ui from './ui.js';
|
import * as ui from './ui.js';
|
||||||
import { clearTerminal, fitTerminal, downloadTerminalOutput } from './terminal.js';
|
import {clearTerminal, downloadTerminalOutput, fitTerminal} from './terminal.js';
|
||||||
import { debounce, isMobile } from './utils.js';
|
import {debounce, isMobile} from './utils.js';
|
||||||
|
|
||||||
// A flag to track if charts have been initialized
|
// A flag to track if charts have been initialized
|
||||||
let chartsInitialized = false;
|
let chartsInitialized = false;
|
||||||
|
|||||||
@@ -11,17 +11,17 @@ import 'bootstrap-icons/font/bootstrap-icons.css';
|
|||||||
import './style.css';
|
import './style.css';
|
||||||
|
|
||||||
// --- Module Imports ---
|
// --- Module Imports ---
|
||||||
import { initWebSocket } from './websocket.js';
|
import {initWebSocket} from './websocket.js';
|
||||||
import { setupTerminal, term } from './terminal.js';
|
import {setupTerminal, term} from './terminal.js';
|
||||||
import {
|
import {
|
||||||
applyTheme,
|
applyTheme,
|
||||||
initUI,
|
initUI,
|
||||||
updateControlStatus,
|
updateControlStatus,
|
||||||
updateSensorUI,
|
updateSensorUI,
|
||||||
updateWifiStatusUI,
|
updateWebsocketStatus,
|
||||||
updateWebsocketStatus
|
updateWifiStatusUI
|
||||||
} from './ui.js';
|
} from './ui.js';
|
||||||
import { setupEventListeners } from './events.js';
|
import {setupEventListeners} from './events.js';
|
||||||
|
|
||||||
// --- WebSocket Event Handlers ---
|
// --- WebSocket Event Handlers ---
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,16 @@
|
|||||||
:root {
|
:root {
|
||||||
--bs-body-font-family: 'Courier New', Courier, monospace;
|
--bs-body-font-family: 'Courier New', Courier, monospace;
|
||||||
/* Chart Channel Colors */
|
/* Chart Channel Colors */
|
||||||
--chart-usb-color: #0d6efd; /* Bootstrap Blue */
|
--chart-usb-color: #0d6efd; /* Bootstrap Blue */
|
||||||
--chart-main-color: #198754; /* Bootstrap Green */
|
--chart-main-color: #198754; /* Bootstrap Green */
|
||||||
--chart-vin-color: #dc3545; /* Bootstrap Red */
|
--chart-vin-color: #dc3545; /* Bootstrap Red */
|
||||||
}
|
}
|
||||||
|
|
||||||
[data-bs-theme="dark"] {
|
[data-bs-theme="dark"] {
|
||||||
/* Chart Channel Colors for Dark Theme */
|
/* Chart Channel Colors for Dark Theme */
|
||||||
--chart-usb-color: #569cd6; /* A lighter blue for dark backgrounds */
|
--chart-usb-color: #569cd6; /* A lighter blue for dark backgrounds */
|
||||||
--chart-main-color: #4ec9b0; /* A teal/cyan for dark backgrounds */
|
--chart-main-color: #4ec9b0; /* A teal/cyan for dark backgrounds */
|
||||||
--chart-vin-color: #d16969; /* A softer red for dark backgrounds */
|
--chart-vin-color: #d16969; /* A softer red for dark backgrounds */
|
||||||
}
|
}
|
||||||
|
|
||||||
body, .card, .modal-content, .list-group-item, .nav-tabs .nav-link {
|
body, .card, .modal-content, .list-group-item, .nav-tabs .nav-link {
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
* theme handling, and data communication with the WebSocket.
|
* theme handling, and data communication with the WebSocket.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Terminal } from '@xterm/xterm';
|
import {Terminal} from '@xterm/xterm';
|
||||||
import '@xterm/xterm/css/xterm.css';
|
import '@xterm/xterm/css/xterm.css';
|
||||||
import { FitAddon } from '@xterm/addon-fit';
|
import {FitAddon} from '@xterm/addon-fit';
|
||||||
import { terminalContainer } from './dom.js';
|
import {terminalContainer} from './dom.js';
|
||||||
import { isMobile } from './utils.js';
|
import {isMobile} from './utils.js';
|
||||||
import { websocket, sendWebsocketMessage } from './websocket.js';
|
import {sendWebsocketMessage} from './websocket.js';
|
||||||
|
|
||||||
// Exported terminal instance and addon for global access
|
// Exported terminal instance and addon for global access
|
||||||
export let term;
|
export let term;
|
||||||
@@ -41,7 +41,7 @@ export function setupTerminal() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fitAddon = new FitAddon();
|
fitAddon = new FitAddon();
|
||||||
term = new Terminal({ convertEol: true, cursorBlink: true });
|
term = new Terminal({convertEol: true, cursorBlink: true});
|
||||||
term.loadAddon(fitAddon);
|
term.loadAddon(fitAddon);
|
||||||
term.open(terminalContainer);
|
term.open(terminalContainer);
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ export function downloadTerminalOutput() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a blob from the text content
|
// Create a blob from the text content
|
||||||
const blob = new Blob([fullText], { type: 'text/plain;charset=utf-8' });
|
const blob = new Blob([fullText], {type: 'text/plain;charset=utf-8'});
|
||||||
|
|
||||||
// Create a link element to trigger the download
|
// Create a link element to trigger the download
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
|
|||||||
@@ -8,9 +8,9 @@
|
|||||||
import * as bootstrap from 'bootstrap';
|
import * as bootstrap from 'bootstrap';
|
||||||
import * as dom from './dom.js';
|
import * as dom from './dom.js';
|
||||||
import * as api from './api.js';
|
import * as api from './api.js';
|
||||||
import { formatUptime, isMobile } from './utils.js';
|
import {formatUptime, isMobile} from './utils.js';
|
||||||
import { applyTerminalTheme, fitTerminal } from './terminal.js';
|
import {applyTerminalTheme, fitTerminal} from './terminal.js';
|
||||||
import { applyChartsTheme, resizeCharts, updateCharts } from './chart.js';
|
import {applyChartsTheme, resizeCharts, updateCharts} from './chart.js';
|
||||||
|
|
||||||
// Instance of the Bootstrap Modal for Wi-Fi connection
|
// Instance of the Bootstrap Modal for Wi-Fi connection
|
||||||
let wifiModal;
|
let wifiModal;
|
||||||
@@ -115,7 +115,7 @@ export async function scanForWifi() {
|
|||||||
wifiModal.show();
|
wifiModal.show();
|
||||||
dom.wifiModalEl.addEventListener('shown.bs.modal', () => {
|
dom.wifiModalEl.addEventListener('shown.bs.modal', () => {
|
||||||
dom.wifiPasswordConnectInput.focus();
|
dom.wifiPasswordConnectInput.focus();
|
||||||
}, { once: true });
|
}, {once: true});
|
||||||
});
|
});
|
||||||
|
|
||||||
dom.wifiApList.appendChild(row);
|
dom.wifiApList.appendChild(row);
|
||||||
@@ -184,10 +184,10 @@ export async function applyNetworkSettings() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
payload = { net_type: 'static', ip, gateway, subnet, dns1 };
|
payload = {net_type: 'static', ip, gateway, subnet, dns1};
|
||||||
if (dns2) payload.dns2 = dns2;
|
if (dns2) payload.dns2 = dns2;
|
||||||
} else {
|
} else {
|
||||||
payload = { net_type: 'dhcp' };
|
payload = {net_type: 'dhcp'};
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -208,7 +208,7 @@ export async function applyNetworkSettings() {
|
|||||||
*/
|
*/
|
||||||
export async function applyApModeSettings() {
|
export async function applyApModeSettings() {
|
||||||
const mode = dom.apModeToggle.checked ? 'apsta' : 'sta';
|
const mode = dom.apModeToggle.checked ? 'apsta' : 'sta';
|
||||||
let payload = { mode };
|
let payload = {mode};
|
||||||
|
|
||||||
dom.apModeApplyButton.disabled = true;
|
dom.apModeApplyButton.disabled = true;
|
||||||
dom.apModeApplyButton.innerHTML = `<span class="spinner-border spinner-border-sm" aria-hidden="true"></span> Applying...`;
|
dom.apModeApplyButton.innerHTML = `<span class="spinner-border spinner-border-sm" aria-hidden="true"></span> Applying...`;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const gateway = `ws://${window.location.host}/ws`;
|
|||||||
* @param {function} callbacks.onClose - Called when the connection is closed.
|
* @param {function} callbacks.onClose - Called when the connection is closed.
|
||||||
* @param {function} callbacks.onMessage - Called when a message is received from the server.
|
* @param {function} callbacks.onMessage - Called when a message is received from the server.
|
||||||
*/
|
*/
|
||||||
export function initWebSocket({ onOpen, onClose, onMessage }) {
|
export function initWebSocket({onOpen, onClose, onMessage}) {
|
||||||
console.log(`Trying to open a WebSocket connection to ${gateway}...`);
|
console.log(`Trying to open a WebSocket connection to ${gateway}...`);
|
||||||
websocket = new WebSocket(gateway);
|
websocket = new WebSocket(gateway);
|
||||||
// Set binary type to arraybuffer to handle raw binary data from the UART.
|
// Set binary type to arraybuffer to handle raw binary data from the UART.
|
||||||
|
|||||||
Reference in New Issue
Block a user