Skip to content

Commit

Permalink
handle incompatible template/key pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
o-tho committed Dec 7, 2024
1 parent 87cea53 commit d92b1c7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ pub fn generate_reports_for_image_container(
) -> Result<String, Box<dyn std::error::Error>> {
use itertools::Itertools;
use rayon::prelude::*;
use template::are_compatible;

if !are_compatible(template, key) {
return Err(Box::new(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
"Template and key are incompatible",
)));
}

let iterator = container.to_iter();
let mut all_records = Vec::new();
let chunksize = 100;
Expand Down
18 changes: 16 additions & 2 deletions src/webapp/generate_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::image_container::{ImageContainer, PdfContainer, SingleImageContainer,
use crate::image_helpers::rgb_to_egui_color_image;
use crate::report::ImageReport;
use crate::scan::Scan;
use crate::template::{ExamKey, Template};
use crate::template::{are_compatible, ExamKey, Template};
use crate::template_scan::TemplateScan;
use crate::webapp::utils::{download_button, upload_button, FileType};
use crate::webapp::webapp::StateView;
Expand Down Expand Up @@ -179,8 +179,18 @@ impl GenerateReport {
FileType::Key,
self.data_channel.0.clone(),
);
if self.key.is_some() {
if let Some(key) = &self.key {
ui.label("👍");
if let Some(template) = &self.template {
if !are_compatible(template, key) {
*self.status.borrow_mut() =
Some("Key and Template don't fit together 😢".to_string());
} else if let Some(current_msg) = &*self.status.borrow() {
if current_msg == "Key and Template don't fit together 😢" {
*self.status.borrow_mut() = None;
}
}
}
}
});
ui.label("Open an exam key (.json).");
Expand All @@ -204,6 +214,10 @@ impl GenerateReport {
if self.template.is_some()
&& self.key.is_some()
&& self.raw_container_data.is_some()
&& are_compatible(
self.template.as_ref().unwrap(),
self.key.as_ref().unwrap(),
)
{
if ui.button("🚀 Do the thing!").clicked() {
log::info!("Zhu Li! Do the thing!");
Expand Down

0 comments on commit d92b1c7

Please sign in to comment.