pub struct Task {
pub id: Option<i32>,
pub task_id: Option<i32>,
pub timestamp: Option<String>,
pub name: String,
pub comment: String,
pub completeness: Option<i32>,
pub excluded_from_search: Option<bool>,
pub tags: Vec<Tag>,
pub jira_key: Option<String>,
}Expand description
A single work item.
task_id links to an external system (a Jira issue id, a GitLab MR);
timestamp is managed by the database layer.
use kasl::libs::task::Task;
let task = Task::new(
"Code review for PR #123",
"Review authentication changes and security implications",
Some(0) // Just started
);use kasl::libs::task::Task;
let existing_task = Task::new("Existing task", "Details", Some(50));
let mut task = existing_task;
task.completeness = Some(75);
task.comment = "Almost finished, testing remaining".to_string();Populating a task from an external issue:
use kasl::libs::task::Task;
// Simulated Jira issue data used to populate a task.
struct JiraIssue {
key: String,
summary: String,
description: Option<String>,
}
let jira_issue = JiraIssue {
key: "PROJ-412".to_string(),
summary: "Fix login bug".to_string(),
description: Some("Users cannot log in with SSO".to_string()),
};
let jira_task = Task {
id: None, // Will be assigned by database
task_id: None, // Set to the task's own id once saved
timestamp: None,
name: jira_issue.summary,
comment: jira_issue.description.unwrap_or_default(),
completeness: Some(100), // Imported completed issues
excluded_from_search: None,
tags: vec![],
jira_key: Some(jira_issue.key),
};Fields§
§id: Option<i32>Database primary key; None until the task is saved.
task_id: Option<i32>Groups a task with its own history across days.
Points at the id of the first task in the chain, so task find can
offer yesterday’s unfinished work and see today’s progress as the same
item. Not an external reference - the Jira issue a task came from is
Task::jira_key.
timestamp: Option<String>"YYYY-MM-DD HH:MM:SS" in local time, set by the database layer.
name: StringTask title.
comment: StringFree-form notes.
completeness: Option<i32>Progress 0-100; imported completed issues default to 100.
excluded_from_search: Option<bool>Hidden from task discovery when true.
Tags, maintained through the task_tags relationship table.
jira_key: Option<String>Jira issue this task was taken from, e.g. PROJ-412.
Set by kasl inbox take; None for tasks that did not come from the
inbox. The key also opens the task’s name, but only this field survives
a rename.
Implementations§
Source§impl Task
impl Task
Sourcepub fn new(name: &str, comment: &str, completeness: Option<i32>) -> Self
pub fn new(name: &str, comment: &str, completeness: Option<i32>) -> Self
Creates an unsaved task; whitespace in name and comment is collapsed.
use kasl::libs::task::Task;
let new_task = Task::new(
"Implement user registration",
"Add email verification and password validation",
Some(0)
);
let completed_task = Task::new(
"Fix login redirect bug",
"Resolved issue with OAuth callback URL handling",
Some(100)
);
let planning_task = Task::new(
"Research authentication libraries",
"Evaluate OAuth2 libraries for Node.js backend",
None
);Sourcepub fn update_from(&mut self, other: &Task)
pub fn update_from(&mut self, other: &Task)
Copies name, comment and completeness from other, keeping
identity fields (id, task_id, timestamp, search flag, tags,
jira_key).
use kasl::libs::task::Task;
use kasl::db::tasks::Tasks;
let mut tasks_db = Tasks::new()?;
let mut existing_task = tasks_db.get_by_id(42)?.expect("task exists");
let updated_task = Task::new(
"Updated task name",
"Updated description with new requirements",
Some(75)
);
existing_task.update_from(&updated_task);
tasks_db.update(&existing_task)?;use kasl::libs::task::Task;
use kasl::db::tasks::Tasks;
let mut tasks_db = Tasks::new()?;
let tasks_to_update: Vec<Task> = vec![];
let get_update_template = |_task: &Task| -> Option<Task> { None };
for mut task in tasks_to_update {
if let Some(template) = get_update_template(&task) {
task.update_from(&template);
tasks_db.update(&task)?;
}
}use kasl::libs::task::Task;
let mut original_task = Task::new(
"Original task",
"Original description",
Some(25)
);
original_task.id = Some(42);
let updated_task = Task::new(
"Updated task name",
"Updated description with more details",
Some(75)
);
original_task.update_from(&updated_task);
assert_eq!(original_task.id, Some(42)); // ID preserved
assert_eq!(original_task.name, "Updated task name"); // Content updated
assert_eq!(original_task.completeness, Some(75)); // Progress updated