Fix drag&drop

This commit is contained in:
Adrian Wozniak 2020-04-16 20:55:03 +02:00
parent 15095dc574
commit cf28ed7ef4
4 changed files with 767 additions and 755 deletions

View File

@ -192,11 +192,13 @@ fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>) {
Msg::AuthTokenStored => {
seed::push_route(vec!["dashboard"]);
orders.skip().send_msg(Msg::ChangePage(Page::Project));
authorize_or_redirect();
return;
}
Msg::AuthTokenErased => {
seed::push_route(vec!["login"]);
orders.skip().send_msg(Msg::ChangePage(Page::Login));
authorize_or_redirect();
return;
}
Msg::ChangePage(page) => {

View File

@ -18,11 +18,13 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
return;
}
match &model.page {
Page::Project | Page::AddIssue | Page::EditIssue(..) => {
match msg {
Msg::ChangePage(Page::Project)
| Msg::ChangePage(Page::AddIssue)
| Msg::ChangePage(Page::EditIssue(..)) => {
model.page_content = PageContent::Project(ProjectPage::default());
}
_ => return,
_ => (),
}
let project_page = match &mut model.page_content {
@ -103,13 +105,13 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
}
Msg::IssueDragStarted(issue_id) => crate::ws::issue::drag_started(issue_id, model),
Msg::IssueDragStopped(_) => {
project_page.dragged_issue_id = None;
crate::ws::issue::sync(model);
}
Msg::ExchangePosition(issue_bellow_id) => {
crate::ws::issue::exchange_position(issue_bellow_id, model)
}
Msg::IssueDragOverStatus(status) => crate::ws::issue::change_status(status, model),
Msg::IssueDropZone(status) => crate::ws::issue::dropped(status, model),
Msg::IssueDropZone(_status) => crate::ws::issue::sync(model),
Msg::DeleteIssue(issue_id) => {
send_ws_msg(jirs_data::WsMsg::IssueDeleteRequest(issue_id));
}

View File

@ -21,7 +21,6 @@ pub fn update(msg: Msg, model: &mut model::Model, orders: &mut impl Orders<Msg>)
}
if model.page != Page::ProjectSettings {
log!("not settings page");
return;
}

View File

@ -1,3 +1,5 @@
use seed::*;
use jirs_data::*;
use crate::api::send_ws_msg;
@ -9,7 +11,6 @@ pub fn drag_started(issue_id: IssueId, model: &mut Model) {
_ => return,
};
project_page.dragged_issue_id = Some(issue_id);
mark_dirty(issue_id, project_page);
}
@ -23,9 +24,9 @@ pub fn exchange_position(issue_bellow_id: IssueId, model: &mut Model) {
{
return;
}
let dragged_id = match project_page.dragged_issue_id {
let dragged_id = match project_page.dragged_issue_id.as_ref().cloned() {
Some(id) => id,
_ => return,
_ => return error!("Nothing is dragged"),
};
let mut below = None;
@ -78,7 +79,10 @@ pub fn exchange_position(issue_bellow_id: IssueId, model: &mut Model) {
project_page.last_drag_exchange_id = Some(issue_bellow_id);
}
pub fn dropped(_status: IssueStatus, model: &mut Model) {
pub fn sync(model: &mut Model) {
log!("------------------------------------------------------------------");
log!("| SYNC |");
log!("------------------------------------------------------------------");
let project_page = match &mut model.page_content {
PageContent::Project(project_page) => project_page,
_ => return,
@ -104,10 +108,12 @@ pub fn dropped(_status: IssueStatus, model: &mut Model) {
reporter_id: issue.reporter_id,
user_ids: issue.user_ids.clone(),
};
project_page.dragged_issue_id = None;
send_ws_msg(WsMsg::IssueUpdateRequest(issue.id, payload));
project_page.last_drag_exchange_id = None;
}
project_page.dragged_issue_id = None;
project_page.last_drag_exchange_id = None;
project_page.dirty_issues.clear();
}
pub fn change_status(status: IssueStatus, model: &mut Model) {
@ -118,7 +124,7 @@ pub fn change_status(status: IssueStatus, model: &mut Model) {
let issue_id = match project_page.dragged_issue_id.as_ref().cloned() {
Some(issue_id) => issue_id,
_ => return,
_ => return error!("Nothing is dragged"),
};
let mut old: Vec<Issue> = vec![];
@ -129,7 +135,10 @@ pub fn change_status(status: IssueStatus, model: &mut Model) {
for mut issue in old.into_iter() {
if issue.status == status {
if issue.list_position != pos {
issue.list_position = pos;
mark_dirty(issue.id, project_page);
}
pos += 1;
}
if issue.id != issue_id {
@ -149,12 +158,12 @@ pub fn change_status(status: IssueStatus, model: &mut Model) {
if issue.status == status {
model.issues.push(issue);
return;
}
} else {
issue.status = status;
issue.list_position = pos + 1;
model.issues.push(issue);
mark_dirty(issue_id, project_page);
}
}
#[inline]