mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-08 22:28:12 -05:00
bin/tau-cli: rank as f32 and cleanup
This commit is contained in:
@@ -43,7 +43,7 @@ pub enum CliTauSubCommands {
|
||||
due: Option<String>,
|
||||
/// Project rank
|
||||
#[clap(short, long)]
|
||||
rank: Option<f64>,
|
||||
rank: Option<f32>,
|
||||
},
|
||||
/// Update/Edit an existing task by ID
|
||||
Update {
|
||||
@@ -98,7 +98,7 @@ struct TaskInfo {
|
||||
assign: Vec<String>,
|
||||
project: Vec<String>,
|
||||
due: String,
|
||||
rank: u32,
|
||||
rank: f32,
|
||||
created_at: String,
|
||||
events: Vec<Value>,
|
||||
comments: Vec<Value>,
|
||||
@@ -246,6 +246,10 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
if &t[(t.len() - 1)..] == "\n" {
|
||||
t.pop();
|
||||
}
|
||||
if t.is_empty() {
|
||||
error!("You can't have a task without a title");
|
||||
return Err(Error::OperationFailed)
|
||||
}
|
||||
Some(t)
|
||||
} else {
|
||||
title
|
||||
@@ -315,20 +319,20 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
||||
table.set_titles(row!["ID", "Title", "Project", "Assigned", "Due", "Rank"]);
|
||||
|
||||
let mut tasks = rep.as_array().unwrap().to_owned();
|
||||
let mut tasks: Vec<Value> = serde_json::from_value(rep)?;
|
||||
tasks.sort_by(|a, b| b["rank"].as_f64().partial_cmp(&a["rank"].as_f64()).unwrap());
|
||||
|
||||
let (max_rank, min_rank) = if !tasks.is_empty() {
|
||||
(
|
||||
tasks[0]["rank"].as_f64().unwrap(),
|
||||
tasks.last().unwrap()["rank"].as_f64().unwrap(),
|
||||
serde_json::from_value(tasks[0]["rank"].clone())?,
|
||||
serde_json::from_value(tasks[tasks.len() - 1]["rank"].clone())?,
|
||||
)
|
||||
} else {
|
||||
(0.0, 0.0)
|
||||
};
|
||||
|
||||
for task in tasks {
|
||||
let project = task["project"].as_array().unwrap();
|
||||
let project: Vec<Value> = serde_json::from_value(task["project"].clone())?;
|
||||
let mut projects = String::new();
|
||||
for (i, _) in project.iter().enumerate() {
|
||||
if !projects.is_empty() {
|
||||
@@ -337,7 +341,7 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
projects.push_str(project.index(i).as_str().unwrap());
|
||||
}
|
||||
|
||||
let assign = task["assign"].as_array().unwrap();
|
||||
let assign: Vec<Value> = serde_json::from_value(task["assign"].clone())?;
|
||||
let mut asgn = String::new();
|
||||
for (i, _) in assign.iter().enumerate() {
|
||||
if !asgn.is_empty() {
|
||||
@@ -353,7 +357,7 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
"".to_string()
|
||||
};
|
||||
|
||||
let rank = task["rank"].as_f64().unwrap_or(0.0);
|
||||
let rank = task["rank"].as_f64().unwrap_or(0.0) as f32;
|
||||
|
||||
table.add_row(Row::new(vec![
|
||||
Cell::new(&task["id"].to_string()),
|
||||
@@ -381,7 +385,7 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
json!(due_as_timestamp(value))
|
||||
}
|
||||
"rank" => {
|
||||
json!(value.parse::<u64>()?)
|
||||
json!(value.parse::<f32>()?)
|
||||
}
|
||||
"project" | "assign" => {
|
||||
json!(value.split(',').collect::<Vec<&str>>())
|
||||
@@ -400,7 +404,7 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
|
||||
Some(CliTauSubCommands::GetState { id }) => {
|
||||
let state = get_state(rpc_addr, id).await?;
|
||||
println!("Task with id: {} is {}", id, state);
|
||||
println!("Task with id {} is: {}", id, state);
|
||||
}
|
||||
|
||||
Some(CliTauSubCommands::SetComment { id, author, content }) => {
|
||||
@@ -409,17 +413,18 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
|
||||
Some(CliTauSubCommands::GetComment { id }) => {
|
||||
let rep = list(rpc_addr, json!([])).await?;
|
||||
let tasks = rep.as_array().unwrap();
|
||||
let tasks: Vec<Value> = serde_json::from_value(rep)?;
|
||||
|
||||
if tasks.iter().any(|x| x["id"].as_u64().unwrap() == id) {
|
||||
let index: usize = (id - 1).try_into().unwrap();
|
||||
let comments = tasks[index]["comments"].as_array().unwrap();
|
||||
let comments: Vec<Value> =
|
||||
serde_json::from_value(tasks[index]["comments"].clone())?;
|
||||
let mut cmnt = String::new();
|
||||
|
||||
for comment in comments {
|
||||
cmnt.push_str(comment["author"].as_str().unwrap());
|
||||
cmnt.push_str(comment["author"].as_str().ok_or(Error::OperationFailed)?);
|
||||
cmnt.push_str(": ");
|
||||
cmnt.push_str(comment["content"].as_str().unwrap());
|
||||
cmnt.push_str(comment["content"].as_str().ok_or(Error::OperationFailed)?);
|
||||
cmnt.push('\n');
|
||||
}
|
||||
cmnt.pop();
|
||||
|
||||
@@ -33,7 +33,7 @@ pub struct BaseTaskInfo {
|
||||
assign: Vec<String>,
|
||||
project: Vec<String>,
|
||||
due: Option<Timestamp>,
|
||||
rank: f64,
|
||||
rank: f32,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -231,7 +231,7 @@ impl JsonRpcInterface {
|
||||
|
||||
if data.contains_key("rank") {
|
||||
let rank = data.get("rank").unwrap().clone();
|
||||
let rank: f64 = serde_json::from_value(rank)?;
|
||||
let rank: f32 = serde_json::from_value(rank)?;
|
||||
task.set_rank(rank);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ pub struct TaskInfo {
|
||||
assign: TaskAssigns,
|
||||
project: TaskProjects,
|
||||
due: Option<Timestamp>,
|
||||
rank: f64,
|
||||
rank: f32,
|
||||
created_at: Timestamp,
|
||||
events: TaskEvents,
|
||||
comments: TaskComments,
|
||||
@@ -68,7 +68,7 @@ impl TaskInfo {
|
||||
title: &str,
|
||||
desc: &str,
|
||||
due: Option<Timestamp>,
|
||||
rank: f64,
|
||||
rank: f32,
|
||||
settings: &Settings,
|
||||
) -> TaudResult<Self> {
|
||||
// generate ref_id
|
||||
@@ -160,7 +160,7 @@ impl TaskInfo {
|
||||
self.comments.0.push(c);
|
||||
}
|
||||
|
||||
pub fn set_rank(&mut self, r: f64) {
|
||||
pub fn set_rank(&mut self, r: f32) {
|
||||
self.rank = r;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
ParseIntError(#[from] std::num::ParseIntError),
|
||||
|
||||
#[error(transparent)]
|
||||
ParseFloatError(#[from] std::num::ParseFloatError),
|
||||
|
||||
#[cfg(feature = "util")]
|
||||
#[error(transparent)]
|
||||
ParseBigIntError(#[from] num_bigint::ParseBigIntError),
|
||||
|
||||
Reference in New Issue
Block a user