checkbox_controller.rs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. use crate::entities::GroupRowsChangesetPB;
  2. use crate::services::field::{CheckboxCellData, CheckboxCellDataParser, CheckboxTypeOptionPB, CHECK, UNCHECK};
  3. use crate::services::group::action::GroupAction;
  4. use crate::services::group::configuration::GenericGroupConfiguration;
  5. use crate::services::group::controller::{
  6. GenericGroupController, GroupController, GroupGenerator, MoveGroupRowContext,
  7. };
  8. use crate::services::group::entities::Group;
  9. use flowy_grid_data_model::revision::{CheckboxGroupConfigurationRevision, FieldRevision, RowRevision};
  10. pub type CheckboxGroupController = GenericGroupController<
  11. CheckboxGroupConfigurationRevision,
  12. CheckboxTypeOptionPB,
  13. CheckboxGroupGenerator,
  14. CheckboxCellDataParser,
  15. >;
  16. pub type CheckboxGroupConfiguration = GenericGroupConfiguration<CheckboxGroupConfigurationRevision>;
  17. impl GroupAction for CheckboxGroupController {
  18. type CellDataType = CheckboxCellData;
  19. fn can_group(&self, _content: &str, _cell_data: &Self::CellDataType) -> bool {
  20. false
  21. }
  22. fn add_row_if_match(
  23. &mut self,
  24. _row_rev: &RowRevision,
  25. _cell_data: &Self::CellDataType,
  26. ) -> Vec<GroupRowsChangesetPB> {
  27. todo!()
  28. }
  29. fn remove_row_if_match(
  30. &mut self,
  31. _row_rev: &RowRevision,
  32. _cell_data: &Self::CellDataType,
  33. ) -> Vec<GroupRowsChangesetPB> {
  34. todo!()
  35. }
  36. fn move_row(
  37. &mut self,
  38. _cell_data: &Self::CellDataType,
  39. _context: MoveGroupRowContext,
  40. ) -> Vec<GroupRowsChangesetPB> {
  41. todo!()
  42. }
  43. }
  44. impl GroupController for CheckboxGroupController {
  45. fn will_create_row(&mut self, _row_rev: &mut RowRevision, _field_rev: &FieldRevision, _group_id: &str) {
  46. todo!()
  47. }
  48. }
  49. pub struct CheckboxGroupGenerator();
  50. impl GroupGenerator for CheckboxGroupGenerator {
  51. type ConfigurationType = CheckboxGroupConfiguration;
  52. type TypeOptionType = CheckboxTypeOptionPB;
  53. fn generate_groups(
  54. field_id: &str,
  55. _configuration: &Self::ConfigurationType,
  56. _type_option: &Option<Self::TypeOptionType>,
  57. ) -> Vec<Group> {
  58. let check_group = Group::new(
  59. "true".to_string(),
  60. field_id.to_owned(),
  61. "".to_string(),
  62. CHECK.to_string(),
  63. );
  64. let uncheck_group = Group::new(
  65. "false".to_string(),
  66. field_id.to_owned(),
  67. "".to_string(),
  68. UNCHECK.to_string(),
  69. );
  70. vec![check_group, uncheck_group]
  71. }
  72. }