plate-tool/src/components/states.rs

112 lines
3.1 KiB
Rust
Raw Normal View History

2023-06-01 17:04:03 +00:00
use serde::{Deserialize, Serialize};
2023-05-24 01:08:32 +00:00
use uuid::Uuid;
2023-06-01 17:04:03 +00:00
use yewdux::{prelude::*, storage};
2023-05-24 01:08:32 +00:00
2023-06-01 17:04:03 +00:00
use crate::data::plate::*;
use crate::data::plate_instances::PlateInstance;
use crate::data::transfer::Transfer;
2023-05-22 17:25:16 +00:00
2023-05-24 22:39:38 +00:00
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize, Store)]
#[store(storage = "session")]
2023-06-07 21:08:43 +00:00
#[non_exhaustive]
2023-05-24 22:39:38 +00:00
pub struct CurrentTransfer {
2023-06-01 17:04:03 +00:00
pub transfer: Transfer,
2023-05-22 17:25:16 +00:00
}
Merge from import_from_csv feature branch Of course, there were other features that got tacked on... Squashed commit of the following: commit 3ee3bd2dab3ed362bf5be9acfea8db1f16f6fc9c Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 19:12:16 2023 -0500 Superior clipboard manipulation Won't work on non-https connections, but actually works... commit 08f647cd01566e9000d71f677df0d96411ed4cd4 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:50:01 2023 -0500 Utility for copying plates as image commit 3456be2e9a07f63bf5d62ca685fe692303875888 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 17:46:38 2023 -0500 Change wording in options menu Father suggests that this wording is more clear to the end user. I agree! commit 4c79cc0b4dd5402a798ce8d7ac69599c03cf49d9 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:20:00 2023 -0500 Set default plate format to 96 well commit 056688c4ec690a384f57c194314cb924253770f5 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:12:00 2023 -0500 Implement in_transfer hashes toggle in plates commit 4937d4ad283b90629a80a213595a873d1a3a2615 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:11:00 2023 -0500 Preferences menu and toggle for in_transfer hashes commit 0101846b52393d1a050c2c7672274b4589c5c993 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:10:00 2023 -0500 Add preferences struct to main state commit ec37887c2f7e834ed7456625a9ec4c4cc7fea08f Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:05:00 2023 -0500 Squashed commit of the following: commit 5e1137c46050d6d1d10fb1cbf842d5efd455f926 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:03:00 2023 -0500 Fix: indexing error w.r.t. logarithm argument commit 535b14a5867b15dea0e193c94829a0b99a29605c Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:02:00 2023 -0500 Space colors evenly, consistently, etc Colors should now: - Not change if new transfers are added - Be evenly spaced throughout the palette - Be persistent across refreshes commit 6e08f479551315e072ec40853290d699220c9ba8 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:01:00 2023 -0500 Add palette function for ordered ids Given an id and a list of sorted ids, yields a color commit 88e838e102602f4d89ab65d8245a820158374959 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:00:00 2023 -0500 Switch to v7 UUIDs from v4 v7 UUIDs are timestamp based and thus we can establish a useful total ordering over them; will base colors on this commit 85d4b30d4795636add23a6a2c47b2068e24dbb74 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 21:18:10 2023 -0400 Update README.md Updated info about import/export, including the new Import Transfer from CSV feature. commit 11a561c1d447e1376e58f970f74d0778e8ed1722 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 20:32:51 2023 -0400 Add text to button commit 562dc2adf60b8569da579b1bb637cea344a7a596 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 20:32:40 2023 -0400 Change to make colors more evenly distributed commit 6b09aad289b83576bdf67882ee3f30b7f1d23619 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 19:27:02 2023 -0400 Implementation 1 commit a9e5f05fd9c0ebcbbb1c3cc86af8f30c92f373c5 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 17:18:45 2023 -0400 Hide parts of transfer menu when Custom transfer selected commit db345bfbb585c826c6f97424c5ee61337c4ffbfd Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 17:18:08 2023 -0400 delete weird whitespace from Cargo.toml commit edcc3528aab3b17aedaf7b3424ece82ad09d591a Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 16:41:58 2023 -0400 First implementation of custom region type commit 9a3a10c8b43e51471f74f79dfbef66b3f69ea0f5 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 16:21:30 2023 -0400 Transfer region no longer copy
2023-12-30 01:39:00 +00:00
#[derive(PartialEq, Clone, Copy, Serialize, Deserialize)]
pub struct Preferences {
pub in_transfer_hashes: bool,
}
impl Default for Preferences {
fn default() -> Self {
Self { in_transfer_hashes: true }
}
}
2023-05-23 00:48:03 +00:00
#[derive(Default, PartialEq, Clone, Serialize, Deserialize)]
2023-06-07 21:08:43 +00:00
#[non_exhaustive]
pub struct MainState {
pub source_plates: Vec<PlateInstance>,
pub destination_plates: Vec<PlateInstance>,
pub transfers: Vec<Transfer>,
pub selected_source_plate: Uuid,
pub selected_dest_plate: Uuid,
pub selected_transfer: Uuid,
Merge from import_from_csv feature branch Of course, there were other features that got tacked on... Squashed commit of the following: commit 3ee3bd2dab3ed362bf5be9acfea8db1f16f6fc9c Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 19:12:16 2023 -0500 Superior clipboard manipulation Won't work on non-https connections, but actually works... commit 08f647cd01566e9000d71f677df0d96411ed4cd4 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:50:01 2023 -0500 Utility for copying plates as image commit 3456be2e9a07f63bf5d62ca685fe692303875888 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 17:46:38 2023 -0500 Change wording in options menu Father suggests that this wording is more clear to the end user. I agree! commit 4c79cc0b4dd5402a798ce8d7ac69599c03cf49d9 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:20:00 2023 -0500 Set default plate format to 96 well commit 056688c4ec690a384f57c194314cb924253770f5 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:12:00 2023 -0500 Implement in_transfer hashes toggle in plates commit 4937d4ad283b90629a80a213595a873d1a3a2615 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:11:00 2023 -0500 Preferences menu and toggle for in_transfer hashes commit 0101846b52393d1a050c2c7672274b4589c5c993 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:10:00 2023 -0500 Add preferences struct to main state commit ec37887c2f7e834ed7456625a9ec4c4cc7fea08f Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:05:00 2023 -0500 Squashed commit of the following: commit 5e1137c46050d6d1d10fb1cbf842d5efd455f926 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:03:00 2023 -0500 Fix: indexing error w.r.t. logarithm argument commit 535b14a5867b15dea0e193c94829a0b99a29605c Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:02:00 2023 -0500 Space colors evenly, consistently, etc Colors should now: - Not change if new transfers are added - Be evenly spaced throughout the palette - Be persistent across refreshes commit 6e08f479551315e072ec40853290d699220c9ba8 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:01:00 2023 -0500 Add palette function for ordered ids Given an id and a list of sorted ids, yields a color commit 88e838e102602f4d89ab65d8245a820158374959 Author: Emilia <contact@emiliaallison.com> Date: Fri Dec 29 18:00:00 2023 -0500 Switch to v7 UUIDs from v4 v7 UUIDs are timestamp based and thus we can establish a useful total ordering over them; will base colors on this commit 85d4b30d4795636add23a6a2c47b2068e24dbb74 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 21:18:10 2023 -0400 Update README.md Updated info about import/export, including the new Import Transfer from CSV feature. commit 11a561c1d447e1376e58f970f74d0778e8ed1722 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 20:32:51 2023 -0400 Add text to button commit 562dc2adf60b8569da579b1bb637cea344a7a596 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 20:32:40 2023 -0400 Change to make colors more evenly distributed commit 6b09aad289b83576bdf67882ee3f30b7f1d23619 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 19:27:02 2023 -0400 Implementation 1 commit a9e5f05fd9c0ebcbbb1c3cc86af8f30c92f373c5 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 17:18:45 2023 -0400 Hide parts of transfer menu when Custom transfer selected commit db345bfbb585c826c6f97424c5ee61337c4ffbfd Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 17:18:08 2023 -0400 delete weird whitespace from Cargo.toml commit edcc3528aab3b17aedaf7b3424ece82ad09d591a Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 16:41:58 2023 -0400 First implementation of custom region type commit 9a3a10c8b43e51471f74f79dfbef66b3f69ea0f5 Author: Emilia <contact@emiliaallison.com> Date: Tue Oct 24 16:21:30 2023 -0400 Transfer region no longer copy
2023-12-30 01:39:00 +00:00
#[serde(default)]
pub preferences: Preferences,
}
impl Store for MainState {
fn new() -> Self {
2023-05-23 00:48:03 +00:00
init_listener(storage::StorageListener::<Self>::new(storage::Area::Local));
storage::load(storage::Area::Local)
.expect("Unable to load state")
.unwrap_or_default()
}
fn should_notify(&self, old: &Self) -> bool {
self != old
}
}
impl MainState {
2023-06-13 21:12:25 +00:00
fn purge_transfers(&mut self) {
// Removes any transfers for which the associated plates are gone
2023-06-08 15:57:03 +00:00
self.transfers.retain(|tr| {
self.source_plates
.iter()
.any(|spi| spi.get_uuid() == tr.source_id)
&& self
.destination_plates
2023-06-01 17:04:03 +00:00
.iter()
2023-06-08 15:57:03 +00:00
.any(|dpi| dpi.get_uuid() == tr.dest_id)
});
}
pub fn add_source_plate(&mut self, plate: PlateInstance) {
assert!(plate.plate.plate_type == PlateType::Source);
self.source_plates.push(plate);
}
pub fn add_dest_plate(&mut self, plate: PlateInstance) {
assert!(plate.plate.plate_type == PlateType::Destination);
self.destination_plates.push(plate);
}
2023-05-24 01:08:32 +00:00
pub fn del_plate(&mut self, id: Uuid) {
2023-06-01 17:04:03 +00:00
if let Some(index) = self
.source_plates
.iter()
.position(|spi| spi.get_uuid() == id)
{
2023-05-24 01:08:32 +00:00
self.source_plates.swap_remove(index);
2023-06-13 21:12:25 +00:00
self.purge_transfers();
2023-05-24 01:08:32 +00:00
}
2023-06-01 17:04:03 +00:00
if let Some(index) = self
.destination_plates
.iter()
.position(|dpi| dpi.get_uuid() == id)
{
2023-05-24 01:08:32 +00:00
self.destination_plates.swap_remove(index);
2023-06-13 21:12:25 +00:00
self.purge_transfers();
2023-05-24 01:08:32 +00:00
}
}
2023-06-06 01:33:23 +00:00
pub fn rename_plate(&mut self, id: Uuid, new_name: &str) {
if let Some(index) = self
.source_plates
.iter()
.position(|spi| spi.get_uuid() == id)
{
self.source_plates[index].change_name(new_name.to_string());
}
if let Some(index) = self
.destination_plates
.iter()
.position(|dpi| dpi.get_uuid() == id)
{
self.destination_plates[index].change_name(new_name.to_string());
}
}
}