|
@@ -4,7 +4,9 @@ use crate::entities::{
|
|
|
};
|
|
|
use crate::services::block_manager::GridBlockManager;
|
|
|
use crate::services::cell::{decode_any_cell_data, CellBytes};
|
|
|
+use crate::services::field::TextCellDataParser;
|
|
|
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
|
|
+use crate::services::group::{GroupAction, GroupCellContentProvider, SingleSelectGroupController};
|
|
|
use bytes::Bytes;
|
|
|
use flowy_error::FlowyResult;
|
|
|
use flowy_grid_data_model::revision::{CellRevision, FieldRevision, GroupConfigurationRevision, RowRevision};
|
|
@@ -56,94 +58,42 @@ impl GridGroupService {
|
|
|
.flatten()
|
|
|
.collect::<Vec<Arc<RowRevision>>>();
|
|
|
|
|
|
+ // let a = SingleSelectGroupController::new;
|
|
|
+ // let b = a(field_rev.clone(), configuration, &self.grid_pad);
|
|
|
+
|
|
|
let groups = match field_type {
|
|
|
FieldType::RichText => {
|
|
|
- let generator = GroupGenerator::<TextGroupConfigurationPB>::from_configuration(configuration);
|
|
|
+ // let generator = GroupGenerator::<TextGroupConfigurationPB>::from_configuration(configuration);
|
|
|
}
|
|
|
FieldType::Number => {
|
|
|
- let generator = GroupGenerator::<NumberGroupConfigurationPB>::from_configuration(configuration);
|
|
|
+ // let generator = GroupGenerator::<NumberGroupConfigurationPB>::from_configuration(configuration);
|
|
|
}
|
|
|
FieldType::DateTime => {
|
|
|
- let generator = GroupGenerator::<DateGroupConfigurationPB>::from_configuration(configuration);
|
|
|
+ // let generator = GroupGenerator::<DateGroupConfigurationPB>::from_configuration(configuration);
|
|
|
}
|
|
|
FieldType::SingleSelect => {
|
|
|
- let generator = GroupGenerator::<SelectOptionGroupConfigurationPB>::from_configuration(configuration);
|
|
|
+ let group_controller =
|
|
|
+ SingleSelectGroupController::new(field_rev.clone(), configuration, &self.grid_pad);
|
|
|
}
|
|
|
FieldType::MultiSelect => {
|
|
|
- let generator = GroupGenerator::<SelectOptionGroupConfigurationPB>::from_configuration(configuration);
|
|
|
+ // let group_generator = MultiSelectGroupControllern(configuration);
|
|
|
}
|
|
|
FieldType::Checkbox => {
|
|
|
- let generator = GroupGenerator::<CheckboxGroupConfigurationPB>::from_configuration(configuration);
|
|
|
+ // let generator = GroupGenerator::<CheckboxGroupConfigurationPB>::from_configuration(configuration);
|
|
|
}
|
|
|
FieldType::URL => {
|
|
|
- let generator = GroupGenerator::<UrlGroupConfigurationPB>::from_configuration(configuration);
|
|
|
+ // let generator = GroupGenerator::<UrlGroupConfigurationPB>::from_configuration(configuration);
|
|
|
}
|
|
|
};
|
|
|
None
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-pub struct GroupGenerator<T> {
|
|
|
- field_id: String,
|
|
|
- groups: Vec<Group>,
|
|
|
- configuration: Option<T>,
|
|
|
-}
|
|
|
-
|
|
|
-pub struct Group {
|
|
|
- row_ids: Vec<String>,
|
|
|
- content: String,
|
|
|
-}
|
|
|
-
|
|
|
-impl<T> GroupGenerator<T>
|
|
|
-where
|
|
|
- T: TryFrom<Bytes, Error = protobuf::ProtobufError>,
|
|
|
-{
|
|
|
- pub fn from_configuration(configuration: GroupConfigurationRevision) -> FlowyResult<Self> {
|
|
|
- let bytes = Bytes::from(configuration.content.unwrap_or(vec![]));
|
|
|
- Self::from_bytes(&configuration.field_id, bytes)
|
|
|
- }
|
|
|
-
|
|
|
- pub fn from_bytes(field_id: &str, bytes: Bytes) -> FlowyResult<Self> {
|
|
|
- let configuration = if bytes.is_empty() {
|
|
|
- None
|
|
|
- } else {
|
|
|
- Some(T::try_from(bytes)?)
|
|
|
- };
|
|
|
- Ok(Self {
|
|
|
- field_id: field_id.to_owned(),
|
|
|
- groups: vec![],
|
|
|
- configuration,
|
|
|
- })
|
|
|
- }
|
|
|
-}
|
|
|
-pub trait GroupConfiguration {
|
|
|
- fn should_group(&self, content: &str, cell_bytes: CellBytes) -> bool;
|
|
|
-}
|
|
|
-
|
|
|
-impl<T> GroupGenerator<T>
|
|
|
-where
|
|
|
- T: GroupConfiguration,
|
|
|
-{
|
|
|
- pub fn group_row(&mut self, field_rev: &Arc<FieldRevision>, row: &RowRevision) {
|
|
|
- if self.configuration.is_none() {
|
|
|
- return;
|
|
|
- }
|
|
|
- let configuration = self.configuration.as_ref().unwrap();
|
|
|
- if let Some(cell_rev) = row.cells.get(&self.field_id) {
|
|
|
- for group in self.groups.iter_mut() {
|
|
|
- let cell_rev: CellRevision = cell_rev.clone();
|
|
|
- let cell_bytes = decode_any_cell_data(cell_rev.data, field_rev);
|
|
|
- if configuration.should_group(&group.content, cell_bytes) {
|
|
|
- group.row_ids.push(row.id.clone());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
fn find_group_field(field_revs: &[Arc<FieldRevision>]) -> Option<&Arc<FieldRevision>> {
|
|
|
field_revs.iter().find(|field_rev| {
|
|
|
let field_type: FieldType = field_rev.field_type_rev.into();
|
|
|
field_type.can_be_group()
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+impl GroupCellContentProvider for Arc<RwLock<GridRevisionPad>> {}
|