event_map.rs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. use crate::event_handler::*;
  2. use crate::manager::DatabaseManager;
  3. use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
  4. use lib_dispatch::prelude::*;
  5. use std::sync::Arc;
  6. use strum_macros::Display;
  7. pub fn init(database_manager: Arc<DatabaseManager>) -> AFPlugin {
  8. let mut plugin = AFPlugin::new()
  9. .name(env!("CARGO_PKG_NAME"))
  10. .state(database_manager);
  11. plugin = plugin
  12. .event(DatabaseEvent::GetDatabase, get_database_data_handler)
  13. // .event(GridEvent::GetGridBlocks, get_grid_blocks_handler)
  14. .event(DatabaseEvent::GetDatabaseSetting, get_database_setting_handler)
  15. .event(DatabaseEvent::UpdateDatabaseSetting, update_database_setting_handler)
  16. .event(DatabaseEvent::GetAllFilters, get_all_filters_handler)
  17. .event(DatabaseEvent::GetAllSorts, get_all_sorts_handler)
  18. .event(DatabaseEvent::DeleteAllSorts, delete_all_sorts_handler)
  19. // Field
  20. .event(DatabaseEvent::GetFields, get_fields_handler)
  21. .event(DatabaseEvent::UpdateField, update_field_handler)
  22. .event(DatabaseEvent::UpdateFieldTypeOption, update_field_type_option_handler)
  23. .event(DatabaseEvent::DeleteField, delete_field_handler)
  24. .event(DatabaseEvent::UpdateFieldType, switch_to_field_handler)
  25. .event(DatabaseEvent::DuplicateField, duplicate_field_handler)
  26. .event(DatabaseEvent::MoveField, move_field_handler)
  27. .event(DatabaseEvent::GetTypeOption, get_field_type_option_data_handler)
  28. .event(DatabaseEvent::CreateTypeOption, create_field_type_option_data_handler)
  29. // Row
  30. .event(DatabaseEvent::CreateRow, create_table_row_handler)
  31. .event(DatabaseEvent::GetRow, get_row_handler)
  32. .event(DatabaseEvent::DeleteRow, delete_row_handler)
  33. .event(DatabaseEvent::DuplicateRow, duplicate_row_handler)
  34. .event(DatabaseEvent::MoveRow, move_row_handler)
  35. // Cell
  36. .event(DatabaseEvent::GetCell, get_cell_handler)
  37. .event(DatabaseEvent::UpdateCell, update_cell_handler)
  38. // SelectOption
  39. .event(DatabaseEvent::CreateSelectOption, new_select_option_handler)
  40. .event(DatabaseEvent::UpdateSelectOption, update_select_option_handler)
  41. .event(DatabaseEvent::GetSelectOptionCellData, get_select_option_handler)
  42. .event(DatabaseEvent::UpdateSelectOptionCell, update_select_option_cell_handler)
  43. // Date
  44. .event(DatabaseEvent::UpdateDateCell, update_date_cell_handler)
  45. // Group
  46. .event(DatabaseEvent::CreateBoardCard, create_board_card_handler)
  47. .event(DatabaseEvent::MoveGroup, move_group_handler)
  48. .event(DatabaseEvent::MoveGroupRow, move_group_row_handler)
  49. .event(DatabaseEvent::GetGroup, get_groups_handler)
  50. // Database
  51. .event(DatabaseEvent::GetDatabases, get_databases_handler)
  52. // Calendar
  53. .event(DatabaseEvent::SetCalenderSetting, set_calendar_setting_handler)
  54. .event(DatabaseEvent::GetCalendarSetting, get_calendar_setting_handler);
  55. plugin
  56. }
  57. /// [DatabaseEvent] 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)
  58. /// out, it includes how to use these annotations: input, output, etc.
  59. #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
  60. #[event_err = "FlowyError"]
  61. pub enum DatabaseEvent {
  62. /// [GetDatabase] event is used to get the [DatabasePB]
  63. ///
  64. /// The event handler accepts a [DatabaseViewIdPB] and returns a [DatabasePB] if there are no errors.
  65. #[event(input = "DatabaseViewIdPB", output = "DatabasePB")]
  66. GetDatabase = 0,
  67. /// [GetDatabaseSetting] event is used to get the database's settings.
  68. ///
  69. /// The event handler accepts [DatabaseViewIdPB] and return [DatabaseViewSettingPB]
  70. /// if there is no errors.
  71. #[event(input = "DatabaseViewIdPB", output = "DatabaseViewSettingPB")]
  72. GetDatabaseSetting = 2,
  73. /// [UpdateDatabaseSetting] event is used to update the database's settings.
  74. ///
  75. /// The event handler accepts [DatabaseSettingChangesetPB] and return errors if failed to modify the grid's settings.
  76. #[event(input = "DatabaseSettingChangesetPB")]
  77. UpdateDatabaseSetting = 3,
  78. #[event(input = "DatabaseViewIdPB", output = "RepeatedFilterPB")]
  79. GetAllFilters = 4,
  80. #[event(input = "DatabaseViewIdPB", output = "RepeatedSortPB")]
  81. GetAllSorts = 5,
  82. #[event(input = "DatabaseViewIdPB")]
  83. DeleteAllSorts = 6,
  84. /// [GetFields] event is used to get the database's settings.
  85. ///
  86. /// The event handler accepts a [GetFieldPayloadPB] and returns a [RepeatedFieldPB]
  87. /// if there are no errors.
  88. #[event(input = "GetFieldPayloadPB", output = "RepeatedFieldPB")]
  89. GetFields = 10,
  90. /// [UpdateField] event is used to update a field's attributes.
  91. ///
  92. /// The event handler accepts a [FieldChangesetPB] and returns errors if failed to modify the
  93. /// field.
  94. #[event(input = "FieldChangesetPB")]
  95. UpdateField = 11,
  96. /// [UpdateFieldTypeOption] event is used to update the field's type-option data. Certain field
  97. /// types have user-defined options such as color, date format, number format, or a list of values
  98. /// for a multi-select list. These options are defined within a specialization of the
  99. /// FieldTypeOption class.
  100. ///
  101. /// Check out [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid#fieldtype)
  102. /// for more information.
  103. ///
  104. /// The event handler accepts a [TypeOptionChangesetPB] and returns errors if failed to modify the
  105. /// field.
  106. #[event(input = "TypeOptionChangesetPB")]
  107. UpdateFieldTypeOption = 12,
  108. /// [DeleteField] event is used to delete a Field. [DeleteFieldPayloadPB] is the context that
  109. /// is used to delete the field from the Database.
  110. #[event(input = "DeleteFieldPayloadPB")]
  111. DeleteField = 14,
  112. /// [UpdateFieldType] event is used to update the current Field's type.
  113. /// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
  114. /// reuse the existing FieldTypeOptionData. You could check the [DatabaseRevisionPad] for more details.
  115. #[event(input = "UpdateFieldTypePayloadPB")]
  116. UpdateFieldType = 20,
  117. /// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
  118. /// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
  119. /// used to duplicate the field.
  120. ///
  121. /// Return errors if failed to duplicate the field.
  122. ///
  123. #[event(input = "DuplicateFieldPayloadPB")]
  124. DuplicateField = 21,
  125. /// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
  126. /// [MoveItemTypePB].
  127. #[event(input = "MoveFieldPayloadPB")]
  128. MoveField = 22,
  129. /// [TypeOptionPathPB] event is used to get the FieldTypeOption data for a specific field type.
  130. ///
  131. /// Check out the [TypeOptionPB] for more details. If the [FieldTypeOptionData] does exist
  132. /// for the target type, the [TypeOptionBuilder] will create the default data for that type.
  133. ///
  134. /// Return the [TypeOptionPB] if there are no errors.
  135. #[event(input = "TypeOptionPathPB", output = "TypeOptionPB")]
  136. GetTypeOption = 23,
  137. /// [CreateTypeOption] event is used to create a new FieldTypeOptionData.
  138. #[event(input = "CreateFieldPayloadPB", output = "TypeOptionPB")]
  139. CreateTypeOption = 24,
  140. /// [CreateSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
  141. /// there are no errors.
  142. #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
  143. CreateSelectOption = 30,
  144. /// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
  145. /// [CellIdPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
  146. /// contains the available options and the currently selected options.
  147. #[event(input = "CellIdPB", output = "SelectOptionCellDataPB")]
  148. GetSelectOptionCellData = 31,
  149. /// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
  150. /// FieldType::SingleSelect or FieldType::MultiSelect.
  151. ///
  152. /// This event may trigger the DatabaseNotification::DidUpdateCell event.
  153. /// For example, DatabaseNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPB]
  154. /// carries a change that updates the name of the option.
  155. #[event(input = "SelectOptionChangesetPB")]
  156. UpdateSelectOption = 32,
  157. #[event(input = "CreateRowPayloadPB", output = "RowPB")]
  158. CreateRow = 50,
  159. /// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
  160. /// to return a nullable row data.
  161. #[event(input = "RowIdPB", output = "OptionalRowPB")]
  162. GetRow = 51,
  163. #[event(input = "RowIdPB")]
  164. DeleteRow = 52,
  165. #[event(input = "RowIdPB")]
  166. DuplicateRow = 53,
  167. #[event(input = "MoveRowPayloadPB")]
  168. MoveRow = 54,
  169. #[event(input = "CellIdPB", output = "CellPB")]
  170. GetCell = 70,
  171. /// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],
  172. /// carries the changes that will be applied to the cell content by calling `update_cell` function.
  173. ///
  174. /// The 'content' property of the [CellChangesetPB] is a String type. It can be used directly if the
  175. /// cell uses string data. For example, the TextCell or NumberCell.
  176. ///
  177. /// But,it can be treated as a generic type, because we can use [serde] to deserialize the string
  178. /// into a specific data type. For the moment, the 'content' will be deserialized to a concrete type
  179. /// when the FieldType is SingleSelect, DateTime, and MultiSelect. Please see
  180. /// the [UpdateSelectOptionCell] and [UpdateDateCell] events for more details.
  181. #[event(input = "CellChangesetPB")]
  182. UpdateCell = 71,
  183. /// [UpdateSelectOptionCell] event is used to update a select option cell's data. [SelectOptionCellChangesetPB]
  184. /// contains options that will be deleted or inserted. It can be cast to [CellChangesetPB] that
  185. /// will be used by the `update_cell` function.
  186. #[event(input = "SelectOptionCellChangesetPB")]
  187. UpdateSelectOptionCell = 72,
  188. /// [UpdateDateCell] event is used to update a date cell's data. [DateChangesetPB]
  189. /// contains the date and the time string. It can be cast to [CellChangesetPB] that
  190. /// will be used by the `update_cell` function.
  191. #[event(input = "DateChangesetPB")]
  192. UpdateDateCell = 80,
  193. #[event(input = "DatabaseViewIdPB", output = "RepeatedGroupPB")]
  194. GetGroup = 100,
  195. #[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
  196. CreateBoardCard = 110,
  197. #[event(input = "MoveGroupPayloadPB")]
  198. MoveGroup = 111,
  199. #[event(input = "MoveGroupRowPayloadPB")]
  200. MoveGroupRow = 112,
  201. #[event(input = "MoveGroupRowPayloadPB")]
  202. GroupByField = 113,
  203. #[event(output = "RepeatedDatabaseDescPB")]
  204. GetDatabases = 114,
  205. #[event(input = "CalendarSettingsPB")]
  206. SetCalenderSetting = 115,
  207. #[event()]
  208. GetCalendarSetting = 116,
  209. }