mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
bin/tau: rewrite set_event()
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -4217,6 +4217,7 @@ dependencies = [
|
||||
"easy-parallel",
|
||||
"futures",
|
||||
"hex",
|
||||
"libc",
|
||||
"log",
|
||||
"rand",
|
||||
"serde",
|
||||
|
||||
@@ -20,6 +20,7 @@ easy-parallel = "3.2.0"
|
||||
futures = "0.3.26"
|
||||
|
||||
# Misc
|
||||
libc = "0.2.139"
|
||||
log = "0.4.17"
|
||||
simplelog = "0.12.0"
|
||||
rand = "0.8.5"
|
||||
|
||||
@@ -39,7 +39,7 @@ use crate::{
|
||||
error::{to_json_result, TaudError, TaudResult},
|
||||
month_tasks::MonthTasks,
|
||||
task_info::{Comment, TaskInfo},
|
||||
util::find_free_id,
|
||||
util::{find_free_id, set_event},
|
||||
};
|
||||
|
||||
pub struct JsonRpcInterface {
|
||||
@@ -212,6 +212,7 @@ impl JsonRpcInterface {
|
||||
|
||||
if states.contains(&state.as_str()) {
|
||||
task.set_state(&state);
|
||||
set_event(&mut task, "state", &self.nickname, &state);
|
||||
}
|
||||
|
||||
self.notify_queue_sender.send(task).await.map_err(Error::from)?;
|
||||
@@ -236,6 +237,7 @@ impl JsonRpcInterface {
|
||||
let mut task: TaskInfo = self.load_task_by_id(¶ms[0], ws)?;
|
||||
|
||||
task.set_comment(Comment::new(&comment_content, &self.nickname));
|
||||
set_event(&mut task, "comment", &self.nickname, &comment_content);
|
||||
|
||||
self.notify_queue_sender.send(task).await.map_err(Error::from)?;
|
||||
|
||||
@@ -413,6 +415,7 @@ impl JsonRpcInterface {
|
||||
let title: String = serde_json::from_value(title)?;
|
||||
if !title.is_empty() {
|
||||
task.set_title(&title);
|
||||
set_event(&mut task, "title", &self.nickname, &title);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,16 +425,23 @@ impl JsonRpcInterface {
|
||||
let description: Option<String> = serde_json::from_value(description.clone())?;
|
||||
if let Some(desc) = description {
|
||||
task.set_desc(&desc);
|
||||
set_event(&mut task, "desc", &self.nickname, &desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if fields.contains_key("rank") {
|
||||
let rank_opt = fields.get("rank");
|
||||
if let Some(rank) = rank_opt {
|
||||
let rank: Option<f32> = serde_json::from_value(rank.clone())?;
|
||||
if let Some(rank) = rank {
|
||||
task.set_rank(Some(rank));
|
||||
let rank_opt = fields.get("rank").unwrap();
|
||||
let rank: Option<Option<f32>> = serde_json::from_value(rank_opt.clone())?;
|
||||
if let Some(rank) = rank {
|
||||
task.set_rank(rank);
|
||||
match rank {
|
||||
Some(r) => {
|
||||
set_event(&mut task, "rank", &self.nickname, &r.to_string());
|
||||
}
|
||||
None => {
|
||||
set_event(&mut task, "rank", &self.nickname, "None");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -441,6 +451,14 @@ impl JsonRpcInterface {
|
||||
let due: Option<Option<Timestamp>> = serde_json::from_value(due)?;
|
||||
if let Some(d) = due {
|
||||
task.set_due(d);
|
||||
match d {
|
||||
Some(v) => {
|
||||
set_event(&mut task, "due", &self.nickname, &v.to_string());
|
||||
}
|
||||
None => {
|
||||
set_event(&mut task, "due", &self.nickname, "None");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,6 +467,7 @@ impl JsonRpcInterface {
|
||||
let assign: Vec<String> = serde_json::from_value(assign)?;
|
||||
if !assign.is_empty() {
|
||||
task.set_assign(&assign);
|
||||
set_event(&mut task, "assign", &self.nickname, &assign.join(", "));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,6 +476,7 @@ impl JsonRpcInterface {
|
||||
let project: Vec<String> = serde_json::from_value(project)?;
|
||||
if !project.is_empty() {
|
||||
task.set_project(&project);
|
||||
set_event(&mut task, "project", &self.nickname, &project.join(", "));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -465,6 +485,7 @@ impl JsonRpcInterface {
|
||||
let tags: Vec<String> = serde_json::from_value(tags)?;
|
||||
if !tags.is_empty() {
|
||||
task.set_tags(&tags);
|
||||
set_event(&mut task, "tags", &self.nickname, &tags.join(", "));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, SerialEncodable, SerialDecodable, PartialEq, Eq)]
|
||||
struct TaskEvent {
|
||||
pub struct TaskEvent {
|
||||
action: String,
|
||||
author: String,
|
||||
content: String,
|
||||
@@ -45,7 +45,7 @@ struct TaskEvent {
|
||||
}
|
||||
|
||||
impl TaskEvent {
|
||||
fn new(action: String, author: String, content: String) -> Self {
|
||||
pub fn new(action: String, author: String, content: String) -> Self {
|
||||
Self { action, author, content, timestamp: Timestamp::current_time() }
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ impl Comment {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
|
||||
pub struct TaskEvents(Vec<TaskEvent>);
|
||||
pub struct TaskEvents(pub Vec<TaskEvent>);
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
|
||||
pub struct TaskComments(Vec<Comment>);
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerialEncodable, SerialDecodable)]
|
||||
@@ -93,7 +93,7 @@ pub struct TaskInfo {
|
||||
rank: Option<f32>,
|
||||
created_at: Timestamp,
|
||||
state: String,
|
||||
events: TaskEvents,
|
||||
pub(crate) events: TaskEvents,
|
||||
comments: TaskComments,
|
||||
}
|
||||
|
||||
@@ -197,13 +197,11 @@ impl TaskInfo {
|
||||
pub fn set_title(&mut self, title: &str) {
|
||||
debug!(target: "tau", "TaskInfo::set_title()");
|
||||
self.title = title.into();
|
||||
self.set_event("title", title);
|
||||
}
|
||||
|
||||
pub fn set_desc(&mut self, desc: &str) {
|
||||
debug!(target: "tau", "TaskInfo::set_desc()");
|
||||
self.desc = desc.into();
|
||||
self.set_event("desc", desc);
|
||||
}
|
||||
|
||||
pub fn set_tags(&mut self, tags: &[String]) {
|
||||
@@ -217,58 +215,31 @@ impl TaskInfo {
|
||||
self.tags.0.retain(|tag| tag != &t);
|
||||
}
|
||||
}
|
||||
self.set_event("tags", &tags.join(", "));
|
||||
}
|
||||
|
||||
pub fn set_assign(&mut self, assigns: &[String]) {
|
||||
debug!(target: "tau", "TaskInfo::set_assign()");
|
||||
self.assign = TaskAssigns(assigns.to_owned());
|
||||
self.set_event("assign", &assigns.join(", "));
|
||||
}
|
||||
|
||||
pub fn set_project(&mut self, projects: &[String]) {
|
||||
debug!(target: "tau", "TaskInfo::set_project()");
|
||||
self.project = TaskProjects(projects.to_owned());
|
||||
self.set_event("project", &projects.join(", "));
|
||||
}
|
||||
|
||||
pub fn set_comment(&mut self, c: Comment) {
|
||||
debug!(target: "tau", "TaskInfo::set_comment()");
|
||||
self.comments.0.push(c.clone());
|
||||
self.set_event("comment", &c.content);
|
||||
self.comments.0.push(c);
|
||||
}
|
||||
|
||||
pub fn set_rank(&mut self, r: Option<f32>) {
|
||||
debug!(target: "tau", "TaskInfo::set_rank()");
|
||||
self.rank = r;
|
||||
match r {
|
||||
Some(v) => {
|
||||
self.set_event("rank", &v.to_string());
|
||||
}
|
||||
None => {
|
||||
self.set_event("rank", "None");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_due(&mut self, d: Option<Timestamp>) {
|
||||
debug!(target: "tau", "TaskInfo::set_due()");
|
||||
self.due = d;
|
||||
match d {
|
||||
Some(v) => {
|
||||
self.set_event("due", &v.to_string());
|
||||
}
|
||||
None => {
|
||||
self.set_event("due", "None");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_event(&mut self, action: &str, content: &str) {
|
||||
debug!(target: "tau", "TaskInfo::set_event()");
|
||||
if !content.is_empty() {
|
||||
self.events.0.push(TaskEvent::new(action.into(), self.owner.clone(), content.into()));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_state(&mut self, state: &str) {
|
||||
@@ -277,6 +248,5 @@ impl TaskInfo {
|
||||
return
|
||||
}
|
||||
self.state = state.to_string();
|
||||
self.set_event("state", state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use log::debug;
|
||||
|
||||
use crate::task_info::{TaskEvent, TaskInfo};
|
||||
|
||||
pub fn find_free_id(task_ids: &[u32]) -> u32 {
|
||||
for i in 1.. {
|
||||
if !task_ids.contains(&i) {
|
||||
@@ -25,6 +29,13 @@ pub fn find_free_id(task_ids: &[u32]) -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
pub fn set_event(task_info: &mut TaskInfo, action: &str, author: &str, content: &str) {
|
||||
debug!(target: "tau", "TaskInfo::set_event()");
|
||||
if !content.is_empty() {
|
||||
task_info.events.0.push(TaskEvent::new(action.into(), author.into(), content.into()));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user