Skip to content

Commit

Permalink
Add urgency to task
Browse files Browse the repository at this point in the history
  • Loading branch information
kdheepak committed Oct 24, 2020
1 parent 2953cf0 commit e5ecba3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/create_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn main() {
None,
None,
None,
None,
UDA::default(),
);
println!("[{}]", to_string(&t).unwrap());
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,5 @@ pub mod status;
pub mod tag;
pub mod task;
pub mod uda;
pub mod urgency;
pub mod tw;
30 changes: 30 additions & 0 deletions src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use tag::Tag;
use date::Date;
use annotation::Annotation;
use uda::{UDA, UDAName, UDAValue};
use urgency::Urgency;

/// Task type
///
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -143,6 +147,7 @@ impl Task {
tags: Option<Vec<Tag>>,
until: Option<Date>,
wait: Option<Date>,
urgency: Option<Urgency>,
uda: UDA,
) -> Task {
Task {
Expand All @@ -168,6 +173,7 @@ impl Task {
tags: tags,
until: until,
wait: wait,
urgency: urgency,
uda: uda,
}
}
Expand Down Expand Up @@ -493,6 +499,21 @@ 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()
Expand Down Expand Up @@ -580,6 +601,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)?;
Expand Down Expand Up @@ -617,6 +641,7 @@ impl<'de> Deserialize<'de> for Task {
"tags",
"until",
"wait",
"urgency",
"uda",
];
deserializer.deserialize_struct("Task", FIELDS, TaskDeserializeVisitor)
Expand Down Expand Up @@ -660,6 +685,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 {
Expand Down Expand Up @@ -740,6 +766,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);
Expand Down Expand Up @@ -792,6 +821,7 @@ impl<'de> Visitor<'de> for TaskDeserializeVisitor {
tags,
until,
wait,
urgency,
uda,
);

Expand Down
10 changes: 10 additions & 0 deletions src/urgency.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit e5ecba3

Please sign in to comment.