Skip to content

Commit

Permalink
Merge pull request #350 from djmitche/issue78
Browse files Browse the repository at this point in the history
Treat priority as an arbitrary string
  • Loading branch information
djmitche authored Apr 6, 2022
2 parents 0dd2d9c + 1b586a4 commit 6f8c734
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 62 deletions.
6 changes: 3 additions & 3 deletions cli/src/invocation/cmd/import_tdb2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod test {
use pretty_assertions::assert_eq;
use std::convert::TryInto;
use taskchampion::chrono::{TimeZone, Utc};
use taskchampion::{Priority, Status};
use taskchampion::Status;
use tempfile::TempDir;

#[test]
Expand All @@ -113,7 +113,7 @@ mod test {
.unwrap();
assert_eq!(task.get_description(), "snake 🐍");
assert_eq!(task.get_status(), Status::Pending);
assert_eq!(task.get_priority(), Priority::M);
assert_eq!(task.get_priority(), "M");
assert_eq!(task.get_wait(), None);
assert_eq!(
task.get_modified(),
Expand All @@ -128,7 +128,7 @@ mod test {
.unwrap();
assert_eq!(task.get_description(), "[TEST] foo");
assert_eq!(task.get_status(), Status::Completed);
assert_eq!(task.get_priority(), Priority::M);
assert_eq!(task.get_priority(), "M".to_string());
assert_eq!(task.get_wait(), None);
assert_eq!(
task.get_modified(),
Expand Down
4 changes: 2 additions & 2 deletions cli/src/invocation/cmd/import_tw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mod test {
use serde_json::json;
use std::convert::TryInto;
use taskchampion::chrono::{TimeZone, Utc};
use taskchampion::{Priority, Status};
use taskchampion::Status;

#[test]
fn stringify_string() {
Expand Down Expand Up @@ -235,7 +235,7 @@ mod test {
.unwrap();
assert_eq!(task.get_description(), "repair window");
assert_eq!(task.get_status(), Status::Completed);
assert_eq!(task.get_priority(), Priority::M);
assert_eq!(task.get_priority(), "M".to_string());
assert_eq!(
task.get_wait(),
Some(Utc.ymd(2021, 12, 25).and_hms(00, 15, 23))
Expand Down
2 changes: 1 addition & 1 deletion taskchampion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub use errors::Error;
pub use replica::Replica;
pub use server::{Server, ServerConfig};
pub use storage::StorageConfig;
pub use task::{Annotation, Priority, Status, Tag, Task, TaskMut};
pub use task::{Annotation, Status, Tag, Task, TaskMut};
pub use workingset::WorkingSet;

/// Re-exported type from the `uuid` crate, for ease of compatibility for consumers of this crate.
Expand Down
2 changes: 0 additions & 2 deletions taskchampion/src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
use chrono::prelude::*;

mod annotation;
mod priority;
mod status;
mod tag;
mod task;

pub use annotation::Annotation;
pub use priority::Priority;
pub use status::Status;
pub use tag::Tag;
pub use task::{Task, TaskMut};
Expand Down
49 changes: 0 additions & 49 deletions taskchampion/src/task/priority.rs

This file was deleted.

30 changes: 25 additions & 5 deletions taskchampion/src/task/task.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::tag::{SyntheticTag, TagInner};
use super::{Annotation, Priority, Status, Tag, Timestamp};
use super::{Annotation, Status, Tag, Timestamp};
use crate::depmap::DependencyMap;
use crate::replica::Replica;
use crate::storage::TaskMap;
Expand Down Expand Up @@ -66,6 +66,7 @@ enum Prop {
Modified,
Start,
Status,
Priority,
Wait,
End,
Entry,
Expand Down Expand Up @@ -138,11 +139,11 @@ impl Task {
self.get_timestamp(Prop::Entry.as_ref())
}

pub fn get_priority(&self) -> Priority {
pub fn get_priority(&self) -> &str {
self.taskmap
.get(Prop::Status.as_ref())
.map(|s| Priority::from_taskmap(s))
.unwrap_or(Priority::M)
.get(Prop::Priority.as_ref())
.map(|s| s.as_ref())
.unwrap_or("")
}

/// Get the wait time. If this value is set, it will be returned, even
Expand Down Expand Up @@ -347,6 +348,10 @@ impl<'r> TaskMut<'r> {
self.set_string(Prop::Description.as_ref(), Some(description))
}

pub fn set_priority(&mut self, priority: String) -> anyhow::Result<()> {
self.set_string(Prop::Priority.as_ref(), Some(priority))
}

pub fn set_entry(&mut self, entry: Option<DateTime<Utc>>) -> anyhow::Result<()> {
self.set_timestamp(Prop::Entry.as_ref(), entry)
}
Expand Down Expand Up @@ -725,6 +730,12 @@ mod test {
);
}

#[test]
fn test_get_priority_default() {
let task = Task::new(Uuid::new_v4(), TaskMap::new(), dm());
assert_eq!(task.get_priority(), "");
}

#[test]
fn test_get_annotations() {
let task = Task::new(
Expand Down Expand Up @@ -810,6 +821,15 @@ mod test {
});
}

#[test]
fn test_set_get_priority() {
with_mut_task(|mut task| {
assert_eq!(task.get_priority(), "");
task.set_priority("H".into()).unwrap();
assert_eq!(task.get_priority(), "H");
});
}

#[test]
fn test_set_status_pending() {
with_mut_task(|mut task| {
Expand Down

0 comments on commit 6f8c734

Please sign in to comment.