checkbox_controller.rs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, GroupConfigurationAction};
  5. use crate::services::group::entities::Group;
  6. use crate::services::group::group_controller::{GenericGroupController, GroupController, GroupGenerator};
  7. use flowy_error::FlowyResult;
  8. use flowy_grid_data_model::revision::{
  9. CheckboxGroupConfigurationRevision, FieldRevision, GroupRecordRevision, RowChangeset, RowRevision,
  10. };
  11. pub type CheckboxGroupController = GenericGroupController<
  12. CheckboxGroupConfigurationRevision,
  13. CheckboxTypeOptionPB,
  14. CheckboxGroupGenerator,
  15. CheckboxCellDataParser,
  16. >;
  17. pub type CheckboxGroupConfiguration = GenericGroupConfiguration<CheckboxGroupConfigurationRevision>;
  18. impl GroupConfigurationAction for CheckboxGroupConfiguration {
  19. fn group_records(&self) -> &[GroupRecordRevision] {
  20. &[]
  21. }
  22. fn merge_groups(&self, groups: Vec<Group>) -> FlowyResult<()> {
  23. Ok(())
  24. }
  25. fn hide_group(&self, group_id: &str) -> FlowyResult<()> {
  26. Ok(())
  27. }
  28. fn show_group(&self, group_id: &str) -> FlowyResult<()> {
  29. Ok(())
  30. }
  31. }
  32. impl GroupAction for CheckboxGroupController {
  33. type CellDataType = CheckboxCellData;
  34. fn can_group(&self, _content: &str, _cell_data: &Self::CellDataType) -> bool {
  35. false
  36. }
  37. fn add_row_if_match(
  38. &mut self,
  39. _row_rev: &RowRevision,
  40. _cell_data: &Self::CellDataType,
  41. ) -> Vec<GroupRowsChangesetPB> {
  42. todo!()
  43. }
  44. fn remove_row_if_match(
  45. &mut self,
  46. _row_rev: &RowRevision,
  47. _cell_data: &Self::CellDataType,
  48. ) -> Vec<GroupRowsChangesetPB> {
  49. todo!()
  50. }
  51. fn move_row_if_match(
  52. &mut self,
  53. _field_rev: &FieldRevision,
  54. _row_rev: &RowRevision,
  55. _row_changeset: &mut RowChangeset,
  56. _cell_data: &Self::CellDataType,
  57. _to_row_id: &str,
  58. ) -> Vec<GroupRowsChangesetPB> {
  59. todo!()
  60. }
  61. }
  62. impl GroupController for CheckboxGroupController {
  63. fn will_create_row(&mut self, _row_rev: &mut RowRevision, _field_rev: &FieldRevision, _group_id: &str) {
  64. todo!()
  65. }
  66. }
  67. pub struct CheckboxGroupGenerator();
  68. impl GroupGenerator for CheckboxGroupGenerator {
  69. type ConfigurationType = CheckboxGroupConfiguration;
  70. type TypeOptionType = CheckboxTypeOptionPB;
  71. fn generate_groups(
  72. field_id: &str,
  73. configuration: &Self::ConfigurationType,
  74. type_option: &Option<Self::TypeOptionType>,
  75. ) -> Vec<Group> {
  76. let check_group = Group::new(
  77. "true".to_string(),
  78. field_id.to_owned(),
  79. "".to_string(),
  80. CHECK.to_string(),
  81. );
  82. let uncheck_group = Group::new(
  83. "false".to_string(),
  84. field_id.to_owned(),
  85. "".to_string(),
  86. UNCHECK.to_string(),
  87. );
  88. vec![check_group, uncheck_group]
  89. }
  90. }