mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
refactor: replace plugin type with layout type
This commit is contained in:
parent
d3cd60e527
commit
af23e3e803
@ -16,7 +16,7 @@ class BlankPluginBuilder extends PluginBuilder {
|
||||
String get menuName => "Blank";
|
||||
|
||||
@override
|
||||
PluginType get pluginType => DefaultPlugin.blank.type();
|
||||
PluginType get pluginType => PluginType.blank;
|
||||
}
|
||||
|
||||
class BlankPluginConfig implements PluginConfig {
|
||||
|
@ -20,13 +20,13 @@ class BoardPluginBuilder implements PluginBuilder {
|
||||
String get menuName => "Board";
|
||||
|
||||
@override
|
||||
PluginType get pluginType => DefaultPlugin.board.type();
|
||||
PluginType get pluginType => PluginType.board;
|
||||
|
||||
@override
|
||||
ViewDataTypePB get dataType => ViewDataTypePB.Database;
|
||||
|
||||
@override
|
||||
SubViewDataTypePB get subDataType => SubViewDataTypePB.Board;
|
||||
ViewLayoutTypePB? get subDataType => ViewLayoutTypePB.Board;
|
||||
}
|
||||
|
||||
class BoardPluginConfig implements PluginConfig {
|
||||
|
@ -42,10 +42,10 @@ class DocumentPluginBuilder extends PluginBuilder {
|
||||
String get menuName => LocaleKeys.document_menuName.tr();
|
||||
|
||||
@override
|
||||
PluginType get pluginType => DefaultPlugin.editor.type();
|
||||
PluginType get pluginType => PluginType.editor;
|
||||
|
||||
@override
|
||||
ViewDataTypePB get dataType => ViewDataTypePB.TextBlock;
|
||||
ViewDataTypePB get dataType => ViewDataTypePB.Text;
|
||||
}
|
||||
|
||||
class DocumentPlugin implements Plugin {
|
||||
|
@ -22,13 +22,13 @@ class GridPluginBuilder implements PluginBuilder {
|
||||
String get menuName => LocaleKeys.grid_menuName.tr();
|
||||
|
||||
@override
|
||||
PluginType get pluginType => DefaultPlugin.grid.type();
|
||||
PluginType get pluginType => PluginType.grid;
|
||||
|
||||
@override
|
||||
ViewDataTypePB get dataType => ViewDataTypePB.Database;
|
||||
|
||||
@override
|
||||
SubViewDataTypePB? get subDataType => SubViewDataTypePB.Grid;
|
||||
ViewLayoutTypePB? get subDataType => ViewLayoutTypePB.Grid;
|
||||
}
|
||||
|
||||
class GridPluginConfig implements PluginConfig {
|
||||
|
@ -23,7 +23,7 @@ class MenuTrash extends StatelessWidget {
|
||||
onTap: () {
|
||||
getIt<MenuSharedState>().latestOpenView = null;
|
||||
getIt<HomeStackManager>()
|
||||
.setPlugin(makePlugin(pluginType: DefaultPlugin.trash.type()));
|
||||
.setPlugin(makePlugin(pluginType: PluginType.trash));
|
||||
},
|
||||
child: _render(context),
|
||||
),
|
||||
|
@ -34,7 +34,7 @@ class TrashPluginBuilder extends PluginBuilder {
|
||||
String get menuName => "TrashPB";
|
||||
|
||||
@override
|
||||
PluginType get pluginType => DefaultPlugin.trash.type();
|
||||
PluginType get pluginType => PluginType.trash;
|
||||
}
|
||||
|
||||
class TrashPluginConfig implements PluginConfig {
|
||||
|
@ -9,7 +9,7 @@ import 'package:flutter/widgets.dart';
|
||||
|
||||
export "./src/sandbox.dart";
|
||||
|
||||
enum DefaultPlugin {
|
||||
enum PluginType {
|
||||
editor,
|
||||
blank,
|
||||
trash,
|
||||
@ -17,24 +17,24 @@ enum DefaultPlugin {
|
||||
board,
|
||||
}
|
||||
|
||||
extension FlowyDefaultPluginExt on DefaultPlugin {
|
||||
int type() {
|
||||
switch (this) {
|
||||
case DefaultPlugin.editor:
|
||||
return 0;
|
||||
case DefaultPlugin.blank:
|
||||
return 1;
|
||||
case DefaultPlugin.trash:
|
||||
return 2;
|
||||
case DefaultPlugin.grid:
|
||||
return 3;
|
||||
case DefaultPlugin.board:
|
||||
return 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
// extension FlowyDefaultPluginExt on DefaultPlugin {
|
||||
// int type() {
|
||||
// switch (this) {
|
||||
// case DefaultPlugin.editor:
|
||||
// return 0;
|
||||
// case DefaultPlugin.blank:
|
||||
// return 1;
|
||||
// case DefaultPlugin.trash:
|
||||
// return 2;
|
||||
// case DefaultPlugin.grid:
|
||||
// return 3;
|
||||
// case DefaultPlugin.board:
|
||||
// return 4;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
typedef PluginType = int;
|
||||
// typedef PluginType = int;
|
||||
typedef PluginId = String;
|
||||
|
||||
abstract class Plugin {
|
||||
@ -54,9 +54,9 @@ abstract class PluginBuilder {
|
||||
|
||||
PluginType get pluginType;
|
||||
|
||||
ViewDataTypePB get dataType => ViewDataTypePB.TextBlock;
|
||||
ViewDataTypePB get dataType => ViewDataTypePB.Text;
|
||||
|
||||
SubViewDataTypePB get subDataType;
|
||||
ViewLayoutTypePB? get subDataType => null;
|
||||
}
|
||||
|
||||
abstract class PluginConfig {
|
||||
|
@ -6,8 +6,10 @@ import '../plugin.dart';
|
||||
import 'runner.dart';
|
||||
|
||||
class PluginSandbox {
|
||||
final LinkedHashMap<PluginType, PluginBuilder> _pluginBuilders = LinkedHashMap();
|
||||
final Map<PluginType, PluginConfig> _pluginConfigs = <PluginType, PluginConfig>{};
|
||||
final LinkedHashMap<PluginType, PluginBuilder> _pluginBuilders =
|
||||
LinkedHashMap();
|
||||
final Map<PluginType, PluginConfig> _pluginConfigs =
|
||||
<PluginType, PluginConfig>{};
|
||||
late PluginRunner pluginRunner;
|
||||
|
||||
PluginSandbox() {
|
||||
@ -15,9 +17,11 @@ class PluginSandbox {
|
||||
}
|
||||
|
||||
int indexOf(PluginType pluginType) {
|
||||
final index = _pluginBuilders.keys.toList().indexWhere((ty) => ty == pluginType);
|
||||
final index =
|
||||
_pluginBuilders.keys.toList().indexWhere((ty) => ty == pluginType);
|
||||
if (index == -1) {
|
||||
throw PlatformException(code: '-1', message: "Can't find the flowy plugin type: $pluginType");
|
||||
throw PlatformException(
|
||||
code: '-1', message: "Can't find the flowy plugin type: $pluginType");
|
||||
}
|
||||
return index;
|
||||
}
|
||||
@ -27,9 +31,11 @@ class PluginSandbox {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
void registerPlugin(PluginType pluginType, PluginBuilder builder, {PluginConfig? config}) {
|
||||
void registerPlugin(PluginType pluginType, PluginBuilder builder,
|
||||
{PluginConfig? config}) {
|
||||
if (_pluginBuilders.containsKey(pluginType)) {
|
||||
throw PlatformException(code: '-1', message: "$pluginType was registered before");
|
||||
throw PlatformException(
|
||||
code: '-1', message: "$pluginType was registered before");
|
||||
}
|
||||
_pluginBuilders[pluginType] = builder;
|
||||
|
||||
@ -38,7 +44,7 @@ class PluginSandbox {
|
||||
}
|
||||
}
|
||||
|
||||
List<int> get supportPluginTypes => _pluginBuilders.keys.toList();
|
||||
List<PluginType> get supportPluginTypes => _pluginBuilders.keys.toList();
|
||||
|
||||
List<PluginBuilder> get builders => _pluginBuilders.values.toList();
|
||||
|
||||
|
@ -86,7 +86,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
|
||||
desc: value.desc,
|
||||
dataType: value.dataType,
|
||||
pluginType: value.pluginType,
|
||||
subDataType: value.subDataType,
|
||||
layout: value.layout,
|
||||
);
|
||||
viewOrFailed.fold(
|
||||
(view) => emit(state.copyWith(
|
||||
@ -140,7 +140,7 @@ class AppEvent with _$AppEvent {
|
||||
String name,
|
||||
String desc,
|
||||
ViewDataTypePB dataType,
|
||||
SubViewDataTypePB subDataType,
|
||||
ViewLayoutTypePB layout,
|
||||
PluginType pluginType,
|
||||
) = CreateView;
|
||||
const factory AppEvent.delete() = Delete;
|
||||
|
@ -26,18 +26,14 @@ class AppService {
|
||||
required String desc,
|
||||
required ViewDataTypePB dataType,
|
||||
required PluginType pluginType,
|
||||
SubViewDataTypePB? subDataType,
|
||||
required ViewLayoutTypePB layout,
|
||||
}) {
|
||||
var payload = CreateViewPayloadPB.create()
|
||||
..belongToId = appId
|
||||
..name = name
|
||||
..desc = desc
|
||||
..dataType = dataType
|
||||
..pluginType = pluginType;
|
||||
|
||||
if (subDataType != null) {
|
||||
payload.subDataType = subDataType;
|
||||
}
|
||||
..layout = layout;
|
||||
|
||||
return FolderEventCreateView(payload).send();
|
||||
}
|
||||
|
@ -113,6 +113,6 @@ class MenuState with _$MenuState {
|
||||
factory MenuState.initial() => MenuState(
|
||||
apps: [],
|
||||
successOrFailure: left(unit),
|
||||
plugin: makePlugin(pluginType: DefaultPlugin.blank.type()),
|
||||
plugin: makePlugin(pluginType: PluginType.blank),
|
||||
);
|
||||
}
|
||||
|
@ -40,6 +40,19 @@ extension ViewExtension on ViewPB {
|
||||
return widget;
|
||||
}
|
||||
|
||||
PluginType get pluginType {
|
||||
switch (layout) {
|
||||
case ViewLayoutTypePB.Board:
|
||||
return PluginType.board;
|
||||
case ViewLayoutTypePB.Document:
|
||||
return PluginType.editor;
|
||||
case ViewLayoutTypePB.Grid:
|
||||
return PluginType.grid;
|
||||
}
|
||||
|
||||
throw UnimplementedError;
|
||||
}
|
||||
|
||||
Plugin plugin() {
|
||||
final plugin = makePlugin(pluginType: pluginType, data: this);
|
||||
return plugin;
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:app_flowy/startup/plugin/plugin.dart';
|
||||
import 'package:app_flowy/workspace/application/home/home_bloc.dart';
|
||||
import 'package:app_flowy/workspace/application/view/view_ext.dart';
|
||||
import 'package:app_flowy/workspace/presentation/widgets/edit_panel/panel_animation.dart';
|
||||
import 'package:app_flowy/workspace/presentation/widgets/float_bubble/question_bubble.dart';
|
||||
import 'package:app_flowy/startup/startup.dart';
|
||||
|
@ -107,7 +107,7 @@ class HomeStackNotifier extends ChangeNotifier {
|
||||
Widget get titleWidget => _plugin.display.leftBarItem;
|
||||
|
||||
HomeStackNotifier({Plugin? plugin})
|
||||
: _plugin = plugin ?? makePlugin(pluginType: DefaultPlugin.blank.type());
|
||||
: _plugin = plugin ?? makePlugin(pluginType: PluginType.blank);
|
||||
|
||||
set plugin(Plugin newPlugin) {
|
||||
if (newPlugin.id == _plugin.id) {
|
||||
|
@ -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, ViewRevision};
|
||||
use flowy_folder_data_model::revision::{gen_view_id, ViewDataTypeRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
@ -31,7 +31,7 @@ pub struct ViewPB {
|
||||
pub create_time: i64,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub plugin_type: i32,
|
||||
pub layout: ViewLayoutTypePB,
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewRevision> for ViewPB {
|
||||
@ -43,14 +43,14 @@ impl std::convert::From<ViewRevision> for ViewPB {
|
||||
data_type: rev.data_type.into(),
|
||||
modified_time: rev.modified_time,
|
||||
create_time: rev.create_time,
|
||||
plugin_type: rev.plugin_type,
|
||||
layout: rev.layout.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
||||
pub enum ViewDataTypePB {
|
||||
Document = 0,
|
||||
Text = 0,
|
||||
Database = 1,
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ impl std::default::Default for ViewDataTypePB {
|
||||
impl std::convert::From<ViewDataTypeRevision> for ViewDataTypePB {
|
||||
fn from(rev: ViewDataTypeRevision) -> Self {
|
||||
match rev {
|
||||
ViewDataTypeRevision::Document => ViewDataTypePB::Document,
|
||||
ViewDataTypeRevision::Text => ViewDataTypePB::Text,
|
||||
ViewDataTypeRevision::Database => ViewDataTypePB::Database,
|
||||
}
|
||||
}
|
||||
@ -72,7 +72,7 @@ impl std::convert::From<ViewDataTypeRevision> for ViewDataTypePB {
|
||||
impl std::convert::From<ViewDataTypePB> for ViewDataTypeRevision {
|
||||
fn from(ty: ViewDataTypePB) -> Self {
|
||||
match ty {
|
||||
ViewDataTypePB::Document => ViewDataTypeRevision::Document,
|
||||
ViewDataTypePB::Text => ViewDataTypeRevision::Text,
|
||||
ViewDataTypePB::Database => ViewDataTypeRevision::Database,
|
||||
}
|
||||
}
|
||||
@ -80,8 +80,9 @@ impl std::convert::From<ViewDataTypePB> for ViewDataTypeRevision {
|
||||
|
||||
#[derive(Eq, PartialEq, Hash, Debug, ProtoBuf_Enum, Clone)]
|
||||
pub enum ViewLayoutTypePB {
|
||||
Grid = 0,
|
||||
Board = 1,
|
||||
Document = 0,
|
||||
Grid = 3,
|
||||
Board = 4,
|
||||
}
|
||||
|
||||
impl std::default::Default for ViewLayoutTypePB {
|
||||
@ -90,6 +91,26 @@ impl std::default::Default for ViewLayoutTypePB {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewLayoutTypeRevision> for ViewLayoutTypePB {
|
||||
fn from(rev: ViewLayoutTypeRevision) -> Self {
|
||||
match rev {
|
||||
ViewLayoutTypeRevision::Grid => ViewLayoutTypePB::Grid,
|
||||
ViewLayoutTypeRevision::Board => ViewLayoutTypePB::Board,
|
||||
ViewLayoutTypeRevision::Document => ViewLayoutTypePB::Document,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<ViewLayoutTypePB> for ViewLayoutTypeRevision {
|
||||
fn from(rev: ViewLayoutTypePB) -> Self {
|
||||
match rev {
|
||||
ViewLayoutTypePB::Grid => ViewLayoutTypeRevision::Grid,
|
||||
ViewLayoutTypePB::Board => ViewLayoutTypeRevision::Board,
|
||||
ViewLayoutTypePB::Document => ViewLayoutTypeRevision::Document,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
|
||||
pub struct RepeatedViewPB {
|
||||
#[pb(index = 1)]
|
||||
@ -131,9 +152,6 @@ pub struct CreateViewPayloadPB {
|
||||
pub layout: ViewLayoutTypePB,
|
||||
|
||||
#[pb(index = 7)]
|
||||
pub plugin_type: i32,
|
||||
|
||||
#[pb(index = 8)]
|
||||
pub view_content_data: Vec<u8>,
|
||||
}
|
||||
|
||||
@ -147,7 +165,6 @@ pub struct CreateViewParams {
|
||||
pub layout: ViewLayoutTypePB,
|
||||
pub view_id: String,
|
||||
pub view_content_data: Vec<u8>,
|
||||
pub plugin_type: i32,
|
||||
}
|
||||
|
||||
impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
||||
@ -171,7 +188,6 @@ impl TryInto<CreateViewParams> for CreateViewPayloadPB {
|
||||
thumbnail,
|
||||
view_id,
|
||||
view_content_data: self.view_content_data,
|
||||
plugin_type: self.plugin_type,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ impl DefaultFolderBuilder {
|
||||
};
|
||||
let _ = view_controller.set_latest_view(&view.id);
|
||||
let _ = view_controller
|
||||
.create_view(&view.id, ViewDataTypePB::Document, Bytes::from(view_data))
|
||||
.create_view(&view.id, ViewDataTypePB::Text, Bytes::from(view_data))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ use flowy_database::{
|
||||
SqliteConnection,
|
||||
};
|
||||
|
||||
use flowy_folder_data_model::revision::{ViewDataTypeRevision, ViewRevision};
|
||||
use flowy_folder_data_model::revision::{ViewDataTypeRevision, ViewLayoutTypeRevision, ViewRevision};
|
||||
use lib_infra::util::timestamp;
|
||||
|
||||
pub struct ViewTableSql();
|
||||
@ -87,7 +87,7 @@ pub(crate) struct ViewTable {
|
||||
impl ViewTable {
|
||||
pub fn new(view_rev: ViewRevision) -> Self {
|
||||
let data_type = match view_rev.data_type {
|
||||
ViewDataTypeRevision::Document => SqlViewDataType::Block,
|
||||
ViewDataTypeRevision::Text => SqlViewDataType::Block,
|
||||
ViewDataTypeRevision::Database => SqlViewDataType::Grid,
|
||||
};
|
||||
|
||||
@ -110,7 +110,7 @@ impl ViewTable {
|
||||
impl std::convert::From<ViewTable> for ViewRevision {
|
||||
fn from(table: ViewTable) -> Self {
|
||||
let data_type = match table.view_type {
|
||||
SqlViewDataType::Block => ViewDataTypeRevision::Document,
|
||||
SqlViewDataType::Block => ViewDataTypeRevision::Text,
|
||||
SqlViewDataType::Grid => ViewDataTypeRevision::Database,
|
||||
};
|
||||
|
||||
@ -127,8 +127,8 @@ impl std::convert::From<ViewTable> for ViewRevision {
|
||||
ext_data: "".to_string(),
|
||||
thumbnail: table.thumbnail,
|
||||
// Store the view in ViewTable was deprecated since v0.0.2.
|
||||
// No need to worry about plugin_type.
|
||||
plugin_type: 0,
|
||||
// No need to worry about layout.
|
||||
layout: ViewLayoutTypeRevision::Document,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -220,10 +220,9 @@ impl ViewController {
|
||||
desc: view_rev.desc,
|
||||
thumbnail: view_rev.thumbnail,
|
||||
data_type: view_rev.data_type.into(),
|
||||
layout: ViewLayoutTypePB::Board,
|
||||
layout: view_rev.layout.into(),
|
||||
view_content_data: delta_bytes.to_vec(),
|
||||
view_id: gen_view_id(),
|
||||
plugin_type: view_rev.plugin_type,
|
||||
};
|
||||
|
||||
let _ = self.create_view_from_params(duplicate_params).await?;
|
||||
@ -468,7 +467,7 @@ fn make_view_rev_from(params: CreateViewParams) -> ViewRevision {
|
||||
create_time: time,
|
||||
ext_data: "".to_string(),
|
||||
thumbnail: params.thumbnail,
|
||||
plugin_type: params.plugin_type,
|
||||
layout: params.layout.into(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ async fn app_create_with_view() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
@ -198,7 +198,7 @@ async fn view_delete_all() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
CreateView {
|
||||
name: "Grid".to_owned(),
|
||||
@ -231,7 +231,7 @@ async fn view_delete_all_permanent() {
|
||||
CreateView {
|
||||
name: "View A".to_owned(),
|
||||
desc: "View A description".to_owned(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
ReadApp(app.id.clone()),
|
||||
])
|
||||
@ -330,7 +330,7 @@ async fn folder_sync_revision_with_new_view() {
|
||||
CreateView {
|
||||
name: view_name.clone(),
|
||||
desc: view_desc.clone(),
|
||||
data_type: ViewDataTypePB::Document,
|
||||
data_type: ViewDataTypePB::Text,
|
||||
},
|
||||
AssertCurrentRevId(3),
|
||||
AssertNextSyncRevId(Some(3)),
|
||||
|
@ -53,6 +53,7 @@ pub enum FolderScript {
|
||||
name: String,
|
||||
desc: String,
|
||||
data_type: ViewDataTypePB,
|
||||
layout: ViewLayoutTypePB,
|
||||
},
|
||||
AssertView(ViewPB),
|
||||
ReadView(String),
|
||||
@ -99,7 +100,8 @@ impl FolderTest {
|
||||
&app.id,
|
||||
"Folder View",
|
||||
"Folder test view",
|
||||
ViewDataTypePB::Document,
|
||||
ViewDataTypePB::Text,
|
||||
ViewLayoutTypePB::Document,
|
||||
)
|
||||
.await;
|
||||
app.belongings = RepeatedViewPB {
|
||||
@ -179,8 +181,13 @@ impl FolderTest {
|
||||
delete_app(sdk, &self.app.id).await;
|
||||
}
|
||||
|
||||
FolderScript::CreateView { name, desc, data_type } => {
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, data_type).await;
|
||||
FolderScript::CreateView {
|
||||
name,
|
||||
desc,
|
||||
data_type,
|
||||
layout,
|
||||
} => {
|
||||
let view = create_view(sdk, &self.app.id, &name, &desc, data_type, layout).await;
|
||||
self.view = view;
|
||||
}
|
||||
FolderScript::AssertView(view) => {
|
||||
@ -353,20 +360,15 @@ pub async fn create_view(
|
||||
name: &str,
|
||||
desc: &str,
|
||||
data_type: ViewDataTypePB,
|
||||
layout: ViewLayoutTypePB,
|
||||
) -> ViewPB {
|
||||
let sub_data_type = match data_type {
|
||||
ViewDataTypePB::Document => None,
|
||||
ViewDataTypePB::Database => Some(ViewLayoutTypePB::Grid),
|
||||
};
|
||||
|
||||
let request = CreateViewPayloadPB {
|
||||
belong_to_id: app_id.to_string(),
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
thumbnail: None,
|
||||
data_type,
|
||||
layout: sub_data_type,
|
||||
plugin_type: 0,
|
||||
layout,
|
||||
view_content_data: vec![],
|
||||
};
|
||||
let view = FolderEventBuilder::new(sdk.clone())
|
||||
|
@ -315,7 +315,7 @@ impl FolderCouldServiceV1 for LocalServer {
|
||||
create_time: time,
|
||||
ext_data: "".to_string(),
|
||||
thumbnail: params.thumbnail,
|
||||
plugin_type: params.plugin_type,
|
||||
layout: params.layout.into(),
|
||||
};
|
||||
FutureResult::new(async { Ok(view) })
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ impl ViewDataProcessor for TextBlockViewDataProcessor {
|
||||
}
|
||||
|
||||
fn data_type(&self) -> ViewDataTypePB {
|
||||
ViewDataTypePB::Document
|
||||
ViewDataTypePB::Text
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,16 +261,20 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
||||
&self,
|
||||
user_id: &str,
|
||||
view_id: &str,
|
||||
sub_data_type: ViewLayoutTypePB,
|
||||
layout: ViewLayoutTypePB,
|
||||
) -> FutureResult<Bytes, FlowyError> {
|
||||
let build_context = match sub_data_type {
|
||||
let build_context = match layout {
|
||||
ViewLayoutTypePB::Grid => make_default_grid(),
|
||||
ViewLayoutTypePB::Board => make_default_board(),
|
||||
ViewLayoutTypePB::Document => {
|
||||
return FutureResult::new(async move {
|
||||
Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))
|
||||
});
|
||||
}
|
||||
};
|
||||
let user_id = user_id.to_string();
|
||||
let view_id = view_id.to_string();
|
||||
let grid_manager = self.0.clone();
|
||||
|
||||
FutureResult::new(async move { make_grid_view_data(&user_id, &view_id, grid_manager, build_context).await })
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ impl ViewTest {
|
||||
}
|
||||
|
||||
pub async fn new_text_block_view(sdk: &FlowySDKTest) -> Self {
|
||||
Self::new(sdk, ViewDataTypePB::Document, ViewLayoutTypePB::Grid, vec![]).await
|
||||
Self::new(sdk, ViewDataTypePB::Text, ViewLayoutTypePB::Grid, vec![]).await
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +103,7 @@ async fn create_view(
|
||||
sdk: &FlowySDKTest,
|
||||
app_id: &str,
|
||||
data_type: ViewDataTypePB,
|
||||
sub_data_type: ViewLayoutTypePB,
|
||||
layout: ViewLayoutTypePB,
|
||||
data: Vec<u8>,
|
||||
) -> ViewPB {
|
||||
let request = CreateViewPayloadPB {
|
||||
@ -112,8 +112,7 @@ async fn create_view(
|
||||
desc: "".to_string(),
|
||||
thumbnail: Some("http://1.png".to_string()),
|
||||
data_type,
|
||||
layout: sub_data_type,
|
||||
plugin_type: 0,
|
||||
layout,
|
||||
view_content_data: data,
|
||||
};
|
||||
|
||||
|
@ -35,9 +35,10 @@ pub struct ViewRevision {
|
||||
pub thumbnail: String,
|
||||
|
||||
#[serde(default = "DEFAULT_PLUGIN_TYPE")]
|
||||
pub plugin_type: i32,
|
||||
#[serde(rename = "plugin_type")]
|
||||
pub layout: ViewLayoutTypeRevision,
|
||||
}
|
||||
const DEFAULT_PLUGIN_TYPE: fn() -> i32 = || 0;
|
||||
const DEFAULT_PLUGIN_TYPE: fn() -> ViewLayoutTypeRevision = || ViewLayoutTypeRevision::Document;
|
||||
|
||||
impl std::convert::From<ViewRevision> for TrashRevision {
|
||||
fn from(view_rev: ViewRevision) -> Self {
|
||||
@ -54,12 +55,27 @@ impl std::convert::From<ViewRevision> for TrashRevision {
|
||||
#[derive(Eq, PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum ViewDataTypeRevision {
|
||||
Document = 0,
|
||||
Text = 0,
|
||||
Database = 1,
|
||||
}
|
||||
|
||||
impl std::default::Default for ViewDataTypeRevision {
|
||||
fn default() -> Self {
|
||||
ViewDataTypeRevision::Document
|
||||
ViewDataTypeRevision::Text
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Debug, Clone, Serialize_repr, Deserialize_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum ViewLayoutTypeRevision {
|
||||
Document = 0,
|
||||
// The for historical reasons, the value of Grid is not 1.
|
||||
Grid = 3,
|
||||
Board = 4,
|
||||
}
|
||||
|
||||
impl std::default::Default for ViewLayoutTypeRevision {
|
||||
fn default() -> Self {
|
||||
ViewLayoutTypeRevision::Document
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use crate::revision::{
|
||||
gen_app_id, gen_view_id, gen_workspace_id, AppRevision, ViewDataTypeRevision, ViewRevision, WorkspaceRevision,
|
||||
gen_app_id, gen_view_id, gen_workspace_id, AppRevision, ViewDataTypeRevision, ViewLayoutTypeRevision, ViewRevision,
|
||||
WorkspaceRevision,
|
||||
};
|
||||
use chrono::Utc;
|
||||
|
||||
@ -46,16 +47,16 @@ fn create_default_view(app_id: String, time: chrono::DateTime<Utc>) -> ViewRevis
|
||||
|
||||
ViewRevision {
|
||||
id: view_id,
|
||||
app_id: app_id,
|
||||
app_id,
|
||||
name,
|
||||
desc: "".to_string(),
|
||||
data_type: ViewDataTypeRevision::Document,
|
||||
data_type: ViewDataTypeRevision::Text,
|
||||
version: 0,
|
||||
belongings: vec![],
|
||||
modified_time: time.timestamp(),
|
||||
create_time: time.timestamp(),
|
||||
ext_data: "".to_string(),
|
||||
thumbnail: "".to_string(),
|
||||
plugin_type: 0,
|
||||
layout: ViewLayoutTypeRevision::Document,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user