2021-12-06 07:49:21 +00:00
|
|
|
use crate::{
|
2022-01-10 15:45:59 +00:00
|
|
|
entities::{
|
2022-07-19 06:11:29 +00:00
|
|
|
app::{AppIdPB, CreateAppParams, UpdateAppParams},
|
|
|
|
trash::RepeatedTrashIdPB,
|
|
|
|
view::{CreateViewParams, RepeatedViewIdPB, UpdateViewParams, ViewIdPB},
|
|
|
|
workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceIdPB},
|
2022-01-10 15:45:59 +00:00
|
|
|
},
|
2021-12-14 10:04:51 +00:00
|
|
|
errors::FlowyError,
|
2022-03-05 13:15:10 +00:00
|
|
|
manager::FolderManager,
|
2022-01-20 15:51:11 +00:00
|
|
|
services::{app::event_handler::*, trash::event_handler::*, view::event_handler::*, workspace::event_handler::*},
|
2021-12-06 07:49:21 +00:00
|
|
|
};
|
2022-01-30 02:33:21 +00:00
|
|
|
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
|
2023-01-31 00:28:31 +00:00
|
|
|
use flowy_sqlite::{ConnectionPool, DBConnection};
|
2023-01-30 03:11:19 +00:00
|
|
|
use folder_model::{AppRevision, TrashRevision, ViewRevision, WorkspaceRevision};
|
2022-01-04 14:54:13 +00:00
|
|
|
use lib_dispatch::prelude::*;
|
2022-01-10 15:45:59 +00:00
|
|
|
use lib_infra::future::FutureResult;
|
|
|
|
use std::sync::Arc;
|
2022-03-19 08:23:34 +00:00
|
|
|
use strum_macros::Display;
|
2021-07-14 00:07:25 +00:00
|
|
|
|
2021-07-20 06:03:21 +00:00
|
|
|
pub trait WorkspaceDeps: WorkspaceUser + WorkspaceDatabase {}
|
|
|
|
|
2021-07-14 13:12:52 +00:00
|
|
|
pub trait WorkspaceUser: Send + Sync {
|
2021-12-14 10:04:51 +00:00
|
|
|
fn user_id(&self) -> Result<String, FlowyError>;
|
|
|
|
fn token(&self) -> Result<String, FlowyError>;
|
2021-07-20 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait WorkspaceDatabase: Send + Sync {
|
2021-12-14 10:04:51 +00:00
|
|
|
fn db_pool(&self) -> Result<Arc<ConnectionPool>, FlowyError>;
|
2021-09-11 12:09:46 +00:00
|
|
|
|
2021-12-14 10:04:51 +00:00
|
|
|
fn db_connection(&self) -> Result<DBConnection, FlowyError> {
|
2021-09-11 12:09:46 +00:00
|
|
|
let pool = self.db_pool()?;
|
2021-12-14 10:04:51 +00:00
|
|
|
let conn = pool.get().map_err(|e| FlowyError::internal().context(e))?;
|
2021-09-11 12:09:46 +00:00
|
|
|
Ok(conn)
|
|
|
|
}
|
2021-07-14 13:12:52 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 00:35:50 +00:00
|
|
|
pub fn init(folder: Arc<FolderManager>) -> AFPlugin {
|
|
|
|
let mut plugin = AFPlugin::new()
|
2021-07-14 00:07:25 +00:00
|
|
|
.name("Flowy-Workspace")
|
2022-12-01 00:35:50 +00:00
|
|
|
.state(folder.workspace_controller.clone())
|
|
|
|
.state(folder.app_controller.clone())
|
|
|
|
.state(folder.view_controller.clone())
|
|
|
|
.state(folder.trash_controller.clone())
|
|
|
|
.state(folder.clone());
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2022-06-15 03:43:24 +00:00
|
|
|
// Workspace
|
2022-12-01 00:35:50 +00:00
|
|
|
plugin = plugin
|
2022-01-27 12:39:54 +00:00
|
|
|
.event(FolderEvent::CreateWorkspace, create_workspace_handler)
|
2022-10-26 02:38:57 +00:00
|
|
|
.event(FolderEvent::ReadCurrentWorkspace, read_cur_workspace_handler)
|
2022-01-27 12:39:54 +00:00
|
|
|
.event(FolderEvent::ReadWorkspaces, read_workspaces_handler)
|
|
|
|
.event(FolderEvent::OpenWorkspace, open_workspace_handler)
|
|
|
|
.event(FolderEvent::ReadWorkspaceApps, read_workspace_apps_handler);
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2022-06-15 03:43:24 +00:00
|
|
|
// App
|
2022-12-01 00:35:50 +00:00
|
|
|
plugin = plugin
|
2022-01-27 12:39:54 +00:00
|
|
|
.event(FolderEvent::CreateApp, create_app_handler)
|
|
|
|
.event(FolderEvent::ReadApp, read_app_handler)
|
|
|
|
.event(FolderEvent::UpdateApp, update_app_handler)
|
|
|
|
.event(FolderEvent::DeleteApp, delete_app_handler);
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2022-06-15 03:43:24 +00:00
|
|
|
// View
|
2022-12-01 00:35:50 +00:00
|
|
|
plugin = plugin
|
2022-01-27 12:39:54 +00:00
|
|
|
.event(FolderEvent::CreateView, create_view_handler)
|
|
|
|
.event(FolderEvent::ReadView, read_view_handler)
|
|
|
|
.event(FolderEvent::UpdateView, update_view_handler)
|
|
|
|
.event(FolderEvent::DeleteView, delete_view_handler)
|
|
|
|
.event(FolderEvent::DuplicateView, duplicate_view_handler)
|
2022-03-06 13:22:42 +00:00
|
|
|
.event(FolderEvent::SetLatestView, set_latest_view_handler)
|
2022-04-26 13:20:02 +00:00
|
|
|
.event(FolderEvent::CloseView, close_view_handler)
|
2023-02-06 07:59:30 +00:00
|
|
|
.event(FolderEvent::MoveItem, move_item_handler);
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2022-06-15 03:43:24 +00:00
|
|
|
// Trash
|
2022-12-01 00:35:50 +00:00
|
|
|
plugin = plugin
|
2022-01-27 12:39:54 +00:00
|
|
|
.event(FolderEvent::ReadTrash, read_trash_handler)
|
|
|
|
.event(FolderEvent::PutbackTrash, putback_trash_handler)
|
|
|
|
.event(FolderEvent::DeleteTrash, delete_trash_handler)
|
|
|
|
.event(FolderEvent::RestoreAllTrash, restore_all_trash_handler)
|
|
|
|
.event(FolderEvent::DeleteAllTrash, delete_all_trash_handler);
|
2021-10-12 14:31:38 +00:00
|
|
|
|
2022-12-01 00:35:50 +00:00
|
|
|
plugin
|
2021-07-14 00:07:25 +00:00
|
|
|
}
|
2022-01-10 15:45:59 +00:00
|
|
|
|
2022-01-30 02:33:21 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
|
|
|
|
#[event_err = "FlowyError"]
|
|
|
|
pub enum FolderEvent {
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Create a new workspace
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "CreateWorkspacePayloadPB", output = "WorkspacePB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
CreateWorkspace = 0,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Read the current opening workspace
|
2022-10-26 02:38:57 +00:00
|
|
|
#[event(output = "WorkspaceSettingPB")]
|
|
|
|
ReadCurrentWorkspace = 1,
|
2022-01-30 02:33:21 +00:00
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Open the workspace and mark it as the current workspace
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "WorkspaceIdPB", output = "RepeatedWorkspacePB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
ReadWorkspaces = 2,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Delete the workspace
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "WorkspaceIdPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
DeleteWorkspace = 3,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Open the workspace and mark it as the current workspace
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "WorkspaceIdPB", output = "WorkspacePB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
OpenWorkspace = 4,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Return a list of apps that belong to this workspace
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "WorkspaceIdPB", output = "RepeatedAppPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
ReadWorkspaceApps = 5,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Create a new app
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "CreateAppPayloadPB", output = "AppPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
CreateApp = 101,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Delete the app
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "AppIdPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
DeleteApp = 102,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Read the app
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "AppIdPB", output = "AppPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
ReadApp = 103,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Update the app's properties including the name,description, etc.
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "UpdateAppPayloadPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
UpdateApp = 104,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Create a new view in the corresponding app
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "CreateViewPayloadPB", output = "ViewPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
CreateView = 201,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Return the view info
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "ViewIdPB", output = "ViewPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
ReadView = 202,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Update the view's properties including the name,description, etc.
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "UpdateViewPayloadPB", output = "ViewPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
UpdateView = 203,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Move the view to the trash folder
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "RepeatedViewIdPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
DeleteView = 204,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Duplicate the view
|
2022-10-22 13:57:44 +00:00
|
|
|
#[event(input = "ViewPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
DuplicateView = 205,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Close and release the resources that are used by this view.
|
|
|
|
/// It should get called when the 'View' page get destroy
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "ViewIdPB")]
|
2022-06-14 00:37:44 +00:00
|
|
|
CloseView = 206,
|
|
|
|
|
|
|
|
#[event()]
|
|
|
|
CopyLink = 220,
|
2022-01-30 02:33:21 +00:00
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Set the current visiting view
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "ViewIdPB")]
|
2022-06-14 00:37:44 +00:00
|
|
|
SetLatestView = 221,
|
2022-01-30 02:33:21 +00:00
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Move the view or app to another place
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "MoveFolderItemPayloadPB")]
|
2023-02-06 07:59:30 +00:00
|
|
|
MoveItem = 230,
|
2022-04-26 13:20:02 +00:00
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Read the trash that was deleted by the user
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(output = "RepeatedTrashPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
ReadTrash = 300,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Put back the trash to the origin folder
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "TrashIdPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
PutbackTrash = 301,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Delete the trash from the disk
|
2022-07-19 06:11:29 +00:00
|
|
|
#[event(input = "RepeatedTrashIdPB")]
|
2022-01-30 02:33:21 +00:00
|
|
|
DeleteTrash = 302,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Put back all the trash to its original folder
|
2022-01-30 02:33:21 +00:00
|
|
|
#[event()]
|
|
|
|
RestoreAllTrash = 303,
|
|
|
|
|
2023-02-06 07:59:30 +00:00
|
|
|
/// Delete all the trash from the disk
|
2022-01-30 02:33:21 +00:00
|
|
|
#[event()]
|
|
|
|
DeleteAllTrash = 304,
|
|
|
|
}
|
|
|
|
|
2022-01-17 03:55:36 +00:00
|
|
|
pub trait FolderCouldServiceV1: Send + Sync {
|
2022-01-10 15:45:59 +00:00
|
|
|
fn init(&self);
|
|
|
|
|
|
|
|
// Workspace
|
2022-06-13 12:59:46 +00:00
|
|
|
fn create_workspace(
|
|
|
|
&self,
|
|
|
|
token: &str,
|
|
|
|
params: CreateWorkspaceParams,
|
|
|
|
) -> FutureResult<WorkspaceRevision, FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
2022-07-19 06:11:29 +00:00
|
|
|
fn read_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<Vec<WorkspaceRevision>, FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
|
|
|
fn update_workspace(&self, token: &str, params: UpdateWorkspaceParams) -> FutureResult<(), FlowyError>;
|
|
|
|
|
2022-07-19 06:11:29 +00:00
|
|
|
fn delete_workspace(&self, token: &str, params: WorkspaceIdPB) -> FutureResult<(), FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
|
|
|
// View
|
2022-06-13 12:59:46 +00:00
|
|
|
fn create_view(&self, token: &str, params: CreateViewParams) -> FutureResult<ViewRevision, FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
2022-07-19 06:11:29 +00:00
|
|
|
fn read_view(&self, token: &str, params: ViewIdPB) -> FutureResult<Option<ViewRevision>, FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
2022-07-19 06:11:29 +00:00
|
|
|
fn delete_view(&self, token: &str, params: RepeatedViewIdPB) -> FutureResult<(), FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
|
|
|
fn update_view(&self, token: &str, params: UpdateViewParams) -> FutureResult<(), FlowyError>;
|
|
|
|
|
|
|
|
// App
|
2022-06-13 12:59:46 +00:00
|
|
|
fn create_app(&self, token: &str, params: CreateAppParams) -> FutureResult<AppRevision, FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
2022-07-19 06:11:29 +00:00
|
|
|
fn read_app(&self, token: &str, params: AppIdPB) -> FutureResult<Option<AppRevision>, FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
|
|
|
fn update_app(&self, token: &str, params: UpdateAppParams) -> FutureResult<(), FlowyError>;
|
|
|
|
|
2022-07-19 06:11:29 +00:00
|
|
|
fn delete_app(&self, token: &str, params: AppIdPB) -> FutureResult<(), FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
|
|
|
// Trash
|
2022-07-19 06:11:29 +00:00
|
|
|
fn create_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
2022-07-19 06:11:29 +00:00
|
|
|
fn delete_trash(&self, token: &str, params: RepeatedTrashIdPB) -> FutureResult<(), FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
|
2022-06-13 12:59:46 +00:00
|
|
|
fn read_trash(&self, token: &str) -> FutureResult<Vec<TrashRevision>, FlowyError>;
|
2022-01-10 15:45:59 +00:00
|
|
|
}
|