Remove deprecated issue status

This commit is contained in:
Adrian Wozniak 2020-03-31 23:49:46 +02:00
parent d272b6a1dc
commit 4be598b9ae
12 changed files with 52 additions and 80 deletions

View File

@ -1,3 +1,5 @@
use seed::Method;
use jirs_data::UpdateIssuePayload;
use crate::shared::host_client;
@ -22,9 +24,11 @@ pub async fn update_issue(
id: i32,
payload: UpdateIssuePayload,
) -> Result<Msg, Msg> {
match host_client(host_url, format!("/issue/{id}", id = id).as_str()) {
match host_client(host_url, format!("/issues/{id}", id = id).as_str()) {
Ok(client) => {
client
.method(Method::Put)
.header("Content-Type", "application/json")
.body_json(&payload)
.fetch_json(Msg::IssueUpdateResult)
.await

View File

@ -1,4 +1,5 @@
use seed::fetch::{FetchObject, ResponseWithDataResult};
use seed::*;
use jirs_data::{FullProjectResponse, Issue};
@ -51,6 +52,8 @@ pub fn current_project_response(fetched: &FetchObject<String>, model: &mut Model
}
pub fn update_issue_response(fetched: &FetchObject<String>, model: &mut Model) {
log!("update_issue_response");
log!(fetched);
if let FetchObject {
result:
Ok(ResponseWithDataResult {

View File

@ -8,7 +8,6 @@ use jirs_data::*;
use crate::{IssueId, UserId, HOST_URL};
pub type ProjectId = i32;
pub type StatusCode = u32;
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialOrd, PartialEq)]
#[serde(rename_all = "kebab-case")]

View File

@ -6,7 +6,7 @@ use crate::model::{Icon, Model, Page};
use crate::shared::styled_avatar::StyledAvatar;
use crate::shared::styled_button::{StyledButton, Variant};
use crate::shared::styled_input::StyledInput;
use crate::shared::{drag_ev, host_client, inner_layout, ToNode};
use crate::shared::{drag_ev, inner_layout, ToNode};
use crate::Msg;
pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Orders<Msg>) {
@ -71,7 +71,7 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
let mut position = 0f64;
let mut found: Option<&mut Issue> = None;
for issue in project.issues.iter_mut() {
if issue.status == status.to_payload() {
if issue.status == status {
position += 1f64;
}
if issue.id == issue_id {
@ -80,22 +80,23 @@ pub fn update(msg: Msg, model: &mut crate::model::Model, orders: &mut impl Order
}
}
if let Some(issue) = found {
issue.status = status.to_payload().to_string();
issue.status = status.clone();
issue.list_position = position + 1f64;
let payload = UpdateIssuePayload {
title: None,
issue_type: None,
title: Some(issue.title.clone()),
issue_type: Some(issue.issue_type.clone()),
status: Some(status.to_payload().to_string()),
priority: None,
list_position: Some(position + 1f64),
description: None,
description_text: None,
estimate: None,
time_spent: None,
time_remaining: None,
project_id: None,
users: None,
user_ids: None,
priority: Some(issue.priority.clone()),
list_position: Some(issue.list_position),
description: Some(issue.description.clone()),
description_text: Some(issue.description_text.clone()),
estimate: Some(issue.estimate),
time_spent: Some(issue.time_spent),
time_remaining: Some(issue.time_remaining),
project_id: Some(issue.project_id),
users: Some(vec![]),
user_ids: Some(issue.user_ids.clone()),
};
orders.skip().perform_cmd(crate::api::update_issue(
model.host_url.clone(),
@ -269,7 +270,7 @@ fn project_issue_list(model: &Model, status: jirs_data::IssueStatus) -> Node<Msg
let issues: Vec<Node<Msg>> = project
.issues
.iter()
.filter(|issue| status.match_name(issue.status.as_str()))
.filter(|issue| status == issue.status)
.map(|issue| project_issue(model, project, issue))
.collect();
let label = status.to_label();
@ -316,7 +317,7 @@ fn project_issue(model: &Model, project: &FullProject, issue: &Issue) -> Node<Ms
})
.collect();
let mut issue_type_icon = match issue.issue_type.parse::<IssueType>() {
let issue_type_icon = match issue.issue_type.parse::<IssueType>() {
Ok(icon) => {
let mut node = crate::shared::styled_icon(icon.into());
node.add_style(
@ -341,7 +342,7 @@ fn project_issue(model: &Model, project: &FullProject, issue: &Issue) -> Node<Ms
};
let issue_id = issue.id;
let drag_started = drag_ev(Ev::DragStart, move |event| Msg::IssueDragStarted(issue_id));
let drag_started = drag_ev(Ev::DragStart, move |_| Msg::IssueDragStarted(issue_id));
let drag_stopped = drag_ev(Ev::DragEnd, move |_| Msg::IssueDragStopped(issue_id));
let mut class_list = vec!["issue"];

View File

@ -1,9 +1,6 @@
use seed::fetch::{FetchObject, ResponseWithDataResult};
use seed::{prelude::*, *};
use wasm_bindgen::JsCast;
use jirs_data::FullProjectResponse;
use crate::model::{Icon, Model};
use crate::Msg;

View File

@ -1 +1 @@
./LICENSE
../LICENSE

View File

@ -50,6 +50,20 @@ pub enum IssueStatus {
Done,
}
impl FromStr for IssueStatus {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"backlog" => Ok(IssueStatus::Backlog),
"selected" => Ok(IssueStatus::Selected),
"in_progress" => Ok(IssueStatus::InProgress),
"done" => Ok(IssueStatus::Done),
_ => Err(format!("Invalid status {:?}", s)),
}
}
}
impl IssueStatus {
pub fn to_label(&self) -> &str {
match self {
@ -69,18 +83,8 @@ impl IssueStatus {
}
}
#[deprecated]
pub fn to_deprecated_payload(&self) -> &str {
match self {
IssueStatus::Backlog => "backlog",
IssueStatus::Selected => "selected",
IssueStatus::InProgress => "inprogress",
IssueStatus::Done => "done",
}
}
pub fn match_name(&self, name: &str) -> bool {
self.to_payload() == name || self.to_deprecated_payload() == name
self.to_payload() == name
}
}
@ -232,7 +236,7 @@ pub struct Issue {
pub title: String,
#[serde(rename = "type")]
pub issue_type: String,
pub status: String,
pub status: IssueStatus,
pub priority: String,
pub list_position: f64,
pub description: Option<String>,

View File

@ -1 +1 @@
./LICENSE
../LICENSE

View File

@ -2,6 +2,8 @@ use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use jirs_data::IssueStatus;
use crate::schema::*;
#[derive(Debug, Serialize, Deserialize, Queryable)]
@ -66,7 +68,11 @@ impl Into<jirs_data::Issue> for Issue {
id: self.id,
title: self.title,
issue_type: self.issue_type,
status: self.status,
status: self
.status
.as_str()
.parse::<IssueStatus>()
.unwrap_or_else(|_| IssueStatus::Backlog),
priority: self.priority,
list_position: self.list_position,
description: self.description,

View File

View File

@ -1,6 +0,0 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();

View File

@ -1,36 +0,0 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
-- Sets up a trigger for the given table to automatically set a column called
-- `updated_at` whenever the row is modified (unless `updated_at` was included
-- in the modified columns)
--
-- # Example
--
-- ```sql
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
--
-- SELECT diesel_manage_updated_at('users');
-- ```
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
BEGIN
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
BEGIN
IF (
NEW IS DISTINCT FROM OLD AND
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
) THEN
NEW.updated_at := current_timestamp;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;