|
@@ -1,12 +1,14 @@
|
|
use crate::services::block_manager::GridBlockManager;
|
|
use crate::services::block_manager::GridBlockManager;
|
|
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
|
use crate::services::grid_editor_task::GridServiceTaskScheduler;
|
|
use crate::services::group::{
|
|
use crate::services::group::{
|
|
- CheckboxGroupController, Group, GroupCellContentProvider, MultiSelectGroupController, SingleSelectGroupController,
|
|
|
|
|
|
+ CheckboxGroupController, Group, GroupActionHandler, GroupCellContentProvider, MultiSelectGroupController,
|
|
|
|
+ SingleSelectGroupController,
|
|
};
|
|
};
|
|
|
|
|
|
use crate::entities::{
|
|
use crate::entities::{
|
|
- CheckboxGroupConfigurationPB, DateGroupConfigurationPB, FieldType, GroupPB, NumberGroupConfigurationPB,
|
|
|
|
- SelectOptionGroupConfigurationPB, TextGroupConfigurationPB, UrlGroupConfigurationPB,
|
|
|
|
|
|
+ CheckboxGroupConfigurationPB, CreateBoardCardParams, DateGroupConfigurationPB, FieldType, GroupPB,
|
|
|
|
+ NumberGroupConfigurationPB, RowPB, SelectOptionGroupConfigurationPB, TextGroupConfigurationPB,
|
|
|
|
+ UrlGroupConfigurationPB,
|
|
};
|
|
};
|
|
use bytes::Bytes;
|
|
use bytes::Bytes;
|
|
use flowy_error::FlowyResult;
|
|
use flowy_error::FlowyResult;
|
|
@@ -18,10 +20,9 @@ use tokio::sync::RwLock;
|
|
pub(crate) struct GridGroupService {
|
|
pub(crate) struct GridGroupService {
|
|
#[allow(dead_code)]
|
|
#[allow(dead_code)]
|
|
scheduler: Arc<dyn GridServiceTaskScheduler>,
|
|
scheduler: Arc<dyn GridServiceTaskScheduler>,
|
|
- #[allow(dead_code)]
|
|
|
|
grid_pad: Arc<RwLock<GridRevisionPad>>,
|
|
grid_pad: Arc<RwLock<GridRevisionPad>>,
|
|
- #[allow(dead_code)]
|
|
|
|
block_manager: Arc<GridBlockManager>,
|
|
block_manager: Arc<GridBlockManager>,
|
|
|
|
+ group_action_handler: Option<Arc<RwLock<dyn GroupActionHandler>>>,
|
|
}
|
|
}
|
|
|
|
|
|
impl GridGroupService {
|
|
impl GridGroupService {
|
|
@@ -35,14 +36,14 @@ impl GridGroupService {
|
|
scheduler,
|
|
scheduler,
|
|
grid_pad,
|
|
grid_pad,
|
|
block_manager,
|
|
block_manager,
|
|
|
|
+ group_action_handler: None,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- pub(crate) async fn load_groups(&self) -> Option<Vec<GroupPB>> {
|
|
|
|
- let grid_pad = self.grid_pad.read().await;
|
|
|
|
- let field_rev = find_group_field(grid_pad.fields()).unwrap();
|
|
|
|
|
|
+ pub(crate) async fn load_groups(&mut self) -> Option<Vec<GroupPB>> {
|
|
|
|
+ let field_rev = find_group_field(self.grid_pad.read().await.fields()).unwrap();
|
|
let field_type: FieldType = field_rev.field_type_rev.into();
|
|
let field_type: FieldType = field_rev.field_type_rev.into();
|
|
- let configuration = self.get_group_configuration(field_rev).await;
|
|
|
|
|
|
+ let configuration = self.get_group_configuration(&field_rev).await;
|
|
|
|
|
|
let blocks = self.block_manager.get_block_snapshots(None).await.unwrap();
|
|
let blocks = self.block_manager.get_block_snapshots(None).await.unwrap();
|
|
let row_revs = blocks
|
|
let row_revs = blocks
|
|
@@ -51,19 +52,28 @@ impl GridGroupService {
|
|
.flatten()
|
|
.flatten()
|
|
.collect::<Vec<Arc<RowRevision>>>();
|
|
.collect::<Vec<Arc<RowRevision>>>();
|
|
|
|
|
|
- match self.build_groups(&field_type, field_rev, row_revs, configuration) {
|
|
|
|
|
|
+ match self
|
|
|
|
+ .build_groups(&field_type, &field_rev, row_revs, configuration)
|
|
|
|
+ .await
|
|
|
|
+ {
|
|
Ok(groups) => Some(groups),
|
|
Ok(groups) => Some(groups),
|
|
Err(_) => None,
|
|
Err(_) => None,
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- async fn get_group_configuration(&self, field_rev: &FieldRevision) -> GroupConfigurationRevision {
|
|
|
|
|
|
+ pub(crate) async fn create_board_card(&self, row_rev: &mut RowRevision) {
|
|
|
|
+ if let Some(group_action_handler) = self.group_action_handler.as_ref() {
|
|
|
|
+ group_action_handler.write().await.create_card(row_rev);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ pub(crate) async fn get_group_configuration(&self, field_rev: &FieldRevision) -> GroupConfigurationRevision {
|
|
let grid_pad = self.grid_pad.read().await;
|
|
let grid_pad = self.grid_pad.read().await;
|
|
let setting = grid_pad.get_setting_rev();
|
|
let setting = grid_pad.get_setting_rev();
|
|
let layout = &setting.layout;
|
|
let layout = &setting.layout;
|
|
let configurations = setting.get_groups(layout, &field_rev.id, &field_rev.field_type_rev);
|
|
let configurations = setting.get_groups(layout, &field_rev.id, &field_rev.field_type_rev);
|
|
match configurations {
|
|
match configurations {
|
|
- None => self.default_group_configuration(field_rev),
|
|
|
|
|
|
+ None => default_group_configuration(field_rev),
|
|
Some(mut configurations) => {
|
|
Some(mut configurations) => {
|
|
assert_eq!(configurations.len(), 1);
|
|
assert_eq!(configurations.len(), 1);
|
|
(&*configurations.pop().unwrap()).clone()
|
|
(&*configurations.pop().unwrap()).clone()
|
|
@@ -71,79 +81,81 @@ impl GridGroupService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fn default_group_configuration(&self, field_rev: &FieldRevision) -> GroupConfigurationRevision {
|
|
|
|
- let field_type: FieldType = field_rev.field_type_rev.clone().into();
|
|
|
|
- let bytes: Bytes = match field_type {
|
|
|
|
- FieldType::RichText => TextGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
- FieldType::Number => NumberGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
- FieldType::DateTime => DateGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
- FieldType::SingleSelect => SelectOptionGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
- FieldType::MultiSelect => SelectOptionGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
- FieldType::Checkbox => CheckboxGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
- FieldType::URL => UrlGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
- };
|
|
|
|
- GroupConfigurationRevision {
|
|
|
|
- id: gen_grid_group_id(),
|
|
|
|
- field_id: field_rev.id.clone(),
|
|
|
|
- field_type_rev: field_rev.field_type_rev.clone(),
|
|
|
|
- content: Some(bytes.to_vec()),
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
|
- fn build_groups(
|
|
|
|
- &self,
|
|
|
|
|
|
+ async fn build_groups(
|
|
|
|
+ &mut self,
|
|
field_type: &FieldType,
|
|
field_type: &FieldType,
|
|
field_rev: &Arc<FieldRevision>,
|
|
field_rev: &Arc<FieldRevision>,
|
|
row_revs: Vec<Arc<RowRevision>>,
|
|
row_revs: Vec<Arc<RowRevision>>,
|
|
configuration: GroupConfigurationRevision,
|
|
configuration: GroupConfigurationRevision,
|
|
) -> FlowyResult<Vec<GroupPB>> {
|
|
) -> FlowyResult<Vec<GroupPB>> {
|
|
- let groups: Vec<Group> = match field_type {
|
|
|
|
|
|
+ match field_type {
|
|
FieldType::RichText => {
|
|
FieldType::RichText => {
|
|
// let generator = GroupGenerator::<TextGroupConfigurationPB>::from_configuration(configuration);
|
|
// let generator = GroupGenerator::<TextGroupConfigurationPB>::from_configuration(configuration);
|
|
- vec![]
|
|
|
|
}
|
|
}
|
|
FieldType::Number => {
|
|
FieldType::Number => {
|
|
// let generator = GroupGenerator::<NumberGroupConfigurationPB>::from_configuration(configuration);
|
|
// let generator = GroupGenerator::<NumberGroupConfigurationPB>::from_configuration(configuration);
|
|
- vec![]
|
|
|
|
}
|
|
}
|
|
FieldType::DateTime => {
|
|
FieldType::DateTime => {
|
|
// let generator = GroupGenerator::<DateGroupConfigurationPB>::from_configuration(configuration);
|
|
// let generator = GroupGenerator::<DateGroupConfigurationPB>::from_configuration(configuration);
|
|
- vec![]
|
|
|
|
}
|
|
}
|
|
FieldType::SingleSelect => {
|
|
FieldType::SingleSelect => {
|
|
- let mut group_controller =
|
|
|
|
- SingleSelectGroupController::new(field_rev.clone(), configuration, &self.grid_pad)?;
|
|
|
|
- let _ = group_controller.group_rows(&row_revs)?;
|
|
|
|
- group_controller.take_groups()
|
|
|
|
|
|
+ let controller = SingleSelectGroupController::new(field_rev.clone(), configuration, &self.grid_pad)?;
|
|
|
|
+ self.group_action_handler = Some(Arc::new(RwLock::new(controller)));
|
|
}
|
|
}
|
|
FieldType::MultiSelect => {
|
|
FieldType::MultiSelect => {
|
|
- let mut group_controller =
|
|
|
|
- MultiSelectGroupController::new(field_rev.clone(), configuration, &self.grid_pad)?;
|
|
|
|
- let _ = group_controller.group_rows(&row_revs)?;
|
|
|
|
- group_controller.take_groups()
|
|
|
|
|
|
+ let controller = MultiSelectGroupController::new(field_rev.clone(), configuration, &self.grid_pad)?;
|
|
|
|
+ self.group_action_handler = Some(Arc::new(RwLock::new(controller)));
|
|
}
|
|
}
|
|
FieldType::Checkbox => {
|
|
FieldType::Checkbox => {
|
|
- let mut group_controller =
|
|
|
|
- CheckboxGroupController::new(field_rev.clone(), configuration, &self.grid_pad)?;
|
|
|
|
- let _ = group_controller.group_rows(&row_revs)?;
|
|
|
|
- group_controller.take_groups()
|
|
|
|
|
|
+ let controller = CheckboxGroupController::new(field_rev.clone(), configuration, &self.grid_pad)?;
|
|
|
|
+ self.group_action_handler = Some(Arc::new(RwLock::new(controller)));
|
|
}
|
|
}
|
|
FieldType::URL => {
|
|
FieldType::URL => {
|
|
// let generator = GroupGenerator::<UrlGroupConfigurationPB>::from_configuration(configuration);
|
|
// let generator = GroupGenerator::<UrlGroupConfigurationPB>::from_configuration(configuration);
|
|
- vec![]
|
|
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ let mut groups = vec![];
|
|
|
|
+ if let Some(group_action_handler) = self.group_action_handler.as_ref() {
|
|
|
|
+ let mut write_guard = group_action_handler.write().await;
|
|
|
|
+ let _ = write_guard.group_rows(&row_revs)?;
|
|
|
|
+ groups = write_guard.get_groups();
|
|
|
|
+ drop(write_guard);
|
|
|
|
+ }
|
|
|
|
+
|
|
Ok(groups.into_iter().map(GroupPB::from).collect())
|
|
Ok(groups.into_iter().map(GroupPB::from).collect())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-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()
|
|
|
|
- })
|
|
|
|
|
|
+fn find_group_field(field_revs: &[Arc<FieldRevision>]) -> Option<Arc<FieldRevision>> {
|
|
|
|
+ let field_rev = field_revs
|
|
|
|
+ .iter()
|
|
|
|
+ .find(|field_rev| {
|
|
|
|
+ let field_type: FieldType = field_rev.field_type_rev.into();
|
|
|
|
+ field_type.can_be_group()
|
|
|
|
+ })
|
|
|
|
+ .cloned();
|
|
|
|
+ field_rev
|
|
}
|
|
}
|
|
|
|
|
|
impl GroupCellContentProvider for Arc<RwLock<GridRevisionPad>> {}
|
|
impl GroupCellContentProvider for Arc<RwLock<GridRevisionPad>> {}
|
|
|
|
+
|
|
|
|
+fn default_group_configuration(field_rev: &FieldRevision) -> GroupConfigurationRevision {
|
|
|
|
+ let field_type: FieldType = field_rev.field_type_rev.clone().into();
|
|
|
|
+ let bytes: Bytes = match field_type {
|
|
|
|
+ FieldType::RichText => TextGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
+ FieldType::Number => NumberGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
+ FieldType::DateTime => DateGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
+ FieldType::SingleSelect => SelectOptionGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
+ FieldType::MultiSelect => SelectOptionGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
+ FieldType::Checkbox => CheckboxGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
+ FieldType::URL => UrlGroupConfigurationPB::default().try_into().unwrap(),
|
|
|
|
+ };
|
|
|
|
+ GroupConfigurationRevision {
|
|
|
|
+ id: gen_grid_group_id(),
|
|
|
|
+ field_id: field_rev.id.clone(),
|
|
|
|
+ field_type_rev: field_rev.field_type_rev.clone(),
|
|
|
|
+ content: Some(bytes.to_vec()),
|
|
|
|
+ }
|
|
|
|
+}
|