mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
bin/taud: don't pass timestamp params to list function
This commit is contained in:
@@ -44,12 +44,6 @@ pub enum CliTauSubCommands {
|
||||
#[clap(short, long)]
|
||||
rank: Option<u32>,
|
||||
},
|
||||
/// List open tasks
|
||||
List {
|
||||
/// Month tasks
|
||||
#[clap(short, long)]
|
||||
month: Option<String>,
|
||||
},
|
||||
/// Update/Edit an existing task by ID
|
||||
Update {
|
||||
/// Task ID
|
||||
@@ -85,6 +79,8 @@ pub enum CliTauSubCommands {
|
||||
/// Task ID
|
||||
id: u64,
|
||||
},
|
||||
/// List open tasks
|
||||
List {},
|
||||
}
|
||||
|
||||
/// Tau cli
|
||||
@@ -158,10 +154,10 @@ async fn add(url: &str, params: Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
// List tasks
|
||||
// --> {"jsonrpc": "2.0", "method": "list", "params": [month_date], "id": 1}
|
||||
// --> {"jsonrpc": "2.0", "method": "list", "params": [], "id": 1}
|
||||
// <-- {"jsonrpc": "2.0", "result": [task, ...], "id": 1}
|
||||
async fn list(url: &str, month: Option<i64>) -> Result<Value> {
|
||||
let req = jsonrpc::request(json!("list"), json!([month]));
|
||||
async fn list(url: &str, params: Value) -> Result<Value> {
|
||||
let req = jsonrpc::request(json!("list"), json!(params));
|
||||
request(req, url.to_string()).await
|
||||
}
|
||||
|
||||
@@ -261,24 +257,13 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
add(rpc_addr, json!([title, desc, assign, project, due, rank])).await?;
|
||||
}
|
||||
|
||||
Some(CliTauSubCommands::List { month }) => {
|
||||
let ts = if month.is_some() {
|
||||
let month = month.unwrap();
|
||||
assert!(month.len() == 4);
|
||||
let (m, y) = (month[..2].parse::<u32>()?, month[2..].parse::<i32>()?);
|
||||
let dt = NaiveDate::from_ymd(y + 2000, m, 1).and_hms(0, 0, 0);
|
||||
|
||||
Some(dt.timestamp())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
Some(CliTauSubCommands::List {}) => {
|
||||
let rep = list(rpc_addr, json!([])).await?;
|
||||
|
||||
let mut table = Table::new();
|
||||
table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR);
|
||||
table.set_titles(row!["ID", "Title", "Project", "Assigned", "Due", "Rank"]);
|
||||
|
||||
let rep = list(rpc_addr, ts).await?;
|
||||
|
||||
let mut tasks = rep.as_array().unwrap().to_owned();
|
||||
tasks.sort_by(|a, b| b["rank"].as_u64().cmp(&a["rank"].as_u64()));
|
||||
|
||||
@@ -356,7 +341,7 @@ async fn start(options: CliTau) -> Result<()> {
|
||||
}
|
||||
|
||||
Some(CliTauSubCommands::GetComment { id }) => {
|
||||
let rep = list(rpc_addr, None).await?;
|
||||
let rep = list(rpc_addr, json!([])).await?;
|
||||
let tasks = rep.as_array().unwrap();
|
||||
|
||||
for task in tasks {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{fs::create_dir_all, path::PathBuf, sync::Arc};
|
||||
use std::{fs::create_dir_all, sync::Arc};
|
||||
|
||||
use async_executor::Executor;
|
||||
use async_trait::async_trait;
|
||||
@@ -143,27 +143,10 @@ impl JsonRpcInterface {
|
||||
|
||||
// RPCAPI:
|
||||
// List tasks
|
||||
// --> {"jsonrpc": "2.0", "method": "list", "params": [month_date], "id": 1}
|
||||
// --> {"jsonrpc": "2.0", "method": "list", "params": [], "id": 1}
|
||||
// <-- {"jsonrpc": "2.0", "result": [task, ...], "id": 1}
|
||||
async fn list(&self, id: Value, params: Value) -> JsonResult {
|
||||
let args = params.as_array().unwrap();
|
||||
|
||||
if args.len() != 1 {
|
||||
return JsonResult::Err(jsonerr(InvalidParams, None, id))
|
||||
}
|
||||
|
||||
let result = || -> Result<Vec<TaskInfo>> {
|
||||
let tasks: Vec<TaskInfo> = if args[0].is_i64() {
|
||||
MonthTasks::load_or_create(&Timestamp(args[0].as_i64().unwrap()), &self.settings)?
|
||||
.objects()?
|
||||
} else {
|
||||
MonthTasks::load_current_open_tasks(&self.settings)?
|
||||
};
|
||||
|
||||
Ok(tasks)
|
||||
};
|
||||
|
||||
match result() {
|
||||
async fn list(&self, id: Value, _params: Value) -> JsonResult {
|
||||
match MonthTasks::load_current_open_tasks(&self.settings) {
|
||||
Ok(tks) => JsonResult::Resp(jsonresp(json!(tks), id)),
|
||||
Err(e) => JsonResult::Err(jsonerr(ServerError(-32603), Some(e.to_string()), id)),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user