feat: task time column
This commit is contained in:
parent
91e04f2c16
commit
04ff65737a
1 changed files with 28 additions and 8 deletions
36
src/task.rs
36
src/task.rs
|
@ -65,14 +65,6 @@ impl Task {
|
||||||
self.state().map_or(State::Open, |s| s.state)
|
self.state().map_or(State::Open, |s| s.state)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_state(&self) -> TaskState {
|
|
||||||
TaskState {
|
|
||||||
name: None,
|
|
||||||
state: State::Open,
|
|
||||||
time: self.event.created_at,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn update_state(&mut self, state: State, comment: &str) {
|
pub(crate) fn update_state(&mut self, state: State, comment: &str) {
|
||||||
self.props.push(make_event(
|
self.props.push(make_event(
|
||||||
state.kind(),
|
state.kind(),
|
||||||
|
@ -81,12 +73,40 @@ impl Task {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_state(&self) -> TaskState {
|
||||||
|
TaskState {
|
||||||
|
name: None,
|
||||||
|
state: State::Open,
|
||||||
|
time: self.event.created_at,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Total time this task has been active.
|
||||||
|
/// Todo: Recursive
|
||||||
|
pub(crate) fn time_tracked(&self) -> u64 {
|
||||||
|
let mut total = 0;
|
||||||
|
let mut start: Option<Timestamp> = None;
|
||||||
|
for state in self.states() {
|
||||||
|
match state.state {
|
||||||
|
State::Active => start = start.or(Some(state.time)),
|
||||||
|
_ => {
|
||||||
|
if let Some(stamp) = start {
|
||||||
|
total += (state.time - stamp).as_u64();
|
||||||
|
start = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
total
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn get(&self, property: &str) -> Option<String> {
|
pub(crate) fn get(&self, property: &str) -> Option<String> {
|
||||||
match property {
|
match property {
|
||||||
"id" => Some(self.event.id.to_string()),
|
"id" => Some(self.event.id.to_string()),
|
||||||
"parentid" => self.parent_id().map(|i| i.to_string()),
|
"parentid" => self.parent_id().map(|i| i.to_string()),
|
||||||
"state" => self.state().map(|s| s.to_string()),
|
"state" => self.state().map(|s| s.to_string()),
|
||||||
"name" => Some(self.event.content.clone()),
|
"name" => Some(self.event.content.clone()),
|
||||||
|
"time" => Some(self.time_tracked().to_string()), // TODO: format properly
|
||||||
"desc" | "description" => self.descriptions().fold(None, |total, s| {
|
"desc" | "description" => self.descriptions().fold(None, |total, s| {
|
||||||
Some(match total {
|
Some(match total {
|
||||||
None => s,
|
None => s,
|
||||||
|
|
Loading…
Add table
Reference in a new issue