mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: add get grid setting handler
This commit is contained in:
parent
759d2ec111
commit
8594da65c4
@ -28,7 +28,7 @@ class BoardPluginBuilder implements PluginBuilder {
|
||||
|
||||
class BoardPluginConfig implements PluginConfig {
|
||||
@override
|
||||
bool get creatable => false;
|
||||
bool get creatable => true;
|
||||
}
|
||||
|
||||
class BoardPlugin extends Plugin {
|
||||
|
@ -15,10 +15,21 @@ pub(crate) async fn get_grid_data_handler(
|
||||
) -> DataResult<Grid, FlowyError> {
|
||||
let grid_id: GridId = data.into_inner();
|
||||
let editor = manager.open_grid(grid_id).await?;
|
||||
let grid = editor.grid_data().await?;
|
||||
let grid = editor.get_grid_data().await?;
|
||||
data_result(grid)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||
pub(crate) async fn get_grid_setting_handler(
|
||||
data: Data<GridId>,
|
||||
manager: AppData<Arc<GridManager>>,
|
||||
) -> DataResult<GridSetting, FlowyError> {
|
||||
let grid_id: GridId = data.into_inner();
|
||||
let editor = manager.open_grid(grid_id).await?;
|
||||
let grid_setting = editor.get_grid_setting().await?;
|
||||
data_result(grid_setting)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||
pub(crate) async fn get_grid_blocks_handler(
|
||||
data: Data<QueryGridBlocksPayload>,
|
||||
|
@ -10,6 +10,7 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
|
||||
module = module
|
||||
.event(GridEvent::GetGridData, get_grid_data_handler)
|
||||
.event(GridEvent::GetGridBlocks, get_grid_blocks_handler)
|
||||
.event(GridEvent::GetGridSetting, get_grid_setting_handler)
|
||||
// Field
|
||||
.event(GridEvent::GetFields, get_fields_handler)
|
||||
.event(GridEvent::UpdateField, update_field_handler)
|
||||
@ -49,6 +50,9 @@ pub enum GridEvent {
|
||||
#[event(input = "QueryGridBlocksPayload", output = "RepeatedGridBlock")]
|
||||
GetGridBlocks = 1,
|
||||
|
||||
#[event(input = "GridId", output = "GridSetting")]
|
||||
GetGridSetting = 2,
|
||||
|
||||
#[event(input = "QueryFieldPayload", output = "RepeatedField")]
|
||||
GetFields = 10,
|
||||
|
||||
|
@ -412,7 +412,7 @@ impl GridMetaEditor {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn grid_data(&self) -> FlowyResult<Grid> {
|
||||
pub async fn get_grid_data(&self) -> FlowyResult<Grid> {
|
||||
let pad_read_guard = self.grid_pad.read().await;
|
||||
let field_orders = pad_read_guard.get_field_orders();
|
||||
let mut block_orders = vec![];
|
||||
@ -432,6 +432,10 @@ impl GridMetaEditor {
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn get_grid_setting(&self) -> FlowyResult<GridSetting> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub async fn grid_block_snapshots(&self, block_ids: Option<Vec<String>>) -> FlowyResult<Vec<GridBlockSnapshot>> {
|
||||
let block_ids = match block_ids {
|
||||
None => self
|
||||
|
@ -1,28 +1,42 @@
|
||||
use crate::parser::{NotEmptyStr, ViewFilterParser, ViewGroupParser, ViewSortParser};
|
||||
use flowy_derive::ProtoBuf;
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error_code::ErrorCode;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct ViewExtData {
|
||||
pub struct GridSetting {
|
||||
#[pb(index = 1)]
|
||||
pub filter: ViewFilter,
|
||||
pub filter: HashMap<String, GridFilter>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub group: ViewGroup,
|
||||
pub group: HashMap<String, GridGroup>,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub sort: ViewSort,
|
||||
pub sort: HashMap<String, GridSort>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)]
|
||||
#[repr(u8)]
|
||||
pub enum GridLayoutType {
|
||||
Table = 0,
|
||||
Board = 1,
|
||||
}
|
||||
|
||||
impl std::default::Default for GridLayoutType {
|
||||
fn default() -> Self {
|
||||
GridLayoutType::Table
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct ViewFilter {
|
||||
pub struct GridFilter {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub field_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct ViewGroup {
|
||||
pub struct GridGroup {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub group_field_id: Option<String>,
|
||||
|
||||
@ -31,37 +45,41 @@ pub struct ViewGroup {
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct ViewSort {
|
||||
pub struct GridSort {
|
||||
#[pb(index = 1, one_of)]
|
||||
pub field_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct GridInfoChangesetPayload {
|
||||
pub struct GridSettingChangesetPayload {
|
||||
#[pb(index = 1)]
|
||||
pub grid_id: String,
|
||||
|
||||
#[pb(index = 2, one_of)]
|
||||
pub filter: Option<ViewFilter>,
|
||||
#[pb(index = 2)]
|
||||
pub layout_type: GridLayoutType,
|
||||
|
||||
#[pb(index = 3, one_of)]
|
||||
pub group: Option<ViewGroup>,
|
||||
pub filter: Option<GridFilter>,
|
||||
|
||||
#[pb(index = 4, one_of)]
|
||||
pub sort: Option<ViewSort>,
|
||||
pub group: Option<GridGroup>,
|
||||
|
||||
#[pb(index = 5, one_of)]
|
||||
pub sort: Option<GridSort>,
|
||||
}
|
||||
|
||||
pub struct GridInfoChangesetParams {
|
||||
pub struct GridSettingChangesetParams {
|
||||
pub view_id: String,
|
||||
pub filter: Option<ViewFilter>,
|
||||
pub group: Option<ViewGroup>,
|
||||
pub sort: Option<ViewSort>,
|
||||
pub layout_type: GridLayoutType,
|
||||
pub filter: Option<GridFilter>,
|
||||
pub group: Option<GridGroup>,
|
||||
pub sort: Option<GridSort>,
|
||||
}
|
||||
|
||||
impl TryInto<GridInfoChangesetParams> for GridInfoChangesetPayload {
|
||||
impl TryInto<GridSettingChangesetParams> for GridSettingChangesetPayload {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<GridInfoChangesetParams, Self::Error> {
|
||||
fn try_into(self) -> Result<GridSettingChangesetParams, Self::Error> {
|
||||
let view_id = NotEmptyStr::parse(self.grid_id)
|
||||
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
||||
.0;
|
||||
@ -81,8 +99,9 @@ impl TryInto<GridInfoChangesetParams> for GridInfoChangesetPayload {
|
||||
Some(sort) => Some(ViewSortParser::parse(sort)?),
|
||||
};
|
||||
|
||||
Ok(GridInfoChangesetParams {
|
||||
Ok(GridSettingChangesetParams {
|
||||
view_id,
|
||||
layout_type: self.layout_type,
|
||||
filter,
|
||||
group,
|
||||
sort,
|
@ -1,7 +1,7 @@
|
||||
mod field;
|
||||
mod grid;
|
||||
mod grid_info;
|
||||
mod grid_setting;
|
||||
|
||||
pub use field::*;
|
||||
pub use grid::*;
|
||||
pub use grid_info::*;
|
||||
pub use grid_setting::*;
|
||||
|
@ -1,24 +1,24 @@
|
||||
use crate::entities::{ViewFilter, ViewGroup, ViewSort};
|
||||
use crate::entities::{GridFilter, GridGroup, GridSort};
|
||||
use crate::parser::NotEmptyStr;
|
||||
use flowy_error_code::ErrorCode;
|
||||
|
||||
pub struct ViewFilterParser(pub ViewFilter);
|
||||
pub struct ViewFilterParser(pub GridFilter);
|
||||
|
||||
impl ViewFilterParser {
|
||||
pub fn parse(value: ViewFilter) -> Result<ViewFilter, ErrorCode> {
|
||||
pub fn parse(value: GridFilter) -> Result<GridFilter, ErrorCode> {
|
||||
let field_id = match value.field_id {
|
||||
None => None,
|
||||
Some(field_id) => Some(NotEmptyStr::parse(field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?.0),
|
||||
};
|
||||
|
||||
Ok(ViewFilter { field_id })
|
||||
Ok(GridFilter { field_id })
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ViewGroupParser(pub ViewGroup);
|
||||
pub struct ViewGroupParser(pub GridGroup);
|
||||
|
||||
impl ViewGroupParser {
|
||||
pub fn parse(value: ViewGroup) -> Result<ViewGroup, ErrorCode> {
|
||||
pub fn parse(value: GridGroup) -> Result<GridGroup, ErrorCode> {
|
||||
let group_field_id = match value.group_field_id {
|
||||
None => None,
|
||||
Some(group_field_id) => Some(
|
||||
@ -37,22 +37,22 @@ impl ViewGroupParser {
|
||||
),
|
||||
};
|
||||
|
||||
Ok(ViewGroup {
|
||||
Ok(GridGroup {
|
||||
group_field_id,
|
||||
sub_group_field_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ViewSortParser(pub ViewSort);
|
||||
pub struct ViewSortParser(pub GridSort);
|
||||
|
||||
impl ViewSortParser {
|
||||
pub fn parse(value: ViewSort) -> Result<ViewSort, ErrorCode> {
|
||||
pub fn parse(value: GridSort) -> Result<GridSort, ErrorCode> {
|
||||
let field_id = match value.field_id {
|
||||
None => None,
|
||||
Some(field_id) => Some(NotEmptyStr::parse(field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?.0),
|
||||
};
|
||||
|
||||
Ok(ViewSort { field_id })
|
||||
Ok(GridSort { field_id })
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,38 @@
|
||||
use crate::entities::{ViewFilter, ViewGroup, ViewSort};
|
||||
use crate::entities::{GridFilter, GridGroup, GridLayoutType, GridSetting, GridSort};
|
||||
use indexmap::IndexMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_repr::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct GridInfoRevision {
|
||||
pub filter: GridFilterRevision,
|
||||
pub group: GridGroupRevision,
|
||||
pub sort: GridSortRevision,
|
||||
pub layout: GridLayoutRevision,
|
||||
#[serde(with = "indexmap::serde_seq")]
|
||||
pub filter: IndexMap<GridLayoutRevision, GridFilterRevision>,
|
||||
|
||||
#[serde(with = "indexmap::serde_seq")]
|
||||
pub group: IndexMap<GridLayoutRevision, GridGroupRevision>,
|
||||
|
||||
#[serde(with = "indexmap::serde_seq")]
|
||||
pub sort: IndexMap<GridLayoutRevision, GridSortRevision>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct GridLayoutRevision {
|
||||
pub ty: GridLayoutType,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize_repr, Deserialize_repr)]
|
||||
#[repr(u8)]
|
||||
pub enum GridLayoutType {
|
||||
pub enum GridLayoutRevision {
|
||||
Table = 0,
|
||||
Board = 1,
|
||||
}
|
||||
|
||||
impl std::default::Default for GridLayoutType {
|
||||
impl ToString for GridLayoutRevision {
|
||||
fn to_string(&self) -> String {
|
||||
let layout_rev = self.clone() as u8;
|
||||
layout_rev.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::default::Default for GridLayoutRevision {
|
||||
fn default() -> Self {
|
||||
GridLayoutType::Table
|
||||
GridLayoutRevision::Table
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,23 +52,56 @@ pub struct GridSortRevision {
|
||||
field_id: Option<String>,
|
||||
}
|
||||
|
||||
impl std::convert::From<GridFilterRevision> for ViewFilter {
|
||||
impl std::convert::From<GridFilterRevision> for GridFilter {
|
||||
fn from(rev: GridFilterRevision) -> Self {
|
||||
ViewFilter { field_id: rev.field_id }
|
||||
GridFilter { field_id: rev.field_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<GridGroupRevision> for ViewGroup {
|
||||
impl std::convert::From<GridGroupRevision> for GridGroup {
|
||||
fn from(rev: GridGroupRevision) -> Self {
|
||||
ViewGroup {
|
||||
GridGroup {
|
||||
group_field_id: rev.group_field_id,
|
||||
sub_group_field_id: rev.sub_group_field_id,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<GridSortRevision> for ViewSort {
|
||||
impl std::convert::From<GridSortRevision> for GridSort {
|
||||
fn from(rev: GridSortRevision) -> Self {
|
||||
ViewSort { field_id: rev.field_id }
|
||||
GridSort { field_id: rev.field_id }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<GridLayoutRevision> for GridLayoutType {
|
||||
fn from(rev: GridLayoutRevision) -> Self {
|
||||
match rev {
|
||||
GridLayoutRevision::Table => GridLayoutType::Table,
|
||||
GridLayoutRevision::Board => GridLayoutType::Board,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<GridInfoRevision> for GridSetting {
|
||||
fn from(rev: GridInfoRevision) -> Self {
|
||||
let filter: HashMap<String, GridFilter> = rev
|
||||
.filter
|
||||
.into_iter()
|
||||
.map(|(layout_rev, filter_rev)| (layout_rev.to_string(), filter_rev.into()))
|
||||
.collect();
|
||||
|
||||
let group: HashMap<String, GridGroup> = rev
|
||||
.group
|
||||
.into_iter()
|
||||
.map(|(layout_rev, group_rev)| (layout_rev.to_string(), group_rev.into()))
|
||||
.collect();
|
||||
|
||||
let sort: HashMap<String, GridSort> = rev
|
||||
.sort
|
||||
.into_iter()
|
||||
.map(|(layout_rev, sort_rev)| (layout_rev.to_string(), sort_rev.into()))
|
||||
.collect();
|
||||
|
||||
GridSetting { filter, group, sort }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user