This commit is contained in:
parent
62d870521e
commit
a90b5f83d8
|
@ -1,10 +1,18 @@
|
||||||
|
use js_sys::Array;
|
||||||
|
use wasm_bindgen::{JsCast, JsValue};
|
||||||
|
use web_sys::{Blob, HtmlAnchorElement, Url};
|
||||||
|
|
||||||
use yew::prelude::*;
|
use yew::prelude::*;
|
||||||
use yewdux::prelude::*;
|
use yewdux::prelude::*;
|
||||||
|
|
||||||
use crate::components::states::{CurrentTransfer, MainState};
|
use crate::components::states::{CurrentTransfer, MainState};
|
||||||
|
|
||||||
|
use crate::data::csv::state_to_csv;
|
||||||
|
|
||||||
|
type NoParamsCallback = Box<dyn Fn(()) -> ()>;
|
||||||
|
|
||||||
pub fn toggle_in_transfer_hashes_callback(
|
pub fn toggle_in_transfer_hashes_callback(
|
||||||
main_dispatch: &Dispatch<MainState>,
|
main_dispatch: Dispatch<MainState>,
|
||||||
) -> Callback<web_sys::MouseEvent> {
|
) -> Callback<web_sys::MouseEvent> {
|
||||||
let main_dispatch = main_dispatch.clone();
|
let main_dispatch = main_dispatch.clone();
|
||||||
Callback::from(move |_| {
|
Callback::from(move |_| {
|
||||||
|
@ -13,3 +21,86 @@ pub fn toggle_in_transfer_hashes_callback(
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn new_plate_dialog_callback(
|
||||||
|
new_plate_dialog_is_open: UseStateHandle<bool>,
|
||||||
|
) -> NoParamsCallback {
|
||||||
|
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
||||||
|
Box::new(move |_| {
|
||||||
|
new_plate_dialog_is_open.set(false);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn open_new_plate_dialog_callback(
|
||||||
|
new_plate_dialog_is_open: UseStateHandle<bool>,
|
||||||
|
) -> NoParamsCallback {
|
||||||
|
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
||||||
|
Box::new(move |_| {
|
||||||
|
new_plate_dialog_is_open.set(true);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_button_callback(
|
||||||
|
main_dispatch: Dispatch<MainState>,
|
||||||
|
ct_dispatch: Dispatch<CurrentTransfer>,
|
||||||
|
) -> Callback<web_sys::MouseEvent> {
|
||||||
|
Callback::from(move |_| {
|
||||||
|
let window = web_sys::window().unwrap();
|
||||||
|
let confirm =
|
||||||
|
window.confirm_with_message("This will reset all plates and transfers. Proceed?");
|
||||||
|
if let Ok(confirm) = confirm {
|
||||||
|
if confirm {
|
||||||
|
main_dispatch.set(MainState::default());
|
||||||
|
ct_dispatch.set(CurrentTransfer::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn save_str(data: &str, name: &str) {
|
||||||
|
let blob =
|
||||||
|
Blob::new_with_str_sequence(&Array::from_iter(std::iter::once(JsValue::from_str(data))));
|
||||||
|
if let Ok(blob) = blob {
|
||||||
|
let url = Url::create_object_url_with_blob(&blob).expect("We have a blob, why not URL?");
|
||||||
|
// Beneath is the cool hack to download files
|
||||||
|
let window = web_sys::window().unwrap();
|
||||||
|
let document = window.document().unwrap();
|
||||||
|
let anchor = document
|
||||||
|
.create_element("a")
|
||||||
|
.unwrap()
|
||||||
|
.dyn_into::<HtmlAnchorElement>()
|
||||||
|
.unwrap();
|
||||||
|
anchor.set_download(name);
|
||||||
|
anchor.set_href(&url);
|
||||||
|
anchor.click();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn export_csv_button_callback(main_state: std::rc::Rc<MainState>) -> Callback<MouseEvent> {
|
||||||
|
Callback::from(move |_| {
|
||||||
|
if main_state.transfers.is_empty() {
|
||||||
|
web_sys::window()
|
||||||
|
.unwrap()
|
||||||
|
.alert_with_message("No transfers to export.")
|
||||||
|
.unwrap();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
web_sys::window().unwrap().alert_with_message("CSV export is currently not importable. Export as JSON if you'd like to back up your work!").unwrap();
|
||||||
|
if let Ok(csv) = state_to_csv(&main_state) {
|
||||||
|
save_str(&csv, "transfers.csv");
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn export_json_button_callback(main_state: std::rc::Rc<MainState>) -> Callback<MouseEvent> {
|
||||||
|
Callback::from(move |_| {
|
||||||
|
if let Ok(json) = serde_json::to_string(&main_state) {
|
||||||
|
save_str(&json, "plate-tool-state.json");
|
||||||
|
} else {
|
||||||
|
web_sys::window()
|
||||||
|
.unwrap()
|
||||||
|
.alert_with_message("Failed to export.")
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,6 @@ use crate::components::states::{CurrentTransfer, MainState};
|
||||||
use crate::components::transfer_menu::{letters_to_num, RegionDisplay, TransferMenu};
|
use crate::components::transfer_menu::{letters_to_num, RegionDisplay, TransferMenu};
|
||||||
use crate::components::tree::Tree;
|
use crate::components::tree::Tree;
|
||||||
|
|
||||||
use crate::data::csv::state_to_csv;
|
|
||||||
use crate::data::plate_instances::PlateInstance;
|
use crate::data::plate_instances::PlateInstance;
|
||||||
use crate::data::transfer::Transfer;
|
use crate::data::transfer::Transfer;
|
||||||
use crate::data::transfer_region::{Region, TransferRegion};
|
use crate::data::transfer_region::{Region, TransferRegion};
|
||||||
|
@ -51,65 +50,30 @@ pub fn MainWindow() -> Html {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let toggle_in_transfer_hashes_callback = main_window_callbacks::test(&main_dispatch);
|
let toggle_in_transfer_hashes_callback = {
|
||||||
|
let main_dispatch = main_dispatch.clone();
|
||||||
|
main_window_callbacks::toggle_in_transfer_hashes_callback(main_dispatch)
|
||||||
|
};
|
||||||
|
|
||||||
let new_plate_dialog_is_open = use_state_eq(|| false);
|
let new_plate_dialog_is_open = use_state_eq(|| false);
|
||||||
let new_plate_dialog_callback = {
|
let new_plate_dialog_callback =
|
||||||
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
main_window_callbacks::new_plate_dialog_callback(new_plate_dialog_is_open.clone());
|
||||||
Callback::from(move |_| {
|
|
||||||
new_plate_dialog_is_open.set(false);
|
let open_new_plate_dialog_callback =
|
||||||
})
|
main_window_callbacks::open_new_plate_dialog_callback(new_plate_dialog_is_open.clone());
|
||||||
};
|
|
||||||
let open_new_plate_dialog_callback = {
|
|
||||||
let new_plate_dialog_is_open = new_plate_dialog_is_open.clone();
|
|
||||||
Callback::from(move |_| {
|
|
||||||
new_plate_dialog_is_open.set(true);
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
let new_button_callback = {
|
let new_button_callback = {
|
||||||
let main_dispatch = main_dispatch.clone();
|
let main_dispatch = main_dispatch.clone();
|
||||||
Callback::from(move |_| {
|
main_window_callbacks::new_button_callback(main_dispatch, ct_dispatch)
|
||||||
let window = web_sys::window().unwrap();
|
|
||||||
let confirm =
|
|
||||||
window.confirm_with_message("This will reset all plates and transfers. Proceed?");
|
|
||||||
if let Ok(confirm) = confirm {
|
|
||||||
if confirm {
|
|
||||||
main_dispatch.set(MainState::default());
|
|
||||||
ct_dispatch.set(CurrentTransfer::default());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let export_csv_button_callback = {
|
let export_csv_button_callback = {
|
||||||
let main_state = main_state.clone();
|
let main_state = main_state.clone();
|
||||||
Callback::from(move |_| {
|
main_window_callbacks::export_csv_button_callback(main_state)
|
||||||
if main_state.transfers.is_empty() {
|
|
||||||
web_sys::window()
|
|
||||||
.unwrap()
|
|
||||||
.alert_with_message("No transfers to export.")
|
|
||||||
.unwrap();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
web_sys::window().unwrap().alert_with_message("CSV export is currently not importable. Export as JSON if you'd like to back up your work!").unwrap();
|
|
||||||
if let Ok(csv) = state_to_csv(&main_state) {
|
|
||||||
save_str(&csv, "transfers.csv");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let export_json_button_callback = {
|
let export_json_button_callback = {
|
||||||
Callback::from(move |_| {
|
main_window_callbacks::export_json_button_callback(main_state)
|
||||||
if let Ok(json) = serde_json::to_string(&main_state) {
|
|
||||||
save_str(&json, "plate-tool-state.json");
|
|
||||||
} else {
|
|
||||||
web_sys::window()
|
|
||||||
.unwrap()
|
|
||||||
.alert_with_message("Failed to export.")
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let import_json_button_callback = {
|
let import_json_button_callback = {
|
||||||
|
@ -373,8 +337,18 @@ pub fn MainWindow() -> Html {
|
||||||
let c2 = REGEX
|
let c2 = REGEX
|
||||||
.captures(&record.destination_well)
|
.captures(&record.destination_well)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
log::debug!("{} {}", &record.source_well, &record.destination_well);
|
log::debug!(
|
||||||
log::debug!("{},{} {},{}", &c1[1], &c1[2], &c2[1], &c2[2]);
|
"{} {}",
|
||||||
|
&record.source_well,
|
||||||
|
&record.destination_well
|
||||||
|
);
|
||||||
|
log::debug!(
|
||||||
|
"{},{} {},{}",
|
||||||
|
&c1[1],
|
||||||
|
&c1[2],
|
||||||
|
&c2[1],
|
||||||
|
&c2[2]
|
||||||
|
);
|
||||||
|
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
|
|
Loading…
Reference in New Issue