Twelve of the round-15 items (the code items; the live-hardware flashing/ testing and the settings/localization/logs work follow separately): #1 Configure-pools: three pool rows (address, account, worker, password), each field with a "+" dropdown of presets (top-11 BTC pool stratums; worker-name placeholders) plus user-addable, persisted entries. Worker picks insert at the cursor rather than replacing. Writes up to three pools per miner via set_pools_config, worker expanded per unit. #2 PIC detection: replace the broken SSH i2cdump (it read 0x48, the temp sensor, not the PIC) with a model lookup -- no firmware exposes PIC over the network, so infer it from the model (noPIC: S19k Pro, S21 family, T21, explicit noPIC; PIC: rest of the S19 line). #4 Zoom: an editable percent field in the status bar (type an exact scale) and Ctrl +/- / Ctrl+0 to zoom in/out/reset. #5 Health icons align in fixed slots (power, control, fans, hashboards); miners with fewer fans/boards leave a gap so hashboards still line up. The max fan/board counts are computed parametrically from the fleet. #6 Light: the locate-light column is on by default (last), shown as a green-over-red beacon flashing quickly instead of a single amber dot. #8 The bottom-left status line is now scan-only; operation progress lives in the Health column (per miner) and failures in the bottom-right indicator. #9 / #10 / #11: drop the Credentials-dialog blurb; move the scan-ranges format help to a tooltip; make Restore-to-stock a plain confirmation (no typed keyword, no warning wall). #12 Z15 fans: the v2020 backend now reads fans from higher fan slots (the Z15 reports fan3/fan4 with fan1/fan2 = 0). Vendored patch 0009. #14 Export: an Export button writes every scanned data point to a CSV, one value per cell (lists expanded to indexed columns) -- complete and machine-readable, unlike the on-screen table. #15 Health tooltips are per-icon: hovering a specific fan or hashboard shows just that component's state, with errors attributed to the board that names them in the message. New wx-rs bridge surface: widget tooltips, save-file dialog, insert-at-cursor, status-bar zoom entry + Ctrl+/-, the light beacon + alignment-gap sentinels, and per-icon cell tooltips (bridge patches 0002/0003 regenerated). Unit tests (worker templates, PIC map, CSV export, health) + headless selftest pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6
157 lines
5.6 KiB
Rust
157 lines
5.6 KiB
Rust
//! Saved view presets: named snapshots of the table's column arrangement,
|
|
//! visibility, sort, and filters. Persisted as JSON in the config dir. The
|
|
//! first preset is always a built-in "Default" profile.
|
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::model::{ColFilter, Column, ViewState, ALL_COLUMNS};
|
|
use crate::scan::config_path;
|
|
|
|
pub const PRESETS_FILE: &str = "presets.json";
|
|
|
|
/// The built-in default profile's visible columns, in display order (Ip first):
|
|
/// IP, model, health (component icons), hashrate, power, chip temp, firmware,
|
|
/// CPU, access. The Health column (round 13 #3) replaced the old errors, boards
|
|
/// (hashboard dots) and status columns.
|
|
const DEFAULT_PROFILE: [Column; 10] = [
|
|
Column::Ip,
|
|
Column::Model,
|
|
Column::Health,
|
|
Column::Hashrate,
|
|
Column::Power,
|
|
Column::ChipTemp,
|
|
Column::Firmware,
|
|
Column::Cpu,
|
|
Column::Locked,
|
|
Column::Light,
|
|
];
|
|
|
|
/// A serializable snapshot of a `ViewState` (Vec-based so JSON has no map keys
|
|
/// that are enums, and column order within `visible` is preserved).
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct PresetView {
|
|
pub order: Vec<Column>,
|
|
pub visible: Vec<Column>,
|
|
pub sort: Option<(Column, bool)>,
|
|
pub filters: Vec<(Column, ColFilter)>,
|
|
}
|
|
|
|
impl PresetView {
|
|
pub fn from_view(v: &ViewState) -> PresetView {
|
|
PresetView {
|
|
order: v.order.clone(),
|
|
// keep the visible columns in display order for stability
|
|
visible: v.order.iter().copied().filter(|c| v.visible.contains(c)).collect(),
|
|
sort: v.sort,
|
|
filters: v.filters.iter().map(|(k, f)| (*k, f.clone())).collect(),
|
|
}
|
|
}
|
|
|
|
/// Rebuild a `ViewState` from this snapshot. Any column missing from a
|
|
/// loaded (possibly older) preset is appended to `order` and left hidden, so
|
|
/// the result always covers every `Column`.
|
|
pub fn to_view(&self) -> ViewState {
|
|
let mut order = self.order.clone();
|
|
for c in ALL_COLUMNS {
|
|
if !order.contains(&c) {
|
|
order.push(c);
|
|
}
|
|
}
|
|
let mut visible: HashSet<Column> = self.visible.iter().copied().collect();
|
|
visible.insert(Column::Ip); // IP is always shown
|
|
let filters: HashMap<Column, ColFilter> = self.filters.iter().cloned().collect();
|
|
ViewState { order, visible, sort: self.sort, filters }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
pub struct Preset {
|
|
pub name: String,
|
|
pub view: PresetView,
|
|
}
|
|
|
|
/// The built-in default profile (always present as the first preset).
|
|
pub fn default_preset() -> Preset {
|
|
let mut order: Vec<Column> = DEFAULT_PROFILE.to_vec();
|
|
for c in ALL_COLUMNS {
|
|
if !order.contains(&c) {
|
|
order.push(c);
|
|
}
|
|
}
|
|
Preset {
|
|
name: "Default".to_string(),
|
|
view: PresetView {
|
|
order,
|
|
visible: DEFAULT_PROFILE.to_vec(),
|
|
sort: None,
|
|
filters: Vec::new(),
|
|
},
|
|
}
|
|
}
|
|
|
|
/// Load saved presets, always with the built-in "Default" first. A missing or
|
|
/// unreadable file yields just the default.
|
|
pub fn load_presets() -> Vec<Preset> {
|
|
let mut presets = std::fs::read_to_string(config_path(PRESETS_FILE))
|
|
.ok()
|
|
.and_then(|s| serde_json::from_str::<Vec<Preset>>(&s).ok())
|
|
.unwrap_or_default();
|
|
// The default profile is always present and always first.
|
|
presets.retain(|p| p.name != "Default");
|
|
presets.insert(0, default_preset());
|
|
presets
|
|
}
|
|
|
|
/// Persist presets (the built-in "Default" is not written; it is re-seeded on
|
|
/// load). Best-effort: errors are returned for the caller to surface.
|
|
pub fn save_presets(presets: &[Preset]) -> std::io::Result<()> {
|
|
let p = config_path(PRESETS_FILE);
|
|
if let Some(dir) = p.parent() {
|
|
std::fs::create_dir_all(dir)?;
|
|
}
|
|
let user: Vec<&Preset> = presets.iter().filter(|p| p.name != "Default").collect();
|
|
let json = serde_json::to_string_pretty(&user)
|
|
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?;
|
|
std::fs::write(p, json)
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn default_preset_round_trips_through_view() {
|
|
let p = default_preset();
|
|
let view = p.view.to_view();
|
|
// IP first + the requested default columns visible.
|
|
assert!(view.visible.contains(&Column::Ip));
|
|
assert!(view.visible.contains(&Column::Model));
|
|
assert!(view.visible.contains(&Column::Health));
|
|
assert!(view.visible.contains(&Column::Cpu));
|
|
assert!(view.visible.contains(&Column::Locked));
|
|
// The Health column (round 13 #3) replaced these in the default profile.
|
|
assert!(!view.visible.contains(&Column::Error));
|
|
assert!(!view.visible.contains(&Column::Hashboards));
|
|
// Columns dropped from the default profile in round 11.
|
|
assert!(!view.visible.contains(&Column::BoardCode), "not in the default profile");
|
|
assert!(!view.visible.contains(&Column::Cooling), "not in the default profile");
|
|
// to_view covers every column in `order`.
|
|
assert_eq!(view.order.len(), ALL_COLUMNS.len());
|
|
// Round-trip a snapshot back out.
|
|
let snap = PresetView::from_view(&view);
|
|
assert_eq!(snap.visible.first(), Some(&Column::Ip));
|
|
}
|
|
|
|
#[test]
|
|
fn preset_json_round_trip() {
|
|
let p = default_preset();
|
|
let json = serde_json::to_string(&vec![&p]).unwrap();
|
|
let back: Vec<Preset> = serde_json::from_str(&json).unwrap();
|
|
assert_eq!(back.len(), 1);
|
|
assert_eq!(back[0].name, "Default");
|
|
assert_eq!(back[0].view.visible, DEFAULT_PROFILE.to_vec());
|
|
}
|
|
}
|