2023-04-04 00:41:16 +00:00
|
|
|
use std::collections::HashMap;
|
|
|
|
use std::convert::TryInto;
|
|
|
|
use std::ops::{Deref, DerefMut};
|
2023-06-23 15:19:34 +00:00
|
|
|
use std::sync::Arc;
|
2023-04-04 00:41:16 +00:00
|
|
|
|
2024-06-25 02:03:02 +00:00
|
|
|
use collab_folder::{View, ViewIcon, ViewLayout};
|
2023-06-06 16:05:27 +00:00
|
|
|
|
|
|
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
|
|
|
use flowy_error::ErrorCode;
|
2024-01-11 06:42:03 +00:00
|
|
|
use flowy_folder_pub::cloud::gen_view_id;
|
2023-06-06 16:05:27 +00:00
|
|
|
|
2023-08-28 05:28:24 +00:00
|
|
|
use crate::entities::icon::ViewIconPB;
|
2024-02-08 15:53:05 +00:00
|
|
|
use crate::entities::parser::view::{ViewIdentify, ViewName, ViewThumbnail};
|
2023-06-06 16:05:27 +00:00
|
|
|
|
2023-06-20 15:48:34 +00:00
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct ChildViewUpdatePB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub parent_view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub create_child_views: Vec<ViewPB>,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub delete_child_views: Vec<String>,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub update_child_views: Vec<ViewPB>,
|
|
|
|
}
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct ViewPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
/// The parent view id of the view.
|
|
|
|
/// Each view should have a parent view except the orphan view.
|
2023-04-04 00:41:16 +00:00
|
|
|
#[pb(index = 2)]
|
2023-04-04 06:08:50 +00:00
|
|
|
pub parent_view_id: String,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub create_time: i64,
|
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
/// Each view can have multiple child views.
|
2023-04-04 00:41:16 +00:00
|
|
|
#[pb(index = 5)]
|
2023-05-10 11:43:32 +00:00
|
|
|
pub child_views: Vec<ViewPB>,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
/// The layout of the view. It will be used to determine how the view should be rendered.
|
2023-04-04 00:41:16 +00:00
|
|
|
#[pb(index = 6)]
|
2023-04-04 06:08:50 +00:00
|
|
|
pub layout: ViewLayoutPB,
|
2023-06-14 14:16:33 +00:00
|
|
|
|
2023-08-04 11:27:14 +00:00
|
|
|
/// The icon of the view.
|
2023-06-14 14:16:33 +00:00
|
|
|
#[pb(index = 7, one_of)]
|
2023-08-04 11:27:14 +00:00
|
|
|
pub icon: Option<ViewIconPB>,
|
2023-06-14 14:16:33 +00:00
|
|
|
|
2023-08-04 11:27:14 +00:00
|
|
|
#[pb(index = 8)]
|
2023-08-02 13:20:51 +00:00
|
|
|
pub is_favorite: bool,
|
2024-04-30 08:55:15 +00:00
|
|
|
|
|
|
|
#[pb(index = 9, one_of)]
|
|
|
|
pub extra: Option<String>,
|
2024-05-30 01:56:44 +00:00
|
|
|
|
|
|
|
// user_id
|
|
|
|
#[pb(index = 10, one_of)]
|
|
|
|
pub created_by: Option<i64>,
|
|
|
|
|
|
|
|
// timestamp
|
|
|
|
#[pb(index = 11)]
|
|
|
|
pub last_edited: i64,
|
|
|
|
|
|
|
|
// user_id
|
|
|
|
#[pb(index = 12, one_of)]
|
|
|
|
pub last_edited_by: Option<i64>,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
|
2024-03-12 02:59:52 +00:00
|
|
|
pub fn view_pb_without_child_views(view: View) -> ViewPB {
|
2023-05-10 11:43:32 +00:00
|
|
|
ViewPB {
|
2024-03-12 02:59:52 +00:00
|
|
|
id: view.id,
|
|
|
|
parent_view_id: view.parent_view_id,
|
|
|
|
name: view.name,
|
2023-05-10 11:43:32 +00:00
|
|
|
create_time: view.created_at,
|
|
|
|
child_views: Default::default(),
|
2024-03-12 02:59:52 +00:00
|
|
|
layout: view.layout.into(),
|
2023-08-04 11:27:14 +00:00
|
|
|
icon: view.icon.clone().map(|icon| icon.into()),
|
|
|
|
is_favorite: view.is_favorite,
|
2024-04-30 08:55:15 +00:00
|
|
|
extra: view.extra,
|
2024-05-30 01:56:44 +00:00
|
|
|
created_by: view.created_by,
|
|
|
|
last_edited: view.last_edited_time,
|
|
|
|
last_edited_by: view.last_edited_by,
|
2023-05-10 11:43:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-23 13:46:57 +00:00
|
|
|
pub fn view_pb_without_child_views_from_arc(view: Arc<View>) -> ViewPB {
|
|
|
|
ViewPB {
|
|
|
|
id: view.id.clone(),
|
|
|
|
parent_view_id: view.parent_view_id.clone(),
|
|
|
|
name: view.name.clone(),
|
|
|
|
create_time: view.created_at,
|
|
|
|
child_views: Default::default(),
|
|
|
|
layout: view.layout.clone().into(),
|
|
|
|
icon: view.icon.clone().map(|icon| icon.into()),
|
|
|
|
is_favorite: view.is_favorite,
|
2024-04-30 08:55:15 +00:00
|
|
|
extra: view.extra.clone(),
|
2024-05-30 01:56:44 +00:00
|
|
|
created_by: view.created_by,
|
|
|
|
last_edited: view.last_edited_time,
|
|
|
|
last_edited_by: view.last_edited_by,
|
2024-04-23 13:46:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-10 11:43:32 +00:00
|
|
|
/// Returns a ViewPB with child views. Only the first level of child views are included.
|
2023-06-23 15:19:34 +00:00
|
|
|
pub fn view_pb_with_child_views(view: Arc<View>, child_views: Vec<Arc<View>>) -> ViewPB {
|
2023-05-10 11:43:32 +00:00
|
|
|
ViewPB {
|
2023-06-23 15:19:34 +00:00
|
|
|
id: view.id.clone(),
|
|
|
|
parent_view_id: view.parent_view_id.clone(),
|
|
|
|
name: view.name.clone(),
|
2023-05-10 11:43:32 +00:00
|
|
|
create_time: view.created_at,
|
|
|
|
child_views: child_views
|
|
|
|
.into_iter()
|
2024-03-12 02:59:52 +00:00
|
|
|
.map(|view| view_pb_without_child_views(view.as_ref().clone()))
|
2023-05-10 11:43:32 +00:00
|
|
|
.collect(),
|
2023-06-23 15:19:34 +00:00
|
|
|
layout: view.layout.clone().into(),
|
2023-08-04 11:27:14 +00:00
|
|
|
icon: view.icon.clone().map(|icon| icon.into()),
|
|
|
|
is_favorite: view.is_favorite,
|
2024-04-30 08:55:15 +00:00
|
|
|
extra: view.extra.clone(),
|
2024-05-30 01:56:44 +00:00
|
|
|
created_by: view.created_by,
|
|
|
|
last_edited: view.last_edited_time,
|
|
|
|
last_edited_by: view.last_edited_by,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-09 14:23:07 +00:00
|
|
|
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone, Default)]
|
2023-04-04 06:08:50 +00:00
|
|
|
pub enum ViewLayoutPB {
|
2023-06-09 14:23:07 +00:00
|
|
|
#[default]
|
2023-04-04 00:41:16 +00:00
|
|
|
Document = 0,
|
2023-06-05 08:09:18 +00:00
|
|
|
Grid = 1,
|
|
|
|
Board = 2,
|
|
|
|
Calendar = 3,
|
2024-06-03 06:27:28 +00:00
|
|
|
Chat = 4,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 06:08:50 +00:00
|
|
|
impl ViewLayoutPB {
|
|
|
|
pub fn is_database(&self) -> bool {
|
|
|
|
matches!(
|
|
|
|
self,
|
|
|
|
ViewLayoutPB::Grid | ViewLayoutPB::Board | ViewLayoutPB::Calendar
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<ViewLayout> for ViewLayoutPB {
|
2023-04-04 00:41:16 +00:00
|
|
|
fn from(rev: ViewLayout) -> Self {
|
|
|
|
match rev {
|
2023-04-04 06:08:50 +00:00
|
|
|
ViewLayout::Grid => ViewLayoutPB::Grid,
|
|
|
|
ViewLayout::Board => ViewLayoutPB::Board,
|
|
|
|
ViewLayout::Document => ViewLayoutPB::Document,
|
|
|
|
ViewLayout::Calendar => ViewLayoutPB::Calendar,
|
2024-06-03 06:27:28 +00:00
|
|
|
ViewLayout::Chat => ViewLayoutPB::Chat,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 04:02:03 +00:00
|
|
|
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
|
|
|
pub struct SectionViewsPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub section: ViewSectionPB,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub views: Vec<ViewPB>,
|
|
|
|
}
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
|
|
|
pub struct RepeatedViewPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<ViewPB>,
|
|
|
|
}
|
|
|
|
|
2024-05-27 00:51:49 +00:00
|
|
|
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
|
|
|
pub struct RepeatedFavoriteViewPB {
|
|
|
|
#[pb(index = 1)]
|
2024-05-30 01:56:44 +00:00
|
|
|
pub items: Vec<SectionViewPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
|
|
|
pub struct RepeatedRecentViewPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<SectionViewPB>,
|
2024-05-27 00:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
2024-05-30 01:56:44 +00:00
|
|
|
pub struct SectionViewPB {
|
2024-05-27 00:51:49 +00:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub item: ViewPB,
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub timestamp: i64,
|
|
|
|
}
|
|
|
|
|
2023-04-04 06:08:50 +00:00
|
|
|
impl std::convert::From<Vec<ViewPB>> for RepeatedViewPB {
|
|
|
|
fn from(items: Vec<ViewPB>) -> Self {
|
2023-04-04 00:41:16 +00:00
|
|
|
RepeatedViewPB { items }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for RepeatedViewPB {
|
|
|
|
type Target = Vec<ViewPB>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl DerefMut for RepeatedViewPB {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct RepeatedViewIdPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct CreateViewPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
2023-05-31 06:08:54 +00:00
|
|
|
pub parent_view_id: String,
|
2023-04-04 00:41:16 +00: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)]
|
2023-04-04 06:08:50 +00:00
|
|
|
pub layout: ViewLayoutPB,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
#[pb(index = 6)]
|
|
|
|
pub initial_data: Vec<u8>,
|
|
|
|
|
|
|
|
#[pb(index = 7)]
|
2023-06-03 05:40:12 +00:00
|
|
|
pub meta: HashMap<String, String>,
|
|
|
|
|
2023-08-02 13:20:51 +00:00
|
|
|
// Mark the view as current view after creation.
|
2023-06-03 05:40:12 +00:00
|
|
|
#[pb(index = 8)]
|
|
|
|
pub set_as_current: bool,
|
2023-08-02 13:20:51 +00:00
|
|
|
|
|
|
|
// The index of the view in the parent view.
|
|
|
|
// If the index is None or the index is out of range, the view will be appended to the end of the parent view.
|
|
|
|
#[pb(index = 9, one_of)]
|
|
|
|
pub index: Option<u32>,
|
2024-03-21 04:02:03 +00:00
|
|
|
|
|
|
|
// The section of the view.
|
|
|
|
// Only the view in public section will be shown in the shared workspace view list.
|
|
|
|
// The view in private section will only be shown in the user's private view list.
|
|
|
|
#[pb(index = 10, one_of)]
|
|
|
|
pub section: Option<ViewSectionPB>,
|
2024-06-25 02:03:02 +00:00
|
|
|
|
|
|
|
#[pb(index = 11, one_of)]
|
|
|
|
pub view_id: Option<String>,
|
2024-03-21 04:02:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone, Default)]
|
|
|
|
pub enum ViewSectionPB {
|
|
|
|
#[default]
|
|
|
|
// only support public and private section now.
|
|
|
|
Private = 0,
|
|
|
|
Public = 1,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
/// The orphan view is meant to be a view that is not attached to any parent view. By default, this
|
|
|
|
/// view will not be shown in the view list unless it is attached to a parent view that is shown in
|
|
|
|
/// the view list.
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct CreateOrphanViewPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub name: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub desc: String,
|
|
|
|
|
|
|
|
#[pb(index = 4)]
|
|
|
|
pub layout: ViewLayoutPB,
|
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub initial_data: Vec<u8>,
|
|
|
|
}
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct CreateViewParams {
|
2023-05-31 06:08:54 +00:00
|
|
|
pub parent_view_id: String,
|
2023-04-04 00:41:16 +00:00
|
|
|
pub name: String,
|
|
|
|
pub desc: String,
|
2023-04-04 06:08:50 +00:00
|
|
|
pub layout: ViewLayoutPB,
|
2023-04-04 00:41:16 +00:00
|
|
|
pub view_id: String,
|
|
|
|
pub initial_data: Vec<u8>,
|
2023-05-31 06:08:54 +00:00
|
|
|
pub meta: HashMap<String, String>,
|
2023-08-02 13:20:51 +00:00
|
|
|
// Mark the view as current view after creation.
|
2023-06-03 05:40:12 +00:00
|
|
|
pub set_as_current: bool,
|
2023-08-02 13:20:51 +00:00
|
|
|
// The index of the view in the parent view.
|
|
|
|
// If the index is None or the index is out of range, the view will be appended to the end of the parent view.
|
|
|
|
pub index: Option<u32>,
|
2024-03-21 04:02:03 +00:00
|
|
|
// The section of the view.
|
|
|
|
pub section: Option<ViewSectionPB>,
|
2024-06-25 02:03:02 +00:00
|
|
|
// The icon of the view.
|
|
|
|
pub icon: Option<ViewIcon>,
|
|
|
|
// The extra data of the view.
|
|
|
|
pub extra: Option<String>,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<CreateViewParams, Self::Error> {
|
|
|
|
let name = ViewName::parse(self.name)?.0;
|
2023-06-14 14:16:33 +00:00
|
|
|
let parent_view_id = ViewIdentify::parse(self.parent_view_id)?.0;
|
2024-06-25 02:03:02 +00:00
|
|
|
// if view_id is not provided, generate a new view_id
|
|
|
|
let view_id = self.view_id.unwrap_or_else(|| gen_view_id().to_string());
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
Ok(CreateViewParams {
|
2023-06-14 14:16:33 +00:00
|
|
|
parent_view_id,
|
2023-04-04 00:41:16 +00:00
|
|
|
name,
|
|
|
|
desc: self.desc,
|
|
|
|
layout: self.layout,
|
|
|
|
view_id,
|
|
|
|
initial_data: self.initial_data,
|
2023-06-03 05:40:12 +00:00
|
|
|
meta: self.meta,
|
|
|
|
set_as_current: self.set_as_current,
|
2023-08-02 13:20:51 +00:00
|
|
|
index: self.index,
|
2024-03-21 04:02:03 +00:00
|
|
|
section: self.section,
|
2024-06-25 02:03:02 +00:00
|
|
|
icon: None,
|
|
|
|
extra: None,
|
2023-04-04 00:41:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 14:16:33 +00:00
|
|
|
impl TryInto<CreateViewParams> for CreateOrphanViewPayloadPB {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<CreateViewParams, Self::Error> {
|
|
|
|
let name = ViewName::parse(self.name)?.0;
|
|
|
|
let parent_view_id = ViewIdentify::parse(self.view_id.clone())?.0;
|
|
|
|
|
|
|
|
Ok(CreateViewParams {
|
|
|
|
parent_view_id,
|
|
|
|
name,
|
|
|
|
desc: self.desc,
|
|
|
|
layout: self.layout,
|
|
|
|
view_id: self.view_id,
|
|
|
|
initial_data: self.initial_data,
|
|
|
|
meta: Default::default(),
|
|
|
|
set_as_current: false,
|
2023-08-02 13:20:51 +00:00
|
|
|
index: None,
|
2024-03-22 09:15:18 +00:00
|
|
|
section: None,
|
2024-06-25 02:03:02 +00:00
|
|
|
icon: None,
|
|
|
|
extra: None,
|
2023-06-14 14:16:33 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
#[derive(Default, ProtoBuf, Clone, Debug)]
|
|
|
|
pub struct ViewIdPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub value: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<&str> for ViewIdPB {
|
|
|
|
fn from(value: &str) -> Self {
|
|
|
|
ViewIdPB {
|
|
|
|
value: value.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf, Clone, Debug)]
|
|
|
|
pub struct DeletedViewPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub index: Option<i32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::Deref for ViewIdPB {
|
|
|
|
type Target = str;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct UpdateViewPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
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>,
|
2023-06-01 12:23:27 +00:00
|
|
|
|
|
|
|
#[pb(index = 5, one_of)]
|
|
|
|
pub layout: Option<ViewLayoutPB>,
|
2023-06-14 14:16:33 +00:00
|
|
|
|
|
|
|
#[pb(index = 6, one_of)]
|
2023-08-02 13:20:51 +00:00
|
|
|
pub is_favorite: Option<bool>,
|
2024-04-30 08:55:15 +00:00
|
|
|
|
|
|
|
#[pb(index = 7, one_of)]
|
|
|
|
// this value used to store the extra data with JSON format
|
|
|
|
// for document:
|
|
|
|
// - cover: { type: "", value: "" }
|
|
|
|
// - type: "0" represents normal color,
|
|
|
|
// "1" represents gradient color,
|
|
|
|
// "2" represents built-in image,
|
|
|
|
// "3" represents custom image,
|
|
|
|
// "4" represents local image,
|
|
|
|
// "5" represents unsplash image
|
|
|
|
// - line_height_layout: "small" or "normal" or "large"
|
|
|
|
// - font_layout: "small", or "normal", or "large"
|
|
|
|
pub extra: Option<String>,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct UpdateViewParams {
|
|
|
|
pub view_id: String,
|
|
|
|
pub name: Option<String>,
|
|
|
|
pub desc: Option<String>,
|
|
|
|
pub thumbnail: Option<String>,
|
2023-08-02 13:20:51 +00:00
|
|
|
pub layout: Option<ViewLayout>,
|
2023-08-04 11:27:14 +00:00
|
|
|
pub is_favorite: Option<bool>,
|
2024-04-30 08:55:15 +00:00
|
|
|
pub extra: Option<String>,
|
2023-04-04 00:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<UpdateViewParams> for UpdateViewPayloadPB {
|
|
|
|
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 thumbnail = match self.thumbnail {
|
|
|
|
None => None,
|
|
|
|
Some(thumbnail) => Some(ViewThumbnail::parse(thumbnail)?.0),
|
|
|
|
};
|
|
|
|
|
2023-08-02 13:20:51 +00:00
|
|
|
let is_favorite = self.is_favorite;
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
Ok(UpdateViewParams {
|
|
|
|
view_id,
|
|
|
|
name,
|
2024-02-08 15:53:05 +00:00
|
|
|
desc: self.desc,
|
2023-04-04 00:41:16 +00:00
|
|
|
thumbnail,
|
2023-08-02 13:20:51 +00:00
|
|
|
is_favorite,
|
2023-06-01 12:23:27 +00:00
|
|
|
layout: self.layout.map(|ty| ty.into()),
|
2024-04-30 08:55:15 +00:00
|
|
|
extra: self.extra,
|
2023-04-04 00:41:16 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default, ProtoBuf)]
|
2023-06-05 08:09:18 +00:00
|
|
|
pub struct MoveViewPayloadPB {
|
2023-04-04 00:41:16 +00:00
|
|
|
#[pb(index = 1)]
|
2023-06-05 08:09:18 +00:00
|
|
|
pub view_id: String,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub from: i32,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub to: i32,
|
|
|
|
}
|
|
|
|
|
2023-07-26 08:49:50 +00:00
|
|
|
/// * `view_id` - A string slice that holds the id of the view to be moved.
|
|
|
|
/// * `new_parent_id` - A string slice that holds the id of the new parent view.
|
|
|
|
/// * `prev_view_id` - An `Option<String>` that holds the id of the view after which the `view_id` should be positioned.
|
|
|
|
///
|
|
|
|
/// If `prev_view_id` is provided, the moved view will be placed right after
|
|
|
|
/// the view corresponding to `prev_view_id` under the `new_parent_id`.
|
|
|
|
///
|
|
|
|
/// If `prev_view_id` is `None`, the moved view will become the first child of the new parent.
|
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct MoveNestedViewPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub new_parent_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3, one_of)]
|
|
|
|
pub prev_view_id: Option<String>,
|
2024-03-21 04:02:03 +00:00
|
|
|
|
|
|
|
#[pb(index = 4, one_of)]
|
|
|
|
pub from_section: Option<ViewSectionPB>,
|
|
|
|
|
|
|
|
#[pb(index = 5, one_of)]
|
|
|
|
pub to_section: Option<ViewSectionPB>,
|
2023-07-26 08:49:50 +00:00
|
|
|
}
|
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
pub struct MoveViewParams {
|
2023-06-06 16:05:27 +00:00
|
|
|
pub view_id: String,
|
2023-04-04 00:41:16 +00:00
|
|
|
pub from: usize,
|
|
|
|
pub to: usize,
|
|
|
|
}
|
|
|
|
|
2023-06-05 08:09:18 +00:00
|
|
|
impl TryInto<MoveViewParams> for MoveViewPayloadPB {
|
2023-04-04 00:41:16 +00:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<MoveViewParams, Self::Error> {
|
2023-06-05 08:09:18 +00:00
|
|
|
let view_id = ViewIdentify::parse(self.view_id)?.0;
|
2023-04-04 00:41:16 +00:00
|
|
|
Ok(MoveViewParams {
|
2023-06-06 16:05:27 +00:00
|
|
|
view_id,
|
2023-04-04 00:41:16 +00:00
|
|
|
from: self.from as usize,
|
|
|
|
to: self.to as usize,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-21 04:02:03 +00:00
|
|
|
#[derive(Debug)]
|
2023-07-26 08:49:50 +00:00
|
|
|
pub struct MoveNestedViewParams {
|
|
|
|
pub view_id: String,
|
|
|
|
pub new_parent_id: String,
|
|
|
|
pub prev_view_id: Option<String>,
|
2024-03-21 04:02:03 +00:00
|
|
|
pub from_section: Option<ViewSectionPB>,
|
|
|
|
pub to_section: Option<ViewSectionPB>,
|
2023-07-26 08:49:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<MoveNestedViewParams> for MoveNestedViewPayloadPB {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<MoveNestedViewParams, Self::Error> {
|
|
|
|
let view_id = ViewIdentify::parse(self.view_id)?.0;
|
|
|
|
let new_parent_id = ViewIdentify::parse(self.new_parent_id)?.0;
|
|
|
|
let prev_view_id = self.prev_view_id;
|
|
|
|
Ok(MoveNestedViewParams {
|
|
|
|
view_id,
|
|
|
|
new_parent_id,
|
|
|
|
prev_view_id,
|
2024-03-21 04:02:03 +00:00
|
|
|
from_section: self.from_section,
|
|
|
|
to_section: self.to_section,
|
2023-07-26 08:49:50 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-01 01:58:36 +00:00
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct UpdateRecentViewPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_ids: Vec<String>,
|
|
|
|
|
|
|
|
// If true, the view will be added to the recent view list.
|
|
|
|
// If false, the view will be removed from the recent view list.
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub add_in_recent: bool,
|
|
|
|
}
|
|
|
|
|
2024-04-01 06:27:29 +00:00
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct UpdateViewVisibilityStatusPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_ids: Vec<String>,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub is_public: bool,
|
|
|
|
}
|
|
|
|
|
2024-06-25 02:03:02 +00:00
|
|
|
#[derive(Default, ProtoBuf)]
|
|
|
|
pub struct DuplicateViewPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub open_after_duplicate: bool,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub include_children: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct DuplicateViewParams {
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
pub open_after_duplicate: bool,
|
|
|
|
|
|
|
|
pub include_children: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryInto<DuplicateViewParams> for DuplicateViewPayloadPB {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<DuplicateViewParams, Self::Error> {
|
|
|
|
let view_id = ViewIdentify::parse(self.view_id)?.0;
|
|
|
|
Ok(DuplicateViewParams {
|
|
|
|
view_id,
|
|
|
|
open_after_duplicate: self.open_after_duplicate,
|
|
|
|
include_children: self.include_children,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 00:41:16 +00: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())
|
|
|
|
// }
|
|
|
|
// }
|