mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: make grid setting from revision
This commit is contained in:
@ -22,16 +22,16 @@ pub struct RepeatedGridFilter {
|
||||
pub items: Vec<GridFilter>,
|
||||
}
|
||||
|
||||
impl std::convert::From<&Arc<GridFilterRevision>> for GridFilter {
|
||||
fn from(rev: &Arc<GridFilterRevision>) -> Self {
|
||||
impl std::convert::From<&GridFilterRevision> for GridFilter {
|
||||
fn from(rev: &GridFilterRevision) -> Self {
|
||||
Self { id: rev.id.clone() }
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&Vec<Arc<GridFilterRevision>>> for RepeatedGridFilter {
|
||||
fn from(revs: &Vec<Arc<GridFilterRevision>>) -> Self {
|
||||
impl std::convert::From<Vec<Arc<GridFilterRevision>>> for RepeatedGridFilter {
|
||||
fn from(revs: Vec<Arc<GridFilterRevision>>) -> Self {
|
||||
RepeatedGridFilter {
|
||||
items: revs.iter().map(|rev| rev.into()).collect(),
|
||||
items: revs.into_iter().map(|rev| rev.as_ref().into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
use flowy_grid_data_model::revision::GridGroupRevision;
|
||||
use flowy_sync::entities::grid::CreateGridGroupParams;
|
||||
use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GridGroup {
|
||||
@ -39,10 +40,10 @@ impl std::convert::From<Vec<GridGroup>> for RepeatedGridGroup {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<&Vec<GridGroupRevision>> for RepeatedGridGroup {
|
||||
fn from(revs: &Vec<GridGroupRevision>) -> Self {
|
||||
impl std::convert::From<Vec<Arc<GridGroupRevision>>> for RepeatedGridGroup {
|
||||
fn from(revs: Vec<Arc<GridGroupRevision>>) -> Self {
|
||||
RepeatedGridGroup {
|
||||
items: revs.iter().map(|rev| rev.into()).collect(),
|
||||
items: revs.iter().map(|rev| rev.as_ref().into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +1,53 @@
|
||||
use crate::entities::{
|
||||
CreateGridFilterPayload, CreateGridGroupPayload, CreateGridSortPayload, DeleteFilterPayload, RepeatedGridFilter,
|
||||
RepeatedGridGroup, RepeatedGridSort,
|
||||
CreateGridFilterPayload, CreateGridGroupPayload, CreateGridSortPayload, DeleteFilterPayload, GridFilter, GridGroup,
|
||||
GridSort, RepeatedGridFilter, RepeatedGridGroup, RepeatedGridSort,
|
||||
};
|
||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||
use flowy_error::ErrorCode;
|
||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
use flowy_grid_data_model::revision::GridLayoutRevision;
|
||||
use flowy_grid_data_model::revision::{GridLayoutRevision, GridSettingRevision};
|
||||
use flowy_sync::entities::grid::GridSettingChangesetParams;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GridSetting {
|
||||
#[pb(index = 1)]
|
||||
pub filters_by_layout_ty: HashMap<String, RepeatedGridFilter>,
|
||||
pub layouts: Vec<GridLayout>,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub groups_by_layout_ty: HashMap<String, RepeatedGridGroup>,
|
||||
pub current_layout_type: GridLayoutType,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub sorts_by_layout_ty: HashMap<String, RepeatedGridSort>,
|
||||
pub filters_by_field_id: HashMap<String, RepeatedGridFilter>,
|
||||
|
||||
#[pb(index = 4)]
|
||||
pub groups_by_field_id: HashMap<String, RepeatedGridGroup>,
|
||||
|
||||
#[pb(index = 5)]
|
||||
pub sorts_by_field_id: HashMap<String, RepeatedGridSort>,
|
||||
}
|
||||
|
||||
//
|
||||
// impl std::convert::From<&GridSettingRevision> for GridSetting {
|
||||
// fn from(rev: &GridSettingRevision) -> Self {
|
||||
// let filters_by_layout_ty: HashMap<String, RepeatedGridFilter> = rev
|
||||
// .filters
|
||||
// .iter()
|
||||
// .map(|(layout_rev, filter_revs)| (layout_rev.to_string(), filter_revs.into()))
|
||||
// .collect();
|
||||
//
|
||||
// let groups_by_layout_ty: HashMap<String, RepeatedGridGroup> = rev
|
||||
// .groups
|
||||
// .iter()
|
||||
// .map(|(layout_rev, group_revs)| (layout_rev.to_string(), group_revs.into()))
|
||||
// .collect();
|
||||
//
|
||||
// let sorts_by_layout_ty: HashMap<String, RepeatedGridSort> = rev
|
||||
// .sorts
|
||||
// .iter()
|
||||
// .map(|(layout_rev, sort_revs)| (layout_rev.to_string(), sort_revs.into()))
|
||||
// .collect();
|
||||
//
|
||||
// GridSetting {
|
||||
// filters_by_layout_ty,
|
||||
// groups_by_layout_ty,
|
||||
// sorts_by_layout_ty,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum)]
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GridLayout {
|
||||
#[pb(index = 1)]
|
||||
ty: GridLayoutType,
|
||||
}
|
||||
|
||||
impl GridLayout {
|
||||
pub fn all() -> Vec<GridLayout> {
|
||||
let mut layouts = vec![];
|
||||
for layout_ty in GridLayoutType::iter() {
|
||||
layouts.push(GridLayout { ty: layout_ty })
|
||||
}
|
||||
|
||||
layouts
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]
|
||||
#[repr(u8)]
|
||||
pub enum GridLayoutType {
|
||||
Table = 0,
|
||||
|
@ -4,6 +4,7 @@ use flowy_grid_data_model::parser::NotEmptyStr;
|
||||
use flowy_grid_data_model::revision::GridSortRevision;
|
||||
use flowy_sync::entities::grid::CreateGridSortParams;
|
||||
use std::convert::TryInto;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||
pub struct GridSort {
|
||||
@ -30,10 +31,10 @@ pub struct RepeatedGridSort {
|
||||
pub items: Vec<GridSort>,
|
||||
}
|
||||
|
||||
impl std::convert::From<&Vec<GridSortRevision>> for RepeatedGridSort {
|
||||
fn from(revs: &Vec<GridSortRevision>) -> Self {
|
||||
impl std::convert::From<Vec<Arc<GridSortRevision>>> for RepeatedGridSort {
|
||||
fn from(revs: Vec<Arc<GridSortRevision>>) -> Self {
|
||||
RepeatedGridSort {
|
||||
items: revs.iter().map(|rev| rev.into()).collect(),
|
||||
items: revs.into_iter().map(|rev| rev.as_ref().into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use crate::services::row::{
|
||||
make_grid_blocks, make_row_from_row_rev, make_row_rev_from_context, make_rows_from_row_revs,
|
||||
CreateRowRevisionBuilder, CreateRowRevisionPayload, GridBlockSnapshot,
|
||||
};
|
||||
use crate::services::setting::make_grid_setting;
|
||||
use bytes::Bytes;
|
||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||
use flowy_grid_data_model::revision::*;
|
||||
@ -453,17 +454,21 @@ impl GridRevisionEditor {
|
||||
}
|
||||
|
||||
pub async fn get_grid_setting(&self) -> FlowyResult<GridSetting> {
|
||||
// let read_guard = self.grid_pad.read().await;
|
||||
// let grid_setting_rev = read_guard.get_grid_setting_rev();
|
||||
// Ok(grid_setting_rev.into())
|
||||
todo!()
|
||||
let read_guard = self.grid_pad.read().await;
|
||||
let grid_setting_rev = read_guard.get_grid_setting_rev();
|
||||
let field_revs = read_guard.get_field_revs(None)?;
|
||||
let grid_setting = make_grid_setting(grid_setting_rev, &field_revs);
|
||||
Ok(grid_setting)
|
||||
}
|
||||
|
||||
pub async fn get_grid_filter(&self, layout_type: &GridLayoutType) -> FlowyResult<Vec<GridFilter>> {
|
||||
let read_guard = self.grid_pad.read().await;
|
||||
let layout_rev = layout_type.clone().into();
|
||||
match read_guard.get_filters(Some(&layout_rev), None) {
|
||||
Some(filter_revs) => Ok(filter_revs.iter().map(GridFilter::from).collect::<Vec<GridFilter>>()),
|
||||
Some(filter_revs) => Ok(filter_revs
|
||||
.iter()
|
||||
.map(|filter_rev| filter_rev.as_ref().into())
|
||||
.collect::<Vec<GridFilter>>()),
|
||||
None => Ok(vec![]),
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
use crate::entities::GridLayoutType;
|
||||
use crate::entities::{
|
||||
GridLayout, GridLayoutType, GridSetting, RepeatedGridFilter, RepeatedGridGroup, RepeatedGridSort,
|
||||
};
|
||||
use flowy_grid_data_model::revision::{FieldRevision, GridSettingRevision};
|
||||
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct GridSettingChangesetBuilder {
|
||||
params: GridSettingChangesetParams,
|
||||
@ -34,3 +39,48 @@ impl GridSettingChangesetBuilder {
|
||||
self.params
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_grid_setting(grid_setting_rev: &GridSettingRevision, field_revs: &[Arc<FieldRevision>]) -> GridSetting {
|
||||
let current_layout_type: GridLayoutType = grid_setting_rev.layout.clone().into();
|
||||
let filters_by_field_id = grid_setting_rev
|
||||
.get_all_filter(&field_revs)
|
||||
.and_then(|filters_by_field_id| {
|
||||
Some(
|
||||
filters_by_field_id
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into()))
|
||||
.collect::<HashMap<String, RepeatedGridFilter>>(),
|
||||
)
|
||||
})
|
||||
.unwrap_or(HashMap::default());
|
||||
let groups_by_field_id = grid_setting_rev
|
||||
.get_all_group()
|
||||
.and_then(|groups_by_field_id| {
|
||||
Some(
|
||||
groups_by_field_id
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into()))
|
||||
.collect::<HashMap<String, RepeatedGridGroup>>(),
|
||||
)
|
||||
})
|
||||
.unwrap_or(HashMap::default());
|
||||
let sorts_by_field_id = grid_setting_rev
|
||||
.get_all_sort()
|
||||
.and_then(|sorts_by_field_id| {
|
||||
Some(
|
||||
sorts_by_field_id
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, v.into()))
|
||||
.collect::<HashMap<String, RepeatedGridSort>>(),
|
||||
)
|
||||
})
|
||||
.unwrap_or(HashMap::default());
|
||||
|
||||
GridSetting {
|
||||
layouts: GridLayout::all(),
|
||||
current_layout_type,
|
||||
filters_by_field_id,
|
||||
groups_by_field_id,
|
||||
sorts_by_field_id,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user