Show task description for selected column
This commit is contained in:
parent
436c9ed3cf
commit
07299d481d
68
Cargo.lock
generated
68
Cargo.lock
generated
@ -68,6 +68,27 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "int-enum"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cff87d3cc4b79b4559e3c75068d64247284aceb6a038bd4bb38387f3f164476d"
|
||||
dependencies = [
|
||||
"int-enum-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "int-enum-impl"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df1f2f068675add1a3fc77f5f5ab2e29290c841ee34d151abc007bce902e5d34"
|
||||
dependencies = [
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.4"
|
||||
@ -80,6 +101,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"crossterm",
|
||||
"indexmap",
|
||||
"int-enum",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tui",
|
||||
@ -122,6 +144,12 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.16.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
@ -145,6 +173,17 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-crate"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"thiserror",
|
||||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.47"
|
||||
@ -262,6 +301,35 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tui"
|
||||
version = "0.19.0"
|
||||
|
@ -10,4 +10,5 @@ tui = "0.19.0"
|
||||
crossterm = "0.25"
|
||||
serde = { version = "1.0.148" , features = [ "derive" ] }
|
||||
serde_json = "1.0.89"
|
||||
indexmap = { version = "1.9.2" , features = [ "serde" ] }
|
||||
indexmap = { version = "1.9.2" , features = [ "serde" ] }
|
||||
int-enum = "0.5.0"
|
24
src/types.rs
24
src/types.rs
@ -1,13 +1,15 @@
|
||||
use indexmap::IndexMap;
|
||||
use int_enum::IntEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[repr(usize)]
|
||||
#[derive(Deserialize, Serialize, Copy, Clone, Debug, PartialEq, PartialOrd, Eq, Ord, Hash, IntEnum)]
|
||||
pub enum TaskStatus {
|
||||
Done,
|
||||
Todo,
|
||||
InProgress,
|
||||
Testing,
|
||||
Backlog,
|
||||
Done = 0,
|
||||
Todo = 1,
|
||||
InProgress = 2,
|
||||
Testing = 3,
|
||||
Backlog = 4,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
@ -28,14 +30,14 @@ impl Default for Task {
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct Project {
|
||||
pub name: String,
|
||||
pub tasks: IndexMap<TaskStatus, Vec<Task>>,
|
||||
pub tasks_per_column: IndexMap<TaskStatus, Vec<Task>>,
|
||||
}
|
||||
|
||||
impl Project {
|
||||
fn new(name: &str) -> Self {
|
||||
Project {
|
||||
name: name.to_owned(),
|
||||
tasks: IndexMap::from(
|
||||
tasks_per_column: IndexMap::from(
|
||||
[(TaskStatus::Done, vec![]),
|
||||
(TaskStatus::Todo, vec![]),
|
||||
(TaskStatus::InProgress, vec![]),
|
||||
@ -46,7 +48,7 @@ impl Project {
|
||||
}
|
||||
|
||||
fn add_task(&mut self, status: TaskStatus, task: Task) {
|
||||
self.tasks.entry(status).or_default().push(task);
|
||||
self.tasks_per_column.entry(status).or_default().push(task);
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,7 +56,7 @@ impl Default for Project {
|
||||
fn default() -> Self {
|
||||
Project {
|
||||
name: String::new(),
|
||||
tasks: IndexMap::new(),
|
||||
tasks_per_column: IndexMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -78,7 +80,7 @@ impl Project {
|
||||
|
||||
pub struct AppState {
|
||||
pub selected_column: usize,
|
||||
pub selected_task: [u8; 5],
|
||||
pub selected_task: [usize; 5],
|
||||
pub current_project: Project,
|
||||
pub quit: bool,
|
||||
}
|
||||
|
16
src/ui.rs
16
src/ui.rs
@ -5,17 +5,18 @@ use tui::style::{Color, Modifier, Style};
|
||||
use tui::text::{Span, Spans};
|
||||
use tui::widgets::*;
|
||||
use crate::types::*;
|
||||
use int_enum::IntEnum;
|
||||
|
||||
fn draw_tasks<B: Backend>(f: &mut Frame<B>, area: &Rect, state: &AppState) {
|
||||
let columns = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints(
|
||||
vec![Constraint::Percentage(20);
|
||||
state.current_project.tasks.len()].as_ref()
|
||||
state.current_project.tasks_per_column.len()].as_ref()
|
||||
)
|
||||
.split(*area);
|
||||
|
||||
for (i, (status, tasks)) in state.current_project.tasks.iter().enumerate() {
|
||||
for (i, (status, tasks)) in state.current_project.tasks_per_column.iter().enumerate() {
|
||||
let items: Vec<ListItem> = tasks.iter().map(|t| {
|
||||
ListItem::new(vec![Spans::from(Span::raw(&t.title))])
|
||||
}).collect();
|
||||
@ -38,7 +39,16 @@ fn draw_task_info<B: Backend>(f: &mut Frame<B>, area: &Rect, state: &AppState) {
|
||||
let block = Block::default()
|
||||
.title("TASK INFO")
|
||||
.borders(Borders::ALL);
|
||||
f.render_widget(block, *area);
|
||||
let column: TaskStatus = TaskStatus::from_int(state.selected_column).unwrap();
|
||||
let tasks = state.current_project.tasks_per_column.get(&column).unwrap();
|
||||
if tasks.len() > 0 {
|
||||
let task: &Task = &tasks[state.selected_task[state.selected_column]];
|
||||
let p = Paragraph::new(&*task.description).block(block);
|
||||
f.render_widget(p, *area);
|
||||
} else {
|
||||
let p = Paragraph::new("No tasks for this column").block(block);
|
||||
f.render_widget(p, *area);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw<B: Backend>(f: &mut Frame<B>, state: &mut AppState) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user