summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDheepak Krishnamurthy <me@kdheepak.com>2020-10-25 09:25:25 -0600
committerGitHub <noreply@github.com>2020-10-25 09:25:25 -0600
commitbc70cae87ee3b48c720cf446c7f70374b78692e7 (patch)
tree1ca7161e6664d20e98e6488404823720bba1d915
parent2953cf02b3c56b164a44e95fac5aae6f38954620 (diff)
parent06777f6aa1ea90f9e7f0d335f804985f54d08e86 (diff)
Merge pull request #85 from kdheepak/add-urgency-to-task
-rw-r--r--examples/create_task.rs1
-rw-r--r--src/lib.rs1
-rw-r--r--src/task.rs45
-rw-r--r--src/urgency.rs10
4 files changed, 55 insertions, 2 deletions
diff --git a/examples/create_task.rs b/examples/create_task.rs
index c79d417..91082cb 100644
--- a/examples/create_task.rs
+++ b/examples/create_task.rs
@@ -36,6 +36,7 @@ fn main() {
None,
None,
None,
+ None,
UDA::default(),
);
println!("[{}]", to_string(&t).unwrap());
diff --git a/src/lib.rs b/src/lib.rs
index dfe1aad..5bacf06 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -70,4 +70,5 @@ pub mod status;
pub mod tag;
pub mod task;
pub mod uda;
+pub mod urgency;
pub mod tw;
diff --git a/src/task.rs b/src/task.rs
index 6e8459b..89d35d9 100644
--- a/src/task.rs
+++ b/src/task.rs
@@ -23,6 +23,7 @@ use tag::Tag;
use date::Date;
use annotation::Annotation;
use uda::{UDA, UDAName, UDAValue};
+use urgency::Urgency;
/// Task type
///
@@ -107,6 +108,9 @@ pub struct Task {
/// This hides the task until the wait date
#[builder(default)]
wait: Option<Date>,
+ /// This contains the urgency of the task
+ #[builder(default)]
+ urgency: Option<Urgency>,
/// A map of user defined attributes
#[builder(default)]
@@ -143,6 +147,7 @@ impl Task {
tags: Option<Vec<Tag>>,
until: Option<Date>,
wait: Option<Date>,
+ urgency: Option<Urgency>,
uda: UDA,
) -> Task {
Task {
@@ -168,6 +173,7 @@ impl Task {
tags: tags,
until: until,
wait: wait,
+ urgency: urgency,
uda: uda,
}
}
@@ -493,6 +499,24 @@ impl Task {
self.until = new.map(Into::into);
}
+ /// Get the urgency of the task
+ pub fn urgency(&self) -> Option<&Urgency> {
+ self.urgency.as_ref()
+ }
+
+ /// Get the urgency of the task
+ pub fn urgency_mut(&mut self) -> Option<&mut Urgency> {
+ self.urgency.as_mut()
+ }
+
+ /// Set the urgency of the task
+ pub fn set_urgency<T>(&mut self, new: Option<T>)
+ where
+ T: Into<Urgency>,
+ {
+ self.urgency = new.map(Into::into);
+ }
+
/// Get the wait date of the task
pub fn wait(&self) -> Option<&Date> {
self.wait.as_ref()
@@ -580,6 +604,9 @@ impl Serialize for Task {
self.wait.as_ref().map(
|ref v| state.serialize_entry("wait", v),
);
+ self.urgency.as_ref().map(
+ |ref v| state.serialize_entry("urgency", v),
+ );
for (key, value) in self.uda().iter() {
state.serialize_entry(key, value)?;
@@ -617,6 +644,7 @@ impl<'de> Deserialize<'de> for Task {
"tags",
"until",
"wait",
+ "urgency",
"uda",
];
deserializer.deserialize_struct("Task", FIELDS, TaskDeserializeVisitor)
@@ -660,6 +688,7 @@ impl<'de> Visitor<'de> for TaskDeserializeVisitor {
let mut tags = None;
let mut until = None;
let mut wait = None;
+ let mut urgency = None;
let mut uda = UDA::default();
loop {
@@ -740,6 +769,9 @@ impl<'de> Visitor<'de> for TaskDeserializeVisitor {
"wait" => {
wait = Some(visitor.next_value()?);
}
+ "urgency" => {
+ urgency = Some(visitor.next_value()?);
+ }
field => {
debug!("Inserting '{}' as UDA", field);
@@ -792,6 +824,7 @@ impl<'de> Visitor<'de> for TaskDeserializeVisitor {
tags,
until,
wait,
+ urgency,
uda,
);
@@ -829,7 +862,8 @@ mod test {
"description": "test",
"entry": "20150619T165438Z",
"status": "waiting",
-"uuid": "8ca953d5-18b4-4eb9-bd56-18f2e5b752f0"
+"uuid": "8ca953d5-18b4-4eb9-bd56-18f2e5b752f0",
+"urgency": 5.3
}"#;
println!("{}", s);
@@ -845,6 +879,7 @@ mod test {
assert!(
task.uuid().clone() == Uuid::parse_str("8ca953d5-18b4-4eb9-bd56-18f2e5b752f0").unwrap()
);
+ assert!(task.urgency() == Some(&5.3));
let back = serde_json::to_string(&task).unwrap();
@@ -855,6 +890,7 @@ mod test {
assert!(back.contains("status"));
assert!(back.contains("waiting"));
assert!(back.contains("uuid"));
+ assert!(back.contains("urgency"));
assert!(back.contains("8ca953d5-18b4-4eb9-bd56-18f2e5b752f0"));
}
@@ -889,6 +925,8 @@ mod test {
task.uuid().clone() == Uuid::parse_str("8ca953d5-18b4-4eb9-bd56-18f2e5b752f0").unwrap()
);
+ assert!(task.urgency() == Some(&0.583562));
+
assert!(task.modified() == Some(&mkdate("20160327T164007Z")));
assert!(task.project() == Some(&String::from("someproject")));
@@ -942,7 +980,7 @@ mod test {
{"entry":"20160423T125926Z","description":"Another Annotation"},
{"entry":"20160422T125942Z","description":"A Third Anno"}
],
-"urgency": 0.583562
+"urgency": -5
}"#;
println!("{}", s);
@@ -952,6 +990,8 @@ mod test {
assert!(task.is_ok());
let task: Task = task.unwrap();
+ assert!(task.urgency() == Some(&-5.0));
+
let all_annotations =
vec![
Annotation::new(mkdate("20160423T125911Z"), String::from("An Annotation")),
@@ -1083,6 +1123,7 @@ mod test {
assert!(t.project().is_some());
assert_eq!(t.project().unwrap(), "project");
assert!(t.tags().is_some());
+ assert!(t.urgency().is_none());
assert_eq!(
t.tags().unwrap(),
&vec!["search".to_owned(), "things".to_owned()]
diff --git a/src/urgency.rs b/src/urgency.rs
new file mode 100644
index 0000000..b59d7ce
--- /dev/null
+++ b/src/urgency.rs
@@ -0,0 +1,10 @@
+//
+// This Source Code Form is subject to the terms of the Mozilla Public
+// License, v. 2.0. If a copy of the MPL was not distributed with this
+// file, You can obtain one at http://mozilla.org/MPL/2.0/.
+//
+
+//! Module containing `Urgency` type
+
+/// type definition for Urgency
+pub type Urgency = f64;