2022-06-19 21:10:07 +08:00
|
|
|
use crate::entities::{GridFilter, GridGroup, GridLayoutType, GridSetting, GridSort};
|
|
|
|
use indexmap::IndexMap;
|
2022-06-15 17:24:46 +08:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use serde_repr::*;
|
2022-06-19 21:10:07 +08:00
|
|
|
use std::collections::HashMap;
|
2022-06-15 17:24:46 +08:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
2022-06-20 09:37:52 +08:00
|
|
|
pub struct GridSettingRevision {
|
2022-06-19 21:10:07 +08:00
|
|
|
#[serde(with = "indexmap::serde_seq")]
|
|
|
|
pub filter: IndexMap<GridLayoutRevision, GridFilterRevision>,
|
2022-06-15 17:24:46 +08:00
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
#[serde(with = "indexmap::serde_seq")]
|
|
|
|
pub group: IndexMap<GridLayoutRevision, GridGroupRevision>,
|
|
|
|
|
|
|
|
#[serde(with = "indexmap::serde_seq")]
|
|
|
|
pub sort: IndexMap<GridLayoutRevision, GridSortRevision>,
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize_repr, Deserialize_repr)]
|
2022-06-15 17:24:46 +08:00
|
|
|
#[repr(u8)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub enum GridLayoutRevision {
|
2022-06-15 17:24:46 +08:00
|
|
|
Table = 0,
|
|
|
|
Board = 1,
|
|
|
|
}
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
impl ToString for GridLayoutRevision {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
let layout_rev = self.clone() as u8;
|
|
|
|
layout_rev.to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::default::Default for GridLayoutRevision {
|
2022-06-15 17:24:46 +08:00
|
|
|
fn default() -> Self {
|
2022-06-19 21:10:07 +08:00
|
|
|
GridLayoutRevision::Table
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 09:37:52 +08:00
|
|
|
impl std::convert::From<GridLayoutRevision> for GridLayoutType {
|
|
|
|
fn from(rev: GridLayoutRevision) -> Self {
|
|
|
|
match rev {
|
|
|
|
GridLayoutRevision::Table => GridLayoutType::Table,
|
|
|
|
GridLayoutRevision::Board => GridLayoutType::Board,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<GridLayoutType> for GridLayoutRevision {
|
|
|
|
fn from(layout: GridLayoutType) -> Self {
|
|
|
|
match layout {
|
|
|
|
GridLayoutType::Table => GridLayoutRevision::Table,
|
|
|
|
GridLayoutType::Board => GridLayoutRevision::Board,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 17:24:46 +08:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
|
|
pub struct GridFilterRevision {
|
|
|
|
pub field_id: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
|
|
pub struct GridGroupRevision {
|
|
|
|
pub group_field_id: Option<String>,
|
|
|
|
pub sub_group_field_id: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
|
|
|
pub struct GridSortRevision {
|
2022-06-20 09:37:52 +08:00
|
|
|
pub field_id: Option<String>,
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
impl std::convert::From<GridFilterRevision> for GridFilter {
|
2022-06-15 17:24:46 +08:00
|
|
|
fn from(rev: GridFilterRevision) -> Self {
|
2022-06-19 21:10:07 +08:00
|
|
|
GridFilter { field_id: rev.field_id }
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
impl std::convert::From<GridGroupRevision> for GridGroup {
|
2022-06-15 17:24:46 +08:00
|
|
|
fn from(rev: GridGroupRevision) -> Self {
|
2022-06-19 21:10:07 +08:00
|
|
|
GridGroup {
|
2022-06-15 17:24:46 +08:00
|
|
|
group_field_id: rev.group_field_id,
|
|
|
|
sub_group_field_id: rev.sub_group_field_id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
impl std::convert::From<GridSortRevision> for GridSort {
|
2022-06-15 17:24:46 +08:00
|
|
|
fn from(rev: GridSortRevision) -> Self {
|
2022-06-19 21:10:07 +08:00
|
|
|
GridSort { field_id: rev.field_id }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-20 09:37:52 +08:00
|
|
|
impl std::convert::From<GridSettingRevision> for GridSetting {
|
|
|
|
fn from(rev: GridSettingRevision) -> Self {
|
2022-06-19 21:10:07 +08:00
|
|
|
let filter: HashMap<String, GridFilter> = rev
|
|
|
|
.filter
|
|
|
|
.into_iter()
|
|
|
|
.map(|(layout_rev, filter_rev)| (layout_rev.to_string(), filter_rev.into()))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let group: HashMap<String, GridGroup> = rev
|
|
|
|
.group
|
|
|
|
.into_iter()
|
|
|
|
.map(|(layout_rev, group_rev)| (layout_rev.to_string(), group_rev.into()))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let sort: HashMap<String, GridSort> = rev
|
|
|
|
.sort
|
|
|
|
.into_iter()
|
|
|
|
.map(|(layout_rev, sort_rev)| (layout_rev.to_string(), sort_rev.into()))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
GridSetting { filter, group, sort }
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
}
|