event_map.rs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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_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::MoveGroup, move_group_handler)
  47. .event(DatabaseEvent::MoveGroupRow, move_group_row_handler)
  48. .event(DatabaseEvent::GetGroups, get_groups_handler)
  49. .event(DatabaseEvent::GetGroup, get_group_handler)
  50. // Database
  51. .event(DatabaseEvent::GetDatabases, get_databases_handler)
  52. // Calendar
  53. .event(DatabaseEvent::GetAllCalendarEvents, get_calendar_events_handler)
  54. .event(DatabaseEvent::GetCalendarEvent, get_calendar_event_handler)
  55. // Layout setting
  56. .event(DatabaseEvent::SetLayoutSetting, set_layout_setting_handler)
  57. .event(DatabaseEvent::GetLayoutSetting, get_layout_setting_handler);
  58. plugin
  59. }
  60. /// [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)
  61. /// out, it includes how to use these annotations: input, output, etc.
  62. #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
  63. #[event_err = "FlowyError"]
  64. pub enum DatabaseEvent {
  65. /// [GetDatabase] event is used to get the [DatabasePB]
  66. ///
  67. /// The event handler accepts a [DatabaseViewIdPB] and returns a [DatabasePB] if there are no errors.
  68. #[event(input = "DatabaseViewIdPB", output = "DatabasePB")]
  69. GetDatabase = 0,
  70. /// [GetDatabaseSetting] event is used to get the database's settings.
  71. ///
  72. /// The event handler accepts [DatabaseViewIdPB] and return [DatabaseViewSettingPB]
  73. /// if there is no errors.
  74. #[event(input = "DatabaseViewIdPB", output = "DatabaseViewSettingPB")]
  75. GetDatabaseSetting = 2,
  76. /// [UpdateDatabaseSetting] event is used to update the database's settings.
  77. ///
  78. /// The event handler accepts [DatabaseSettingChangesetPB] and return errors if failed to modify the grid's settings.
  79. #[event(input = "DatabaseSettingChangesetPB")]
  80. UpdateDatabaseSetting = 3,
  81. #[event(input = "DatabaseViewIdPB", output = "RepeatedFilterPB")]
  82. GetAllFilters = 4,
  83. #[event(input = "DatabaseViewIdPB", output = "RepeatedSortPB")]
  84. GetAllSorts = 5,
  85. #[event(input = "DatabaseViewIdPB")]
  86. DeleteAllSorts = 6,
  87. /// [GetFields] event is used to get the database's settings.
  88. ///
  89. /// The event handler accepts a [GetFieldPayloadPB] and returns a [RepeatedFieldPB]
  90. /// if there are no errors.
  91. #[event(input = "GetFieldPayloadPB", output = "RepeatedFieldPB")]
  92. GetFields = 10,
  93. /// [UpdateField] event is used to update a field's attributes.
  94. ///
  95. /// The event handler accepts a [FieldChangesetPB] and returns errors if failed to modify the
  96. /// field.
  97. #[event(input = "FieldChangesetPB")]
  98. UpdateField = 11,
  99. /// [UpdateFieldTypeOption] event is used to update the field's type-option data. Certain field
  100. /// types have user-defined options such as color, date format, number format, or a list of values
  101. /// for a multi-select list. These options are defined within a specialization of the
  102. /// FieldTypeOption class.
  103. ///
  104. /// Check out [this](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/architecture/frontend/grid#fieldtype)
  105. /// for more information.
  106. ///
  107. /// The event handler accepts a [TypeOptionChangesetPB] and returns errors if failed to modify the
  108. /// field.
  109. #[event(input = "TypeOptionChangesetPB")]
  110. UpdateFieldTypeOption = 12,
  111. /// [DeleteField] event is used to delete a Field. [DeleteFieldPayloadPB] is the context that
  112. /// is used to delete the field from the Database.
  113. #[event(input = "DeleteFieldPayloadPB")]
  114. DeleteField = 14,
  115. /// [UpdateFieldType] event is used to update the current Field's type.
  116. /// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
  117. /// reuse the existing FieldTypeOptionData. You could check the [DatabaseRevisionPad] for more details.
  118. #[event(input = "UpdateFieldTypePayloadPB")]
  119. UpdateFieldType = 20,
  120. /// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
  121. /// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
  122. /// used to duplicate the field.
  123. ///
  124. /// Return errors if failed to duplicate the field.
  125. ///
  126. #[event(input = "DuplicateFieldPayloadPB")]
  127. DuplicateField = 21,
  128. /// [MoveItem] event is used to move an item. For the moment, Item has two types defined in
  129. /// [MoveItemTypePB].
  130. #[event(input = "MoveFieldPayloadPB")]
  131. MoveField = 22,
  132. /// [TypeOptionPathPB] event is used to get the FieldTypeOption data for a specific field type.
  133. ///
  134. /// Check out the [TypeOptionPB] for more details. If the [FieldTypeOptionData] does exist
  135. /// for the target type, the [TypeOptionBuilder] will create the default data for that type.
  136. ///
  137. /// Return the [TypeOptionPB] if there are no errors.
  138. #[event(input = "TypeOptionPathPB", output = "TypeOptionPB")]
  139. GetTypeOption = 23,
  140. /// [CreateTypeOption] event is used to create a new FieldTypeOptionData.
  141. #[event(input = "CreateFieldPayloadPB", output = "TypeOptionPB")]
  142. CreateTypeOption = 24,
  143. /// [CreateSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
  144. /// there are no errors.
  145. #[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
  146. CreateSelectOption = 30,
  147. /// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
  148. /// [CellIdPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
  149. /// contains the available options and the currently selected options.
  150. #[event(input = "CellIdPB", output = "SelectOptionCellDataPB")]
  151. GetSelectOptionCellData = 31,
  152. /// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
  153. /// FieldType::SingleSelect or FieldType::MultiSelect.
  154. ///
  155. /// This event may trigger the DatabaseNotification::DidUpdateCell event.
  156. /// For example, DatabaseNotification::DidUpdateCell will be triggered if the [SelectOptionChangesetPB]
  157. /// carries a change that updates the name of the option.
  158. #[event(input = "SelectOptionChangesetPB")]
  159. UpdateSelectOption = 32,
  160. #[event(input = "CreateRowPayloadPB", output = "RowPB")]
  161. CreateRow = 50,
  162. /// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
  163. /// to return a nullable row data.
  164. #[event(input = "RowIdPB", output = "OptionalRowPB")]
  165. GetRow = 51,
  166. #[event(input = "RowIdPB")]
  167. DeleteRow = 52,
  168. #[event(input = "RowIdPB")]
  169. DuplicateRow = 53,
  170. #[event(input = "MoveRowPayloadPB")]
  171. MoveRow = 54,
  172. #[event(input = "CellIdPB", output = "CellPB")]
  173. GetCell = 70,
  174. /// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],
  175. /// carries the changes that will be applied to the cell content by calling `update_cell` function.
  176. ///
  177. /// The 'content' property of the [CellChangesetPB] is a String type. It can be used directly if the
  178. /// cell uses string data. For example, the TextCell or NumberCell.
  179. ///
  180. /// But,it can be treated as a generic type, because we can use [serde] to deserialize the string
  181. /// into a specific data type. For the moment, the 'content' will be deserialized to a concrete type
  182. /// when the FieldType is SingleSelect, DateTime, and MultiSelect. Please see
  183. /// the [UpdateSelectOptionCell] and [UpdateDateCell] events for more details.
  184. #[event(input = "CellChangesetPB")]
  185. UpdateCell = 71,
  186. /// [UpdateSelectOptionCell] event is used to update a select option cell's data. [SelectOptionCellChangesetPB]
  187. /// contains options that will be deleted or inserted. It can be cast to [CellChangesetPB] that
  188. /// will be used by the `update_cell` function.
  189. #[event(input = "SelectOptionCellChangesetPB")]
  190. UpdateSelectOptionCell = 72,
  191. /// [UpdateDateCell] event is used to update a date cell's data. [DateChangesetPB]
  192. /// contains the date and the time string. It can be cast to [CellChangesetPB] that
  193. /// will be used by the `update_cell` function.
  194. #[event(input = "DateChangesetPB")]
  195. UpdateDateCell = 80,
  196. #[event(input = "DatabaseViewIdPB", output = "RepeatedGroupPB")]
  197. GetGroups = 100,
  198. #[event(input = "DatabaseGroupIdPB", output = "GroupPB")]
  199. GetGroup = 101,
  200. #[event(input = "MoveGroupPayloadPB")]
  201. MoveGroup = 111,
  202. #[event(input = "MoveGroupRowPayloadPB")]
  203. MoveGroupRow = 112,
  204. #[event(input = "MoveGroupRowPayloadPB")]
  205. GroupByField = 113,
  206. /// Returns all the databases
  207. #[event(output = "RepeatedDatabaseDescriptionPB")]
  208. GetDatabases = 114,
  209. #[event(input = "UpdateLayoutSettingPB")]
  210. SetLayoutSetting = 115,
  211. #[event(input = "DatabaseLayoutIdPB", output = "LayoutSettingPB")]
  212. GetLayoutSetting = 116,
  213. #[event(input = "CalendarEventRequestPB", output = "RepeatedCalendarEventPB")]
  214. GetAllCalendarEvents = 117,
  215. #[event(input = "RowIdPB", output = "CalendarEventPB")]
  216. GetCalendarEvent = 118,
  217. #[event(input = "MoveCalendarEventPB")]
  218. MoveCalendarEvent = 119,
  219. }