2022-05-22 05:08:38 +00:00
|
|
|
use crate::entities::*;
|
2022-03-04 14:09:16 +00:00
|
|
|
use crate::manager::GridManager;
|
2022-12-26 12:28:18 +00:00
|
|
|
use crate::services::cell::{FromCellString, ToCellChangesetString, TypeCellData};
|
2022-07-07 10:20:12 +00:00
|
|
|
use crate::services::field::{
|
2022-10-12 13:52:02 +00:00
|
|
|
default_type_option_builder_from_type, select_type_option_from_field_rev, type_option_builder_from_json_str,
|
2022-11-14 04:03:22 +00:00
|
|
|
DateCellChangeset, DateChangesetPB, SelectOptionCellChangeset, SelectOptionCellChangesetPB,
|
2022-11-14 01:59:23 +00:00
|
|
|
SelectOptionCellChangesetParams, SelectOptionCellDataPB, SelectOptionChangeset, SelectOptionChangesetPB,
|
2022-12-17 02:15:13 +00:00
|
|
|
SelectOptionIds, SelectOptionPB,
|
2022-07-07 10:20:12 +00:00
|
|
|
};
|
2022-12-11 03:35:42 +00:00
|
|
|
use crate::services::row::make_row_from_row_rev;
|
2022-04-07 00:33:10 +00:00
|
|
|
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
2022-11-08 05:51:12 +00:00
|
|
|
use grid_rev_model::FieldRevision;
|
2022-12-01 00:35:50 +00:00
|
|
|
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
|
2022-03-02 14:43:04 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-06-24 10:13:40 +00:00
|
|
|
pub(crate) async fn get_grid_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<GridIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-07-17 05:38:53 +00:00
|
|
|
) -> DataResult<GridPB, FlowyError> {
|
|
|
|
let grid_id: GridIdPB = data.into_inner();
|
2022-12-12 02:44:34 +00:00
|
|
|
let editor = manager.open_grid(grid_id.as_ref()).await?;
|
|
|
|
let grid = editor.get_grid(grid_id.as_ref()).await?;
|
2022-03-05 02:59:44 +00:00
|
|
|
data_result(grid)
|
2022-03-03 14:17:07 +00:00
|
|
|
}
|
|
|
|
|
2022-06-19 13:10:07 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn get_grid_setting_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<GridIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-07-17 05:38:53 +00:00
|
|
|
) -> DataResult<GridSettingPB, FlowyError> {
|
|
|
|
let grid_id: GridIdPB = data.into_inner();
|
2022-06-19 13:10:07 +00:00
|
|
|
let editor = manager.open_grid(grid_id).await?;
|
2022-11-13 14:23:57 +00:00
|
|
|
let grid_setting = editor.get_setting().await?;
|
2022-06-22 09:11:56 +00:00
|
|
|
data_result(grid_setting)
|
2022-06-19 13:10:07 +00:00
|
|
|
}
|
|
|
|
|
2022-09-04 07:33:07 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn update_grid_setting_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<GridSettingChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-09-04 07:33:07 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
|
|
|
let params: GridSettingChangesetParams = data.into_inner().try_into()?;
|
|
|
|
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-09-04 07:33:07 +00:00
|
|
|
if let Some(insert_params) = params.insert_group {
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.insert_group(insert_params).await?;
|
2022-09-04 07:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(delete_params) = params.delete_group {
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.delete_group(delete_params).await?;
|
2022-09-04 07:33:07 +00:00
|
|
|
}
|
|
|
|
|
2022-11-26 13:28:08 +00:00
|
|
|
if let Some(alter_filter) = params.insert_filter {
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.create_or_update_filter(alter_filter).await?;
|
2022-09-04 07:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(delete_filter) = params.delete_filter {
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.delete_filter(delete_filter).await?;
|
2022-09-04 07:33:07 +00:00
|
|
|
}
|
2022-12-12 02:52:14 +00:00
|
|
|
|
|
|
|
if let Some(alter_sort) = params.alert_sort {
|
|
|
|
let _ = editor.create_or_update_sort(alter_sort).await?;
|
|
|
|
}
|
|
|
|
if let Some(delete_sort) = params.delete_sort {
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.delete_sort(delete_sort).await?;
|
2022-12-12 02:52:14 +00:00
|
|
|
}
|
2022-09-04 07:33:07 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-11-15 15:17:01 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn get_all_filters_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<GridIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-11-15 15:17:01 +00:00
|
|
|
) -> DataResult<RepeatedFilterPB, FlowyError> {
|
|
|
|
let grid_id: GridIdPB = data.into_inner();
|
|
|
|
let editor = manager.open_grid(grid_id).await?;
|
|
|
|
let filters = RepeatedFilterPB {
|
|
|
|
items: editor.get_all_filters().await?,
|
|
|
|
};
|
|
|
|
data_result(filters)
|
|
|
|
}
|
|
|
|
|
2023-01-11 09:48:53 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn get_all_sorts_handler(
|
|
|
|
data: AFPluginData<GridIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
|
|
|
) -> DataResult<RepeatedSortPB, FlowyError> {
|
|
|
|
let grid_id: GridIdPB = data.into_inner();
|
|
|
|
let editor = manager.open_grid(grid_id.as_ref()).await?;
|
|
|
|
let sorts = RepeatedSortPB {
|
|
|
|
items: editor.get_all_sorts(grid_id.as_ref()).await?,
|
|
|
|
};
|
|
|
|
data_result(sorts)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn delete_all_sorts_handler(
|
|
|
|
data: AFPluginData<GridIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
|
|
|
) -> Result<(), FlowyError> {
|
|
|
|
let grid_id: GridIdPB = data.into_inner();
|
|
|
|
let editor = manager.open_grid(grid_id.as_ref()).await?;
|
2023-01-17 08:27:17 +00:00
|
|
|
editor.delete_all_sorts(grid_id.as_ref()).await?;
|
2023-01-11 09:48:53 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-03-23 14:10:31 +00:00
|
|
|
pub(crate) async fn get_fields_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<GetFieldPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-08-11 05:25:55 +00:00
|
|
|
) -> DataResult<RepeatedFieldPB, FlowyError> {
|
2022-11-14 01:59:23 +00:00
|
|
|
let params: GetFieldParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-11-26 13:28:08 +00:00
|
|
|
let field_revs = editor.get_field_revs(params.field_ids).await?;
|
2022-08-11 05:25:55 +00:00
|
|
|
let repeated_field: RepeatedFieldPB = field_revs.into_iter().map(FieldPB::from).collect::<Vec<_>>().into();
|
2022-03-23 14:10:31 +00:00
|
|
|
data_result(repeated_field)
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-03-23 14:10:31 +00:00
|
|
|
pub(crate) async fn update_field_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<FieldChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-03-23 14:10:31 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-03-27 01:35:10 +00:00
|
|
|
let changeset: FieldChangesetParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(&changeset.grid_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.update_field(changeset).await?;
|
2022-03-23 14:10:31 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-05-10 01:33:34 +00:00
|
|
|
pub(crate) async fn update_field_type_option_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<TypeOptionChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-05-10 01:33:34 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-11-14 01:59:23 +00:00
|
|
|
let params: TypeOptionChangesetParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-11-26 13:28:08 +00:00
|
|
|
let old_field_rev = editor.get_field_rev(¶ms.field_id).await;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor
|
2022-11-29 05:34:10 +00:00
|
|
|
.update_field_type_option(
|
2022-11-26 13:28:08 +00:00
|
|
|
¶ms.grid_id,
|
|
|
|
¶ms.field_id,
|
|
|
|
params.type_option_data,
|
|
|
|
old_field_rev,
|
|
|
|
)
|
2022-05-10 01:33:34 +00:00
|
|
|
.await?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-03-27 01:35:10 +00:00
|
|
|
pub(crate) async fn delete_field_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<DeleteFieldPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-03-27 01:35:10 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-08-11 05:25:55 +00:00
|
|
|
let params: FieldIdParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.delete_field(¶ms.field_id).await?;
|
2022-03-27 03:14:21 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-04-01 01:31:10 +00:00
|
|
|
pub(crate) async fn switch_to_field_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<EditFieldChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-10-10 12:02:52 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-04-01 01:31:10 +00:00
|
|
|
let params: EditFieldParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-11-26 13:28:08 +00:00
|
|
|
let old_field_rev = editor.get_field_rev(¶ms.field_id).await;
|
2022-05-19 02:41:00 +00:00
|
|
|
editor
|
|
|
|
.switch_to_field_type(¶ms.field_id, ¶ms.field_type)
|
|
|
|
.await?;
|
|
|
|
|
2022-10-26 14:36:34 +00:00
|
|
|
// Get the field_rev with field_id, if it doesn't exist, we create the default FieldRevision from the FieldType.
|
2022-11-26 13:28:08 +00:00
|
|
|
let new_field_rev = editor
|
2022-06-15 07:13:50 +00:00
|
|
|
.get_field_rev(¶ms.field_id)
|
2022-05-19 02:41:00 +00:00
|
|
|
.await
|
2022-07-01 02:36:07 +00:00
|
|
|
.unwrap_or(Arc::new(editor.next_field_rev(¶ms.field_type).await?));
|
2022-05-19 02:41:00 +00:00
|
|
|
|
2022-10-11 13:51:02 +00:00
|
|
|
// Update the type-option data after the field type has been changed
|
2022-11-26 13:28:08 +00:00
|
|
|
let type_option_data = get_type_option_data(&new_field_rev, ¶ms.field_type).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor
|
2022-11-29 05:34:10 +00:00
|
|
|
.update_field_type_option(¶ms.grid_id, &new_field_rev.id, type_option_data, old_field_rev)
|
2022-10-10 12:02:52 +00:00
|
|
|
.await?;
|
2022-05-19 02:41:00 +00:00
|
|
|
|
2022-10-10 12:02:52 +00:00
|
|
|
Ok(())
|
2022-04-01 01:31:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-03-27 03:14:21 +00:00
|
|
|
pub(crate) async fn duplicate_field_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<DuplicateFieldPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-03-27 03:14:21 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-08-11 05:25:55 +00:00
|
|
|
let params: FieldIdParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.duplicate_field(¶ms.field_id).await?;
|
2022-03-27 01:35:10 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-05-19 02:41:00 +00:00
|
|
|
/// Return the FieldTypeOptionData if the Field exists otherwise return record not found error.
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-05-09 05:23:03 +00:00
|
|
|
pub(crate) async fn get_field_type_option_data_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<TypeOptionPathPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-11-14 01:59:23 +00:00
|
|
|
) -> DataResult<TypeOptionPB, FlowyError> {
|
|
|
|
let params: TypeOptionPathParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-06-15 07:13:50 +00:00
|
|
|
match editor.get_field_rev(¶ms.field_id).await {
|
2022-05-19 02:41:00 +00:00
|
|
|
None => Err(FlowyError::record_not_found()),
|
2022-06-15 07:13:50 +00:00
|
|
|
Some(field_rev) => {
|
2022-08-19 03:56:47 +00:00
|
|
|
let field_type = field_rev.ty.into();
|
2022-07-01 12:32:11 +00:00
|
|
|
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
2022-11-14 01:59:23 +00:00
|
|
|
let data = TypeOptionPB {
|
2022-05-19 02:41:00 +00:00
|
|
|
grid_id: params.grid_id,
|
2022-06-15 07:13:50 +00:00
|
|
|
field: field_rev.into(),
|
2022-05-19 02:41:00 +00:00
|
|
|
type_option_data,
|
|
|
|
};
|
|
|
|
data_result(data)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create FieldMeta and save it. Return the FieldTypeOptionData.
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-05-19 02:41:00 +00:00
|
|
|
pub(crate) async fn create_field_type_option_data_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<CreateFieldPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-11-14 01:59:23 +00:00
|
|
|
) -> DataResult<TypeOptionPB, FlowyError> {
|
2022-05-19 02:41:00 +00:00
|
|
|
let params: CreateFieldParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-10-10 13:21:29 +00:00
|
|
|
let field_rev = editor
|
2022-12-09 01:19:47 +00:00
|
|
|
.create_new_field_rev_with_type_option(¶ms.field_type, params.type_option_data)
|
2022-10-10 13:21:29 +00:00
|
|
|
.await?;
|
2022-08-19 03:56:47 +00:00
|
|
|
let field_type: FieldType = field_rev.ty.into();
|
2022-07-01 12:32:11 +00:00
|
|
|
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
2022-05-09 05:23:03 +00:00
|
|
|
|
2022-11-14 01:59:23 +00:00
|
|
|
data_result(TypeOptionPB {
|
2022-05-17 08:57:37 +00:00
|
|
|
grid_id: params.grid_id,
|
2022-06-15 07:13:50 +00:00
|
|
|
field: field_rev.into(),
|
2022-05-09 05:23:03 +00:00
|
|
|
type_option_data,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-08-16 07:49:54 +00:00
|
|
|
pub(crate) async fn move_field_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<MoveFieldPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-04-13 06:24:54 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-08-16 07:49:54 +00:00
|
|
|
let params: MoveFieldParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.move_field(params).await?;
|
2022-04-13 06:24:54 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-10-10 12:02:52 +00:00
|
|
|
/// The [FieldRevision] contains multiple data, each of them belongs to a specific FieldType.
|
2022-06-15 07:13:50 +00:00
|
|
|
async fn get_type_option_data(field_rev: &FieldRevision, field_type: &FieldType) -> FlowyResult<Vec<u8>> {
|
2022-12-31 00:06:10 +00:00
|
|
|
let s = field_rev
|
|
|
|
.get_type_option_str(field_type)
|
|
|
|
.map(|value| value.to_owned())
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
default_type_option_builder_from_type(field_type)
|
|
|
|
.serializer()
|
|
|
|
.json_str()
|
|
|
|
});
|
2022-08-19 03:56:47 +00:00
|
|
|
let field_type: FieldType = field_rev.ty.into();
|
2022-07-01 12:32:11 +00:00
|
|
|
let builder = type_option_builder_from_json_str(&s, &field_type);
|
2022-10-11 13:51:02 +00:00
|
|
|
let type_option_data = builder.serializer().protobuf_bytes().to_vec();
|
2022-05-09 05:23:03 +00:00
|
|
|
|
|
|
|
Ok(type_option_data)
|
|
|
|
}
|
|
|
|
|
2022-08-18 09:40:23 +00:00
|
|
|
// #[tracing::instrument(level = "debug", skip(data, manager), err)]
|
2022-03-18 09:14:46 +00:00
|
|
|
pub(crate) async fn get_row_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<RowIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-07-17 05:38:53 +00:00
|
|
|
) -> DataResult<OptionalRowPB, FlowyError> {
|
2022-08-11 05:25:55 +00:00
|
|
|
let params: RowIdParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-08-14 07:15:56 +00:00
|
|
|
let row = editor.get_row_rev(¶ms.row_id).await?.map(make_row_from_row_rev);
|
2022-07-12 07:49:14 +00:00
|
|
|
|
2022-07-17 05:38:53 +00:00
|
|
|
data_result(OptionalRowPB { row })
|
2022-03-18 09:14:46 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 03:28:24 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
2022-04-09 14:07:48 +00:00
|
|
|
pub(crate) async fn delete_row_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<RowIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-04-09 14:42:42 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-08-11 05:25:55 +00:00
|
|
|
let params: RowIdParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.delete_row(¶ms.row_id).await?;
|
2022-04-09 14:42:42 +00:00
|
|
|
Ok(())
|
2022-04-09 14:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn duplicate_row_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<RowIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-04-09 14:42:42 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-08-11 05:25:55 +00:00
|
|
|
let params: RowIdParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.duplicate_row(¶ms.row_id).await?;
|
2022-04-09 14:42:42 +00:00
|
|
|
Ok(())
|
2022-04-09 14:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
2022-08-16 07:49:54 +00:00
|
|
|
pub(crate) async fn move_row_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<MoveRowPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-08-16 07:49:54 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
|
|
|
let params: MoveRowParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.view_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.move_row(params).await?;
|
2022-08-16 07:49:54 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn create_table_row_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<CreateTableRowPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-08-13 08:23:44 +00:00
|
|
|
) -> DataResult<RowPB, FlowyError> {
|
2022-03-18 09:14:46 +00:00
|
|
|
let params: CreateRowParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(params.grid_id.as_ref()).await?;
|
2022-08-15 12:07:01 +00:00
|
|
|
let row = editor.create_row(params).await?;
|
2022-08-13 08:23:44 +00:00
|
|
|
data_result(row)
|
2022-03-02 14:43:04 +00:00
|
|
|
}
|
2022-03-09 08:11:24 +00:00
|
|
|
|
2022-08-25 04:36:56 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
2022-04-07 12:15:00 +00:00
|
|
|
pub(crate) async fn get_cell_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<CellPathPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-11-14 01:59:23 +00:00
|
|
|
) -> DataResult<CellPB, FlowyError> {
|
|
|
|
let params: CellPathParams = data.into_inner().try_into()?;
|
2022-12-20 00:39:46 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.view_id).await?;
|
2022-04-07 12:15:00 +00:00
|
|
|
match editor.get_cell(¶ms).await {
|
2023-01-05 13:27:21 +00:00
|
|
|
None => data_result(CellPB::empty(¶ms.field_id, ¶ms.row_id)),
|
2022-04-07 12:15:00 +00:00
|
|
|
Some(cell) => data_result(cell),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
2022-03-09 08:11:24 +00:00
|
|
|
pub(crate) async fn update_cell_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<CellChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-03-09 08:11:24 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-07-17 06:13:12 +00:00
|
|
|
let changeset: CellChangesetPB = data.into_inner();
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(&changeset.grid_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor
|
2022-12-26 12:28:18 +00:00
|
|
|
.update_cell_with_changeset(&changeset.row_id, &changeset.field_id, changeset.type_cell_data)
|
|
|
|
.await?;
|
2022-03-09 08:11:24 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-04-05 06:25:07 +00:00
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
2022-04-18 09:17:42 +00:00
|
|
|
pub(crate) async fn new_select_option_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<CreateSelectOptionPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-07-17 05:38:53 +00:00
|
|
|
) -> DataResult<SelectOptionPB, FlowyError> {
|
2022-04-18 09:17:42 +00:00
|
|
|
let params: CreateSelectOptionParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.grid_id).await?;
|
2022-06-15 07:13:50 +00:00
|
|
|
match editor.get_field_rev(¶ms.field_id).await {
|
2022-04-18 09:17:42 +00:00
|
|
|
None => Err(ErrorCode::InvalidData.into()),
|
2022-06-15 07:13:50 +00:00
|
|
|
Some(field_rev) => {
|
2022-10-12 13:52:02 +00:00
|
|
|
let type_option = select_type_option_from_field_rev(&field_rev)?;
|
2022-04-18 09:17:42 +00:00
|
|
|
let select_option = type_option.create_option(¶ms.option_name);
|
|
|
|
data_result(select_option)
|
|
|
|
}
|
|
|
|
}
|
2022-04-07 00:33:10 +00:00
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
2022-04-12 02:06:47 +00:00
|
|
|
pub(crate) async fn update_select_option_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<SelectOptionChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-04-05 06:25:07 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-04-07 00:33:10 +00:00
|
|
|
let changeset: SelectOptionChangeset = data.into_inner().try_into()?;
|
2022-12-26 12:28:18 +00:00
|
|
|
let editor = manager.get_grid_editor(&changeset.cell_path.view_id).await?;
|
|
|
|
let field_id = changeset.cell_path.field_id.clone();
|
2023-01-05 13:27:21 +00:00
|
|
|
editor
|
2022-12-26 12:28:18 +00:00
|
|
|
.modify_field_rev(&field_id, |field_rev| {
|
2022-10-12 13:52:02 +00:00
|
|
|
let mut type_option = select_type_option_from_field_rev(field_rev)?;
|
2022-12-26 12:28:18 +00:00
|
|
|
let mut cell_changeset_str = None;
|
2022-10-10 17:04:13 +00:00
|
|
|
let mut is_changed = None;
|
|
|
|
|
2022-10-11 05:43:29 +00:00
|
|
|
for option in changeset.insert_options {
|
2022-12-26 12:28:18 +00:00
|
|
|
cell_changeset_str =
|
|
|
|
Some(SelectOptionCellChangeset::from_insert_option_id(&option.id).to_cell_changeset_str());
|
2022-10-10 17:04:13 +00:00
|
|
|
type_option.insert_option(option);
|
|
|
|
is_changed = Some(());
|
|
|
|
}
|
|
|
|
|
2022-10-11 05:43:29 +00:00
|
|
|
for option in changeset.update_options {
|
2022-10-10 17:04:13 +00:00
|
|
|
type_option.insert_option(option);
|
|
|
|
is_changed = Some(());
|
|
|
|
}
|
|
|
|
|
2022-10-11 05:43:29 +00:00
|
|
|
for option in changeset.delete_options {
|
2022-12-26 12:28:18 +00:00
|
|
|
cell_changeset_str =
|
|
|
|
Some(SelectOptionCellChangeset::from_delete_option_id(&option.id).to_cell_changeset_str());
|
2022-10-10 17:04:13 +00:00
|
|
|
type_option.delete_option(option);
|
|
|
|
is_changed = Some(());
|
|
|
|
}
|
|
|
|
|
|
|
|
if is_changed.is_some() {
|
|
|
|
field_rev.insert_type_option(&*type_option);
|
|
|
|
}
|
|
|
|
|
2022-12-26 12:28:18 +00:00
|
|
|
if let Some(cell_changeset_str) = cell_changeset_str {
|
2022-10-10 17:04:13 +00:00
|
|
|
let cloned_editor = editor.clone();
|
|
|
|
tokio::spawn(async move {
|
2022-12-26 12:28:18 +00:00
|
|
|
match cloned_editor
|
|
|
|
.update_cell_with_changeset(
|
|
|
|
&changeset.cell_path.row_id,
|
|
|
|
&changeset.cell_path.field_id,
|
|
|
|
cell_changeset_str,
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
{
|
2022-10-10 17:04:13 +00:00
|
|
|
Ok(_) => {}
|
2022-10-11 13:51:02 +00:00
|
|
|
Err(e) => tracing::error!("{}", e),
|
2022-10-10 17:04:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Ok(is_changed)
|
|
|
|
})
|
|
|
|
.await?;
|
2022-04-07 00:33:10 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
2022-04-07 00:33:10 +00:00
|
|
|
pub(crate) async fn get_select_option_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<CellPathPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-07-17 05:38:53 +00:00
|
|
|
) -> DataResult<SelectOptionCellDataPB, FlowyError> {
|
2022-11-14 01:59:23 +00:00
|
|
|
let params: CellPathParams = data.into_inner().try_into()?;
|
2022-12-20 00:39:46 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.view_id).await?;
|
2022-06-15 07:13:50 +00:00
|
|
|
match editor.get_field_rev(¶ms.field_id).await {
|
2022-04-07 00:33:10 +00:00
|
|
|
None => {
|
2022-05-27 11:03:48 +00:00
|
|
|
tracing::error!("Can't find the select option field with id: {}", params.field_id);
|
2022-07-17 05:38:53 +00:00
|
|
|
data_result(SelectOptionCellDataPB::default())
|
2022-04-07 00:33:10 +00:00
|
|
|
}
|
2022-06-15 07:13:50 +00:00
|
|
|
Some(field_rev) => {
|
2022-07-10 14:17:44 +00:00
|
|
|
//
|
2022-06-15 07:13:50 +00:00
|
|
|
let cell_rev = editor.get_cell_rev(¶ms.row_id, ¶ms.field_id).await?;
|
2022-10-12 13:52:02 +00:00
|
|
|
let type_option = select_type_option_from_field_rev(&field_rev)?;
|
2022-12-12 09:36:36 +00:00
|
|
|
let type_cell_data: TypeCellData = match cell_rev {
|
2022-11-17 08:44:17 +00:00
|
|
|
None => TypeCellData {
|
2022-12-21 03:00:08 +00:00
|
|
|
cell_str: "".to_string(),
|
2022-08-19 03:56:47 +00:00
|
|
|
field_type: field_rev.ty.into(),
|
2022-07-10 14:17:44 +00:00
|
|
|
},
|
|
|
|
Some(cell_rev) => cell_rev.try_into()?,
|
|
|
|
};
|
2022-12-21 03:00:08 +00:00
|
|
|
let ids = SelectOptionIds::from_cell_str(&type_cell_data.cell_str)?;
|
2022-12-17 02:15:13 +00:00
|
|
|
let selected_options = type_option.get_selected_options(ids);
|
2022-10-12 13:52:02 +00:00
|
|
|
data_result(selected_options)
|
2022-04-07 00:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
2022-05-11 03:34:13 +00:00
|
|
|
pub(crate) async fn update_select_option_cell_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<SelectOptionCellChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-04-07 00:33:10 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
|
|
|
let params: SelectOptionCellChangesetParams = data.into_inner().try_into()?;
|
2022-12-20 00:39:46 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.cell_identifier.view_id).await?;
|
2022-12-26 12:28:18 +00:00
|
|
|
let changeset = SelectOptionCellChangeset {
|
|
|
|
insert_option_ids: params.insert_option_ids,
|
|
|
|
delete_option_ids: params.delete_option_ids,
|
|
|
|
};
|
|
|
|
|
2023-01-05 13:27:21 +00:00
|
|
|
editor
|
2022-12-26 12:28:18 +00:00
|
|
|
.update_cell_with_changeset(
|
|
|
|
¶ms.cell_identifier.row_id,
|
|
|
|
¶ms.cell_identifier.field_id,
|
|
|
|
changeset,
|
|
|
|
)
|
|
|
|
.await?;
|
2022-05-11 03:34:13 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2022-05-26 09:28:44 +00:00
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
2022-05-11 03:34:13 +00:00
|
|
|
pub(crate) async fn update_date_cell_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<DateChangesetPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-05-11 03:34:13 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-11-14 04:03:22 +00:00
|
|
|
let data = data.into_inner();
|
|
|
|
let cell_path: CellPathParams = data.cell_path.try_into()?;
|
2022-12-26 12:28:18 +00:00
|
|
|
let cell_changeset = DateCellChangeset {
|
2022-11-14 04:03:22 +00:00
|
|
|
date: data.date,
|
|
|
|
time: data.time,
|
|
|
|
is_utc: data.is_utc,
|
|
|
|
};
|
|
|
|
|
2022-12-20 00:39:46 +00:00
|
|
|
let editor = manager.get_grid_editor(&cell_path.view_id).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor
|
2022-12-26 12:28:18 +00:00
|
|
|
.update_cell(cell_path.row_id, cell_path.field_id, cell_changeset)
|
2022-11-14 04:03:22 +00:00
|
|
|
.await?;
|
2022-04-05 06:25:07 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-08-11 05:04:45 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
2022-08-11 13:18:27 +00:00
|
|
|
pub(crate) async fn get_groups_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<GridIdPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-11-26 13:28:08 +00:00
|
|
|
) -> DataResult<RepeatedGroupPB, FlowyError> {
|
2022-08-11 05:04:45 +00:00
|
|
|
let params: GridIdPB = data.into_inner();
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(¶ms.value).await?;
|
2022-08-11 13:18:27 +00:00
|
|
|
let group = editor.load_groups().await?;
|
2022-08-11 05:04:45 +00:00
|
|
|
data_result(group)
|
|
|
|
}
|
2022-08-13 15:26:42 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn create_board_card_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<CreateBoardCardPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-08-13 15:26:42 +00:00
|
|
|
) -> DataResult<RowPB, FlowyError> {
|
2022-08-15 12:07:01 +00:00
|
|
|
let params: CreateRowParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(params.grid_id.as_ref()).await?;
|
2022-08-15 12:07:01 +00:00
|
|
|
let row = editor.create_row(params).await?;
|
2022-08-13 15:26:42 +00:00
|
|
|
data_result(row)
|
|
|
|
}
|
2022-08-19 11:59:09 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn move_group_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<MoveGroupPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-08-21 05:56:06 +00:00
|
|
|
) -> FlowyResult<()> {
|
2022-08-19 11:59:09 +00:00
|
|
|
let params: MoveGroupParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(params.view_id.as_ref()).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.move_group(params).await?;
|
2022-08-21 05:56:06 +00:00
|
|
|
Ok(())
|
2022-08-19 11:59:09 +00:00
|
|
|
}
|
2022-08-22 08:16:15 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn move_group_row_handler(
|
2022-12-01 00:35:50 +00:00
|
|
|
data: AFPluginData<MoveGroupRowPayloadPB>,
|
|
|
|
manager: AFPluginState<Arc<GridManager>>,
|
2022-08-22 08:16:15 +00:00
|
|
|
) -> FlowyResult<()> {
|
|
|
|
let params: MoveGroupRowParams = data.into_inner().try_into()?;
|
2022-11-08 01:30:10 +00:00
|
|
|
let editor = manager.get_grid_editor(params.view_id.as_ref()).await?;
|
2023-01-05 13:27:21 +00:00
|
|
|
editor.move_group_row(params).await?;
|
2022-08-22 08:16:15 +00:00
|
|
|
Ok(())
|
|
|
|
}
|