2022-03-04 14:09:16 +00:00
|
|
|
use crate::manager::GridManager;
|
2022-03-02 14:43:04 +00:00
|
|
|
use flowy_error::FlowyError;
|
2022-03-09 08:11:24 +00:00
|
|
|
use flowy_grid_data_model::entities::{
|
|
|
|
Cell, Grid, GridId, QueryFieldPayload, QueryRowPayload, RepeatedField, RepeatedRow,
|
|
|
|
};
|
2022-03-05 02:59:44 +00:00
|
|
|
use lib_dispatch::prelude::{data_result, AppData, Data, DataResult};
|
2022-03-02 14:43:04 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-03-06 03:28:24 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
2022-03-06 13:22:42 +00:00
|
|
|
pub(crate) async fn get_grid_data_handler(
|
2022-03-02 14:43:04 +00:00
|
|
|
data: Data<GridId>,
|
2022-03-05 02:59:44 +00:00
|
|
|
manager: AppData<Arc<GridManager>>,
|
2022-03-02 14:43:04 +00:00
|
|
|
) -> DataResult<Grid, FlowyError> {
|
2022-03-05 02:59:44 +00:00
|
|
|
let grid_id: GridId = data.into_inner();
|
|
|
|
let editor = manager.open_grid(grid_id).await?;
|
|
|
|
let grid = editor.grid_data().await;
|
|
|
|
data_result(grid)
|
2022-03-03 14:17:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 03:28:24 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
2022-03-03 14:17:07 +00:00
|
|
|
pub(crate) async fn get_rows_handler(
|
2022-03-05 09:52:25 +00:00
|
|
|
data: Data<QueryRowPayload>,
|
2022-03-05 02:59:44 +00:00
|
|
|
manager: AppData<Arc<GridManager>>,
|
2022-03-04 00:22:49 +00:00
|
|
|
) -> DataResult<RepeatedRow, FlowyError> {
|
2022-03-05 09:52:25 +00:00
|
|
|
let payload: QueryRowPayload = data.into_inner();
|
|
|
|
let editor = manager.get_grid_editor(&payload.grid_id)?;
|
|
|
|
let repeated_row = editor.get_rows(payload.row_orders).await?;
|
2022-03-05 02:59:44 +00:00
|
|
|
data_result(repeated_row)
|
2022-03-03 14:17:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 03:28:24 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
2022-03-03 14:17:07 +00:00
|
|
|
pub(crate) async fn get_fields_handler(
|
2022-03-05 09:52:25 +00:00
|
|
|
data: Data<QueryFieldPayload>,
|
2022-03-05 02:59:44 +00:00
|
|
|
manager: AppData<Arc<GridManager>>,
|
2022-03-04 00:22:49 +00:00
|
|
|
) -> DataResult<RepeatedField, FlowyError> {
|
2022-03-05 09:52:25 +00:00
|
|
|
let payload: QueryFieldPayload = data.into_inner();
|
|
|
|
let editor = manager.get_grid_editor(&payload.grid_id)?;
|
2022-03-12 14:52:24 +00:00
|
|
|
let repeated_field = editor.get_fields(Some(payload.field_orders)).await?;
|
2022-03-05 02:59:44 +00:00
|
|
|
data_result(repeated_field)
|
2022-03-03 14:17:07 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 03:28:24 +00:00
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
2022-03-03 14:17:07 +00:00
|
|
|
pub(crate) async fn create_row_handler(
|
|
|
|
data: Data<GridId>,
|
2022-03-05 02:59:44 +00:00
|
|
|
manager: AppData<Arc<GridManager>>,
|
2022-03-04 00:22:49 +00:00
|
|
|
) -> Result<(), FlowyError> {
|
2022-03-03 14:17:07 +00:00
|
|
|
let id: GridId = data.into_inner();
|
2022-03-05 02:59:44 +00:00
|
|
|
let editor = manager.get_grid_editor(id.as_ref())?;
|
2022-03-12 01:30:13 +00:00
|
|
|
let _ = editor.create_row().await?;
|
2022-03-04 00:22:49 +00:00
|
|
|
Ok(())
|
2022-03-02 14:43:04 +00:00
|
|
|
}
|
2022-03-09 08:11:24 +00:00
|
|
|
|
|
|
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
|
|
|
pub(crate) async fn update_cell_handler(
|
|
|
|
data: Data<Cell>,
|
|
|
|
manager: AppData<Arc<GridManager>>,
|
|
|
|
) -> Result<(), FlowyError> {
|
2022-03-12 01:30:13 +00:00
|
|
|
let _cell: Cell = data.into_inner();
|
2022-03-10 04:01:31 +00:00
|
|
|
// let editor = manager.get_grid_editor(id.as_ref())?;
|
|
|
|
// let _ = editor.create_empty_row().await?;
|
2022-03-09 08:11:24 +00:00
|
|
|
Ok(())
|
|
|
|
}
|