Merge remote-tracking branch 'origin/master'

This commit is contained in:
Adrian Wozniak 2020-04-07 20:32:34 +02:00
commit 673453e08e
5 changed files with 61 additions and 16 deletions

View File

@ -98,7 +98,7 @@ pub fn update(msg: &Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>
project_id: Some(issue.project_id.clone()),
user_ids: Some(issue.user_ids.clone()),
};
send_ws_msg(jirs_data::WsMsg::IssueUpdateRequest(form));
send_ws_msg(jirs_data::WsMsg::IssueUpdateRequest(issue_id.clone(), form));
}
_ => {}
}

View File

@ -96,17 +96,24 @@ pub struct ProjectPage {
#[derive(Debug)]
pub struct Model {
pub host_url: String,
pub access_token: Option<Uuid>,
// mapped
pub comments_by_project_id: HashMap<ProjectId, Vec<Comment>>,
// forms
pub project_form: Option<UpdateProjectForm>,
pub issue_form: Option<CreateIssueForm>,
pub comment_form: Option<CreateCommentForm>,
pub comments_by_project_id: HashMap<ProjectId, Vec<Comment>>,
pub page: Page,
pub host_url: String,
pub project_page: ProjectPage,
// modals
pub modals: Vec<ModalType>,
// pages
pub page: Page,
pub project_page: ProjectPage,
pub project: Option<Project>,
pub user: Option<User>,
pub issues: Vec<Issue>,

View File

@ -133,7 +133,7 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
user_ids: Some(issue.user_ids.clone()),
};
model.project_page.dragged_issue_id = None;
send_ws_msg(WsMsg::IssueUpdateRequest(payload));
send_ws_msg(WsMsg::IssueUpdateRequest(issue_id, payload));
}
_ => error!("Drag stopped before drop :("),
},

View File

@ -406,7 +406,7 @@ pub enum WsMsg {
ProjectUsersLoaded(Vec<User>),
// issue
IssueUpdateRequest(UpdateIssuePayload),
IssueUpdateRequest(i32, UpdateIssuePayload),
IssueUpdated(Issue),
IssueDeleteRequest(i32),
IssueDeleted(i32),

View File

@ -6,7 +6,7 @@ use actix_web_actors::ws;
use jirs_data::{Project, WsMsg};
use crate::db::authorize_user::AuthorizeUser;
use crate::db::issues::LoadProjectIssues;
use crate::db::issues::{LoadProjectIssues, UpdateIssue};
use crate::db::projects::LoadCurrentProject;
use crate::db::users::LoadProjectUsers;
use crate::db::DbExecutor;
@ -53,14 +53,9 @@ impl WebSocketActor {
Err("Invalid auth token".to_string()),
)),
},
WsMsg::ProjectIssuesRequest => match block_on(self.load_issues()) {
Some(msg) => Some(msg),
_ => None,
},
WsMsg::ProjectUsersRequest => match block_on(self.load_project_users()) {
Some(msg) => Some(msg),
_ => None,
},
WsMsg::ProjectIssuesRequest => block_on(self.load_issues()),
WsMsg::ProjectUsersRequest => block_on(self.load_project_users()),
WsMsg::IssueUpdateRequest(id, payload) => block_on(self.update_issue(id, payload)),
_ => {
error!("Failed to resolve message");
None
@ -115,6 +110,49 @@ impl WebSocketActor {
_ => None,
}
}
async fn update_issue(
&mut self,
issue_id: i32,
payload: jirs_data::UpdateIssuePayload,
) -> Option<WsMsg> {
let jirs_data::UpdateIssuePayload {
title,
issue_type,
status,
priority,
list_position,
description,
description_text,
estimate,
time_spent,
time_remaining,
project_id,
user_ids,
} = payload;
match self
.db
.send(UpdateIssue {
issue_id,
title,
issue_type,
status,
priority,
list_position,
description,
description_text,
estimate,
time_spent,
time_remaining,
project_id,
user_ids,
})
.await
{
Ok(Ok(issue)) => Some(WsMsg::IssueUpdated(issue.into())),
_ => None,
}
}
}
impl StreamHandler<Result<ws::Message, ws::ProtocolError>> for WebSocketActor {