mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: send group notification
This commit is contained in:
parent
0b26ad0541
commit
b7d71428be
@ -18,14 +18,13 @@ class FieldService {
|
|||||||
FieldService({required this.gridId, required this.fieldId});
|
FieldService({required this.gridId, required this.fieldId});
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> moveField(int fromIndex, int toIndex) {
|
Future<Either<Unit, FlowyError>> moveField(int fromIndex, int toIndex) {
|
||||||
final payload = MoveItemPayloadPB.create()
|
final payload = MoveFieldPayloadPB.create()
|
||||||
..gridId = gridId
|
..gridId = gridId
|
||||||
..itemId = fieldId
|
..fieldId = fieldId
|
||||||
..ty = MoveItemTypePB.MoveField
|
|
||||||
..fromIndex = fromIndex
|
..fromIndex = fromIndex
|
||||||
..toIndex = toIndex;
|
..toIndex = toIndex;
|
||||||
|
|
||||||
return GridEventMoveItem(payload).send();
|
return GridEventMoveField(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> updateField({
|
Future<Either<Unit, FlowyError>> updateField({
|
||||||
|
@ -4,6 +4,7 @@ import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
|||||||
import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-grid/block_entities.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-grid/grid_entities.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-grid/grid_entities.pb.dart';
|
||||||
import 'package:flowy_sdk/protobuf/flowy-grid/row_entities.pb.dart';
|
import 'package:flowy_sdk/protobuf/flowy-grid/row_entities.pb.dart';
|
||||||
|
import 'package:flowy_sdk/protobuf/flowy-grid/setting_entities.pb.dart';
|
||||||
|
|
||||||
class RowFFIService {
|
class RowFFIService {
|
||||||
final String gridId;
|
final String gridId;
|
||||||
@ -21,16 +22,25 @@ class RowFFIService {
|
|||||||
return GridEventCreateRow(payload).send();
|
return GridEventCreateRow(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> moveRow(
|
Future<Either<Unit, FlowyError>> moveRow({
|
||||||
String rowId, int fromIndex, int toIndex) {
|
required String rowId,
|
||||||
final payload = MoveItemPayloadPB.create()
|
required int fromIndex,
|
||||||
..gridId = gridId
|
required int toIndex,
|
||||||
..itemId = rowId
|
required GridLayout layout,
|
||||||
..ty = MoveItemTypePB.MoveRow
|
String? upperRowId,
|
||||||
|
}) {
|
||||||
|
var payload = MoveRowPayloadPB.create()
|
||||||
|
..viewId = gridId
|
||||||
|
..rowId = rowId
|
||||||
|
..layout = layout
|
||||||
..fromIndex = fromIndex
|
..fromIndex = fromIndex
|
||||||
..toIndex = toIndex;
|
..toIndex = toIndex;
|
||||||
|
|
||||||
return GridEventMoveItem(payload).send();
|
if (upperRowId != null) {
|
||||||
|
payload.upperRowId = upperRowId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GridEventMoveRow(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<OptionalRowPB, FlowyError>> getRow() {
|
Future<Either<OptionalRowPB, FlowyError>> getRow() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::entities::{BlockPB, FieldIdPB};
|
use crate::entities::{BlockPB, FieldIdPB, GridLayout};
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
|
|
||||||
@ -52,25 +52,51 @@ impl std::convert::From<&str> for GridBlockIdPB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, ProtoBuf_Enum)]
|
|
||||||
pub enum MoveItemTypePB {
|
|
||||||
MoveField = 0,
|
|
||||||
MoveRow = 1,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::default::Default for MoveItemTypePB {
|
|
||||||
fn default() -> Self {
|
|
||||||
MoveItemTypePB::MoveField
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||||
pub struct MoveItemPayloadPB {
|
pub struct MoveFieldPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub grid_id: String,
|
pub grid_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub item_id: String,
|
pub field_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 3)]
|
||||||
|
pub from_index: i32,
|
||||||
|
|
||||||
|
#[pb(index = 4)]
|
||||||
|
pub to_index: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct MoveFieldParams {
|
||||||
|
pub grid_id: String,
|
||||||
|
pub field_id: String,
|
||||||
|
pub from_index: i32,
|
||||||
|
pub to_index: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryInto<MoveFieldParams> for MoveFieldPayloadPB {
|
||||||
|
type Error = ErrorCode;
|
||||||
|
|
||||||
|
fn try_into(self) -> Result<MoveFieldParams, Self::Error> {
|
||||||
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
||||||
|
let item_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::InvalidData)?;
|
||||||
|
Ok(MoveFieldParams {
|
||||||
|
grid_id: grid_id.0,
|
||||||
|
field_id: item_id.0,
|
||||||
|
from_index: self.from_index,
|
||||||
|
to_index: self.to_index,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||||
|
pub struct MoveRowPayloadPB {
|
||||||
|
#[pb(index = 1)]
|
||||||
|
pub view_id: String,
|
||||||
|
|
||||||
|
#[pb(index = 2)]
|
||||||
|
pub row_id: String,
|
||||||
|
|
||||||
#[pb(index = 3)]
|
#[pb(index = 3)]
|
||||||
pub from_index: i32,
|
pub from_index: i32,
|
||||||
@ -79,30 +105,38 @@ pub struct MoveItemPayloadPB {
|
|||||||
pub to_index: i32,
|
pub to_index: i32,
|
||||||
|
|
||||||
#[pb(index = 5)]
|
#[pb(index = 5)]
|
||||||
pub ty: MoveItemTypePB,
|
pub layout: GridLayout,
|
||||||
|
|
||||||
|
#[pb(index = 6, one_of)]
|
||||||
|
pub upper_row_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
pub struct MoveRowParams {
|
||||||
pub struct MoveItemParams {
|
pub view_id: String,
|
||||||
pub grid_id: String,
|
pub row_id: String,
|
||||||
pub item_id: String,
|
|
||||||
pub from_index: i32,
|
pub from_index: i32,
|
||||||
pub to_index: i32,
|
pub to_index: i32,
|
||||||
pub ty: MoveItemTypePB,
|
pub layout: GridLayout,
|
||||||
|
pub upper_row_id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<MoveItemParams> for MoveItemPayloadPB {
|
impl TryInto<MoveRowParams> for MoveRowPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<MoveItemParams, Self::Error> {
|
fn try_into(self) -> Result<MoveRowParams, Self::Error> {
|
||||||
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::GridViewIdIsEmpty)?;
|
||||||
let item_id = NotEmptyStr::parse(self.item_id).map_err(|_| ErrorCode::InvalidData)?;
|
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
|
||||||
Ok(MoveItemParams {
|
let upper_row_id = match self.upper_row_id {
|
||||||
grid_id: grid_id.0,
|
None => None,
|
||||||
item_id: item_id.0,
|
Some(upper_row_id) => Some(NotEmptyStr::parse(upper_row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?.0),
|
||||||
|
};
|
||||||
|
Ok(MoveRowParams {
|
||||||
|
view_id: view_id.0,
|
||||||
|
row_id: row_id.0,
|
||||||
from_index: self.from_index,
|
from_index: self.from_index,
|
||||||
to_index: self.to_index,
|
to_index: self.to_index,
|
||||||
ty: self.ty,
|
layout: self.layout,
|
||||||
|
upper_row_id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{CreateRowParams, RowPB};
|
use crate::entities::{CreateRowParams, GridLayout, RowPB};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
@ -22,45 +22,46 @@ impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
|
|||||||
grid_id: grid_id.0,
|
grid_id: grid_id.0,
|
||||||
start_row_id: None,
|
start_row_id: None,
|
||||||
group_id: Some(group_id.0),
|
group_id: Some(group_id.0),
|
||||||
|
layout: GridLayout::Board,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
pub struct BoardCardChangesetPB {
|
pub struct GroupRowsChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub group_id: String,
|
pub group_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub inserted_cards: Vec<RowPB>,
|
pub inserted_rows: Vec<RowPB>,
|
||||||
|
|
||||||
#[pb(index = 3)]
|
#[pb(index = 3)]
|
||||||
pub deleted_cards: Vec<String>,
|
pub deleted_rows: Vec<String>,
|
||||||
|
|
||||||
#[pb(index = 4)]
|
#[pb(index = 4)]
|
||||||
pub updated_cards: Vec<RowPB>,
|
pub updated_rows: Vec<RowPB>,
|
||||||
}
|
}
|
||||||
impl BoardCardChangesetPB {
|
impl GroupRowsChangesetPB {
|
||||||
pub fn insert(group_id: String, inserted_cards: Vec<RowPB>) -> Self {
|
pub fn insert(group_id: String, inserted_rows: Vec<RowPB>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
group_id,
|
group_id,
|
||||||
inserted_cards,
|
inserted_rows,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete(group_id: String, deleted_cards: Vec<String>) -> Self {
|
pub fn delete(group_id: String, deleted_rows: Vec<String>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
group_id,
|
group_id,
|
||||||
deleted_cards,
|
deleted_rows,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(group_id: String, updated_cards: Vec<RowPB>) -> Self {
|
pub fn update(group_id: String, updated_rows: Vec<RowPB>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
group_id,
|
group_id,
|
||||||
updated_cards,
|
updated_rows,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::entities::GridLayout;
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use flowy_grid_data_model::parser::NotEmptyStr;
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
||||||
@ -46,7 +47,7 @@ pub struct BlockRowIdPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ProtoBuf, Default)]
|
#[derive(ProtoBuf, Default)]
|
||||||
pub struct CreateRowPayloadPB {
|
pub struct CreateTableRowPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub grid_id: String,
|
pub grid_id: String,
|
||||||
|
|
||||||
@ -59,17 +60,20 @@ pub struct CreateRowParams {
|
|||||||
pub grid_id: String,
|
pub grid_id: String,
|
||||||
pub start_row_id: Option<String>,
|
pub start_row_id: Option<String>,
|
||||||
pub group_id: Option<String>,
|
pub group_id: Option<String>,
|
||||||
|
pub layout: GridLayout,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<CreateRowParams> for CreateRowPayloadPB {
|
impl TryInto<CreateRowParams> for CreateTableRowPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
||||||
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
||||||
|
|
||||||
Ok(CreateRowParams {
|
Ok(CreateRowParams {
|
||||||
grid_id: grid_id.0,
|
grid_id: grid_id.0,
|
||||||
start_row_id: self.start_row_id,
|
start_row_id: self.start_row_id,
|
||||||
group_id: None,
|
group_id: None,
|
||||||
|
layout: GridLayout::Table,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ pub struct GridSettingPB {
|
|||||||
pub layouts: Vec<GridLayoutPB>,
|
pub layouts: Vec<GridLayoutPB>,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub current_layout_type: Layout,
|
pub current_layout_type: GridLayout,
|
||||||
|
|
||||||
#[pb(index = 3)]
|
#[pb(index = 3)]
|
||||||
pub filter_configuration_by_field_id: HashMap<String, RepeatedGridConfigurationFilterPB>,
|
pub filter_configuration_by_field_id: HashMap<String, RepeatedGridConfigurationFilterPB>,
|
||||||
@ -34,13 +34,13 @@ pub struct GridSettingPB {
|
|||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct GridLayoutPB {
|
pub struct GridLayoutPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
ty: Layout,
|
ty: GridLayout,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridLayoutPB {
|
impl GridLayoutPB {
|
||||||
pub fn all() -> Vec<GridLayoutPB> {
|
pub fn all() -> Vec<GridLayoutPB> {
|
||||||
let mut layouts = vec![];
|
let mut layouts = vec![];
|
||||||
for layout_ty in Layout::iter() {
|
for layout_ty in GridLayout::iter() {
|
||||||
layouts.push(GridLayoutPB { ty: layout_ty })
|
layouts.push(GridLayoutPB { ty: layout_ty })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,31 +50,31 @@ impl GridLayoutPB {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]
|
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Layout {
|
pub enum GridLayout {
|
||||||
Table = 0,
|
Table = 0,
|
||||||
Board = 1,
|
Board = 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for Layout {
|
impl std::default::Default for GridLayout {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Layout::Table
|
GridLayout::Table
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<LayoutRevision> for Layout {
|
impl std::convert::From<LayoutRevision> for GridLayout {
|
||||||
fn from(rev: LayoutRevision) -> Self {
|
fn from(rev: LayoutRevision) -> Self {
|
||||||
match rev {
|
match rev {
|
||||||
LayoutRevision::Table => Layout::Table,
|
LayoutRevision::Table => GridLayout::Table,
|
||||||
LayoutRevision::Board => Layout::Board,
|
LayoutRevision::Board => GridLayout::Board,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<Layout> for LayoutRevision {
|
impl std::convert::From<GridLayout> for LayoutRevision {
|
||||||
fn from(layout: Layout) -> Self {
|
fn from(layout: GridLayout) -> Self {
|
||||||
match layout {
|
match layout {
|
||||||
Layout::Table => LayoutRevision::Table,
|
GridLayout::Table => LayoutRevision::Table,
|
||||||
Layout::Board => LayoutRevision::Board,
|
GridLayout::Board => LayoutRevision::Board,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ pub struct GridSettingChangesetPayloadPB {
|
|||||||
pub grid_id: String,
|
pub grid_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub layout_type: Layout,
|
pub layout_type: GridLayout,
|
||||||
|
|
||||||
#[pb(index = 3, one_of)]
|
#[pb(index = 3, one_of)]
|
||||||
pub insert_filter: Option<CreateGridFilterPayloadPB>,
|
pub insert_filter: Option<CreateGridFilterPayloadPB>,
|
||||||
|
@ -203,13 +203,13 @@ pub(crate) async fn create_field_type_option_data_handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn move_item_handler(
|
pub(crate) async fn move_field_handler(
|
||||||
data: Data<MoveItemPayloadPB>,
|
data: Data<MoveFieldPayloadPB>,
|
||||||
manager: AppData<Arc<GridManager>>,
|
manager: AppData<Arc<GridManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: MoveItemParams = data.into_inner().try_into()?;
|
let params: MoveFieldParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
let editor = manager.get_grid_editor(¶ms.grid_id)?;
|
||||||
let _ = editor.move_item(params).await?;
|
let _ = editor.move_field(params).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,8 +260,19 @@ pub(crate) async fn duplicate_row_handler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||||
pub(crate) async fn create_row_handler(
|
pub(crate) async fn move_row_handler(
|
||||||
data: Data<CreateRowPayloadPB>,
|
data: Data<MoveRowPayloadPB>,
|
||||||
|
manager: AppData<Arc<GridManager>>,
|
||||||
|
) -> Result<(), FlowyError> {
|
||||||
|
let params: MoveRowParams = data.into_inner().try_into()?;
|
||||||
|
let editor = manager.get_grid_editor(¶ms.view_id)?;
|
||||||
|
let _ = editor.move_row(params).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||||
|
pub(crate) async fn create_table_row_handler(
|
||||||
|
data: Data<CreateTableRowPayloadPB>,
|
||||||
manager: AppData<Arc<GridManager>>,
|
manager: AppData<Arc<GridManager>>,
|
||||||
) -> DataResult<RowPB, FlowyError> {
|
) -> DataResult<RowPB, FlowyError> {
|
||||||
let params: CreateRowParams = data.into_inner().try_into()?;
|
let params: CreateRowParams = data.into_inner().try_into()?;
|
||||||
|
@ -20,14 +20,15 @@ pub fn create(grid_manager: Arc<GridManager>) -> Module {
|
|||||||
.event(GridEvent::DeleteField, delete_field_handler)
|
.event(GridEvent::DeleteField, delete_field_handler)
|
||||||
.event(GridEvent::SwitchToField, switch_to_field_handler)
|
.event(GridEvent::SwitchToField, switch_to_field_handler)
|
||||||
.event(GridEvent::DuplicateField, duplicate_field_handler)
|
.event(GridEvent::DuplicateField, duplicate_field_handler)
|
||||||
.event(GridEvent::MoveItem, move_item_handler)
|
.event(GridEvent::MoveField, move_field_handler)
|
||||||
.event(GridEvent::GetFieldTypeOption, get_field_type_option_data_handler)
|
.event(GridEvent::GetFieldTypeOption, get_field_type_option_data_handler)
|
||||||
.event(GridEvent::CreateFieldTypeOption, create_field_type_option_data_handler)
|
.event(GridEvent::CreateFieldTypeOption, create_field_type_option_data_handler)
|
||||||
// Row
|
// Row
|
||||||
.event(GridEvent::CreateRow, create_row_handler)
|
.event(GridEvent::CreateTableRow, create_table_row_handler)
|
||||||
.event(GridEvent::GetRow, get_row_handler)
|
.event(GridEvent::GetRow, get_row_handler)
|
||||||
.event(GridEvent::DeleteRow, delete_row_handler)
|
.event(GridEvent::DeleteRow, delete_row_handler)
|
||||||
.event(GridEvent::DuplicateRow, duplicate_row_handler)
|
.event(GridEvent::DuplicateRow, duplicate_row_handler)
|
||||||
|
.event(GridEvent::MoveRow, move_row_handler)
|
||||||
// Cell
|
// Cell
|
||||||
.event(GridEvent::GetCell, get_cell_handler)
|
.event(GridEvent::GetCell, get_cell_handler)
|
||||||
.event(GridEvent::UpdateCell, update_cell_handler)
|
.event(GridEvent::UpdateCell, update_cell_handler)
|
||||||
@ -130,8 +131,8 @@ pub enum GridEvent {
|
|||||||
|
|
||||||
/// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
|
/// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
|
||||||
/// [MoveItemTypePB].
|
/// [MoveItemTypePB].
|
||||||
#[event(input = "MoveItemPayloadPB")]
|
#[event(input = "MoveFieldPayloadPB")]
|
||||||
MoveItem = 22,
|
MoveField = 22,
|
||||||
|
|
||||||
/// [FieldTypeOptionIdPB] event is used to get the FieldTypeOption data for a specific field type.
|
/// [FieldTypeOptionIdPB] event is used to get the FieldTypeOption data for a specific field type.
|
||||||
///
|
///
|
||||||
@ -166,8 +167,8 @@ pub enum GridEvent {
|
|||||||
#[event(input = "SelectOptionChangesetPayloadPB")]
|
#[event(input = "SelectOptionChangesetPayloadPB")]
|
||||||
UpdateSelectOption = 32,
|
UpdateSelectOption = 32,
|
||||||
|
|
||||||
#[event(input = "CreateRowPayloadPB", output = "RowPB")]
|
#[event(input = "CreateTableRowPayloadPB", output = "RowPB")]
|
||||||
CreateRow = 50,
|
CreateTableRow = 50,
|
||||||
|
|
||||||
/// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
|
/// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
|
||||||
/// to return a nullable row data.
|
/// to return a nullable row data.
|
||||||
@ -180,6 +181,9 @@ pub enum GridEvent {
|
|||||||
#[event(input = "RowIdPB")]
|
#[event(input = "RowIdPB")]
|
||||||
DuplicateRow = 53,
|
DuplicateRow = 53,
|
||||||
|
|
||||||
|
#[event(input = "MoveRowPayloadPB")]
|
||||||
|
MoveRow = 54,
|
||||||
|
|
||||||
#[event(input = "GridCellIdPB", output = "GridCellPB")]
|
#[event(input = "GridCellIdPB", output = "GridCellPB")]
|
||||||
GetCell = 70,
|
GetCell = 70,
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ impl GridBlockRevisionEditor {
|
|||||||
if let Some(start_row_id) = prev_row_id.as_ref() {
|
if let Some(start_row_id) = prev_row_id.as_ref() {
|
||||||
match block_pad.index_of_row(start_row_id) {
|
match block_pad.index_of_row(start_row_id) {
|
||||||
None => {}
|
None => {}
|
||||||
Some(index) => row_index = Some(index + 1),
|
Some(index) => row_index = Some(index as i32 + 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +100,10 @@ impl GridBlockRevisionEditor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn index_of_row(&self, row_id: &str) -> Option<usize> {
|
||||||
|
self.pad.read().await.index_of_row(row_id)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_row_rev(&self, row_id: &str) -> FlowyResult<Option<Arc<RowRevision>>> {
|
pub async fn get_row_rev(&self, row_id: &str) -> FlowyResult<Option<Arc<RowRevision>>> {
|
||||||
let row_ids = vec![Cow::Borrowed(row_id)];
|
let row_ids = vec![Cow::Borrowed(row_id)];
|
||||||
let row_rev = self.get_row_revs(Some(row_ids)).await?.pop();
|
let row_rev = self.get_row_revs(Some(row_ids)).await?.pop();
|
||||||
|
@ -52,7 +52,7 @@ impl GridBlockManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_editor_from_row_id(&self, row_id: &str) -> FlowyResult<Arc<GridBlockRevisionEditor>> {
|
pub(crate) async fn get_editor_from_row_id(&self, row_id: &str) -> FlowyResult<Arc<GridBlockRevisionEditor>> {
|
||||||
let block_id = self.persistence.get_block_id(row_id)?;
|
let block_id = self.persistence.get_block_id(row_id)?;
|
||||||
Ok(self.get_block_editor(&block_id).await?)
|
Ok(self.get_block_editor(&block_id).await?)
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ impl GridBlockManager {
|
|||||||
|
|
||||||
Ok(changesets)
|
Ok(changesets)
|
||||||
}
|
}
|
||||||
|
// This function will be moved to GridViewRevisionEditor
|
||||||
pub(crate) async fn move_row(&self, row_rev: Arc<RowRevision>, from: usize, to: usize) -> FlowyResult<()> {
|
pub(crate) async fn move_row(&self, row_rev: Arc<RowRevision>, from: usize, to: usize) -> FlowyResult<()> {
|
||||||
let editor = self.get_editor_from_row_id(&row_rev.id).await?;
|
let editor = self.get_editor_from_row_id(&row_rev.id).await?;
|
||||||
let _ = editor.move_row(&row_rev.id, from, to).await?;
|
let _ = editor.move_row(&row_rev.id, from, to).await?;
|
||||||
@ -180,6 +180,14 @@ impl GridBlockManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function will be moved to GridViewRevisionEditor.
|
||||||
|
pub async fn index_of_row(&self, row_id: &str) -> Option<usize> {
|
||||||
|
match self.get_editor_from_row_id(row_id).await {
|
||||||
|
Ok(editor) => editor.index_of_row(row_id).await,
|
||||||
|
Err(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_cell<F>(&self, changeset: CellChangesetPB, row_builder: F) -> FlowyResult<()>
|
pub async fn update_cell<F>(&self, changeset: CellChangesetPB, row_builder: F) -> FlowyResult<()>
|
||||||
where
|
where
|
||||||
F: FnOnce(Arc<RowRevision>) -> RowPB,
|
F: FnOnce(Arc<RowRevision>) -> RowPB,
|
||||||
|
@ -342,7 +342,7 @@ impl GridRevisionEditor {
|
|||||||
|
|
||||||
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
|
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
|
||||||
let _ = self.block_manager.delete_row(row_id).await?;
|
let _ = self.block_manager.delete_row(row_id).await?;
|
||||||
self.view_manager.delete_row(row_id).await;
|
self.view_manager.did_delete_row(row_id).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,21 +484,22 @@ impl GridRevisionEditor {
|
|||||||
Ok(snapshots)
|
Ok(snapshots)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn move_item(&self, params: MoveItemParams) -> FlowyResult<()> {
|
pub async fn move_row(&self, params: MoveRowParams) -> FlowyResult<()> {
|
||||||
match params.ty {
|
self.view_manager.move_row(params).await
|
||||||
MoveItemTypePB::MoveField => {
|
|
||||||
self.move_field(¶ms.item_id, params.from_index, params.to_index)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
MoveItemTypePB::MoveRow => self.move_row(¶ms.item_id, params.from_index, params.to_index).await,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn move_field(&self, field_id: &str, from: i32, to: i32) -> FlowyResult<()> {
|
pub async fn move_field(&self, params: MoveFieldParams) -> FlowyResult<()> {
|
||||||
|
let MoveFieldParams {
|
||||||
|
grid_id: _,
|
||||||
|
field_id,
|
||||||
|
from_index,
|
||||||
|
to_index,
|
||||||
|
} = params;
|
||||||
|
|
||||||
let _ = self
|
let _ = self
|
||||||
.modify(|grid_pad| Ok(grid_pad.move_field(field_id, from as usize, to as usize)?))
|
.modify(|grid_pad| Ok(grid_pad.move_field(&field_id, from_index as usize, to_index as usize)?))
|
||||||
.await?;
|
.await?;
|
||||||
if let Some((index, field_rev)) = self.grid_pad.read().await.get_field_rev(field_id) {
|
if let Some((index, field_rev)) = self.grid_pad.read().await.get_field_rev(&field_id) {
|
||||||
let delete_field_order = FieldIdPB::from(field_id);
|
let delete_field_order = FieldIdPB::from(field_id);
|
||||||
let insert_field = IndexFieldPB::from_field_rev(field_rev, index);
|
let insert_field = IndexFieldPB::from_field_rev(field_rev, index);
|
||||||
let notified_changeset = FieldChangesetPB {
|
let notified_changeset = FieldChangesetPB {
|
||||||
@ -513,10 +514,6 @@ impl GridRevisionEditor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn move_row(&self, row_id: &str, from: i32, to: i32) -> FlowyResult<()> {
|
|
||||||
self.view_manager.move_row(row_id, from, to).await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delta_bytes(&self) -> Bytes {
|
pub async fn delta_bytes(&self) -> Bytes {
|
||||||
self.grid_pad.read().await.delta_bytes()
|
self.grid_pad.read().await.delta_bytes()
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
use flowy_error::{FlowyError, FlowyResult};
|
use flowy_error::{FlowyError, FlowyResult};
|
||||||
|
|
||||||
use crate::entities::{CreateRowParams, GridFilterConfiguration, GridSettingPB, GroupPB, RowPB};
|
use crate::entities::{
|
||||||
|
CreateRowParams, GridFilterConfiguration, GridLayout, GridSettingPB, GroupPB, GroupRowsChangesetPB, RowPB,
|
||||||
|
};
|
||||||
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
||||||
use crate::services::group::{default_group_configuration, GroupConfigurationDelegate, GroupService};
|
use crate::services::group::{default_group_configuration, Group, GroupConfigurationDelegate, GroupService};
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, GroupConfigurationRevision, RowRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, GroupConfigurationRevision, RowRevision};
|
||||||
use flowy_revision::{RevisionCloudService, RevisionManager, RevisionObjectBuilder};
|
use flowy_revision::{RevisionCloudService, RevisionManager, RevisionObjectBuilder};
|
||||||
use flowy_sync::client_grid::{GridViewRevisionChangeset, GridViewRevisionPad};
|
use flowy_sync::client_grid::{GridViewRevisionChangeset, GridViewRevisionPad};
|
||||||
use flowy_sync::entities::revision::Revision;
|
use flowy_sync::entities::revision::Revision;
|
||||||
|
|
||||||
|
use crate::dart_notification::{send_dart_notification, GridNotification};
|
||||||
use crate::services::setting::make_grid_setting;
|
use crate::services::setting::make_grid_setting;
|
||||||
use flowy_sync::entities::grid::GridSettingChangesetParams;
|
use flowy_sync::entities::grid::GridSettingChangesetParams;
|
||||||
use lib_infra::future::{wrap_future, AFFuture, FutureResult};
|
use lib_infra::future::{wrap_future, AFFuture, FutureResult};
|
||||||
@ -19,7 +22,7 @@ pub trait GridViewRevisionDelegate: Send + Sync + 'static {
|
|||||||
fn get_field_rev(&self, field_id: &str) -> AFFuture<Option<Arc<FieldRevision>>>;
|
fn get_field_rev(&self, field_id: &str) -> AFFuture<Option<Arc<FieldRevision>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GridViewRevisionDataSource: Send + Sync + 'static {
|
pub trait GridViewRevisionRowDataSource: Send + Sync + 'static {
|
||||||
fn row_revs(&self) -> AFFuture<Vec<Arc<RowRevision>>>;
|
fn row_revs(&self) -> AFFuture<Vec<Arc<RowRevision>>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,8 +33,9 @@ pub struct GridViewRevisionEditor {
|
|||||||
pad: Arc<RwLock<GridViewRevisionPad>>,
|
pad: Arc<RwLock<GridViewRevisionPad>>,
|
||||||
rev_manager: Arc<RevisionManager>,
|
rev_manager: Arc<RevisionManager>,
|
||||||
delegate: Arc<dyn GridViewRevisionDelegate>,
|
delegate: Arc<dyn GridViewRevisionDelegate>,
|
||||||
data_source: Arc<dyn GridViewRevisionDataSource>,
|
data_source: Arc<dyn GridViewRevisionRowDataSource>,
|
||||||
group_service: Arc<RwLock<GroupService>>,
|
group_service: Arc<RwLock<GroupService>>,
|
||||||
|
groups: Arc<RwLock<Vec<Group>>>,
|
||||||
scheduler: Arc<dyn GridServiceTaskScheduler>,
|
scheduler: Arc<dyn GridServiceTaskScheduler>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +51,7 @@ impl GridViewRevisionEditor {
|
|||||||
) -> FlowyResult<Self>
|
) -> FlowyResult<Self>
|
||||||
where
|
where
|
||||||
Delegate: GridViewRevisionDelegate,
|
Delegate: GridViewRevisionDelegate,
|
||||||
DataSource: GridViewRevisionDataSource,
|
DataSource: GridViewRevisionRowDataSource,
|
||||||
{
|
{
|
||||||
let cloud = Arc::new(GridViewRevisionCloudService {
|
let cloud = Arc::new(GridViewRevisionCloudService {
|
||||||
token: token.to_owned(),
|
token: token.to_owned(),
|
||||||
@ -57,52 +61,85 @@ impl GridViewRevisionEditor {
|
|||||||
let rev_manager = Arc::new(rev_manager);
|
let rev_manager = Arc::new(rev_manager);
|
||||||
let group_service = GroupService::new(Box::new(pad.clone())).await;
|
let group_service = GroupService::new(Box::new(pad.clone())).await;
|
||||||
let user_id = user_id.to_owned();
|
let user_id = user_id.to_owned();
|
||||||
|
let groups = Arc::new(RwLock::new(vec![]));
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
pad,
|
pad,
|
||||||
user_id,
|
user_id,
|
||||||
view_id,
|
view_id,
|
||||||
rev_manager,
|
rev_manager,
|
||||||
scheduler,
|
scheduler,
|
||||||
|
groups,
|
||||||
delegate: Arc::new(delegate),
|
delegate: Arc::new(delegate),
|
||||||
data_source: Arc::new(data_source),
|
data_source: Arc::new(data_source),
|
||||||
group_service: Arc::new(RwLock::new(group_service)),
|
group_service: Arc::new(RwLock::new(group_service)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn create_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
|
pub(crate) async fn update_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
|
||||||
match params.group_id.as_ref() {
|
match params.layout {
|
||||||
None => {}
|
GridLayout::Table => {
|
||||||
Some(group_id) => {
|
// Table can be grouped too
|
||||||
self.group_service
|
|
||||||
.read()
|
|
||||||
.await
|
|
||||||
.update_row(row_rev, group_id, |field_id| self.delegate.get_field_rev(&field_id))
|
|
||||||
.await;
|
|
||||||
}
|
}
|
||||||
|
GridLayout::Board => match params.group_id.as_ref() {
|
||||||
|
None => {}
|
||||||
|
Some(group_id) => {
|
||||||
|
self.group_service
|
||||||
|
.read()
|
||||||
|
.await
|
||||||
|
.update_row(row_rev, group_id, |field_id| self.delegate.get_field_rev(&field_id))
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn did_create_row(&self, row_pb: &RowPB, params: &CreateRowParams) {
|
pub(crate) async fn did_create_row(&self, row_pb: &RowPB, params: &CreateRowParams) {
|
||||||
|
// Send the group notification if the current view has groups
|
||||||
match params.group_id.as_ref() {
|
match params.group_id.as_ref() {
|
||||||
None => {}
|
None => {}
|
||||||
Some(group_id) => {
|
Some(group_id) => {
|
||||||
self.group_service.read().await.did_create_row(group_id, row_pb).await;
|
let changeset = GroupRowsChangesetPB::insert(group_id.clone(), vec![row_pb.clone()]);
|
||||||
|
self.notify_did_update_group(changeset).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn delete_row(&self, row_id: &str) {
|
pub(crate) async fn did_delete_row(&self, row_id: &str) {
|
||||||
self.group_service.read().await.did_delete_card(row_id.to_owned()).await;
|
// Send the group notification if the current view has groups;
|
||||||
|
match self.group_id_of_row(row_id).await {
|
||||||
|
None => {}
|
||||||
|
Some(group_id) => {
|
||||||
|
let changeset = GroupRowsChangesetPB::delete(group_id, vec![row_id.to_owned()]);
|
||||||
|
self.notify_did_update_group(changeset).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn group_id_of_row(&self, row_id: &str) -> Option<String> {
|
||||||
|
let read_guard = self.groups.read().await;
|
||||||
|
for group in read_guard.iter() {
|
||||||
|
if group.rows.iter().find(|row| row.id == row_id).is_some() {
|
||||||
|
return Some(group.id.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn load_groups(&self) -> FlowyResult<Vec<GroupPB>> {
|
pub(crate) async fn load_groups(&self) -> FlowyResult<Vec<GroupPB>> {
|
||||||
let field_revs = self.delegate.get_field_revs().await;
|
let field_revs = self.delegate.get_field_revs().await;
|
||||||
let row_revs = self.data_source.row_revs().await;
|
let row_revs = self.data_source.row_revs().await;
|
||||||
|
|
||||||
|
//
|
||||||
let mut write_guard = self.group_service.write().await;
|
let mut write_guard = self.group_service.write().await;
|
||||||
match write_guard.load_groups(&field_revs, row_revs).await {
|
match write_guard.load_groups(&field_revs, row_revs).await {
|
||||||
None => Ok(vec![]),
|
None => Ok(vec![]),
|
||||||
Some(groups) => Ok(groups),
|
Some(groups) => {
|
||||||
|
*self.groups.write().await = groups.clone();
|
||||||
|
Ok(groups.into_iter().map(GroupPB::from).collect())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,6 +166,12 @@ impl GridViewRevisionEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn notify_did_update_group(&self, changeset: GroupRowsChangesetPB) {
|
||||||
|
send_dart_notification(&changeset.group_id, GridNotification::DidUpdateBoard)
|
||||||
|
.payload(changeset)
|
||||||
|
.send();
|
||||||
|
}
|
||||||
|
|
||||||
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
||||||
where
|
where
|
||||||
F: for<'a> FnOnce(&'a mut GridViewRevisionPad) -> FlowyResult<Option<GridViewRevisionChangeset>>,
|
F: for<'a> FnOnce(&'a mut GridViewRevisionPad) -> FlowyResult<Option<GridViewRevisionChangeset>>,
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
use crate::entities::{CreateRowParams, GridFilterConfiguration, GridSettingPB, RepeatedGridGroupPB, RowPB};
|
use crate::entities::{
|
||||||
|
CreateRowParams, GridFilterConfiguration, GridLayout, GridSettingPB, MoveRowParams, RepeatedGridGroupPB, RowPB,
|
||||||
|
};
|
||||||
use crate::manager::GridUser;
|
use crate::manager::GridUser;
|
||||||
use crate::services::block_manager::GridBlockManager;
|
use crate::services::block_manager::GridBlockManager;
|
||||||
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
||||||
use crate::services::grid_view_editor::{GridViewRevisionDataSource, GridViewRevisionDelegate, GridViewRevisionEditor};
|
use crate::services::grid_view_editor::{
|
||||||
|
GridViewRevisionDelegate, GridViewRevisionEditor, GridViewRevisionRowDataSource,
|
||||||
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
@ -45,7 +49,7 @@ impl GridViewManager {
|
|||||||
|
|
||||||
pub(crate) async fn update_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
|
pub(crate) async fn update_row(&self, row_rev: &mut RowRevision, params: &CreateRowParams) {
|
||||||
for view_editor in self.view_editors.iter() {
|
for view_editor in self.view_editors.iter() {
|
||||||
view_editor.create_row(row_rev, params).await;
|
view_editor.update_row(row_rev, params).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,9 +59,9 @@ impl GridViewManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn delete_row(&self, row_id: &str) {
|
pub(crate) async fn did_delete_row(&self, row_id: &str) {
|
||||||
for view_editor in self.view_editors.iter() {
|
for view_editor in self.view_editors.iter() {
|
||||||
view_editor.delete_row(row_id).await;
|
view_editor.did_delete_row(row_id).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,15 +87,35 @@ impl GridViewManager {
|
|||||||
Ok(RepeatedGridGroupPB { items: groups })
|
Ok(RepeatedGridGroupPB { items: groups })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn move_row(&self, row_id: &str, from: i32, to: i32) -> FlowyResult<()> {
|
pub(crate) async fn move_row(&self, params: MoveRowParams) -> FlowyResult<()> {
|
||||||
match self.block_manager.get_row_rev(row_id).await? {
|
let MoveRowParams {
|
||||||
|
view_id: _,
|
||||||
|
row_id,
|
||||||
|
from_index,
|
||||||
|
to_index,
|
||||||
|
layout,
|
||||||
|
upper_row_id,
|
||||||
|
} = params;
|
||||||
|
|
||||||
|
let from_index = from_index as usize;
|
||||||
|
|
||||||
|
match self.block_manager.get_row_rev(&row_id).await? {
|
||||||
None => tracing::warn!("Move row failed, can not find the row:{}", row_id),
|
None => tracing::warn!("Move row failed, can not find the row:{}", row_id),
|
||||||
Some(row_rev) => {
|
Some(row_rev) => match layout {
|
||||||
let _ = self
|
GridLayout::Table => {
|
||||||
.block_manager
|
tracing::trace!("Move row from {} to {}", from_index, to_index);
|
||||||
.move_row(row_rev.clone(), from as usize, to as usize)
|
let to_index = to_index as usize;
|
||||||
.await?;
|
let _ = self.block_manager.move_row(row_rev, from_index, to_index).await?;
|
||||||
}
|
}
|
||||||
|
GridLayout::Board => {
|
||||||
|
if let Some(upper_row_id) = upper_row_id {
|
||||||
|
if let Some(to_index) = self.block_manager.index_of_row(&upper_row_id).await {
|
||||||
|
tracing::trace!("Move row from {} to {}", from_index, to_index);
|
||||||
|
let _ = self.block_manager.move_row(row_rev, from_index, to_index).await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -132,7 +156,7 @@ async fn make_view_editor<Delegate, DataSource>(
|
|||||||
) -> FlowyResult<GridViewRevisionEditor>
|
) -> FlowyResult<GridViewRevisionEditor>
|
||||||
where
|
where
|
||||||
Delegate: GridViewRevisionDelegate,
|
Delegate: GridViewRevisionDelegate,
|
||||||
DataSource: GridViewRevisionDataSource,
|
DataSource: GridViewRevisionRowDataSource,
|
||||||
{
|
{
|
||||||
tracing::trace!("Open view:{} editor", view_id);
|
tracing::trace!("Open view:{} editor", view_id);
|
||||||
|
|
||||||
@ -170,7 +194,7 @@ impl RevisionCompactor for GridViewRevisionCompactor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridViewRevisionDataSource for Arc<GridBlockManager> {
|
impl GridViewRevisionRowDataSource for Arc<GridBlockManager> {
|
||||||
fn row_revs(&self) -> AFFuture<Vec<Arc<RowRevision>>> {
|
fn row_revs(&self) -> AFFuture<Vec<Arc<RowRevision>>> {
|
||||||
let block_manager = self.clone();
|
let block_manager = self.clone();
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ impl GroupActionHandler for CheckboxGroupController {
|
|||||||
&self.field_id
|
&self.field_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_groups(&self) -> Vec<Group> {
|
fn build_groups(&self) -> Vec<Group> {
|
||||||
self.make_groups()
|
self.make_groups()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ pub trait Groupable {
|
|||||||
|
|
||||||
pub trait GroupActionHandler: Send + Sync {
|
pub trait GroupActionHandler: Send + Sync {
|
||||||
fn field_id(&self) -> &str;
|
fn field_id(&self) -> &str;
|
||||||
fn get_groups(&self) -> Vec<Group>;
|
fn build_groups(&self) -> Vec<Group>;
|
||||||
fn group_rows(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<()>;
|
fn group_rows(&mut self, row_revs: &[Arc<RowRevision>], field_rev: &FieldRevision) -> FlowyResult<()>;
|
||||||
fn update_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
|
fn update_card(&self, row_rev: &mut RowRevision, field_rev: &FieldRevision, group_id: &str);
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ impl GroupActionHandler for SingleSelectGroupController {
|
|||||||
&self.field_id
|
&self.field_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_groups(&self) -> Vec<Group> {
|
fn build_groups(&self) -> Vec<Group> {
|
||||||
self.make_groups()
|
self.make_groups()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ impl GroupActionHandler for MultiSelectGroupController {
|
|||||||
&self.field_id
|
&self.field_id
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_groups(&self) -> Vec<Group> {
|
fn build_groups(&self) -> Vec<Group> {
|
||||||
self.make_groups()
|
self.make_groups()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::dart_notification::{send_dart_notification, GridNotification};
|
use crate::dart_notification::{send_dart_notification, GridNotification};
|
||||||
use crate::entities::{
|
use crate::entities::{
|
||||||
BoardCardChangesetPB, CheckboxGroupConfigurationPB, DateGroupConfigurationPB, FieldType, GroupPB,
|
CheckboxGroupConfigurationPB, DateGroupConfigurationPB, FieldType, GroupPB, GroupRowsChangesetPB,
|
||||||
NumberGroupConfigurationPB, RowPB, SelectOptionGroupConfigurationPB, TextGroupConfigurationPB,
|
NumberGroupConfigurationPB, RowPB, SelectOptionGroupConfigurationPB, TextGroupConfigurationPB,
|
||||||
UrlGroupConfigurationPB,
|
UrlGroupConfigurationPB,
|
||||||
};
|
};
|
||||||
use crate::services::group::{
|
use crate::services::group::{
|
||||||
CheckboxGroupController, GroupActionHandler, MultiSelectGroupController, SingleSelectGroupController,
|
CheckboxGroupController, Group, GroupActionHandler, MultiSelectGroupController, SingleSelectGroupController,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
@ -36,7 +36,7 @@ impl GroupService {
|
|||||||
&mut self,
|
&mut self,
|
||||||
field_revs: &[Arc<FieldRevision>],
|
field_revs: &[Arc<FieldRevision>],
|
||||||
row_revs: Vec<Arc<RowRevision>>,
|
row_revs: Vec<Arc<RowRevision>>,
|
||||||
) -> Option<Vec<GroupPB>> {
|
) -> Option<Vec<Group>> {
|
||||||
let field_rev = find_group_field(field_revs).unwrap();
|
let field_rev = find_group_field(field_revs).unwrap();
|
||||||
let field_type: FieldType = field_rev.field_type_rev.into();
|
let field_type: FieldType = field_rev.field_type_rev.into();
|
||||||
let configuration = self.delegate.get_group_configuration(field_rev.clone()).await;
|
let configuration = self.delegate.get_group_configuration(field_rev.clone()).await;
|
||||||
@ -79,26 +79,6 @@ impl GroupService {
|
|||||||
// let row_pb = make_row_from_row_rev(row_rev);
|
// let row_pb = make_row_from_row_rev(row_rev);
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
#[allow(dead_code)]
|
|
||||||
pub async fn did_delete_card(&self, _row_id: String) {
|
|
||||||
// let changeset = BoardCardChangesetPB::delete(group_id.to_owned(), vec![row_id]);
|
|
||||||
// self.notify_did_update_board(changeset).await;
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn did_create_row(&self, group_id: &str, row_pb: &RowPB) {
|
|
||||||
let changeset = BoardCardChangesetPB::insert(group_id.to_owned(), vec![row_pb.clone()]);
|
|
||||||
self.notify_did_update_board(changeset).await;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn notify_did_update_board(&self, changeset: BoardCardChangesetPB) {
|
|
||||||
if self.action_handler.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
send_dart_notification(&changeset.group_id, GridNotification::DidUpdateBoard)
|
|
||||||
.payload(changeset)
|
|
||||||
.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
async fn build_groups(
|
async fn build_groups(
|
||||||
@ -107,7 +87,7 @@ impl GroupService {
|
|||||||
field_rev: &Arc<FieldRevision>,
|
field_rev: &Arc<FieldRevision>,
|
||||||
row_revs: Vec<Arc<RowRevision>>,
|
row_revs: Vec<Arc<RowRevision>>,
|
||||||
configuration: GroupConfigurationRevision,
|
configuration: GroupConfigurationRevision,
|
||||||
) -> FlowyResult<Vec<GroupPB>> {
|
) -> FlowyResult<Vec<Group>> {
|
||||||
match field_type {
|
match field_type {
|
||||||
FieldType::RichText => {
|
FieldType::RichText => {
|
||||||
// let generator = GroupGenerator::<TextGroupConfigurationPB>::from_configuration(configuration);
|
// let generator = GroupGenerator::<TextGroupConfigurationPB>::from_configuration(configuration);
|
||||||
@ -139,11 +119,11 @@ impl GroupService {
|
|||||||
if let Some(group_action_handler) = self.action_handler.as_ref() {
|
if let Some(group_action_handler) = self.action_handler.as_ref() {
|
||||||
let mut write_guard = group_action_handler.write().await;
|
let mut write_guard = group_action_handler.write().await;
|
||||||
let _ = write_guard.group_rows(&row_revs, field_rev)?;
|
let _ = write_guard.group_rows(&row_revs, field_rev)?;
|
||||||
groups = write_guard.get_groups();
|
groups = write_guard.build_groups();
|
||||||
drop(write_guard);
|
drop(write_guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(groups.into_iter().map(GroupPB::from).collect())
|
Ok(groups)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::entities::{
|
use crate::entities::{
|
||||||
GridLayoutPB, GridSettingPB, Layout, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB,
|
GridLayout, GridLayoutPB, GridSettingPB, RepeatedGridConfigurationFilterPB, RepeatedGridGroupConfigurationPB,
|
||||||
RepeatedGridSortPB,
|
RepeatedGridSortPB,
|
||||||
};
|
};
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, SettingRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, SettingRevision};
|
||||||
@ -12,7 +12,7 @@ pub struct GridSettingChangesetBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GridSettingChangesetBuilder {
|
impl GridSettingChangesetBuilder {
|
||||||
pub fn new(grid_id: &str, layout_type: &Layout) -> Self {
|
pub fn new(grid_id: &str, layout_type: &GridLayout) -> Self {
|
||||||
let params = GridSettingChangesetParams {
|
let params = GridSettingChangesetParams {
|
||||||
grid_id: grid_id.to_string(),
|
grid_id: grid_id.to_string(),
|
||||||
layout_type: layout_type.clone().into(),
|
layout_type: layout_type.clone().into(),
|
||||||
@ -42,7 +42,7 @@ impl GridSettingChangesetBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_grid_setting(grid_setting_rev: &SettingRevision, field_revs: &[Arc<FieldRevision>]) -> GridSettingPB {
|
pub fn make_grid_setting(grid_setting_rev: &SettingRevision, field_revs: &[Arc<FieldRevision>]) -> GridSettingPB {
|
||||||
let current_layout_type: Layout = grid_setting_rev.layout.clone().into();
|
let current_layout_type: GridLayout = grid_setting_rev.layout.clone().into();
|
||||||
let filters_by_field_id = grid_setting_rev
|
let filters_by_field_id = grid_setting_rev
|
||||||
.get_all_filters(field_revs)
|
.get_all_filters(field_revs)
|
||||||
.map(|filters_by_field_id| {
|
.map(|filters_by_field_id| {
|
||||||
|
@ -2,7 +2,7 @@ use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow};
|
|||||||
use crate::grid::block_test::util::GridRowTestBuilder;
|
use crate::grid::block_test::util::GridRowTestBuilder;
|
||||||
use crate::grid::grid_editor::GridEditorTest;
|
use crate::grid::grid_editor::GridEditorTest;
|
||||||
|
|
||||||
use flowy_grid::entities::{CreateRowParams, FieldType, GridCellIdParams, RowPB};
|
use flowy_grid::entities::{CreateRowParams, FieldType, GridCellIdParams, GridLayout, RowPB};
|
||||||
use flowy_grid::services::field::*;
|
use flowy_grid::services::field::*;
|
||||||
use flowy_grid_data_model::revision::{
|
use flowy_grid_data_model::revision::{
|
||||||
GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision,
|
GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowMetaChangeset, RowRevision,
|
||||||
@ -81,6 +81,7 @@ impl GridRowTest {
|
|||||||
grid_id: self.editor.grid_id.clone(),
|
grid_id: self.editor.grid_id.clone(),
|
||||||
start_row_id: None,
|
start_row_id: None,
|
||||||
group_id: None,
|
group_id: None,
|
||||||
|
layout: GridLayout::Table,
|
||||||
};
|
};
|
||||||
let row_order = self.editor.create_row(params).await.unwrap();
|
let row_order = self.editor.create_row(params).await.unwrap();
|
||||||
self.row_order_by_row_id
|
self.row_order_by_row_id
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
#![allow(unused_imports)]
|
#![allow(unused_imports)]
|
||||||
|
|
||||||
use flowy_grid::entities::{CreateGridFilterPayloadPB, Layout, GridSettingPB};
|
use flowy_grid::entities::{CreateGridFilterPayloadPB, GridLayout, GridSettingPB};
|
||||||
use flowy_grid::services::setting::GridSettingChangesetBuilder;
|
use flowy_grid::services::setting::GridSettingChangesetBuilder;
|
||||||
use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision};
|
use flowy_grid_data_model::revision::{FieldRevision, FieldTypeRevision};
|
||||||
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
use flowy_sync::entities::grid::{CreateGridFilterParams, DeleteFilterParams, GridSettingChangesetParams};
|
||||||
@ -55,7 +55,7 @@ impl GridFilterTest {
|
|||||||
}
|
}
|
||||||
FilterScript::InsertGridTableFilter { payload } => {
|
FilterScript::InsertGridTableFilter { payload } => {
|
||||||
let params: CreateGridFilterParams = payload.try_into().unwrap();
|
let params: CreateGridFilterParams = payload.try_into().unwrap();
|
||||||
let layout_type = Layout::Table;
|
let layout_type = GridLayout::Table;
|
||||||
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
||||||
.insert_filter(params)
|
.insert_filter(params)
|
||||||
.build();
|
.build();
|
||||||
@ -66,7 +66,7 @@ impl GridFilterTest {
|
|||||||
assert_eq!(count as usize, filters.len());
|
assert_eq!(count as usize, filters.len());
|
||||||
}
|
}
|
||||||
FilterScript::DeleteGridTableFilter { filter_id, field_rev} => {
|
FilterScript::DeleteGridTableFilter { filter_id, field_rev} => {
|
||||||
let layout_type = Layout::Table;
|
let layout_type = GridLayout::Table;
|
||||||
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
let params = GridSettingChangesetBuilder::new(&self.grid_id, &layout_type)
|
||||||
.delete_filter(DeleteFilterParams { field_id: field_rev.id, filter_id, field_type_rev: field_rev.field_type_rev })
|
.delete_filter(DeleteFilterParams { field_id: field_rev.id, filter_id, field_type_rev: field_rev.field_type_rev })
|
||||||
.build();
|
.build();
|
||||||
|
@ -91,6 +91,9 @@ pub enum ErrorCode {
|
|||||||
|
|
||||||
#[display(fmt = "Grid id is empty")]
|
#[display(fmt = "Grid id is empty")]
|
||||||
GridIdIsEmpty = 410,
|
GridIdIsEmpty = 410,
|
||||||
|
#[display(fmt = "Grid view id is empty")]
|
||||||
|
GridViewIdIsEmpty = 411,
|
||||||
|
|
||||||
#[display(fmt = "Grid block id is empty")]
|
#[display(fmt = "Grid block id is empty")]
|
||||||
BlockIdIsEmpty = 420,
|
BlockIdIsEmpty = 420,
|
||||||
#[display(fmt = "Row id is empty")]
|
#[display(fmt = "Row id is empty")]
|
||||||
|
@ -139,12 +139,8 @@ impl GridBlockRevisionPad {
|
|||||||
self.block.rows.len() as i32
|
self.block.rows.len() as i32
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index_of_row(&self, row_id: &str) -> Option<i32> {
|
pub fn index_of_row(&self, row_id: &str) -> Option<usize> {
|
||||||
self.block
|
self.block.rows.iter().position(|row| row.id == row_id)
|
||||||
.rows
|
|
||||||
.iter()
|
|
||||||
.position(|row| row.id == row_id)
|
|
||||||
.map(|index| index as i32)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_row(&mut self, changeset: RowMetaChangeset) -> CollaborateResult<Option<GridBlockRevisionChangeset>> {
|
pub fn update_row(&mut self, changeset: RowMetaChangeset) -> CollaborateResult<Option<GridBlockRevisionChangeset>> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user