Pedantic clippy pass
This commit is contained in:
parent
7fe20e6ae8
commit
c3255c97f5
13
src/app.rs
13
src/app.rs
@ -2,7 +2,7 @@
|
|||||||
// use int_enum::IntEnum;
|
// use int_enum::IntEnum;
|
||||||
use rusqlite::Connection;
|
use rusqlite::Connection;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::min;
|
use std::{cmp::min, error::Error};
|
||||||
use tui_textarea::TextArea;
|
use tui_textarea::TextArea;
|
||||||
|
|
||||||
use crate::db;
|
use crate::db;
|
||||||
@ -29,7 +29,6 @@ pub struct Task {
|
|||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize, Debug)]
|
||||||
pub struct Project {
|
pub struct Project {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub filepath: String,
|
|
||||||
pub selected_column_idx: usize,
|
pub selected_column_idx: usize,
|
||||||
pub columns: Vec<Column>,
|
pub columns: Vec<Column>,
|
||||||
}
|
}
|
||||||
@ -182,12 +181,16 @@ impl<'a> Column {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Project {
|
impl Project {
|
||||||
pub async fn load(pool: &Connection) -> Result<Self, KanbanError> {
|
/// .
|
||||||
let columns = db::get_all_columns(&pool).unwrap();
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function will return an error if it has issues reading from the database
|
||||||
|
pub fn load(conn: &Connection) -> Result<Self, Box<dyn Error>> {
|
||||||
|
let columns = db::get_all_columns(conn)?;
|
||||||
|
|
||||||
Ok(Project {
|
Ok(Project {
|
||||||
name: String::from("Kanban Board"),
|
name: String::from("Kanban Board"),
|
||||||
filepath: String::from("path"),
|
|
||||||
columns,
|
columns,
|
||||||
selected_column_idx: 0,
|
selected_column_idx: 0,
|
||||||
})
|
})
|
||||||
|
45
src/db.rs
45
src/db.rs
@ -1,6 +1,11 @@
|
|||||||
use crate::{Column, Task};
|
use crate::{Column, Task};
|
||||||
use rusqlite::{params, Connection, Result};
|
use rusqlite::{params, Connection, Result};
|
||||||
|
|
||||||
|
/// .
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function will return an error if something is wrong with the SQL
|
||||||
pub fn get_tasks_by_column(conn: &Connection, column_name: &String) -> Result<Vec<Task>> {
|
pub fn get_tasks_by_column(conn: &Connection, column_name: &String) -> Result<Vec<Task>> {
|
||||||
let mut stmt = conn.prepare(
|
let mut stmt = conn.prepare(
|
||||||
r#"
|
r#"
|
||||||
@ -11,7 +16,7 @@ pub fn get_tasks_by_column(conn: &Connection, column_name: &String) -> Result<Ve
|
|||||||
"#,
|
"#,
|
||||||
)?;
|
)?;
|
||||||
let mut tasks = Vec::new();
|
let mut tasks = Vec::new();
|
||||||
let rows = stmt.query_map(&[column_name], |row| {
|
let rows = stmt.query_map([column_name], |row| {
|
||||||
Ok(Task {
|
Ok(Task {
|
||||||
id: row.get(0)?,
|
id: row.get(0)?,
|
||||||
title: row.get(1)?,
|
title: row.get(1)?,
|
||||||
@ -24,6 +29,11 @@ pub fn get_tasks_by_column(conn: &Connection, column_name: &String) -> Result<Ve
|
|||||||
Ok(tasks)
|
Ok(tasks)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// .
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function will return an error if there are issues with the SQL
|
||||||
pub fn get_all_columns(conn: &Connection) -> Result<Vec<Column>> {
|
pub fn get_all_columns(conn: &Connection) -> Result<Vec<Column>> {
|
||||||
let mut stmt = conn.prepare("select id, name from kb_column")?;
|
let mut stmt = conn.prepare("select id, name from kb_column")?;
|
||||||
let query_rows = stmt.query_map((), |row| {
|
let query_rows = stmt.query_map((), |row| {
|
||||||
@ -33,11 +43,11 @@ pub fn get_all_columns(conn: &Connection) -> Result<Vec<Column>> {
|
|||||||
for row in query_rows {
|
for row in query_rows {
|
||||||
let r = &row?;
|
let r = &row?;
|
||||||
let name = &r.1;
|
let name = &r.1;
|
||||||
let tasks = get_tasks_by_column(conn, &name).unwrap();
|
let tasks = get_tasks_by_column(conn, name)?;
|
||||||
let col = Column {
|
let col = Column {
|
||||||
id: r.0,
|
id: r.0,
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
tasks: tasks,
|
tasks,
|
||||||
selected_task_idx: 0,
|
selected_task_idx: 0,
|
||||||
};
|
};
|
||||||
columns.push(col);
|
columns.push(col);
|
||||||
@ -45,6 +55,11 @@ pub fn get_all_columns(conn: &Connection) -> Result<Vec<Column>> {
|
|||||||
Ok(columns)
|
Ok(columns)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// .
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if something goes wrong with the SQL
|
||||||
pub fn insert_new_task(
|
pub fn insert_new_task(
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
title: String,
|
title: String,
|
||||||
@ -64,11 +79,21 @@ pub fn insert_new_task(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// .
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if something goes wrong with the SQL
|
||||||
pub fn delete_task(conn: &Connection, task: &Task) {
|
pub fn delete_task(conn: &Connection, task: &Task) {
|
||||||
let mut stmt = conn.prepare("delete from task where id = ?1").unwrap();
|
let mut stmt = conn.prepare("delete from task where id = ?1").unwrap();
|
||||||
stmt.execute([task.id]).unwrap();
|
stmt.execute([task.id]).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// .
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if something goes wrong with the SQL
|
||||||
pub fn update_task_text(conn: &Connection, task: &Task) {
|
pub fn update_task_text(conn: &Connection, task: &Task) {
|
||||||
let mut stmt = conn
|
let mut stmt = conn
|
||||||
.prepare("update task set title = ?2, description = ?3 where id = ?1")
|
.prepare("update task set title = ?2, description = ?3 where id = ?1")
|
||||||
@ -77,6 +102,11 @@ pub fn update_task_text(conn: &Connection, task: &Task) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// .
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if something goes wrong with the SQL
|
||||||
pub fn move_task_to_column(conn: &Connection, task: &Task, target_column: &Column) {
|
pub fn move_task_to_column(conn: &Connection, task: &Task, target_column: &Column) {
|
||||||
let mut stmt = conn
|
let mut stmt = conn
|
||||||
.prepare(
|
.prepare(
|
||||||
@ -93,12 +123,17 @@ pub fn move_task_to_column(conn: &Connection, task: &Task, target_column: &Colum
|
|||||||
stmt.execute((&task.id, &target_column.id)).unwrap();
|
stmt.execute((&task.id, &target_column.id)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// .
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Panics if something goes wrong with the SQL
|
||||||
pub fn swap_task_order(conn: &mut Connection, task1: &Task, task2: &Task) {
|
pub fn swap_task_order(conn: &mut Connection, task1: &Task, task2: &Task) {
|
||||||
let tx = conn.transaction().unwrap();
|
let tx = conn.transaction().unwrap();
|
||||||
|
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"create temp table temp_order as select sort_order from task where id = ?1",
|
"create temp table temp_order as select sort_order from task where id = ?1",
|
||||||
&[&task1.id],
|
[&task1.id],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
@ -111,7 +146,7 @@ pub fn swap_task_order(conn: &mut Connection, task1: &Task, task2: &Task) {
|
|||||||
|
|
||||||
tx.execute(
|
tx.execute(
|
||||||
"update task set sort_order = (select sort_order from temp_order) where id = ?1",
|
"update task set sort_order = (select sort_order from temp_order) where id = ?1",
|
||||||
&[&task2.id],
|
[&task2.id],
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
tx.execute("drop table temp_order", ()).unwrap();
|
tx.execute("drop table temp_order", ()).unwrap();
|
||||||
|
18
src/input.rs
18
src/input.rs
@ -6,6 +6,10 @@ use crossterm::event::{Event, KeyCode};
|
|||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Crossterm `event::read()` might return an error
|
/// Crossterm `event::read()` might return an error
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// Shouldn't really panic because there are checks to ensure we can unwrap safely
|
||||||
pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
||||||
let project = &mut state.project;
|
let project = &mut state.project;
|
||||||
let column = project.get_selected_column_mut();
|
let column = project.get_selected_column_mut();
|
||||||
@ -40,14 +44,14 @@ pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
|||||||
if let Some(selected_task) = column.get_selected_task_mut() {
|
if let Some(selected_task) = column.get_selected_task_mut() {
|
||||||
selected_task.title = title;
|
selected_task.title = title;
|
||||||
selected_task.description = description;
|
selected_task.description = description;
|
||||||
db::update_task_text(&state.db_conn, &selected_task);
|
db::update_task_text(&state.db_conn, selected_task);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let task = db::insert_new_task(
|
let task = db::insert_new_task(
|
||||||
&state.db_conn,
|
&state.db_conn,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
&column,
|
column,
|
||||||
);
|
);
|
||||||
column.add_task(task);
|
column.add_task(task);
|
||||||
}
|
}
|
||||||
@ -82,7 +86,7 @@ pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
|||||||
project.move_task_previous_column();
|
project.move_task_previous_column();
|
||||||
let col = project.get_selected_column();
|
let col = project.get_selected_column();
|
||||||
let t = col.get_selected_task().unwrap();
|
let t = col.get_selected_task().unwrap();
|
||||||
db::move_task_to_column(&state.db_conn, &t, &col);
|
db::move_task_to_column(&state.db_conn, t, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('L') => {
|
KeyCode::Char('L') => {
|
||||||
@ -90,26 +94,26 @@ pub fn handle(state: &mut State<'_>) -> Result<(), std::io::Error> {
|
|||||||
project.move_task_next_column();
|
project.move_task_next_column();
|
||||||
let col = project.get_selected_column();
|
let col = project.get_selected_column();
|
||||||
let t = col.get_selected_task().unwrap();
|
let t = col.get_selected_task().unwrap();
|
||||||
db::move_task_to_column(&state.db_conn, &t, &col);
|
db::move_task_to_column(&state.db_conn, t, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('J') => {
|
KeyCode::Char('J') => {
|
||||||
if column.move_task_down() {
|
if column.move_task_down() {
|
||||||
let task1 = column.get_selected_task().unwrap();
|
let task1 = column.get_selected_task().unwrap();
|
||||||
let task2 = column.get_previous_task().unwrap();
|
let task2 = column.get_previous_task().unwrap();
|
||||||
db::swap_task_order(&mut state.db_conn, &task1, &task2);
|
db::swap_task_order(&mut state.db_conn, task1, task2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('K') => {
|
KeyCode::Char('K') => {
|
||||||
if column.move_task_up() {
|
if column.move_task_up() {
|
||||||
let task1 = column.get_selected_task().unwrap();
|
let task1 = column.get_selected_task().unwrap();
|
||||||
let task2 = column.get_next_task().unwrap();
|
let task2 = column.get_next_task().unwrap();
|
||||||
db::swap_task_order(&mut state.db_conn, &task1, &task2);
|
db::swap_task_order(&mut state.db_conn, task1, task2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('n') => state.task_edit_state = Some(TaskState::default()),
|
KeyCode::Char('n') => state.task_edit_state = Some(TaskState::default()),
|
||||||
KeyCode::Char('e') => {
|
KeyCode::Char('e') => {
|
||||||
state.task_edit_state = column.get_task_state_from_curr_selected_task()
|
state.task_edit_state = column.get_task_state_from_curr_selected_task();
|
||||||
}
|
}
|
||||||
KeyCode::Char('D') => {
|
KeyCode::Char('D') => {
|
||||||
if !column.tasks.is_empty() {
|
if !column.tasks.is_empty() {
|
||||||
|
@ -32,7 +32,7 @@ async fn main() -> anyhow::Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
if migrate {
|
if migrate {
|
||||||
let migrations = include_str!("../sql/migrations.sql");
|
let migrations = include_str!("../sql/migrations.sql");
|
||||||
let migrations: Vec<&str> = migrations.split(";").collect();
|
let migrations: Vec<&str> = migrations.split(';').collect();
|
||||||
let tx = conn.transaction()?;
|
let tx = conn.transaction()?;
|
||||||
for m in migrations {
|
for m in migrations {
|
||||||
if !m.trim().is_empty() {
|
if !m.trim().is_empty() {
|
||||||
@ -42,7 +42,7 @@ async fn main() -> anyhow::Result<(), Box<dyn Error>> {
|
|||||||
tx.commit()?;
|
tx.commit()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let project = Project::load(&conn).await?;
|
let project = Project::load(&conn)?;
|
||||||
let mut state = State::new(conn, project);
|
let mut state = State::new(conn, project);
|
||||||
|
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user