mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
docs/update database documentation (#1824)
* chore: update event name * chore: add events and notifications documentation & remove unused code
This commit is contained in:
@ -8,7 +8,7 @@ import 'package:dartz/dartz.dart';
|
|||||||
import 'package:appflowy_backend/protobuf/flowy-database/group.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database/group.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database/group_changeset.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database/group_changeset.pb.dart';
|
||||||
|
|
||||||
typedef GroupUpdateValue = Either<GroupViewChangesetPB, FlowyError>;
|
typedef GroupUpdateValue = Either<GroupChangesetPB, FlowyError>;
|
||||||
typedef GroupByNewFieldValue = Either<List<GroupPB>, FlowyError>;
|
typedef GroupByNewFieldValue = Either<List<GroupPB>, FlowyError>;
|
||||||
|
|
||||||
class BoardListener {
|
class BoardListener {
|
||||||
@ -36,17 +36,17 @@ class BoardListener {
|
|||||||
Either<Uint8List, FlowyError> result,
|
Either<Uint8List, FlowyError> result,
|
||||||
) {
|
) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case DatabaseNotification.DidUpdateGroupView:
|
case DatabaseNotification.DidUpdateGroups:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _groupUpdateNotifier?.value =
|
(payload) => _groupUpdateNotifier?.value =
|
||||||
left(GroupViewChangesetPB.fromBuffer(payload)),
|
left(GroupChangesetPB.fromBuffer(payload)),
|
||||||
(error) => _groupUpdateNotifier?.value = right(error),
|
(error) => _groupUpdateNotifier?.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case DatabaseNotification.DidGroupByNewField:
|
case DatabaseNotification.DidGroupByField:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _groupByNewFieldNotifier?.value =
|
(payload) => _groupByNewFieldNotifier?.value =
|
||||||
left(GroupViewChangesetPB.fromBuffer(payload).initialGroups),
|
left(GroupChangesetPB.fromBuffer(payload).initialGroups),
|
||||||
(error) => _groupByNewFieldNotifier?.value = right(error),
|
(error) => _groupByNewFieldNotifier?.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
@ -31,7 +31,7 @@ class GroupListener {
|
|||||||
Either<Uint8List, FlowyError> result,
|
Either<Uint8List, FlowyError> result,
|
||||||
) {
|
) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case DatabaseNotification.DidUpdateGroup:
|
case DatabaseNotification.DidUpdateGroupRow:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _groupNotifier?.value =
|
(payload) => _groupNotifier?.value =
|
||||||
left(GroupRowsNotificationPB.fromBuffer(payload)),
|
left(GroupRowsNotificationPB.fromBuffer(payload)),
|
||||||
|
@ -60,8 +60,8 @@ class DateCellDataPersistence implements GridCellDataPersistence<CalendarData> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CellPathPB _makeCellPath(GridCellIdentifier cellId) {
|
CellIdPB _makeCellPath(GridCellIdentifier cellId) {
|
||||||
return CellPathPB.create()
|
return CellIdPB.create()
|
||||||
..databaseId = cellId.databaseId
|
..databaseId = cellId.databaseId
|
||||||
..fieldId = cellId.fieldId
|
..fieldId = cellId.fieldId
|
||||||
..rowId = cellId.rowId;
|
..rowId = cellId.rowId;
|
||||||
|
@ -45,7 +45,7 @@ class CellService {
|
|||||||
Future<Either<CellPB, FlowyError>> getCell({
|
Future<Either<CellPB, FlowyError>> getCell({
|
||||||
required GridCellIdentifier cellId,
|
required GridCellIdentifier cellId,
|
||||||
}) {
|
}) {
|
||||||
final payload = CellPathPB.create()
|
final payload = CellIdPB.create()
|
||||||
..databaseId = cellId.databaseId
|
..databaseId = cellId.databaseId
|
||||||
..fieldId = cellId.fieldId
|
..fieldId = cellId.fieldId
|
||||||
..rowId = cellId.rowId;
|
..rowId = cellId.rowId;
|
||||||
|
@ -22,7 +22,7 @@ class SelectOptionFFIService {
|
|||||||
(result) {
|
(result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(option) {
|
(option) {
|
||||||
final cellIdentifier = CellPathPB.create()
|
final cellIdentifier = CellIdPB.create()
|
||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..rowId = rowId;
|
..rowId = rowId;
|
||||||
@ -61,7 +61,7 @@ class SelectOptionFFIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<SelectOptionCellDataPB, FlowyError>> getOptionContext() {
|
Future<Either<SelectOptionCellDataPB, FlowyError>> getOptionContext() {
|
||||||
final payload = CellPathPB.create()
|
final payload = CellIdPB.create()
|
||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..rowId = rowId;
|
..rowId = rowId;
|
||||||
@ -85,8 +85,8 @@ class SelectOptionFFIService {
|
|||||||
return DatabaseEventUpdateSelectOptionCell(payload).send();
|
return DatabaseEventUpdateSelectOptionCell(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
CellPathPB _cellIdentifier() {
|
CellIdPB _cellIdentifier() {
|
||||||
return CellPathPB.create()
|
return CellIdPB.create()
|
||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..rowId = rowId;
|
..rowId = rowId;
|
||||||
|
@ -97,7 +97,7 @@ class FieldService {
|
|||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..fieldType = fieldType;
|
..fieldType = fieldType;
|
||||||
return DatabaseEventGetFieldTypeOption(payload).send().then((result) {
|
return DatabaseEventGetTypeOption(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(data) => left(data),
|
(data) => left(data),
|
||||||
(err) => right(err),
|
(err) => right(err),
|
||||||
|
@ -27,7 +27,7 @@ class DatabaseFieldsListener {
|
|||||||
|
|
||||||
void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
|
void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case DatabaseNotification.DidUpdateDatabaseFields:
|
case DatabaseNotification.DidUpdateFields:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => updateFieldsNotifier?.value =
|
(payload) => updateFieldsNotifier?.value =
|
||||||
left(DatabaseFieldChangesetPB.fromBuffer(payload)),
|
left(DatabaseFieldChangesetPB.fromBuffer(payload)),
|
||||||
|
@ -160,12 +160,12 @@ abstract class IFieldTypeOptionLoader {
|
|||||||
|
|
||||||
Future<Either<Unit, FlowyError>> switchToField(
|
Future<Either<Unit, FlowyError>> switchToField(
|
||||||
String fieldId, FieldType fieldType) {
|
String fieldId, FieldType fieldType) {
|
||||||
final payload = EditFieldChangesetPB.create()
|
final payload = UpdateFieldTypePayloadPB.create()
|
||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..fieldType = fieldType;
|
..fieldType = fieldType;
|
||||||
|
|
||||||
return DatabaseEventSwitchToField(payload).send();
|
return DatabaseEventUpdateFieldType(payload).send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,13 +189,13 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
|||||||
..fieldId = fieldTypeOption!.field_2.id
|
..fieldId = fieldTypeOption!.field_2.id
|
||||||
..fieldType = fieldTypeOption!.field_2.fieldType;
|
..fieldType = fieldTypeOption!.field_2.fieldType;
|
||||||
|
|
||||||
return DatabaseEventGetFieldTypeOption(payload).send();
|
return DatabaseEventGetTypeOption(payload).send();
|
||||||
} else {
|
} else {
|
||||||
final payload = CreateFieldPayloadPB.create()
|
final payload = CreateFieldPayloadPB.create()
|
||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..fieldType = FieldType.RichText;
|
..fieldType = FieldType.RichText;
|
||||||
|
|
||||||
return DatabaseEventCreateFieldTypeOption(payload).send().then((result) {
|
return DatabaseEventCreateTypeOption(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(newFieldTypeOption) {
|
(newFieldTypeOption) {
|
||||||
fieldTypeOption = newFieldTypeOption;
|
fieldTypeOption = newFieldTypeOption;
|
||||||
@ -226,6 +226,6 @@ class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
|||||||
..fieldId = field.id
|
..fieldId = field.id
|
||||||
..fieldType = field.fieldType;
|
..fieldType = field.fieldType;
|
||||||
|
|
||||||
return DatabaseEventGetFieldTypeOption(payload).send();
|
return DatabaseEventGetTypeOption(payload).send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,6 @@ class TypeOptionFFIService {
|
|||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..fieldId = fieldId;
|
..fieldId = fieldId;
|
||||||
|
|
||||||
return DatabaseEventNewSelectOption(payload).send();
|
return DatabaseEventCreateSelectOption(payload).send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,9 @@ class DatabaseFFIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<RowPB, FlowyError>> createRow({Option<String>? startRowId}) {
|
Future<Either<RowPB, FlowyError>> createRow({Option<String>? startRowId}) {
|
||||||
var payload = CreateTableRowPayloadPB.create()..databaseId = databaseId;
|
var payload = CreateRowPayloadPB.create()..databaseId = databaseId;
|
||||||
startRowId?.fold(() => null, (id) => payload.startRowId = id);
|
startRowId?.fold(() => null, (id) => payload.startRowId = id);
|
||||||
return DatabaseEventCreateTableRow(payload).send();
|
return DatabaseEventCreateRow(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<RowPB, FlowyError>> createBoardCard(
|
Future<Either<RowPB, FlowyError>> createBoardCard(
|
||||||
|
@ -1,46 +0,0 @@
|
|||||||
import 'package:app_flowy/core/grid_notification.dart';
|
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database/notification.pb.dart';
|
|
||||||
import 'package:flowy_infra/notifier.dart';
|
|
||||||
import 'dart:async';
|
|
||||||
import 'dart:typed_data';
|
|
||||||
import 'package:dartz/dartz.dart';
|
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database/field_entities.pb.dart';
|
|
||||||
import 'package:appflowy_backend/protobuf/flowy-database/row_entities.pb.dart';
|
|
||||||
|
|
||||||
typedef UpdateRowNotifiedValue = Either<RowPB, FlowyError>;
|
|
||||||
typedef UpdateFieldNotifiedValue = Either<List<FieldPB>, FlowyError>;
|
|
||||||
|
|
||||||
class RowListener {
|
|
||||||
final String rowId;
|
|
||||||
PublishNotifier<UpdateRowNotifiedValue>? updateRowNotifier =
|
|
||||||
PublishNotifier();
|
|
||||||
DatabaseNotificationListener? _listener;
|
|
||||||
|
|
||||||
RowListener({required this.rowId});
|
|
||||||
|
|
||||||
void start() {
|
|
||||||
_listener =
|
|
||||||
DatabaseNotificationListener(objectId: rowId, handler: _handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
|
|
||||||
switch (ty) {
|
|
||||||
case DatabaseNotification.DidUpdateRow:
|
|
||||||
result.fold(
|
|
||||||
(payload) =>
|
|
||||||
updateRowNotifier?.value = left(RowPB.fromBuffer(payload)),
|
|
||||||
(error) => updateRowNotifier?.value = right(error),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> stop() async {
|
|
||||||
await _listener?.stop();
|
|
||||||
updateRowNotifier?.dispose();
|
|
||||||
updateRowNotifier = null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,11 +13,11 @@ class RowFFIService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Future<Either<RowPB, FlowyError>> createRow(String rowId) {
|
Future<Either<RowPB, FlowyError>> createRow(String rowId) {
|
||||||
final payload = CreateTableRowPayloadPB.create()
|
final payload = CreateRowPayloadPB.create()
|
||||||
..databaseId = databaseId
|
..databaseId = databaseId
|
||||||
..startRowId = rowId;
|
..startRowId = rowId;
|
||||||
|
|
||||||
return DatabaseEventCreateTableRow(payload).send();
|
return DatabaseEventCreateRow(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<OptionalRowPB, FlowyError>> getRow(String rowId) {
|
Future<Either<OptionalRowPB, FlowyError>> getRow(String rowId) {
|
||||||
|
@ -27,7 +27,7 @@ class DatabaseSettingListener {
|
|||||||
|
|
||||||
void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
|
void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case DatabaseNotification.DidUpdateDatabaseSetting:
|
case DatabaseNotification.DidUpdateSettings:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _updateSettingNotifier?.value = left(
|
(payload) => _updateSettingNotifier?.value = left(
|
||||||
DatabaseViewSettingPB.fromBuffer(payload),
|
DatabaseViewSettingPB.fromBuffer(payload),
|
||||||
|
@ -53,14 +53,14 @@ class GridViewListener {
|
|||||||
|
|
||||||
void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
|
void _handler(DatabaseNotification ty, Either<Uint8List, FlowyError> result) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case DatabaseNotification.DidUpdateDatabaseViewRowsVisibility:
|
case DatabaseNotification.DidUpdateViewRowsVisibility:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _rowsVisibility?.value =
|
(payload) => _rowsVisibility?.value =
|
||||||
left(ViewRowsVisibilityChangesetPB.fromBuffer(payload)),
|
left(ViewRowsVisibilityChangesetPB.fromBuffer(payload)),
|
||||||
(error) => _rowsVisibility?.value = right(error),
|
(error) => _rowsVisibility?.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case DatabaseNotification.DidUpdateDatabaseViewRows:
|
case DatabaseNotification.DidUpdateViewRows:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _rowsNotifier?.value =
|
(payload) => _rowsNotifier?.value =
|
||||||
left(ViewRowsChangesetPB.fromBuffer(payload)),
|
left(ViewRowsChangesetPB.fromBuffer(payload)),
|
||||||
|
@ -29,7 +29,7 @@ class TrashListener {
|
|||||||
Either<Uint8List, FlowyError> result,
|
Either<Uint8List, FlowyError> result,
|
||||||
) {
|
) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case FolderNotification.TrashUpdated:
|
case FolderNotification.DidUpdateTrash:
|
||||||
if (_trashUpdated != null) {
|
if (_trashUpdated != null) {
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) {
|
(payload) {
|
||||||
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||||||
import 'package:app_flowy/core/folder_notification.dart';
|
import 'package:app_flowy/core/folder_notification.dart';
|
||||||
import 'package:app_flowy/core/user_notification.dart';
|
import 'package:app_flowy/core/user_notification.dart';
|
||||||
import 'package:dartz/dartz.dart';
|
import 'package:dartz/dartz.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/code.pb.dart';
|
|
||||||
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-folder/workspace.pb.dart';
|
||||||
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-error/errors.pb.dart';
|
||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
@ -122,29 +121,21 @@ class UserWorkspaceListener {
|
|||||||
void _handleObservableType(
|
void _handleObservableType(
|
||||||
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case FolderNotification.UserCreateWorkspace:
|
case FolderNotification.DidCreateWorkspace:
|
||||||
case FolderNotification.UserDeleteWorkspace:
|
case FolderNotification.DidDeleteWorkspace:
|
||||||
case FolderNotification.WorkspaceListUpdated:
|
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _workspacesChangedNotifier?.value =
|
(payload) => _workspacesChangedNotifier?.value =
|
||||||
left(RepeatedWorkspacePB.fromBuffer(payload).items),
|
left(RepeatedWorkspacePB.fromBuffer(payload).items),
|
||||||
(error) => _workspacesChangedNotifier?.value = right(error),
|
(error) => _workspacesChangedNotifier?.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case FolderNotification.WorkspaceSetting:
|
case FolderNotification.DidUpdateWorkspaceSetting:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _settingChangedNotifier?.value =
|
(payload) => _settingChangedNotifier?.value =
|
||||||
left(WorkspaceSettingPB.fromBuffer(payload)),
|
left(WorkspaceSettingPB.fromBuffer(payload)),
|
||||||
(error) => _settingChangedNotifier?.value = right(error),
|
(error) => _settingChangedNotifier?.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case FolderNotification.UserUnauthorized:
|
|
||||||
result.fold(
|
|
||||||
(_) {},
|
|
||||||
(error) => _authNotifier?.value = right(
|
|
||||||
FlowyError.create()..code = ErrorCode.UserUnauthorized.value),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ class AppListener {
|
|||||||
void _handleCallback(
|
void _handleCallback(
|
||||||
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case FolderNotification.AppUpdated:
|
case FolderNotification.DidUpdateApp:
|
||||||
if (_updated != null) {
|
if (_updated != null) {
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) {
|
(payload) {
|
||||||
|
@ -75,28 +75,28 @@ class ViewListener {
|
|||||||
void _handleObservableType(
|
void _handleObservableType(
|
||||||
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case FolderNotification.ViewUpdated:
|
case FolderNotification.DidUpdateView:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) =>
|
(payload) =>
|
||||||
_updatedViewNotifier.value = left(ViewPB.fromBuffer(payload)),
|
_updatedViewNotifier.value = left(ViewPB.fromBuffer(payload)),
|
||||||
(error) => _updatedViewNotifier.value = right(error),
|
(error) => _updatedViewNotifier.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case FolderNotification.ViewDeleted:
|
case FolderNotification.DidDeleteView:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) =>
|
(payload) =>
|
||||||
_deletedNotifier.value = left(ViewPB.fromBuffer(payload)),
|
_deletedNotifier.value = left(ViewPB.fromBuffer(payload)),
|
||||||
(error) => _deletedNotifier.value = right(error),
|
(error) => _deletedNotifier.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case FolderNotification.ViewRestored:
|
case FolderNotification.DidRestoreView:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) =>
|
(payload) =>
|
||||||
_restoredNotifier.value = left(ViewPB.fromBuffer(payload)),
|
_restoredNotifier.value = left(ViewPB.fromBuffer(payload)),
|
||||||
(error) => _restoredNotifier.value = right(error),
|
(error) => _restoredNotifier.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case FolderNotification.ViewMoveToTrash:
|
case FolderNotification.DidMoveViewToTrash:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _moveToTrashNotifier.value =
|
(payload) => _moveToTrashNotifier.value =
|
||||||
left(DeletedViewPB.fromBuffer(payload)),
|
left(DeletedViewPB.fromBuffer(payload)),
|
||||||
|
@ -48,14 +48,14 @@ class WorkspaceListener {
|
|||||||
void _handleObservableType(
|
void _handleObservableType(
|
||||||
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
FolderNotification ty, Either<Uint8List, FlowyError> result) {
|
||||||
switch (ty) {
|
switch (ty) {
|
||||||
case FolderNotification.WorkspaceUpdated:
|
case FolderNotification.DidUpdateWorkspace:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _workspaceUpdatedNotifier?.value =
|
(payload) => _workspaceUpdatedNotifier?.value =
|
||||||
left(WorkspacePB.fromBuffer(payload)),
|
left(WorkspacePB.fromBuffer(payload)),
|
||||||
(error) => _workspaceUpdatedNotifier?.value = right(error),
|
(error) => _workspaceUpdatedNotifier?.value = right(error),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case FolderNotification.WorkspaceAppsChanged:
|
case FolderNotification.DidUpdateWorkspaceApps:
|
||||||
result.fold(
|
result.fold(
|
||||||
(payload) => _appsChangedNotifier?.value =
|
(payload) => _appsChangedNotifier?.value =
|
||||||
left(RepeatedAppPB.fromBuffer(payload).items),
|
left(RepeatedAppPB.fromBuffer(payload).items),
|
||||||
|
@ -2,7 +2,7 @@ use bytes::Bytes;
|
|||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
|
|
||||||
use flowy_client_ws::FlowyWebSocketConnect;
|
use flowy_client_ws::FlowyWebSocketConnect;
|
||||||
use flowy_database::entities::DatabaseViewLayout;
|
use flowy_database::entities::LayoutTypePB;
|
||||||
use flowy_database::manager::{make_database_view_data, DatabaseManager};
|
use flowy_database::manager::{make_database_view_data, DatabaseManager};
|
||||||
use flowy_database::util::{make_default_board, make_default_calendar, make_default_grid};
|
use flowy_database::util::{make_default_board, make_default_calendar, make_default_grid};
|
||||||
use flowy_document::DocumentManager;
|
use flowy_document::DocumentManager;
|
||||||
@ -261,9 +261,9 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
|||||||
) -> FutureResult<Bytes, FlowyError> {
|
) -> FutureResult<Bytes, FlowyError> {
|
||||||
debug_assert_eq!(data_format, ViewDataFormatPB::DatabaseFormat);
|
debug_assert_eq!(data_format, ViewDataFormatPB::DatabaseFormat);
|
||||||
let (build_context, layout) = match layout {
|
let (build_context, layout) = match layout {
|
||||||
ViewLayoutTypePB::Grid => (make_default_grid(), DatabaseViewLayout::Grid),
|
ViewLayoutTypePB::Grid => (make_default_grid(), LayoutTypePB::Grid),
|
||||||
ViewLayoutTypePB::Board => (make_default_board(), DatabaseViewLayout::Board),
|
ViewLayoutTypePB::Board => (make_default_board(), LayoutTypePB::Board),
|
||||||
ViewLayoutTypePB::Calendar => (make_default_calendar(), DatabaseViewLayout::Calendar),
|
ViewLayoutTypePB::Calendar => (make_default_calendar(), LayoutTypePB::Calendar),
|
||||||
ViewLayoutTypePB::Document => {
|
ViewLayoutTypePB::Document => {
|
||||||
return FutureResult::new(async move {
|
return FutureResult::new(async move {
|
||||||
Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))
|
Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))
|
||||||
@ -291,9 +291,9 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
|||||||
let grid_manager = self.0.clone();
|
let grid_manager = self.0.clone();
|
||||||
|
|
||||||
let layout = match layout {
|
let layout = match layout {
|
||||||
ViewLayoutTypePB::Grid => DatabaseViewLayout::Grid,
|
ViewLayoutTypePB::Grid => LayoutTypePB::Grid,
|
||||||
ViewLayoutTypePB::Board => DatabaseViewLayout::Board,
|
ViewLayoutTypePB::Board => LayoutTypePB::Board,
|
||||||
ViewLayoutTypePB::Calendar => DatabaseViewLayout::Calendar,
|
ViewLayoutTypePB::Calendar => LayoutTypePB::Calendar,
|
||||||
ViewLayoutTypePB::Document => {
|
ViewLayoutTypePB::Document => {
|
||||||
return FutureResult::new(async move {
|
return FutureResult::new(async move {
|
||||||
Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))
|
Err(FlowyError::internal().context(format!("Can't handle {:?} layout type", layout)))
|
||||||
|
@ -39,7 +39,7 @@ impl TryInto<CreateSelectOptionParams> for CreateSelectOptionPayloadPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||||
pub struct CellPathPB {
|
pub struct CellIdPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub database_id: String,
|
||||||
|
|
||||||
@ -52,20 +52,20 @@ pub struct CellPathPB {
|
|||||||
|
|
||||||
/// Represents as the cell identifier. It's used to locate the cell in corresponding
|
/// Represents as the cell identifier. It's used to locate the cell in corresponding
|
||||||
/// view's row with the field id.
|
/// view's row with the field id.
|
||||||
pub struct CellPathParams {
|
pub struct CellIdParams {
|
||||||
pub database_id: String,
|
pub database_id: String,
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
pub row_id: String,
|
pub row_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<CellPathParams> for CellPathPB {
|
impl TryInto<CellIdParams> for CellIdPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CellPathParams, Self::Error> {
|
fn try_into(self) -> Result<CellIdParams, Self::Error> {
|
||||||
let database_id = NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
let database_id = NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
|
let field_id = NotEmptyStr::parse(self.field_id).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
|
||||||
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
|
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
|
||||||
Ok(CellPathParams {
|
Ok(CellIdParams {
|
||||||
database_id: database_id.0,
|
database_id: database_id.0,
|
||||||
field_id: field_id.0,
|
field_id: field_id.0,
|
||||||
row_id: row_id.0,
|
row_id: row_id.0,
|
||||||
|
@ -178,7 +178,7 @@ impl TryInto<CreateFieldParams> for CreateFieldPayloadPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
pub struct EditFieldChangesetPB {
|
pub struct UpdateFieldTypePayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub database_id: String,
|
||||||
|
|
||||||
@ -198,7 +198,7 @@ pub struct EditFieldParams {
|
|||||||
pub field_type: FieldType,
|
pub field_type: FieldType,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<EditFieldParams> for EditFieldChangesetPB {
|
impl TryInto<EditFieldParams> for UpdateFieldTypePayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<EditFieldParams, Self::Error> {
|
fn try_into(self) -> Result<EditFieldParams, Self::Error> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::entities::parser::NotEmptyStr;
|
use crate::entities::parser::NotEmptyStr;
|
||||||
use crate::entities::{CreateRowParams, DatabaseViewLayout, FieldType, RowPB};
|
use crate::entities::{CreateRowParams, FieldType, LayoutTypePB, RowPB};
|
||||||
use crate::services::group::Group;
|
use crate::services::group::Group;
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
@ -33,7 +33,7 @@ impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
|
|||||||
database_id: database_id.0,
|
database_id: database_id.0,
|
||||||
start_row_id,
|
start_row_id,
|
||||||
group_id: Some(group_id.0),
|
group_id: Some(group_id.0),
|
||||||
layout: DatabaseViewLayout::Board,
|
layout: LayoutTypePB::Board,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ impl TryInto<MoveGroupParams> for MoveGroupPayloadPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
pub struct GroupViewChangesetPB {
|
pub struct GroupChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub view_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ pub struct GroupViewChangesetPB {
|
|||||||
pub update_groups: Vec<GroupPB>,
|
pub update_groups: Vec<GroupPB>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GroupViewChangesetPB {
|
impl GroupChangesetPB {
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.initial_groups.is_empty()
|
self.initial_groups.is_empty()
|
||||||
&& self.inserted_groups.is_empty()
|
&& self.inserted_groups.is_empty()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::entities::parser::NotEmptyStr;
|
use crate::entities::parser::NotEmptyStr;
|
||||||
use crate::entities::DatabaseViewLayout;
|
use crate::entities::LayoutTypePB;
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::RowRevision;
|
use grid_model::RowRevision;
|
||||||
@ -171,7 +171,7 @@ pub struct BlockRowIdPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ProtoBuf, Default)]
|
#[derive(ProtoBuf, Default)]
|
||||||
pub struct CreateTableRowPayloadPB {
|
pub struct CreateRowPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub database_id: String,
|
||||||
|
|
||||||
@ -184,10 +184,10 @@ pub struct CreateRowParams {
|
|||||||
pub database_id: String,
|
pub database_id: String,
|
||||||
pub start_row_id: Option<String>,
|
pub start_row_id: Option<String>,
|
||||||
pub group_id: Option<String>,
|
pub group_id: Option<String>,
|
||||||
pub layout: DatabaseViewLayout,
|
pub layout: LayoutTypePB,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<CreateRowParams> for CreateTableRowPayloadPB {
|
impl TryInto<CreateRowParams> for CreateRowPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
||||||
@ -197,7 +197,7 @@ impl TryInto<CreateRowParams> for CreateTableRowPayloadPB {
|
|||||||
database_id: database_id.0,
|
database_id: database_id.0,
|
||||||
start_row_id: self.start_row_id,
|
start_row_id: self.start_row_id,
|
||||||
group_id: None,
|
group_id: None,
|
||||||
layout: DatabaseViewLayout::Grid,
|
layout: LayoutTypePB::Grid,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,10 +15,10 @@ use strum_macros::EnumIter;
|
|||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct DatabaseViewSettingPB {
|
pub struct DatabaseViewSettingPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub layouts: Vec<ViewLayoutConfigPB>,
|
pub support_layouts: Vec<ViewLayoutPB>,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub layout_type: DatabaseViewLayout,
|
pub current_layout: LayoutTypePB,
|
||||||
|
|
||||||
#[pb(index = 3)]
|
#[pb(index = 3)]
|
||||||
pub filters: RepeatedFilterPB,
|
pub filters: RepeatedFilterPB,
|
||||||
@ -31,16 +31,16 @@ pub struct DatabaseViewSettingPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct ViewLayoutConfigPB {
|
pub struct ViewLayoutPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
ty: DatabaseViewLayout,
|
ty: LayoutTypePB,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ViewLayoutConfigPB {
|
impl ViewLayoutPB {
|
||||||
pub fn all() -> Vec<ViewLayoutConfigPB> {
|
pub fn all() -> Vec<ViewLayoutPB> {
|
||||||
let mut layouts = vec![];
|
let mut layouts = vec![];
|
||||||
for layout_ty in DatabaseViewLayout::iter() {
|
for layout_ty in LayoutTypePB::iter() {
|
||||||
layouts.push(ViewLayoutConfigPB { ty: layout_ty })
|
layouts.push(ViewLayoutPB { ty: layout_ty })
|
||||||
}
|
}
|
||||||
|
|
||||||
layouts
|
layouts
|
||||||
@ -49,34 +49,34 @@ impl ViewLayoutConfigPB {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]
|
#[derive(Debug, Clone, PartialEq, Eq, ProtoBuf_Enum, EnumIter)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum DatabaseViewLayout {
|
pub enum LayoutTypePB {
|
||||||
Grid = 0,
|
Grid = 0,
|
||||||
Board = 1,
|
Board = 1,
|
||||||
Calendar = 2,
|
Calendar = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for DatabaseViewLayout {
|
impl std::default::Default for LayoutTypePB {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
DatabaseViewLayout::Grid
|
LayoutTypePB::Grid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<LayoutRevision> for DatabaseViewLayout {
|
impl std::convert::From<LayoutRevision> for LayoutTypePB {
|
||||||
fn from(rev: LayoutRevision) -> Self {
|
fn from(rev: LayoutRevision) -> Self {
|
||||||
match rev {
|
match rev {
|
||||||
LayoutRevision::Grid => DatabaseViewLayout::Grid,
|
LayoutRevision::Grid => LayoutTypePB::Grid,
|
||||||
LayoutRevision::Board => DatabaseViewLayout::Board,
|
LayoutRevision::Board => LayoutTypePB::Board,
|
||||||
LayoutRevision::Calendar => DatabaseViewLayout::Calendar,
|
LayoutRevision::Calendar => LayoutTypePB::Calendar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<DatabaseViewLayout> for LayoutRevision {
|
impl std::convert::From<LayoutTypePB> for LayoutRevision {
|
||||||
fn from(layout: DatabaseViewLayout) -> Self {
|
fn from(layout: LayoutTypePB) -> Self {
|
||||||
match layout {
|
match layout {
|
||||||
DatabaseViewLayout::Grid => LayoutRevision::Grid,
|
LayoutTypePB::Grid => LayoutRevision::Grid,
|
||||||
DatabaseViewLayout::Board => LayoutRevision::Board,
|
LayoutTypePB::Board => LayoutRevision::Board,
|
||||||
DatabaseViewLayout::Calendar => LayoutRevision::Calendar,
|
LayoutTypePB::Calendar => LayoutRevision::Calendar,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +87,7 @@ pub struct DatabaseSettingChangesetPB {
|
|||||||
pub database_id: String,
|
pub database_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub layout_type: DatabaseViewLayout,
|
pub layout_type: LayoutTypePB,
|
||||||
|
|
||||||
#[pb(index = 3, one_of)]
|
#[pb(index = 3, one_of)]
|
||||||
pub alter_filter: Option<AlterFilterPayloadPB>,
|
pub alter_filter: Option<AlterFilterPayloadPB>,
|
||||||
|
@ -160,7 +160,7 @@ pub(crate) async fn delete_field_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn switch_to_field_handler(
|
pub(crate) async fn switch_to_field_handler(
|
||||||
data: AFPluginData<EditFieldChangesetPB>,
|
data: AFPluginData<UpdateFieldTypePayloadPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: EditFieldParams = data.into_inner().try_into()?;
|
let params: EditFieldParams = data.into_inner().try_into()?;
|
||||||
@ -315,7 +315,7 @@ pub(crate) async fn move_row_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
#[tracing::instrument(level = "debug", skip(data, manager), err)]
|
||||||
pub(crate) async fn create_table_row_handler(
|
pub(crate) async fn create_table_row_handler(
|
||||||
data: AFPluginData<CreateTableRowPayloadPB>,
|
data: AFPluginData<CreateRowPayloadPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<RowPB, FlowyError> {
|
) -> DataResult<RowPB, FlowyError> {
|
||||||
let params: CreateRowParams = data.into_inner().try_into()?;
|
let params: CreateRowParams = data.into_inner().try_into()?;
|
||||||
@ -326,10 +326,10 @@ pub(crate) async fn create_table_row_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
pub(crate) async fn get_cell_handler(
|
pub(crate) async fn get_cell_handler(
|
||||||
data: AFPluginData<CellPathPB>,
|
data: AFPluginData<CellIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<CellPB, FlowyError> {
|
) -> DataResult<CellPB, FlowyError> {
|
||||||
let params: CellPathParams = data.into_inner().try_into()?;
|
let params: CellIdParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
||||||
match editor.get_cell(¶ms).await {
|
match editor.get_cell(¶ms).await {
|
||||||
None => data_result(CellPB::empty(¶ms.field_id, ¶ms.row_id)),
|
None => data_result(CellPB::empty(¶ms.field_id, ¶ms.row_id)),
|
||||||
@ -427,10 +427,10 @@ pub(crate) async fn update_select_option_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn get_select_option_handler(
|
pub(crate) async fn get_select_option_handler(
|
||||||
data: AFPluginData<CellPathPB>,
|
data: AFPluginData<CellIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<SelectOptionCellDataPB, FlowyError> {
|
) -> DataResult<SelectOptionCellDataPB, FlowyError> {
|
||||||
let params: CellPathParams = data.into_inner().try_into()?;
|
let params: CellIdParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
||||||
match editor.get_field_rev(¶ms.field_id).await {
|
match editor.get_field_rev(¶ms.field_id).await {
|
||||||
None => {
|
None => {
|
||||||
@ -483,7 +483,7 @@ pub(crate) async fn update_date_cell_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
let cell_path: CellPathParams = data.cell_path.try_into()?;
|
let cell_path: CellIdParams = data.cell_path.try_into()?;
|
||||||
let cell_changeset = DateCellChangeset {
|
let cell_changeset = DateCellChangeset {
|
||||||
date: data.date,
|
date: data.date,
|
||||||
time: data.time,
|
time: data.time,
|
||||||
|
@ -20,16 +20,13 @@ pub fn init(database_manager: Arc<DatabaseManager>) -> AFPlugin {
|
|||||||
.event(DatabaseEvent::UpdateField, update_field_handler)
|
.event(DatabaseEvent::UpdateField, update_field_handler)
|
||||||
.event(DatabaseEvent::UpdateFieldTypeOption, update_field_type_option_handler)
|
.event(DatabaseEvent::UpdateFieldTypeOption, update_field_type_option_handler)
|
||||||
.event(DatabaseEvent::DeleteField, delete_field_handler)
|
.event(DatabaseEvent::DeleteField, delete_field_handler)
|
||||||
.event(DatabaseEvent::SwitchToField, switch_to_field_handler)
|
.event(DatabaseEvent::UpdateFieldType, switch_to_field_handler)
|
||||||
.event(DatabaseEvent::DuplicateField, duplicate_field_handler)
|
.event(DatabaseEvent::DuplicateField, duplicate_field_handler)
|
||||||
.event(DatabaseEvent::MoveField, move_field_handler)
|
.event(DatabaseEvent::MoveField, move_field_handler)
|
||||||
.event(DatabaseEvent::GetFieldTypeOption, get_field_type_option_data_handler)
|
.event(DatabaseEvent::GetTypeOption, get_field_type_option_data_handler)
|
||||||
.event(
|
.event(DatabaseEvent::CreateTypeOption, create_field_type_option_data_handler)
|
||||||
DatabaseEvent::CreateFieldTypeOption,
|
|
||||||
create_field_type_option_data_handler,
|
|
||||||
)
|
|
||||||
// Row
|
// Row
|
||||||
.event(DatabaseEvent::CreateTableRow, create_table_row_handler)
|
.event(DatabaseEvent::CreateRow, create_table_row_handler)
|
||||||
.event(DatabaseEvent::GetRow, get_row_handler)
|
.event(DatabaseEvent::GetRow, get_row_handler)
|
||||||
.event(DatabaseEvent::DeleteRow, delete_row_handler)
|
.event(DatabaseEvent::DeleteRow, delete_row_handler)
|
||||||
.event(DatabaseEvent::DuplicateRow, duplicate_row_handler)
|
.event(DatabaseEvent::DuplicateRow, duplicate_row_handler)
|
||||||
@ -38,7 +35,7 @@ pub fn init(database_manager: Arc<DatabaseManager>) -> AFPlugin {
|
|||||||
.event(DatabaseEvent::GetCell, get_cell_handler)
|
.event(DatabaseEvent::GetCell, get_cell_handler)
|
||||||
.event(DatabaseEvent::UpdateCell, update_cell_handler)
|
.event(DatabaseEvent::UpdateCell, update_cell_handler)
|
||||||
// SelectOption
|
// SelectOption
|
||||||
.event(DatabaseEvent::NewSelectOption, new_select_option_handler)
|
.event(DatabaseEvent::CreateSelectOption, new_select_option_handler)
|
||||||
.event(DatabaseEvent::UpdateSelectOption, update_select_option_handler)
|
.event(DatabaseEvent::UpdateSelectOption, update_select_option_handler)
|
||||||
.event(DatabaseEvent::GetSelectOptionCellData, get_select_option_handler)
|
.event(DatabaseEvent::GetSelectOptionCellData, get_select_option_handler)
|
||||||
.event(DatabaseEvent::UpdateSelectOptionCell, update_select_option_cell_handler)
|
.event(DatabaseEvent::UpdateSelectOptionCell, update_select_option_cell_handler)
|
||||||
@ -118,11 +115,11 @@ pub enum DatabaseEvent {
|
|||||||
#[event(input = "DeleteFieldPayloadPB")]
|
#[event(input = "DeleteFieldPayloadPB")]
|
||||||
DeleteField = 14,
|
DeleteField = 14,
|
||||||
|
|
||||||
/// [SwitchToField] event is used to update the current Field's type.
|
/// [UpdateFieldType] event is used to update the current Field's type.
|
||||||
/// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
|
/// It will insert a new FieldTypeOptionData if the new FieldType doesn't exist before, otherwise
|
||||||
/// reuse the existing FieldTypeOptionData. You could check the [DatabaseRevisionPad] for more details.
|
/// reuse the existing FieldTypeOptionData. You could check the [DatabaseRevisionPad] for more details.
|
||||||
#[event(input = "EditFieldChangesetPB")]
|
#[event(input = "UpdateFieldTypePayloadPB")]
|
||||||
SwitchToField = 20,
|
UpdateFieldType = 20,
|
||||||
|
|
||||||
/// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
|
/// [DuplicateField] event is used to duplicate a Field. The duplicated field data is kind of
|
||||||
/// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
|
/// deep copy of the target field. The passed in [DuplicateFieldPayloadPB] is the context that is
|
||||||
@ -145,21 +142,21 @@ pub enum DatabaseEvent {
|
|||||||
///
|
///
|
||||||
/// Return the [TypeOptionPB] if there are no errors.
|
/// Return the [TypeOptionPB] if there are no errors.
|
||||||
#[event(input = "TypeOptionPathPB", output = "TypeOptionPB")]
|
#[event(input = "TypeOptionPathPB", output = "TypeOptionPB")]
|
||||||
GetFieldTypeOption = 23,
|
GetTypeOption = 23,
|
||||||
|
|
||||||
/// [CreateFieldTypeOption] event is used to create a new FieldTypeOptionData.
|
/// [CreateTypeOption] event is used to create a new FieldTypeOptionData.
|
||||||
#[event(input = "CreateFieldPayloadPB", output = "TypeOptionPB")]
|
#[event(input = "CreateFieldPayloadPB", output = "TypeOptionPB")]
|
||||||
CreateFieldTypeOption = 24,
|
CreateTypeOption = 24,
|
||||||
|
|
||||||
/// [NewSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
|
/// [CreateSelectOption] event is used to create a new select option. Returns a [SelectOptionPB] if
|
||||||
/// there are no errors.
|
/// there are no errors.
|
||||||
#[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
|
#[event(input = "CreateSelectOptionPayloadPB", output = "SelectOptionPB")]
|
||||||
NewSelectOption = 30,
|
CreateSelectOption = 30,
|
||||||
|
|
||||||
/// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
|
/// [GetSelectOptionCellData] event is used to get the select option data for cell editing.
|
||||||
/// [CellPathPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
|
/// [CellIdPB] locate which cell data that will be read from. The return value, [SelectOptionCellDataPB]
|
||||||
/// contains the available options and the currently selected options.
|
/// contains the available options and the currently selected options.
|
||||||
#[event(input = "CellPathPB", output = "SelectOptionCellDataPB")]
|
#[event(input = "CellIdPB", output = "SelectOptionCellDataPB")]
|
||||||
GetSelectOptionCellData = 31,
|
GetSelectOptionCellData = 31,
|
||||||
|
|
||||||
/// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
|
/// [UpdateSelectOption] event is used to update a FieldTypeOptionData whose field_type is
|
||||||
@ -171,8 +168,8 @@ pub enum DatabaseEvent {
|
|||||||
#[event(input = "SelectOptionChangesetPB")]
|
#[event(input = "SelectOptionChangesetPB")]
|
||||||
UpdateSelectOption = 32,
|
UpdateSelectOption = 32,
|
||||||
|
|
||||||
#[event(input = "CreateTableRowPayloadPB", output = "RowPB")]
|
#[event(input = "CreateRowPayloadPB", output = "RowPB")]
|
||||||
CreateTableRow = 50,
|
CreateRow = 50,
|
||||||
|
|
||||||
/// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
|
/// [GetRow] event is used to get the row data,[RowPB]. [OptionalRowPB] is a wrapper that enables
|
||||||
/// to return a nullable row data.
|
/// to return a nullable row data.
|
||||||
@ -188,7 +185,7 @@ pub enum DatabaseEvent {
|
|||||||
#[event(input = "MoveRowPayloadPB")]
|
#[event(input = "MoveRowPayloadPB")]
|
||||||
MoveRow = 54,
|
MoveRow = 54,
|
||||||
|
|
||||||
#[event(input = "CellPathPB", output = "CellPB")]
|
#[event(input = "CellIdPB", output = "CellPB")]
|
||||||
GetCell = 70,
|
GetCell = 70,
|
||||||
|
|
||||||
/// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],
|
/// [UpdateCell] event is used to update the cell content. The passed in data, [CellChangesetPB],
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::DatabaseViewLayout;
|
use crate::entities::LayoutTypePB;
|
||||||
use crate::services::grid_editor::{
|
use crate::services::grid_editor::{
|
||||||
DatabaseRevisionEditor, GridRevisionCloudService, GridRevisionMergeable, GridRevisionSerde,
|
DatabaseRevisionEditor, GridRevisionCloudService, GridRevisionMergeable, GridRevisionSerde,
|
||||||
};
|
};
|
||||||
@ -196,7 +196,7 @@ impl DatabaseManager {
|
|||||||
pub async fn make_database_view_data(
|
pub async fn make_database_view_data(
|
||||||
_user_id: &str,
|
_user_id: &str,
|
||||||
view_id: &str,
|
view_id: &str,
|
||||||
layout: DatabaseViewLayout,
|
layout: LayoutTypePB,
|
||||||
database_manager: Arc<DatabaseManager>,
|
database_manager: Arc<DatabaseManager>,
|
||||||
build_context: BuildDatabaseContext,
|
build_context: BuildDatabaseContext,
|
||||||
) -> FlowyResult<Bytes> {
|
) -> FlowyResult<Bytes> {
|
||||||
|
@ -5,21 +5,32 @@ const OBSERVABLE_CATEGORY: &str = "Grid";
|
|||||||
#[derive(ProtoBuf_Enum, Debug)]
|
#[derive(ProtoBuf_Enum, Debug)]
|
||||||
pub enum DatabaseNotification {
|
pub enum DatabaseNotification {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
DidCreateBlock = 11,
|
/// Trigger after inserting/deleting/updating a row
|
||||||
DidUpdateDatabaseViewRows = 20,
|
DidUpdateViewRows = 20,
|
||||||
DidUpdateDatabaseViewRowsVisibility = 21,
|
/// Trigger when the visibility of the row was changed. For example, updating the filter will trigger the notification
|
||||||
DidUpdateDatabaseFields = 22,
|
DidUpdateViewRowsVisibility = 21,
|
||||||
DidUpdateRow = 30,
|
/// Trigger after inserting/deleting/updating a field
|
||||||
|
DidUpdateFields = 22,
|
||||||
|
/// Trigger after editing a cell
|
||||||
DidUpdateCell = 40,
|
DidUpdateCell = 40,
|
||||||
|
/// Trigger after editing a field properties including rename,update type option, etc
|
||||||
DidUpdateField = 50,
|
DidUpdateField = 50,
|
||||||
DidUpdateGroupView = 60,
|
/// Trigger after the number of groups is changed
|
||||||
DidUpdateGroup = 61,
|
DidUpdateGroups = 60,
|
||||||
DidGroupByNewField = 62,
|
/// Trigger after inserting/deleting/updating/moving a row
|
||||||
|
DidUpdateGroupRow = 61,
|
||||||
|
/// Trigger when setting a new grouping field
|
||||||
|
DidGroupByField = 62,
|
||||||
|
/// Trigger after inserting/deleting/updating a filter
|
||||||
DidUpdateFilter = 63,
|
DidUpdateFilter = 63,
|
||||||
|
/// Trigger after inserting/deleting/updating a sort
|
||||||
DidUpdateSort = 64,
|
DidUpdateSort = 64,
|
||||||
|
/// Trigger after the sort configurations are changed
|
||||||
DidReorderRows = 65,
|
DidReorderRows = 65,
|
||||||
|
/// Trigger after editing the row that hit the sort rule
|
||||||
DidReorderSingleRow = 66,
|
DidReorderSingleRow = 66,
|
||||||
DidUpdateDatabaseSetting = 70,
|
/// Trigger when the settings of the database are changed
|
||||||
|
DidUpdateSettings = 70,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for DatabaseNotification {
|
impl std::default::Default for DatabaseNotification {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::CellPathPB;
|
use crate::entities::CellIdPB;
|
||||||
use crate::services::cell::{
|
use crate::services::cell::{
|
||||||
CellProtobufBlobParser, DecodedCellData, FromCellChangesetString, FromCellString, ToCellChangesetString,
|
CellProtobufBlobParser, DecodedCellData, FromCellChangesetString, FromCellString, ToCellChangesetString,
|
||||||
};
|
};
|
||||||
@ -23,7 +23,7 @@ pub struct DateCellDataPB {
|
|||||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||||
pub struct DateChangesetPB {
|
pub struct DateChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub cell_path: CellPathPB,
|
pub cell_path: CellIdPB,
|
||||||
|
|
||||||
#[pb(index = 2, one_of)]
|
#[pb(index = 2, one_of)]
|
||||||
pub date: Option<String>,
|
pub date: Option<String>,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::entities::parser::NotEmptyStr;
|
use crate::entities::parser::NotEmptyStr;
|
||||||
use crate::entities::{CellPathPB, CellPathParams, FieldType};
|
use crate::entities::{CellIdPB, CellIdParams, FieldType};
|
||||||
use crate::services::cell::{
|
use crate::services::cell::{
|
||||||
CellDataDecoder, CellProtobufBlobParser, DecodedCellData, FromCellChangesetString, FromCellString,
|
CellDataDecoder, CellProtobufBlobParser, DecodedCellData, FromCellChangesetString, FromCellString,
|
||||||
ToCellChangesetString,
|
ToCellChangesetString,
|
||||||
@ -366,7 +366,7 @@ impl CellProtobufBlobParser for SelectOptionCellDataParser {
|
|||||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||||
pub struct SelectOptionCellChangesetPB {
|
pub struct SelectOptionCellChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub cell_identifier: CellPathPB,
|
pub cell_identifier: CellIdPB,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub insert_option_ids: Vec<String>,
|
pub insert_option_ids: Vec<String>,
|
||||||
@ -376,7 +376,7 @@ pub struct SelectOptionCellChangesetPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct SelectOptionCellChangesetParams {
|
pub struct SelectOptionCellChangesetParams {
|
||||||
pub cell_identifier: CellPathParams,
|
pub cell_identifier: CellIdParams,
|
||||||
pub insert_option_ids: Vec<String>,
|
pub insert_option_ids: Vec<String>,
|
||||||
pub delete_option_ids: Vec<String>,
|
pub delete_option_ids: Vec<String>,
|
||||||
}
|
}
|
||||||
@ -385,7 +385,7 @@ impl TryInto<SelectOptionCellChangesetParams> for SelectOptionCellChangesetPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<SelectOptionCellChangesetParams, Self::Error> {
|
fn try_into(self) -> Result<SelectOptionCellChangesetParams, Self::Error> {
|
||||||
let cell_identifier: CellPathParams = self.cell_identifier.try_into()?;
|
let cell_identifier: CellIdParams = self.cell_identifier.try_into()?;
|
||||||
let insert_option_ids = self
|
let insert_option_ids = self
|
||||||
.insert_option_ids
|
.insert_option_ids
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -487,7 +487,7 @@ pub struct SelectOptionCellDataPB {
|
|||||||
#[derive(Clone, Debug, Default, ProtoBuf)]
|
#[derive(Clone, Debug, Default, ProtoBuf)]
|
||||||
pub struct SelectOptionChangesetPB {
|
pub struct SelectOptionChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub cell_identifier: CellPathPB,
|
pub cell_identifier: CellIdPB,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub insert_options: Vec<SelectOptionPB>,
|
pub insert_options: Vec<SelectOptionPB>,
|
||||||
@ -500,7 +500,7 @@ pub struct SelectOptionChangesetPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct SelectOptionChangeset {
|
pub struct SelectOptionChangeset {
|
||||||
pub cell_path: CellPathParams,
|
pub cell_path: CellIdParams,
|
||||||
pub insert_options: Vec<SelectOptionPB>,
|
pub insert_options: Vec<SelectOptionPB>,
|
||||||
pub update_options: Vec<SelectOptionPB>,
|
pub update_options: Vec<SelectOptionPB>,
|
||||||
pub delete_options: Vec<SelectOptionPB>,
|
pub delete_options: Vec<SelectOptionPB>,
|
||||||
|
@ -4,7 +4,7 @@ use crate::services::cell::{AnyTypeCache, AtomicCellDataCache, AtomicCellFilterC
|
|||||||
use crate::services::field::*;
|
use crate::services::field::*;
|
||||||
use crate::services::filter::{FilterChangeset, FilterResult, FilterResultNotification, FilterType};
|
use crate::services::filter::{FilterChangeset, FilterResult, FilterResultNotification, FilterType};
|
||||||
use crate::services::row::DatabaseBlockRowRevision;
|
use crate::services::row::DatabaseBlockRowRevision;
|
||||||
use crate::services::view_editor::{GridViewChanged, GridViewChangedNotifier};
|
use crate::services::view_editor::{DatabaseViewChanged, GridViewChangedNotifier};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
|
use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
|
||||||
@ -149,7 +149,9 @@ impl FilterController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _ = self.notifier.send(GridViewChanged::FilterNotification(notification));
|
let _ = self
|
||||||
|
.notifier
|
||||||
|
.send(DatabaseViewChanged::FilterNotification(notification));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -185,7 +187,9 @@ impl FilterController {
|
|||||||
visible_rows,
|
visible_rows,
|
||||||
};
|
};
|
||||||
tracing::Span::current().record("filter_result", format!("{:?}", ¬ification).as_str());
|
tracing::Span::current().record("filter_result", format!("{:?}", ¬ification).as_str());
|
||||||
let _ = self.notifier.send(GridViewChanged::FilterNotification(notification));
|
let _ = self
|
||||||
|
.notifier
|
||||||
|
.send(DatabaseViewChanged::FilterNotification(notification));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::CellPathParams;
|
use crate::entities::CellIdParams;
|
||||||
use crate::entities::*;
|
use crate::entities::*;
|
||||||
use crate::manager::DatabaseUser;
|
use crate::manager::DatabaseUser;
|
||||||
use crate::notification::{send_notification, DatabaseNotification};
|
use crate::notification::{send_notification, DatabaseNotification};
|
||||||
@ -16,7 +16,7 @@ use crate::services::filter::FilterType;
|
|||||||
use crate::services::grid_editor_trait_impl::GridViewEditorDelegateImpl;
|
use crate::services::grid_editor_trait_impl::GridViewEditorDelegateImpl;
|
||||||
use crate::services::persistence::block_index::BlockIndexCache;
|
use crate::services::persistence::block_index::BlockIndexCache;
|
||||||
use crate::services::row::{DatabaseBlockRow, DatabaseBlockRowRevision, RowRevisionBuilder};
|
use crate::services::row::{DatabaseBlockRow, DatabaseBlockRowRevision, RowRevisionBuilder};
|
||||||
use crate::services::view_editor::{DatabaseViewManager, GridViewChanged};
|
use crate::services::view_editor::{DatabaseViewChanged, DatabaseViewManager};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use flowy_client_sync::client_database::{DatabaseRevisionChangeset, DatabaseRevisionPad, JsonDeserializer};
|
use flowy_client_sync::client_database::{DatabaseRevisionChangeset, DatabaseRevisionPad, JsonDeserializer};
|
||||||
use flowy_client_sync::errors::{SyncError, SyncResult};
|
use flowy_client_sync::errors::{SyncError, SyncResult};
|
||||||
@ -428,7 +428,7 @@ impl DatabaseRevisionEditor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<GridViewChanged>> {
|
pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<DatabaseViewChanged>> {
|
||||||
self.view_manager.subscribe_view_changed(view_id).await
|
self.view_manager.subscribe_view_changed(view_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +437,7 @@ impl DatabaseRevisionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the cell data that encoded in protobuf.
|
/// Returns the cell data that encoded in protobuf.
|
||||||
pub async fn get_cell(&self, params: &CellPathParams) -> Option<CellPB> {
|
pub async fn get_cell(&self, params: &CellIdParams) -> Option<CellPB> {
|
||||||
let (field_type, cell_bytes) = self.get_type_cell_protobuf(params).await?;
|
let (field_type, cell_bytes) = self.get_type_cell_protobuf(params).await?;
|
||||||
Some(CellPB::new(
|
Some(CellPB::new(
|
||||||
¶ms.field_id,
|
¶ms.field_id,
|
||||||
@ -453,7 +453,7 @@ impl DatabaseRevisionEditor {
|
|||||||
/// Number: 123 => $123 if the currency set.
|
/// Number: 123 => $123 if the currency set.
|
||||||
/// Date: 1653609600 => May 27,2022
|
/// Date: 1653609600 => May 27,2022
|
||||||
///
|
///
|
||||||
pub async fn get_cell_display_str(&self, params: &CellPathParams) -> String {
|
pub async fn get_cell_display_str(&self, params: &CellIdParams) -> String {
|
||||||
let display_str = || async {
|
let display_str = || async {
|
||||||
let field_rev = self.get_field_rev(¶ms.field_id).await?;
|
let field_rev = self.get_field_rev(¶ms.field_id).await?;
|
||||||
let field_type: FieldType = field_rev.ty.into();
|
let field_type: FieldType = field_rev.ty.into();
|
||||||
@ -470,12 +470,12 @@ impl DatabaseRevisionEditor {
|
|||||||
display_str().await.unwrap_or_default()
|
display_str().await.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_cell_protobuf(&self, params: &CellPathParams) -> Option<CellProtobufBlob> {
|
pub async fn get_cell_protobuf(&self, params: &CellIdParams) -> Option<CellProtobufBlob> {
|
||||||
let (_, cell_data) = self.get_type_cell_protobuf(params).await?;
|
let (_, cell_data) = self.get_type_cell_protobuf(params).await?;
|
||||||
Some(cell_data)
|
Some(cell_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_type_cell_protobuf(&self, params: &CellPathParams) -> Option<(FieldType, CellProtobufBlob)> {
|
async fn get_type_cell_protobuf(&self, params: &CellIdParams) -> Option<(FieldType, CellProtobufBlob)> {
|
||||||
let field_rev = self.get_field_rev(¶ms.field_id).await?;
|
let field_rev = self.get_field_rev(¶ms.field_id).await?;
|
||||||
let (_, row_rev) = self.block_manager.get_row_rev(¶ms.row_id).await.ok()??;
|
let (_, row_rev) = self.block_manager.get_row_rev(¶ms.row_id).await.ok()??;
|
||||||
let cell_rev = row_rev.cells.get(¶ms.field_id)?.clone();
|
let cell_rev = row_rev.cells.get(¶ms.field_id)?.clone();
|
||||||
@ -861,7 +861,7 @@ impl DatabaseRevisionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn notify_did_update_grid(&self, changeset: DatabaseFieldChangesetPB) -> FlowyResult<()> {
|
async fn notify_did_update_grid(&self, changeset: DatabaseFieldChangesetPB) -> FlowyResult<()> {
|
||||||
send_notification(&self.database_id, DatabaseNotification::DidUpdateDatabaseFields)
|
send_notification(&self.database_id, DatabaseNotification::DidUpdateFields)
|
||||||
.payload(changeset)
|
.payload(changeset)
|
||||||
.send();
|
.send();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{GroupPB, GroupRowsNotificationPB, GroupViewChangesetPB, InsertedGroupPB};
|
use crate::entities::{GroupChangesetPB, GroupPB, GroupRowsNotificationPB, InsertedGroupPB};
|
||||||
use crate::services::cell::DecodedCellData;
|
use crate::services::cell::DecodedCellData;
|
||||||
use crate::services::group::controller::MoveGroupRowContext;
|
use crate::services::group::controller::MoveGroupRowContext;
|
||||||
use crate::services::group::Group;
|
use crate::services::group::Group;
|
||||||
@ -91,7 +91,7 @@ pub trait GroupControllerActions: Send + Sync {
|
|||||||
fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<DidMoveGroupRowResult>;
|
fn move_group_row(&mut self, context: MoveGroupRowContext) -> FlowyResult<DidMoveGroupRowResult>;
|
||||||
|
|
||||||
/// Update the group if the corresponding field is changed
|
/// Update the group if the corresponding field is changed
|
||||||
fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>>;
|
fn did_update_group_field(&mut self, field_rev: &FieldRevision) -> FlowyResult<Option<GroupChangesetPB>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{GroupPB, GroupViewChangesetPB, InsertedGroupPB};
|
use crate::entities::{GroupChangesetPB, GroupPB, InsertedGroupPB};
|
||||||
use crate::services::field::RowSingleCellData;
|
use crate::services::field::RowSingleCellData;
|
||||||
use crate::services::group::{default_group_configuration, GeneratedGroupContext, Group};
|
use crate::services::group::{default_group_configuration, GeneratedGroupContext, Group};
|
||||||
use flowy_error::{FlowyError, FlowyResult};
|
use flowy_error::{FlowyError, FlowyResult};
|
||||||
@ -223,7 +223,7 @@ where
|
|||||||
pub(crate) fn init_groups(
|
pub(crate) fn init_groups(
|
||||||
&mut self,
|
&mut self,
|
||||||
generated_group_context: GeneratedGroupContext,
|
generated_group_context: GeneratedGroupContext,
|
||||||
) -> FlowyResult<Option<GroupViewChangesetPB>> {
|
) -> FlowyResult<Option<GroupChangesetPB>> {
|
||||||
let GeneratedGroupContext {
|
let GeneratedGroupContext {
|
||||||
no_status_group,
|
no_status_group,
|
||||||
group_configs,
|
group_configs,
|
||||||
@ -312,7 +312,7 @@ where
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let changeset = GroupViewChangesetPB {
|
let changeset = GroupChangesetPB {
|
||||||
view_id: self.view_id.clone(),
|
view_id: self.view_id.clone(),
|
||||||
initial_groups,
|
initial_groups,
|
||||||
deleted_groups: deleted_group_ids,
|
deleted_groups: deleted_group_ids,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{GroupRowsNotificationPB, GroupViewChangesetPB, InsertedRowPB, RowPB};
|
use crate::entities::{GroupChangesetPB, GroupRowsNotificationPB, InsertedRowPB, RowPB};
|
||||||
use crate::services::cell::{get_type_cell_protobuf, CellProtobufBlobParser, DecodedCellData};
|
use crate::services::cell::{get_type_cell_protobuf, CellProtobufBlobParser, DecodedCellData};
|
||||||
|
|
||||||
use crate::services::group::action::{
|
use crate::services::group::action::{
|
||||||
@ -319,7 +319,7 @@ where
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>> {
|
fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupChangesetPB>> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{GroupViewChangesetPB, RowPB};
|
use crate::entities::{GroupChangesetPB, RowPB};
|
||||||
use crate::services::group::action::{DidMoveGroupRowResult, DidUpdateGroupRowResult, GroupControllerActions};
|
use crate::services::group::action::{DidMoveGroupRowResult, DidUpdateGroupRowResult, GroupControllerActions};
|
||||||
use crate::services::group::{Group, GroupController, MoveGroupRowContext};
|
use crate::services::group::{Group, GroupController, MoveGroupRowContext};
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
@ -86,7 +86,7 @@ impl GroupControllerActions for DefaultGroupController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupViewChangesetPB>> {
|
fn did_update_group_field(&mut self, _field_rev: &FieldRevision) -> FlowyResult<Option<GroupChangesetPB>> {
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
use crate::entities::{AlterFilterParams, DatabaseSettingChangesetParams, DatabaseViewLayout, DeleteFilterParams};
|
use crate::entities::{AlterFilterParams, DatabaseSettingChangesetParams, DeleteFilterParams, LayoutTypePB};
|
||||||
|
|
||||||
pub struct GridSettingChangesetBuilder {
|
pub struct GridSettingChangesetBuilder {
|
||||||
params: DatabaseSettingChangesetParams,
|
params: DatabaseSettingChangesetParams,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridSettingChangesetBuilder {
|
impl GridSettingChangesetBuilder {
|
||||||
pub fn new(grid_id: &str, layout_type: &DatabaseViewLayout) -> Self {
|
pub fn new(grid_id: &str, layout_type: &LayoutTypePB) -> Self {
|
||||||
let params = DatabaseSettingChangesetParams {
|
let params = DatabaseSettingChangesetParams {
|
||||||
database_id: grid_id.to_string(),
|
database_id: grid_id.to_string(),
|
||||||
layout_type: layout_type.clone().into(),
|
layout_type: layout_type.clone().into(),
|
||||||
|
@ -3,7 +3,7 @@ use crate::entities::SortChangesetNotificationPB;
|
|||||||
use crate::services::cell::{AtomicCellDataCache, TypeCellData};
|
use crate::services::cell::{AtomicCellDataCache, TypeCellData};
|
||||||
use crate::services::field::{default_order, TypeOptionCellExt};
|
use crate::services::field::{default_order, TypeOptionCellExt};
|
||||||
use crate::services::sort::{ReorderAllRowsResult, ReorderSingleRowResult, SortChangeset, SortType};
|
use crate::services::sort::{ReorderAllRowsResult, ReorderSingleRowResult, SortChangeset, SortType};
|
||||||
use crate::services::view_editor::{GridViewChanged, GridViewChangedNotifier};
|
use crate::services::view_editor::{DatabaseViewChanged, GridViewChangedNotifier};
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
|
use flowy_task::{QualityOfService, Task, TaskContent, TaskDispatcher};
|
||||||
use grid_model::{CellRevision, FieldRevision, RowRevision, SortCondition, SortRevision};
|
use grid_model::{CellRevision, FieldRevision, RowRevision, SortCondition, SortRevision};
|
||||||
@ -92,7 +92,7 @@ impl SortController {
|
|||||||
|
|
||||||
let _ = self
|
let _ = self
|
||||||
.notifier
|
.notifier
|
||||||
.send(GridViewChanged::ReorderAllRowsNotification(notification));
|
.send(DatabaseViewChanged::ReorderAllRowsNotification(notification));
|
||||||
}
|
}
|
||||||
SortEvent::RowDidChanged(row_id) => {
|
SortEvent::RowDidChanged(row_id) => {
|
||||||
let old_row_index = self.row_index_cache.get(&row_id).cloned();
|
let old_row_index = self.row_index_cache.get(&row_id).cloned();
|
||||||
@ -111,7 +111,7 @@ impl SortController {
|
|||||||
};
|
};
|
||||||
let _ = self
|
let _ = self
|
||||||
.notifier
|
.notifier
|
||||||
.send(GridViewChanged::ReorderSingleRowNotification(notification));
|
.send(DatabaseViewChanged::ReorderSingleRowNotification(notification));
|
||||||
}
|
}
|
||||||
_ => tracing::trace!("The row index cache is outdated"),
|
_ => tracing::trace!("The row index cache is outdated"),
|
||||||
}
|
}
|
||||||
|
@ -7,15 +7,15 @@ use futures::stream::StreamExt;
|
|||||||
use tokio::sync::broadcast;
|
use tokio::sync::broadcast;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum GridViewChanged {
|
pub enum DatabaseViewChanged {
|
||||||
FilterNotification(FilterResultNotification),
|
FilterNotification(FilterResultNotification),
|
||||||
ReorderAllRowsNotification(ReorderAllRowsResult),
|
ReorderAllRowsNotification(ReorderAllRowsResult),
|
||||||
ReorderSingleRowNotification(ReorderSingleRowResult),
|
ReorderSingleRowNotification(ReorderSingleRowResult),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type GridViewChangedNotifier = broadcast::Sender<GridViewChanged>;
|
pub type GridViewChangedNotifier = broadcast::Sender<DatabaseViewChanged>;
|
||||||
|
|
||||||
pub(crate) struct GridViewChangedReceiverRunner(pub(crate) Option<broadcast::Receiver<GridViewChanged>>);
|
pub(crate) struct GridViewChangedReceiverRunner(pub(crate) Option<broadcast::Receiver<DatabaseViewChanged>>);
|
||||||
impl GridViewChangedReceiverRunner {
|
impl GridViewChangedReceiverRunner {
|
||||||
pub(crate) async fn run(mut self) {
|
pub(crate) async fn run(mut self) {
|
||||||
let mut receiver = self.0.take().expect("Only take once");
|
let mut receiver = self.0.take().expect("Only take once");
|
||||||
@ -30,21 +30,18 @@ impl GridViewChangedReceiverRunner {
|
|||||||
stream
|
stream
|
||||||
.for_each(|changed| async {
|
.for_each(|changed| async {
|
||||||
match changed {
|
match changed {
|
||||||
GridViewChanged::FilterNotification(notification) => {
|
DatabaseViewChanged::FilterNotification(notification) => {
|
||||||
let changeset = ViewRowsVisibilityChangesetPB {
|
let changeset = ViewRowsVisibilityChangesetPB {
|
||||||
view_id: notification.view_id,
|
view_id: notification.view_id,
|
||||||
visible_rows: notification.visible_rows,
|
visible_rows: notification.visible_rows,
|
||||||
invisible_rows: notification.invisible_rows,
|
invisible_rows: notification.invisible_rows,
|
||||||
};
|
};
|
||||||
|
|
||||||
send_notification(
|
send_notification(&changeset.view_id, DatabaseNotification::DidUpdateViewRowsVisibility)
|
||||||
&changeset.view_id,
|
.payload(changeset)
|
||||||
DatabaseNotification::DidUpdateDatabaseViewRowsVisibility,
|
.send()
|
||||||
)
|
|
||||||
.payload(changeset)
|
|
||||||
.send()
|
|
||||||
}
|
}
|
||||||
GridViewChanged::ReorderAllRowsNotification(notification) => {
|
DatabaseViewChanged::ReorderAllRowsNotification(notification) => {
|
||||||
let row_orders = ReorderAllRowsPB {
|
let row_orders = ReorderAllRowsPB {
|
||||||
row_orders: notification.row_orders,
|
row_orders: notification.row_orders,
|
||||||
};
|
};
|
||||||
@ -52,7 +49,7 @@ impl GridViewChangedReceiverRunner {
|
|||||||
.payload(row_orders)
|
.payload(row_orders)
|
||||||
.send()
|
.send()
|
||||||
}
|
}
|
||||||
GridViewChanged::ReorderSingleRowNotification(notification) => {
|
DatabaseViewChanged::ReorderSingleRowNotification(notification) => {
|
||||||
let reorder_row = ReorderSingleRowPB {
|
let reorder_row = ReorderSingleRowPB {
|
||||||
row_id: notification.row_id,
|
row_id: notification.row_id,
|
||||||
old_index: notification.old_index as i32,
|
old_index: notification.old_index as i32,
|
||||||
|
@ -184,7 +184,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
send_notification(&self.view_id, DatabaseNotification::DidUpdateDatabaseViewRows)
|
send_notification(&self.view_id, DatabaseNotification::DidUpdateViewRows)
|
||||||
.payload(changeset)
|
.payload(changeset)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Some(Ok(result)) = result {
|
if let Some(Ok(result)) = result {
|
||||||
let mut changeset = GroupViewChangesetPB {
|
let mut changeset = GroupChangesetPB {
|
||||||
view_id: self.view_id.clone(),
|
view_id: self.view_id.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@ -274,7 +274,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
tracing::trace!("Delete group after editing the row: {:?}", delete_group);
|
tracing::trace!("Delete group after editing the row: {:?}", delete_group);
|
||||||
changeset.deleted_groups.push(delete_group.group_id);
|
changeset.deleted_groups.push(delete_group.group_id);
|
||||||
}
|
}
|
||||||
self.notify_did_update_view(changeset).await;
|
self.notify_did_update_groups(changeset).await;
|
||||||
|
|
||||||
tracing::trace!("Group changesets after editing the row: {:?}", result.row_changesets);
|
tracing::trace!("Group changesets after editing the row: {:?}", result.row_changesets);
|
||||||
for changeset in result.row_changesets {
|
for changeset in result.row_changesets {
|
||||||
@ -312,7 +312,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
if let Some(result) = result {
|
if let Some(result) = result {
|
||||||
let mut changeset = GroupViewChangesetPB {
|
let mut changeset = GroupChangesetPB {
|
||||||
view_id: self.view_id.clone(),
|
view_id: self.view_id.clone(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@ -320,7 +320,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
tracing::info!("Delete group after moving the row: {:?}", delete_group);
|
tracing::info!("Delete group after moving the row: {:?}", delete_group);
|
||||||
changeset.deleted_groups.push(delete_group.group_id);
|
changeset.deleted_groups.push(delete_group.group_id);
|
||||||
}
|
}
|
||||||
self.notify_did_update_view(changeset).await;
|
self.notify_did_update_groups(changeset).await;
|
||||||
|
|
||||||
for changeset in result.row_changesets {
|
for changeset in result.row_changesets {
|
||||||
self.notify_did_update_group_rows(changeset).await;
|
self.notify_did_update_group_rows(changeset).await;
|
||||||
@ -356,7 +356,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
index: index as i32,
|
index: index as i32,
|
||||||
};
|
};
|
||||||
|
|
||||||
let changeset = GroupViewChangesetPB {
|
let changeset = GroupChangesetPB {
|
||||||
view_id: self.view_id.clone(),
|
view_id: self.view_id.clone(),
|
||||||
inserted_groups: vec![inserted_group],
|
inserted_groups: vec![inserted_group],
|
||||||
deleted_groups: vec![params.from_group_id.clone()],
|
deleted_groups: vec![params.from_group_id.clone()],
|
||||||
@ -364,7 +364,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
initial_groups: vec![],
|
initial_groups: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
self.notify_did_update_view(changeset).await;
|
self.notify_did_update_groups(changeset).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -632,7 +632,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
*self.group_controller.write().await = new_group_controller;
|
*self.group_controller.write().await = new_group_controller;
|
||||||
let changeset = GroupViewChangesetPB {
|
let changeset = GroupChangesetPB {
|
||||||
view_id: self.view_id.clone(),
|
view_id: self.view_id.clone(),
|
||||||
initial_groups: new_groups,
|
initial_groups: new_groups,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@ -640,7 +640,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
|
|
||||||
debug_assert!(!changeset.is_empty());
|
debug_assert!(!changeset.is_empty());
|
||||||
if !changeset.is_empty() {
|
if !changeset.is_empty() {
|
||||||
send_notification(&changeset.view_id, DatabaseNotification::DidGroupByNewField)
|
send_notification(&changeset.view_id, DatabaseNotification::DidGroupByField)
|
||||||
.payload(changeset)
|
.payload(changeset)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
@ -654,13 +654,13 @@ impl DatabaseViewRevisionEditor {
|
|||||||
|
|
||||||
async fn notify_did_update_setting(&self) {
|
async fn notify_did_update_setting(&self) {
|
||||||
let setting = self.get_view_setting().await;
|
let setting = self.get_view_setting().await;
|
||||||
send_notification(&self.view_id, DatabaseNotification::DidUpdateDatabaseSetting)
|
send_notification(&self.view_id, DatabaseNotification::DidUpdateSettings)
|
||||||
.payload(setting)
|
.payload(setting)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn notify_did_update_group_rows(&self, payload: GroupRowsNotificationPB) {
|
pub async fn notify_did_update_group_rows(&self, payload: GroupRowsNotificationPB) {
|
||||||
send_notification(&payload.group_id, DatabaseNotification::DidUpdateGroup)
|
send_notification(&payload.group_id, DatabaseNotification::DidUpdateGroupRow)
|
||||||
.payload(payload)
|
.payload(payload)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
@ -679,8 +679,8 @@ impl DatabaseViewRevisionEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn notify_did_update_view(&self, changeset: GroupViewChangesetPB) {
|
async fn notify_did_update_groups(&self, changeset: GroupChangesetPB) {
|
||||||
send_notification(&self.view_id, DatabaseNotification::DidUpdateGroupView)
|
send_notification(&self.view_id, DatabaseNotification::DidUpdateGroups)
|
||||||
.payload(changeset)
|
.payload(changeset)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ impl DatabaseViewManager {
|
|||||||
self.view_editors.write().await.remove(view_id).await;
|
self.view_editors.write().await.remove(view_id).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<GridViewChanged>> {
|
pub async fn subscribe_view_changed(&self, view_id: &str) -> FlowyResult<broadcast::Receiver<DatabaseViewChanged>> {
|
||||||
Ok(self.get_view_editor(view_id).await?.notifier.subscribe())
|
Ok(self.get_view_editor(view_id).await?.notifier.subscribe())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::entities::{DatabaseViewLayout, DatabaseViewSettingPB, ViewLayoutConfigPB};
|
use crate::entities::{DatabaseViewSettingPB, LayoutTypePB, ViewLayoutPB};
|
||||||
use crate::services::field::RowSingleCellData;
|
use crate::services::field::RowSingleCellData;
|
||||||
use crate::services::filter::{FilterController, FilterDelegate, FilterType};
|
use crate::services::filter::{FilterController, FilterDelegate, FilterType};
|
||||||
use crate::services::group::{GroupConfigurationReader, GroupConfigurationWriter};
|
use crate::services::group::{GroupConfigurationReader, GroupConfigurationWriter};
|
||||||
@ -132,13 +132,13 @@ pub(crate) async fn apply_change(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_grid_setting(view_pad: &GridViewRevisionPad, field_revs: &[Arc<FieldRevision>]) -> DatabaseViewSettingPB {
|
pub fn make_grid_setting(view_pad: &GridViewRevisionPad, field_revs: &[Arc<FieldRevision>]) -> DatabaseViewSettingPB {
|
||||||
let layout_type: DatabaseViewLayout = view_pad.layout.clone().into();
|
let layout_type: LayoutTypePB = view_pad.layout.clone().into();
|
||||||
let filters = view_pad.get_all_filters(field_revs);
|
let filters = view_pad.get_all_filters(field_revs);
|
||||||
let group_configurations = view_pad.get_groups_by_field_revs(field_revs);
|
let group_configurations = view_pad.get_groups_by_field_revs(field_revs);
|
||||||
let sorts = view_pad.get_all_sorts(field_revs);
|
let sorts = view_pad.get_all_sorts(field_revs);
|
||||||
DatabaseViewSettingPB {
|
DatabaseViewSettingPB {
|
||||||
layouts: ViewLayoutConfigPB::all(),
|
support_layouts: ViewLayoutPB::all(),
|
||||||
layout_type,
|
current_layout: layout_type,
|
||||||
filters: filters.into(),
|
filters: filters.into(),
|
||||||
sorts: sorts.into(),
|
sorts: sorts.into(),
|
||||||
group_configurations: group_configurations.into(),
|
group_configurations: group_configurations.into(),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow};
|
use crate::grid::block_test::script::RowScript::{AssertCell, CreateRow};
|
||||||
use crate::grid::block_test::util::GridRowTestBuilder;
|
use crate::grid::block_test::util::GridRowTestBuilder;
|
||||||
use crate::grid::database_editor::DatabaseEditorTest;
|
use crate::grid::database_editor::DatabaseEditorTest;
|
||||||
use flowy_database::entities::{CellPathParams, CreateRowParams, DatabaseViewLayout, FieldType, RowPB};
|
use flowy_database::entities::{CellIdParams, CreateRowParams, FieldType, LayoutTypePB, RowPB};
|
||||||
use flowy_database::services::field::*;
|
use flowy_database::services::field::*;
|
||||||
use flowy_database::services::row::DatabaseBlockRow;
|
use flowy_database::services::row::DatabaseBlockRow;
|
||||||
use grid_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision};
|
use grid_model::{GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision};
|
||||||
@ -79,7 +79,7 @@ impl DatabaseRowTest {
|
|||||||
database_id: self.editor.database_id.clone(),
|
database_id: self.editor.database_id.clone(),
|
||||||
start_row_id: None,
|
start_row_id: None,
|
||||||
group_id: None,
|
group_id: None,
|
||||||
layout: DatabaseViewLayout::Grid,
|
layout: LayoutTypePB::Grid,
|
||||||
};
|
};
|
||||||
let row_order = self.editor.create_row(params).await.unwrap();
|
let row_order = self.editor.create_row(params).await.unwrap();
|
||||||
self.row_by_row_id.insert(row_order.row_id().to_owned(), row_order);
|
self.row_by_row_id.insert(row_order.row_id().to_owned(), row_order);
|
||||||
@ -112,7 +112,7 @@ impl DatabaseRowTest {
|
|||||||
field_type,
|
field_type,
|
||||||
expected,
|
expected,
|
||||||
} => {
|
} => {
|
||||||
let id = CellPathParams {
|
let id = CellIdParams {
|
||||||
database_id: self.view_id.clone(),
|
database_id: self.view_id.clone(),
|
||||||
field_id,
|
field_id,
|
||||||
row_id,
|
row_id,
|
||||||
@ -157,7 +157,7 @@ impl DatabaseRowTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn compare_cell_content(&self, cell_id: CellPathParams, field_type: FieldType, expected: String) {
|
async fn compare_cell_content(&self, cell_id: CellIdParams, field_type: FieldType, expected: String) {
|
||||||
match field_type {
|
match field_type {
|
||||||
FieldType::RichText => {
|
FieldType::RichText => {
|
||||||
let cell_data = self
|
let cell_data = self
|
||||||
|
@ -25,28 +25,28 @@ pub struct DatabaseEditorTest {
|
|||||||
|
|
||||||
impl DatabaseEditorTest {
|
impl DatabaseEditorTest {
|
||||||
pub async fn new_table() -> Self {
|
pub async fn new_table() -> Self {
|
||||||
Self::new(DatabaseViewLayout::Grid).await
|
Self::new(LayoutTypePB::Grid).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new_board() -> Self {
|
pub async fn new_board() -> Self {
|
||||||
Self::new(DatabaseViewLayout::Board).await
|
Self::new(LayoutTypePB::Board).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new(layout: DatabaseViewLayout) -> Self {
|
pub async fn new(layout: LayoutTypePB) -> Self {
|
||||||
let sdk = FlowySDKTest::default();
|
let sdk = FlowySDKTest::default();
|
||||||
let _ = sdk.init_user().await;
|
let _ = sdk.init_user().await;
|
||||||
let test = match layout {
|
let test = match layout {
|
||||||
DatabaseViewLayout::Grid => {
|
LayoutTypePB::Grid => {
|
||||||
let build_context = make_test_grid();
|
let build_context = make_test_grid();
|
||||||
let view_data: Bytes = build_context.into();
|
let view_data: Bytes = build_context.into();
|
||||||
ViewTest::new_grid_view(&sdk, view_data.to_vec()).await
|
ViewTest::new_grid_view(&sdk, view_data.to_vec()).await
|
||||||
}
|
}
|
||||||
DatabaseViewLayout::Board => {
|
LayoutTypePB::Board => {
|
||||||
let build_context = make_test_board();
|
let build_context = make_test_board();
|
||||||
let view_data: Bytes = build_context.into();
|
let view_data: Bytes = build_context.into();
|
||||||
ViewTest::new_board_view(&sdk, view_data.to_vec()).await
|
ViewTest::new_board_view(&sdk, view_data.to_vec()).await
|
||||||
}
|
}
|
||||||
DatabaseViewLayout::Calendar => {
|
LayoutTypePB::Calendar => {
|
||||||
let build_context = make_test_calendar();
|
let build_context = make_test_calendar();
|
||||||
let view_data: Bytes = build_context.into();
|
let view_data: Bytes = build_context.into();
|
||||||
ViewTest::new_calendar_view(&sdk, view_data.to_vec()).await
|
ViewTest::new_calendar_view(&sdk, view_data.to_vec()).await
|
||||||
|
@ -7,14 +7,14 @@ use std::time::Duration;
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures::TryFutureExt;
|
use futures::TryFutureExt;
|
||||||
use tokio::sync::broadcast::Receiver;
|
use tokio::sync::broadcast::Receiver;
|
||||||
use flowy_database::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, DatabaseViewLayout, DatabaseSettingChangesetParams, DatabaseViewSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB};
|
use flowy_database::entities::{AlterFilterParams, AlterFilterPayloadPB, DeleteFilterParams, LayoutTypePB, DatabaseSettingChangesetParams, DatabaseViewSettingPB, RowPB, TextFilterConditionPB, FieldType, NumberFilterConditionPB, CheckboxFilterConditionPB, DateFilterConditionPB, DateFilterContentPB, SelectOptionConditionPB, TextFilterPB, NumberFilterPB, CheckboxFilterPB, DateFilterPB, SelectOptionFilterPB, CellChangesetPB, FilterPB, ChecklistFilterConditionPB, ChecklistFilterPB};
|
||||||
use flowy_database::services::field::{SelectOptionCellChangeset, SelectOptionIds};
|
use flowy_database::services::field::{SelectOptionCellChangeset, SelectOptionIds};
|
||||||
use flowy_database::services::setting::GridSettingChangesetBuilder;
|
use flowy_database::services::setting::GridSettingChangesetBuilder;
|
||||||
use grid_model::{FieldRevision, FieldTypeRevision};
|
use grid_model::{FieldRevision, FieldTypeRevision};
|
||||||
use flowy_sqlite::schema::view_table::dsl::view_table;
|
use flowy_sqlite::schema::view_table::dsl::view_table;
|
||||||
use flowy_database::services::cell::insert_select_option_cell;
|
use flowy_database::services::cell::insert_select_option_cell;
|
||||||
use flowy_database::services::filter::FilterType;
|
use flowy_database::services::filter::FilterType;
|
||||||
use flowy_database::services::view_editor::GridViewChanged;
|
use flowy_database::services::view_editor::DatabaseViewChanged;
|
||||||
use crate::grid::database_editor::DatabaseEditorTest;
|
use crate::grid::database_editor::DatabaseEditorTest;
|
||||||
|
|
||||||
pub struct FilterRowChanged {
|
pub struct FilterRowChanged {
|
||||||
@ -101,7 +101,7 @@ pub enum FilterScript {
|
|||||||
|
|
||||||
pub struct DatabaseFilterTest {
|
pub struct DatabaseFilterTest {
|
||||||
inner: DatabaseEditorTest,
|
inner: DatabaseEditorTest,
|
||||||
recv: Option<Receiver<GridViewChanged>>,
|
recv: Option<Receiver<DatabaseViewChanged>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseFilterTest {
|
impl DatabaseFilterTest {
|
||||||
@ -274,7 +274,7 @@ impl DatabaseFilterTest {
|
|||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
match tokio::time::timeout(Duration::from_secs(2), receiver.recv()).await {
|
match tokio::time::timeout(Duration::from_secs(2), receiver.recv()).await {
|
||||||
Ok(changed) => {
|
Ok(changed) => {
|
||||||
match changed.unwrap() { GridViewChanged::FilterNotification(notification) => {
|
match changed.unwrap() { DatabaseViewChanged::FilterNotification(notification) => {
|
||||||
assert_eq!(notification.visible_rows.len(), change.showing_num_of_rows, "visible rows not match");
|
assert_eq!(notification.visible_rows.len(), change.showing_num_of_rows, "visible rows not match");
|
||||||
assert_eq!(notification.invisible_rows.len(), change.hiding_num_of_rows, "invisible rows not match");
|
assert_eq!(notification.invisible_rows.len(), change.hiding_num_of_rows, "invisible rows not match");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::grid::database_editor::DatabaseEditorTest;
|
use crate::grid::database_editor::DatabaseEditorTest;
|
||||||
use flowy_database::entities::{
|
use flowy_database::entities::{
|
||||||
CreateRowParams, DatabaseViewLayout, FieldType, GroupPB, MoveGroupParams, MoveGroupRowParams, RowPB,
|
CreateRowParams, FieldType, GroupPB, LayoutTypePB, MoveGroupParams, MoveGroupRowParams, RowPB,
|
||||||
};
|
};
|
||||||
use flowy_database::services::cell::{delete_select_option_cell, insert_select_option_cell, insert_url_cell};
|
use flowy_database::services::cell::{delete_select_option_cell, insert_select_option_cell, insert_url_cell};
|
||||||
use flowy_database::services::field::{
|
use flowy_database::services::field::{
|
||||||
@ -119,7 +119,7 @@ impl DatabaseGroupTest {
|
|||||||
database_id: self.editor.database_id.clone(),
|
database_id: self.editor.database_id.clone(),
|
||||||
start_row_id: None,
|
start_row_id: None,
|
||||||
group_id: Some(group.group_id.clone()),
|
group_id: Some(group.group_id.clone()),
|
||||||
layout: DatabaseViewLayout::Board,
|
layout: LayoutTypePB::Board,
|
||||||
};
|
};
|
||||||
let _ = self.editor.create_row(params).await.unwrap();
|
let _ = self.editor.create_row(params).await.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::grid::database_editor::DatabaseEditorTest;
|
use crate::grid::database_editor::DatabaseEditorTest;
|
||||||
use async_stream::stream;
|
use async_stream::stream;
|
||||||
use flowy_database::entities::{AlterSortParams, CellPathParams, DeleteSortParams};
|
use flowy_database::entities::{AlterSortParams, CellIdParams, DeleteSortParams};
|
||||||
use flowy_database::services::sort::SortType;
|
use flowy_database::services::sort::SortType;
|
||||||
use flowy_database::services::view_editor::GridViewChanged;
|
use flowy_database::services::view_editor::DatabaseViewChanged;
|
||||||
use futures::stream::StreamExt;
|
use futures::stream::StreamExt;
|
||||||
use grid_model::{FieldRevision, SortCondition, SortRevision};
|
use grid_model::{FieldRevision, SortCondition, SortRevision};
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
@ -39,7 +39,7 @@ pub enum SortScript {
|
|||||||
pub struct DatabaseSortTest {
|
pub struct DatabaseSortTest {
|
||||||
inner: DatabaseEditorTest,
|
inner: DatabaseEditorTest,
|
||||||
pub current_sort_rev: Option<SortRevision>,
|
pub current_sort_rev: Option<SortRevision>,
|
||||||
recv: Option<Receiver<GridViewChanged>>,
|
recv: Option<Receiver<DatabaseViewChanged>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseSortTest {
|
impl DatabaseSortTest {
|
||||||
@ -85,7 +85,7 @@ impl DatabaseSortTest {
|
|||||||
let mut cells = vec![];
|
let mut cells = vec![];
|
||||||
let rows = self.editor.get_database(&self.view_id).await.unwrap().rows;
|
let rows = self.editor.get_database(&self.view_id).await.unwrap().rows;
|
||||||
for row in rows {
|
for row in rows {
|
||||||
let params = CellPathParams {
|
let params = CellIdParams {
|
||||||
database_id: self.view_id.clone(),
|
database_id: self.view_id.clone(),
|
||||||
field_id: field_id.clone(),
|
field_id: field_id.clone(),
|
||||||
row_id: row.id,
|
row_id: row.id,
|
||||||
@ -125,7 +125,7 @@ impl DatabaseSortTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn assert_sort_changed(
|
async fn assert_sort_changed(
|
||||||
mut receiver: Receiver<GridViewChanged>,
|
mut receiver: Receiver<DatabaseViewChanged>,
|
||||||
new_row_orders: Vec<String>,
|
new_row_orders: Vec<String>,
|
||||||
old_row_orders: Vec<String>,
|
old_row_orders: Vec<String>,
|
||||||
) {
|
) {
|
||||||
@ -141,8 +141,8 @@ async fn assert_sort_changed(
|
|||||||
stream
|
stream
|
||||||
.for_each(|changed| async {
|
.for_each(|changed| async {
|
||||||
match changed {
|
match changed {
|
||||||
GridViewChanged::ReorderAllRowsNotification(_changed) => {}
|
DatabaseViewChanged::ReorderAllRowsNotification(_changed) => {}
|
||||||
GridViewChanged::ReorderSingleRowNotification(changed) => {
|
DatabaseViewChanged::ReorderSingleRowNotification(changed) => {
|
||||||
let mut old_row_orders = old_row_orders.clone();
|
let mut old_row_orders = old_row_orders.clone();
|
||||||
let old = old_row_orders.remove(changed.old_index);
|
let old = old_row_orders.remove(changed.old_index);
|
||||||
old_row_orders.insert(changed.new_index, old);
|
old_row_orders.insert(changed.new_index, old);
|
||||||
|
@ -61,7 +61,6 @@ impl AsRef<str> for FolderId {
|
|||||||
|
|
||||||
pub struct FolderManager {
|
pub struct FolderManager {
|
||||||
pub user: Arc<dyn WorkspaceUser>,
|
pub user: Arc<dyn WorkspaceUser>,
|
||||||
pub(crate) cloud_service: Arc<dyn FolderCouldServiceV1>,
|
|
||||||
pub(crate) persistence: Arc<FolderPersistence>,
|
pub(crate) persistence: Arc<FolderPersistence>,
|
||||||
pub(crate) workspace_controller: Arc<WorkspaceController>,
|
pub(crate) workspace_controller: Arc<WorkspaceController>,
|
||||||
pub(crate) app_controller: Arc<AppController>,
|
pub(crate) app_controller: Arc<AppController>,
|
||||||
@ -118,7 +117,6 @@ impl FolderManager {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
user,
|
user,
|
||||||
cloud_service,
|
|
||||||
persistence,
|
persistence,
|
||||||
workspace_controller,
|
workspace_controller,
|
||||||
app_controller,
|
app_controller,
|
||||||
@ -249,7 +247,7 @@ impl DefaultFolderBuilder {
|
|||||||
let repeated_workspace = RepeatedWorkspacePB {
|
let repeated_workspace = RepeatedWorkspacePB {
|
||||||
items: vec![workspace_rev.into()],
|
items: vec![workspace_rev.into()],
|
||||||
};
|
};
|
||||||
send_notification(token, FolderNotification::UserCreateWorkspace)
|
send_notification(token, FolderNotification::DidCreateWorkspace)
|
||||||
.payload(repeated_workspace)
|
.payload(repeated_workspace)
|
||||||
.send();
|
.send();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -5,19 +5,28 @@ const OBSERVABLE_CATEGORY: &str = "Workspace";
|
|||||||
#[derive(ProtoBuf_Enum, Debug)]
|
#[derive(ProtoBuf_Enum, Debug)]
|
||||||
pub(crate) enum FolderNotification {
|
pub(crate) enum FolderNotification {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
UserCreateWorkspace = 10,
|
/// Trigger after creating a workspace
|
||||||
UserDeleteWorkspace = 11,
|
DidCreateWorkspace = 1,
|
||||||
WorkspaceUpdated = 12,
|
/// Trigger after deleting a workspace
|
||||||
WorkspaceListUpdated = 13,
|
DidDeleteWorkspace = 2,
|
||||||
WorkspaceAppsChanged = 14,
|
/// Trigger after updating a workspace
|
||||||
WorkspaceSetting = 15,
|
DidUpdateWorkspace = 3,
|
||||||
AppUpdated = 21,
|
/// Trigger when the number of apps of the workspace is changed
|
||||||
ViewUpdated = 31,
|
DidUpdateWorkspaceApps = 4,
|
||||||
ViewDeleted = 32,
|
/// Trigger when the settings of the workspace are changed. The changes including the latest visiting view, etc
|
||||||
ViewRestored = 33,
|
DidUpdateWorkspaceSetting = 5,
|
||||||
ViewMoveToTrash = 34,
|
/// Trigger when the properties including rename,update description of the app are changed
|
||||||
UserUnauthorized = 100,
|
DidUpdateApp = 20,
|
||||||
TrashUpdated = 1000,
|
/// Trigger when the properties including rename,update description of the view are changed
|
||||||
|
DidUpdateView = 30,
|
||||||
|
/// Trigger after deleting the view
|
||||||
|
DidDeleteView = 31,
|
||||||
|
/// Trigger when restore the view from trash
|
||||||
|
DidRestoreView = 32,
|
||||||
|
/// Trigger after moving the view to trash
|
||||||
|
DidMoveViewToTrash = 33,
|
||||||
|
/// Trigger when the number of trash is changed
|
||||||
|
DidUpdateTrash = 34,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for FolderNotification {
|
impl std::default::Default for FolderNotification {
|
||||||
|
@ -72,7 +72,6 @@ impl AppController {
|
|||||||
Ok(Some(app))
|
Ok(Some(app))
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
self.read_app_on_server(params)?;
|
|
||||||
Ok(app)
|
Ok(app)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +88,7 @@ impl AppController {
|
|||||||
})
|
})
|
||||||
.await?
|
.await?
|
||||||
.into();
|
.into();
|
||||||
send_notification(&app_id, FolderNotification::AppUpdated)
|
send_notification(&app_id, FolderNotification::DidUpdateApp)
|
||||||
.payload(app)
|
.payload(app)
|
||||||
.send();
|
.send();
|
||||||
self.update_app_on_server(params)?;
|
self.update_app_on_server(params)?;
|
||||||
@ -147,34 +146,6 @@ impl AppController {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(self), err)]
|
|
||||||
fn read_app_on_server(&self, params: AppIdPB) -> Result<(), FlowyError> {
|
|
||||||
let token = self.user.token()?;
|
|
||||||
let server = self.cloud_service.clone();
|
|
||||||
let persistence = self.persistence.clone();
|
|
||||||
tokio::spawn(async move {
|
|
||||||
match server.read_app(&token, params).await {
|
|
||||||
Ok(Some(app_rev)) => {
|
|
||||||
match persistence
|
|
||||||
.begin_transaction(|transaction| transaction.create_app(app_rev.clone()))
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(_) => {
|
|
||||||
let app: AppPB = app_rev.into();
|
|
||||||
send_notification(&app.id, FolderNotification::AppUpdated)
|
|
||||||
.payload(app)
|
|
||||||
.send();
|
|
||||||
}
|
|
||||||
Err(e) => log::error!("Save app failed: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None) => {}
|
|
||||||
Err(e) => log::error!("Read app failed: {:?}", e),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn listen_trash_controller_event(&self) {
|
fn listen_trash_controller_event(&self) {
|
||||||
let mut rx = self.trash_controller.subscribe();
|
let mut rx = self.trash_controller.subscribe();
|
||||||
let persistence = self.persistence.clone();
|
let persistence = self.persistence.clone();
|
||||||
@ -246,7 +217,7 @@ fn notify_apps_changed<'a>(
|
|||||||
.map(|app_rev| app_rev.into())
|
.map(|app_rev| app_rev.into())
|
||||||
.collect();
|
.collect();
|
||||||
let repeated_app = RepeatedAppPB { items };
|
let repeated_app = RepeatedAppPB { items };
|
||||||
send_notification(workspace_id, FolderNotification::WorkspaceAppsChanged)
|
send_notification(workspace_id, FolderNotification::DidUpdateWorkspaceApps)
|
||||||
.payload(repeated_app)
|
.payload(repeated_app)
|
||||||
.send();
|
.send();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -206,7 +206,7 @@ impl TrashController {
|
|||||||
fn notify_trash_changed<T: Into<RepeatedTrashPB>>(repeated_trash: T) {
|
fn notify_trash_changed<T: Into<RepeatedTrashPB>>(repeated_trash: T) {
|
||||||
let repeated_trash = repeated_trash.into();
|
let repeated_trash = repeated_trash.into();
|
||||||
tracing::Span::current().record("n_trash", repeated_trash.len());
|
tracing::Span::current().record("n_trash", repeated_trash.len());
|
||||||
send_anonymous_notification(FolderNotification::TrashUpdated)
|
send_anonymous_notification(FolderNotification::DidUpdateTrash)
|
||||||
.payload(repeated_trash)
|
.payload(repeated_trash)
|
||||||
.send();
|
.send();
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use crate::manager::{ViewDataProcessor, ViewDataProcessorMap};
|
|||||||
use crate::{
|
use crate::{
|
||||||
entities::{
|
entities::{
|
||||||
trash::{RepeatedTrashIdPB, TrashType},
|
trash::{RepeatedTrashIdPB, TrashType},
|
||||||
view::{CreateViewParams, UpdateViewParams, ViewIdPB, ViewPB},
|
view::{CreateViewParams, UpdateViewParams, ViewPB},
|
||||||
},
|
},
|
||||||
errors::{FlowyError, FlowyResult},
|
errors::{FlowyError, FlowyResult},
|
||||||
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
event_map::{FolderCouldServiceV1, WorkspaceUser},
|
||||||
@ -194,7 +194,7 @@ impl ViewController {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
send_notification(view_id, FolderNotification::ViewMoveToTrash)
|
send_notification(view_id, FolderNotification::DidMoveViewToTrash)
|
||||||
.payload(deleted_view)
|
.payload(deleted_view)
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
@ -260,7 +260,7 @@ impl ViewController {
|
|||||||
transaction.update_view(changeset)?;
|
transaction.update_view(changeset)?;
|
||||||
let view_rev = transaction.read_view(&view_id)?;
|
let view_rev = transaction.read_view(&view_id)?;
|
||||||
let view: ViewPB = view_rev.clone().into();
|
let view: ViewPB = view_rev.clone().into();
|
||||||
send_notification(&view_id, FolderNotification::ViewUpdated)
|
send_notification(&view_id, FolderNotification::DidUpdateView)
|
||||||
.payload(view)
|
.payload(view)
|
||||||
.send();
|
.send();
|
||||||
notify_views_changed(&view_rev.app_id, self.trash_controller.clone(), &transaction)?;
|
notify_views_changed(&view_rev.app_id, self.trash_controller.clone(), &transaction)?;
|
||||||
@ -310,35 +310,6 @@ impl ViewController {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "debug", skip(self), err)]
|
|
||||||
fn read_view_on_server(&self, params: ViewIdPB) -> Result<(), FlowyError> {
|
|
||||||
let token = self.user.token()?;
|
|
||||||
let server = self.cloud_service.clone();
|
|
||||||
let persistence = self.persistence.clone();
|
|
||||||
// TODO: Retry with RetryAction?
|
|
||||||
tokio::spawn(async move {
|
|
||||||
match server.read_view(&token, params).await {
|
|
||||||
Ok(Some(view_rev)) => {
|
|
||||||
match persistence
|
|
||||||
.begin_transaction(|transaction| transaction.create_view(view_rev.clone()))
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
Ok(_) => {
|
|
||||||
let view: ViewPB = view_rev.into();
|
|
||||||
send_notification(&view.id, FolderNotification::ViewUpdated)
|
|
||||||
.payload(view)
|
|
||||||
.send();
|
|
||||||
}
|
|
||||||
Err(e) => log::error!("Save view failed: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None) => {}
|
|
||||||
Err(e) => log::error!("Read view failed: {:?}", e),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn listen_trash_can_event(&self) {
|
fn listen_trash_can_event(&self) {
|
||||||
let mut rx = self.trash_controller.subscribe();
|
let mut rx = self.trash_controller.subscribe();
|
||||||
let persistence = self.persistence.clone();
|
let persistence = self.persistence.clone();
|
||||||
@ -407,7 +378,7 @@ async fn handle_trash_event(
|
|||||||
let view_revs = read_local_views_with_transaction(identifiers, &transaction)?;
|
let view_revs = read_local_views_with_transaction(identifiers, &transaction)?;
|
||||||
for view_rev in view_revs {
|
for view_rev in view_revs {
|
||||||
notify_views_changed(&view_rev.app_id, trash_can.clone(), &transaction)?;
|
notify_views_changed(&view_rev.app_id, trash_can.clone(), &transaction)?;
|
||||||
notify_dart(view_rev.into(), FolderNotification::ViewDeleted);
|
notify_dart(view_rev.into(), FolderNotification::DidDeleteView);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@ -420,7 +391,7 @@ async fn handle_trash_event(
|
|||||||
let view_revs = read_local_views_with_transaction(identifiers, &transaction)?;
|
let view_revs = read_local_views_with_transaction(identifiers, &transaction)?;
|
||||||
for view_rev in view_revs {
|
for view_rev in view_revs {
|
||||||
notify_views_changed(&view_rev.app_id, trash_can.clone(), &transaction)?;
|
notify_views_changed(&view_rev.app_id, trash_can.clone(), &transaction)?;
|
||||||
notify_dart(view_rev.into(), FolderNotification::ViewRestored);
|
notify_dart(view_rev.into(), FolderNotification::DidRestoreView);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@ -506,7 +477,7 @@ fn notify_views_changed<'a>(
|
|||||||
app_rev.belongings.retain(|view| !trash_ids.contains(&view.id));
|
app_rev.belongings.retain(|view| !trash_ids.contains(&view.id));
|
||||||
let app: AppPB = app_rev.into();
|
let app: AppPB = app_rev.into();
|
||||||
|
|
||||||
send_notification(belong_to_id, FolderNotification::AppUpdated)
|
send_notification(belong_to_id, FolderNotification::DidUpdateApp)
|
||||||
.payload(app)
|
.payload(app)
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ impl WorkspaceController {
|
|||||||
.map(|workspace_rev| workspace_rev.into())
|
.map(|workspace_rev| workspace_rev.into())
|
||||||
.collect();
|
.collect();
|
||||||
let repeated_workspace = RepeatedWorkspacePB { items: workspaces };
|
let repeated_workspace = RepeatedWorkspacePB { items: workspaces };
|
||||||
send_notification(&token, FolderNotification::UserCreateWorkspace)
|
send_notification(&token, FolderNotification::DidCreateWorkspace)
|
||||||
.payload(repeated_workspace)
|
.payload(repeated_workspace)
|
||||||
.send();
|
.send();
|
||||||
set_current_workspace(&user_id, &workspace.id);
|
set_current_workspace(&user_id, &workspace.id);
|
||||||
@ -73,7 +73,7 @@ impl WorkspaceController {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
send_notification(&workspace_id, FolderNotification::WorkspaceUpdated)
|
send_notification(&workspace_id, FolderNotification::DidUpdateWorkspace)
|
||||||
.payload(workspace)
|
.payload(workspace)
|
||||||
.send();
|
.send();
|
||||||
self.update_workspace_on_server(params)?;
|
self.update_workspace_on_server(params)?;
|
||||||
@ -92,7 +92,7 @@ impl WorkspaceController {
|
|||||||
self.read_workspaces(None, &user_id, &transaction)
|
self.read_workspaces(None, &user_id, &transaction)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
send_notification(&token, FolderNotification::UserDeleteWorkspace)
|
send_notification(&token, FolderNotification::DidDeleteWorkspace)
|
||||||
.payload(repeated_workspace)
|
.payload(repeated_workspace)
|
||||||
.send();
|
.send();
|
||||||
self.delete_workspace_on_server(workspace_id)?;
|
self.delete_workspace_on_server(workspace_id)?;
|
||||||
@ -236,7 +236,7 @@ pub async fn notify_workspace_setting_did_change(
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
send_notification(&token, FolderNotification::WorkspaceSetting)
|
send_notification(&token, FolderNotification::DidUpdateWorkspaceSetting)
|
||||||
.payload(workspace_setting)
|
.payload(workspace_setting)
|
||||||
.send();
|
.send();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -6,7 +6,6 @@ use crate::entities::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
errors::FlowyError,
|
errors::FlowyError,
|
||||||
manager::FolderManager,
|
manager::FolderManager,
|
||||||
notification::{send_notification, FolderNotification},
|
|
||||||
services::{get_current_workspace, read_workspace_apps, WorkspaceController},
|
services::{get_current_workspace, read_workspace_apps, WorkspaceController},
|
||||||
};
|
};
|
||||||
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
|
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
|
||||||
@ -71,7 +70,6 @@ pub(crate) async fn read_workspaces_handler(
|
|||||||
Ok(workspaces)
|
Ok(workspaces)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
let _ = read_workspaces_on_server(folder, user_id, params);
|
|
||||||
data_result(workspaces)
|
data_result(workspaces)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,10 +79,6 @@ pub async fn read_cur_workspace_handler(
|
|||||||
) -> DataResult<WorkspaceSettingPB, FlowyError> {
|
) -> DataResult<WorkspaceSettingPB, FlowyError> {
|
||||||
let user_id = folder.user.user_id()?;
|
let user_id = folder.user.user_id()?;
|
||||||
let workspace_id = get_current_workspace(&user_id)?;
|
let workspace_id = get_current_workspace(&user_id)?;
|
||||||
let params = WorkspaceIdPB {
|
|
||||||
value: Some(workspace_id.clone()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let workspace = folder
|
let workspace = folder
|
||||||
.persistence
|
.persistence
|
||||||
.begin_transaction(|transaction| {
|
.begin_transaction(|transaction| {
|
||||||
@ -101,60 +95,5 @@ pub async fn read_cur_workspace_handler(
|
|||||||
.unwrap_or(None)
|
.unwrap_or(None)
|
||||||
.map(|view_rev| view_rev.into());
|
.map(|view_rev| view_rev.into());
|
||||||
let setting = WorkspaceSettingPB { workspace, latest_view };
|
let setting = WorkspaceSettingPB { workspace, latest_view };
|
||||||
let _ = read_workspaces_on_server(folder, user_id, params);
|
|
||||||
data_result(setting)
|
data_result(setting)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(folder_manager), err)]
|
|
||||||
fn read_workspaces_on_server(
|
|
||||||
folder_manager: AFPluginState<Arc<FolderManager>>,
|
|
||||||
user_id: String,
|
|
||||||
params: WorkspaceIdPB,
|
|
||||||
) -> Result<(), FlowyError> {
|
|
||||||
let (token, server) = (folder_manager.user.token()?, folder_manager.cloud_service.clone());
|
|
||||||
let persistence = folder_manager.persistence.clone();
|
|
||||||
|
|
||||||
tokio::spawn(async move {
|
|
||||||
let workspace_revs = server.read_workspace(&token, params).await?;
|
|
||||||
persistence
|
|
||||||
.begin_transaction(|transaction| {
|
|
||||||
for workspace_rev in &workspace_revs {
|
|
||||||
let m_workspace = workspace_rev.clone();
|
|
||||||
let app_revs = m_workspace.apps.clone();
|
|
||||||
transaction.create_workspace(&user_id, m_workspace)?;
|
|
||||||
tracing::trace!("Save {} apps", app_revs.len());
|
|
||||||
for app_rev in app_revs {
|
|
||||||
let view_revs = app_rev.belongings.clone();
|
|
||||||
match transaction.create_app(app_rev) {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(e) => log::error!("create app failed: {:?}", e),
|
|
||||||
}
|
|
||||||
|
|
||||||
tracing::trace!("Save {} views", view_revs.len());
|
|
||||||
for view_rev in view_revs {
|
|
||||||
match transaction.create_view(view_rev) {
|
|
||||||
Ok(_) => {}
|
|
||||||
Err(e) => log::error!("create view failed: {:?}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let repeated_workspace = RepeatedWorkspacePB {
|
|
||||||
items: workspace_revs
|
|
||||||
.into_iter()
|
|
||||||
.map(|workspace_rev| workspace_rev.into())
|
|
||||||
.collect(),
|
|
||||||
};
|
|
||||||
|
|
||||||
send_notification(&token, FolderNotification::WorkspaceListUpdated)
|
|
||||||
.payload(repeated_workspace)
|
|
||||||
.send();
|
|
||||||
Result::<(), FlowyError>::Ok(())
|
|
||||||
});
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user