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>,
}Expand description
Represents a single task or work item in the productivity tracking system.
The Task struct encapsulates all information about a work item including its identification, description, progress status, and associated metadata. Tasks serve as the fundamental unit of work organization within kasl.
§Field Descriptions
§Identification Fields
id: Database primary key for persistence and relationshipstask_id: Reference ID for linking to external systems or parent taskstimestamp: Creation/modification time for audit trails
§Content Fields
name: Brief, descriptive title for the taskcomment: Detailed description, notes, or additional contextcompleteness: Progress percentage (0-100) indicating work completion
§Configuration Fields
excluded_from_search: Flag to hide tasks from general searchestags: Collection of categorization labels for organization
§Usage Patterns
§New Task Creation
use kasl::libs::task::Task;
let task = Task::new(
"Code review for PR #123",
"Review authentication changes and security implications",
Some(0) // Just started
);§Task Updates
use kasl::libs::task::Task;
let existing_task = Task::new("Existing task", "Details", Some(50));
let mut task = existing_task;
task.completeness = Some(75); // 75% complete
task.comment = "Almost finished, testing remaining".to_string();§External Integration
use kasl::libs::task::Task;
// Simulated Jira issue data used to populate a task.
let jira_issue_id = 42;
struct JiraIssue {
summary: String,
description: Option<String>,
}
let jira_issue = JiraIssue {
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: Some(jira_issue_id),
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![],
};Fields§
§id: Option<i32>Database primary key for task identification and relationships.
This field contains the unique identifier assigned by the database when the task is first saved. Itâs used for:
- Database queries and updates
- Foreign key relationships (tags, time tracking)
- Cross-referencing with other application data
Values:
Some(id): Task exists in database with assigned IDNone: New task not yet saved to database
task_id: Option<i32>Reference identifier for external system integration or task linking.
This field provides a way to link tasks to external systems or create hierarchical relationships between tasks. Common uses include:
- Jira issue numbers for imported tasks
- GitLab merge request IDs for code review tasks
- Parent task IDs for subtask relationships
- External project management system references
Values:
Some(id): Task is linked to external system or parent taskNone: Standalone task with no external references
timestamp: Option<String>ISO 8601 timestamp string indicating task creation or last modification.
This field provides audit trail information for task management. The timestamp is automatically managed by the database layer and is primarily used for:
- Sorting tasks by creation or modification time
- Audit trails and change tracking
- Time-based filtering and reporting
- Synchronization with external systems
Format: âYYYY-MM-DD HH:MM:SSâ in local timezone Example: â2025-01-15 14:30:45â
name: StringBrief, descriptive title summarizing the taskâs purpose or objective.
The task name should be concise yet descriptive enough to understand the work item at a glance. It appears in task lists, reports, and notifications throughout the application.
Guidelines:
- Keep under 100 characters for display compatibility
- Use action-oriented language (âImplementâ, âReviewâ, âFixâ)
- Include key context (âFix login bug in mobile appâ)
- Avoid technical jargon when possible
Examples:
- âImplement OAuth2 authenticationâ
- âReview security audit findingsâ
- âUpdate API documentation for v2.0â
comment: StringDetailed description, notes, or additional context for the task.
The comment field provides space for detailed information that doesnât fit in the task name. This might include:
- Technical requirements and specifications
- Links to related resources or documentation
- Progress notes and status updates
- Dependencies and prerequisites
- Testing criteria and acceptance conditions
Content Guidelines:
- Use clear, structured formatting when helpful
- Include links to relevant resources
- Update with progress notes and findings
- Keep information current and relevant
completeness: Option<i32>Completion percentage indicating task progress from 0% to 100%.
This field tracks the taskâs progress through its lifecycle, providing quantitative measurement of work completion. The percentage is used for:
- Progress reporting and analytics
- Filtering incomplete vs. complete tasks
- Productivity calculations and trends
- Project status tracking and reporting
Values:
Some(0): Task not startedSome(1-99): Task in progressSome(100): Task completedNone: Progress not tracked or unknown
Default: 100% for tasks imported from external systems
excluded_from_search: Option<bool>Flag indicating whether task should be hidden from general searches.
This field allows tasks to be excluded from default search results while remaining accessible through direct queries. Useful for:
- Administrative or system-generated tasks
- Deprecated or obsolete tasks that shouldnât appear in normal workflow
- Sensitive tasks that require explicit access
- Archived tasks that should remain searchable but not prominent
Values:
Some(true): Task excluded from general searchesSome(false)orNone: Task included in normal search results
Collection of categorization tags associated with this task.
Tags provide a flexible labeling system for task organization and filtering. They enable:
- Project-based organization (âfrontendâ, âbackendâ, âmobileâ)
- Priority classification (âurgentâ, âlow-priorityâ, ânice-to-haveâ)
- Status indicators (âblockedâ, âwaiting-reviewâ, âapprovedâ)
- Skill-based categorization (âjavascriptâ, âdatabaseâ, âui-designâ)
Management:
- Tags are created automatically when first used
- Multiple tags can be associated with a single task
- Tag associations are maintained in separate database table
- Tags can be deleted if no longer associated with any tasks
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 a new task with the specified name, comment, and completion status.
This constructor initializes a new task with the provided information and sets appropriate defaults for other fields. The task is not automatically saved to the database - use the database layer for persistence.
§Default Values
New tasks are initialized with:
id: None (assigned when saved to database)task_id: None (no external reference)timestamp: None (managed by database)excluded_from_search: None (included in searches)tags: Empty vector (no initial categorization)
§Parameter Guidelines
§Task Name
- Should be concise but descriptive
- Use action-oriented language
- Include key context for clarity
§Comment
- Provide detailed context and requirements
- Include links to related resources
- Can be updated as work progresses
§Completeness
- Use
Some(0)for new tasks that havenât started - Use
Some(100)for already completed imported tasks - Use
Noneif progress tracking isnât needed
§Arguments
name- Brief, descriptive task titlecomment- Detailed description or notescompleteness- Optional completion percentage (0-100)
§Returns
A new Task instance ready for use or database persistence.
§Examples
use kasl::libs::task::Task;
// Create a new task that's just starting
let new_task = Task::new(
"Implement user registration",
"Add email verification and password validation",
Some(0)
);
// Create a completed task (e.g., imported from external system)
let completed_task = Task::new(
"Fix login redirect bug",
"Resolved issue with OAuth callback URL handling",
Some(100)
);
// Create a task without progress tracking
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)
Updates task fields from another task while preserving identity fields.
This method provides a convenient way to update task content while maintaining database identity and relationships. Itâs particularly useful for implementing task editing workflows where the user modifies task details but the taskâs core identity remains unchanged.
§Preserved Fields
The following fields are not updated to maintain task identity:
id: Database primary key remains unchangedtask_id: External reference remains unchangedtimestamp: Will be updated by database on saveexcluded_from_search: Search visibility remains unchangedtags: Tag associations require separate management
§Updated Fields
The following fields are copied from the source task:
name: Task title is updatedcomment: Description and notes are updatedcompleteness: Progress percentage is updated
§Use Cases
§Task Editing Workflow
use kasl::libs::task::Task;
use kasl::db::tasks::Tasks;
let mut tasks_db = Tasks::new()?;
// Load existing task from database
let mut existing_task = tasks_db.get_by_id(42)?.expect("task exists");
// Create updated version with user modifications
let updated_task = Task::new(
"Updated task name",
"Updated description with new requirements",
Some(75)
);
// Apply updates while preserving identity
existing_task.update_from(&updated_task);
// Save to database
tasks_db.update(&existing_task)?;§Bulk Task Updates
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)?;
}
}§Arguments
other- Source task containing the updated field values
§Examples
use kasl::libs::task::Task;
let mut original_task = Task::new(
"Original task",
"Original description",
Some(25)
);
// Simulate database assignment
original_task.id = Some(42);
let updated_task = Task::new(
"Updated task name",
"Updated description with more details",
Some(75)
);
// Apply updates while preserving ID
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