Echo client export now available

This commit is contained in:
Emilia Allison 2025-11-22 22:23:46 -05:00
parent d99c03d441
commit a05c62cd9b
No known key found for this signature in database
GPG Key ID: FEC1CE6360EEC9A8
1 changed files with 88 additions and 31 deletions

View File

@ -2,7 +2,9 @@ use std::ops::DerefMut;
use std::sync::Mutex;
use eframe::egui::{self};
use plate_tool_lib::csv::{TransferRecord, records_to_csv, transfer_to_records};
use plate_tool_lib::csv::{
records_to_csv, records_to_echo_client_csv, transfer_to_records, TransferRecord,
};
use crate::file_handling::save_file;
use crate::main_state::{construct_fake_mainstate, MainState};
@ -16,6 +18,7 @@ use crate::tree::tree;
struct MainWindowState {
show_side_panel: bool,
plate_display_options: PlateDisplayOptions,
csv_export_type: CsvExportType,
}
impl Default for MainWindowState {
@ -23,6 +26,24 @@ impl Default for MainWindowState {
Self {
show_side_panel: true,
plate_display_options: PlateDisplayOptions::default(),
csv_export_type: CsvExportType::default(),
}
}
}
#[non_exhaustive]
#[derive(Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, std::default::Default)]
enum CsvExportType {
#[default]
Normal,
EchoClient,
}
impl std::fmt::Display for CsvExportType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Normal => write!(f, "Normal"),
Self::EchoClient => write!(f, "Echo Client"),
}
}
}
@ -121,23 +142,48 @@ impl eframe::App for PlateToolEframe {
.transfers
.iter()
.flat_map(|transfer| {
let src_barcode = self.main_state.source_plates
let src_barcode = self
.main_state
.source_plates
.iter()
.find(|spi| spi.get_uuid() == transfer.source_id)?;
let dest_barcode = self.main_state.destination_plates
let dest_barcode = self
.main_state
.destination_plates
.iter()
.find(|dpi| dpi.get_uuid() == transfer.dest_id)?;
Some(transfer_to_records(transfer, &src_barcode.name, &dest_barcode.name))
if self.main_window_state.csv_export_type
!= CsvExportType::EchoClient
|| self
.main_state
.get_current_source_uuid()
.is_some_and(|x| x != src_barcode.get_uuid())
|| self
.main_state
.get_current_destination_uuid()
.is_some_and(|x| x != dest_barcode.get_uuid())
{
return None;
}
Some(transfer_to_records(
transfer,
&src_barcode.name,
&dest_barcode.name,
))
})
.flatten()
.collect();
if let Ok(data) = records_to_csv(records)
{
let data = match self.main_window_state.csv_export_type {
CsvExportType::Normal => records_to_csv(records),
CsvExportType::EchoClient => records_to_echo_client_csv(records),
};
if let Ok(data) = data {
let bytes: &[u8] = data.as_bytes();
save_file(bytes, Some("transfers.csv"));
}
}
if ui.button("Export as JSON").clicked() {}
});
@ -178,7 +224,18 @@ impl eframe::App for PlateToolEframe {
);
});
ui.menu_button("Exports", |ui| {
if ui.button("Change CSV export type").clicked() {}
ui.menu_button("CSV Export Type", |ui| {
ui.radio_value(
&mut self.main_window_state.csv_export_type,
CsvExportType::Normal,
format!("{}", CsvExportType::Normal),
);
ui.radio_value(
&mut self.main_window_state.csv_export_type,
CsvExportType::EchoClient,
format!("{}", CsvExportType::EchoClient),
);
});
});
ui.menu_button("Windows", |ui| {
ui.toggle_value(