web: auto button
This commit is contained in:
parent
1aa4c1b7bb
commit
c2a64d679a
|
@ -24,7 +24,7 @@ const W384_ROW_MAX: u8 = 16;
|
|||
const W1536_COL_MAX: u8 = 48;
|
||||
const W1536_ROW_MAX: u8 = 32;
|
||||
|
||||
pub fn auto(records: &Vec<TransferRecord>) -> AutoOutput {
|
||||
pub fn auto(records: &[TransferRecord]) -> AutoOutput {
|
||||
let unique_plates = find_unique_plates(records);
|
||||
let transfers = get_transfer_for_all_pairs(records, &unique_plates);
|
||||
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use regex::Regex;
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use web_sys::{
|
||||
FileReader, HtmlButtonElement, HtmlDialogElement, HtmlFormElement, HtmlInputElement,
|
||||
HtmlOptionElement, HtmlSelectElement,
|
||||
FileReader, HtmlButtonElement, HtmlDialogElement, HtmlElement, HtmlFormElement,
|
||||
HtmlInputElement, HtmlOptionElement, HtmlSelectElement,
|
||||
};
|
||||
use yew::prelude::*;
|
||||
use yewdux::prelude::*;
|
||||
|
||||
use crate::components::states::MainState;
|
||||
use plate_tool_lib::util::letters_to_num;
|
||||
|
||||
use plate_tool_lib::transfer::Transfer;
|
||||
use plate_tool_lib::transfer_region::{Region, TransferRegion};
|
||||
|
||||
use plate_tool_lib::csv::{TransferRecord, string_well_to_pt};
|
||||
use plate_tool_lib::csv::{auto, string_well_to_pt, TransferRecord};
|
||||
|
||||
use super::main_window_callbacks::create_close_button;
|
||||
|
||||
|
@ -115,6 +112,17 @@ pub fn import_transfer_csv_onload_callback(
|
|||
|
||||
let window = web_sys::window().unwrap();
|
||||
let document = window.document().unwrap();
|
||||
|
||||
let auto_button = document
|
||||
.create_element("button")
|
||||
.unwrap()
|
||||
.dyn_into::<HtmlElement>()
|
||||
.unwrap();
|
||||
auto_button.set_inner_text("Auto");
|
||||
let auto_button_callback = auto_callback(main_dispatch.clone(), &records);
|
||||
auto_button.set_onclick(Some(auto_button_callback.as_ref().unchecked_ref()));
|
||||
auto_button_callback.forget();
|
||||
|
||||
let form = document
|
||||
.create_element("form")
|
||||
.unwrap()
|
||||
|
@ -211,6 +219,7 @@ pub fn import_transfer_csv_onload_callback(
|
|||
form.append_child(&to_dest).unwrap();
|
||||
modal.append_child(&submit).unwrap();
|
||||
modal.append_child(&form).unwrap();
|
||||
modal.append_child(&auto_button).unwrap();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -236,7 +245,7 @@ pub fn import_transfer_csv_submit_callback(
|
|||
.map(|record| {
|
||||
(
|
||||
string_well_to_pt(&record.source_well).unwrap(),
|
||||
string_well_to_pt(&record.destination_well).unwrap()
|
||||
string_well_to_pt(&record.destination_well).unwrap(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
@ -277,3 +286,20 @@ pub fn import_transfer_csv_submit_callback(
|
|||
});
|
||||
})
|
||||
}
|
||||
|
||||
fn auto_callback(
|
||||
main_dispatch: Dispatch<MainState>,
|
||||
records: &[TransferRecord],
|
||||
) -> Closure<dyn FnMut(Event)> {
|
||||
let records = Vec::from(records);
|
||||
Closure::<dyn FnMut(_)>::new(move |_| {
|
||||
let res = auto(&records);
|
||||
main_dispatch.reduce_mut(|state| {
|
||||
state.source_plates.extend(res.sources.into_iter());
|
||||
state
|
||||
.destination_plates
|
||||
.extend(res.destinations.into_iter());
|
||||
state.transfers.extend(res.transfers.into_iter());
|
||||
});
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue