2022-03-02 22:43:04 +08:00
use crate ::event_handler ::* ;
2022-03-04 22:09:16 +08:00
use crate ::manager ::GridManager ;
2022-03-02 22:43:04 +08:00
use flowy_derive ::{ Flowy_Event , ProtoBuf_Enum } ;
use lib_dispatch ::prelude ::* ;
use std ::sync ::Arc ;
use strum_macros ::Display ;
pub fn create ( grid_manager : Arc < GridManager > ) -> Module {
let mut module = Module ::new ( ) . name ( env! ( " CARGO_PKG_NAME " ) ) . data ( grid_manager ) ;
module = module
2022-06-24 18:13:40 +08:00
. event ( GridEvent ::GetGrid , get_grid_handler )
2022-03-17 17:25:43 +08:00
. event ( GridEvent ::GetGridBlocks , get_grid_blocks_handler )
2022-06-19 21:10:07 +08:00
. event ( GridEvent ::GetGridSetting , get_grid_setting_handler )
2022-09-04 15:33:07 +08:00
. event ( GridEvent ::UpdateGridSetting , update_grid_setting_handler )
2022-04-05 21:25:59 +08:00
// Field
2022-03-03 22:17:07 +08:00
. event ( GridEvent ::GetFields , get_fields_handler )
2022-03-23 22:10:31 +08:00
. event ( GridEvent ::UpdateField , update_field_handler )
2022-05-10 09:33:34 +08:00
. event ( GridEvent ::UpdateFieldTypeOption , update_field_type_option_handler )
2022-03-27 11:14:21 +08:00
. event ( GridEvent ::DeleteField , delete_field_handler )
2022-04-01 09:31:10 +08:00
. event ( GridEvent ::SwitchToField , switch_to_field_handler )
2022-03-27 11:14:21 +08:00
. event ( GridEvent ::DuplicateField , duplicate_field_handler )
2022-08-16 15:49:54 +08:00
. event ( GridEvent ::MoveField , move_field_handler )
2022-05-09 13:23:03 +08:00
. event ( GridEvent ::GetFieldTypeOption , get_field_type_option_data_handler )
2022-05-19 10:41:00 +08:00
. event ( GridEvent ::CreateFieldTypeOption , create_field_type_option_data_handler )
2022-04-05 21:25:59 +08:00
// Row
2022-08-16 15:49:54 +08:00
. event ( GridEvent ::CreateTableRow , create_table_row_handler )
2022-03-18 17:14:46 +08:00
. event ( GridEvent ::GetRow , get_row_handler )
2022-04-09 22:07:48 +08:00
. event ( GridEvent ::DeleteRow , delete_row_handler )
. event ( GridEvent ::DuplicateRow , duplicate_row_handler )
2022-08-16 15:49:54 +08:00
. event ( GridEvent ::MoveRow , move_row_handler )
2022-04-05 21:25:59 +08:00
// Cell
2022-04-07 20:15:00 +08:00
. event ( GridEvent ::GetCell , get_cell_handler )
2022-04-05 14:25:07 +08:00
. event ( GridEvent ::UpdateCell , update_cell_handler )
2022-04-05 21:25:59 +08:00
// SelectOption
2022-04-07 08:33:10 +08:00
. event ( GridEvent ::NewSelectOption , new_select_option_handler )
2022-04-12 10:06:47 +08:00
. event ( GridEvent ::UpdateSelectOption , update_select_option_handler )
2022-05-12 22:36:39 +08:00
. event ( GridEvent ::GetSelectOptionCellData , get_select_option_handler )
2022-05-11 11:34:13 +08:00
. event ( GridEvent ::UpdateSelectOptionCell , update_select_option_cell_handler )
// Date
2022-08-11 13:04:45 +08:00
. event ( GridEvent ::UpdateDateCell , update_date_cell_handler )
// Group
2022-08-14 11:05:55 +08:00
. event ( GridEvent ::CreateBoardCard , create_board_card_handler )
2022-08-19 19:59:09 +08:00
. event ( GridEvent ::MoveGroup , move_group_handler )
2022-08-22 16:16:15 +08:00
. event ( GridEvent ::MoveGroupRow , move_group_row_handler )
2022-08-11 21:18:27 +08:00
. event ( GridEvent ::GetGroup , get_groups_handler ) ;
2022-03-02 22:43:04 +08:00
module
}
2022-07-25 12:45:35 +08:00
/// [GridEvent] defines events that are used to interact with the Grid. You could check [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/backend/protobuf)
/// out, it includes how to use these annotations: input, output, etc.
2022-03-02 22:43:04 +08:00
#[ derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event) ]
#[ event_err = " FlowyError " ]
pub enum GridEvent {
2022-07-25 12:45:35 +08:00
/// [GetGrid] event is used to get the [GridPB]
///
2022-07-25 17:17:11 -04:00
/// The event handler accepts a [GridIdPB] and returns a [GridPB] if there are no errors.
2022-07-17 14:13:12 +08:00
#[ event(input = " GridIdPB " , output = " GridPB " ) ]
2022-06-24 18:13:40 +08:00
GetGrid = 0 ,
2022-03-03 22:17:07 +08:00
2022-07-25 12:45:35 +08:00
/// [GetGridBlocks] event is used to get the grid's block.
///
2022-08-11 13:25:55 +08:00
/// The event handler accepts a [QueryBlocksPayloadPB] and returns a [RepeatedBlockPB]
2022-07-25 17:17:11 -04:00
/// if there are no errors.
2022-08-11 13:25:55 +08:00
#[ event(input = " QueryBlocksPayloadPB " , output = " RepeatedBlockPB " ) ]
2022-03-17 17:25:43 +08:00
GetGridBlocks = 1 ,
2022-03-03 22:17:07 +08:00
2022-07-25 17:17:11 -04:00
/// [GetGridSetting] event is used to get the grid's settings.
2022-07-25 12:45:35 +08:00
///
/// The event handler accepts [GridIdPB] and return [GridSettingPB]
/// if there is no errors.
2022-07-17 14:13:12 +08:00
#[ event(input = " GridIdPB " , output = " GridSettingPB " ) ]
2022-06-19 21:10:07 +08:00
GetGridSetting = 2 ,
2022-07-25 17:17:11 -04:00
/// [UpdateGridSetting] event is used to update the grid's settings.
2022-07-25 12:45:35 +08:00
///
2022-09-04 15:33:07 +08:00
/// The event handler accepts [GridSettingChangesetPayloadPB] and return errors if failed to modify the grid's settings.
#[ event(input = " GridSettingChangesetPayloadPB " ) ]
2022-06-20 09:37:52 +08:00
UpdateGridSetting = 3 ,
2022-07-25 17:17:11 -04:00
/// [GetFields] event is used to get the grid's settings.
2022-07-25 12:45:35 +08:00
///
2022-08-11 13:25:55 +08:00
/// The event handler accepts a [QueryFieldPayloadPB] and returns a [RepeatedFieldPB]
2022-07-25 17:17:11 -04:00
/// if there are no errors.
2022-08-11 13:25:55 +08:00
#[ event(input = " QueryFieldPayloadPB " , output = " RepeatedFieldPB " ) ]
2022-03-18 17:14:46 +08:00
GetFields = 10 ,
2022-03-03 22:17:07 +08:00
2022-07-25 17:17:11 -04:00
/// [UpdateField] event is used to update a field's attributes.
2022-07-25 12:45:35 +08:00
///
2022-07-25 17:17:11 -04:00
/// The event handler accepts a [FieldChangesetPayloadPB] and returns errors if failed to modify the
2022-07-25 12:45:35 +08:00
/// field.
2022-07-17 14:13:12 +08:00
#[ event(input = " FieldChangesetPayloadPB " ) ]
2022-03-23 22:10:31 +08:00
UpdateField = 11 ,
2022-10-11 21:51:02 +08:00
/// [UpdateFieldTypeOption] event is used to update the field's type-option data. Certain field
2022-07-25 12:45:35 +08:00
/// types have user-defined options such as color, date format, number format, or a list of values
/// for a multi-select list. These options are defined within a specialization of the
/// FieldTypeOption class.
///
/// Check out [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid#fieldtype)
/// for more information.
///
2022-07-25 17:17:11 -04:00
/// The event handler accepts a [UpdateFieldTypeOptionPayloadPB] and returns errors if failed to modify the
2022-07-25 12:45:35 +08:00
/// field.
2022-07-17 14:13:12 +08:00
#[ event(input = " UpdateFieldTypeOptionPayloadPB " ) ]
2022-05-10 09:33:34 +08:00
UpdateFieldTypeOption = 12 ,
2022-07-25 17:17:11 -04:00
/// [DeleteField] event is used to delete a Field. [DeleteFieldPayloadPB] is the context that
2022-07-25 12:45:35 +08:00
/// is used to delete the field from the Grid.
2022-07-25 13:15:11 +08:00
#[ event(input = " DeleteFieldPayloadPB " ) ]
2022-05-10 09:33:34 +08:00
DeleteField = 14 ,
2022-03-27 09:35:10 +08:00
2022-07-25 17:17:11 -04:00
/// [SwitchToField] event is used to update the current Field's type.
2022-07-25 12:45:35 +08:00
/// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
/// reuse the existing FieldTypeOptionData. You could check the [GridRevisionPad] for more details.
2022-10-10 20:02:52 +08:00
#[ event(input = " EditFieldPayloadPB " ) ]
2022-05-10 09:33:34 +08:00
SwitchToField = 20 ,
2022-04-01 09:31:10 +08:00
2022-07-25 17:17:11 -04:00
/// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
2022-07-25 12:45:35 +08:00
/// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
/// used to duplicate the field.
///
/// Return errors if failed to duplicate the field.
///
2022-07-25 13:15:11 +08:00
#[ event(input = " DuplicateFieldPayloadPB " ) ]
2022-05-10 09:33:34 +08:00
DuplicateField = 21 ,
2022-03-27 11:14:21 +08:00
2022-07-25 17:17:11 -04:00
/// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
/// [MoveItemTypePB].
2022-08-16 15:49:54 +08:00
#[ event(input = " MoveFieldPayloadPB " ) ]
MoveField = 22 ,
2022-04-13 14:24:54 +08:00
2022-08-11 13:25:55 +08:00
/// [FieldTypeOptionIdPB] event is used to get the FieldTypeOption data for a specific field type.
2022-07-25 12:45:35 +08:00
///
/// Check out the [FieldTypeOptionDataPB] for more details. If the [FieldTypeOptionData] does exist
/// for the target type, the [TypeOptionBuilder] will create the default data for that type.
///
2022-07-25 17:17:11 -04:00
/// Return the [FieldTypeOptionDataPB] if there are no errors.
2022-08-11 13:25:55 +08:00
#[ event(input = " FieldTypeOptionIdPB " , output = " FieldTypeOptionDataPB " ) ]
2022-05-17 16:57:37 +08:00
GetFieldTypeOption = 23 ,
2022-05-09 13:23:03 +08:00
2022-07-25 12:45:35 +08:00
/// [CreateFieldTypeOption] event is used to create a new FieldTypeOptionData.
2022-07-25 13:15:11 +08:00
#[ event(input = " CreateFieldPayloadPB " , output = " FieldTypeOptionDataPB " ) ]
2022-05-19 10:41:00 +08:00
CreateFieldTypeOption = 24 ,
2022-07-25 17:17:11 -04:00
/// [NewSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
/// there are no errors.
2022-07-17 14:13:12 +08:00
#[ event(input = " CreateSelectOptionPayloadPB " , output = " SelectOptionPB " ) ]
2022-04-07 08:33:10 +08:00
NewSelectOption = 30 ,
2022-03-29 22:58:38 +08:00
2022-07-25 12:45:35 +08:00
/// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
/// [GridCellIdPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
/// contains the available options and the currently selected options.
2022-07-25 13:15:11 +08:00
#[ event(input = " GridCellIdPB " , output = " SelectOptionCellDataPB " ) ]
2022-05-12 22:36:39 +08:00
GetSelectOptionCellData = 31 ,
2022-04-07 08:33:10 +08:00
2022-07-25 17:17:11 -04:00
/// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
2022-07-25 12:45:35 +08:00
/// FieldType::SingleSelect or FieldType::MultiSelect.
///
/// This event may trigger the GridNotification::DidUpdateCell event.
2022-07-31 19:43:52 +08:00
/// For example, GridNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPayloadPB]
2022-07-25 17:17:11 -04:00
/// carries a change that updates the name of the option.
2022-07-17 14:13:12 +08:00
#[ event(input = " SelectOptionChangesetPayloadPB " ) ]
2022-04-12 10:06:47 +08:00
UpdateSelectOption = 32 ,
2022-04-05 14:25:07 +08:00
2022-08-16 15:49:54 +08:00
#[ event(input = " CreateTableRowPayloadPB " , output = " RowPB " ) ]
CreateTableRow = 50 ,
2022-03-18 17:14:46 +08:00
2022-08-11 13:25:55 +08:00
/// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
2022-07-25 12:45:35 +08:00
/// to return a nullable row data.
2022-08-11 13:25:55 +08:00
#[ event(input = " RowIdPB " , output = " OptionalRowPB " ) ]
2022-03-29 22:58:38 +08:00
GetRow = 51 ,
2022-03-09 16:11:24 +08:00
2022-08-11 13:25:55 +08:00
#[ event(input = " RowIdPB " ) ]
2022-04-09 22:07:48 +08:00
DeleteRow = 52 ,
2022-08-11 13:25:55 +08:00
#[ event(input = " RowIdPB " ) ]
2022-04-09 22:07:48 +08:00
DuplicateRow = 53 ,
2022-08-16 15:49:54 +08:00
#[ event(input = " MoveRowPayloadPB " ) ]
MoveRow = 54 ,
2022-07-25 13:15:11 +08:00
#[ event(input = " GridCellIdPB " , output = " GridCellPB " ) ]
2022-04-07 20:15:00 +08:00
GetCell = 70 ,
2022-07-25 12:45:35 +08:00
/// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],
/// carries the changes that will be applied to the cell content by calling `update_cell` function.
///
2022-07-25 17:17:11 -04:00
/// The 'content' property of the [CellChangesetPB] is a String type. It can be used directly if the
/// cell uses string data. For example, the TextCell or NumberCell.
2022-07-25 12:45:35 +08:00
///
/// But,it can be treated as a generic type, because we can use [serde] to deserialize the string
2022-07-25 17:17:11 -04:00
/// into a specific data type. For the moment, the 'content' will be deserialized to a concrete type
/// when the FieldType is SingleSelect, DateTime, and MultiSelect. Please see
/// the [UpdateSelectOptionCell] and [UpdateDateCell] events for more details.
2022-07-17 14:13:12 +08:00
#[ event(input = " CellChangesetPB " ) ]
2022-04-07 20:15:00 +08:00
UpdateCell = 71 ,
2022-04-05 14:25:07 +08:00
2022-07-25 17:17:11 -04:00
/// [UpdateSelectOptionCell] event is used to update a select option cell's data. [SelectOptionCellChangesetPayloadPB]
2022-07-25 12:45:35 +08:00
/// contains options that will be deleted or inserted. It can be cast to [CellChangesetPB] that
/// will be used by the `update_cell` function.
2022-07-17 14:13:12 +08:00
#[ event(input = " SelectOptionCellChangesetPayloadPB " ) ]
2022-05-11 11:34:13 +08:00
UpdateSelectOptionCell = 72 ,
2022-07-25 17:17:11 -04:00
/// [UpdateDateCell] event is used to update a date cell's data. [DateChangesetPayloadPB]
2022-07-25 12:45:35 +08:00
/// contains the date and the time string. It can be cast to [CellChangesetPB] that
/// will be used by the `update_cell` function.
2022-07-17 14:13:12 +08:00
#[ event(input = " DateChangesetPayloadPB " ) ]
2022-05-11 11:34:13 +08:00
UpdateDateCell = 80 ,
2022-08-11 13:04:45 +08:00
#[ event(input = " GridIdPB " , output = " RepeatedGridGroupPB " ) ]
GetGroup = 100 ,
2022-08-13 23:26:42 +08:00
#[ event(input = " CreateBoardCardPayloadPB " , output = " RowPB " ) ]
CreateBoardCard = 110 ,
2022-08-19 19:59:09 +08:00
2022-08-21 13:56:06 +08:00
#[ event(input = " MoveGroupPayloadPB " ) ]
2022-08-19 19:59:09 +08:00
MoveGroup = 111 ,
2022-08-22 16:16:15 +08:00
#[ event(input = " MoveGroupRowPayloadPB " ) ]
MoveGroupRow = 112 ,
2022-09-04 15:33:07 +08:00
#[ event(input = " MoveGroupRowPayloadPB " ) ]
GroupByField = 113 ,
2022-03-02 22:43:04 +08:00
}