191 lines
5.5 KiB
Rust
Raw Normal View History

use async_trait::async_trait;
use bytes::Bytes;
feat: support publish document (#5576) * feat: support a event for getting encoded collab of document * feat: support publish view and unpublish views * feat: publish page to the web * chore: refacotor share bloc * feat: call the publish event * feat: support publish view and unpublish views * feat: integrate publish api * feat: integrate unpublish api * feat: fetch the publish info to show the publish status * feat: support publish interfaces * fix: lint error * fix: modified web server * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: update codes * fix: update codes * fix: update codes * fix: update codes * fix: update codes * chore: refactor publish bloc * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: the name is too long to publish * chore: change color * fix: some style * fix: some style * feat: refacotor share menu UI * fix: some style * fix: lint * fix: some style * feat: refacotor export-as * fix: some style * chore: refactor share menu colors * fix: rust ci * fix: some style * fix: some style * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: rerelease * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: og image * fix: support copy button * fix: support copy button * fix: support copy button * chore: add a params * feat: use default publish name * chore: update copy * feat: show a confirm deletion dialog if the deleted page contains published page * feat: add copy toast in publish tab * fix: to 404 fix: to 404 fix: to 404 fix: the error to 404 * feat: unpublish the page auto when moving it to another space * feat: improve confirm deletion dialog * feat: show unpublish error * chore: use beta.appflowy.com * feat: disable publish in non-apppflowy-cloud user mode * fix: modified bullted icon style * fix: the dark mode color * fix: save the dark mode in local storage * fix: text color * chore: make bash script more portable (#5679) * fix: title longer * chore: move the files and modified the en * chore: update deploy.sh * chore: modified Dockerfile * chore: modified server.cjs to server.js * chore: modifed server.js to server.ts * chore: replace publish url * chore: remove todo list hover * chore: show confirm dialog before deleting page * fix: unpublish the pages before deleting * fix: table cell bg color * fix: callout icon * fix: list number * fix: emoji * fix: number icon * fix: callout icon position * fix: add margin bottom * fix: code block * fix: support scroll for breadcrumbs * fix: the breadcrumb doesn't update after moving page * fix: 0705 issues * fix: update publish status afer deleting page * chore: add hover effect for visit site button * fix: remove puiblish url text field enable border color * chore: update delete page copy * chore: enable debug category * fix: only render sidebar if the spaces are ready * fix: the breadcrumb doesn't update after moving page * fix: auto code * fix: add emoji * fix: add emoji * fix: favicon * fix: cypress test * fix: remove deploy ci * fix: default url * chore: revert launch.json * fix: docker ci * fix: change favicon * fix: flutter integration test * feat: add hover effect to share menu * chore: add a checkmark if the page has been published * chore: revert space deletion --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> Co-authored-by: Zack <speed2exe@live.com.sg>
2024-07-08 13:45:57 +08:00
use collab::entity::EncodedCollab;
use collab_entity::CollabType;
use collab_folder::hierarchy_builder::NestedViewBuilder;
pub use collab_folder::View;
use collab_folder::ViewLayout;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use flowy_error::FlowyError;
use lib_infra::util::timestamp;
use crate::entities::{CreateViewParams, ViewLayoutPB};
use crate::manager::FolderUser;
use crate::share::ImportType;
#[derive(Debug, Clone)]
pub enum EncodedCollabWrapper {
Document(DocumentEncodedCollab),
Database(DatabaseEncodedCollab),
Unknown,
}
#[derive(Debug, Clone)]
pub struct DocumentEncodedCollab {
pub document_encoded_collab: EncodedCollab,
}
#[derive(Debug, Clone)]
pub struct DatabaseEncodedCollab {
pub database_encoded_collab: EncodedCollab,
pub database_row_encoded_collabs: HashMap<String, EncodedCollab>,
pub database_row_document_encoded_collabs: HashMap<String, EncodedCollab>,
pub database_relations: HashMap<String, String>,
}
pub type ImportedData = (String, CollabType, EncodedCollab);
/// The handler will be used to handler the folder operation for a specific
/// view layout. Each [ViewLayout] will have a handler. So when creating a new
/// view, the [ViewLayout] will be used to get the handler.
#[async_trait]
pub trait FolderOperationHandler {
fn name(&self) -> &str;
/// Create the view for the workspace of new user.
/// Only called once when the user is created.
async fn create_workspace_view(
&self,
_uid: i64,
_workspace_view_builder: Arc<RwLock<NestedViewBuilder>>,
) -> Result<(), FlowyError> {
Ok(())
}
async fn open_view(&self, view_id: &str) -> Result<(), FlowyError>;
/// Closes the view and releases the resources that this view has in
/// the backend
async fn close_view(&self, view_id: &str) -> Result<(), FlowyError>;
/// Called when the view is deleted.
/// This will called after the view is deleted from the trash.
async fn delete_view(&self, view_id: &str) -> Result<(), FlowyError>;
/// Returns the [ViewData] that can be used to create the same view.
async fn duplicate_view(&self, view_id: &str) -> Result<Bytes, FlowyError>;
/// get the encoded collab data from the disk.
async fn get_encoded_collab_v1_from_disk(
feat: support publish document (#5576) * feat: support a event for getting encoded collab of document * feat: support publish view and unpublish views * feat: publish page to the web * chore: refacotor share bloc * feat: call the publish event * feat: support publish view and unpublish views * feat: integrate publish api * feat: integrate unpublish api * feat: fetch the publish info to show the publish status * feat: support publish interfaces * fix: lint error * fix: modified web server * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: update codes * fix: update codes * fix: update codes * fix: update codes * fix: update codes * chore: refactor publish bloc * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: the name is too long to publish * chore: change color * fix: some style * fix: some style * feat: refacotor share menu UI * fix: some style * fix: lint * fix: some style * feat: refacotor export-as * fix: some style * chore: refactor share menu colors * fix: rust ci * fix: some style * fix: some style * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: rerelease * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: og image * fix: support copy button * fix: support copy button * fix: support copy button * chore: add a params * feat: use default publish name * chore: update copy * feat: show a confirm deletion dialog if the deleted page contains published page * feat: add copy toast in publish tab * fix: to 404 fix: to 404 fix: to 404 fix: the error to 404 * feat: unpublish the page auto when moving it to another space * feat: improve confirm deletion dialog * feat: show unpublish error * chore: use beta.appflowy.com * feat: disable publish in non-apppflowy-cloud user mode * fix: modified bullted icon style * fix: the dark mode color * fix: save the dark mode in local storage * fix: text color * chore: make bash script more portable (#5679) * fix: title longer * chore: move the files and modified the en * chore: update deploy.sh * chore: modified Dockerfile * chore: modified server.cjs to server.js * chore: modifed server.js to server.ts * chore: replace publish url * chore: remove todo list hover * chore: show confirm dialog before deleting page * fix: unpublish the pages before deleting * fix: table cell bg color * fix: callout icon * fix: list number * fix: emoji * fix: number icon * fix: callout icon position * fix: add margin bottom * fix: code block * fix: support scroll for breadcrumbs * fix: the breadcrumb doesn't update after moving page * fix: 0705 issues * fix: update publish status afer deleting page * chore: add hover effect for visit site button * fix: remove puiblish url text field enable border color * chore: update delete page copy * chore: enable debug category * fix: only render sidebar if the spaces are ready * fix: the breadcrumb doesn't update after moving page * fix: auto code * fix: add emoji * fix: add emoji * fix: favicon * fix: cypress test * fix: remove deploy ci * fix: default url * chore: revert launch.json * fix: docker ci * fix: change favicon * fix: flutter integration test * feat: add hover effect to share menu * chore: add a checkmark if the page has been published * chore: revert space deletion --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> Co-authored-by: Zack <speed2exe@live.com.sg>
2024-07-08 13:45:57 +08:00
&self,
_user: Arc<dyn FolderUser>,
_view_id: &str,
) -> Result<EncodedCollabWrapper, FlowyError> {
Err(FlowyError::not_support())
}
feat: support publish document (#5576) * feat: support a event for getting encoded collab of document * feat: support publish view and unpublish views * feat: publish page to the web * chore: refacotor share bloc * feat: call the publish event * feat: support publish view and unpublish views * feat: integrate publish api * feat: integrate unpublish api * feat: fetch the publish info to show the publish status * feat: support publish interfaces * fix: lint error * fix: modified web server * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: update codes * fix: update codes * fix: update codes * fix: update codes * fix: update codes * chore: refactor publish bloc * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: some style * fix: the name is too long to publish * chore: change color * fix: some style * fix: some style * feat: refacotor share menu UI * fix: some style * fix: lint * fix: some style * feat: refacotor export-as * fix: some style * chore: refactor share menu colors * fix: rust ci * fix: some style * fix: some style * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: bugs * fix: rerelease * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: deploy * fix: og image * fix: support copy button * fix: support copy button * fix: support copy button * chore: add a params * feat: use default publish name * chore: update copy * feat: show a confirm deletion dialog if the deleted page contains published page * feat: add copy toast in publish tab * fix: to 404 fix: to 404 fix: to 404 fix: the error to 404 * feat: unpublish the page auto when moving it to another space * feat: improve confirm deletion dialog * feat: show unpublish error * chore: use beta.appflowy.com * feat: disable publish in non-apppflowy-cloud user mode * fix: modified bullted icon style * fix: the dark mode color * fix: save the dark mode in local storage * fix: text color * chore: make bash script more portable (#5679) * fix: title longer * chore: move the files and modified the en * chore: update deploy.sh * chore: modified Dockerfile * chore: modified server.cjs to server.js * chore: modifed server.js to server.ts * chore: replace publish url * chore: remove todo list hover * chore: show confirm dialog before deleting page * fix: unpublish the pages before deleting * fix: table cell bg color * fix: callout icon * fix: list number * fix: emoji * fix: number icon * fix: callout icon position * fix: add margin bottom * fix: code block * fix: support scroll for breadcrumbs * fix: the breadcrumb doesn't update after moving page * fix: 0705 issues * fix: update publish status afer deleting page * chore: add hover effect for visit site button * fix: remove puiblish url text field enable border color * chore: update delete page copy * chore: enable debug category * fix: only render sidebar if the spaces are ready * fix: the breadcrumb doesn't update after moving page * fix: auto code * fix: add emoji * fix: add emoji * fix: favicon * fix: cypress test * fix: remove deploy ci * fix: default url * chore: revert launch.json * fix: docker ci * fix: change favicon * fix: flutter integration test * feat: add hover effect to share menu * chore: add a checkmark if the page has been published * chore: revert space deletion --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> Co-authored-by: Zack <speed2exe@live.com.sg>
2024-07-08 13:45:57 +08:00
/// Create a view with the data.
///
/// # Arguments
///
/// * `user_id`: the user id
/// * `view_id`: the view id
/// * `name`: the name of the view
/// * `data`: initial data of the view. The data should be parsed by the [FolderOperationHandler]
/// implementation.
/// For example,
/// 1. the data of the database will be [DatabaseData] that is serialized to JSON
/// 2. the data of the document will be [DocumentData] that is serialized to JSON
/// * `layout`: the layout of the view
/// * `meta`: use to carry extra information. For example, the database view will use this
/// to carry the reference database id.
///
/// The return value is the [Option<EncodedCollab>] that can be used to create the view.
/// It can be used in syncing the view data to cloud.
async fn create_view_with_view_data(
&self,
user_id: i64,
params: CreateViewParams,
) -> Result<Option<EncodedCollab>, FlowyError>;
/// Create a view with the pre-defined data.
/// For example, the initial data of the grid/calendar/kanban board when
/// you create a new view.
async fn create_view_with_default_data(
&self,
user_id: i64,
view_id: &str,
name: &str,
layout: ViewLayout,
) -> Result<(), FlowyError>;
/// Create a view by importing data
///
/// The return value
async fn import_from_bytes(
&self,
uid: i64,
view_id: &str,
name: &str,
import_type: ImportType,
bytes: Vec<u8>,
) -> Result<Vec<ImportedData>, FlowyError>;
/// Create a view by importing data from a file
async fn import_from_file_path(
&self,
view_id: &str,
name: &str,
path: String,
) -> Result<(), FlowyError>;
/// Called when the view is updated. The handler is the `old` registered handler.
async fn did_update_view(&self, _old: &View, _new: &View) -> Result<(), FlowyError> {
Ok(())
}
}
pub type FolderOperationHandlers =
Arc<HashMap<ViewLayout, Arc<dyn FolderOperationHandler + Send + Sync>>>;
impl From<ViewLayoutPB> for ViewLayout {
fn from(pb: ViewLayoutPB) -> Self {
match pb {
ViewLayoutPB::Document => ViewLayout::Document,
ViewLayoutPB::Grid => ViewLayout::Grid,
ViewLayoutPB::Board => ViewLayout::Board,
ViewLayoutPB::Calendar => ViewLayout::Calendar,
ViewLayoutPB::Chat => ViewLayout::Chat,
}
}
}
pub(crate) fn create_view(uid: i64, params: CreateViewParams, layout: ViewLayout) -> View {
let time = timestamp();
View {
id: params.view_id,
parent_view_id: params.parent_view_id,
name: params.name,
created_at: time,
2023-08-02 18:50:51 +05:30
is_favorite: false,
layout,
2024-06-25 10:03:02 +08:00
icon: params.icon,
created_by: Some(uid),
last_edited_time: 0,
last_edited_by: Some(uid),
2024-06-25 10:03:02 +08:00
extra: params.extra,
children: Default::default(),
}
}
#[derive(Debug, Clone)]
pub enum ViewData {
/// Indicate the data is duplicated from another view.
DuplicateData(Bytes),
/// Indicate the data is created by the user.
Data(Bytes),
Empty,
}
impl ViewData {
pub fn is_empty(&self) -> bool {
match self {
ViewData::DuplicateData(data) => data.is_empty(),
ViewData::Data(data) => data.is_empty(),
ViewData::Empty => true,
}
}
}