2022-06-15 17:24:46 +08:00
|
|
|
use crate::parser::{NotEmptyStr, ViewFilterParser, ViewGroupParser, ViewSortParser};
|
2022-06-19 21:10:07 +08:00
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
2022-06-15 17:24:46 +08:00
|
|
|
use flowy_error_code::ErrorCode;
|
2022-06-19 21:10:07 +08:00
|
|
|
use std::collections::HashMap;
|
2022-06-15 17:24:46 +08:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub struct GridSetting {
|
2022-06-15 17:24:46 +08:00
|
|
|
#[pb(index = 1)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub filter: HashMap<String, GridFilter>,
|
2022-06-15 17:24:46 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub group: HashMap<String, GridGroup>,
|
2022-06-15 17:24:46 +08:00
|
|
|
|
|
|
|
#[pb(index = 3)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub sort: HashMap<String, GridSort>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)]
|
|
|
|
#[repr(u8)]
|
|
|
|
pub enum GridLayoutType {
|
|
|
|
Table = 0,
|
|
|
|
Board = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::default::Default for GridLayoutType {
|
|
|
|
fn default() -> Self {
|
|
|
|
GridLayoutType::Table
|
|
|
|
}
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub struct GridFilter {
|
2022-06-15 17:24:46 +08:00
|
|
|
#[pb(index = 1, one_of)]
|
|
|
|
pub field_id: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub struct GridGroup {
|
2022-06-15 17:24:46 +08:00
|
|
|
#[pb(index = 1, one_of)]
|
|
|
|
pub group_field_id: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub sub_group_field_id: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub struct GridSort {
|
2022-06-15 17:24:46 +08:00
|
|
|
#[pb(index = 1, one_of)]
|
|
|
|
pub field_id: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub struct GridSettingChangesetPayload {
|
2022-06-15 17:24:46 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub grid_id: String,
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
#[pb(index = 2)]
|
|
|
|
pub layout_type: GridLayoutType,
|
2022-06-15 17:24:46 +08:00
|
|
|
|
|
|
|
#[pb(index = 3, one_of)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub filter: Option<GridFilter>,
|
2022-06-15 17:24:46 +08:00
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
2022-06-19 21:10:07 +08:00
|
|
|
pub group: Option<GridGroup>,
|
|
|
|
|
|
|
|
#[pb(index = 5, one_of)]
|
|
|
|
pub sort: Option<GridSort>,
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
pub struct GridSettingChangesetParams {
|
2022-06-20 09:37:52 +08:00
|
|
|
pub grid_id: String,
|
2022-06-19 21:10:07 +08:00
|
|
|
pub layout_type: GridLayoutType,
|
|
|
|
pub filter: Option<GridFilter>,
|
|
|
|
pub group: Option<GridGroup>,
|
|
|
|
pub sort: Option<GridSort>,
|
2022-06-15 17:24:46 +08:00
|
|
|
}
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
impl TryInto<GridSettingChangesetParams> for GridSettingChangesetPayload {
|
2022-06-15 17:24:46 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
fn try_into(self) -> Result<GridSettingChangesetParams, Self::Error> {
|
2022-06-15 17:24:46 +08:00
|
|
|
let view_id = NotEmptyStr::parse(self.grid_id)
|
|
|
|
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
|
|
|
.0;
|
|
|
|
|
|
|
|
let filter = match self.filter {
|
|
|
|
None => None,
|
|
|
|
Some(filter) => Some(ViewFilterParser::parse(filter)?),
|
|
|
|
};
|
|
|
|
|
|
|
|
let group = match self.group {
|
|
|
|
None => None,
|
|
|
|
Some(group) => Some(ViewGroupParser::parse(group)?),
|
|
|
|
};
|
|
|
|
|
|
|
|
let sort = match self.sort {
|
|
|
|
None => None,
|
|
|
|
Some(sort) => Some(ViewSortParser::parse(sort)?),
|
|
|
|
};
|
|
|
|
|
2022-06-19 21:10:07 +08:00
|
|
|
Ok(GridSettingChangesetParams {
|
2022-06-20 09:37:52 +08:00
|
|
|
grid_id: view_id,
|
2022-06-19 21:10:07 +08:00
|
|
|
layout_type: self.layout_type,
|
2022-06-15 17:24:46 +08:00
|
|
|
filter,
|
|
|
|
group,
|
|
|
|
sort,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|