AppFlowy/frontend/rust-lib/flowy-folder/src/event_map.rs

224 lines
7.6 KiB
Rust
Raw Normal View History

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,
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};
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 {}
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-12-14 10:04:51 +00:00
fn db_connection(&self) -> Result<DBConnection, FlowyError> {
let pool = self.db_pool()?;
2021-12-14 10:04:51 +00:00
let conn = pool.get().map_err(|e| FlowyError::internal().context(e))?;
Ok(conn)
}
}
pub fn init(folder: Arc<FolderManager>) -> AFPlugin {
let mut plugin = AFPlugin::new()
2021-07-14 00:07:25 +00:00
.name("Flowy-Workspace")
.state(folder.workspace_controller.clone())
.state(folder.app_controller.clone())
.state(folder.view_controller.clone())
.state(folder.trash_controller.clone())
.state(folder.clone());
2022-06-15 03:43:24 +00:00
// Workspace
plugin = plugin
.event(FolderEvent::CreateWorkspace, create_workspace_handler)
2022-10-26 02:38:57 +00:00
.event(FolderEvent::ReadCurrentWorkspace, read_cur_workspace_handler)
.event(FolderEvent::ReadWorkspaces, read_workspaces_handler)
.event(FolderEvent::OpenWorkspace, open_workspace_handler)
.event(FolderEvent::ReadWorkspaceApps, read_workspace_apps_handler);
2022-06-15 03:43:24 +00:00
// App
plugin = plugin
.event(FolderEvent::CreateApp, create_app_handler)
.event(FolderEvent::ReadApp, read_app_handler)
.event(FolderEvent::UpdateApp, update_app_handler)
.event(FolderEvent::DeleteApp, delete_app_handler);
2022-06-15 03:43:24 +00:00
// View
plugin = plugin
.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)
.event(FolderEvent::MoveItem, move_item_handler);
2022-06-15 03:43:24 +00:00
// Trash
plugin = plugin
.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
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 {
/// 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,
/// 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
/// 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,
/// Delete the workspace
2022-07-19 06:11:29 +00:00
#[event(input = "WorkspaceIdPB")]
2022-01-30 02:33:21 +00:00
DeleteWorkspace = 3,
/// 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,
/// 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,
/// 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,
/// Delete the app
2022-07-19 06:11:29 +00:00
#[event(input = "AppIdPB")]
2022-01-30 02:33:21 +00:00
DeleteApp = 102,
/// 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,
/// 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,
/// 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,
/// 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,
/// 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,
/// 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,
/// Duplicate the view
2022-10-22 13:57:44 +00:00
#[event(input = "ViewPB")]
2022-01-30 02:33:21 +00:00
DuplicateView = 205,
/// 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
/// 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
/// Move the view or app to another place
2022-07-19 06:11:29 +00:00
#[event(input = "MoveFolderItemPayloadPB")]
MoveItem = 230,
2022-04-26 13:20:02 +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,
/// 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,
/// 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,
/// Put back all the trash to its original folder
2022-01-30 02:33:21 +00:00
#[event()]
RestoreAllTrash = 303,
/// 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
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
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
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
fn read_trash(&self, token: &str) -> FutureResult<Vec<TrashRevision>, FlowyError>;
2022-01-10 15:45:59 +00:00
}