mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Integrate appflowy editor (#1040)
This commit is contained in:
@ -7,7 +7,7 @@ use crate::{
|
||||
impl_def_and_def_mut,
|
||||
};
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use flowy_folder_data_model::revision::{gen_view_id, ViewDataFormatRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
@ -22,7 +22,7 @@ pub struct ViewPB {
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub data_type: ViewDataTypePB,
|
||||
pub data_format: ViewDataFormatPB,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub modified_time: i64,
|
||||
@ -40,7 +40,7 @@ impl std::convert::From<ViewRevision> for ViewPB {
|
||||
id: rev.id,
|
||||
app_id: rev.app_id,
|
||||
name: rev.name,
|
||||
data_type: rev.data_type.into(),
|
||||
data_format: rev.data_format.into(),
|
||||
modified_time: rev.modified_time,
|
||||
create_time: rev.create_time,
|
||||
layout: rev.layout.into(),
|
||||
@ -49,31 +49,34 @@ impl std::convert::From<ViewRevision> for ViewPB {
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
||||
pub enum ViewDataTypePB {
|
||||
Text = 0,
|
||||
Database = 1,
|
||||
pub enum ViewDataFormatPB {
|
||||
DeltaFormat = 0,
|
||||
DatabaseFormat = 1,
|
||||
TreeFormat = 2,
|
||||
}
|
||||
|
||||
impl std::default::Default for ViewDataTypePB {
|
||||
impl std::default::Default for ViewDataFormatPB {
|
||||
fn default() -> Self {
|
||||
ViewDataTypeRevision::default().into()
|
||||
ViewDataFormatRevision::default().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewDataTypeRevision> for ViewDataTypePB {
|
||||
fn from(rev: ViewDataTypeRevision) -> Self {
|
||||
impl std::convert::From<ViewDataFormatRevision> for ViewDataFormatPB {
|
||||
fn from(rev: ViewDataFormatRevision) -> Self {
|
||||
match rev {
|
||||
ViewDataTypeRevision::Text => ViewDataTypePB::Text,
|
||||
ViewDataTypeRevision::Database => ViewDataTypePB::Database,
|
||||
ViewDataFormatRevision::DeltaFormat => ViewDataFormatPB::DeltaFormat,
|
||||
ViewDataFormatRevision::DatabaseFormat => ViewDataFormatPB::DatabaseFormat,
|
||||
ViewDataFormatRevision::TreeFormat => ViewDataFormatPB::TreeFormat,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewDataTypePB> for ViewDataTypeRevision {
|
||||
fn from(ty: ViewDataTypePB) -> Self {
|
||||
impl std::convert::From<ViewDataFormatPB> for ViewDataFormatRevision {
|
||||
fn from(ty: ViewDataFormatPB) -> Self {
|
||||
match ty {
|
||||
ViewDataTypePB::Text => ViewDataTypeRevision::Text,
|
||||
ViewDataTypePB::Database => ViewDataTypeRevision::Database,
|
||||
ViewDataFormatPB::DeltaFormat => ViewDataFormatRevision::DeltaFormat,
|
||||
ViewDataFormatPB::DatabaseFormat => ViewDataFormatRevision::DatabaseFormat,
|
||||
ViewDataFormatPB::TreeFormat => ViewDataFormatRevision::TreeFormat,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,7 +149,7 @@ pub struct CreateViewPayloadPB {
|
||||
pub thumbnail: Option<String>,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub data_type: ViewDataTypePB,
|
||||
pub data_format: ViewDataFormatPB,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub layout: ViewLayoutTypePB,
|
||||
@ -161,7 +164,7 @@ pub struct CreateViewParams {
|
||||
pub name: String,
|
||||
pub desc: String,
|
||||
pub thumbnail: String,
|
||||
pub data_type: ViewDataTypePB,
|
||||
pub data_format: ViewDataFormatPB,
|
||||
pub layout: ViewLayoutTypePB,
|
||||
pub view_id: String,
|
||||
pub view_content_data: Vec<u8>,
|
||||
@ -183,7 +186,7 @@ impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
||||
belong_to_id,
|
||||
name,
|
||||
desc: self.desc,
|
||||
data_type: self.data_type,
|
||||
data_format: self.data_format,
|
||||
layout: self.layout,
|
||||
thumbnail,
|
||||
view_id,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{RepeatedViewPB, ViewDataTypePB};
|
||||
use crate::entities::{RepeatedViewPB, ViewDataFormatPB};
|
||||
use flowy_derive::ProtoBuf;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
@ -16,7 +16,7 @@ pub struct ViewInfoPB {
|
||||
pub desc: String,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub data_type: ViewDataTypePB,
|
||||
pub data_type: ViewDataFormatPB,
|
||||
|
||||
#[pb(index = 6)]
|
||||
pub belongings: RepeatedViewPB,
|
||||
|
@ -126,7 +126,7 @@ pub enum FolderEvent {
|
||||
#[event(input = "RepeatedViewIdPB")]
|
||||
DeleteView = 204,
|
||||
|
||||
#[event(input = "ViewIdPB")]
|
||||
#[event(input = "ViewPB")]
|
||||
DuplicateView = 205,
|
||||
|
||||
#[event(input = "ViewIdPB")]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::view::ViewDataTypePB;
|
||||
use crate::entities::ViewLayoutTypePB;
|
||||
use crate::entities::view::ViewDataFormatPB;
|
||||
use crate::entities::{ViewLayoutTypePB, ViewPB};
|
||||
use crate::services::folder_editor::FolderRevisionCompress;
|
||||
use crate::{
|
||||
dart_notification::{send_dart_notification, FolderNotification},
|
||||
@ -14,13 +14,14 @@ use crate::{
|
||||
use bytes::Bytes;
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_folder_data_model::user_default;
|
||||
use flowy_revision::disk::SQLiteDocumentRevisionPersistence;
|
||||
use flowy_revision::disk::SQLiteDeltaDocumentRevisionPersistence;
|
||||
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionWebSocket, SQLiteRevisionSnapshotPersistence};
|
||||
use flowy_sync::client_document::default::initial_read_me;
|
||||
|
||||
use flowy_document::editor::initial_read_me;
|
||||
use flowy_sync::{client_folder::FolderPad, entities::ws_data::ServerRevisionWSData};
|
||||
use lazy_static::lazy_static;
|
||||
use lib_infra::future::FutureResult;
|
||||
|
||||
use std::{collections::HashMap, convert::TryInto, fmt::Formatter, sync::Arc};
|
||||
use tokio::sync::RwLock as TokioRwLock;
|
||||
lazy_static! {
|
||||
@ -64,7 +65,6 @@ pub struct FolderManager {
|
||||
pub(crate) trash_controller: Arc<TrashController>,
|
||||
web_socket: Arc<dyn RevisionWebSocket>,
|
||||
folder_editor: Arc<TokioRwLock<Option<Arc<FolderEditor>>>>,
|
||||
data_processors: ViewDataProcessorMap,
|
||||
}
|
||||
|
||||
impl FolderManager {
|
||||
@ -95,7 +95,7 @@ impl FolderManager {
|
||||
persistence.clone(),
|
||||
cloud_service.clone(),
|
||||
trash_controller.clone(),
|
||||
data_processors.clone(),
|
||||
data_processors,
|
||||
));
|
||||
|
||||
let app_controller = Arc::new(AppController::new(
|
||||
@ -122,7 +122,6 @@ impl FolderManager {
|
||||
trash_controller,
|
||||
web_socket,
|
||||
folder_editor,
|
||||
data_processors,
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,6 +150,7 @@ impl FolderManager {
|
||||
}
|
||||
}
|
||||
|
||||
/// Called immediately after the application launched with the user sign in/sign up.
|
||||
#[tracing::instrument(level = "trace", skip(self), err)]
|
||||
pub async fn initialize(&self, user_id: &str, token: &str) -> FlowyResult<()> {
|
||||
let mut write_guard = INIT_FOLDER_FLAG.write().await;
|
||||
@ -165,7 +165,7 @@ impl FolderManager {
|
||||
|
||||
let pool = self.persistence.db_pool()?;
|
||||
let object_id = folder_id.as_ref();
|
||||
let disk_cache = SQLiteDocumentRevisionPersistence::new(user_id, pool.clone());
|
||||
let disk_cache = SQLiteDeltaDocumentRevisionPersistence::new(user_id, pool.clone());
|
||||
let rev_persistence = RevisionPersistence::new(user_id, object_id, disk_cache);
|
||||
let rev_compactor = FolderRevisionCompress();
|
||||
// let history_persistence = SQLiteRevisionHistoryPersistence::new(object_id, pool.clone());
|
||||
@ -184,17 +184,24 @@ impl FolderManager {
|
||||
|
||||
let _ = self.app_controller.initialize()?;
|
||||
let _ = self.view_controller.initialize()?;
|
||||
|
||||
self.data_processors.iter().for_each(|(_, processor)| {
|
||||
processor.initialize();
|
||||
});
|
||||
|
||||
write_guard.insert(user_id.to_owned(), true);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn initialize_with_new_user(&self, user_id: &str, token: &str) -> FlowyResult<()> {
|
||||
DefaultFolderBuilder::build(token, user_id, self.persistence.clone(), self.view_controller.clone()).await?;
|
||||
pub async fn initialize_with_new_user(
|
||||
&self,
|
||||
user_id: &str,
|
||||
token: &str,
|
||||
view_data_format: ViewDataFormatPB,
|
||||
) -> FlowyResult<()> {
|
||||
DefaultFolderBuilder::build(
|
||||
token,
|
||||
user_id,
|
||||
self.persistence.clone(),
|
||||
self.view_controller.clone(),
|
||||
|| (view_data_format.clone(), Bytes::from(initial_read_me())),
|
||||
)
|
||||
.await?;
|
||||
self.initialize(user_id, token).await
|
||||
}
|
||||
|
||||
@ -205,23 +212,24 @@ impl FolderManager {
|
||||
|
||||
struct DefaultFolderBuilder();
|
||||
impl DefaultFolderBuilder {
|
||||
async fn build(
|
||||
async fn build<F: Fn() -> (ViewDataFormatPB, Bytes)>(
|
||||
token: &str,
|
||||
user_id: &str,
|
||||
persistence: Arc<FolderPersistence>,
|
||||
view_controller: Arc<ViewController>,
|
||||
create_view_fn: F,
|
||||
) -> FlowyResult<()> {
|
||||
log::debug!("Create user default workspace");
|
||||
let workspace_rev = user_default::create_default_workspace();
|
||||
set_current_workspace(&workspace_rev.id);
|
||||
for app in workspace_rev.apps.iter() {
|
||||
for (index, view) in app.belongings.iter().enumerate() {
|
||||
let (view_data_type, view_data) = create_view_fn();
|
||||
if index == 0 {
|
||||
let view_data = initial_read_me().json_str();
|
||||
let _ = view_controller.set_latest_view(&view.id);
|
||||
let layout_type = ViewLayoutTypePB::from(view.layout.clone());
|
||||
let _ = view_controller
|
||||
.create_view(&view.id, ViewDataTypePB::Text, layout_type, Bytes::from(view_data))
|
||||
.create_view(&view.id, view_data_type, layout_type, view_data)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
@ -247,25 +255,24 @@ impl FolderManager {
|
||||
}
|
||||
|
||||
pub trait ViewDataProcessor {
|
||||
fn initialize(&self) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn create_container(
|
||||
fn create_view(
|
||||
&self,
|
||||
user_id: &str,
|
||||
view_id: &str,
|
||||
layout: ViewLayoutTypePB,
|
||||
delta_data: Bytes,
|
||||
view_data: Bytes,
|
||||
) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn close_container(&self, view_id: &str) -> FutureResult<(), FlowyError>;
|
||||
fn close_view(&self, view_id: &str) -> FutureResult<(), FlowyError>;
|
||||
|
||||
fn get_view_data(&self, view_id: &str) -> FutureResult<Bytes, FlowyError>;
|
||||
fn get_view_data(&self, view: &ViewPB) -> FutureResult<Bytes, FlowyError>;
|
||||
|
||||
fn create_default_view(
|
||||
&self,
|
||||
user_id: &str,
|
||||
view_id: &str,
|
||||
layout: ViewLayoutTypePB,
|
||||
data_format: ViewDataFormatPB,
|
||||
) -> FutureResult<Bytes, FlowyError>;
|
||||
|
||||
fn create_view_from_delta_data(
|
||||
@ -276,7 +283,7 @@ pub trait ViewDataProcessor {
|
||||
layout: ViewLayoutTypePB,
|
||||
) -> FutureResult<Bytes, FlowyError>;
|
||||
|
||||
fn data_type(&self) -> ViewDataTypePB;
|
||||
fn data_types(&self) -> Vec<ViewDataFormatPB>;
|
||||
}
|
||||
|
||||
pub type ViewDataProcessorMap = Arc<HashMap<ViewDataTypePB, Arc<dyn ViewDataProcessor + Send + Sync>>>;
|
||||
pub type ViewDataProcessorMap = Arc<HashMap<ViewDataFormatPB, Arc<dyn ViewDataProcessor + Send + Sync>>>;
|
||||
|
@ -7,12 +7,13 @@ use bytes::Bytes;
|
||||
use flowy_database::kv::KV;
|
||||
use flowy_error::{FlowyError, FlowyResult};
|
||||
use flowy_folder_data_model::revision::{AppRevision, FolderRevision, ViewRevision, WorkspaceRevision};
|
||||
use flowy_revision::disk::SQLiteDocumentRevisionPersistence;
|
||||
use flowy_revision::disk::SQLiteDeltaDocumentRevisionPersistence;
|
||||
use flowy_revision::reset::{RevisionResettable, RevisionStructReset};
|
||||
use flowy_sync::client_folder::make_folder_rev_json_str;
|
||||
use flowy_sync::entities::revision::Revision;
|
||||
use flowy_sync::server_folder::FolderOperationsBuilder;
|
||||
use flowy_sync::{client_folder::FolderPad, entities::revision::md5};
|
||||
use lib_ot::core::DeltaBuilder;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
const V1_MIGRATION: &str = "FOLDER_V1_MIGRATION";
|
||||
@ -112,7 +113,7 @@ impl FolderMigration {
|
||||
};
|
||||
|
||||
let pool = self.database.db_pool()?;
|
||||
let disk_cache = SQLiteDocumentRevisionPersistence::new(&self.user_id, pool);
|
||||
let disk_cache = SQLiteDeltaDocumentRevisionPersistence::new(&self.user_id, pool);
|
||||
let reset = RevisionStructReset::new(&self.user_id, object, Arc::new(disk_cache));
|
||||
reset.run().await
|
||||
}
|
||||
@ -134,7 +135,7 @@ impl RevisionResettable for FolderRevisionResettable {
|
||||
fn reset_data(&self, revisions: Vec<Revision>) -> FlowyResult<Bytes> {
|
||||
let pad = FolderPad::from_revisions(revisions)?;
|
||||
let json = pad.to_json()?;
|
||||
let bytes = DeltaBuilder::new().insert(&json).build().json_bytes();
|
||||
let bytes = FolderOperationsBuilder::new().insert(&json).build().json_bytes();
|
||||
Ok(bytes)
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,8 @@ use flowy_folder_data_model::revision::{AppRevision, TrashRevision, ViewRevision
|
||||
use flowy_revision::disk::{RevisionRecord, RevisionState};
|
||||
use flowy_revision::mk_text_block_revision_disk_cache;
|
||||
use flowy_sync::{client_folder::FolderPad, entities::revision::Revision};
|
||||
use lib_ot::core::DeltaBuilder;
|
||||
|
||||
use flowy_sync::server_folder::FolderOperationsBuilder;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
pub use version_1::{app_sql::*, trash_sql::*, v1_impl::V1Transaction, view_sql::*, workspace_sql::*};
|
||||
@ -108,7 +109,7 @@ impl FolderPersistence {
|
||||
pub async fn save_folder(&self, user_id: &str, folder_id: &FolderId, folder: FolderPad) -> FlowyResult<()> {
|
||||
let pool = self.database.db_pool()?;
|
||||
let json = folder.to_json()?;
|
||||
let delta_data = DeltaBuilder::new().insert(&json).build().json_bytes();
|
||||
let delta_data = FolderOperationsBuilder::new().insert(&json).build().json_bytes();
|
||||
let revision = Revision::initial_revision(user_id, folder_id.as_ref(), delta_data);
|
||||
let record = RevisionRecord {
|
||||
revision,
|
||||
|
@ -13,7 +13,7 @@ use flowy_database::{
|
||||
SqliteConnection,
|
||||
};
|
||||
|
||||
use flowy_folder_data_model::revision::{ViewDataTypeRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use flowy_folder_data_model::revision::{ViewDataFormatRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use lib_infra::util::timestamp;
|
||||
|
||||
pub struct ViewTableSql();
|
||||
@ -78,7 +78,7 @@ pub(crate) struct ViewTable {
|
||||
pub modified_time: i64,
|
||||
pub create_time: i64,
|
||||
pub thumbnail: String,
|
||||
pub view_type: SqlViewDataType,
|
||||
pub view_type: SqlViewDataFormat,
|
||||
pub version: i64,
|
||||
pub is_trash: bool,
|
||||
pub ext_data: String,
|
||||
@ -86,9 +86,10 @@ pub(crate) struct ViewTable {
|
||||
|
||||
impl ViewTable {
|
||||
pub fn new(view_rev: ViewRevision) -> Self {
|
||||
let data_type = match view_rev.data_type {
|
||||
ViewDataTypeRevision::Text => SqlViewDataType::Block,
|
||||
ViewDataTypeRevision::Database => SqlViewDataType::Grid,
|
||||
let data_type = match view_rev.data_format {
|
||||
ViewDataFormatRevision::DeltaFormat => SqlViewDataFormat::Delta,
|
||||
ViewDataFormatRevision::DatabaseFormat => SqlViewDataFormat::Database,
|
||||
ViewDataFormatRevision::TreeFormat => SqlViewDataFormat::Tree,
|
||||
};
|
||||
|
||||
ViewTable {
|
||||
@ -110,8 +111,9 @@ impl ViewTable {
|
||||
impl std::convert::From<ViewTable> for ViewRevision {
|
||||
fn from(table: ViewTable) -> Self {
|
||||
let data_type = match table.view_type {
|
||||
SqlViewDataType::Block => ViewDataTypeRevision::Text,
|
||||
SqlViewDataType::Grid => ViewDataTypeRevision::Database,
|
||||
SqlViewDataFormat::Delta => ViewDataFormatRevision::DeltaFormat,
|
||||
SqlViewDataFormat::Database => ViewDataFormatRevision::DatabaseFormat,
|
||||
SqlViewDataFormat::Tree => ViewDataFormatRevision::TreeFormat,
|
||||
};
|
||||
|
||||
ViewRevision {
|
||||
@ -119,7 +121,7 @@ impl std::convert::From<ViewTable> for ViewRevision {
|
||||
app_id: table.belong_to_id,
|
||||
name: table.name,
|
||||
desc: table.desc,
|
||||
data_type,
|
||||
data_format: data_type,
|
||||
belongings: vec![],
|
||||
modified_time: table.modified_time,
|
||||
version: table.version,
|
||||
@ -180,34 +182,36 @@ impl ViewChangeset {
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash, FromSqlRow, AsExpression)]
|
||||
#[repr(i32)]
|
||||
#[sql_type = "Integer"]
|
||||
pub enum SqlViewDataType {
|
||||
Block = 0,
|
||||
Grid = 1,
|
||||
pub enum SqlViewDataFormat {
|
||||
Delta = 0,
|
||||
Database = 1,
|
||||
Tree = 2,
|
||||
}
|
||||
|
||||
impl std::default::Default for SqlViewDataType {
|
||||
impl std::default::Default for SqlViewDataFormat {
|
||||
fn default() -> Self {
|
||||
SqlViewDataType::Block
|
||||
SqlViewDataFormat::Delta
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<i32> for SqlViewDataType {
|
||||
impl std::convert::From<i32> for SqlViewDataFormat {
|
||||
fn from(value: i32) -> Self {
|
||||
match value {
|
||||
0 => SqlViewDataType::Block,
|
||||
1 => SqlViewDataType::Grid,
|
||||
0 => SqlViewDataFormat::Delta,
|
||||
1 => SqlViewDataFormat::Database,
|
||||
2 => SqlViewDataFormat::Tree,
|
||||
o => {
|
||||
log::error!("Unsupported view type {}, fallback to ViewType::Block", o);
|
||||
SqlViewDataType::Block
|
||||
SqlViewDataFormat::Delta
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SqlViewDataType {
|
||||
impl SqlViewDataFormat {
|
||||
pub fn value(&self) -> i32 {
|
||||
*self as i32
|
||||
}
|
||||
}
|
||||
|
||||
impl_sql_integer_expression!(SqlViewDataType);
|
||||
impl_sql_integer_expression!(SqlViewDataFormat);
|
||||
|
@ -1,4 +1,4 @@
|
||||
pub use crate::entities::view::ViewDataTypePB;
|
||||
pub use crate::entities::view::ViewDataFormatPB;
|
||||
use crate::entities::{DeletedViewPB, ViewInfoPB, ViewLayoutTypePB};
|
||||
use crate::manager::{ViewDataProcessor, ViewDataProcessorMap};
|
||||
use crate::{
|
||||
@ -58,12 +58,17 @@ impl ViewController {
|
||||
&self,
|
||||
mut params: CreateViewParams,
|
||||
) -> Result<ViewRevision, FlowyError> {
|
||||
let processor = self.get_data_processor(params.data_type.clone())?;
|
||||
let processor = self.get_data_processor(params.data_format.clone())?;
|
||||
let user_id = self.user.user_id()?;
|
||||
if params.view_content_data.is_empty() {
|
||||
tracing::trace!("Create view with build-in data");
|
||||
let view_data = processor
|
||||
.create_default_view(&user_id, ¶ms.view_id, params.layout.clone())
|
||||
.create_default_view(
|
||||
&user_id,
|
||||
¶ms.view_id,
|
||||
params.layout.clone(),
|
||||
params.data_format.clone(),
|
||||
)
|
||||
.await?;
|
||||
params.view_content_data = view_data.to_vec();
|
||||
} else {
|
||||
@ -79,7 +84,7 @@ impl ViewController {
|
||||
let _ = self
|
||||
.create_view(
|
||||
¶ms.view_id,
|
||||
params.data_type.clone(),
|
||||
params.data_format.clone(),
|
||||
params.layout.clone(),
|
||||
delta_data,
|
||||
)
|
||||
@ -91,22 +96,20 @@ impl ViewController {
|
||||
Ok(view_rev)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self, view_id, delta_data), err)]
|
||||
#[tracing::instrument(level = "debug", skip(self, view_id, view_data), err)]
|
||||
pub(crate) async fn create_view(
|
||||
&self,
|
||||
view_id: &str,
|
||||
data_type: ViewDataTypePB,
|
||||
data_type: ViewDataFormatPB,
|
||||
layout_type: ViewLayoutTypePB,
|
||||
delta_data: Bytes,
|
||||
view_data: Bytes,
|
||||
) -> Result<(), FlowyError> {
|
||||
if delta_data.is_empty() {
|
||||
if view_data.is_empty() {
|
||||
return Err(FlowyError::internal().context("The content of the view should not be empty"));
|
||||
}
|
||||
let user_id = self.user.user_id()?;
|
||||
let processor = self.get_data_processor(data_type)?;
|
||||
let _ = processor
|
||||
.create_container(&user_id, view_id, layout_type, delta_data)
|
||||
.await?;
|
||||
let _ = processor.create_view(&user_id, view_id, layout_type, view_data).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -156,7 +159,7 @@ impl ViewController {
|
||||
belong_to_id: view_rev.app_id,
|
||||
name: view_rev.name,
|
||||
desc: view_rev.desc,
|
||||
data_type: view_rev.data_type.into(),
|
||||
data_type: view_rev.data_format.into(),
|
||||
belongings: RepeatedViewPB { items },
|
||||
ext_data: view_rev.ext_data,
|
||||
};
|
||||
@ -188,7 +191,7 @@ impl ViewController {
|
||||
#[tracing::instrument(level = "debug", skip(self), err)]
|
||||
pub(crate) async fn close_view(&self, view_id: &str) -> Result<(), FlowyError> {
|
||||
let processor = self.get_data_processor_from_view_id(view_id).await?;
|
||||
let _ = processor.close_container(view_id).await?;
|
||||
let _ = processor.close_view(view_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -223,7 +226,7 @@ impl ViewController {
|
||||
.send();
|
||||
|
||||
let processor = self.get_data_processor_from_view_id(&view_id).await?;
|
||||
let _ = processor.close_container(&view_id).await?;
|
||||
let _ = processor.close_view(&view_id).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -242,20 +245,20 @@ impl ViewController {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self), err)]
|
||||
pub(crate) async fn duplicate_view(&self, view_id: &str) -> Result<(), FlowyError> {
|
||||
pub(crate) async fn duplicate_view(&self, view: ViewPB) -> Result<(), FlowyError> {
|
||||
let view_rev = self
|
||||
.persistence
|
||||
.begin_transaction(|transaction| transaction.read_view(view_id))
|
||||
.begin_transaction(|transaction| transaction.read_view(&view.id))
|
||||
.await?;
|
||||
|
||||
let processor = self.get_data_processor(view_rev.data_type.clone())?;
|
||||
let view_data = processor.get_view_data(view_id).await?;
|
||||
let processor = self.get_data_processor(view_rev.data_format.clone())?;
|
||||
let view_data = processor.get_view_data(&view).await?;
|
||||
let duplicate_params = CreateViewParams {
|
||||
belong_to_id: view_rev.app_id.clone(),
|
||||
name: format!("{} (copy)", &view_rev.name),
|
||||
desc: view_rev.desc,
|
||||
thumbnail: view_rev.thumbnail,
|
||||
data_type: view_rev.data_type.into(),
|
||||
data_format: view_rev.data_format.into(),
|
||||
layout: view_rev.layout.into(),
|
||||
view_content_data: view_data.to_vec(),
|
||||
view_id: gen_view_id(),
|
||||
@ -399,11 +402,11 @@ impl ViewController {
|
||||
.persistence
|
||||
.begin_transaction(|transaction| transaction.read_view(view_id))
|
||||
.await?;
|
||||
self.get_data_processor(view.data_type)
|
||||
self.get_data_processor(view.data_format)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_data_processor<T: Into<ViewDataTypePB>>(
|
||||
fn get_data_processor<T: Into<ViewDataFormatPB>>(
|
||||
&self,
|
||||
data_type: T,
|
||||
) -> FlowyResult<Arc<dyn ViewDataProcessor + Send + Sync>> {
|
||||
@ -472,10 +475,10 @@ async fn handle_trash_event(
|
||||
.await?;
|
||||
|
||||
for view in views {
|
||||
let data_type = view.data_type.clone().into();
|
||||
let data_type = view.data_format.clone().into();
|
||||
match get_data_processor(data_processors.clone(), &data_type) {
|
||||
Ok(processor) => {
|
||||
let _ = processor.close_container(&view.id).await?;
|
||||
let _ = processor.close_view(&view.id).await?;
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("{}", e)
|
||||
@ -491,7 +494,7 @@ async fn handle_trash_event(
|
||||
|
||||
fn get_data_processor(
|
||||
data_processors: ViewDataProcessorMap,
|
||||
data_type: &ViewDataTypePB,
|
||||
data_type: &ViewDataFormatPB,
|
||||
) -> FlowyResult<Arc<dyn ViewDataProcessor + Send + Sync>> {
|
||||
match data_processors.get(data_type) {
|
||||
None => Err(FlowyError::internal().context(format!(
|
||||
|
@ -121,10 +121,10 @@ pub(crate) async fn move_item_handler(
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, controller), err)]
|
||||
pub(crate) async fn duplicate_view_handler(
|
||||
data: Data<ViewIdPB>,
|
||||
data: Data<ViewPB>,
|
||||
controller: AppData<Arc<ViewController>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let view_id: ViewIdPB = data.into_inner();
|
||||
let _ = controller.duplicate_view(&view_id.value).await?;
|
||||
let view: ViewPB = data.into_inner();
|
||||
let _ = controller.duplicate_view(view).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::script::{invalid_workspace_name_test_case, FolderScript::*, FolderTest};
|
||||
use flowy_folder::entities::view::ViewDataTypePB;
|
||||
use flowy_folder::entities::view::ViewDataFormatPB;
|
||||
use flowy_folder::entities::workspace::CreateWorkspacePayloadPB;
|
||||
use flowy_revision::disk::RevisionState;
|
||||
use flowy_test::{event_builder::*, FlowySDKTest};
|
||||
@ -133,12 +133,12 @@ async fn app_create_with_view() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
data_type: ViewDataFormatPB::DeltaFormat,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
desc: "Grid description".to_owned(),
|
||||
data_type: ViewDataTypePB::Database,
|
||||
data_type: ViewDataFormatPB::DatabaseFormat,
|
||||
},
|
||||
ReadApp(app.id),
|
||||
])
|
||||
@ -197,12 +197,12 @@ async fn view_delete_all() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
data_type: ViewDataFormatPB::DeltaFormat,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
desc: "Grid description".to_owned(),
|
||||
data_type: ViewDataTypePB::Database,
|
||||
data_type: ViewDataFormatPB::DatabaseFormat,
|
||||
},
|
||||
ReadApp(app.id.clone()),
|
||||
])
|
||||
@ -230,7 +230,7 @@ async fn view_delete_all_permanent() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
data_type: ViewDataFormatPB::DeltaFormat,
|
||||
},
|
||||
ReadApp(app.id.clone()),
|
||||
])
|
||||
@ -329,7 +329,7 @@ async fn folder_sync_revision_with_new_view() {
|
||||
CreateView {
|
||||
name: view_name.clone(),
|
||||
desc: view_desc.clone(),
|
||||
data_type: ViewDataTypePB::Text,
|
||||
data_type: ViewDataFormatPB::DeltaFormat,
|
||||
},
|
||||
AssertCurrentRevId(3),
|
||||
AssertNextSyncRevId(Some(3)),
|
||||
|
@ -10,7 +10,7 @@ use flowy_folder::entities::{
|
||||
use flowy_folder::entities::{
|
||||
app::{AppPB, RepeatedAppPB},
|
||||
trash::TrashPB,
|
||||
view::{RepeatedViewPB, ViewDataTypePB, ViewPB},
|
||||
view::{RepeatedViewPB, ViewDataFormatPB, ViewPB},
|
||||
workspace::WorkspacePB,
|
||||
};
|
||||
use flowy_folder::event_map::FolderEvent::*;
|
||||
@ -52,7 +52,7 @@ pub enum FolderScript {
|
||||
CreateView {
|
||||
name: String,
|
||||
desc: String,
|
||||
data_type: ViewDataTypePB,
|
||||
data_type: ViewDataFormatPB,
|
||||
},
|
||||
AssertView(ViewPB),
|
||||
ReadView(String),
|
||||
@ -99,7 +99,7 @@ impl FolderTest {
|
||||
&app.id,
|
||||
"Folder View",
|
||||
"Folder test view",
|
||||
ViewDataTypePB::Text,
|
||||
ViewDataFormatPB::DeltaFormat,
|
||||
ViewLayoutTypePB::Document,
|
||||
)
|
||||
.await;
|
||||
@ -182,8 +182,9 @@ impl FolderTest {
|
||||
|
||||
FolderScript::CreateView { name, desc, data_type } => {
|
||||
let layout = match data_type {
|
||||
ViewDataTypePB::Text => ViewLayoutTypePB::Document,
|
||||
ViewDataTypePB::Database => ViewLayoutTypePB::Grid,
|
||||
ViewDataFormatPB::DeltaFormat => ViewLayoutTypePB::Document,
|
||||
ViewDataFormatPB::TreeFormat => ViewLayoutTypePB::Document,
|
||||
ViewDataFormatPB::DatabaseFormat => ViewLayoutTypePB::Grid,
|
||||
};
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, data_type, layout).await;
|
||||
self.view = view;
|
||||
@ -357,7 +358,7 @@ pub async fn create_view(
|
||||
app_id: &str,
|
||||
name: &str,
|
||||
desc: &str,
|
||||
data_type: ViewDataTypePB,
|
||||
data_type: ViewDataFormatPB,
|
||||
layout: ViewLayoutTypePB,
|
||||
) -> ViewPB {
|
||||
let request = CreateViewPayloadPB {
|
||||
@ -365,7 +366,7 @@ pub async fn create_view(
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
thumbnail: None,
|
||||
data_type,
|
||||
data_format: data_type,
|
||||
layout,
|
||||
view_content_data: vec![],
|
||||
};
|
||||
|
Reference in New Issue
Block a user