lib migration pt 2

This commit is contained in:
Emilia Allison 2024-02-11 19:46:43 -05:00
parent ffc81f505b
commit 7d35959ac2
Signed by: emilia
GPG Key ID: 05D5D1107E5100A1
17 changed files with 67 additions and 74 deletions

View File

@ -22,30 +22,9 @@ pub struct TransferRecord {
} }
/* /*
pub fn state_to_csv(state: &MainState) -> Result<String, Box<dyn Error>> {
let mut records: Vec<TransferRecord> = Vec::new();
for transfer in &state.transfers {
let src_barcode = state
.source_plates
.iter()
.find(|spi| spi.get_uuid() == transfer.source_id)
.ok_or("Found unpurged transfer")?;
let dest_barcode = state
.destination_plates
.iter()
.find(|dpi| dpi.get_uuid() == transfer.dest_id)
.ok_or("Found unpurged transfer")?;
records.append(&mut transfer_to_records(
transfer,
&src_barcode.name,
&dest_barcode.name,
))
}
records_to_csv(records)
}
*/ */
fn transfer_to_records( pub fn transfer_to_records(
tr: &Transfer, tr: &Transfer,
src_barcode: &str, src_barcode: &str,
dest_barcode: &str, dest_barcode: &str,
@ -73,7 +52,7 @@ fn transfer_to_records(
records records
} }
fn records_to_csv(trs: Vec<TransferRecord>) -> Result<String, Box<dyn Error>> { pub fn records_to_csv(trs: Vec<TransferRecord>) -> Result<String, Box<dyn Error>> {
let mut wtr = csv::WriterBuilder::new().from_writer(vec![]); let mut wtr = csv::WriterBuilder::new().from_writer(vec![]);
for record in trs { for record in trs {
wtr.serialize(record)? wtr.serialize(record)?

View File

@ -41,3 +41,10 @@ impl From<Plate> for PlateInstance {
} }
} }
} }
impl From<&PlateInstance> for String {
fn from(value: &PlateInstance) -> Self {
// Could have other formatting here
format!("{}, {}", value.name, value.plate.plate_format)
}
}

View File

@ -1,24 +1,22 @@
use std::collections::HashSet; use std::collections::HashSet;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use wasm_bindgen::{prelude::*, JsCast}; use wasm_bindgen::{prelude::*, JsCast};
use web_sys::{ use web_sys::{
FileReader, HtmlButtonElement, HtmlDialogElement, FileReader, HtmlButtonElement, HtmlDialogElement, HtmlFormElement, HtmlInputElement,
HtmlFormElement, HtmlInputElement, HtmlOptionElement, HtmlSelectElement, HtmlOptionElement, HtmlSelectElement,
}; };
use yew::prelude::*; use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
use crate::components::states::{MainState}; use crate::components::states::MainState;
use crate::components::transfer_menu::letters_to_num; use plate_tool_lib::util::letters_to_num;
use crate::data::transfer::Transfer; use plate_tool_lib::transfer::Transfer;
use crate::data::transfer_region::{Region, TransferRegion}; use plate_tool_lib::transfer_region::{Region, TransferRegion};
use crate::data::csv::{TransferRecord}; use plate_tool_lib::csv::TransferRecord;
use super::main_window_callbacks::create_close_button; use super::main_window_callbacks::create_close_button;
@ -111,7 +109,7 @@ pub fn import_transfer_csv_onload_callback(
log::info!("{}", modified); log::info!("{}", modified);
let mut rdr = csv::Reader::from_reader(value.as_bytes()); let mut rdr = csv::Reader::from_reader(value.as_bytes());
let mut records = Vec::new(); let mut records = Vec::new();
for record in rdr.deserialize::<crate::data::csv::TransferRecord>() { for record in rdr.deserialize::<plate_tool_lib::csv::TransferRecord>() {
match record { match record {
Ok(r) => { Ok(r) => {
//log::debug!("{:?}", r); //log::debug!("{:?}", r);

View File

@ -14,11 +14,7 @@ use yewdux::prelude::*;
use crate::components::states::{CurrentTransfer, MainState}; use crate::components::states::{CurrentTransfer, MainState};
use crate::state_to_csv;
use crate::data::csv::{state_to_csv};
type NoParamsCallback = Box<dyn Fn(())>; type NoParamsCallback = Box<dyn Fn(())>;

View File

@ -5,8 +5,8 @@ use wasm_bindgen::JsCast;
use web_sys::{EventTarget, FormData, HtmlFormElement}; use web_sys::{EventTarget, FormData, HtmlFormElement};
use crate::components::states::MainState; use crate::components::states::MainState;
use crate::data::plate::*; use plate_tool_lib::plate::*;
use crate::data::plate_instances::PlateInstance; use plate_tool_lib::plate_instances::PlateInstance;
pub fn new_plate_callback( pub fn new_plate_callback(
dispatch: Dispatch<MainState>, dispatch: Dispatch<MainState>,

View File

@ -6,7 +6,7 @@ use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
use crate::components::transfer_menu::RegionDisplay; use crate::components::transfer_menu::RegionDisplay;
use crate::data::{transfer::Transfer, transfer_region::Region}; use plate_tool_lib::{transfer::Transfer, transfer_region::Region};
use crate::components::states::{CurrentTransfer, MainState}; use crate::components::states::{CurrentTransfer, MainState};

View File

@ -6,7 +6,7 @@ use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
use crate::components::states::{CurrentTransfer, MainState}; use crate::components::states::{CurrentTransfer, MainState};
use crate::data::transfer_region::Region; use plate_tool_lib::transfer_region::Region;
type NoParamsCallback = Box<dyn Fn(())>; type NoParamsCallback = Box<dyn Fn(())>;

View File

@ -1,8 +1,4 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
use yew::prelude::*; use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
@ -12,7 +8,7 @@ use crate::components::states::{CurrentTransfer, MainState};
use crate::components::transfer_menu::TransferMenu; use crate::components::transfer_menu::TransferMenu;
use crate::components::tree::Tree; use crate::components::tree::Tree;
use crate::data::plate_instances::PlateInstance; use plate_tool_lib::plate_instances::PlateInstance;
use crate::components::callbacks::main_window_callbacks; use crate::components::callbacks::main_window_callbacks;

View File

@ -4,7 +4,7 @@ use yewdux::prelude::*;
use web_sys::HtmlDialogElement; use web_sys::HtmlDialogElement;
use crate::components::states::MainState; use crate::components::states::MainState;
use crate::data::plate_instances::PlateInstance; use plate_tool_lib::plate_instances::PlateInstance;
use crate::components::callbacks::new_plate_dialog_callbacks; use crate::components::callbacks::new_plate_dialog_callbacks;
@ -69,10 +69,3 @@ pub fn NewPlateDialog(props: &NewPlateDialogProps) -> Html {
</dialog> </dialog>
} }
} }
impl From<&PlateInstance> for String {
fn from(value: &PlateInstance) -> Self {
// Could have other formatting here
format!("{}, {}", value.name, value.plate.plate_format)
}
}

View File

@ -5,15 +5,15 @@ use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
use crate::components::states::{CurrentTransfer, MainState}; use crate::components::states::{CurrentTransfer, MainState};
use crate::data::plate::PlateType; use plate_tool_lib::plate::PlateType;
use crate::data::transfer::Transfer; use plate_tool_lib::transfer::Transfer;
use crate::data::transfer_region::Region; use plate_tool_lib::transfer_region::Region;
// Color Palette for the Source Plates, can be changed here // Color Palette for the Source Plates, can be changed here
use crate::components::plates::util::Palettes; use crate::components::plates::util::Palettes;
const PALETTE: super::util::ColorPalette = Palettes::RAINBOW; const PALETTE: super::util::ColorPalette = Palettes::RAINBOW;
use super::super::transfer_menu::{num_to_letters}; use plate_tool_lib::util::num_to_letters;
use super::plate_data::*; use super::plate_data::*;
use super::plate_callbacks; use super::plate_callbacks;

View File

@ -2,7 +2,7 @@ use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
use crate::components::states::CurrentTransfer; use crate::components::states::CurrentTransfer;
use crate::data::transfer_region::Region; use plate_tool_lib::transfer_region::Region;
// Color Palette for the Source Plates, can be changed here // Color Palette for the Source Plates, can be changed here

View File

@ -3,8 +3,8 @@ use wasm_bindgen::prelude::Closure;
use wasm_bindgen::JsCast; use wasm_bindgen::JsCast;
use yew::prelude::*; use yew::prelude::*;
use crate::data::plate::PlateType; use plate_tool_lib::plate::PlateType;
use crate::data::plate_instances::PlateInstance; use plate_tool_lib::plate_instances::PlateInstance;
// use super::destination_plate::DestinationPlate; // use super::destination_plate::DestinationPlate;
// use super::source_plate::SourcePlate; // use super::source_plate::SourcePlate;

View File

@ -1,8 +1,8 @@
use yew::prelude::*; use yew::prelude::*;
use crate::data::plate_instances::PlateInstance; use plate_tool_lib::plate_instances::PlateInstance;
use crate::data::plate::PlateType; use plate_tool_lib::plate::PlateType;
#[derive(PartialEq, Properties)] #[derive(PartialEq, Properties)]
pub struct PlateProps { pub struct PlateProps {

View File

@ -2,10 +2,6 @@
// https://iquilezles.org/articles/palettes/ // https://iquilezles.org/articles/palettes/
// http://dev.thi.ng/gradients/ // http://dev.thi.ng/gradients/
#[derive(Clone, Copy, PartialEq, Debug)] #[derive(Clone, Copy, PartialEq, Debug)]
pub struct ColorPalette { pub struct ColorPalette {
a: [f64; 3], a: [f64; 3],

View File

@ -2,9 +2,9 @@ use serde::{Deserialize, Serialize};
use uuid::Uuid; use uuid::Uuid;
use yewdux::{prelude::*, storage}; use yewdux::{prelude::*, storage};
use crate::data::plate::*; use plate_tool_lib::plate::*;
use crate::data::plate_instances::PlateInstance; use plate_tool_lib::plate_instances::PlateInstance;
use crate::data::transfer::Transfer; use plate_tool_lib::transfer::Transfer;
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Store)] #[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Store)]
#[store(storage = "session")] #[store(storage = "session")]

View File

@ -7,7 +7,8 @@ use yew::prelude::*;
use yewdux::prelude::*; use yewdux::prelude::*;
use crate::components::callbacks::transfer_menu_callbacks; use crate::components::callbacks::transfer_menu_callbacks;
use crate::data::transfer_region::Region; use plate_tool_lib::transfer_region::Region;
use plate_tool_lib::util::{letters_to_num, num_to_letters};
use super::states::{CurrentTransfer, MainState}; use super::states::{CurrentTransfer, MainState};
@ -282,6 +283,8 @@ impl TryFrom<(u8, u8, u8, u8)> for RegionDisplay {
mod tests { mod tests {
use wasm_bindgen_test::*; use wasm_bindgen_test::*;
use super::*;
#[test] #[test]
#[wasm_bindgen_test] #[wasm_bindgen_test]
fn test_try_from_string_for_regiondisplay() { fn test_try_from_string_for_regiondisplay() {

View File

@ -1,12 +1,15 @@
#![allow(non_snake_case)] #![allow(non_snake_case)]
mod components; mod components;
mod data;
use std::error::Error;
use components::main_window::MainWindow; use components::main_window::MainWindow;
use components::states::MainState;
use plate_tool_lib::csv::*;
use yew::prelude::*; use yew::prelude::*;
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
use data::*; use plate_tool_lib::*;
#[function_component] #[function_component]
pub fn App() -> Html { pub fn App() -> Html {
@ -35,3 +38,25 @@ pub fn plate_test() {
println!("{:?} -> {:?}", w, m(w)); println!("{:?} -> {:?}", w, m(w));
} }
} }
pub fn state_to_csv(state: &MainState) -> Result<String, Box<dyn Error>> {
let mut records: Vec<TransferRecord> = Vec::new();
for transfer in &state.transfers {
let src_barcode = state
.source_plates
.iter()
.find(|spi| spi.get_uuid() == transfer.source_id)
.ok_or("Found unpurged transfer")?;
let dest_barcode = state
.destination_plates
.iter()
.find(|dpi| dpi.get_uuid() == transfer.dest_id)
.ok_or("Found unpurged transfer")?;
records.append(&mut transfer_to_records(
transfer,
&src_barcode.name,
&dest_barcode.name,
))
}
records_to_csv(records)
}