2022-04-07 08:33:10 +08:00
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
use flowy_error::ErrorCode;
|
2022-04-11 15:27:03 +08:00
|
|
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
2022-07-01 20:32:11 +08:00
|
|
|
use flowy_grid_data_model::revision::{CellRevision, RowMetaChangeset};
|
|
|
|
use std::collections::HashMap;
|
2022-04-07 08:33:10 +08:00
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default)]
|
2022-07-17 14:13:12 +08:00
|
|
|
pub struct CreateSelectOptionPayloadPB {
|
2022-04-07 08:33:10 +08:00
|
|
|
#[pb(index = 1)]
|
2022-07-25 13:15:11 +08:00
|
|
|
pub field_id: String,
|
2022-04-07 08:33:10 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2022-07-25 13:15:11 +08:00
|
|
|
pub grid_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
2022-04-07 08:33:10 +08:00
|
|
|
pub option_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CreateSelectOptionParams {
|
2022-07-25 13:15:11 +08:00
|
|
|
pub field_id: String,
|
|
|
|
pub grid_id: String,
|
2022-04-07 08:33:10 +08:00
|
|
|
pub option_name: String,
|
2022-04-18 17:17:42 +08:00
|
|
|
}
|
|
|
|
|
2022-07-17 14:13:12 +08:00
|
|
|
impl TryInto<CreateSelectOptionParams> for CreateSelectOptionPayloadPB {
|
2022-04-07 08:33:10 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<CreateSelectOptionParams, Self::Error> {
|
|
|
|
let option_name = NotEmptyStr::parse(self.option_name).map_err(|_| ErrorCode::SelectOptionNameIsEmpty)?;
|
2022-07-25 13:15:11 +08:00
|
|
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
|
|
|
let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
|
2022-04-07 08:33:10 +08:00
|
|
|
Ok(CreateSelectOptionParams {
|
2022-07-25 13:15:11 +08:00
|
|
|
field_id: field_id.0,
|
2022-04-07 08:33:10 +08:00
|
|
|
option_name: option_name.0,
|
2022-07-25 13:15:11 +08:00
|
|
|
grid_id: grid_id.0,
|
2022-04-07 08:33:10 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
2022-07-25 13:15:11 +08:00
|
|
|
pub struct GridCellIdPB {
|
2022-04-07 08:33:10 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub grid_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub row_id: String,
|
|
|
|
}
|
|
|
|
|
2022-07-25 13:15:11 +08:00
|
|
|
pub struct GridCellIdParams {
|
2022-04-07 08:33:10 +08:00
|
|
|
pub grid_id: String,
|
|
|
|
pub field_id: String,
|
|
|
|
pub row_id: String,
|
|
|
|
}
|
|
|
|
|
2022-07-25 13:15:11 +08:00
|
|
|
impl TryInto<GridCellIdParams> for GridCellIdPB {
|
2022-04-07 08:33:10 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
2022-07-25 13:15:11 +08:00
|
|
|
fn try_into(self) -> Result<GridCellIdParams, Self::Error> {
|
2022-04-11 15:27:03 +08:00
|
|
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
|
|
|
let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
|
|
|
|
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
|
2022-07-25 13:15:11 +08:00
|
|
|
Ok(GridCellIdParams {
|
2022-04-07 08:33:10 +08:00
|
|
|
grid_id: grid_id.0,
|
|
|
|
field_id: field_id.0,
|
|
|
|
row_id: row_id.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 20:32:11 +08:00
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
2022-07-17 14:13:12 +08:00
|
|
|
pub struct GridCellPB {
|
2022-07-01 20:32:11 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub data: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
2022-07-17 14:13:12 +08:00
|
|
|
impl GridCellPB {
|
2022-07-01 20:32:11 +08:00
|
|
|
pub fn new(field_id: &str, data: Vec<u8>) -> Self {
|
|
|
|
Self {
|
|
|
|
field_id: field_id.to_owned(),
|
|
|
|
data,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn empty(field_id: &str) -> Self {
|
|
|
|
Self {
|
|
|
|
field_id: field_id.to_owned(),
|
|
|
|
data: vec![],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
2022-07-17 14:13:12 +08:00
|
|
|
pub struct RepeatedCellPB {
|
2022-07-01 20:32:11 +08:00
|
|
|
#[pb(index = 1)]
|
2022-07-17 14:13:12 +08:00
|
|
|
pub items: Vec<GridCellPB>,
|
2022-07-01 20:32:11 +08:00
|
|
|
}
|
|
|
|
|
2022-07-17 14:13:12 +08:00
|
|
|
impl std::ops::Deref for RepeatedCellPB {
|
|
|
|
type Target = Vec<GridCellPB>;
|
2022-07-01 20:32:11 +08:00
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-17 14:13:12 +08:00
|
|
|
impl std::ops::DerefMut for RepeatedCellPB {
|
2022-07-01 20:32:11 +08:00
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-17 14:13:12 +08:00
|
|
|
impl std::convert::From<Vec<GridCellPB>> for RepeatedCellPB {
|
|
|
|
fn from(items: Vec<GridCellPB>) -> Self {
|
2022-07-01 20:32:11 +08:00
|
|
|
Self { items }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-25 12:45:35 +08:00
|
|
|
///
|
2022-07-01 20:32:11 +08:00
|
|
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
2022-07-17 14:13:12 +08:00
|
|
|
pub struct CellChangesetPB {
|
2022-07-01 20:32:11 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub grid_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub row_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
2022-07-08 14:54:11 +08:00
|
|
|
pub content: Option<String>,
|
2022-07-01 20:32:11 +08:00
|
|
|
}
|
|
|
|
|
2022-07-17 14:13:12 +08:00
|
|
|
impl std::convert::From<CellChangesetPB> for RowMetaChangeset {
|
|
|
|
fn from(changeset: CellChangesetPB) -> Self {
|
2022-07-01 20:32:11 +08:00
|
|
|
let mut cell_by_field_id = HashMap::with_capacity(1);
|
|
|
|
let field_id = changeset.field_id;
|
|
|
|
let cell_rev = CellRevision {
|
2022-07-08 14:54:11 +08:00
|
|
|
data: changeset.content.unwrap_or_else(|| "".to_owned()),
|
2022-07-01 20:32:11 +08:00
|
|
|
};
|
|
|
|
cell_by_field_id.insert(field_id, cell_rev);
|
|
|
|
|
|
|
|
RowMetaChangeset {
|
|
|
|
row_id: changeset.row_id,
|
|
|
|
height: None,
|
|
|
|
visibility: None,
|
|
|
|
cell_by_field_id,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|