|
@@ -18,8 +18,8 @@ use crate::entities::{
|
|
AlterFilterParams, AlterSortParams, CalendarEventPB, CellChangesetNotifyPB, CellPB,
|
|
AlterFilterParams, AlterSortParams, CalendarEventPB, CellChangesetNotifyPB, CellPB,
|
|
CreateRowParams, DatabaseFieldChangesetPB, DatabasePB, DatabaseViewSettingPB, DeleteFilterParams,
|
|
CreateRowParams, DatabaseFieldChangesetPB, DatabasePB, DatabaseViewSettingPB, DeleteFilterParams,
|
|
DeleteGroupParams, DeleteSortParams, FieldChangesetParams, FieldIdPB, FieldPB, FieldType,
|
|
DeleteGroupParams, DeleteSortParams, FieldChangesetParams, FieldIdPB, FieldPB, FieldType,
|
|
- GroupPB, IndexFieldPB, InsertGroupParams, LayoutSettingParams, RepeatedFilterPB, RepeatedGroupPB,
|
|
|
|
- RepeatedSortPB, RowPB, SelectOptionCellDataPB, SelectOptionPB,
|
|
|
|
|
|
+ GroupPB, IndexFieldPB, InsertGroupParams, InsertedRowPB, LayoutSettingParams, RepeatedFilterPB,
|
|
|
|
+ RepeatedGroupPB, RepeatedSortPB, RowPB, RowsChangesetPB, SelectOptionCellDataPB, SelectOptionPB,
|
|
};
|
|
};
|
|
use crate::notification::{send_notification, DatabaseNotification};
|
|
use crate::notification::{send_notification, DatabaseNotification};
|
|
use crate::services::cell::{
|
|
use crate::services::cell::{
|
|
@@ -278,18 +278,26 @@ impl DatabaseEditor {
|
|
let _ = self.database.lock().duplicate_row(view_id, row_id);
|
|
let _ = self.database.lock().duplicate_row(view_id, row_id);
|
|
}
|
|
}
|
|
|
|
|
|
- pub async fn move_row(&self, _view_id: &str, _from: RowId, _to: RowId) {
|
|
|
|
- // self.database.lock().views.update_view(view_id, |view| {
|
|
|
|
- // view.move_row_order(from as u32, to as u32);
|
|
|
|
- // });
|
|
|
|
- // let changeset = RowsChangesetPB::from_move(
|
|
|
|
- // view_id.to_string(),
|
|
|
|
- // vec![from.into_inner()],
|
|
|
|
- // vec![to.into()],
|
|
|
|
- // );
|
|
|
|
- // send_notification(&self.view_id, DatabaseNotification::DidUpdateViewRows)
|
|
|
|
- // .payload(changeset)
|
|
|
|
- // .send();
|
|
|
|
|
|
+ pub async fn move_row(&self, view_id: &str, from: RowId, to: RowId) {
|
|
|
|
+ let database = self.database.lock();
|
|
|
|
+ if let (Some(row), Some(from_index), Some(to_index)) = (
|
|
|
|
+ database.get_row(&from),
|
|
|
|
+ database.index_of_row(view_id, &from),
|
|
|
|
+ database.index_of_row(view_id, &to),
|
|
|
|
+ ) {
|
|
|
|
+ database.views.update_view(view_id, |view| {
|
|
|
|
+ view.move_row_order(from_index as u32, to_index as u32);
|
|
|
|
+ });
|
|
|
|
+ drop(database);
|
|
|
|
+
|
|
|
|
+ let delete_row_id = from.into_inner();
|
|
|
|
+ let insert_row = InsertedRowPB::from(&row).with_index(to_index as i32);
|
|
|
|
+ let changeset =
|
|
|
|
+ RowsChangesetPB::from_move(view_id.to_string(), vec![delete_row_id], vec![insert_row]);
|
|
|
|
+ send_notification(view_id, DatabaseNotification::DidUpdateViewRows)
|
|
|
|
+ .payload(changeset)
|
|
|
|
+ .send();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
pub async fn create_row(&self, params: CreateRowParams) -> FlowyResult<Option<Row>> {
|
|
pub async fn create_row(&self, params: CreateRowParams) -> FlowyResult<Option<Row>> {
|