bitque/jirs-client/src/model.rs

172 lines
4.2 KiB
Rust
Raw Normal View History

2020-03-30 08:16:26 +02:00
use std::collections::hash_map::HashMap;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use jirs_data::*;
2020-03-30 14:56:22 +02:00
use crate::HOST_URL;
2020-03-30 14:26:25 +02:00
pub type ProjectId = i32;
pub type StatusCode = u32;
2020-03-30 08:16:26 +02:00
2020-03-30 14:56:22 +02:00
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialOrd, PartialEq)]
#[serde(rename_all = "kebab-case")]
2020-03-30 14:26:25 +02:00
pub enum Page {
Project,
ProjectSettings,
Login,
Register,
}
2020-03-30 14:56:22 +02:00
impl Page {
pub fn to_path(&self) -> String {
match self {
Page::Project => "/board",
Page::ProjectSettings => "/project-settings",
Page::Login => "/login",
Page::Register => "/register",
}
.to_string()
}
}
2020-03-30 14:26:25 +02:00
#[derive(Serialize, Deserialize, Debug)]
2020-03-30 08:16:26 +02:00
pub struct CreateCommentForm {
2020-03-30 14:26:25 +02:00
pub fields: CreateCommentPayload,
2020-03-30 08:16:26 +02:00
}
2020-03-30 14:26:25 +02:00
#[derive(Serialize, Deserialize, Debug)]
2020-03-30 08:16:26 +02:00
pub struct CreateIssueForm {
2020-03-30 14:26:25 +02:00
pub fields: CreateIssuePayload,
2020-03-30 08:16:26 +02:00
}
2020-03-30 14:26:25 +02:00
#[derive(Serialize, Deserialize, Debug)]
2020-03-30 08:16:26 +02:00
pub struct UpdateProjectForm {
2020-03-30 14:26:25 +02:00
pub id: ProjectId,
pub fields: UpdateProjectPayload,
2020-03-30 08:16:26 +02:00
}
#[derive(Serialize, Deserialize, Debug)]
pub struct ProjectPage {
pub about_tooltip_visible: bool,
pub text_filter: String,
2020-03-31 11:11:06 +02:00
pub active_avatar_filters: Vec<i32>,
pub only_my_filter: bool,
}
2020-03-30 14:26:25 +02:00
#[derive(Serialize, Deserialize, Debug)]
2020-03-30 08:16:26 +02:00
pub struct Model {
2020-03-30 14:26:25 +02:00
pub access_token: Option<Uuid>,
pub user: Option<User>,
pub project: Option<FullProject>,
pub project_form: Option<UpdateProjectForm>,
pub issue_form: Option<CreateIssueForm>,
pub comment_form: Option<CreateCommentForm>,
pub issues: Vec<Issue>,
pub comments_by_project_id: HashMap<ProjectId, Vec<Comment>>,
pub page: Page,
pub host_url: String,
pub project_page: ProjectPage,
2020-03-30 08:16:26 +02:00
}
impl Default for Model {
fn default() -> Self {
2020-03-30 14:26:25 +02:00
let host_url = unsafe { HOST_URL.clone() };
2020-03-30 08:16:26 +02:00
Self {
access_token: None,
project: None,
user: None,
issue_form: None,
project_form: None,
comment_form: None,
issues: vec![],
comments_by_project_id: Default::default(),
2020-03-30 14:26:25 +02:00
page: Page::Project,
host_url,
project_page: ProjectPage {
about_tooltip_visible: false,
text_filter: "".to_string(),
2020-03-31 11:11:06 +02:00
active_avatar_filters: vec![],
only_my_filter: false,
},
2020-03-30 08:16:26 +02:00
}
}
}
2020-03-30 14:26:25 +02:00
#[derive(Copy, Clone, Debug)]
pub enum Icon {
Bug,
Stopwatch,
Task,
Story,
ArrowDown,
ArrowLeftCircle,
ArrowUp,
ChevronDown,
ChevronLeft,
ChevronRight,
ChevronUp,
Board,
Help,
Link,
Menu,
More,
Attach,
Plus,
Search,
Issues,
Settings,
Close,
Feedback,
Trash,
Github,
Shipping,
Component,
Reports,
Page,
Calendar,
ArrowLeft,
ArrowRight,
}
impl std::fmt::Display for Icon {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let code = match self {
Icon::Bug => "bug",
Icon::Stopwatch => "stopwatch",
Icon::Task => "task",
Icon::Story => "story",
Icon::ArrowDown => "arrowDown",
Icon::ArrowLeftCircle => "arrowLeftCircle",
Icon::ArrowUp => "arrowUp",
Icon::ChevronDown => "chevronDown",
Icon::ChevronLeft => "chevronLeft",
Icon::ChevronRight => "chevronRight",
Icon::ChevronUp => "chevronUp",
Icon::Board => "board",
Icon::Help => "help",
Icon::Link => "link",
Icon::Menu => "menu",
Icon::More => "more",
Icon::Attach => "attach",
Icon::Plus => "plus",
Icon::Search => "search",
Icon::Issues => "issues",
Icon::Settings => "settings",
Icon::Close => "close",
Icon::Feedback => "feedback",
Icon::Trash => "trash",
Icon::Github => "github",
Icon::Shipping => "shipping",
Icon::Component => "component",
Icon::Reports => "reports",
Icon::Page => "page",
Icon::Calendar => "calendar",
Icon::ArrowLeft => "arrowLeft",
Icon::ArrowRight => "arrowRight",
};
f.write_str(code)
}
}