2021-07-19 22:44:37 +08:00
|
|
|
use crate::{
|
2022-07-04 14:28:41 +08:00
|
|
|
entities::parser::{
|
2021-12-31 10:32:25 +08:00
|
|
|
app::AppIdentify,
|
2022-03-16 10:02:37 +08:00
|
|
|
view::{ViewDesc, ViewIdentify, ViewName, ViewThumbnail},
|
2021-11-07 23:23:16 +08:00
|
|
|
},
|
2022-07-04 14:28:41 +08:00
|
|
|
errors::ErrorCode,
|
|
|
|
impl_def_and_def_mut,
|
2021-07-19 22:44:37 +08:00
|
|
|
};
|
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
2022-11-08 13:43:41 +08:00
|
|
|
use folder_rev_model::{gen_view_id, ViewDataFormatRevision, ViewLayoutTypeRevision, ViewRevision};
|
2021-07-19 22:44:37 +08:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2022-06-13 20:59:46 +08:00
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub struct ViewPB {
|
2022-01-13 11:16:26 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2022-08-18 17:40:23 +08:00
|
|
|
pub app_id: String,
|
2022-01-13 11:16:26 +08:00
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub name: String,
|
|
|
|
|
2022-06-13 20:59:46 +08:00
|
|
|
#[pb(index = 4)]
|
2022-10-22 21:57:44 +08:00
|
|
|
pub data_format: ViewDataFormatPB,
|
2022-06-13 20:59:46 +08:00
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub modified_time: i64,
|
|
|
|
|
|
|
|
#[pb(index = 6)]
|
|
|
|
pub create_time: i64,
|
|
|
|
|
|
|
|
#[pb(index = 7)]
|
2022-08-18 19:32:08 +08:00
|
|
|
pub layout: ViewLayoutTypePB,
|
2022-06-13 20:59:46 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl std::convert::From<ViewRevision> for ViewPB {
|
2022-07-04 14:28:41 +08:00
|
|
|
fn from(rev: ViewRevision) -> Self {
|
2022-07-19 14:11:29 +08:00
|
|
|
ViewPB {
|
2022-07-04 14:28:41 +08:00
|
|
|
id: rev.id,
|
2022-08-18 17:40:23 +08:00
|
|
|
app_id: rev.app_id,
|
2022-07-04 14:28:41 +08:00
|
|
|
name: rev.name,
|
2022-10-22 21:57:44 +08:00
|
|
|
data_format: rev.data_format.into(),
|
2022-07-04 14:28:41 +08:00
|
|
|
modified_time: rev.modified_time,
|
|
|
|
create_time: rev.create_time,
|
2022-08-18 19:32:08 +08:00
|
|
|
layout: rev.layout.into(),
|
2022-07-04 14:28:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
2022-10-22 21:57:44 +08:00
|
|
|
pub enum ViewDataFormatPB {
|
|
|
|
DeltaFormat = 0,
|
|
|
|
DatabaseFormat = 1,
|
|
|
|
TreeFormat = 2,
|
2021-07-19 22:44:37 +08:00
|
|
|
}
|
|
|
|
|
2022-10-22 21:57:44 +08:00
|
|
|
impl std::default::Default for ViewDataFormatPB {
|
2022-01-24 17:35:58 +08:00
|
|
|
fn default() -> Self {
|
2022-10-22 21:57:44 +08:00
|
|
|
ViewDataFormatRevision::default().into()
|
2022-07-04 14:28:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-22 21:57:44 +08:00
|
|
|
impl std::convert::From<ViewDataFormatRevision> for ViewDataFormatPB {
|
|
|
|
fn from(rev: ViewDataFormatRevision) -> Self {
|
2022-07-04 14:28:41 +08:00
|
|
|
match rev {
|
2022-10-22 21:57:44 +08:00
|
|
|
ViewDataFormatRevision::DeltaFormat => ViewDataFormatPB::DeltaFormat,
|
|
|
|
ViewDataFormatRevision::DatabaseFormat => ViewDataFormatPB::DatabaseFormat,
|
|
|
|
ViewDataFormatRevision::TreeFormat => ViewDataFormatPB::TreeFormat,
|
2022-07-04 14:28:41 +08:00
|
|
|
}
|
2022-01-24 17:35:58 +08:00
|
|
|
}
|
2021-07-19 22:44:37 +08:00
|
|
|
}
|
|
|
|
|
2022-10-22 21:57:44 +08:00
|
|
|
impl std::convert::From<ViewDataFormatPB> for ViewDataFormatRevision {
|
|
|
|
fn from(ty: ViewDataFormatPB) -> Self {
|
2022-07-04 14:28:41 +08:00
|
|
|
match ty {
|
2022-10-22 21:57:44 +08:00
|
|
|
ViewDataFormatPB::DeltaFormat => ViewDataFormatRevision::DeltaFormat,
|
|
|
|
ViewDataFormatPB::DatabaseFormat => ViewDataFormatRevision::DatabaseFormat,
|
|
|
|
ViewDataFormatPB::TreeFormat => ViewDataFormatRevision::TreeFormat,
|
2021-08-25 21:33:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-18 17:40:23 +08:00
|
|
|
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
|
|
|
pub enum ViewLayoutTypePB {
|
2022-08-18 19:32:08 +08:00
|
|
|
Document = 0,
|
|
|
|
Grid = 3,
|
|
|
|
Board = 4,
|
2022-08-18 17:40:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::default::Default for ViewLayoutTypePB {
|
|
|
|
fn default() -> Self {
|
|
|
|
ViewLayoutTypePB::Grid
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-18 19:32:08 +08:00
|
|
|
impl std::convert::From<ViewLayoutTypeRevision> for ViewLayoutTypePB {
|
|
|
|
fn from(rev: ViewLayoutTypeRevision) -> Self {
|
|
|
|
match rev {
|
|
|
|
ViewLayoutTypeRevision::Grid => ViewLayoutTypePB::Grid,
|
|
|
|
ViewLayoutTypeRevision::Board => ViewLayoutTypePB::Board,
|
|
|
|
ViewLayoutTypeRevision::Document => ViewLayoutTypePB::Document,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<ViewLayoutTypePB> for ViewLayoutTypeRevision {
|
|
|
|
fn from(rev: ViewLayoutTypePB) -> Self {
|
|
|
|
match rev {
|
|
|
|
ViewLayoutTypePB::Grid => ViewLayoutTypeRevision::Grid,
|
|
|
|
ViewLayoutTypePB::Board => ViewLayoutTypeRevision::Board,
|
|
|
|
ViewLayoutTypePB::Document => ViewLayoutTypeRevision::Document,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 23:11:48 +08:00
|
|
|
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub struct RepeatedViewPB {
|
2022-06-14 23:11:48 +08:00
|
|
|
#[pb(index = 1)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub items: Vec<ViewPB>,
|
2022-06-14 23:11:48 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl_def_and_def_mut!(RepeatedViewPB, ViewPB);
|
2022-06-14 23:11:48 +08:00
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl std::convert::From<Vec<ViewRevision>> for RepeatedViewPB {
|
2022-07-04 14:28:41 +08:00
|
|
|
fn from(values: Vec<ViewRevision>) -> Self {
|
2022-07-19 14:11:29 +08:00
|
|
|
let items = values.into_iter().map(|value| value.into()).collect::<Vec<ViewPB>>();
|
|
|
|
RepeatedViewPB { items }
|
2022-07-04 14:28:41 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-14 23:11:48 +08:00
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub struct RepeatedViewIdPB {
|
2022-06-14 23:11:48 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2021-07-19 22:44:37 +08:00
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub struct CreateViewPayloadPB {
|
2021-07-19 22:44:37 +08:00
|
|
|
#[pb(index = 1)]
|
2021-07-28 13:41:39 +08:00
|
|
|
pub belong_to_id: String,
|
2021-07-19 22:44:37 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub desc: String,
|
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
|
|
|
pub thumbnail: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 5)]
|
2022-10-22 21:57:44 +08:00
|
|
|
pub data_format: ViewDataFormatPB,
|
2022-02-28 16:00:43 +08:00
|
|
|
|
2022-08-18 17:40:23 +08:00
|
|
|
#[pb(index = 6)]
|
|
|
|
pub layout: ViewLayoutTypePB,
|
2022-03-01 10:25:21 +08:00
|
|
|
|
|
|
|
#[pb(index = 7)]
|
2022-08-18 17:40:23 +08:00
|
|
|
pub view_content_data: Vec<u8>,
|
2021-07-19 22:44:37 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
#[derive(Debug, Clone)]
|
2021-07-19 22:44:37 +08:00
|
|
|
pub struct CreateViewParams {
|
2021-07-28 13:41:39 +08:00
|
|
|
pub belong_to_id: String,
|
2021-07-19 22:44:37 +08:00
|
|
|
pub name: String,
|
|
|
|
pub desc: String,
|
|
|
|
pub thumbnail: String,
|
2022-10-22 21:57:44 +08:00
|
|
|
pub data_format: ViewDataFormatPB,
|
2022-08-18 17:40:23 +08:00
|
|
|
pub layout: ViewLayoutTypePB,
|
2021-12-29 00:34:00 +08:00
|
|
|
pub view_id: String,
|
2022-08-18 17:40:23 +08:00
|
|
|
pub view_content_data: Vec<u8>,
|
2021-07-19 22:44:37 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
2021-11-07 23:23:16 +08:00
|
|
|
type Error = ErrorCode;
|
2021-07-19 22:44:37 +08:00
|
|
|
|
|
|
|
fn try_into(self) -> Result<CreateViewParams, Self::Error> {
|
2021-11-07 23:23:16 +08:00
|
|
|
let name = ViewName::parse(self.name)?.0;
|
2021-12-31 10:32:25 +08:00
|
|
|
let belong_to_id = AppIdentify::parse(self.belong_to_id)?.0;
|
2022-04-11 15:27:03 +08:00
|
|
|
let view_id = gen_view_id();
|
2021-07-19 22:44:37 +08:00
|
|
|
let thumbnail = match self.thumbnail {
|
|
|
|
None => "".to_string(),
|
2021-11-07 23:23:16 +08:00
|
|
|
Some(thumbnail) => ViewThumbnail::parse(thumbnail)?.0,
|
2021-07-19 22:44:37 +08:00
|
|
|
};
|
|
|
|
|
2022-02-28 22:38:53 +08:00
|
|
|
Ok(CreateViewParams {
|
2021-09-26 16:39:57 +08:00
|
|
|
belong_to_id,
|
|
|
|
name,
|
2022-02-28 22:38:53 +08:00
|
|
|
desc: self.desc,
|
2022-10-22 21:57:44 +08:00
|
|
|
data_format: self.data_format,
|
2022-08-18 17:40:23 +08:00
|
|
|
layout: self.layout,
|
2021-09-26 16:39:57 +08:00
|
|
|
thumbnail,
|
2021-12-29 00:34:00 +08:00
|
|
|
view_id,
|
2022-08-18 17:40:23 +08:00
|
|
|
view_content_data: self.view_content_data,
|
2022-02-28 22:38:53 +08:00
|
|
|
})
|
2021-07-19 22:44:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 11:16:26 +08:00
|
|
|
#[derive(Default, ProtoBuf, Clone, Debug)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub struct ViewIdPB {
|
2022-01-13 11:16:26 +08:00
|
|
|
#[pb(index = 1)]
|
2022-02-24 21:49:18 +08:00
|
|
|
pub value: String,
|
2022-01-13 11:16:26 +08:00
|
|
|
}
|
2021-07-19 22:44:37 +08:00
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl std::convert::From<&str> for ViewIdPB {
|
2022-02-24 21:49:18 +08:00
|
|
|
fn from(value: &str) -> Self {
|
2022-07-19 14:11:29 +08:00
|
|
|
ViewIdPB {
|
2022-02-24 21:49:18 +08:00
|
|
|
value: value.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-02 19:57:19 +08:00
|
|
|
|
2022-09-26 16:59:58 +08:00
|
|
|
#[derive(Default, ProtoBuf, Clone, Debug)]
|
|
|
|
pub struct DeletedViewPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub index: Option<i32>,
|
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl std::ops::Deref for ViewIdPB {
|
2022-05-05 10:45:53 +08:00
|
|
|
type Target = str;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-13 11:16:26 +08:00
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub struct UpdateViewPayloadPB {
|
2021-07-20 15:51:49 +08:00
|
|
|
#[pb(index = 1)]
|
2022-01-13 11:16:26 +08:00
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub name: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 3, one_of)]
|
|
|
|
pub desc: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
|
|
|
pub thumbnail: Option<String>,
|
2021-07-20 15:51:49 +08:00
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
#[derive(Clone, Debug)]
|
2022-01-13 11:16:26 +08:00
|
|
|
pub struct UpdateViewParams {
|
|
|
|
pub view_id: String,
|
|
|
|
pub name: Option<String>,
|
|
|
|
pub desc: Option<String>,
|
|
|
|
pub thumbnail: Option<String>,
|
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl TryInto<UpdateViewParams> for UpdateViewPayloadPB {
|
2022-01-13 11:16:26 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<UpdateViewParams, Self::Error> {
|
|
|
|
let view_id = ViewIdentify::parse(self.view_id)?.0;
|
|
|
|
|
|
|
|
let name = match self.name {
|
|
|
|
None => None,
|
|
|
|
Some(name) => Some(ViewName::parse(name)?.0),
|
|
|
|
};
|
|
|
|
|
|
|
|
let desc = match self.desc {
|
|
|
|
None => None,
|
|
|
|
Some(desc) => Some(ViewDesc::parse(desc)?.0),
|
|
|
|
};
|
|
|
|
|
|
|
|
let thumbnail = match self.thumbnail {
|
|
|
|
None => None,
|
|
|
|
Some(thumbnail) => Some(ViewThumbnail::parse(thumbnail)?.0),
|
|
|
|
};
|
|
|
|
|
|
|
|
Ok(UpdateViewParams {
|
|
|
|
view_id,
|
|
|
|
name,
|
|
|
|
desc,
|
|
|
|
thumbnail,
|
|
|
|
})
|
|
|
|
}
|
2021-10-13 11:10:29 +08:00
|
|
|
}
|
2022-02-26 18:28:09 +08:00
|
|
|
|
2022-04-26 21:20:02 +08:00
|
|
|
#[derive(ProtoBuf_Enum)]
|
|
|
|
pub enum MoveFolderItemType {
|
|
|
|
MoveApp = 0,
|
|
|
|
MoveView = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::default::Default for MoveFolderItemType {
|
|
|
|
fn default() -> Self {
|
|
|
|
MoveFolderItemType::MoveApp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
2022-07-19 14:11:29 +08:00
|
|
|
pub struct MoveFolderItemPayloadPB {
|
2022-04-26 21:20:02 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub item_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub from: i32,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub to: i32,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub ty: MoveFolderItemType,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct MoveFolderItemParams {
|
|
|
|
pub item_id: String,
|
|
|
|
pub from: usize,
|
|
|
|
pub to: usize,
|
|
|
|
pub ty: MoveFolderItemType,
|
|
|
|
}
|
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
impl TryInto<MoveFolderItemParams> for MoveFolderItemPayloadPB {
|
2022-04-26 21:20:02 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<MoveFolderItemParams, Self::Error> {
|
|
|
|
let view_id = ViewIdentify::parse(self.item_id)?.0;
|
|
|
|
Ok(MoveFolderItemParams {
|
|
|
|
item_id: view_id,
|
|
|
|
from: self.from as usize,
|
|
|
|
to: self.to as usize,
|
|
|
|
ty: self.ty,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 20:51:49 +08:00
|
|
|
// impl<'de> Deserialize<'de> for ViewDataType {
|
|
|
|
// fn deserialize<D>(deserializer: D) -> Result<Self, <D as Deserializer<'de>>::Error>
|
|
|
|
// where
|
|
|
|
// D: Deserializer<'de>,
|
|
|
|
// {
|
|
|
|
// struct ViewTypeVisitor();
|
|
|
|
//
|
|
|
|
// impl<'de> Visitor<'de> for ViewTypeVisitor {
|
|
|
|
// type Value = ViewDataType;
|
|
|
|
// fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
// formatter.write_str("RichText, PlainText")
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// fn visit_u8<E>(self, v: u8) -> Result<Self::Value, E>
|
|
|
|
// where
|
|
|
|
// E: de::Error,
|
|
|
|
// {
|
|
|
|
// let data_type;
|
|
|
|
// match v {
|
|
|
|
// 0 => {
|
|
|
|
// data_type = ViewDataType::RichText;
|
|
|
|
// }
|
|
|
|
// 1 => {
|
|
|
|
// data_type = ViewDataType::PlainText;
|
|
|
|
// }
|
|
|
|
// _ => {
|
|
|
|
// return Err(de::Error::invalid_value(Unexpected::Unsigned(v as u64), &self));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Ok(data_type)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// fn visit_str<E>(self, s: &str) -> Result<Self::Value, E>
|
|
|
|
// where
|
|
|
|
// E: de::Error,
|
|
|
|
// {
|
|
|
|
// let data_type;
|
|
|
|
// match s {
|
|
|
|
// "Doc" | "RichText" => {
|
|
|
|
// // Rename ViewDataType::Doc to ViewDataType::RichText, So we need to migrate the ViewType manually.
|
|
|
|
// data_type = ViewDataType::RichText;
|
|
|
|
// }
|
|
|
|
// "PlainText" => {
|
|
|
|
// data_type = ViewDataType::PlainText;
|
|
|
|
// }
|
|
|
|
// unknown => {
|
|
|
|
// return Err(de::Error::invalid_value(Unexpected::Str(unknown), &self));
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// Ok(data_type)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// deserializer.deserialize_any(ViewTypeVisitor())
|
|
|
|
// }
|
|
|
|
// }
|