Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions crates/procnote-core/src/event/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ mod tests {
Event::StepStarted {
at: now,
execution_id: id,
step_heading: "Preconditions".to_string(),
step_id: "step-0".to_string(),
},
Event::CheckboxToggled {
at: now,
execution_id: id,
step_heading: "Preconditions".to_string(),
text: "Chamber pressure < 1e-5 Pa".to_string(),
step_id: "step-0".to_string(),
checkbox_id: "step-0/cb-0".to_string(),
checked: true,
},
Event::StepCompleted {
at: now,
execution_id: id,
step_heading: "Preconditions".to_string(),
step_id: "step-0".to_string(),
},
Event::ExecutionCompleted {
at: now,
Expand Down Expand Up @@ -210,54 +210,55 @@ mod tests {
Event::StepAdded {
at: now,
execution_id: id,
step_id: "dyn-step-1".to_string(),
heading: "New Step".to_string(),
content: vec![StepContent::Prose {
text: "Added during execution".to_string(),
}],
after_step: Some("Preconditions".to_string()),
after_step_id: Some("step-0".to_string()),
},
Event::StepStarted {
at: now,
execution_id: id,
step_heading: "Step 1".to_string(),
step_id: "step-0".to_string(),
},
Event::StepCompleted {
at: now,
execution_id: id,
step_heading: "Step 1".to_string(),
step_id: "step-0".to_string(),
},
Event::StepSkipped {
at: now,
execution_id: id,
step_heading: "Step 2".to_string(),
step_id: "step-1".to_string(),
reason: "Not applicable".to_string(),
},
Event::CheckboxToggled {
at: now,
execution_id: id,
step_heading: "Step 1".to_string(),
text: "Check item".to_string(),
step_id: "step-0".to_string(),
checkbox_id: "step-0/cb-0".to_string(),
checked: true,
},
Event::InputRecorded {
at: now,
execution_id: id,
step_heading: "Step 1".to_string(),
label: "Current".to_string(),
step_id: "step-0".to_string(),
input_id: "current-draw".to_string(),
value: "120".to_string(),
unit: Some("mA".to_string()),
},
Event::NoteAdded {
at: now,
execution_id: id,
text: "Observation noted".to_string(),
step_heading: Some("Step 1".to_string()),
step_id: Some("step-0".to_string()),
},
Event::AttachmentAdded {
at: now,
execution_id: id,
step_heading: "Step 1".to_string(),
label: "Log file".to_string(),
step_id: "step-0".to_string(),
input_id: "log-file".to_string(),
filename: "photo.jpg".to_string(),
path: "attachments/photo.jpg".to_string(),
content_type: "image/jpeg".to_string(),
Expand Down
68 changes: 30 additions & 38 deletions crates/procnote-core/src/event/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,44 +47,47 @@ pub enum Event {
StepAdded {
at: DateTime<Utc>,
execution_id: ExecutionId,
/// Stable element ID for this step.
step_id: String,
heading: String,
/// Ordered content items from the template (prose, checkboxes, input blocks).
/// Checkbox and input items carry their own IDs.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
content: Vec<StepContent>,
/// Insert after this step heading. `None` means append at end.
/// Insert after this step ID. `None` means append at end.
#[serde(skip_serializing_if = "Option::is_none")]
after_step: Option<String>,
after_step_id: Option<String>,
},
StepStarted {
at: DateTime<Utc>,
execution_id: ExecutionId,
step_heading: String,
step_id: String,
},
StepCompleted {
at: DateTime<Utc>,
execution_id: ExecutionId,
step_heading: String,
step_id: String,
},
StepSkipped {
at: DateTime<Utc>,
execution_id: ExecutionId,
step_heading: String,
step_id: String,
reason: String,
},

// -- Data --
CheckboxToggled {
at: DateTime<Utc>,
execution_id: ExecutionId,
step_heading: String,
text: String,
step_id: String,
checkbox_id: String,
checked: bool,
},
InputRecorded {
at: DateTime<Utc>,
execution_id: ExecutionId,
step_heading: String,
label: String,
step_id: String,
input_id: String,
value: String,
#[serde(skip_serializing_if = "Option::is_none")]
unit: Option<String>,
Expand All @@ -94,15 +97,15 @@ pub enum Event {
execution_id: ExecutionId,
text: String,
#[serde(skip_serializing_if = "Option::is_none")]
step_heading: Option<String>,
step_id: Option<String>,
},

// -- Attachment --
AttachmentAdded {
at: DateTime<Utc>,
execution_id: ExecutionId,
step_heading: String,
label: String,
step_id: String,
input_id: String,
filename: String,
path: String,
content_type: String,
Expand Down Expand Up @@ -185,42 +188,34 @@ impl Event {
format!("Aborted execution: {reason}")
}
Self::StepAdded { heading, .. } => format!("Added step: {heading}"),
Self::StepStarted { step_heading, .. } => {
format!("Started step: {step_heading}")
Self::StepStarted { step_id, .. } => {
format!("Started step: {step_id}")
}
Self::StepCompleted { step_heading, .. } => {
format!("Completed step: {step_heading}")
Self::StepCompleted { step_id, .. } => {
format!("Completed step: {step_id}")
}
Self::StepSkipped {
step_heading,
reason,
..
step_id, reason, ..
} => {
format!("Skipped step: {step_heading} ({reason})")
format!("Skipped step: {step_id} ({reason})")
}
Self::CheckboxToggled {
step_heading,
text,
checkbox_id,
checked,
..
} => {
let verb = if *checked { "Checked" } else { "Unchecked" };
format!("{verb} checkbox '{text}' in {step_heading}")
format!("{verb} checkbox {checkbox_id}")
}
Self::InputRecorded {
step_heading,
label,
value,
..
input_id, value, ..
} => {
format!("Recorded {label} = {value} in {step_heading}")
format!("Recorded {input_id} = {value}")
}
Self::NoteAdded {
text, step_heading, ..
} => {
let scope = step_heading
Self::NoteAdded { text, step_id, .. } => {
let scope = step_id
.as_ref()
.map(|h| format!(" to {h}"))
.map(|id| format!(" to {id}"))
.unwrap_or_default();
let truncated = if text.len() > 50 {
format!("{}...", &text[..50])
Expand All @@ -230,12 +225,9 @@ impl Event {
format!("Added note{scope}: {truncated}")
}
Self::AttachmentAdded {
step_heading,
label,
filename,
..
input_id, filename, ..
} => {
format!("Recorded {label} = {filename} in {step_heading}")
format!("Recorded {input_id} = {filename}")
}
Self::ExecutionRenamed { name, .. } => {
format!("Renamed execution to: {name}")
Expand Down
Loading