mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Feat/database view (#1875)
* chore: rename structs * chore: add todos * chore: hidden database id * refactor: add database folder, prepare to extract the view * refactor: rename grid-model to datbase-model * ci: fix warnings
This commit is contained in:
parent
346a09b2ae
commit
f76d722b4c
2
.github/workflows/tauri_ci.yaml
vendored
2
.github/workflows/tauri_ci.yaml
vendored
@ -74,7 +74,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
mkdir dist
|
mkdir dist
|
||||||
npm install
|
npm install
|
||||||
cargo make --cwd .. build_tauri_backend
|
cargo make --cwd .. tauri_build
|
||||||
yarn && yarn build
|
yarn && yarn build
|
||||||
|
|
||||||
- uses: tauri-apps/tauri-action@v0
|
- uses: tauri-apps/tauri-action@v0
|
||||||
|
@ -45,7 +45,7 @@ class BoardDataController {
|
|||||||
BoardDataController({required ViewPB view})
|
BoardDataController({required ViewPB view})
|
||||||
: viewId = view.id,
|
: viewId = view.id,
|
||||||
_listener = BoardListener(view.id),
|
_listener = BoardListener(view.id),
|
||||||
_databaseFFIService = DatabaseFFIService(databaseId: view.id),
|
_databaseFFIService = DatabaseFFIService(viewId: view.id),
|
||||||
fieldController = GridFieldController(databaseId: view.id) {
|
fieldController = GridFieldController(databaseId: view.id) {
|
||||||
//
|
//
|
||||||
_viewCache = DatabaseViewCache(
|
_viewCache = DatabaseViewCache(
|
||||||
|
@ -152,7 +152,7 @@ class GridCellController<T, D> extends Equatable {
|
|||||||
_cellDataPersistence = cellDataPersistence,
|
_cellDataPersistence = cellDataPersistence,
|
||||||
_fieldNotifier = fieldNotifier,
|
_fieldNotifier = fieldNotifier,
|
||||||
_fieldService = FieldService(
|
_fieldService = FieldService(
|
||||||
databaseId: cellId.databaseId,
|
viewId: cellId.databaseId,
|
||||||
fieldId: cellId.fieldInfo.id,
|
fieldId: cellId.fieldInfo.id,
|
||||||
),
|
),
|
||||||
_cacheKey = GridCellCacheKey(
|
_cacheKey = GridCellCacheKey(
|
||||||
|
@ -175,7 +175,7 @@ class DateCalBloc extends Bloc<DateCalEvent, DateCalState> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final result = await FieldService.updateFieldTypeOption(
|
final result = await FieldService.updateFieldTypeOption(
|
||||||
databaseId: cellController.databaseId,
|
viewId: cellController.databaseId,
|
||||||
fieldId: cellController.fieldInfo.id,
|
fieldId: cellController.fieldInfo.id,
|
||||||
typeOptionData: newDateTypeOption.writeToBuffer(),
|
typeOptionData: newDateTypeOption.writeToBuffer(),
|
||||||
);
|
);
|
||||||
|
@ -13,7 +13,7 @@ class FieldActionSheetBloc
|
|||||||
|
|
||||||
FieldActionSheetBloc({required GridFieldCellContext fieldCellContext})
|
FieldActionSheetBloc({required GridFieldCellContext fieldCellContext})
|
||||||
: fieldService = FieldService(
|
: fieldService = FieldService(
|
||||||
databaseId: fieldCellContext.databaseId,
|
viewId: fieldCellContext.viewId,
|
||||||
fieldId: fieldCellContext.field.id,
|
fieldId: fieldCellContext.field.id,
|
||||||
),
|
),
|
||||||
super(
|
super(
|
||||||
|
@ -16,7 +16,7 @@ class FieldCellBloc extends Bloc<FieldCellEvent, FieldCellState> {
|
|||||||
required GridFieldCellContext cellContext,
|
required GridFieldCellContext cellContext,
|
||||||
}) : _fieldListener = SingleFieldListener(fieldId: cellContext.field.id),
|
}) : _fieldListener = SingleFieldListener(fieldId: cellContext.field.id),
|
||||||
_fieldService = FieldService(
|
_fieldService = FieldService(
|
||||||
databaseId: cellContext.databaseId, fieldId: cellContext.field.id),
|
viewId: cellContext.viewId, fieldId: cellContext.field.id),
|
||||||
super(FieldCellState.initial(cellContext)) {
|
super(FieldCellState.initial(cellContext)) {
|
||||||
on<FieldCellEvent>(
|
on<FieldCellEvent>(
|
||||||
(event, emit) async {
|
(event, emit) async {
|
||||||
@ -80,7 +80,7 @@ class FieldCellState with _$FieldCellState {
|
|||||||
|
|
||||||
factory FieldCellState.initial(GridFieldCellContext cellContext) =>
|
factory FieldCellState.initial(GridFieldCellContext cellContext) =>
|
||||||
FieldCellState(
|
FieldCellState(
|
||||||
databaseId: cellContext.databaseId,
|
databaseId: cellContext.viewId,
|
||||||
field: cellContext.field,
|
field: cellContext.field,
|
||||||
width: cellContext.field.width.toDouble(),
|
width: cellContext.field.width.toDouble(),
|
||||||
);
|
);
|
||||||
|
@ -150,9 +150,9 @@ class GridFieldController {
|
|||||||
GridFieldController({required this.databaseId})
|
GridFieldController({required this.databaseId})
|
||||||
: _fieldListener = DatabaseFieldsListener(databaseId: databaseId),
|
: _fieldListener = DatabaseFieldsListener(databaseId: databaseId),
|
||||||
_settingListener = DatabaseSettingListener(databaseId: databaseId),
|
_settingListener = DatabaseSettingListener(databaseId: databaseId),
|
||||||
_filterFFIService = FilterFFIService(databaseId: databaseId),
|
_filterFFIService = FilterFFIService(viewId: databaseId),
|
||||||
_filtersListener = FiltersListener(viewId: databaseId),
|
_filtersListener = FiltersListener(viewId: databaseId),
|
||||||
_gridFFIService = DatabaseFFIService(databaseId: databaseId),
|
_gridFFIService = DatabaseFFIService(viewId: databaseId),
|
||||||
_sortFFIService = SortFFIService(viewId: databaseId),
|
_sortFFIService = SortFFIService(viewId: databaseId),
|
||||||
_sortsListener = SortsListener(viewId: databaseId),
|
_sortsListener = SortsListener(viewId: databaseId),
|
||||||
_settingFFIService = SettingFFIService(viewId: databaseId) {
|
_settingFFIService = SettingFFIService(viewId: databaseId) {
|
||||||
|
@ -49,7 +49,7 @@ class FieldEditorBloc extends Bloc<FieldEditorEvent, FieldEditorState> {
|
|||||||
() => null,
|
() => null,
|
||||||
(field) {
|
(field) {
|
||||||
final fieldService = FieldService(
|
final fieldService = FieldService(
|
||||||
databaseId: databaseId,
|
viewId: databaseId,
|
||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
);
|
);
|
||||||
fieldService.deleteField();
|
fieldService.deleteField();
|
||||||
|
@ -12,14 +12,14 @@ part 'field_service.freezed.dart';
|
|||||||
///
|
///
|
||||||
/// You could check out the rust-lib/flowy-database/event_map.rs for more information.
|
/// You could check out the rust-lib/flowy-database/event_map.rs for more information.
|
||||||
class FieldService {
|
class FieldService {
|
||||||
final String databaseId;
|
final String viewId;
|
||||||
final String fieldId;
|
final String fieldId;
|
||||||
|
|
||||||
FieldService({required this.databaseId, required this.fieldId});
|
FieldService({required this.viewId, required this.fieldId});
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> moveField(int fromIndex, int toIndex) {
|
Future<Either<Unit, FlowyError>> moveField(int fromIndex, int toIndex) {
|
||||||
final payload = MoveFieldPayloadPB.create()
|
final payload = MoveFieldPayloadPB.create()
|
||||||
..viewId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..fromIndex = fromIndex
|
..fromIndex = fromIndex
|
||||||
..toIndex = toIndex;
|
..toIndex = toIndex;
|
||||||
@ -35,7 +35,7 @@ class FieldService {
|
|||||||
double? width,
|
double? width,
|
||||||
}) {
|
}) {
|
||||||
var payload = FieldChangesetPB.create()
|
var payload = FieldChangesetPB.create()
|
||||||
..databaseId = databaseId
|
..databaseId = viewId
|
||||||
..fieldId = fieldId;
|
..fieldId = fieldId;
|
||||||
|
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
@ -62,12 +62,12 @@ class FieldService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<Either<Unit, FlowyError>> updateFieldTypeOption({
|
static Future<Either<Unit, FlowyError>> updateFieldTypeOption({
|
||||||
required String databaseId,
|
required String viewId,
|
||||||
required String fieldId,
|
required String fieldId,
|
||||||
required List<int> typeOptionData,
|
required List<int> typeOptionData,
|
||||||
}) {
|
}) {
|
||||||
var payload = TypeOptionChangesetPB.create()
|
var payload = TypeOptionChangesetPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..typeOptionData = typeOptionData;
|
..typeOptionData = typeOptionData;
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ class FieldService {
|
|||||||
|
|
||||||
Future<Either<Unit, FlowyError>> deleteField() {
|
Future<Either<Unit, FlowyError>> deleteField() {
|
||||||
final payload = DeleteFieldPayloadPB.create()
|
final payload = DeleteFieldPayloadPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = fieldId;
|
..fieldId = fieldId;
|
||||||
|
|
||||||
return DatabaseEventDeleteField(payload).send();
|
return DatabaseEventDeleteField(payload).send();
|
||||||
@ -84,7 +84,7 @@ class FieldService {
|
|||||||
|
|
||||||
Future<Either<Unit, FlowyError>> duplicateField() {
|
Future<Either<Unit, FlowyError>> duplicateField() {
|
||||||
final payload = DuplicateFieldPayloadPB.create()
|
final payload = DuplicateFieldPayloadPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = fieldId;
|
..fieldId = fieldId;
|
||||||
|
|
||||||
return DatabaseEventDuplicateField(payload).send();
|
return DatabaseEventDuplicateField(payload).send();
|
||||||
@ -94,7 +94,7 @@ class FieldService {
|
|||||||
required FieldType fieldType,
|
required FieldType fieldType,
|
||||||
}) {
|
}) {
|
||||||
final payload = TypeOptionPathPB.create()
|
final payload = TypeOptionPathPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..fieldType = fieldType;
|
..fieldType = fieldType;
|
||||||
return DatabaseEventGetTypeOption(payload).send().then((result) {
|
return DatabaseEventGetTypeOption(payload).send().then((result) {
|
||||||
@ -109,7 +109,7 @@ class FieldService {
|
|||||||
@freezed
|
@freezed
|
||||||
class GridFieldCellContext with _$GridFieldCellContext {
|
class GridFieldCellContext with _$GridFieldCellContext {
|
||||||
const factory GridFieldCellContext({
|
const factory GridFieldCellContext({
|
||||||
required String databaseId,
|
required String viewId,
|
||||||
required FieldPB field,
|
required FieldPB field,
|
||||||
}) = _GridFieldCellContext;
|
}) = _GridFieldCellContext;
|
||||||
}
|
}
|
||||||
|
@ -155,13 +155,13 @@ abstract class TypeOptionFieldDelegate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class IFieldTypeOptionLoader {
|
abstract class IFieldTypeOptionLoader {
|
||||||
String get databaseId;
|
String get viewId;
|
||||||
Future<Either<TypeOptionPB, FlowyError>> load();
|
Future<Either<TypeOptionPB, FlowyError>> load();
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> switchToField(
|
Future<Either<Unit, FlowyError>> switchToField(
|
||||||
String fieldId, FieldType fieldType) {
|
String fieldId, FieldType fieldType) {
|
||||||
final payload = UpdateFieldTypePayloadPB.create()
|
final payload = UpdateFieldTypePayloadPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..fieldType = fieldType;
|
..fieldType = fieldType;
|
||||||
|
|
||||||
@ -174,9 +174,9 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
|||||||
TypeOptionPB? fieldTypeOption;
|
TypeOptionPB? fieldTypeOption;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String databaseId;
|
final String viewId;
|
||||||
NewFieldTypeOptionLoader({
|
NewFieldTypeOptionLoader({
|
||||||
required this.databaseId,
|
required this.viewId,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Creates the field type option if the fieldTypeOption is null.
|
/// Creates the field type option if the fieldTypeOption is null.
|
||||||
@ -185,14 +185,14 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
|||||||
Future<Either<TypeOptionPB, FlowyError>> load() {
|
Future<Either<TypeOptionPB, FlowyError>> load() {
|
||||||
if (fieldTypeOption != null) {
|
if (fieldTypeOption != null) {
|
||||||
final payload = TypeOptionPathPB.create()
|
final payload = TypeOptionPathPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = fieldTypeOption!.field_2.id
|
..fieldId = fieldTypeOption!.field_2.id
|
||||||
..fieldType = fieldTypeOption!.field_2.fieldType;
|
..fieldType = fieldTypeOption!.field_2.fieldType;
|
||||||
|
|
||||||
return DatabaseEventGetTypeOption(payload).send();
|
return DatabaseEventGetTypeOption(payload).send();
|
||||||
} else {
|
} else {
|
||||||
final payload = CreateFieldPayloadPB.create()
|
final payload = CreateFieldPayloadPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldType = FieldType.RichText;
|
..fieldType = FieldType.RichText;
|
||||||
|
|
||||||
return DatabaseEventCreateTypeOption(payload).send().then((result) {
|
return DatabaseEventCreateTypeOption(payload).send().then((result) {
|
||||||
@ -211,18 +211,18 @@ class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
|||||||
/// Uses when editing a existing field
|
/// Uses when editing a existing field
|
||||||
class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
||||||
@override
|
@override
|
||||||
final String databaseId;
|
final String viewId;
|
||||||
final FieldPB field;
|
final FieldPB field;
|
||||||
|
|
||||||
FieldTypeOptionLoader({
|
FieldTypeOptionLoader({
|
||||||
required this.databaseId,
|
required this.viewId,
|
||||||
required this.field,
|
required this.field,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Either<TypeOptionPB, FlowyError>> load() {
|
Future<Either<TypeOptionPB, FlowyError>> load() {
|
||||||
final payload = TypeOptionPathPB.create()
|
final payload = TypeOptionPathPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..fieldId = field.id
|
..fieldId = field.id
|
||||||
..fieldType = field.fieldType;
|
..fieldType = field.fieldType;
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ class TypeOptionDataController {
|
|||||||
}) {
|
}) {
|
||||||
if (fieldInfo != null) {
|
if (fieldInfo != null) {
|
||||||
_typeOptiondata = TypeOptionPB.create()
|
_typeOptiondata = TypeOptionPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = databaseId
|
||||||
..field_2 = fieldInfo.field;
|
..field_2 = fieldInfo.field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -66,8 +66,7 @@ class TypeOptionDataController {
|
|||||||
|
|
||||||
_fieldNotifier.value = _typeOptiondata.field_2;
|
_fieldNotifier.value = _typeOptiondata.field_2;
|
||||||
|
|
||||||
FieldService(databaseId: databaseId, fieldId: field.id)
|
FieldService(viewId: databaseId, fieldId: field.id).updateField(name: name);
|
||||||
.updateField(name: name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set typeOptionData(List<int> typeOptionData) {
|
set typeOptionData(List<int> typeOptionData) {
|
||||||
@ -78,7 +77,7 @@ class TypeOptionDataController {
|
|||||||
});
|
});
|
||||||
|
|
||||||
FieldService.updateFieldTypeOption(
|
FieldService.updateFieldTypeOption(
|
||||||
databaseId: databaseId,
|
viewId: databaseId,
|
||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
typeOptionData: typeOptionData,
|
typeOptionData: typeOptionData,
|
||||||
);
|
);
|
||||||
|
@ -16,7 +16,7 @@ class CheckboxFilterEditorBloc
|
|||||||
final FilterListener _listener;
|
final FilterListener _listener;
|
||||||
|
|
||||||
CheckboxFilterEditorBloc({required this.filterInfo})
|
CheckboxFilterEditorBloc({required this.filterInfo})
|
||||||
: _ffiService = FilterFFIService(databaseId: filterInfo.viewId),
|
: _ffiService = FilterFFIService(viewId: filterInfo.viewId),
|
||||||
_listener = FilterListener(
|
_listener = FilterListener(
|
||||||
viewId: filterInfo.viewId,
|
viewId: filterInfo.viewId,
|
||||||
filterId: filterInfo.filter.id,
|
filterId: filterInfo.filter.id,
|
||||||
|
@ -18,7 +18,7 @@ class ChecklistFilterEditorBloc
|
|||||||
|
|
||||||
ChecklistFilterEditorBloc({
|
ChecklistFilterEditorBloc({
|
||||||
required this.filterInfo,
|
required this.filterInfo,
|
||||||
}) : _ffiService = FilterFFIService(databaseId: filterInfo.viewId),
|
}) : _ffiService = FilterFFIService(viewId: filterInfo.viewId),
|
||||||
// _selectOptionService =
|
// _selectOptionService =
|
||||||
// SelectOptionFFIService(cellId: cellController.cellId)
|
// SelectOptionFFIService(cellId: cellController.cellId)
|
||||||
_listener = FilterListener(
|
_listener = FilterListener(
|
||||||
|
@ -22,7 +22,7 @@ class GridCreateFilterBloc
|
|||||||
final GridFieldController fieldController;
|
final GridFieldController fieldController;
|
||||||
void Function(List<FieldInfo>)? _onFieldFn;
|
void Function(List<FieldInfo>)? _onFieldFn;
|
||||||
GridCreateFilterBloc({required this.viewId, required this.fieldController})
|
GridCreateFilterBloc({required this.viewId, required this.fieldController})
|
||||||
: _ffiService = FilterFFIService(databaseId: viewId),
|
: _ffiService = FilterFFIService(viewId: viewId),
|
||||||
super(GridCreateFilterState.initial(fieldController.fieldInfos)) {
|
super(GridCreateFilterState.initial(fieldController.fieldInfos)) {
|
||||||
on<GridCreateFilterEvent>(
|
on<GridCreateFilterEvent>(
|
||||||
(event, emit) async {
|
(event, emit) async {
|
||||||
|
@ -15,11 +15,11 @@ import 'package:appflowy_backend/protobuf/flowy-database/util.pb.dart';
|
|||||||
import 'package:fixnum/fixnum.dart' as $fixnum;
|
import 'package:fixnum/fixnum.dart' as $fixnum;
|
||||||
|
|
||||||
class FilterFFIService {
|
class FilterFFIService {
|
||||||
final String databaseId;
|
final String viewId;
|
||||||
const FilterFFIService({required this.databaseId});
|
const FilterFFIService({required this.viewId});
|
||||||
|
|
||||||
Future<Either<List<FilterPB>, FlowyError>> getAllFilters() {
|
Future<Either<List<FilterPB>, FlowyError>> getAllFilters() {
|
||||||
final payload = DatabaseIdPB()..value = databaseId;
|
final payload = DatabaseViewIdPB()..value = viewId;
|
||||||
|
|
||||||
return DatabaseEventGetAllFilters(payload).send().then((result) {
|
return DatabaseEventGetAllFilters(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
@ -171,7 +171,7 @@ class FilterFFIService {
|
|||||||
var insertFilterPayload = AlterFilterPayloadPB.create()
|
var insertFilterPayload = AlterFilterPayloadPB.create()
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..fieldType = fieldType
|
..fieldType = fieldType
|
||||||
..viewId = databaseId
|
..viewId = viewId
|
||||||
..data = data;
|
..data = data;
|
||||||
|
|
||||||
if (filterId != null) {
|
if (filterId != null) {
|
||||||
@ -179,7 +179,7 @@ class FilterFFIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final payload = DatabaseSettingChangesetPB.create()
|
final payload = DatabaseSettingChangesetPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..alterFilter = insertFilterPayload;
|
..alterFilter = insertFilterPayload;
|
||||||
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
@ -200,11 +200,11 @@ class FilterFFIService {
|
|||||||
final deleteFilterPayload = DeleteFilterPayloadPB.create()
|
final deleteFilterPayload = DeleteFilterPayloadPB.create()
|
||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..filterId = filterId
|
..filterId = filterId
|
||||||
..viewId = databaseId
|
..viewId = viewId
|
||||||
..fieldType = fieldType;
|
..fieldType = fieldType;
|
||||||
|
|
||||||
final payload = DatabaseSettingChangesetPB.create()
|
final payload = DatabaseSettingChangesetPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..deleteFilter = deleteFilterPayload;
|
..deleteFilter = deleteFilterPayload;
|
||||||
|
|
||||||
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
||||||
|
@ -20,7 +20,7 @@ class SelectOptionFilterEditorBloc
|
|||||||
SelectOptionFilterEditorBloc({
|
SelectOptionFilterEditorBloc({
|
||||||
required this.filterInfo,
|
required this.filterInfo,
|
||||||
required this.delegate,
|
required this.delegate,
|
||||||
}) : _ffiService = FilterFFIService(databaseId: filterInfo.viewId),
|
}) : _ffiService = FilterFFIService(viewId: filterInfo.viewId),
|
||||||
_listener = FilterListener(
|
_listener = FilterListener(
|
||||||
viewId: filterInfo.viewId,
|
viewId: filterInfo.viewId,
|
||||||
filterId: filterInfo.filter.id,
|
filterId: filterInfo.filter.id,
|
||||||
|
@ -16,7 +16,7 @@ class TextFilterEditorBloc
|
|||||||
final FilterListener _listener;
|
final FilterListener _listener;
|
||||||
|
|
||||||
TextFilterEditorBloc({required this.filterInfo})
|
TextFilterEditorBloc({required this.filterInfo})
|
||||||
: _ffiService = FilterFFIService(databaseId: filterInfo.viewId),
|
: _ffiService = FilterFFIService(viewId: filterInfo.viewId),
|
||||||
_listener = FilterListener(
|
_listener = FilterListener(
|
||||||
viewId: filterInfo.viewId,
|
viewId: filterInfo.viewId,
|
||||||
filterId: filterInfo.filter.id,
|
filterId: filterInfo.filter.id,
|
||||||
|
@ -32,7 +32,7 @@ class GridController {
|
|||||||
|
|
||||||
GridController({required ViewPB view})
|
GridController({required ViewPB view})
|
||||||
: databaseId = view.id,
|
: databaseId = view.id,
|
||||||
_gridFFIService = DatabaseFFIService(databaseId: view.id),
|
_gridFFIService = DatabaseFFIService(viewId: view.id),
|
||||||
fieldController = GridFieldController(databaseId: view.id) {
|
fieldController = GridFieldController(databaseId: view.id) {
|
||||||
_viewCache = DatabaseViewCache(
|
_viewCache = DatabaseViewCache(
|
||||||
databaseId: databaseId,
|
databaseId: databaseId,
|
||||||
|
@ -46,7 +46,7 @@ class GridHeaderBloc extends Bloc<GridHeaderEvent, GridHeaderState> {
|
|||||||
emit(state.copyWith(fields: fields));
|
emit(state.copyWith(fields: fields));
|
||||||
|
|
||||||
final fieldService =
|
final fieldService =
|
||||||
FieldService(databaseId: databaseId, fieldId: value.field.id);
|
FieldService(viewId: databaseId, fieldId: value.field.id);
|
||||||
final result = await fieldService.moveField(
|
final result = await fieldService.moveField(
|
||||||
value.fromIndex,
|
value.fromIndex,
|
||||||
value.toIndex,
|
value.toIndex,
|
||||||
|
@ -8,20 +8,20 @@ import 'package:appflowy_backend/protobuf/flowy-database/group.pb.dart';
|
|||||||
import 'package:appflowy_backend/protobuf/flowy-database/row_entities.pb.dart';
|
import 'package:appflowy_backend/protobuf/flowy-database/row_entities.pb.dart';
|
||||||
|
|
||||||
class DatabaseFFIService {
|
class DatabaseFFIService {
|
||||||
final String databaseId;
|
final String viewId;
|
||||||
DatabaseFFIService({
|
DatabaseFFIService({
|
||||||
required this.databaseId,
|
required this.viewId,
|
||||||
});
|
});
|
||||||
|
|
||||||
Future<Either<DatabasePB, FlowyError>> openGrid() async {
|
Future<Either<DatabasePB, FlowyError>> openGrid() async {
|
||||||
await FolderEventSetLatestView(ViewIdPB(value: databaseId)).send();
|
await FolderEventSetLatestView(ViewIdPB(value: viewId)).send();
|
||||||
|
|
||||||
final payload = DatabaseIdPB(value: databaseId);
|
final payload = DatabaseViewIdPB(value: viewId);
|
||||||
return DatabaseEventGetDatabase(payload).send();
|
return DatabaseEventGetDatabase(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<RowPB, FlowyError>> createRow({Option<String>? startRowId}) {
|
Future<Either<RowPB, FlowyError>> createRow({Option<String>? startRowId}) {
|
||||||
var payload = CreateRowPayloadPB.create()..databaseId = databaseId;
|
var payload = CreateRowPayloadPB.create()..viewId = viewId;
|
||||||
startRowId?.fold(() => null, (id) => payload.startRowId = id);
|
startRowId?.fold(() => null, (id) => payload.startRowId = id);
|
||||||
return DatabaseEventCreateRow(payload).send();
|
return DatabaseEventCreateRow(payload).send();
|
||||||
}
|
}
|
||||||
@ -31,7 +31,7 @@ class DatabaseFFIService {
|
|||||||
String? startRowId,
|
String? startRowId,
|
||||||
) {
|
) {
|
||||||
CreateBoardCardPayloadPB payload = CreateBoardCardPayloadPB.create()
|
CreateBoardCardPayloadPB payload = CreateBoardCardPayloadPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = viewId
|
||||||
..groupId = groupId;
|
..groupId = groupId;
|
||||||
|
|
||||||
if (startRowId != null) {
|
if (startRowId != null) {
|
||||||
@ -43,7 +43,7 @@ class DatabaseFFIService {
|
|||||||
|
|
||||||
Future<Either<List<FieldPB>, FlowyError>> getFields(
|
Future<Either<List<FieldPB>, FlowyError>> getFields(
|
||||||
{List<FieldIdPB>? fieldIds}) {
|
{List<FieldIdPB>? fieldIds}) {
|
||||||
var payload = GetFieldPayloadPB.create()..databaseId = databaseId;
|
var payload = GetFieldPayloadPB.create()..viewId = viewId;
|
||||||
|
|
||||||
if (fieldIds != null) {
|
if (fieldIds != null) {
|
||||||
payload.fieldIds = RepeatedFieldIdPB(items: fieldIds);
|
payload.fieldIds = RepeatedFieldIdPB(items: fieldIds);
|
||||||
@ -54,12 +54,12 @@ class DatabaseFFIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> closeGrid() {
|
Future<Either<Unit, FlowyError>> closeGrid() {
|
||||||
final request = ViewIdPB(value: databaseId);
|
final request = ViewIdPB(value: viewId);
|
||||||
return FolderEventCloseView(request).send();
|
return FolderEventCloseView(request).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<RepeatedGroupPB, FlowyError>> loadGroups() {
|
Future<Either<RepeatedGroupPB, FlowyError>> loadGroups() {
|
||||||
final payload = DatabaseIdPB(value: databaseId);
|
final payload = DatabaseViewIdPB(value: viewId);
|
||||||
return DatabaseEventGetGroup(payload).send();
|
return DatabaseEventGetGroup(payload).send();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +214,7 @@ class GridRowCache {
|
|||||||
|
|
||||||
Future<void> _loadRow(String rowId) async {
|
Future<void> _loadRow(String rowId) async {
|
||||||
final payload = RowIdPB.create()
|
final payload = RowIdPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = databaseId
|
||||||
..rowId = rowId;
|
..rowId = rowId;
|
||||||
|
|
||||||
final result = await DatabaseEventGetRow(payload).send();
|
final result = await DatabaseEventGetRow(payload).send();
|
||||||
|
@ -27,7 +27,7 @@ class RowDetailBloc extends Bloc<RowDetailEvent, RowDetailState> {
|
|||||||
},
|
},
|
||||||
deleteField: (_DeleteField value) {
|
deleteField: (_DeleteField value) {
|
||||||
final fieldService = FieldService(
|
final fieldService = FieldService(
|
||||||
databaseId: dataController.rowInfo.databaseId,
|
viewId: dataController.rowInfo.databaseId,
|
||||||
fieldId: value.fieldId,
|
fieldId: value.fieldId,
|
||||||
);
|
);
|
||||||
fieldService.deleteField();
|
fieldService.deleteField();
|
||||||
|
@ -14,7 +14,7 @@ class RowFFIService {
|
|||||||
|
|
||||||
Future<Either<RowPB, FlowyError>> createRow(String rowId) {
|
Future<Either<RowPB, FlowyError>> createRow(String rowId) {
|
||||||
final payload = CreateRowPayloadPB.create()
|
final payload = CreateRowPayloadPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = databaseId
|
||||||
..startRowId = rowId;
|
..startRowId = rowId;
|
||||||
|
|
||||||
return DatabaseEventCreateRow(payload).send();
|
return DatabaseEventCreateRow(payload).send();
|
||||||
@ -22,7 +22,7 @@ class RowFFIService {
|
|||||||
|
|
||||||
Future<Either<OptionalRowPB, FlowyError>> getRow(String rowId) {
|
Future<Either<OptionalRowPB, FlowyError>> getRow(String rowId) {
|
||||||
final payload = RowIdPB.create()
|
final payload = RowIdPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = databaseId
|
||||||
..rowId = rowId;
|
..rowId = rowId;
|
||||||
|
|
||||||
return DatabaseEventGetRow(payload).send();
|
return DatabaseEventGetRow(payload).send();
|
||||||
@ -30,7 +30,7 @@ class RowFFIService {
|
|||||||
|
|
||||||
Future<Either<Unit, FlowyError>> deleteRow(String rowId) {
|
Future<Either<Unit, FlowyError>> deleteRow(String rowId) {
|
||||||
final payload = RowIdPB.create()
|
final payload = RowIdPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = databaseId
|
||||||
..rowId = rowId;
|
..rowId = rowId;
|
||||||
|
|
||||||
return DatabaseEventDeleteRow(payload).send();
|
return DatabaseEventDeleteRow(payload).send();
|
||||||
@ -38,7 +38,7 @@ class RowFFIService {
|
|||||||
|
|
||||||
Future<Either<Unit, FlowyError>> duplicateRow(String rowId) {
|
Future<Either<Unit, FlowyError>> duplicateRow(String rowId) {
|
||||||
final payload = RowIdPB.create()
|
final payload = RowIdPB.create()
|
||||||
..databaseId = databaseId
|
..viewId = databaseId
|
||||||
..rowId = rowId;
|
..rowId = rowId;
|
||||||
|
|
||||||
return DatabaseEventDuplicateRow(payload).send();
|
return DatabaseEventDuplicateRow(payload).send();
|
||||||
|
@ -26,7 +26,7 @@ class GridPropertyBloc extends Bloc<GridPropertyEvent, GridPropertyState> {
|
|||||||
},
|
},
|
||||||
setFieldVisibility: (_SetFieldVisibility value) async {
|
setFieldVisibility: (_SetFieldVisibility value) async {
|
||||||
final fieldService =
|
final fieldService =
|
||||||
FieldService(databaseId: databaseId, fieldId: value.fieldId);
|
FieldService(viewId: databaseId, fieldId: value.fieldId);
|
||||||
final result =
|
final result =
|
||||||
await fieldService.updateField(visibility: value.visibility);
|
await fieldService.updateField(visibility: value.visibility);
|
||||||
result.fold(
|
result.fold(
|
||||||
|
@ -12,7 +12,7 @@ class SettingFFIService {
|
|||||||
const SettingFFIService({required this.viewId});
|
const SettingFFIService({required this.viewId});
|
||||||
|
|
||||||
Future<Either<DatabaseViewSettingPB, FlowyError>> getSetting() {
|
Future<Either<DatabaseViewSettingPB, FlowyError>> getSetting() {
|
||||||
final payload = DatabaseIdPB.create()..value = viewId;
|
final payload = DatabaseViewIdPB.create()..value = viewId;
|
||||||
return DatabaseEventGetDatabaseSetting(payload).send();
|
return DatabaseEventGetDatabaseSetting(payload).send();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class SettingFFIService {
|
|||||||
..fieldId = fieldId
|
..fieldId = fieldId
|
||||||
..fieldType = fieldType;
|
..fieldType = fieldType;
|
||||||
final payload = DatabaseSettingChangesetPB.create()
|
final payload = DatabaseSettingChangesetPB.create()
|
||||||
..databaseId = viewId
|
..viewId = viewId
|
||||||
..insertGroup = insertGroupPayload;
|
..insertGroup = insertGroupPayload;
|
||||||
|
|
||||||
return DatabaseEventUpdateDatabaseSetting(payload).send();
|
return DatabaseEventUpdateDatabaseSetting(payload).send();
|
||||||
|
@ -13,7 +13,7 @@ class SortFFIService {
|
|||||||
SortFFIService({required this.viewId});
|
SortFFIService({required this.viewId});
|
||||||
|
|
||||||
Future<Either<List<SortPB>, FlowyError>> getAllSorts() {
|
Future<Either<List<SortPB>, FlowyError>> getAllSorts() {
|
||||||
final payload = DatabaseIdPB()..value = viewId;
|
final payload = DatabaseViewIdPB()..value = viewId;
|
||||||
|
|
||||||
return DatabaseEventGetAllSorts(payload).send().then((result) {
|
return DatabaseEventGetAllSorts(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
@ -37,7 +37,7 @@ class SortFFIService {
|
|||||||
..sortId = sortId;
|
..sortId = sortId;
|
||||||
|
|
||||||
final payload = DatabaseSettingChangesetPB.create()
|
final payload = DatabaseSettingChangesetPB.create()
|
||||||
..databaseId = viewId
|
..viewId = viewId
|
||||||
..alterSort = insertSortPayload;
|
..alterSort = insertSortPayload;
|
||||||
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
@ -62,7 +62,7 @@ class SortFFIService {
|
|||||||
..condition = condition;
|
..condition = condition;
|
||||||
|
|
||||||
final payload = DatabaseSettingChangesetPB.create()
|
final payload = DatabaseSettingChangesetPB.create()
|
||||||
..databaseId = viewId
|
..viewId = viewId
|
||||||
..alterSort = insertSortPayload;
|
..alterSort = insertSortPayload;
|
||||||
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
@ -87,7 +87,7 @@ class SortFFIService {
|
|||||||
..fieldType = fieldType;
|
..fieldType = fieldType;
|
||||||
|
|
||||||
final payload = DatabaseSettingChangesetPB.create()
|
final payload = DatabaseSettingChangesetPB.create()
|
||||||
..databaseId = viewId
|
..viewId = viewId
|
||||||
..deleteSort = deleteFilterPayload;
|
..deleteSort = deleteFilterPayload;
|
||||||
|
|
||||||
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
return DatabaseEventUpdateDatabaseSetting(payload).send().then((result) {
|
||||||
@ -102,7 +102,7 @@ class SortFFIService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Unit, FlowyError>> deleteAllSorts() {
|
Future<Either<Unit, FlowyError>> deleteAllSorts() {
|
||||||
final payload = DatabaseIdPB(value: viewId);
|
final payload = DatabaseViewIdPB(value: viewId);
|
||||||
return DatabaseEventDeleteAllSorts(payload).send().then((result) {
|
return DatabaseEventDeleteAllSorts(payload).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(l) => left(l),
|
(l) => left(l),
|
||||||
|
@ -35,10 +35,10 @@ class _GridFieldCellActionSheetState extends State<GridFieldCellActionSheet> {
|
|||||||
return SizedBox(
|
return SizedBox(
|
||||||
width: 400,
|
width: 400,
|
||||||
child: FieldEditor(
|
child: FieldEditor(
|
||||||
databaseId: widget.cellContext.databaseId,
|
databaseId: widget.cellContext.viewId,
|
||||||
fieldName: field.name,
|
fieldName: field.name,
|
||||||
typeOptionLoader: FieldTypeOptionLoader(
|
typeOptionLoader: FieldTypeOptionLoader(
|
||||||
databaseId: widget.cellContext.databaseId,
|
viewId: widget.cellContext.viewId,
|
||||||
field: field,
|
field: field,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -206,7 +206,7 @@ extension _FieldActionExtension on FieldAction {
|
|||||||
PopoverContainer.of(context).close();
|
PopoverContainer.of(context).close();
|
||||||
|
|
||||||
FieldService(
|
FieldService(
|
||||||
databaseId: fieldInfo.databaseId,
|
viewId: fieldInfo.viewId,
|
||||||
fieldId: fieldInfo.field.id,
|
fieldId: fieldInfo.field.id,
|
||||||
).duplicateField();
|
).duplicateField();
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ extension _FieldActionExtension on FieldAction {
|
|||||||
title: LocaleKeys.grid_field_deleteFieldPromptMessage.tr(),
|
title: LocaleKeys.grid_field_deleteFieldPromptMessage.tr(),
|
||||||
confirm: () {
|
confirm: () {
|
||||||
FieldService(
|
FieldService(
|
||||||
databaseId: fieldInfo.databaseId,
|
viewId: fieldInfo.viewId,
|
||||||
fieldId: fieldInfo.field.id,
|
fieldId: fieldInfo.field.id,
|
||||||
).deleteField();
|
).deleteField();
|
||||||
},
|
},
|
||||||
|
@ -98,8 +98,8 @@ class _GridHeaderState extends State<_GridHeader> {
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
final cells = state.fields
|
final cells = state.fields
|
||||||
.where((field) => field.visibility)
|
.where((field) => field.visibility)
|
||||||
.map((field) => GridFieldCellContext(
|
.map((field) =>
|
||||||
databaseId: widget.viewId, field: field.field))
|
GridFieldCellContext(viewId: widget.viewId, field: field.field))
|
||||||
.map((ctx) =>
|
.map((ctx) =>
|
||||||
GridFieldCell(key: _getKeyById(ctx.field.id), cellContext: ctx))
|
GridFieldCell(key: _getKeyById(ctx.field.id), cellContext: ctx))
|
||||||
.toList();
|
.toList();
|
||||||
@ -189,7 +189,7 @@ class CreateFieldButton extends StatelessWidget {
|
|||||||
popupBuilder: (BuildContext popover) {
|
popupBuilder: (BuildContext popover) {
|
||||||
return FieldEditor(
|
return FieldEditor(
|
||||||
databaseId: databaseId,
|
databaseId: databaseId,
|
||||||
typeOptionLoader: NewFieldTypeOptionLoader(databaseId: databaseId),
|
typeOptionLoader: NewFieldTypeOptionLoader(viewId: databaseId),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -144,7 +144,7 @@ TypeOptionContext<T> makeTypeOptionContext<T extends GeneratedMessage>({
|
|||||||
required FieldInfo fieldInfo,
|
required FieldInfo fieldInfo,
|
||||||
}) {
|
}) {
|
||||||
final loader =
|
final loader =
|
||||||
FieldTypeOptionLoader(databaseId: databaseId, field: fieldInfo.field);
|
FieldTypeOptionLoader(viewId: databaseId, field: fieldInfo.field);
|
||||||
final dataController = TypeOptionDataController(
|
final dataController = TypeOptionDataController(
|
||||||
databaseId: databaseId,
|
databaseId: databaseId,
|
||||||
loader: loader,
|
loader: loader,
|
||||||
@ -176,7 +176,7 @@ TypeOptionContext<T> makeSelectTypeOptionContext<T extends GeneratedMessage>({
|
|||||||
required FieldPB fieldPB,
|
required FieldPB fieldPB,
|
||||||
}) {
|
}) {
|
||||||
final loader = FieldTypeOptionLoader(
|
final loader = FieldTypeOptionLoader(
|
||||||
databaseId: databaseId,
|
viewId: databaseId,
|
||||||
field: fieldPB,
|
field: fieldPB,
|
||||||
);
|
);
|
||||||
final dataController = TypeOptionDataController(
|
final dataController = TypeOptionDataController(
|
||||||
|
@ -206,7 +206,7 @@ class _CreateFieldButtonState extends State<_CreateFieldButton> {
|
|||||||
popupBuilder: (BuildContext popOverContext) {
|
popupBuilder: (BuildContext popOverContext) {
|
||||||
return FieldEditor(
|
return FieldEditor(
|
||||||
databaseId: widget.viewId,
|
databaseId: widget.viewId,
|
||||||
typeOptionLoader: NewFieldTypeOptionLoader(databaseId: widget.viewId),
|
typeOptionLoader: NewFieldTypeOptionLoader(viewId: widget.viewId),
|
||||||
onDeleted: (fieldId) {
|
onDeleted: (fieldId) {
|
||||||
popoverController.close();
|
popoverController.close();
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ class _RowDetailCellState extends State<_RowDetailCell> {
|
|||||||
fieldName: widget.cellId.fieldInfo.field.name,
|
fieldName: widget.cellId.fieldInfo.field.name,
|
||||||
isGroupField: widget.cellId.fieldInfo.isGroupField,
|
isGroupField: widget.cellId.fieldInfo.isGroupField,
|
||||||
typeOptionLoader: FieldTypeOptionLoader(
|
typeOptionLoader: FieldTypeOptionLoader(
|
||||||
databaseId: widget.cellId.databaseId,
|
viewId: widget.cellId.databaseId,
|
||||||
field: widget.cellId.fieldInfo.field,
|
field: widget.cellId.fieldInfo.field,
|
||||||
),
|
),
|
||||||
onDeleted: (fieldId) {
|
onDeleted: (fieldId) {
|
||||||
|
@ -139,7 +139,7 @@ class _GridPropertyCellState extends State<_GridPropertyCell> {
|
|||||||
databaseId: widget.databaseId,
|
databaseId: widget.databaseId,
|
||||||
fieldName: widget.fieldInfo.name,
|
fieldName: widget.fieldInfo.name,
|
||||||
typeOptionLoader: FieldTypeOptionLoader(
|
typeOptionLoader: FieldTypeOptionLoader(
|
||||||
databaseId: widget.databaseId,
|
viewId: widget.databaseId,
|
||||||
field: widget.fieldInfo.field,
|
field: widget.fieldInfo.field,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -30,7 +30,7 @@ void main() {
|
|||||||
|
|
||||||
final fieldInfo = context.singleSelectFieldContext();
|
final fieldInfo = context.singleSelectFieldContext();
|
||||||
final loader = FieldTypeOptionLoader(
|
final loader = FieldTypeOptionLoader(
|
||||||
databaseId: context.gridView.id,
|
viewId: context.gridView.id,
|
||||||
field: fieldInfo.field,
|
field: fieldInfo.field,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -81,10 +81,10 @@ class BoardTestContext {
|
|||||||
}) {
|
}) {
|
||||||
IFieldTypeOptionLoader loader;
|
IFieldTypeOptionLoader loader;
|
||||||
if (fieldInfo == null) {
|
if (fieldInfo == null) {
|
||||||
loader = NewFieldTypeOptionLoader(databaseId: gridView.id);
|
loader = NewFieldTypeOptionLoader(viewId: gridView.id);
|
||||||
} else {
|
} else {
|
||||||
loader = FieldTypeOptionLoader(
|
loader =
|
||||||
databaseId: gridView.id, field: fieldInfo.field);
|
FieldTypeOptionLoader(viewId: gridView.id, field: fieldInfo.field);
|
||||||
}
|
}
|
||||||
|
|
||||||
final editorBloc = FieldEditorBloc(
|
final editorBloc = FieldEditorBloc(
|
||||||
@ -144,7 +144,7 @@ class BoardTestContext {
|
|||||||
|
|
||||||
GridFieldCellContext singleSelectFieldCellContext() {
|
GridFieldCellContext singleSelectFieldCellContext() {
|
||||||
final field = singleSelectFieldContext().field;
|
final field = singleSelectFieldContext().field;
|
||||||
return GridFieldCellContext(databaseId: gridView.id, field: field);
|
return GridFieldCellContext(viewId: gridView.id, field: field);
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldInfo textFieldContext() {
|
FieldInfo textFieldContext() {
|
||||||
|
@ -8,7 +8,7 @@ Future<FieldEditorBloc> createEditorBloc(AppFlowyGridTest gridTest) async {
|
|||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final fieldInfo = context.singleSelectFieldContext();
|
final fieldInfo = context.singleSelectFieldContext();
|
||||||
final loader = FieldTypeOptionLoader(
|
final loader = FieldTypeOptionLoader(
|
||||||
databaseId: context.gridView.id,
|
viewId: context.gridView.id,
|
||||||
field: fieldInfo.field,
|
field: fieldInfo.field,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ Future<FieldEditorBloc> makeEditorBloc(AppFlowyGridTest gridTest) async {
|
|||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final fieldInfo = context.singleSelectFieldContext();
|
final fieldInfo = context.singleSelectFieldContext();
|
||||||
final loader = FieldTypeOptionLoader(
|
final loader = FieldTypeOptionLoader(
|
||||||
databaseId: context.gridView.id,
|
viewId: context.gridView.id,
|
||||||
field: fieldInfo.field,
|
field: fieldInfo.field,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ void main() {
|
|||||||
|
|
||||||
test('create a text filter)', () async {
|
test('create a text filter)', () async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
fieldId: textField.id,
|
fieldId: textField.id,
|
||||||
@ -28,7 +28,7 @@ void main() {
|
|||||||
|
|
||||||
test('delete a text filter)', () async {
|
test('delete a text filter)', () async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
fieldId: textField.id,
|
fieldId: textField.id,
|
||||||
@ -49,7 +49,7 @@ void main() {
|
|||||||
|
|
||||||
test('filter rows with condition: text is empty', () async {
|
test('filter rows with condition: text is empty', () async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final gridController = GridController(view: context.gridView);
|
final gridController = GridController(view: context.gridView);
|
||||||
final gridBloc = GridBloc(
|
final gridBloc = GridBloc(
|
||||||
view: context.gridView,
|
view: context.gridView,
|
||||||
@ -70,7 +70,7 @@ void main() {
|
|||||||
test('filter rows with condition: text is empty(After edit the row)',
|
test('filter rows with condition: text is empty(After edit the row)',
|
||||||
() async {
|
() async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final gridController = GridController(view: context.gridView);
|
final gridController = GridController(view: context.gridView);
|
||||||
final gridBloc = GridBloc(
|
final gridBloc = GridBloc(
|
||||||
view: context.gridView,
|
view: context.gridView,
|
||||||
@ -97,7 +97,7 @@ void main() {
|
|||||||
|
|
||||||
test('filter rows with condition: text is not empty', () async {
|
test('filter rows with condition: text is not empty', () async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
await gridResponseFuture();
|
await gridResponseFuture();
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
@ -111,7 +111,7 @@ void main() {
|
|||||||
test('filter rows with condition: checkbox uncheck', () async {
|
test('filter rows with condition: checkbox uncheck', () async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final checkboxField = context.checkboxFieldContext();
|
final checkboxField = context.checkboxFieldContext();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final gridController = GridController(view: context.gridView);
|
final gridController = GridController(view: context.gridView);
|
||||||
final gridBloc = GridBloc(
|
final gridBloc = GridBloc(
|
||||||
view: context.gridView,
|
view: context.gridView,
|
||||||
@ -130,7 +130,7 @@ void main() {
|
|||||||
test('filter rows with condition: checkbox check', () async {
|
test('filter rows with condition: checkbox check', () async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final checkboxField = context.checkboxFieldContext();
|
final checkboxField = context.checkboxFieldContext();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final gridController = GridController(view: context.gridView);
|
final gridController = GridController(view: context.gridView);
|
||||||
final gridBloc = GridBloc(
|
final gridBloc = GridBloc(
|
||||||
view: context.gridView,
|
view: context.gridView,
|
||||||
|
@ -16,7 +16,7 @@ void main() {
|
|||||||
|
|
||||||
test("create a text filter and then alter the filter's field)", () async {
|
test("create a text filter and then alter the filter's field)", () async {
|
||||||
final context = await gridTest.createTestGrid();
|
final context = await gridTest.createTestGrid();
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
|
|
||||||
// Create the filter menu bloc
|
// Create the filter menu bloc
|
||||||
@ -35,7 +35,7 @@ void main() {
|
|||||||
|
|
||||||
// Edit the text field
|
// Edit the text field
|
||||||
final loader = FieldTypeOptionLoader(
|
final loader = FieldTypeOptionLoader(
|
||||||
databaseId: context.gridView.id,
|
viewId: context.gridView.id,
|
||||||
field: textField.field,
|
field: textField.field,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ void main() {
|
|||||||
await gridResponseFuture();
|
await gridResponseFuture();
|
||||||
assert(menuBloc.state.creatableFields.length == 3);
|
assert(menuBloc.state.creatableFields.length == 3);
|
||||||
|
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
fieldId: textField.id,
|
fieldId: textField.id,
|
||||||
@ -36,7 +36,7 @@ void main() {
|
|||||||
..add(const GridFilterMenuEvent.initial());
|
..add(const GridFilterMenuEvent.initial());
|
||||||
await gridResponseFuture();
|
await gridResponseFuture();
|
||||||
|
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
|
|
||||||
// Create filter
|
// Create filter
|
||||||
|
@ -13,7 +13,7 @@ void main() {
|
|||||||
|
|
||||||
test('filter rows by checkbox is check condition)', () async {
|
test('filter rows by checkbox is check condition)', () async {
|
||||||
final context = await createTestFilterGrid(gridTest);
|
final context = await createTestFilterGrid(gridTest);
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
|
|
||||||
final controller = await context.makeCheckboxCellController(0);
|
final controller = await context.makeCheckboxCellController(0);
|
||||||
controller.saveCellData("Yes");
|
controller.saveCellData("Yes");
|
||||||
@ -32,7 +32,7 @@ void main() {
|
|||||||
|
|
||||||
test('filter rows by checkbox is uncheck condition)', () async {
|
test('filter rows by checkbox is uncheck condition)', () async {
|
||||||
final context = await createTestFilterGrid(gridTest);
|
final context = await createTestFilterGrid(gridTest);
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
|
|
||||||
final controller = await context.makeCheckboxCellController(0);
|
final controller = await context.makeCheckboxCellController(0);
|
||||||
controller.saveCellData("Yes");
|
controller.saveCellData("Yes");
|
||||||
|
@ -14,7 +14,7 @@ void main() {
|
|||||||
test('filter rows by text is empty condition)', () async {
|
test('filter rows by text is empty condition)', () async {
|
||||||
final context = await createTestFilterGrid(gridTest);
|
final context = await createTestFilterGrid(gridTest);
|
||||||
|
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
// create a new filter
|
// create a new filter
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
@ -41,7 +41,7 @@ void main() {
|
|||||||
test('filter rows by text is not empty condition)', () async {
|
test('filter rows by text is not empty condition)', () async {
|
||||||
final context = await createTestFilterGrid(gridTest);
|
final context = await createTestFilterGrid(gridTest);
|
||||||
|
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
// create a new filter
|
// create a new filter
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
@ -66,7 +66,7 @@ void main() {
|
|||||||
test('filter rows by text is empty or is not empty condition)', () async {
|
test('filter rows by text is empty or is not empty condition)', () async {
|
||||||
final context = await createTestFilterGrid(gridTest);
|
final context = await createTestFilterGrid(gridTest);
|
||||||
|
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
// create a new filter
|
// create a new filter
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
@ -102,7 +102,7 @@ void main() {
|
|||||||
test('filter rows by text is condition)', () async {
|
test('filter rows by text is condition)', () async {
|
||||||
final context = await createTestFilterGrid(gridTest);
|
final context = await createTestFilterGrid(gridTest);
|
||||||
|
|
||||||
final service = FilterFFIService(databaseId: context.gridView.id);
|
final service = FilterFFIService(viewId: context.gridView.id);
|
||||||
final textField = context.textFieldContext();
|
final textField = context.textFieldContext();
|
||||||
// create a new filter
|
// create a new filter
|
||||||
await service.insertTextFilter(
|
await service.insertTextFilter(
|
||||||
|
@ -39,10 +39,10 @@ class GridTestContext {
|
|||||||
}) {
|
}) {
|
||||||
IFieldTypeOptionLoader loader;
|
IFieldTypeOptionLoader loader;
|
||||||
if (fieldInfo == null) {
|
if (fieldInfo == null) {
|
||||||
loader = NewFieldTypeOptionLoader(databaseId: gridView.id);
|
loader = NewFieldTypeOptionLoader(viewId: gridView.id);
|
||||||
} else {
|
} else {
|
||||||
loader = FieldTypeOptionLoader(
|
loader =
|
||||||
databaseId: gridView.id, field: fieldInfo.field);
|
FieldTypeOptionLoader(viewId: gridView.id, field: fieldInfo.field);
|
||||||
}
|
}
|
||||||
|
|
||||||
final editorBloc = FieldEditorBloc(
|
final editorBloc = FieldEditorBloc(
|
||||||
@ -104,7 +104,7 @@ class GridTestContext {
|
|||||||
|
|
||||||
GridFieldCellContext singleSelectFieldCellContext() {
|
GridFieldCellContext singleSelectFieldCellContext() {
|
||||||
final field = singleSelectFieldContext().field;
|
final field = singleSelectFieldContext().field;
|
||||||
return GridFieldCellContext(databaseId: gridView.id, field: field);
|
return GridFieldCellContext(viewId: gridView.id, field: field);
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldInfo textFieldContext() {
|
FieldInfo textFieldContext() {
|
||||||
|
30
frontend/appflowy_tauri/src-tauri/Cargo.lock
generated
30
frontend/appflowy_tauri/src-tauri/Cargo.lock
generated
@ -849,6 +849,18 @@ dependencies = [
|
|||||||
"parking_lot_core",
|
"parking_lot_core",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "database-model"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"indexmap",
|
||||||
|
"nanoid",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derivative"
|
name = "derivative"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
@ -1132,12 +1144,12 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"database-model",
|
||||||
"dissimilar",
|
"dissimilar",
|
||||||
"document-model",
|
"document-model",
|
||||||
"flowy-derive",
|
"flowy-derive",
|
||||||
"flowy-sync",
|
"flowy-sync",
|
||||||
"folder-model",
|
"folder-model",
|
||||||
"grid-model",
|
|
||||||
"lib-infra",
|
"lib-infra",
|
||||||
"lib-ot",
|
"lib-ot",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
@ -1195,6 +1207,7 @@ name = "flowy-core"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"database-model",
|
||||||
"flowy-client-ws",
|
"flowy-client-ws",
|
||||||
"flowy-database",
|
"flowy-database",
|
||||||
"flowy-document",
|
"flowy-document",
|
||||||
@ -1206,7 +1219,6 @@ dependencies = [
|
|||||||
"flowy-task",
|
"flowy-task",
|
||||||
"flowy-user",
|
"flowy-user",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"grid-model",
|
|
||||||
"lib-dispatch",
|
"lib-dispatch",
|
||||||
"lib-infra",
|
"lib-infra",
|
||||||
"lib-log",
|
"lib-log",
|
||||||
@ -1230,6 +1242,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
|
"database-model",
|
||||||
"diesel",
|
"diesel",
|
||||||
"fancy-regex 0.10.0",
|
"fancy-regex 0.10.0",
|
||||||
"flowy-client-sync",
|
"flowy-client-sync",
|
||||||
@ -1242,7 +1255,6 @@ dependencies = [
|
|||||||
"flowy-sqlite",
|
"flowy-sqlite",
|
||||||
"flowy-task",
|
"flowy-task",
|
||||||
"futures",
|
"futures",
|
||||||
"grid-model",
|
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lib-dispatch",
|
"lib-dispatch",
|
||||||
@ -1960,18 +1972,6 @@ dependencies = [
|
|||||||
"system-deps 6.0.3",
|
"system-deps 6.0.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "grid-model"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bytes",
|
|
||||||
"indexmap",
|
|
||||||
"nanoid",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"serde_repr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gtk"
|
name = "gtk"
|
||||||
version = "0.15.5"
|
version = "0.15.5"
|
||||||
|
@ -3,7 +3,7 @@ import {
|
|||||||
DatabaseEventGetDatabase,
|
DatabaseEventGetDatabase,
|
||||||
DatabaseEventGetFields,
|
DatabaseEventGetFields,
|
||||||
} from '../../../../services/backend/events/flowy-database/event';
|
} from '../../../../services/backend/events/flowy-database/event';
|
||||||
import { DatabaseIdPB } from '../../../../services/backend/models/flowy-database';
|
import { DatabaseViewIdPB } from '../../../../services/backend/models/flowy-database';
|
||||||
import { CreateRowPayloadPB } from '../../../../services/backend/models/flowy-database/row_entities';
|
import { CreateRowPayloadPB } from '../../../../services/backend/models/flowy-database/row_entities';
|
||||||
import {
|
import {
|
||||||
GetFieldPayloadPB,
|
GetFieldPayloadPB,
|
||||||
@ -21,7 +21,7 @@ export class DatabaseBackendService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
openDatabase = async () => {
|
openDatabase = async () => {
|
||||||
const payload = DatabaseIdPB.fromObject({
|
const payload = DatabaseViewIdPB.fromObject({
|
||||||
value: this.viewId,
|
value: this.viewId,
|
||||||
});
|
});
|
||||||
return DatabaseEventGetDatabase(payload);
|
return DatabaseEventGetDatabase(payload);
|
||||||
@ -39,7 +39,7 @@ export class DatabaseBackendService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getFields = async (fieldIds?: FieldIdPB[]) => {
|
getFields = async (fieldIds?: FieldIdPB[]) => {
|
||||||
const payload = GetFieldPayloadPB.fromObject({ database_id: this.viewId });
|
const payload = GetFieldPayloadPB.fromObject({ view_id: this.viewId });
|
||||||
|
|
||||||
if (!fieldIds) {
|
if (!fieldIds) {
|
||||||
payload.field_ids = RepeatedFieldIdPB.fromObject({ items: fieldIds });
|
payload.field_ids = RepeatedFieldIdPB.fromObject({ items: fieldIds });
|
||||||
|
@ -19,7 +19,7 @@ export abstract class TypeOptionParser<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class FieldBackendService {
|
export class FieldBackendService {
|
||||||
constructor(public readonly databaseId: string, public readonly fieldId: string) {}
|
constructor(public readonly viewId: string, public readonly fieldId: string) {}
|
||||||
|
|
||||||
updateField = (data: {
|
updateField = (data: {
|
||||||
name?: string;
|
name?: string;
|
||||||
@ -28,7 +28,7 @@ export class FieldBackendService {
|
|||||||
visibility?: boolean;
|
visibility?: boolean;
|
||||||
width?: number;
|
width?: number;
|
||||||
}) => {
|
}) => {
|
||||||
const payload = FieldChangesetPB.fromObject({ database_id: this.databaseId, field_id: this.fieldId });
|
const payload = FieldChangesetPB.fromObject({ database_id: this.viewId, field_id: this.fieldId });
|
||||||
|
|
||||||
if (data.name !== undefined) {
|
if (data.name !== undefined) {
|
||||||
payload.name = data.name;
|
payload.name = data.name;
|
||||||
@ -55,7 +55,7 @@ export class FieldBackendService {
|
|||||||
|
|
||||||
updateTypeOption = (typeOptionData: Uint8Array) => {
|
updateTypeOption = (typeOptionData: Uint8Array) => {
|
||||||
const payload = TypeOptionChangesetPB.fromObject({
|
const payload = TypeOptionChangesetPB.fromObject({
|
||||||
database_id: this.databaseId,
|
view_id: this.viewId,
|
||||||
field_id: this.fieldId,
|
field_id: this.fieldId,
|
||||||
type_option_data: typeOptionData,
|
type_option_data: typeOptionData,
|
||||||
});
|
});
|
||||||
@ -64,20 +64,20 @@ export class FieldBackendService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
deleteField = () => {
|
deleteField = () => {
|
||||||
const payload = DeleteFieldPayloadPB.fromObject({ database_id: this.databaseId, field_id: this.fieldId });
|
const payload = DeleteFieldPayloadPB.fromObject({ view_id: this.viewId, field_id: this.fieldId });
|
||||||
|
|
||||||
return DatabaseEventDeleteField(payload);
|
return DatabaseEventDeleteField(payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
duplicateField = () => {
|
duplicateField = () => {
|
||||||
const payload = DuplicateFieldPayloadPB.fromObject({ database_id: this.databaseId, field_id: this.fieldId });
|
const payload = DuplicateFieldPayloadPB.fromObject({ view_id: this.viewId, field_id: this.fieldId });
|
||||||
|
|
||||||
return DatabaseEventDuplicateField(payload);
|
return DatabaseEventDuplicateField(payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
getTypeOptionData = (fieldType: FieldType) => {
|
getTypeOptionData = (fieldType: FieldType) => {
|
||||||
const payload = TypeOptionPathPB.fromObject({
|
const payload = TypeOptionPathPB.fromObject({
|
||||||
database_id: this.databaseId,
|
view_id: this.viewId,
|
||||||
field_id: this.fieldId,
|
field_id: this.fieldId,
|
||||||
field_type: fieldType,
|
field_type: fieldType,
|
||||||
});
|
});
|
||||||
|
30
frontend/rust-lib/Cargo.lock
generated
30
frontend/rust-lib/Cargo.lock
generated
@ -695,6 +695,18 @@ dependencies = [
|
|||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "database-model"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"bytes",
|
||||||
|
"indexmap",
|
||||||
|
"nanoid",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"serde_repr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "derivative"
|
name = "derivative"
|
||||||
version = "2.2.0"
|
version = "2.2.0"
|
||||||
@ -921,12 +933,12 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"database-model",
|
||||||
"dissimilar",
|
"dissimilar",
|
||||||
"document-model",
|
"document-model",
|
||||||
"flowy-derive",
|
"flowy-derive",
|
||||||
"flowy-sync",
|
"flowy-sync",
|
||||||
"folder-model",
|
"folder-model",
|
||||||
"grid-model",
|
|
||||||
"lib-infra",
|
"lib-infra",
|
||||||
"lib-ot",
|
"lib-ot",
|
||||||
"parking_lot 0.12.1",
|
"parking_lot 0.12.1",
|
||||||
@ -984,6 +996,7 @@ name = "flowy-core"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"database-model",
|
||||||
"flowy-client-ws",
|
"flowy-client-ws",
|
||||||
"flowy-database",
|
"flowy-database",
|
||||||
"flowy-document",
|
"flowy-document",
|
||||||
@ -995,7 +1008,6 @@ dependencies = [
|
|||||||
"flowy-task",
|
"flowy-task",
|
||||||
"flowy-user",
|
"flowy-user",
|
||||||
"futures-core",
|
"futures-core",
|
||||||
"grid-model",
|
|
||||||
"lib-dispatch",
|
"lib-dispatch",
|
||||||
"lib-infra",
|
"lib-infra",
|
||||||
"lib-log",
|
"lib-log",
|
||||||
@ -1019,6 +1031,7 @@ dependencies = [
|
|||||||
"chrono",
|
"chrono",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"dashmap",
|
"dashmap",
|
||||||
|
"database-model",
|
||||||
"diesel",
|
"diesel",
|
||||||
"fancy-regex 0.10.0",
|
"fancy-regex 0.10.0",
|
||||||
"flowy-client-sync",
|
"flowy-client-sync",
|
||||||
@ -1033,7 +1046,6 @@ dependencies = [
|
|||||||
"flowy-task",
|
"flowy-task",
|
||||||
"flowy-test",
|
"flowy-test",
|
||||||
"futures",
|
"futures",
|
||||||
"grid-model",
|
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"lib-dispatch",
|
"lib-dispatch",
|
||||||
@ -1613,18 +1625,6 @@ dependencies = [
|
|||||||
"walkdir",
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "grid-model"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bytes",
|
|
||||||
"indexmap",
|
|
||||||
"nanoid",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"serde_repr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "h2"
|
name = "h2"
|
||||||
version = "0.3.15"
|
version = "0.3.15"
|
||||||
|
@ -10,7 +10,7 @@ lib-ot = { path = "../../../shared-lib/lib-ot" }
|
|||||||
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||||
flowy-derive = { path = "../flowy-derive" }
|
flowy-derive = { path = "../flowy-derive" }
|
||||||
folder-model = { path = "../../../shared-lib/folder-model" }
|
folder-model = { path = "../../../shared-lib/folder-model" }
|
||||||
grid-model = { path = "../../../shared-lib/grid-model" }
|
database-model = { path = "../../../shared-lib/database-model" }
|
||||||
revision-model = { path = "../../../shared-lib/revision-model" }
|
revision-model = { path = "../../../shared-lib/revision-model" }
|
||||||
document-model = { path = "../../../shared-lib/document-model" }
|
document-model = { path = "../../../shared-lib/document-model" }
|
||||||
flowy-sync = { path = "../../../shared-lib/flowy-sync" }
|
flowy-sync = { path = "../../../shared-lib/flowy-sync" }
|
||||||
|
@ -1,26 +1,27 @@
|
|||||||
use crate::errors::{SyncError, SyncResult};
|
use crate::errors::{SyncError, SyncResult};
|
||||||
use crate::util::cal_diff;
|
use crate::util::cal_diff;
|
||||||
use flowy_sync::util::make_operations_from_revisions;
|
use database_model::{
|
||||||
use grid_model::{
|
|
||||||
gen_block_id, gen_row_id, CellRevision, DatabaseBlockRevision, RowChangeset, RowRevision,
|
gen_block_id, gen_row_id, CellRevision, DatabaseBlockRevision, RowChangeset, RowRevision,
|
||||||
};
|
};
|
||||||
|
use flowy_sync::util::make_operations_from_revisions;
|
||||||
use lib_infra::util::md5;
|
use lib_infra::util::md5;
|
||||||
use lib_ot::core::{DeltaBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
use lib_ot::core::{DeltaBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
|
use std::any::type_name;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub type GridBlockOperations = DeltaOperations<EmptyAttributes>;
|
pub type DatabaseBlockOperations = DeltaOperations<EmptyAttributes>;
|
||||||
pub type GridBlockOperationsBuilder = DeltaBuilder;
|
pub type DatabaseBlockOperationsBuilder = DeltaBuilder;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct GridBlockRevisionPad {
|
pub struct DatabaseBlockRevisionPad {
|
||||||
block: DatabaseBlockRevision,
|
block: DatabaseBlockRevision,
|
||||||
operations: GridBlockOperations,
|
operations: DatabaseBlockOperations,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Deref for GridBlockRevisionPad {
|
impl std::ops::Deref for DatabaseBlockRevisionPad {
|
||||||
type Target = DatabaseBlockRevision;
|
type Target = DatabaseBlockRevision;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
@ -28,7 +29,7 @@ impl std::ops::Deref for GridBlockRevisionPad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridBlockRevisionPad {
|
impl DatabaseBlockRevisionPad {
|
||||||
pub fn duplicate_data(&self, duplicated_block_id: &str) -> DatabaseBlockRevision {
|
pub fn duplicate_data(&self, duplicated_block_id: &str) -> DatabaseBlockRevision {
|
||||||
let duplicated_rows = self
|
let duplicated_rows = self
|
||||||
.block
|
.block
|
||||||
@ -47,10 +48,14 @@ impl GridBlockRevisionPad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_operations(operations: GridBlockOperations) -> SyncResult<Self> {
|
pub fn from_operations(operations: DatabaseBlockOperations) -> SyncResult<Self> {
|
||||||
let s = operations.content()?;
|
let s = operations.content()?;
|
||||||
let revision: DatabaseBlockRevision = serde_json::from_str(&s).map_err(|e| {
|
let revision: DatabaseBlockRevision = serde_json::from_str(&s).map_err(|e| {
|
||||||
let msg = format!("Deserialize operations to GridBlockRevision failed: {}", e);
|
let msg = format!(
|
||||||
|
"Deserialize operations to {} failed: {}",
|
||||||
|
type_name::<DatabaseBlockRevision>(),
|
||||||
|
e
|
||||||
|
);
|
||||||
tracing::error!("{}", s);
|
tracing::error!("{}", s);
|
||||||
SyncError::internal().context(msg)
|
SyncError::internal().context(msg)
|
||||||
})?;
|
})?;
|
||||||
@ -60,8 +65,8 @@ impl GridBlockRevisionPad {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_revisions(_grid_id: &str, revisions: Vec<Revision>) -> SyncResult<Self> {
|
pub fn from_revisions(revisions: Vec<Revision>) -> SyncResult<Self> {
|
||||||
let operations: GridBlockOperations = make_operations_from_revisions(revisions)?;
|
let operations: DatabaseBlockOperations = make_operations_from_revisions(revisions)?;
|
||||||
Self::from_operations(operations)
|
Self::from_operations(operations)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +75,7 @@ impl GridBlockRevisionPad {
|
|||||||
&mut self,
|
&mut self,
|
||||||
row: RowRevision,
|
row: RowRevision,
|
||||||
start_row_id: Option<String>,
|
start_row_id: Option<String>,
|
||||||
) -> SyncResult<Option<GridBlockRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseBlockRevisionChangeset>> {
|
||||||
self.modify(|rows| {
|
self.modify(|rows| {
|
||||||
if let Some(start_row_id) = start_row_id {
|
if let Some(start_row_id) = start_row_id {
|
||||||
if !start_row_id.is_empty() {
|
if !start_row_id.is_empty() {
|
||||||
@ -89,7 +94,7 @@ impl GridBlockRevisionPad {
|
|||||||
pub fn delete_rows(
|
pub fn delete_rows(
|
||||||
&mut self,
|
&mut self,
|
||||||
row_ids: Vec<Cow<'_, String>>,
|
row_ids: Vec<Cow<'_, String>>,
|
||||||
) -> SyncResult<Option<GridBlockRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseBlockRevisionChangeset>> {
|
||||||
self.modify(|rows| {
|
self.modify(|rows| {
|
||||||
rows.retain(|row| !row_ids.contains(&Cow::Borrowed(&row.id)));
|
rows.retain(|row| !row_ids.contains(&Cow::Borrowed(&row.id)));
|
||||||
Ok(Some(()))
|
Ok(Some(()))
|
||||||
@ -168,7 +173,7 @@ impl GridBlockRevisionPad {
|
|||||||
pub fn update_row(
|
pub fn update_row(
|
||||||
&mut self,
|
&mut self,
|
||||||
changeset: RowChangeset,
|
changeset: RowChangeset,
|
||||||
) -> SyncResult<Option<GridBlockRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseBlockRevisionChangeset>> {
|
||||||
let row_id = changeset.row_id.clone();
|
let row_id = changeset.row_id.clone();
|
||||||
self.modify_row(&row_id, |row| {
|
self.modify_row(&row_id, |row| {
|
||||||
let mut is_changed = None;
|
let mut is_changed = None;
|
||||||
@ -201,7 +206,7 @@ impl GridBlockRevisionPad {
|
|||||||
row_id: &str,
|
row_id: &str,
|
||||||
from: usize,
|
from: usize,
|
||||||
to: usize,
|
to: usize,
|
||||||
) -> SyncResult<Option<GridBlockRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseBlockRevisionChangeset>> {
|
||||||
self.modify(|row_revs| {
|
self.modify(|row_revs| {
|
||||||
if let Some(position) = row_revs.iter().position(|row_rev| row_rev.id == row_id) {
|
if let Some(position) = row_revs.iter().position(|row_rev| row_rev.id == row_id) {
|
||||||
debug_assert_eq!(from, position);
|
debug_assert_eq!(from, position);
|
||||||
@ -218,7 +223,7 @@ impl GridBlockRevisionPad {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn modify<F>(&mut self, f: F) -> SyncResult<Option<GridBlockRevisionChangeset>>
|
pub fn modify<F>(&mut self, f: F) -> SyncResult<Option<DatabaseBlockRevisionChangeset>>
|
||||||
where
|
where
|
||||||
F: for<'a> FnOnce(&'a mut Vec<Arc<RowRevision>>) -> SyncResult<Option<()>>,
|
F: for<'a> FnOnce(&'a mut Vec<Arc<RowRevision>>) -> SyncResult<Option<()>>,
|
||||||
{
|
{
|
||||||
@ -232,11 +237,12 @@ impl GridBlockRevisionPad {
|
|||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(operations) => {
|
Some(operations) => {
|
||||||
tracing::trace!(
|
tracing::trace!(
|
||||||
"[GridBlockRevision] Composing operations {}",
|
"[{}] Composing operations {}",
|
||||||
|
type_name::<DatabaseBlockRevision>(),
|
||||||
operations.json_str()
|
operations.json_str()
|
||||||
);
|
);
|
||||||
self.operations = self.operations.compose(&operations)?;
|
self.operations = self.operations.compose(&operations)?;
|
||||||
Ok(Some(GridBlockRevisionChangeset {
|
Ok(Some(DatabaseBlockRevisionChangeset {
|
||||||
operations,
|
operations,
|
||||||
md5: md5(&self.operations.json_bytes()),
|
md5: md5(&self.operations.json_bytes()),
|
||||||
}))
|
}))
|
||||||
@ -246,7 +252,11 @@ impl GridBlockRevisionPad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_row<F>(&mut self, row_id: &str, f: F) -> SyncResult<Option<GridBlockRevisionChangeset>>
|
fn modify_row<F>(
|
||||||
|
&mut self,
|
||||||
|
row_id: &str,
|
||||||
|
f: F,
|
||||||
|
) -> SyncResult<Option<DatabaseBlockRevisionChangeset>>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut RowRevision) -> SyncResult<Option<()>>,
|
F: FnOnce(&mut RowRevision) -> SyncResult<Option<()>>,
|
||||||
{
|
{
|
||||||
@ -270,28 +280,30 @@ impl GridBlockRevisionPad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridBlockRevisionChangeset {
|
pub struct DatabaseBlockRevisionChangeset {
|
||||||
pub operations: GridBlockOperations,
|
pub operations: DatabaseBlockOperations,
|
||||||
/// md5: the md5 of the grid after applying the change.
|
/// md5: the md5 of the grid after applying the change.
|
||||||
pub md5: String,
|
pub md5: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_database_block_operations(block_rev: &DatabaseBlockRevision) -> GridBlockOperations {
|
pub fn make_database_block_operations(
|
||||||
|
block_rev: &DatabaseBlockRevision,
|
||||||
|
) -> DatabaseBlockOperations {
|
||||||
let json = serde_json::to_string(&block_rev).unwrap();
|
let json = serde_json::to_string(&block_rev).unwrap();
|
||||||
GridBlockOperationsBuilder::new().insert(&json).build()
|
DatabaseBlockOperationsBuilder::new().insert(&json).build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_grid_block_revisions(
|
pub fn make_database_block_revisions(
|
||||||
_user_id: &str,
|
_user_id: &str,
|
||||||
grid_block_meta_data: &DatabaseBlockRevision,
|
database_block_meta_data: &DatabaseBlockRevision,
|
||||||
) -> Vec<Revision> {
|
) -> Vec<Revision> {
|
||||||
let operations = make_database_block_operations(grid_block_meta_data);
|
let operations = make_database_block_operations(database_block_meta_data);
|
||||||
let bytes = operations.json_bytes();
|
let bytes = operations.json_bytes();
|
||||||
let revision = Revision::initial_revision(&grid_block_meta_data.block_id, bytes);
|
let revision = Revision::initial_revision(&database_block_meta_data.block_id, bytes);
|
||||||
vec![revision]
|
vec![revision]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for GridBlockRevisionPad {
|
impl std::default::Default for DatabaseBlockRevisionPad {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let block_revision = DatabaseBlockRevision {
|
let block_revision = DatabaseBlockRevision {
|
||||||
block_id: gen_block_id(),
|
block_id: gen_block_id(),
|
||||||
@ -299,7 +311,7 @@ impl std::default::Default for GridBlockRevisionPad {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let operations = make_database_block_operations(&block_revision);
|
let operations = make_database_block_operations(&block_revision);
|
||||||
GridBlockRevisionPad {
|
DatabaseBlockRevisionPad {
|
||||||
block: block_revision,
|
block: block_revision,
|
||||||
operations,
|
operations,
|
||||||
}
|
}
|
||||||
@ -308,8 +320,8 @@ impl std::default::Default for GridBlockRevisionPad {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::client_database::{GridBlockOperations, GridBlockRevisionPad};
|
use crate::client_database::{DatabaseBlockOperations, DatabaseBlockRevisionPad};
|
||||||
use grid_model::{RowChangeset, RowRevision};
|
use database_model::{RowChangeset, RowRevision};
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
@ -365,7 +377,7 @@ mod tests {
|
|||||||
assert_eq!(*pad.rows[2], row_3);
|
assert_eq!(*pad.rows[2], row_3);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_row_rev(id: &str, pad: &GridBlockRevisionPad) -> RowRevision {
|
fn test_row_rev(id: &str, pad: &DatabaseBlockRevisionPad) -> RowRevision {
|
||||||
RowRevision {
|
RowRevision {
|
||||||
id: id.to_string(),
|
id: id.to_string(),
|
||||||
block_id: pad.block_id.clone(),
|
block_id: pad.block_id.clone(),
|
||||||
@ -470,9 +482,10 @@ mod tests {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pad() -> GridBlockRevisionPad {
|
fn test_pad() -> DatabaseBlockRevisionPad {
|
||||||
let operations =
|
let operations =
|
||||||
GridBlockOperations::from_json(r#"[{"insert":"{\"block_id\":\"1\",\"rows\":[]}"}]"#).unwrap();
|
DatabaseBlockOperations::from_json(r#"[{"insert":"{\"block_id\":\"1\",\"rows\":[]}"}]"#)
|
||||||
GridBlockRevisionPad::from_operations(operations).unwrap()
|
.unwrap();
|
||||||
|
DatabaseBlockRevisionPad::from_operations(operations).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::errors::{SyncError, SyncResult};
|
use crate::errors::{SyncError, SyncResult};
|
||||||
use grid_model::{
|
use database_model::{
|
||||||
BuildDatabaseContext, DatabaseBlockRevision, FieldRevision, GridBlockMetaRevision, RowRevision,
|
BuildDatabaseContext, DatabaseBlockMetaRevision, DatabaseBlockRevision, FieldRevision,
|
||||||
|
RowRevision,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -12,7 +13,7 @@ impl std::default::Default for DatabaseBuilder {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let mut build_context = BuildDatabaseContext::new();
|
let mut build_context = BuildDatabaseContext::new();
|
||||||
|
|
||||||
let block_meta = GridBlockMetaRevision::new();
|
let block_meta = DatabaseBlockMetaRevision::new();
|
||||||
let block_meta_data = DatabaseBlockRevision {
|
let block_meta_data = DatabaseBlockRevision {
|
||||||
block_id: block_meta.block_id.clone(),
|
block_id: block_meta.block_id.clone(),
|
||||||
rows: vec![],
|
rows: vec![],
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use crate::errors::{internal_sync_error, SyncError, SyncResult};
|
use crate::errors::{internal_sync_error, SyncError, SyncResult};
|
||||||
use crate::util::cal_diff;
|
use crate::util::cal_diff;
|
||||||
use flowy_sync::util::make_operations_from_revisions;
|
use database_model::{
|
||||||
use grid_model::{
|
gen_block_id, gen_database_id, DatabaseBlockMetaRevision, DatabaseBlockMetaRevisionChangeset,
|
||||||
gen_block_id, gen_grid_id, DatabaseRevision, FieldRevision, FieldTypeRevision,
|
DatabaseRevision, FieldRevision, FieldTypeRevision,
|
||||||
GridBlockMetaRevision, GridBlockMetaRevisionChangeset,
|
|
||||||
};
|
};
|
||||||
|
use flowy_sync::util::make_operations_from_revisions;
|
||||||
use lib_infra::util::md5;
|
use lib_infra::util::md5;
|
||||||
use lib_infra::util::move_vec_element;
|
use lib_infra::util::move_vec_element;
|
||||||
use lib_ot::core::{DeltaOperationBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
use lib_ot::core::{DeltaOperationBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
||||||
@ -17,7 +17,7 @@ pub type DatabaseOperationsBuilder = DeltaOperationBuilder<EmptyAttributes>;
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DatabaseRevisionPad {
|
pub struct DatabaseRevisionPad {
|
||||||
grid_rev: Arc<DatabaseRevision>,
|
database_rev: Arc<DatabaseRevision>,
|
||||||
operations: DatabaseOperations,
|
operations: DatabaseOperations,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,21 +26,22 @@ pub trait JsonDeserializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseRevisionPad {
|
impl DatabaseRevisionPad {
|
||||||
pub fn grid_id(&self) -> String {
|
pub fn database_id(&self) -> String {
|
||||||
self.grid_rev.grid_id.clone()
|
self.database_rev.database_id.clone()
|
||||||
}
|
}
|
||||||
pub async fn duplicate_grid_block_meta(
|
|
||||||
|
pub async fn duplicate_database_block_meta(
|
||||||
&self,
|
&self,
|
||||||
) -> (Vec<FieldRevision>, Vec<GridBlockMetaRevision>) {
|
) -> (Vec<FieldRevision>, Vec<DatabaseBlockMetaRevision>) {
|
||||||
let fields = self
|
let fields = self
|
||||||
.grid_rev
|
.database_rev
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field_rev| field_rev.as_ref().clone())
|
.map(|field_rev| field_rev.as_ref().clone())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let blocks = self
|
let blocks = self
|
||||||
.grid_rev
|
.database_rev
|
||||||
.blocks
|
.blocks
|
||||||
.iter()
|
.iter()
|
||||||
.map(|block| {
|
.map(|block| {
|
||||||
@ -48,21 +49,21 @@ impl DatabaseRevisionPad {
|
|||||||
duplicated_block.block_id = gen_block_id();
|
duplicated_block.block_id = gen_block_id();
|
||||||
duplicated_block
|
duplicated_block
|
||||||
})
|
})
|
||||||
.collect::<Vec<GridBlockMetaRevision>>();
|
.collect::<Vec<DatabaseBlockMetaRevision>>();
|
||||||
|
|
||||||
(fields, blocks)
|
(fields, blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_operations(operations: DatabaseOperations) -> SyncResult<Self> {
|
pub fn from_operations(operations: DatabaseOperations) -> SyncResult<Self> {
|
||||||
let content = operations.content()?;
|
let content = operations.content()?;
|
||||||
let grid: DatabaseRevision = serde_json::from_str(&content).map_err(|e| {
|
let database_rev: DatabaseRevision = serde_json::from_str(&content).map_err(|e| {
|
||||||
let msg = format!("Deserialize operations to grid failed: {}", e);
|
let msg = format!("Deserialize operations to grid failed: {}", e);
|
||||||
tracing::error!("{}", msg);
|
tracing::error!("{}", msg);
|
||||||
SyncError::internal().context(msg)
|
SyncError::internal().context(msg)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
grid_rev: Arc::new(grid),
|
database_rev: Arc::new(database_rev),
|
||||||
operations,
|
operations,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -78,7 +79,7 @@ impl DatabaseRevisionPad {
|
|||||||
new_field_rev: FieldRevision,
|
new_field_rev: FieldRevision,
|
||||||
start_field_id: Option<String>,
|
start_field_id: Option<String>,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_database(|grid_meta| {
|
||||||
// Check if the field exists or not
|
// Check if the field exists or not
|
||||||
if grid_meta
|
if grid_meta
|
||||||
.fields
|
.fields
|
||||||
@ -109,7 +110,7 @@ impl DatabaseRevisionPad {
|
|||||||
&mut self,
|
&mut self,
|
||||||
field_id: &str,
|
field_id: &str,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_database(|grid_meta| {
|
||||||
match grid_meta
|
match grid_meta
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
@ -133,7 +134,7 @@ impl DatabaseRevisionPad {
|
|||||||
field_id: &str,
|
field_id: &str,
|
||||||
duplicated_field_id: &str,
|
duplicated_field_id: &str,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_database(|grid_meta| {
|
||||||
match grid_meta
|
match grid_meta
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
@ -176,7 +177,7 @@ impl DatabaseRevisionPad {
|
|||||||
T: Into<FieldTypeRevision>,
|
T: Into<FieldTypeRevision>,
|
||||||
{
|
{
|
||||||
let new_field_type = new_field_type.into();
|
let new_field_type = new_field_type.into();
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_database(|grid_meta| {
|
||||||
match grid_meta
|
match grid_meta
|
||||||
.fields
|
.fields
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
@ -224,7 +225,7 @@ impl DatabaseRevisionPad {
|
|||||||
&mut self,
|
&mut self,
|
||||||
field_rev: Arc<FieldRevision>,
|
field_rev: Arc<FieldRevision>,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_database(|grid_meta| {
|
||||||
match grid_meta
|
match grid_meta
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
@ -246,7 +247,7 @@ impl DatabaseRevisionPad {
|
|||||||
from_index: usize,
|
from_index: usize,
|
||||||
to_index: usize,
|
to_index: usize,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_database(|grid_meta| {
|
||||||
match move_vec_element(
|
match move_vec_element(
|
||||||
&mut grid_meta.fields,
|
&mut grid_meta.fields,
|
||||||
|field| field.id == field_id,
|
|field| field.id == field_id,
|
||||||
@ -263,7 +264,7 @@ impl DatabaseRevisionPad {
|
|||||||
|
|
||||||
pub fn contain_field(&self, field_id: &str) -> bool {
|
pub fn contain_field(&self, field_id: &str) -> bool {
|
||||||
self
|
self
|
||||||
.grid_rev
|
.database_rev
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.any(|field| field.id == field_id)
|
.any(|field| field.id == field_id)
|
||||||
@ -271,7 +272,7 @@ impl DatabaseRevisionPad {
|
|||||||
|
|
||||||
pub fn get_field_rev(&self, field_id: &str) -> Option<(usize, &Arc<FieldRevision>)> {
|
pub fn get_field_rev(&self, field_id: &str) -> Option<(usize, &Arc<FieldRevision>)> {
|
||||||
self
|
self
|
||||||
.grid_rev
|
.database_rev
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@ -283,10 +284,10 @@ impl DatabaseRevisionPad {
|
|||||||
field_ids: Option<Vec<String>>,
|
field_ids: Option<Vec<String>>,
|
||||||
) -> SyncResult<Vec<Arc<FieldRevision>>> {
|
) -> SyncResult<Vec<Arc<FieldRevision>>> {
|
||||||
match field_ids {
|
match field_ids {
|
||||||
None => Ok(self.grid_rev.fields.clone()),
|
None => Ok(self.database_rev.fields.clone()),
|
||||||
Some(field_ids) => {
|
Some(field_ids) => {
|
||||||
let field_by_field_id = self
|
let field_by_field_id = self
|
||||||
.grid_rev
|
.database_rev
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
.map(|field| (&field.id, field))
|
.map(|field| (&field.id, field))
|
||||||
@ -309,9 +310,9 @@ impl DatabaseRevisionPad {
|
|||||||
|
|
||||||
pub fn create_block_meta_rev(
|
pub fn create_block_meta_rev(
|
||||||
&mut self,
|
&mut self,
|
||||||
block: GridBlockMetaRevision,
|
block: DatabaseBlockMetaRevision,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
||||||
self.modify_grid(|grid_meta| {
|
self.modify_database(|grid_meta| {
|
||||||
if grid_meta.blocks.iter().any(|b| b.block_id == block.block_id) {
|
if grid_meta.blocks.iter().any(|b| b.block_id == block.block_id) {
|
||||||
tracing::warn!("Duplicate grid block");
|
tracing::warn!("Duplicate grid block");
|
||||||
Ok(None)
|
Ok(None)
|
||||||
@ -333,13 +334,13 @@ impl DatabaseRevisionPad {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_block_meta_revs(&self) -> Vec<Arc<GridBlockMetaRevision>> {
|
pub fn get_block_meta_revs(&self) -> Vec<Arc<DatabaseBlockMetaRevision>> {
|
||||||
self.grid_rev.blocks.clone()
|
self.database_rev.blocks.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_block_rev(
|
pub fn update_block_rev(
|
||||||
&mut self,
|
&mut self,
|
||||||
changeset: GridBlockMetaRevisionChangeset,
|
changeset: DatabaseBlockMetaRevisionChangeset,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
) -> SyncResult<Option<DatabaseRevisionChangeset>> {
|
||||||
let block_id = changeset.block_id.clone();
|
let block_id = changeset.block_id.clone();
|
||||||
self.modify_block(&block_id, |block| {
|
self.modify_block(&block_id, |block| {
|
||||||
@ -368,18 +369,18 @@ impl DatabaseRevisionPad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_fields(&self) -> &[Arc<FieldRevision>] {
|
pub fn get_fields(&self) -> &[Arc<FieldRevision>] {
|
||||||
&self.grid_rev.fields
|
&self.database_rev.fields
|
||||||
}
|
}
|
||||||
|
|
||||||
fn modify_grid<F>(&mut self, f: F) -> SyncResult<Option<DatabaseRevisionChangeset>>
|
fn modify_database<F>(&mut self, f: F) -> SyncResult<Option<DatabaseRevisionChangeset>>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut DatabaseRevision) -> SyncResult<Option<()>>,
|
F: FnOnce(&mut DatabaseRevision) -> SyncResult<Option<()>>,
|
||||||
{
|
{
|
||||||
let cloned_grid = self.grid_rev.clone();
|
let cloned_database = self.database_rev.clone();
|
||||||
match f(Arc::make_mut(&mut self.grid_rev))? {
|
match f(Arc::make_mut(&mut self.database_rev))? {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
let old = make_database_rev_json_str(&cloned_grid)?;
|
let old = make_database_rev_json_str(&cloned_database)?;
|
||||||
let new = self.json_str()?;
|
let new = self.json_str()?;
|
||||||
match cal_diff::<EmptyAttributes>(old, new) {
|
match cal_diff::<EmptyAttributes>(old, new) {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
@ -401,9 +402,9 @@ impl DatabaseRevisionPad {
|
|||||||
f: F,
|
f: F,
|
||||||
) -> SyncResult<Option<DatabaseRevisionChangeset>>
|
) -> SyncResult<Option<DatabaseRevisionChangeset>>
|
||||||
where
|
where
|
||||||
F: FnOnce(&mut GridBlockMetaRevision) -> SyncResult<Option<()>>,
|
F: FnOnce(&mut DatabaseBlockMetaRevision) -> SyncResult<Option<()>>,
|
||||||
{
|
{
|
||||||
self.modify_grid(|grid_rev| {
|
self.modify_database(|grid_rev| {
|
||||||
match grid_rev
|
match grid_rev
|
||||||
.blocks
|
.blocks
|
||||||
.iter()
|
.iter()
|
||||||
@ -429,7 +430,7 @@ impl DatabaseRevisionPad {
|
|||||||
where
|
where
|
||||||
F: FnOnce(&mut FieldRevision) -> SyncResult<Option<()>>,
|
F: FnOnce(&mut FieldRevision) -> SyncResult<Option<()>>,
|
||||||
{
|
{
|
||||||
self.modify_grid(|grid_rev| {
|
self.modify_database(|grid_rev| {
|
||||||
match grid_rev
|
match grid_rev
|
||||||
.fields
|
.fields
|
||||||
.iter()
|
.iter()
|
||||||
@ -448,7 +449,7 @@ impl DatabaseRevisionPad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn json_str(&self) -> SyncResult<String> {
|
pub fn json_str(&self) -> SyncResult<String> {
|
||||||
make_database_rev_json_str(&self.grid_rev)
|
make_database_rev_json_str(&self.database_rev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -472,16 +473,16 @@ pub fn make_database_operations(grid_rev: &DatabaseRevision) -> DatabaseOperatio
|
|||||||
pub fn make_database_revisions(_user_id: &str, grid_rev: &DatabaseRevision) -> Vec<Revision> {
|
pub fn make_database_revisions(_user_id: &str, grid_rev: &DatabaseRevision) -> Vec<Revision> {
|
||||||
let operations = make_database_operations(grid_rev);
|
let operations = make_database_operations(grid_rev);
|
||||||
let bytes = operations.json_bytes();
|
let bytes = operations.json_bytes();
|
||||||
let revision = Revision::initial_revision(&grid_rev.grid_id, bytes);
|
let revision = Revision::initial_revision(&grid_rev.database_id, bytes);
|
||||||
vec![revision]
|
vec![revision]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for DatabaseRevisionPad {
|
impl std::default::Default for DatabaseRevisionPad {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let grid = DatabaseRevision::new(&gen_grid_id());
|
let database = DatabaseRevision::new(&gen_database_id());
|
||||||
let operations = make_database_operations(&grid);
|
let operations = make_database_operations(&database);
|
||||||
DatabaseRevisionPad {
|
DatabaseRevisionPad {
|
||||||
grid_rev: Arc::new(grid),
|
database_rev: Arc::new(database),
|
||||||
operations,
|
operations,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
use crate::errors::{internal_sync_error, SyncError, SyncResult};
|
use crate::errors::{internal_sync_error, SyncError, SyncResult};
|
||||||
use crate::util::cal_diff;
|
use crate::util::cal_diff;
|
||||||
use flowy_sync::util::make_operations_from_revisions;
|
use database_model::{
|
||||||
use grid_model::{
|
|
||||||
DatabaseViewRevision, FieldRevision, FieldTypeRevision, FilterRevision,
|
DatabaseViewRevision, FieldRevision, FieldTypeRevision, FilterRevision,
|
||||||
GroupConfigurationRevision, LayoutRevision, SortRevision,
|
GroupConfigurationRevision, LayoutRevision, SortRevision,
|
||||||
};
|
};
|
||||||
|
use flowy_sync::util::make_operations_from_revisions;
|
||||||
use lib_infra::util::md5;
|
use lib_infra::util::md5;
|
||||||
use lib_ot::core::{DeltaBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
use lib_ot::core::{DeltaBuilder, DeltaOperations, EmptyAttributes, OperationTransform};
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
@ -14,12 +14,12 @@ pub type GridViewOperations = DeltaOperations<EmptyAttributes>;
|
|||||||
pub type GridViewOperationsBuilder = DeltaBuilder;
|
pub type GridViewOperationsBuilder = DeltaBuilder;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct GridViewRevisionPad {
|
pub struct DatabaseViewRevisionPad {
|
||||||
view: Arc<DatabaseViewRevision>,
|
view: Arc<DatabaseViewRevision>,
|
||||||
operations: GridViewOperations,
|
operations: GridViewOperations,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::ops::Deref for GridViewRevisionPad {
|
impl std::ops::Deref for DatabaseViewRevisionPad {
|
||||||
type Target = DatabaseViewRevision;
|
type Target = DatabaseViewRevision;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
@ -27,23 +27,19 @@ impl std::ops::Deref for GridViewRevisionPad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridViewRevisionPad {
|
impl DatabaseViewRevisionPad {
|
||||||
// For the moment, the view_id is equal to grid_id. The grid_id represents the database id.
|
// For the moment, the view_id is equal to grid_id. The database_id represents the database id.
|
||||||
// A database can be referenced by multiple views.
|
// A database can be referenced by multiple views.
|
||||||
pub fn new(grid_id: String, view_id: String, layout: LayoutRevision) -> Self {
|
pub fn new(database_id: String, view_id: String, layout: LayoutRevision) -> Self {
|
||||||
let view = Arc::new(DatabaseViewRevision::new(grid_id, view_id, layout));
|
let view = Arc::new(DatabaseViewRevision::new(database_id, view_id, layout));
|
||||||
let json = serde_json::to_string(&view).unwrap();
|
let json = serde_json::to_string(&view).unwrap();
|
||||||
let operations = GridViewOperationsBuilder::new().insert(&json).build();
|
let operations = GridViewOperationsBuilder::new().insert(&json).build();
|
||||||
Self { view, operations }
|
Self { view, operations }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_operations(view_id: &str, operations: GridViewOperations) -> SyncResult<Self> {
|
pub fn from_operations(operations: GridViewOperations) -> SyncResult<Self> {
|
||||||
if operations.is_empty() {
|
if operations.is_empty() {
|
||||||
return Ok(GridViewRevisionPad::new(
|
return Err(SyncError::record_not_found().context("Unexpected empty operations"));
|
||||||
view_id.to_owned(),
|
|
||||||
view_id.to_owned(),
|
|
||||||
LayoutRevision::Grid,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
let s = operations.content()?;
|
let s = operations.content()?;
|
||||||
let view: DatabaseViewRevision = serde_json::from_str(&s).map_err(|e| {
|
let view: DatabaseViewRevision = serde_json::from_str(&s).map_err(|e| {
|
||||||
@ -57,9 +53,9 @@ impl GridViewRevisionPad {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_revisions(view_id: &str, revisions: Vec<Revision>) -> SyncResult<Self> {
|
pub fn from_revisions(revisions: Vec<Revision>) -> SyncResult<Self> {
|
||||||
let operations: GridViewOperations = make_operations_from_revisions(revisions)?;
|
let operations: GridViewOperations = make_operations_from_revisions(revisions)?;
|
||||||
Self::from_operations(view_id, operations)
|
Self::from_operations(operations)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_groups_by_field_revs(
|
pub fn get_groups_by_field_revs(
|
@ -1,9 +1,9 @@
|
|||||||
mod block_revision_pad;
|
mod block_revision_pad;
|
||||||
mod database_builder;
|
mod database_builder;
|
||||||
mod database_revision_pad;
|
mod database_revision_pad;
|
||||||
mod view_revision_pad;
|
mod database_view_revision_pad;
|
||||||
|
|
||||||
pub use block_revision_pad::*;
|
pub use block_revision_pad::*;
|
||||||
pub use database_builder::*;
|
pub use database_builder::*;
|
||||||
pub use database_revision_pad::*;
|
pub use database_revision_pad::*;
|
||||||
pub use view_revision_pad::*;
|
pub use database_view_revision_pad::*;
|
||||||
|
@ -12,7 +12,7 @@ flowy-user = { path = "../flowy-user" }
|
|||||||
flowy-net = { path = "../flowy-net" }
|
flowy-net = { path = "../flowy-net" }
|
||||||
flowy-folder = { path = "../flowy-folder" }
|
flowy-folder = { path = "../flowy-folder" }
|
||||||
flowy-database = { path = "../flowy-database" }
|
flowy-database = { path = "../flowy-database" }
|
||||||
grid-model = { path = "../../../shared-lib/grid-model" }
|
database-model = { path = "../../../shared-lib/database-model" }
|
||||||
user-model = { path = "../../../shared-lib/user-model" }
|
user-model = { path = "../../../shared-lib/user-model" }
|
||||||
flowy-client-ws = { path = "../../../shared-lib/flowy-client-ws" }
|
flowy-client-ws = { path = "../../../shared-lib/flowy-client-ws" }
|
||||||
flowy-sqlite = { path = "../flowy-sqlite", optional = true }
|
flowy-sqlite = { path = "../flowy-sqlite", optional = true }
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
|
|
||||||
|
use database_model::BuildDatabaseContext;
|
||||||
use flowy_client_ws::FlowyWebSocketConnect;
|
use flowy_client_ws::FlowyWebSocketConnect;
|
||||||
use flowy_database::entities::LayoutTypePB;
|
use flowy_database::entities::LayoutTypePB;
|
||||||
use flowy_database::manager::{make_database_view_data, DatabaseManager};
|
use flowy_database::manager::{make_database_view_data, DatabaseManager};
|
||||||
@ -19,7 +20,6 @@ use flowy_net::{http_server::folder::FolderHttpCloudService, local_server::Local
|
|||||||
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
|
use flowy_revision::{RevisionWebSocket, WSStateReceiver};
|
||||||
use flowy_user::services::UserSession;
|
use flowy_user::services::UserSession;
|
||||||
use futures_core::future::BoxFuture;
|
use futures_core::future::BoxFuture;
|
||||||
use grid_model::BuildDatabaseContext;
|
|
||||||
use lib_infra::future::{BoxResultFuture, FutureResult};
|
use lib_infra::future::{BoxResultFuture, FutureResult};
|
||||||
use lib_ws::{WSChannel, WSMessageReceiver, WebSocketRawMessage};
|
use lib_ws::{WSChannel, WSMessageReceiver, WebSocketRawMessage};
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
@ -36,7 +36,7 @@ impl FolderDepsResolver {
|
|||||||
server_config: &ClientServerConfiguration,
|
server_config: &ClientServerConfiguration,
|
||||||
ws_conn: &Arc<FlowyWebSocketConnect>,
|
ws_conn: &Arc<FlowyWebSocketConnect>,
|
||||||
text_block_manager: &Arc<DocumentManager>,
|
text_block_manager: &Arc<DocumentManager>,
|
||||||
grid_manager: &Arc<DatabaseManager>,
|
database_manager: &Arc<DatabaseManager>,
|
||||||
) -> Arc<FolderManager> {
|
) -> Arc<FolderManager> {
|
||||||
let user: Arc<dyn WorkspaceUser> = Arc::new(WorkspaceUserImpl(user_session.clone()));
|
let user: Arc<dyn WorkspaceUser> = Arc::new(WorkspaceUserImpl(user_session.clone()));
|
||||||
let database: Arc<dyn WorkspaceDatabase> = Arc::new(WorkspaceDatabaseImpl(user_session));
|
let database: Arc<dyn WorkspaceDatabase> = Arc::new(WorkspaceDatabaseImpl(user_session));
|
||||||
@ -47,7 +47,7 @@ impl FolderDepsResolver {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let view_data_processor =
|
let view_data_processor =
|
||||||
make_view_data_processor(text_block_manager.clone(), grid_manager.clone());
|
make_view_data_processor(text_block_manager.clone(), database_manager.clone());
|
||||||
let folder_manager = Arc::new(
|
let folder_manager = Arc::new(
|
||||||
FolderManager::new(
|
FolderManager::new(
|
||||||
user.clone(),
|
user.clone(),
|
||||||
@ -74,7 +74,7 @@ impl FolderDepsResolver {
|
|||||||
|
|
||||||
fn make_view_data_processor(
|
fn make_view_data_processor(
|
||||||
document_manager: Arc<DocumentManager>,
|
document_manager: Arc<DocumentManager>,
|
||||||
grid_manager: Arc<DatabaseManager>,
|
database_manager: Arc<DatabaseManager>,
|
||||||
) -> ViewDataProcessorMap {
|
) -> ViewDataProcessorMap {
|
||||||
let mut map: HashMap<ViewDataFormatPB, Arc<dyn ViewDataProcessor + Send + Sync>> = HashMap::new();
|
let mut map: HashMap<ViewDataFormatPB, Arc<dyn ViewDataProcessor + Send + Sync>> = HashMap::new();
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ fn make_view_data_processor(
|
|||||||
map.insert(data_type, document_processor.clone());
|
map.insert(data_type, document_processor.clone());
|
||||||
});
|
});
|
||||||
|
|
||||||
let grid_data_impl = Arc::new(GridViewDataProcessor(grid_manager));
|
let grid_data_impl = Arc::new(GridViewDataProcessor(database_manager));
|
||||||
grid_data_impl
|
grid_data_impl
|
||||||
.data_types()
|
.data_types()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -177,7 +177,7 @@ impl ViewDataProcessor for DocumentViewDataProcessor {
|
|||||||
debug_assert_eq!(layout, ViewLayoutTypePB::Document);
|
debug_assert_eq!(layout, ViewLayoutTypePB::Document);
|
||||||
let view_data = match String::from_utf8(view_data.to_vec()) {
|
let view_data = match String::from_utf8(view_data.to_vec()) {
|
||||||
Ok(content) => match make_transaction_from_document_content(&content) {
|
Ok(content) => match make_transaction_from_document_content(&content) {
|
||||||
Ok(transaction) => transaction.to_bytes().unwrap_or(vec![]),
|
Ok(transaction) => transaction.to_bytes().unwrap_or_else(|_| vec![]),
|
||||||
Err(_) => vec![],
|
Err(_) => vec![],
|
||||||
},
|
},
|
||||||
Err(_) => vec![],
|
Err(_) => vec![],
|
||||||
@ -259,9 +259,9 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
|||||||
) -> FutureResult<(), FlowyError> {
|
) -> FutureResult<(), FlowyError> {
|
||||||
let revision = Revision::initial_revision(view_id, delta_data);
|
let revision = Revision::initial_revision(view_id, delta_data);
|
||||||
let view_id = view_id.to_string();
|
let view_id = view_id.to_string();
|
||||||
let grid_manager = self.0.clone();
|
let database_manager = self.0.clone();
|
||||||
FutureResult::new(async move {
|
FutureResult::new(async move {
|
||||||
grid_manager
|
database_manager
|
||||||
.create_database(view_id, vec![revision])
|
.create_database(view_id, vec![revision])
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -269,20 +269,20 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn close_view(&self, view_id: &str) -> FutureResult<(), FlowyError> {
|
fn close_view(&self, view_id: &str) -> FutureResult<(), FlowyError> {
|
||||||
let grid_manager = self.0.clone();
|
let database_manager = self.0.clone();
|
||||||
let view_id = view_id.to_string();
|
let view_id = view_id.to_string();
|
||||||
FutureResult::new(async move {
|
FutureResult::new(async move {
|
||||||
grid_manager.close_database(view_id).await?;
|
database_manager.close_database(view_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_view_data(&self, view: &ViewPB) -> FutureResult<Bytes, FlowyError> {
|
fn get_view_data(&self, view: &ViewPB) -> FutureResult<Bytes, FlowyError> {
|
||||||
let grid_manager = self.0.clone();
|
let database_manager = self.0.clone();
|
||||||
let view_id = view.id.clone();
|
let view_id = view.id.clone();
|
||||||
FutureResult::new(async move {
|
FutureResult::new(async move {
|
||||||
let editor = grid_manager.open_database(view_id).await?;
|
let editor = database_manager.open_database(view_id).await?;
|
||||||
let delta_bytes = editor.duplicate_grid().await?;
|
let delta_bytes = editor.duplicate_database().await?;
|
||||||
Ok(delta_bytes.into())
|
Ok(delta_bytes.into())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -308,9 +308,9 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
|||||||
|
|
||||||
let user_id = user_id.to_string();
|
let user_id = user_id.to_string();
|
||||||
let view_id = view_id.to_string();
|
let view_id = view_id.to_string();
|
||||||
let grid_manager = self.0.clone();
|
let database_manager = self.0.clone();
|
||||||
FutureResult::new(async move {
|
FutureResult::new(async move {
|
||||||
make_database_view_data(&user_id, &view_id, layout, grid_manager, build_context).await
|
make_database_view_data(&user_id, &view_id, layout, database_manager, build_context).await
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
|||||||
) -> FutureResult<Bytes, FlowyError> {
|
) -> FutureResult<Bytes, FlowyError> {
|
||||||
let user_id = user_id.to_string();
|
let user_id = user_id.to_string();
|
||||||
let view_id = view_id.to_string();
|
let view_id = view_id.to_string();
|
||||||
let grid_manager = self.0.clone();
|
let database_manager = self.0.clone();
|
||||||
|
|
||||||
let layout = match layout {
|
let layout = match layout {
|
||||||
ViewLayoutTypePB::Grid => LayoutTypePB::Grid,
|
ViewLayoutTypePB::Grid => LayoutTypePB::Grid,
|
||||||
@ -339,7 +339,7 @@ impl ViewDataProcessor for GridViewDataProcessor {
|
|||||||
FutureResult::new(async move {
|
FutureResult::new(async move {
|
||||||
let bytes = Bytes::from(data);
|
let bytes = Bytes::from(data);
|
||||||
let build_context = BuildDatabaseContext::try_from(bytes)?;
|
let build_context = BuildDatabaseContext::try_from(bytes)?;
|
||||||
make_database_view_data(&user_id, &view_id, layout, grid_manager, build_context).await
|
make_database_view_data(&user_id, &view_id, layout, database_manager, build_context).await
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ flowy-error = { path = "../flowy-error", features = ["adaptor_database", "adapto
|
|||||||
flowy-derive = { path = "../flowy-derive" }
|
flowy-derive = { path = "../flowy-derive" }
|
||||||
lib-ot = { path = "../../../shared-lib/lib-ot" }
|
lib-ot = { path = "../../../shared-lib/lib-ot" }
|
||||||
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
lib-infra = { path = "../../../shared-lib/lib-infra" }
|
||||||
grid-model = { path = "../../../shared-lib/grid-model" }
|
database-model = { path = "../../../shared-lib/database-model" }
|
||||||
flowy-client-sync = { path = "../flowy-client-sync"}
|
flowy-client-sync = { path = "../flowy-client-sync"}
|
||||||
revision-model = { path = "../../../shared-lib/revision-model" }
|
revision-model = { path = "../../../shared-lib/revision-model" }
|
||||||
flowy-sqlite = { path = "../flowy-sqlite", optional = true }
|
flowy-sqlite = { path = "../flowy-sqlite", optional = true }
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::entities::parser::NotEmptyStr;
|
use crate::entities::parser::NotEmptyStr;
|
||||||
use crate::entities::FieldType;
|
use crate::entities::FieldType;
|
||||||
|
use database_model::{CellRevision, RowChangeset};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::{CellRevision, RowChangeset};
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
#[derive(ProtoBuf, Default)]
|
#[derive(ProtoBuf, Default)]
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
use database_model::{FieldRevision, FieldTypeRevision};
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::{FieldRevision, FieldTypeRevision};
|
|
||||||
use serde_repr::*;
|
use serde_repr::*;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ impl std::convert::From<&Arc<FieldRevision>> for FieldIdPB {
|
|||||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
#[derive(Debug, Clone, Default, ProtoBuf)]
|
||||||
pub struct DatabaseFieldChangesetPB {
|
pub struct DatabaseFieldChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub inserted_fields: Vec<IndexFieldPB>,
|
pub inserted_fields: Vec<IndexFieldPB>,
|
||||||
@ -103,7 +103,7 @@ pub struct DatabaseFieldChangesetPB {
|
|||||||
impl DatabaseFieldChangesetPB {
|
impl DatabaseFieldChangesetPB {
|
||||||
pub fn insert(database_id: &str, inserted_fields: Vec<IndexFieldPB>) -> Self {
|
pub fn insert(database_id: &str, inserted_fields: Vec<IndexFieldPB>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
database_id: database_id.to_owned(),
|
view_id: database_id.to_owned(),
|
||||||
inserted_fields,
|
inserted_fields,
|
||||||
deleted_fields: vec![],
|
deleted_fields: vec![],
|
||||||
updated_fields: vec![],
|
updated_fields: vec![],
|
||||||
@ -112,7 +112,7 @@ impl DatabaseFieldChangesetPB {
|
|||||||
|
|
||||||
pub fn delete(database_id: &str, deleted_fields: Vec<FieldIdPB>) -> Self {
|
pub fn delete(database_id: &str, deleted_fields: Vec<FieldIdPB>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
database_id: database_id.to_string(),
|
view_id: database_id.to_string(),
|
||||||
inserted_fields: vec![],
|
inserted_fields: vec![],
|
||||||
deleted_fields,
|
deleted_fields,
|
||||||
updated_fields: vec![],
|
updated_fields: vec![],
|
||||||
@ -121,7 +121,7 @@ impl DatabaseFieldChangesetPB {
|
|||||||
|
|
||||||
pub fn update(database_id: &str, updated_fields: Vec<FieldPB>) -> Self {
|
pub fn update(database_id: &str, updated_fields: Vec<FieldPB>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
database_id: database_id.to_string(),
|
view_id: database_id.to_string(),
|
||||||
inserted_fields: vec![],
|
inserted_fields: vec![],
|
||||||
deleted_fields: vec![],
|
deleted_fields: vec![],
|
||||||
updated_fields,
|
updated_fields,
|
||||||
@ -150,7 +150,7 @@ impl IndexFieldPB {
|
|||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
pub struct CreateFieldPayloadPB {
|
pub struct CreateFieldPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub field_type: FieldType,
|
pub field_type: FieldType,
|
||||||
@ -161,7 +161,7 @@ pub struct CreateFieldPayloadPB {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CreateFieldParams {
|
pub struct CreateFieldParams {
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
pub field_type: FieldType,
|
pub field_type: FieldType,
|
||||||
pub type_option_data: Option<Vec<u8>>,
|
pub type_option_data: Option<Vec<u8>>,
|
||||||
}
|
}
|
||||||
@ -170,10 +170,9 @@ impl TryInto<CreateFieldParams> for CreateFieldPayloadPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateFieldParams, Self::Error> {
|
fn try_into(self) -> Result<CreateFieldParams, Self::Error> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
|
||||||
Ok(CreateFieldParams {
|
Ok(CreateFieldParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
field_type: self.field_type,
|
field_type: self.field_type,
|
||||||
type_option_data: self.type_option_data,
|
type_option_data: self.type_option_data,
|
||||||
})
|
})
|
||||||
@ -183,7 +182,7 @@ impl TryInto<CreateFieldParams> for CreateFieldPayloadPB {
|
|||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
pub struct UpdateFieldTypePayloadPB {
|
pub struct UpdateFieldTypePayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
@ -196,7 +195,7 @@ pub struct UpdateFieldTypePayloadPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct EditFieldParams {
|
pub struct EditFieldParams {
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
pub field_type: FieldType,
|
pub field_type: FieldType,
|
||||||
}
|
}
|
||||||
@ -205,11 +204,10 @@ 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> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
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)?;
|
||||||
Ok(EditFieldParams {
|
Ok(EditFieldParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
field_id: field_id.0,
|
field_id: field_id.0,
|
||||||
field_type: self.field_type,
|
field_type: self.field_type,
|
||||||
})
|
})
|
||||||
@ -219,7 +217,7 @@ impl TryInto<EditFieldParams> for UpdateFieldTypePayloadPB {
|
|||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
pub struct TypeOptionPathPB {
|
pub struct TypeOptionPathPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
@ -229,7 +227,7 @@ pub struct TypeOptionPathPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct TypeOptionPathParams {
|
pub struct TypeOptionPathParams {
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
pub field_type: FieldType,
|
pub field_type: FieldType,
|
||||||
}
|
}
|
||||||
@ -238,11 +236,10 @@ impl TryInto<TypeOptionPathParams> for TypeOptionPathPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<TypeOptionPathParams, Self::Error> {
|
fn try_into(self) -> Result<TypeOptionPathParams, Self::Error> {
|
||||||
let database_id =
|
let database_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
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)?;
|
||||||
Ok(TypeOptionPathParams {
|
Ok(TypeOptionPathParams {
|
||||||
database_id: database_id.0,
|
view_id: database_id.0,
|
||||||
field_id: field_id.0,
|
field_id: field_id.0,
|
||||||
field_type: self.field_type,
|
field_type: self.field_type,
|
||||||
})
|
})
|
||||||
@ -252,7 +249,7 @@ impl TryInto<TypeOptionPathParams> for TypeOptionPathPB {
|
|||||||
#[derive(Debug, Default, ProtoBuf)]
|
#[derive(Debug, Default, ProtoBuf)]
|
||||||
pub struct TypeOptionPB {
|
pub struct TypeOptionPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub field: FieldPB,
|
pub field: FieldPB,
|
||||||
@ -317,7 +314,7 @@ impl std::convert::From<String> for RepeatedFieldIdPB {
|
|||||||
#[derive(ProtoBuf, Default)]
|
#[derive(ProtoBuf, Default)]
|
||||||
pub struct TypeOptionChangesetPB {
|
pub struct TypeOptionChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
@ -329,7 +326,7 @@ pub struct TypeOptionChangesetPB {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TypeOptionChangesetParams {
|
pub struct TypeOptionChangesetParams {
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
pub type_option_data: Vec<u8>,
|
pub type_option_data: Vec<u8>,
|
||||||
}
|
}
|
||||||
@ -338,12 +335,11 @@ impl TryInto<TypeOptionChangesetParams> for TypeOptionChangesetPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<TypeOptionChangesetParams, Self::Error> {
|
fn try_into(self) -> Result<TypeOptionChangesetParams, Self::Error> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
|
||||||
let _ = NotEmptyStr::parse(self.field_id.clone()).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
|
let _ = NotEmptyStr::parse(self.field_id.clone()).map_err(|_| ErrorCode::FieldIdIsEmpty)?;
|
||||||
|
|
||||||
Ok(TypeOptionChangesetParams {
|
Ok(TypeOptionChangesetParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
field_id: self.field_id,
|
field_id: self.field_id,
|
||||||
type_option_data: self.type_option_data,
|
type_option_data: self.type_option_data,
|
||||||
})
|
})
|
||||||
@ -353,14 +349,14 @@ impl TryInto<TypeOptionChangesetParams> for TypeOptionChangesetPB {
|
|||||||
#[derive(ProtoBuf, Default)]
|
#[derive(ProtoBuf, Default)]
|
||||||
pub struct GetFieldPayloadPB {
|
pub struct GetFieldPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2, one_of)]
|
#[pb(index = 2, one_of)]
|
||||||
pub field_ids: Option<RepeatedFieldIdPB>,
|
pub field_ids: Option<RepeatedFieldIdPB>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GetFieldParams {
|
pub struct GetFieldParams {
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
pub field_ids: Option<Vec<String>>,
|
pub field_ids: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,8 +364,7 @@ impl TryInto<GetFieldParams> for GetFieldPayloadPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<GetFieldParams, Self::Error> {
|
fn try_into(self) -> Result<GetFieldParams, Self::Error> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
|
||||||
let field_ids = self.field_ids.map(|repeated| {
|
let field_ids = self.field_ids.map(|repeated| {
|
||||||
repeated
|
repeated
|
||||||
.items
|
.items
|
||||||
@ -379,7 +374,7 @@ impl TryInto<GetFieldParams> for GetFieldPayloadPB {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Ok(GetFieldParams {
|
Ok(GetFieldParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
field_ids,
|
field_ids,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -624,27 +619,26 @@ pub struct DuplicateFieldPayloadPB {
|
|||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, ProtoBuf)]
|
// #[derive(Debug, Clone, Default, ProtoBuf)]
|
||||||
pub struct GridFieldIdentifierPayloadPB {
|
// pub struct GridFieldIdentifierPayloadPB {
|
||||||
#[pb(index = 1)]
|
// #[pb(index = 1)]
|
||||||
pub field_id: String,
|
// pub field_id: String,
|
||||||
|
//
|
||||||
#[pb(index = 2)]
|
// #[pb(index = 2)]
|
||||||
pub database_id: String,
|
// pub view_id: String,
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl TryInto<FieldIdParams> for DuplicateFieldPayloadPB {
|
impl TryInto<FieldIdParams> for DuplicateFieldPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<FieldIdParams, Self::Error> {
|
fn try_into(self) -> Result<FieldIdParams, Self::Error> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
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)?;
|
||||||
Ok(FieldIdParams {
|
Ok(FieldIdParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
field_id: field_id.0,
|
field_id: field_id.0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -656,18 +650,17 @@ pub struct DeleteFieldPayloadPB {
|
|||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryInto<FieldIdParams> for DeleteFieldPayloadPB {
|
impl TryInto<FieldIdParams> for DeleteFieldPayloadPB {
|
||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<FieldIdParams, Self::Error> {
|
fn try_into(self) -> Result<FieldIdParams, Self::Error> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
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)?;
|
||||||
Ok(FieldIdParams {
|
Ok(FieldIdParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
field_id: field_id.0,
|
field_id: field_id.0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -675,5 +668,5 @@ impl TryInto<FieldIdParams> for DeleteFieldPayloadPB {
|
|||||||
|
|
||||||
pub struct FieldIdParams {
|
pub struct FieldIdParams {
|
||||||
pub field_id: String,
|
pub field_id: String,
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::services::filter::FromFilterString;
|
use crate::services::filter::FromFilterString;
|
||||||
|
use database_model::FilterRevision;
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::FilterRevision;
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct CheckboxFilterPB {
|
pub struct CheckboxFilterPB {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::services::filter::FromFilterString;
|
use crate::services::filter::FromFilterString;
|
||||||
|
use database_model::FilterRevision;
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::FilterRevision;
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct ChecklistFilterPB {
|
pub struct ChecklistFilterPB {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::services::filter::FromFilterString;
|
use crate::services::filter::FromFilterString;
|
||||||
|
use database_model::FilterRevision;
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::FilterRevision;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::services::filter::FromFilterString;
|
use crate::services::filter::FromFilterString;
|
||||||
|
use database_model::FilterRevision;
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::FilterRevision;
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct NumberFilterPB {
|
pub struct NumberFilterPB {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::services::field::SelectOptionIds;
|
use crate::services::field::SelectOptionIds;
|
||||||
use crate::services::filter::FromFilterString;
|
use crate::services::filter::FromFilterString;
|
||||||
|
use database_model::FilterRevision;
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::FilterRevision;
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct SelectOptionFilterPB {
|
pub struct SelectOptionFilterPB {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::services::filter::FromFilterString;
|
use crate::services::filter::FromFilterString;
|
||||||
|
use database_model::FilterRevision;
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::FilterRevision;
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct TextFilterPB {
|
pub struct TextFilterPB {
|
||||||
|
@ -6,9 +6,9 @@ use crate::entities::{
|
|||||||
use crate::services::field::SelectOptionIds;
|
use crate::services::field::SelectOptionIds;
|
||||||
use crate::services::filter::FilterType;
|
use crate::services::filter::FilterType;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, FieldTypeRevision, FilterRevision};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::{FieldRevision, FieldTypeRevision, FilterRevision};
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
@ -23,12 +23,12 @@ pub struct CreateDatabasePayloadPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, ProtoBuf, Default, Debug)]
|
#[derive(Clone, ProtoBuf, Default, Debug)]
|
||||||
pub struct DatabaseIdPB {
|
pub struct DatabaseViewIdPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub value: String,
|
pub value: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsRef<str> for DatabaseIdPB {
|
impl AsRef<str> for DatabaseViewIdPB {
|
||||||
fn as_ref(&self) -> &str {
|
fn as_ref(&self) -> &str {
|
||||||
&self.value
|
&self.value
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
use database_model::{GroupRevision, SelectOptionGroupConfigurationRevision};
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use grid_model::{GroupRevision, SelectOptionGroupConfigurationRevision};
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct UrlGroupConfigurationPB {
|
pub struct UrlGroupConfigurationPB {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
use crate::entities::parser::NotEmptyStr;
|
use crate::entities::parser::NotEmptyStr;
|
||||||
use crate::entities::{CreateRowParams, FieldType, LayoutTypePB, RowPB};
|
use crate::entities::{CreateRowParams, FieldType, LayoutTypePB, RowPB};
|
||||||
use crate::services::group::Group;
|
use crate::services::group::Group;
|
||||||
|
use database_model::{FieldTypeRevision, GroupConfigurationRevision};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::{FieldTypeRevision, GroupConfigurationRevision};
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(ProtoBuf, Debug, Default, Clone)]
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct CreateBoardCardPayloadPB {
|
pub struct CreateBoardCardPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub group_id: String,
|
pub group_id: String,
|
||||||
@ -23,8 +23,7 @@ impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
|
||||||
let group_id = NotEmptyStr::parse(self.group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;
|
let group_id = NotEmptyStr::parse(self.group_id).map_err(|_| ErrorCode::GroupIdIsEmpty)?;
|
||||||
let start_row_id = match self.start_row_id {
|
let start_row_id = match self.start_row_id {
|
||||||
None => None,
|
None => None,
|
||||||
@ -35,7 +34,7 @@ impl TryInto<CreateRowParams> for CreateBoardCardPayloadPB {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
Ok(CreateRowParams {
|
Ok(CreateRowParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
start_row_id,
|
start_row_id,
|
||||||
group_id: Some(group_id.0),
|
group_id: Some(group_id.0),
|
||||||
layout: LayoutTypePB::Board,
|
layout: LayoutTypePB::Board,
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::entities::parser::NotEmptyStr;
|
use crate::entities::parser::NotEmptyStr;
|
||||||
use crate::entities::LayoutTypePB;
|
use crate::entities::LayoutTypePB;
|
||||||
|
use database_model::RowRevision;
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::RowRevision;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
/// [RowPB] Describes a row. Has the id of the parent Block. Has the metadata of the row.
|
/// [RowPB] Describes a row. Has the id of the parent Block. Has the metadata of the row.
|
||||||
@ -136,14 +136,14 @@ pub struct UpdatedRowPB {
|
|||||||
#[derive(Debug, Default, Clone, ProtoBuf)]
|
#[derive(Debug, Default, Clone, ProtoBuf)]
|
||||||
pub struct RowIdPB {
|
pub struct RowIdPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub row_id: String,
|
pub row_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct RowIdParams {
|
pub struct RowIdParams {
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
pub row_id: String,
|
pub row_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,12 +151,11 @@ impl TryInto<RowIdParams> for RowIdPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<RowIdParams, Self::Error> {
|
fn try_into(self) -> Result<RowIdParams, Self::Error> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
|
||||||
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(RowIdParams {
|
Ok(RowIdParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
row_id: row_id.0,
|
row_id: row_id.0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -174,7 +173,7 @@ pub struct BlockRowIdPB {
|
|||||||
#[derive(ProtoBuf, Default)]
|
#[derive(ProtoBuf, Default)]
|
||||||
pub struct CreateRowPayloadPB {
|
pub struct CreateRowPayloadPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2, one_of)]
|
#[pb(index = 2, one_of)]
|
||||||
pub start_row_id: Option<String>,
|
pub start_row_id: Option<String>,
|
||||||
@ -182,7 +181,7 @@ pub struct CreateRowPayloadPB {
|
|||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct CreateRowParams {
|
pub struct CreateRowParams {
|
||||||
pub database_id: String,
|
pub view_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: LayoutTypePB,
|
pub layout: LayoutTypePB,
|
||||||
@ -192,11 +191,10 @@ 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> {
|
||||||
let database_id =
|
let view_id = NotEmptyStr::parse(self.view_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
||||||
NotEmptyStr::parse(self.database_id).map_err(|_| ErrorCode::DatabaseIdIsEmpty)?;
|
|
||||||
|
|
||||||
Ok(CreateRowParams {
|
Ok(CreateRowParams {
|
||||||
database_id: database_id.0,
|
view_id: view_id.0,
|
||||||
start_row_id: self.start_row_id,
|
start_row_id: self.start_row_id,
|
||||||
group_id: None,
|
group_id: None,
|
||||||
layout: LayoutTypePB::Grid,
|
layout: LayoutTypePB::Grid,
|
||||||
|
@ -5,9 +5,9 @@ use crate::entities::{
|
|||||||
DeleteSortPayloadPB, InsertGroupParams, InsertGroupPayloadPB, RepeatedFilterPB,
|
DeleteSortPayloadPB, InsertGroupParams, InsertGroupPayloadPB, RepeatedFilterPB,
|
||||||
RepeatedGroupConfigurationPB, RepeatedSortPB,
|
RepeatedGroupConfigurationPB, RepeatedSortPB,
|
||||||
};
|
};
|
||||||
|
use database_model::LayoutRevision;
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::LayoutRevision;
|
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
use strum_macros::EnumIter;
|
use strum_macros::EnumIter;
|
||||||
@ -85,7 +85,7 @@ impl std::convert::From<LayoutTypePB> for LayoutRevision {
|
|||||||
#[derive(Default, ProtoBuf)]
|
#[derive(Default, ProtoBuf)]
|
||||||
pub struct DatabaseSettingChangesetPB {
|
pub struct DatabaseSettingChangesetPB {
|
||||||
#[pb(index = 1)]
|
#[pb(index = 1)]
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
|
|
||||||
#[pb(index = 2)]
|
#[pb(index = 2)]
|
||||||
pub layout_type: LayoutTypePB,
|
pub layout_type: LayoutTypePB,
|
||||||
@ -113,7 +113,7 @@ impl TryInto<DatabaseSettingChangesetParams> for DatabaseSettingChangesetPB {
|
|||||||
type Error = ErrorCode;
|
type Error = ErrorCode;
|
||||||
|
|
||||||
fn try_into(self) -> Result<DatabaseSettingChangesetParams, Self::Error> {
|
fn try_into(self) -> Result<DatabaseSettingChangesetParams, Self::Error> {
|
||||||
let database_id = NotEmptyStr::parse(self.database_id)
|
let view_id = NotEmptyStr::parse(self.view_id)
|
||||||
.map_err(|_| ErrorCode::ViewIdInvalid)?
|
.map_err(|_| ErrorCode::ViewIdInvalid)?
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ impl TryInto<DatabaseSettingChangesetParams> for DatabaseSettingChangesetPB {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(DatabaseSettingChangesetParams {
|
Ok(DatabaseSettingChangesetParams {
|
||||||
database_id,
|
view_id,
|
||||||
layout_type: self.layout_type.into(),
|
layout_type: self.layout_type.into(),
|
||||||
insert_filter,
|
insert_filter,
|
||||||
delete_filter,
|
delete_filter,
|
||||||
@ -161,7 +161,7 @@ impl TryInto<DatabaseSettingChangesetParams> for DatabaseSettingChangesetPB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct DatabaseSettingChangesetParams {
|
pub struct DatabaseSettingChangesetParams {
|
||||||
pub database_id: String,
|
pub view_id: String,
|
||||||
pub layout_type: LayoutRevision,
|
pub layout_type: LayoutRevision,
|
||||||
pub insert_filter: Option<AlterFilterParams>,
|
pub insert_filter: Option<AlterFilterParams>,
|
||||||
pub delete_filter: Option<DeleteFilterParams>,
|
pub delete_filter: Option<DeleteFilterParams>,
|
||||||
|
@ -3,9 +3,9 @@ use crate::entities::FieldType;
|
|||||||
use crate::services::sort::SortType;
|
use crate::services::sort::SortType;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use database_model::{FieldTypeRevision, SortCondition, SortRevision};
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::ErrorCode;
|
use flowy_error::ErrorCode;
|
||||||
use grid_model::{FieldTypeRevision, SortCondition, SortRevision};
|
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
||||||
pub struct SortPB {
|
pub struct SortPB {
|
||||||
|
@ -8,17 +8,17 @@ use crate::services::field::{
|
|||||||
SelectOptionChangeset, SelectOptionChangesetPB, SelectOptionIds, SelectOptionPB,
|
SelectOptionChangeset, SelectOptionChangesetPB, SelectOptionIds, SelectOptionPB,
|
||||||
};
|
};
|
||||||
use crate::services::row::make_row_from_row_rev;
|
use crate::services::row::make_row_from_row_rev;
|
||||||
|
use database_model::FieldRevision;
|
||||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||||
use grid_model::FieldRevision;
|
|
||||||
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
|
use lib_dispatch::prelude::{data_result, AFPluginData, AFPluginState, DataResult};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn get_database_data_handler(
|
pub(crate) async fn get_database_data_handler(
|
||||||
data: AFPluginData<DatabaseIdPB>,
|
data: AFPluginData<DatabaseViewIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<DatabasePB, FlowyError> {
|
) -> DataResult<DatabasePB, FlowyError> {
|
||||||
let database_id: DatabaseIdPB = data.into_inner();
|
let database_id: DatabaseViewIdPB = data.into_inner();
|
||||||
let editor = manager.open_database(database_id.as_ref()).await?;
|
let editor = manager.open_database(database_id.as_ref()).await?;
|
||||||
let database = editor.get_database(database_id.as_ref()).await?;
|
let database = editor.get_database(database_id.as_ref()).await?;
|
||||||
data_result(database)
|
data_result(database)
|
||||||
@ -26,10 +26,10 @@ pub(crate) async fn get_database_data_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn get_database_setting_handler(
|
pub(crate) async fn get_database_setting_handler(
|
||||||
data: AFPluginData<DatabaseIdPB>,
|
data: AFPluginData<DatabaseViewIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<DatabaseViewSettingPB, FlowyError> {
|
) -> DataResult<DatabaseViewSettingPB, FlowyError> {
|
||||||
let database_id: DatabaseIdPB = data.into_inner();
|
let database_id: DatabaseViewIdPB = data.into_inner();
|
||||||
let editor = manager.open_database(database_id).await?;
|
let editor = manager.open_database(database_id).await?;
|
||||||
let database_setting = editor.get_setting().await?;
|
let database_setting = editor.get_setting().await?;
|
||||||
data_result(database_setting)
|
data_result(database_setting)
|
||||||
@ -42,7 +42,7 @@ pub(crate) async fn update_database_setting_handler(
|
|||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: DatabaseSettingChangesetParams = data.into_inner().try_into()?;
|
let params: DatabaseSettingChangesetParams = data.into_inner().try_into()?;
|
||||||
|
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
if let Some(insert_params) = params.insert_group {
|
if let Some(insert_params) = params.insert_group {
|
||||||
editor.insert_group(insert_params).await?;
|
editor.insert_group(insert_params).await?;
|
||||||
}
|
}
|
||||||
@ -70,10 +70,10 @@ pub(crate) async fn update_database_setting_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn get_all_filters_handler(
|
pub(crate) async fn get_all_filters_handler(
|
||||||
data: AFPluginData<DatabaseIdPB>,
|
data: AFPluginData<DatabaseViewIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<RepeatedFilterPB, FlowyError> {
|
) -> DataResult<RepeatedFilterPB, FlowyError> {
|
||||||
let database_id: DatabaseIdPB = data.into_inner();
|
let database_id: DatabaseViewIdPB = data.into_inner();
|
||||||
let editor = manager.open_database(database_id).await?;
|
let editor = manager.open_database(database_id).await?;
|
||||||
let filters = RepeatedFilterPB {
|
let filters = RepeatedFilterPB {
|
||||||
items: editor.get_all_filters().await?,
|
items: editor.get_all_filters().await?,
|
||||||
@ -83,10 +83,10 @@ pub(crate) async fn get_all_filters_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn get_all_sorts_handler(
|
pub(crate) async fn get_all_sorts_handler(
|
||||||
data: AFPluginData<DatabaseIdPB>,
|
data: AFPluginData<DatabaseViewIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<RepeatedSortPB, FlowyError> {
|
) -> DataResult<RepeatedSortPB, FlowyError> {
|
||||||
let database_id: DatabaseIdPB = data.into_inner();
|
let database_id: DatabaseViewIdPB = data.into_inner();
|
||||||
let editor = manager.open_database(database_id.as_ref()).await?;
|
let editor = manager.open_database(database_id.as_ref()).await?;
|
||||||
let sorts = RepeatedSortPB {
|
let sorts = RepeatedSortPB {
|
||||||
items: editor.get_all_sorts(database_id.as_ref()).await?,
|
items: editor.get_all_sorts(database_id.as_ref()).await?,
|
||||||
@ -96,10 +96,10 @@ pub(crate) async fn get_all_sorts_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
#[tracing::instrument(level = "trace", skip(data, manager), err)]
|
||||||
pub(crate) async fn delete_all_sorts_handler(
|
pub(crate) async fn delete_all_sorts_handler(
|
||||||
data: AFPluginData<DatabaseIdPB>,
|
data: AFPluginData<DatabaseViewIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let database_id: DatabaseIdPB = data.into_inner();
|
let database_id: DatabaseViewIdPB = data.into_inner();
|
||||||
let editor = manager.open_database(database_id.as_ref()).await?;
|
let editor = manager.open_database(database_id.as_ref()).await?;
|
||||||
editor.delete_all_sorts(database_id.as_ref()).await?;
|
editor.delete_all_sorts(database_id.as_ref()).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -111,7 +111,7 @@ pub(crate) async fn get_fields_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<RepeatedFieldPB, FlowyError> {
|
) -> DataResult<RepeatedFieldPB, FlowyError> {
|
||||||
let params: GetFieldParams = data.into_inner().try_into()?;
|
let params: GetFieldParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
let field_revs = editor.get_field_revs(params.field_ids).await?;
|
let field_revs = editor.get_field_revs(params.field_ids).await?;
|
||||||
let repeated_field: RepeatedFieldPB = field_revs
|
let repeated_field: RepeatedFieldPB = field_revs
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -138,15 +138,10 @@ pub(crate) async fn update_field_type_option_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: TypeOptionChangesetParams = data.into_inner().try_into()?;
|
let params: TypeOptionChangesetParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
let old_field_rev = editor.get_field_rev(¶ms.field_id).await;
|
let old_field_rev = editor.get_field_rev(¶ms.field_id).await;
|
||||||
editor
|
editor
|
||||||
.update_field_type_option(
|
.update_field_type_option(¶ms.field_id, params.type_option_data, old_field_rev)
|
||||||
¶ms.database_id,
|
|
||||||
¶ms.field_id,
|
|
||||||
params.type_option_data,
|
|
||||||
old_field_rev,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -157,7 +152,7 @@ pub(crate) async fn delete_field_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: FieldIdParams = data.into_inner().try_into()?;
|
let params: FieldIdParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
editor.delete_field(¶ms.field_id).await?;
|
editor.delete_field(¶ms.field_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -168,7 +163,7 @@ pub(crate) async fn switch_to_field_handler(
|
|||||||
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()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
let old_field_rev = editor.get_field_rev(¶ms.field_id).await;
|
let old_field_rev = editor.get_field_rev(¶ms.field_id).await;
|
||||||
editor
|
editor
|
||||||
.switch_to_field_type(¶ms.field_id, ¶ms.field_type)
|
.switch_to_field_type(¶ms.field_id, ¶ms.field_type)
|
||||||
@ -183,12 +178,7 @@ pub(crate) async fn switch_to_field_handler(
|
|||||||
// Update the type-option data after the field type has been changed
|
// Update the type-option data after the field type has been changed
|
||||||
let type_option_data = get_type_option_data(&new_field_rev, ¶ms.field_type).await?;
|
let type_option_data = get_type_option_data(&new_field_rev, ¶ms.field_type).await?;
|
||||||
editor
|
editor
|
||||||
.update_field_type_option(
|
.update_field_type_option(&new_field_rev.id, type_option_data, old_field_rev)
|
||||||
¶ms.database_id,
|
|
||||||
&new_field_rev.id,
|
|
||||||
type_option_data,
|
|
||||||
old_field_rev,
|
|
||||||
)
|
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -200,7 +190,7 @@ pub(crate) async fn duplicate_field_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: FieldIdParams = data.into_inner().try_into()?;
|
let params: FieldIdParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
editor.duplicate_field(¶ms.field_id).await?;
|
editor.duplicate_field(¶ms.field_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -212,14 +202,14 @@ pub(crate) async fn get_field_type_option_data_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<TypeOptionPB, FlowyError> {
|
) -> DataResult<TypeOptionPB, FlowyError> {
|
||||||
let params: TypeOptionPathParams = data.into_inner().try_into()?;
|
let params: TypeOptionPathParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
match editor.get_field_rev(¶ms.field_id).await {
|
match editor.get_field_rev(¶ms.field_id).await {
|
||||||
None => Err(FlowyError::record_not_found()),
|
None => Err(FlowyError::record_not_found()),
|
||||||
Some(field_rev) => {
|
Some(field_rev) => {
|
||||||
let field_type = field_rev.ty.into();
|
let field_type = field_rev.ty.into();
|
||||||
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
||||||
let data = TypeOptionPB {
|
let data = TypeOptionPB {
|
||||||
database_id: params.database_id,
|
view_id: params.view_id,
|
||||||
field: field_rev.into(),
|
field: field_rev.into(),
|
||||||
type_option_data,
|
type_option_data,
|
||||||
};
|
};
|
||||||
@ -235,7 +225,7 @@ pub(crate) async fn create_field_type_option_data_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<TypeOptionPB, FlowyError> {
|
) -> DataResult<TypeOptionPB, FlowyError> {
|
||||||
let params: CreateFieldParams = data.into_inner().try_into()?;
|
let params: CreateFieldParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
let field_rev = editor
|
let field_rev = editor
|
||||||
.create_new_field_rev_with_type_option(¶ms.field_type, params.type_option_data)
|
.create_new_field_rev_with_type_option(¶ms.field_type, params.type_option_data)
|
||||||
.await?;
|
.await?;
|
||||||
@ -243,7 +233,7 @@ pub(crate) async fn create_field_type_option_data_handler(
|
|||||||
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
let type_option_data = get_type_option_data(&field_rev, &field_type).await?;
|
||||||
|
|
||||||
data_result(TypeOptionPB {
|
data_result(TypeOptionPB {
|
||||||
database_id: params.database_id,
|
view_id: params.view_id,
|
||||||
field: field_rev.into(),
|
field: field_rev.into(),
|
||||||
type_option_data,
|
type_option_data,
|
||||||
})
|
})
|
||||||
@ -286,7 +276,7 @@ pub(crate) async fn get_row_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<OptionalRowPB, FlowyError> {
|
) -> DataResult<OptionalRowPB, FlowyError> {
|
||||||
let params: RowIdParams = data.into_inner().try_into()?;
|
let params: RowIdParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
let row = editor
|
let row = editor
|
||||||
.get_row_rev(¶ms.row_id)
|
.get_row_rev(¶ms.row_id)
|
||||||
.await?
|
.await?
|
||||||
@ -301,7 +291,7 @@ pub(crate) async fn delete_row_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: RowIdParams = data.into_inner().try_into()?;
|
let params: RowIdParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
editor.delete_row(¶ms.row_id).await?;
|
editor.delete_row(¶ms.row_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -312,7 +302,7 @@ pub(crate) async fn duplicate_row_handler(
|
|||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> Result<(), FlowyError> {
|
) -> Result<(), FlowyError> {
|
||||||
let params: RowIdParams = data.into_inner().try_into()?;
|
let params: RowIdParams = data.into_inner().try_into()?;
|
||||||
let editor = manager.get_database_editor(¶ms.database_id).await?;
|
let editor = manager.get_database_editor(¶ms.view_id).await?;
|
||||||
editor.duplicate_row(¶ms.row_id).await?;
|
editor.duplicate_row(¶ms.row_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -334,9 +324,7 @@ pub(crate) async fn create_table_row_handler(
|
|||||||
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()?;
|
||||||
let editor = manager
|
let editor = manager.get_database_editor(params.view_id.as_ref()).await?;
|
||||||
.get_database_editor(params.database_id.as_ref())
|
|
||||||
.await?;
|
|
||||||
let row = editor.create_row(params).await?;
|
let row = editor.create_row(params).await?;
|
||||||
data_result(row)
|
data_result(row)
|
||||||
}
|
}
|
||||||
@ -531,10 +519,10 @@ pub(crate) async fn update_date_cell_handler(
|
|||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
pub(crate) async fn get_groups_handler(
|
pub(crate) async fn get_groups_handler(
|
||||||
data: AFPluginData<DatabaseIdPB>,
|
data: AFPluginData<DatabaseViewIdPB>,
|
||||||
manager: AFPluginState<Arc<DatabaseManager>>,
|
manager: AFPluginState<Arc<DatabaseManager>>,
|
||||||
) -> DataResult<RepeatedGroupPB, FlowyError> {
|
) -> DataResult<RepeatedGroupPB, FlowyError> {
|
||||||
let params: DatabaseIdPB = data.into_inner();
|
let params: DatabaseViewIdPB = data.into_inner();
|
||||||
let editor = manager.get_database_editor(¶ms.value).await?;
|
let editor = manager.get_database_editor(¶ms.value).await?;
|
||||||
let group = editor.load_groups().await?;
|
let group = editor.load_groups().await?;
|
||||||
data_result(group)
|
data_result(group)
|
||||||
@ -546,9 +534,7 @@ pub(crate) async fn create_board_card_handler(
|
|||||||
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()?;
|
||||||
let editor = manager
|
let editor = manager.get_database_editor(params.view_id.as_ref()).await?;
|
||||||
.get_database_editor(params.database_id.as_ref())
|
|
||||||
.await?;
|
|
||||||
let row = editor.create_row(params).await?;
|
let row = editor.create_row(params).await?;
|
||||||
data_result(row)
|
data_result(row)
|
||||||
}
|
}
|
||||||
|
@ -59,15 +59,15 @@ pub fn init(database_manager: Arc<DatabaseManager>) -> AFPlugin {
|
|||||||
pub enum DatabaseEvent {
|
pub enum DatabaseEvent {
|
||||||
/// [GetDatabase] event is used to get the [DatabasePB]
|
/// [GetDatabase] event is used to get the [DatabasePB]
|
||||||
///
|
///
|
||||||
/// The event handler accepts a [DatabaseIdPB] and returns a [DatabasePB] if there are no errors.
|
/// The event handler accepts a [DatabaseViewIdPB] and returns a [DatabasePB] if there are no errors.
|
||||||
#[event(input = "DatabaseIdPB", output = "DatabasePB")]
|
#[event(input = "DatabaseViewIdPB", output = "DatabasePB")]
|
||||||
GetDatabase = 0,
|
GetDatabase = 0,
|
||||||
|
|
||||||
/// [GetDatabaseSetting] event is used to get the database's settings.
|
/// [GetDatabaseSetting] event is used to get the database's settings.
|
||||||
///
|
///
|
||||||
/// The event handler accepts [DatabaseIdPB] and return [DatabaseViewSettingPB]
|
/// The event handler accepts [DatabaseViewIdPB] and return [DatabaseViewSettingPB]
|
||||||
/// if there is no errors.
|
/// if there is no errors.
|
||||||
#[event(input = "DatabaseIdPB", output = "DatabaseViewSettingPB")]
|
#[event(input = "DatabaseViewIdPB", output = "DatabaseViewSettingPB")]
|
||||||
GetDatabaseSetting = 2,
|
GetDatabaseSetting = 2,
|
||||||
|
|
||||||
/// [UpdateDatabaseSetting] event is used to update the database's settings.
|
/// [UpdateDatabaseSetting] event is used to update the database's settings.
|
||||||
@ -76,13 +76,13 @@ pub enum DatabaseEvent {
|
|||||||
#[event(input = "DatabaseSettingChangesetPB")]
|
#[event(input = "DatabaseSettingChangesetPB")]
|
||||||
UpdateDatabaseSetting = 3,
|
UpdateDatabaseSetting = 3,
|
||||||
|
|
||||||
#[event(input = "DatabaseIdPB", output = "RepeatedFilterPB")]
|
#[event(input = "DatabaseViewIdPB", output = "RepeatedFilterPB")]
|
||||||
GetAllFilters = 4,
|
GetAllFilters = 4,
|
||||||
|
|
||||||
#[event(input = "DatabaseIdPB", output = "RepeatedSortPB")]
|
#[event(input = "DatabaseViewIdPB", output = "RepeatedSortPB")]
|
||||||
GetAllSorts = 5,
|
GetAllSorts = 5,
|
||||||
|
|
||||||
#[event(input = "DatabaseIdPB")]
|
#[event(input = "DatabaseViewIdPB")]
|
||||||
DeleteAllSorts = 6,
|
DeleteAllSorts = 6,
|
||||||
|
|
||||||
/// [GetFields] event is used to get the database's settings.
|
/// [GetFields] event is used to get the database's settings.
|
||||||
@ -215,7 +215,7 @@ pub enum DatabaseEvent {
|
|||||||
#[event(input = "DateChangesetPB")]
|
#[event(input = "DateChangesetPB")]
|
||||||
UpdateDateCell = 80,
|
UpdateDateCell = 80,
|
||||||
|
|
||||||
#[event(input = "DatabaseIdPB", output = "RepeatedGroupPB")]
|
#[event(input = "DatabaseViewIdPB", output = "RepeatedGroupPB")]
|
||||||
GetGroup = 100,
|
GetGroup = 100,
|
||||||
|
|
||||||
#[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
|
#[event(input = "CreateBoardCardPayloadPB", output = "RowPB")]
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
use crate::entities::LayoutTypePB;
|
use crate::entities::LayoutTypePB;
|
||||||
use crate::services::grid_editor::{
|
use crate::services::database::{
|
||||||
DatabaseRevisionEditor, GridRevisionCloudService, GridRevisionMergeable, GridRevisionSerde,
|
make_database_block_rev_manager, DatabaseRevisionCloudService, DatabaseRevisionEditor,
|
||||||
|
DatabaseRevisionMergeable, DatabaseRevisionSerde,
|
||||||
};
|
};
|
||||||
|
use crate::services::database_view::make_database_view_rev_manager;
|
||||||
use crate::services::persistence::block_index::BlockIndexCache;
|
use crate::services::persistence::block_index::BlockIndexCache;
|
||||||
use crate::services::persistence::kv::DatabaseKVPersistence;
|
use crate::services::persistence::kv::DatabaseKVPersistence;
|
||||||
use crate::services::persistence::migration::DatabaseMigration;
|
use crate::services::persistence::migration::DatabaseMigration;
|
||||||
@ -9,8 +11,8 @@ use crate::services::persistence::rev_sqlite::{
|
|||||||
SQLiteDatabaseRevisionPersistence, SQLiteDatabaseRevisionSnapshotPersistence,
|
SQLiteDatabaseRevisionPersistence, SQLiteDatabaseRevisionSnapshotPersistence,
|
||||||
};
|
};
|
||||||
use crate::services::persistence::GridDatabase;
|
use crate::services::persistence::GridDatabase;
|
||||||
use crate::services::view_editor::make_database_view_rev_manager;
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{BuildDatabaseContext, DatabaseRevision, DatabaseViewRevision};
|
||||||
use flowy_client_sync::client_database::{
|
use flowy_client_sync::client_database::{
|
||||||
make_database_block_operations, make_database_operations, make_grid_view_operations,
|
make_database_block_operations, make_database_operations, make_grid_view_operations,
|
||||||
};
|
};
|
||||||
@ -19,12 +21,10 @@ use flowy_revision::{
|
|||||||
RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration, RevisionWebSocket,
|
RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration, RevisionWebSocket,
|
||||||
};
|
};
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use grid_model::{BuildDatabaseContext, DatabaseRevision, DatabaseViewRevision};
|
|
||||||
use lib_infra::async_trait::async_trait;
|
use lib_infra::async_trait::async_trait;
|
||||||
use lib_infra::ref_map::{RefCountHashMap, RefCountValue};
|
use lib_infra::ref_map::{RefCountHashMap, RefCountValue};
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
|
|
||||||
use crate::services::block_manager::make_database_block_rev_manager;
|
|
||||||
use flowy_task::TaskDispatcher;
|
use flowy_task::TaskDispatcher;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
@ -135,6 +135,7 @@ impl DatabaseManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// #[tracing::instrument(level = "debug", skip(self), err)]
|
// #[tracing::instrument(level = "debug", skip(self), err)]
|
||||||
|
//TODO(nathan): map the view_id to database_id
|
||||||
pub async fn get_database_editor(
|
pub async fn get_database_editor(
|
||||||
&self,
|
&self,
|
||||||
database_id: &str,
|
database_id: &str,
|
||||||
@ -175,11 +176,11 @@ impl DatabaseManager {
|
|||||||
) -> Result<Arc<DatabaseRevisionEditor>, FlowyError> {
|
) -> Result<Arc<DatabaseRevisionEditor>, FlowyError> {
|
||||||
let user = self.database_user.clone();
|
let user = self.database_user.clone();
|
||||||
let token = user.token()?;
|
let token = user.token()?;
|
||||||
let cloud = Arc::new(GridRevisionCloudService::new(token));
|
let cloud = Arc::new(DatabaseRevisionCloudService::new(token));
|
||||||
let mut rev_manager = self.make_database_rev_manager(database_id, pool.clone())?;
|
let mut rev_manager = self.make_database_rev_manager(database_id, pool.clone())?;
|
||||||
let database_pad = Arc::new(RwLock::new(
|
let database_pad = Arc::new(RwLock::new(
|
||||||
rev_manager
|
rev_manager
|
||||||
.initialize::<GridRevisionSerde>(Some(cloud))
|
.initialize::<DatabaseRevisionSerde>(Some(cloud))
|
||||||
.await?,
|
.await?,
|
||||||
));
|
));
|
||||||
let database_editor = DatabaseRevisionEditor::new(
|
let database_editor = DatabaseRevisionEditor::new(
|
||||||
@ -213,7 +214,7 @@ impl DatabaseManager {
|
|||||||
let snapshot_persistence =
|
let snapshot_persistence =
|
||||||
SQLiteDatabaseRevisionSnapshotPersistence::new(&snapshot_object_id, pool);
|
SQLiteDatabaseRevisionSnapshotPersistence::new(&snapshot_object_id, pool);
|
||||||
|
|
||||||
let rev_compress = GridRevisionMergeable();
|
let rev_compress = DatabaseRevisionMergeable();
|
||||||
let rev_manager = RevisionManager::new(
|
let rev_manager = RevisionManager::new(
|
||||||
&user_id,
|
&user_id,
|
||||||
database_id,
|
database_id,
|
||||||
@ -236,7 +237,7 @@ pub async fn make_database_view_data(
|
|||||||
field_revs,
|
field_revs,
|
||||||
block_metas,
|
block_metas,
|
||||||
blocks,
|
blocks,
|
||||||
grid_view_revision_data,
|
database_view_data: grid_view_revision_data,
|
||||||
} = build_context;
|
} = build_context;
|
||||||
|
|
||||||
for block_meta_data in &blocks {
|
for block_meta_data in &blocks {
|
||||||
@ -249,40 +250,40 @@ pub async fn make_database_view_data(
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Create grid's block
|
// Create grid's block
|
||||||
let grid_block_delta = make_database_block_operations(block_meta_data);
|
let database_block_ops = make_database_block_operations(block_meta_data);
|
||||||
let block_delta_data = grid_block_delta.json_bytes();
|
let database_block_bytes = database_block_ops.json_bytes();
|
||||||
let revision = Revision::initial_revision(block_id, block_delta_data);
|
let revision = Revision::initial_revision(block_id, database_block_bytes);
|
||||||
database_manager
|
database_manager
|
||||||
.create_database_block(&block_id, vec![revision])
|
.create_database_block(&block_id, vec![revision])
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Will replace the grid_id with the value returned by the gen_grid_id()
|
// Will replace the grid_id with the value returned by the gen_grid_id()
|
||||||
let grid_id = view_id.to_owned();
|
let database_id = view_id.to_owned();
|
||||||
let grid_rev = DatabaseRevision::from_build_context(&grid_id, field_revs, block_metas);
|
let database_rev = DatabaseRevision::from_build_context(&database_id, field_revs, block_metas);
|
||||||
|
|
||||||
// Create grid
|
// Create grid
|
||||||
let grid_rev_delta = make_database_operations(&grid_rev);
|
let database_ops = make_database_operations(&database_rev);
|
||||||
let grid_rev_delta_bytes = grid_rev_delta.json_bytes();
|
let database_bytes = database_ops.json_bytes();
|
||||||
let revision = Revision::initial_revision(&grid_id, grid_rev_delta_bytes.clone());
|
let revision = Revision::initial_revision(&database_id, database_bytes.clone());
|
||||||
database_manager
|
database_manager
|
||||||
.create_database(&grid_id, vec![revision])
|
.create_database(&database_id, vec![revision])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// Create grid view
|
// Create grid view
|
||||||
let grid_view = if grid_view_revision_data.is_empty() {
|
let grid_view = if grid_view_revision_data.is_empty() {
|
||||||
DatabaseViewRevision::new(grid_id, view_id.to_owned(), layout.into())
|
DatabaseViewRevision::new(database_id, view_id.to_owned(), layout.into())
|
||||||
} else {
|
} else {
|
||||||
DatabaseViewRevision::from_json(grid_view_revision_data)?
|
DatabaseViewRevision::from_json(grid_view_revision_data)?
|
||||||
};
|
};
|
||||||
let grid_view_delta = make_grid_view_operations(&grid_view);
|
let database_view_ops = make_grid_view_operations(&grid_view);
|
||||||
let grid_view_delta_bytes = grid_view_delta.json_bytes();
|
let database_view_bytes = database_view_ops.json_bytes();
|
||||||
let revision = Revision::initial_revision(view_id, grid_view_delta_bytes);
|
let revision = Revision::initial_revision(view_id, database_view_bytes);
|
||||||
database_manager
|
database_manager
|
||||||
.create_database_view(view_id, vec![revision])
|
.create_database_view(view_id, vec![revision])
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(grid_rev_delta_bytes)
|
Ok(database_bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
@ -3,8 +3,8 @@ use crate::services::cell::{AtomicCellDataCache, CellProtobufBlob, TypeCellData}
|
|||||||
use crate::services::field::*;
|
use crate::services::field::*;
|
||||||
|
|
||||||
use crate::services::group::make_no_status_group;
|
use crate::services::group::make_no_status_group;
|
||||||
|
use database_model::{CellRevision, FieldRevision};
|
||||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||||
use grid_model::{CellRevision, FieldRevision};
|
|
||||||
|
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::entities::FieldType;
|
use crate::entities::FieldType;
|
||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::CellRevision;
|
||||||
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
use flowy_error::{internal_error, FlowyError, FlowyResult};
|
||||||
use grid_model::CellRevision;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
/// TypeCellData is a generic CellData, you can parse the type_cell_data according to the field_type.
|
/// TypeCellData is a generic CellData, you can parse the type_cell_data according to the field_type.
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use crate::services::retry::GetRowDataRetryAction;
|
use crate::services::database::retry::GetRowDataRetryAction;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use flowy_client_sync::client_database::{GridBlockRevisionChangeset, GridBlockRevisionPad};
|
use database_model::{CellRevision, DatabaseBlockRevision, RowChangeset, RowRevision};
|
||||||
|
use flowy_client_sync::client_database::{
|
||||||
|
DatabaseBlockRevisionChangeset, DatabaseBlockRevisionPad,
|
||||||
|
};
|
||||||
use flowy_client_sync::make_operations_from_revisions;
|
use flowy_client_sync::make_operations_from_revisions;
|
||||||
use flowy_error::{FlowyError, FlowyResult};
|
use flowy_error::{FlowyError, FlowyResult};
|
||||||
use flowy_revision::{
|
use flowy_revision::{
|
||||||
@ -8,7 +11,6 @@ use flowy_revision::{
|
|||||||
RevisionObjectSerializer,
|
RevisionObjectSerializer,
|
||||||
};
|
};
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use grid_model::{CellRevision, DatabaseBlockRevision, RowChangeset, RowRevision};
|
|
||||||
use lib_infra::future::FutureResult;
|
use lib_infra::future::FutureResult;
|
||||||
use lib_infra::retry::spawn_retry;
|
use lib_infra::retry::spawn_retry;
|
||||||
use lib_ot::core::EmptyAttributes;
|
use lib_ot::core::EmptyAttributes;
|
||||||
@ -21,7 +23,7 @@ pub struct DatabaseBlockRevisionEditor {
|
|||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
user_id: String,
|
user_id: String,
|
||||||
pub block_id: String,
|
pub block_id: String,
|
||||||
pad: Arc<RwLock<GridBlockRevisionPad>>,
|
pad: Arc<RwLock<DatabaseBlockRevisionPad>>,
|
||||||
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +34,7 @@ impl DatabaseBlockRevisionEditor {
|
|||||||
block_id: &str,
|
block_id: &str,
|
||||||
mut rev_manager: RevisionManager<Arc<ConnectionPool>>,
|
mut rev_manager: RevisionManager<Arc<ConnectionPool>>,
|
||||||
) -> FlowyResult<Self> {
|
) -> FlowyResult<Self> {
|
||||||
let cloud = Arc::new(GridBlockRevisionCloudService {
|
let cloud = Arc::new(DatabaseBlockRevisionCloudService {
|
||||||
token: token.to_owned(),
|
token: token.to_owned(),
|
||||||
});
|
});
|
||||||
let block_revision_pad = rev_manager
|
let block_revision_pad = rev_manager
|
||||||
@ -165,8 +167,8 @@ impl DatabaseBlockRevisionEditor {
|
|||||||
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
||||||
where
|
where
|
||||||
F: for<'a> FnOnce(
|
F: for<'a> FnOnce(
|
||||||
&'a mut GridBlockRevisionPad,
|
&'a mut DatabaseBlockRevisionPad,
|
||||||
) -> FlowyResult<Option<GridBlockRevisionChangeset>>,
|
) -> FlowyResult<Option<DatabaseBlockRevisionChangeset>>,
|
||||||
{
|
{
|
||||||
let mut write_guard = self.pad.write().await;
|
let mut write_guard = self.pad.write().await;
|
||||||
let changeset = f(&mut write_guard)?;
|
let changeset = f(&mut write_guard)?;
|
||||||
@ -179,8 +181,8 @@ impl DatabaseBlockRevisionEditor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn apply_change(&self, change: GridBlockRevisionChangeset) -> FlowyResult<()> {
|
async fn apply_change(&self, change: DatabaseBlockRevisionChangeset) -> FlowyResult<()> {
|
||||||
let GridBlockRevisionChangeset {
|
let DatabaseBlockRevisionChangeset {
|
||||||
operations: delta,
|
operations: delta,
|
||||||
md5,
|
md5,
|
||||||
} = change;
|
} = change;
|
||||||
@ -190,12 +192,12 @@ impl DatabaseBlockRevisionEditor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GridBlockRevisionCloudService {
|
struct DatabaseBlockRevisionCloudService {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
token: String,
|
token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RevisionCloudService for GridBlockRevisionCloudService {
|
impl RevisionCloudService for DatabaseBlockRevisionCloudService {
|
||||||
#[tracing::instrument(level = "trace", skip(self))]
|
#[tracing::instrument(level = "trace", skip(self))]
|
||||||
fn fetch_object(
|
fn fetch_object(
|
||||||
&self,
|
&self,
|
||||||
@ -208,10 +210,13 @@ impl RevisionCloudService for GridBlockRevisionCloudService {
|
|||||||
|
|
||||||
struct DatabaseBlockRevisionSerde();
|
struct DatabaseBlockRevisionSerde();
|
||||||
impl RevisionObjectDeserializer for DatabaseBlockRevisionSerde {
|
impl RevisionObjectDeserializer for DatabaseBlockRevisionSerde {
|
||||||
type Output = GridBlockRevisionPad;
|
type Output = DatabaseBlockRevisionPad;
|
||||||
|
|
||||||
fn deserialize_revisions(object_id: &str, revisions: Vec<Revision>) -> FlowyResult<Self::Output> {
|
fn deserialize_revisions(
|
||||||
let pad = GridBlockRevisionPad::from_revisions(object_id, revisions)?;
|
_object_id: &str,
|
||||||
|
revisions: Vec<Revision>,
|
||||||
|
) -> FlowyResult<Self::Output> {
|
||||||
|
let pad = DatabaseBlockRevisionPad::from_revisions(revisions)?;
|
||||||
Ok(pad)
|
Ok(pad)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,8 +232,8 @@ impl RevisionObjectSerializer for DatabaseBlockRevisionSerde {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridBlockRevisionMergeable();
|
pub struct DatabaseBlockRevisionMergeable();
|
||||||
impl RevisionMergeable for GridBlockRevisionMergeable {
|
impl RevisionMergeable for DatabaseBlockRevisionMergeable {
|
||||||
fn combine_revisions(&self, revisions: Vec<Revision>) -> FlowyResult<Bytes> {
|
fn combine_revisions(&self, revisions: Vec<Revision>) -> FlowyResult<Bytes> {
|
||||||
DatabaseBlockRevisionSerde::combine_revisions(revisions)
|
DatabaseBlockRevisionSerde::combine_revisions(revisions)
|
||||||
}
|
}
|
@ -1,19 +1,19 @@
|
|||||||
use crate::entities::{CellChangesetPB, InsertedRowPB, UpdatedRowPB};
|
use crate::entities::{CellChangesetPB, InsertedRowPB, UpdatedRowPB};
|
||||||
use crate::manager::DatabaseUser;
|
use crate::manager::DatabaseUser;
|
||||||
use crate::notification::{send_notification, DatabaseNotification};
|
use crate::notification::{send_notification, DatabaseNotification};
|
||||||
use crate::services::block_editor::{DatabaseBlockRevisionEditor, GridBlockRevisionMergeable};
|
use crate::services::database::{DatabaseBlockRevisionEditor, DatabaseBlockRevisionMergeable};
|
||||||
use crate::services::persistence::block_index::BlockIndexCache;
|
use crate::services::persistence::block_index::BlockIndexCache;
|
||||||
use crate::services::persistence::rev_sqlite::{
|
use crate::services::persistence::rev_sqlite::{
|
||||||
SQLiteDatabaseBlockRevisionPersistence, SQLiteDatabaseRevisionSnapshotPersistence,
|
SQLiteDatabaseBlockRevisionPersistence, SQLiteDatabaseRevisionSnapshotPersistence,
|
||||||
};
|
};
|
||||||
use crate::services::row::{make_row_from_row_rev, DatabaseBlockRow, DatabaseBlockRowRevision};
|
use crate::services::row::{make_row_from_row_rev, DatabaseBlockRow, DatabaseBlockRowRevision};
|
||||||
use dashmap::DashMap;
|
use dashmap::DashMap;
|
||||||
|
use database_model::{
|
||||||
|
DatabaseBlockMetaRevision, DatabaseBlockMetaRevisionChangeset, RowChangeset, RowRevision,
|
||||||
|
};
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
|
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use grid_model::{
|
|
||||||
GridBlockMetaRevision, GridBlockMetaRevisionChangeset, RowChangeset, RowRevision,
|
|
||||||
};
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@ -51,7 +51,7 @@ pub(crate) struct DatabaseBlockManager {
|
|||||||
impl DatabaseBlockManager {
|
impl DatabaseBlockManager {
|
||||||
pub(crate) async fn new(
|
pub(crate) async fn new(
|
||||||
user: &Arc<dyn DatabaseUser>,
|
user: &Arc<dyn DatabaseUser>,
|
||||||
block_meta_revs: Vec<Arc<GridBlockMetaRevision>>,
|
block_meta_revs: Vec<Arc<DatabaseBlockMetaRevision>>,
|
||||||
persistence: Arc<BlockIndexCache>,
|
persistence: Arc<BlockIndexCache>,
|
||||||
event_notifier: broadcast::Sender<DatabaseBlockEvent>,
|
event_notifier: broadcast::Sender<DatabaseBlockEvent>,
|
||||||
) -> FlowyResult<Self> {
|
) -> FlowyResult<Self> {
|
||||||
@ -73,7 +73,7 @@ impl DatabaseBlockManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// #[tracing::instrument(level = "trace", skip(self))]
|
// #[tracing::instrument(level = "trace", skip(self))]
|
||||||
pub(crate) async fn get_block_editor(
|
pub(crate) async fn get_or_create_block_editor(
|
||||||
&self,
|
&self,
|
||||||
block_id: &str,
|
block_id: &str,
|
||||||
) -> FlowyResult<Arc<DatabaseBlockRevisionEditor>> {
|
) -> FlowyResult<Arc<DatabaseBlockRevisionEditor>> {
|
||||||
@ -99,7 +99,7 @@ impl DatabaseBlockManager {
|
|||||||
row_id: &str,
|
row_id: &str,
|
||||||
) -> FlowyResult<Arc<DatabaseBlockRevisionEditor>> {
|
) -> FlowyResult<Arc<DatabaseBlockRevisionEditor>> {
|
||||||
let block_id = self.persistence.get_block_id(row_id)?;
|
let block_id = self.persistence.get_block_id(row_id)?;
|
||||||
self.get_block_editor(&block_id).await
|
self.get_or_create_block_editor(&block_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip(self, start_row_id), err)]
|
#[tracing::instrument(level = "trace", skip(self, start_row_id), err)]
|
||||||
@ -110,7 +110,7 @@ impl DatabaseBlockManager {
|
|||||||
) -> FlowyResult<i32> {
|
) -> FlowyResult<i32> {
|
||||||
let block_id = row_rev.block_id.clone();
|
let block_id = row_rev.block_id.clone();
|
||||||
self.persistence.insert(&row_rev.block_id, &row_rev.id)?;
|
self.persistence.insert(&row_rev.block_id, &row_rev.id)?;
|
||||||
let editor = self.get_block_editor(&row_rev.block_id).await?;
|
let editor = self.get_or_create_block_editor(&row_rev.block_id).await?;
|
||||||
|
|
||||||
let mut row = InsertedRowPB::from(&row_rev);
|
let mut row = InsertedRowPB::from(&row_rev);
|
||||||
let (number_of_rows, index) = editor.create_row(row_rev, start_row_id).await?;
|
let (number_of_rows, index) = editor.create_row(row_rev, start_row_id).await?;
|
||||||
@ -125,10 +125,10 @@ impl DatabaseBlockManager {
|
|||||||
pub(crate) async fn insert_row(
|
pub(crate) async fn insert_row(
|
||||||
&self,
|
&self,
|
||||||
rows_by_block_id: HashMap<String, Vec<RowRevision>>,
|
rows_by_block_id: HashMap<String, Vec<RowRevision>>,
|
||||||
) -> FlowyResult<Vec<GridBlockMetaRevisionChangeset>> {
|
) -> FlowyResult<Vec<DatabaseBlockMetaRevisionChangeset>> {
|
||||||
let mut changesets = vec![];
|
let mut changesets = vec![];
|
||||||
for (block_id, row_revs) in rows_by_block_id {
|
for (block_id, row_revs) in rows_by_block_id {
|
||||||
let editor = self.get_block_editor(&block_id).await?;
|
let editor = self.get_or_create_block_editor(&block_id).await?;
|
||||||
for row_rev in row_revs {
|
for row_rev in row_revs {
|
||||||
self.persistence.insert(&row_rev.block_id, &row_rev.id)?;
|
self.persistence.insert(&row_rev.block_id, &row_rev.id)?;
|
||||||
let mut row = InsertedRowPB::from(&row_rev);
|
let mut row = InsertedRowPB::from(&row_rev);
|
||||||
@ -138,7 +138,7 @@ impl DatabaseBlockManager {
|
|||||||
row,
|
row,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
changesets.push(GridBlockMetaRevisionChangeset::from_row_count(
|
changesets.push(DatabaseBlockMetaRevisionChangeset::from_row_count(
|
||||||
block_id.clone(),
|
block_id.clone(),
|
||||||
editor.number_of_rows().await,
|
editor.number_of_rows().await,
|
||||||
));
|
));
|
||||||
@ -179,7 +179,7 @@ impl DatabaseBlockManager {
|
|||||||
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<Option<Arc<RowRevision>>> {
|
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<Option<Arc<RowRevision>>> {
|
||||||
let row_id = row_id.to_owned();
|
let row_id = row_id.to_owned();
|
||||||
let block_id = self.persistence.get_block_id(&row_id)?;
|
let block_id = self.persistence.get_block_id(&row_id)?;
|
||||||
let editor = self.get_block_editor(&block_id).await?;
|
let editor = self.get_or_create_block_editor(&block_id).await?;
|
||||||
match editor.get_row_rev(&row_id).await? {
|
match editor.get_row_rev(&row_id).await? {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some((_, row_rev)) => {
|
Some((_, row_rev)) => {
|
||||||
@ -197,17 +197,18 @@ impl DatabaseBlockManager {
|
|||||||
pub(crate) async fn delete_rows(
|
pub(crate) async fn delete_rows(
|
||||||
&self,
|
&self,
|
||||||
block_rows: Vec<DatabaseBlockRow>,
|
block_rows: Vec<DatabaseBlockRow>,
|
||||||
) -> FlowyResult<Vec<GridBlockMetaRevisionChangeset>> {
|
) -> FlowyResult<Vec<DatabaseBlockMetaRevisionChangeset>> {
|
||||||
let mut changesets = vec![];
|
let mut changesets = vec![];
|
||||||
for block_row in block_rows {
|
for block_row in block_rows {
|
||||||
let editor = self.get_block_editor(&block_row.block_id).await?;
|
let editor = self.get_or_create_block_editor(&block_row.block_id).await?;
|
||||||
let row_ids = block_row
|
let row_ids = block_row
|
||||||
.row_ids
|
.row_ids
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Cow::Owned)
|
.map(Cow::Owned)
|
||||||
.collect::<Vec<Cow<String>>>();
|
.collect::<Vec<Cow<String>>>();
|
||||||
let row_count = editor.delete_rows(row_ids).await?;
|
let row_count = editor.delete_rows(row_ids).await?;
|
||||||
let changeset = GridBlockMetaRevisionChangeset::from_row_count(block_row.block_id, row_count);
|
let changeset =
|
||||||
|
DatabaseBlockMetaRevisionChangeset::from_row_count(block_row.block_id, row_count);
|
||||||
changesets.push(changeset);
|
changesets.push(changeset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,7 +286,7 @@ impl DatabaseBlockManager {
|
|||||||
},
|
},
|
||||||
Some(block_ids) => {
|
Some(block_ids) => {
|
||||||
for block_id in block_ids {
|
for block_id in block_ids {
|
||||||
let editor = self.get_block_editor(&block_id).await?;
|
let editor = self.get_or_create_block_editor(&block_id).await?;
|
||||||
let row_revs = editor.get_row_revs::<&str>(None).await?;
|
let row_revs = editor.get_row_revs::<&str>(None).await?;
|
||||||
blocks.push(DatabaseBlockRowRevision { block_id, row_revs });
|
blocks.push(DatabaseBlockRowRevision { block_id, row_revs });
|
||||||
}
|
}
|
||||||
@ -304,7 +305,7 @@ impl DatabaseBlockManager {
|
|||||||
/// Initialize each block editor
|
/// Initialize each block editor
|
||||||
async fn make_block_editors(
|
async fn make_block_editors(
|
||||||
user: &Arc<dyn DatabaseUser>,
|
user: &Arc<dyn DatabaseUser>,
|
||||||
block_meta_revs: Vec<Arc<GridBlockMetaRevision>>,
|
block_meta_revs: Vec<Arc<DatabaseBlockMetaRevision>>,
|
||||||
) -> FlowyResult<DashMap<String, Arc<DatabaseBlockRevisionEditor>>> {
|
) -> FlowyResult<DashMap<String, Arc<DatabaseBlockRevisionEditor>>> {
|
||||||
let editor_map = DashMap::new();
|
let editor_map = DashMap::new();
|
||||||
for block_meta_rev in block_meta_revs {
|
for block_meta_rev in block_meta_revs {
|
||||||
@ -343,7 +344,7 @@ pub fn make_database_block_rev_manager(
|
|||||||
let snapshot_persistence =
|
let snapshot_persistence =
|
||||||
SQLiteDatabaseRevisionSnapshotPersistence::new(&snapshot_object_id, pool);
|
SQLiteDatabaseRevisionSnapshotPersistence::new(&snapshot_object_id, pool);
|
||||||
|
|
||||||
let rev_compress = GridBlockRevisionMergeable();
|
let rev_compress = DatabaseBlockRevisionMergeable();
|
||||||
let rev_manager = RevisionManager::new(
|
let rev_manager = RevisionManager::new(
|
||||||
&user_id,
|
&user_id,
|
||||||
block_id,
|
block_id,
|
@ -2,26 +2,28 @@ 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};
|
||||||
use crate::services::block_manager::DatabaseBlockManager;
|
|
||||||
use crate::services::cell::{
|
use crate::services::cell::{
|
||||||
apply_cell_data_changeset, get_type_cell_protobuf, stringify_cell_data, AnyTypeCache,
|
apply_cell_data_changeset, get_type_cell_protobuf, stringify_cell_data, AnyTypeCache,
|
||||||
AtomicCellDataCache, CellProtobufBlob, ToCellChangesetString, TypeCellData,
|
AtomicCellDataCache, CellProtobufBlob, ToCellChangesetString, TypeCellData,
|
||||||
};
|
};
|
||||||
|
use crate::services::database::DatabaseBlockManager;
|
||||||
use crate::services::field::{
|
use crate::services::field::{
|
||||||
default_type_option_builder_from_type, transform_type_option, type_option_builder_from_bytes,
|
default_type_option_builder_from_type, transform_type_option, type_option_builder_from_bytes,
|
||||||
FieldBuilder, RowSingleCellData,
|
FieldBuilder, RowSingleCellData,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::services::database::DatabaseViewEditorDelegateImpl;
|
||||||
|
use crate::services::database_view::{DatabaseViewChanged, DatabaseViewManager};
|
||||||
use crate::services::filter::FilterType;
|
use crate::services::filter::FilterType;
|
||||||
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::{DatabaseViewChanged, DatabaseViewManager};
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::*;
|
||||||
use flowy_client_sync::client_database::{
|
use flowy_client_sync::client_database::{
|
||||||
DatabaseRevisionChangeset, DatabaseRevisionPad, JsonDeserializer,
|
DatabaseRevisionChangeset, DatabaseRevisionPad, JsonDeserializer,
|
||||||
};
|
};
|
||||||
use flowy_client_sync::errors::{SyncError, SyncResult};
|
use flowy_client_sync::errors::{SyncError, SyncResult};
|
||||||
|
use flowy_client_sync::make_operations_from_revisions;
|
||||||
use flowy_error::{FlowyError, FlowyResult};
|
use flowy_error::{FlowyError, FlowyResult};
|
||||||
use flowy_revision::{
|
use flowy_revision::{
|
||||||
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer,
|
RevisionCloudService, RevisionManager, RevisionMergeable, RevisionObjectDeserializer,
|
||||||
@ -29,30 +31,25 @@ use flowy_revision::{
|
|||||||
};
|
};
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use flowy_task::TaskDispatcher;
|
use flowy_task::TaskDispatcher;
|
||||||
use grid_model::*;
|
|
||||||
use lib_infra::future::{to_fut, FutureResult};
|
use lib_infra::future::{to_fut, FutureResult};
|
||||||
use lib_ot::core::EmptyAttributes;
|
use lib_ot::core::EmptyAttributes;
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use flowy_client_sync::make_operations_from_revisions;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::{broadcast, RwLock};
|
use tokio::sync::{broadcast, RwLock};
|
||||||
|
|
||||||
pub struct DatabaseRevisionEditor {
|
pub struct DatabaseRevisionEditor {
|
||||||
pub database_id: String,
|
pub database_id: String,
|
||||||
#[allow(dead_code)]
|
|
||||||
user: Arc<dyn DatabaseUser>,
|
|
||||||
database_pad: Arc<RwLock<DatabaseRevisionPad>>,
|
database_pad: Arc<RwLock<DatabaseRevisionPad>>,
|
||||||
view_manager: Arc<DatabaseViewManager>,
|
|
||||||
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
||||||
block_manager: Arc<DatabaseBlockManager>,
|
database_view_manager: Arc<DatabaseViewManager>,
|
||||||
|
database_block_manager: Arc<DatabaseBlockManager>,
|
||||||
cell_data_cache: AtomicCellDataCache,
|
cell_data_cache: AtomicCellDataCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for DatabaseRevisionEditor {
|
impl Drop for DatabaseRevisionEditor {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
tracing::trace!("Drop GridRevisionEditor");
|
tracing::trace!("Drop DatabaseRevisionEditor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,18 +68,18 @@ impl DatabaseRevisionEditor {
|
|||||||
// Block manager
|
// Block manager
|
||||||
let (block_event_tx, block_event_rx) = broadcast::channel(100);
|
let (block_event_tx, block_event_rx) = broadcast::channel(100);
|
||||||
let block_meta_revs = database_pad.read().await.get_block_meta_revs();
|
let block_meta_revs = database_pad.read().await.get_block_meta_revs();
|
||||||
let block_manager = Arc::new(
|
let database_block_manager = Arc::new(
|
||||||
DatabaseBlockManager::new(&user, block_meta_revs, persistence, block_event_tx).await?,
|
DatabaseBlockManager::new(&user, block_meta_revs, persistence, block_event_tx).await?,
|
||||||
);
|
);
|
||||||
let delegate = Arc::new(GridViewEditorDelegateImpl {
|
let delegate = Arc::new(DatabaseViewEditorDelegateImpl {
|
||||||
pad: database_pad.clone(),
|
pad: database_pad.clone(),
|
||||||
block_manager: block_manager.clone(),
|
block_manager: database_block_manager.clone(),
|
||||||
task_scheduler,
|
task_scheduler,
|
||||||
cell_data_cache: cell_data_cache.clone(),
|
cell_data_cache: cell_data_cache.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// View manager
|
// View manager
|
||||||
let view_manager = Arc::new(
|
let database_view_manager = Arc::new(
|
||||||
DatabaseViewManager::new(
|
DatabaseViewManager::new(
|
||||||
database_id.to_owned(),
|
database_id.to_owned(),
|
||||||
user.clone(),
|
user.clone(),
|
||||||
@ -95,23 +92,22 @@ impl DatabaseRevisionEditor {
|
|||||||
|
|
||||||
let editor = Arc::new(Self {
|
let editor = Arc::new(Self {
|
||||||
database_id: database_id.to_owned(),
|
database_id: database_id.to_owned(),
|
||||||
user,
|
|
||||||
database_pad,
|
database_pad,
|
||||||
rev_manager,
|
rev_manager,
|
||||||
block_manager,
|
database_block_manager,
|
||||||
view_manager,
|
database_view_manager,
|
||||||
cell_data_cache,
|
cell_data_cache,
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(editor)
|
Ok(editor)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "close grid editor", level = "trace", skip_all)]
|
#[tracing::instrument(name = "close database editor", level = "trace", skip_all)]
|
||||||
pub async fn close(&self) {
|
pub async fn close(&self) {
|
||||||
self.block_manager.close().await;
|
self.database_block_manager.close().await;
|
||||||
self.rev_manager.generate_snapshot().await;
|
self.rev_manager.generate_snapshot().await;
|
||||||
self.rev_manager.close().await;
|
self.rev_manager.close().await;
|
||||||
self.view_manager.close(&self.database_id).await;
|
self.database_view_manager.close(&self.database_id).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Save the type-option data to disk and send a `DatabaseNotification::DidUpdateField` notification
|
/// Save the type-option data to disk and send a `DatabaseNotification::DidUpdateField` notification
|
||||||
@ -120,14 +116,12 @@ impl DatabaseRevisionEditor {
|
|||||||
/// It will do nothing if the passed-in type_option_data is empty
|
/// It will do nothing if the passed-in type_option_data is empty
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `grid_id`: the id of the grid
|
|
||||||
/// * `field_id`: the id of the field
|
/// * `field_id`: the id of the field
|
||||||
/// * `type_option_data`: the updated type-option data. The `type-option` data might be empty
|
/// * `type_option_data`: the updated type-option data. The `type-option` data might be empty
|
||||||
/// if there is no type-option config for that field. For example, the `RichTextTypeOptionPB`.
|
/// if there is no type-option config for that field. For example, the `RichTextTypeOptionPB`.
|
||||||
///
|
///
|
||||||
pub async fn update_field_type_option(
|
pub async fn update_field_type_option(
|
||||||
&self,
|
&self,
|
||||||
_grid_id: &str,
|
|
||||||
field_id: &str,
|
field_id: &str,
|
||||||
type_option_data: Vec<u8>,
|
type_option_data: Vec<u8>,
|
||||||
old_field_rev: Option<Arc<FieldRevision>>,
|
old_field_rev: Option<Arc<FieldRevision>>,
|
||||||
@ -139,8 +133,8 @@ impl DatabaseRevisionEditor {
|
|||||||
}
|
}
|
||||||
let field_rev = result.unwrap();
|
let field_rev = result.unwrap();
|
||||||
self
|
self
|
||||||
.modify(|grid| {
|
.modify(|pad| {
|
||||||
let changeset = grid.modify_field(field_id, |field| {
|
let changeset = pad.modify_field(field_id, |field| {
|
||||||
let deserializer = TypeOptionJsonDeserializer(field_rev.ty.into());
|
let deserializer = TypeOptionJsonDeserializer(field_rev.ty.into());
|
||||||
match deserializer.deserialize(type_option_data) {
|
match deserializer.deserialize(type_option_data) {
|
||||||
Ok(json_str) => {
|
Ok(json_str) => {
|
||||||
@ -158,10 +152,10 @@ impl DatabaseRevisionEditor {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self
|
self
|
||||||
.view_manager
|
.database_view_manager
|
||||||
.did_update_view_field_type_option(field_id, old_field_rev)
|
.did_update_view_field_type_option(field_id, old_field_rev)
|
||||||
.await?;
|
.await?;
|
||||||
self.notify_did_update_grid_field(field_id).await?;
|
self.notify_did_update_database_field(field_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,9 +173,9 @@ impl DatabaseRevisionEditor {
|
|||||||
pub async fn create_new_field_rev(&self, field_rev: FieldRevision) -> FlowyResult<()> {
|
pub async fn create_new_field_rev(&self, field_rev: FieldRevision) -> FlowyResult<()> {
|
||||||
let field_id = field_rev.id.clone();
|
let field_id = field_rev.id.clone();
|
||||||
self
|
self
|
||||||
.modify(|grid| Ok(grid.create_field_rev(field_rev, None)?))
|
.modify(|pad| Ok(pad.create_field_rev(field_rev, None)?))
|
||||||
.await?;
|
.await?;
|
||||||
self.notify_did_insert_grid_field(&field_id).await?;
|
self.notify_did_insert_database_field(&field_id).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -197,9 +191,9 @@ impl DatabaseRevisionEditor {
|
|||||||
field_rev.insert_type_option(type_option_builder.serializer());
|
field_rev.insert_type_option(type_option_builder.serializer());
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
.modify(|grid| Ok(grid.create_field_rev(field_rev.clone(), None)?))
|
.modify(|pad| Ok(pad.create_field_rev(field_rev.clone(), None)?))
|
||||||
.await?;
|
.await?;
|
||||||
self.notify_did_insert_grid_field(&field_rev.id).await?;
|
self.notify_did_insert_database_field(&field_rev.id).await?;
|
||||||
|
|
||||||
Ok(field_rev)
|
Ok(field_rev)
|
||||||
}
|
}
|
||||||
@ -211,8 +205,8 @@ impl DatabaseRevisionEditor {
|
|||||||
pub async fn update_field(&self, params: FieldChangesetParams) -> FlowyResult<()> {
|
pub async fn update_field(&self, params: FieldChangesetParams) -> FlowyResult<()> {
|
||||||
let field_id = params.field_id.clone();
|
let field_id = params.field_id.clone();
|
||||||
self
|
self
|
||||||
.modify(|grid| {
|
.modify(|pad| {
|
||||||
let changeset = grid.modify_field(¶ms.field_id, |field| {
|
let changeset = pad.modify_field(¶ms.field_id, |field| {
|
||||||
if let Some(name) = params.name {
|
if let Some(name) = params.name {
|
||||||
field.name = name;
|
field.name = name;
|
||||||
}
|
}
|
||||||
@ -236,7 +230,7 @@ impl DatabaseRevisionEditor {
|
|||||||
Ok(changeset)
|
Ok(changeset)
|
||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
self.notify_did_update_grid_field(&field_id).await?;
|
self.notify_did_update_database_field(&field_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,8 +241,8 @@ impl DatabaseRevisionEditor {
|
|||||||
let mut is_changed = false;
|
let mut is_changed = false;
|
||||||
let old_field_rev = self.get_field_rev(field_id).await;
|
let old_field_rev = self.get_field_rev(field_id).await;
|
||||||
self
|
self
|
||||||
.modify(|grid| {
|
.modify(|pad| {
|
||||||
let changeset = grid.modify_field(field_id, |field_rev| {
|
let changeset = pad.modify_field(field_id, |field_rev| {
|
||||||
f(field_rev).map_err(|e| SyncError::internal().context(e))
|
f(field_rev).map_err(|e| SyncError::internal().context(e))
|
||||||
})?;
|
})?;
|
||||||
is_changed = changeset.is_some();
|
is_changed = changeset.is_some();
|
||||||
@ -258,30 +252,30 @@ impl DatabaseRevisionEditor {
|
|||||||
|
|
||||||
if is_changed {
|
if is_changed {
|
||||||
match self
|
match self
|
||||||
.view_manager
|
.database_view_manager
|
||||||
.did_update_view_field_type_option(field_id, old_field_rev)
|
.did_update_view_field_type_option(field_id, old_field_rev)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => tracing::error!("View manager update field failed: {:?}", e),
|
Err(e) => tracing::error!("View manager update field failed: {:?}", e),
|
||||||
}
|
}
|
||||||
self.notify_did_update_grid_field(field_id).await?;
|
self.notify_did_update_database_field(field_id).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> {
|
pub async fn delete_field(&self, field_id: &str) -> FlowyResult<()> {
|
||||||
self
|
self
|
||||||
.modify(|grid_pad| Ok(grid_pad.delete_field_rev(field_id)?))
|
.modify(|pad| Ok(pad.delete_field_rev(field_id)?))
|
||||||
.await?;
|
.await?;
|
||||||
let field_order = FieldIdPB::from(field_id);
|
let field_order = FieldIdPB::from(field_id);
|
||||||
let notified_changeset = DatabaseFieldChangesetPB::delete(&self.database_id, vec![field_order]);
|
let notified_changeset = DatabaseFieldChangesetPB::delete(&self.database_id, vec![field_order]);
|
||||||
self.notify_did_update_grid(notified_changeset).await?;
|
self.notify_did_update_database(notified_changeset).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn group_by_field(&self, field_id: &str) -> FlowyResult<()> {
|
pub async fn group_by_field(&self, field_id: &str) -> FlowyResult<()> {
|
||||||
self.view_manager.group_by_field(field_id).await?;
|
self.database_view_manager.group_by_field(field_id).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,8 +315,8 @@ impl DatabaseRevisionEditor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
self
|
self
|
||||||
.modify(|grid| {
|
.modify(|pad| {
|
||||||
Ok(grid.switch_to_field(
|
Ok(pad.switch_to_field(
|
||||||
field_id,
|
field_id,
|
||||||
new_field_type.clone(),
|
new_field_type.clone(),
|
||||||
make_default_type_option,
|
make_default_type_option,
|
||||||
@ -331,7 +325,7 @@ impl DatabaseRevisionEditor {
|
|||||||
})
|
})
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.notify_did_update_grid_field(field_id).await?;
|
self.notify_did_update_database_field(field_id).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -339,11 +333,11 @@ impl DatabaseRevisionEditor {
|
|||||||
pub async fn duplicate_field(&self, field_id: &str) -> FlowyResult<()> {
|
pub async fn duplicate_field(&self, field_id: &str) -> FlowyResult<()> {
|
||||||
let duplicated_field_id = gen_field_id();
|
let duplicated_field_id = gen_field_id();
|
||||||
self
|
self
|
||||||
.modify(|grid| Ok(grid.duplicate_field_rev(field_id, &duplicated_field_id)?))
|
.modify(|pad| Ok(pad.duplicate_field_rev(field_id, &duplicated_field_id)?))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self
|
self
|
||||||
.notify_did_insert_grid_field(&duplicated_field_id)
|
.notify_did_insert_database_field(&duplicated_field_id)
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -385,16 +379,19 @@ impl DatabaseRevisionEditor {
|
|||||||
Ok(field_revs)
|
Ok(field_revs)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_block(&self, block_meta_rev: GridBlockMetaRevision) -> FlowyResult<()> {
|
pub async fn create_block(&self, block_meta_rev: DatabaseBlockMetaRevision) -> FlowyResult<()> {
|
||||||
self
|
self
|
||||||
.modify(|grid_pad| Ok(grid_pad.create_block_meta_rev(block_meta_rev)?))
|
.modify(|pad| Ok(pad.create_block_meta_rev(block_meta_rev)?))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn update_block(&self, changeset: GridBlockMetaRevisionChangeset) -> FlowyResult<()> {
|
pub async fn update_block(
|
||||||
|
&self,
|
||||||
|
changeset: DatabaseBlockMetaRevisionChangeset,
|
||||||
|
) -> FlowyResult<()> {
|
||||||
self
|
self
|
||||||
.modify(|grid_pad| Ok(grid_pad.update_block_rev(changeset)?))
|
.modify(|pad| Ok(pad.update_block_rev(changeset)?))
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -403,7 +400,7 @@ impl DatabaseRevisionEditor {
|
|||||||
let mut row_rev = self.create_row_rev().await?;
|
let mut row_rev = self.create_row_rev().await?;
|
||||||
|
|
||||||
self
|
self
|
||||||
.view_manager
|
.database_view_manager
|
||||||
.will_create_row(&mut row_rev, ¶ms)
|
.will_create_row(&mut row_rev, ¶ms)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
@ -411,13 +408,16 @@ impl DatabaseRevisionEditor {
|
|||||||
.create_row_pb(row_rev, params.start_row_id.clone())
|
.create_row_pb(row_rev, params.start_row_id.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.view_manager.did_create_row(&row_pb, ¶ms).await;
|
self
|
||||||
|
.database_view_manager
|
||||||
|
.did_create_row(&row_pb, ¶ms)
|
||||||
|
.await;
|
||||||
Ok(row_pb)
|
Ok(row_pb)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
pub async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
|
pub async fn move_group(&self, params: MoveGroupParams) -> FlowyResult<()> {
|
||||||
self.view_manager.move_group(params).await?;
|
self.database_view_manager.move_group(params).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +432,10 @@ impl DatabaseRevisionEditor {
|
|||||||
.or_insert_with(Vec::new)
|
.or_insert_with(Vec::new)
|
||||||
.push(row_rev);
|
.push(row_rev);
|
||||||
}
|
}
|
||||||
let changesets = self.block_manager.insert_row(rows_by_block_id).await?;
|
let changesets = self
|
||||||
|
.database_block_manager
|
||||||
|
.insert_row(rows_by_block_id)
|
||||||
|
.await?;
|
||||||
for changeset in changesets {
|
for changeset in changesets {
|
||||||
self.update_block(changeset).await?;
|
self.update_block(changeset).await?;
|
||||||
}
|
}
|
||||||
@ -442,14 +445,20 @@ impl DatabaseRevisionEditor {
|
|||||||
pub async fn update_row(&self, changeset: RowChangeset) -> FlowyResult<()> {
|
pub async fn update_row(&self, changeset: RowChangeset) -> FlowyResult<()> {
|
||||||
let row_id = changeset.row_id.clone();
|
let row_id = changeset.row_id.clone();
|
||||||
let old_row = self.get_row_rev(&row_id).await?;
|
let old_row = self.get_row_rev(&row_id).await?;
|
||||||
self.block_manager.update_row(changeset).await?;
|
self.database_block_manager.update_row(changeset).await?;
|
||||||
self.view_manager.did_update_row(old_row, &row_id).await;
|
self
|
||||||
|
.database_view_manager
|
||||||
|
.did_update_row(old_row, &row_id)
|
||||||
|
.await;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns all the rows in this block.
|
/// Returns all the rows in this block.
|
||||||
pub async fn get_row_pbs(&self, view_id: &str, block_id: &str) -> FlowyResult<Vec<RowPB>> {
|
pub async fn get_row_pbs(&self, view_id: &str, block_id: &str) -> FlowyResult<Vec<RowPB>> {
|
||||||
let rows = self.view_manager.get_row_revs(view_id, block_id).await?;
|
let rows = self
|
||||||
|
.database_view_manager
|
||||||
|
.get_row_revs(view_id, block_id)
|
||||||
|
.await?;
|
||||||
let rows = rows
|
let rows = rows
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|row_rev| RowPB::from(&row_rev))
|
.map(|row_rev| RowPB::from(&row_rev))
|
||||||
@ -459,10 +468,10 @@ impl DatabaseRevisionEditor {
|
|||||||
|
|
||||||
pub async fn get_all_row_revs(&self, view_id: &str) -> FlowyResult<Vec<Arc<RowRevision>>> {
|
pub async fn get_all_row_revs(&self, view_id: &str) -> FlowyResult<Vec<Arc<RowRevision>>> {
|
||||||
let mut all_rows = vec![];
|
let mut all_rows = vec![];
|
||||||
let blocks = self.block_manager.get_blocks(None).await?;
|
let blocks = self.database_block_manager.get_blocks(None).await?;
|
||||||
for block in blocks {
|
for block in blocks {
|
||||||
let rows = self
|
let rows = self
|
||||||
.view_manager
|
.database_view_manager
|
||||||
.get_row_revs(view_id, &block.block_id)
|
.get_row_revs(view_id, &block.block_id)
|
||||||
.await?;
|
.await?;
|
||||||
all_rows.extend(rows);
|
all_rows.extend(rows);
|
||||||
@ -471,17 +480,17 @@ impl DatabaseRevisionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_row_rev(&self, row_id: &str) -> FlowyResult<Option<Arc<RowRevision>>> {
|
pub async fn get_row_rev(&self, row_id: &str) -> FlowyResult<Option<Arc<RowRevision>>> {
|
||||||
match self.block_manager.get_row_rev(row_id).await? {
|
match self.database_block_manager.get_row_rev(row_id).await? {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some((_, row_rev)) => Ok(Some(row_rev)),
|
Some((_, row_rev)) => Ok(Some(row_rev)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
|
pub async fn delete_row(&self, row_id: &str) -> FlowyResult<()> {
|
||||||
let row_rev = self.block_manager.delete_row(row_id).await?;
|
let row_rev = self.database_block_manager.delete_row(row_id).await?;
|
||||||
tracing::trace!("Did delete row:{:?}", row_rev);
|
tracing::trace!("Did delete row:{:?}", row_rev);
|
||||||
if let Some(row_rev) = row_rev {
|
if let Some(row_rev) = row_rev {
|
||||||
self.view_manager.did_delete_row(row_rev).await;
|
self.database_view_manager.did_delete_row(row_rev).await;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -490,7 +499,10 @@ impl DatabaseRevisionEditor {
|
|||||||
&self,
|
&self,
|
||||||
view_id: &str,
|
view_id: &str,
|
||||||
) -> FlowyResult<broadcast::Receiver<DatabaseViewChanged>> {
|
) -> FlowyResult<broadcast::Receiver<DatabaseViewChanged>> {
|
||||||
self.view_manager.subscribe_view_changed(view_id).await
|
self
|
||||||
|
.database_view_manager
|
||||||
|
.subscribe_view_changed(view_id)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn duplicate_row(&self, _row_id: &str) -> FlowyResult<()> {
|
pub async fn duplicate_row(&self, _row_id: &str) -> FlowyResult<()> {
|
||||||
@ -545,7 +557,7 @@ impl DatabaseRevisionEditor {
|
|||||||
) -> Option<(FieldType, CellProtobufBlob)> {
|
) -> 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
|
let (_, row_rev) = self
|
||||||
.block_manager
|
.database_block_manager
|
||||||
.get_row_rev(¶ms.row_id)
|
.get_row_rev(¶ms.row_id)
|
||||||
.await
|
.await
|
||||||
.ok()??;
|
.ok()??;
|
||||||
@ -562,7 +574,7 @@ impl DatabaseRevisionEditor {
|
|||||||
row_id: &str,
|
row_id: &str,
|
||||||
field_id: &str,
|
field_id: &str,
|
||||||
) -> FlowyResult<Option<CellRevision>> {
|
) -> FlowyResult<Option<CellRevision>> {
|
||||||
match self.block_manager.get_row_rev(row_id).await? {
|
match self.database_block_manager.get_row_rev(row_id).await? {
|
||||||
None => Ok(None),
|
None => Ok(None),
|
||||||
Some((_, row_rev)) => {
|
Some((_, row_rev)) => {
|
||||||
let cell_rev = row_rev.cells.get(field_id).cloned();
|
let cell_rev = row_rev.cells.get(field_id).cloned();
|
||||||
@ -577,7 +589,7 @@ impl DatabaseRevisionEditor {
|
|||||||
view_id: &str,
|
view_id: &str,
|
||||||
field_id: &str,
|
field_id: &str,
|
||||||
) -> FlowyResult<Vec<RowSingleCellData>> {
|
) -> FlowyResult<Vec<RowSingleCellData>> {
|
||||||
let view_editor = self.view_manager.get_view_editor(view_id).await?;
|
let view_editor = self.database_view_manager.get_view_editor(view_id).await?;
|
||||||
view_editor.get_cells_for_field(field_id).await
|
view_editor.get_cells_for_field(field_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,8 +626,14 @@ impl DatabaseRevisionEditor {
|
|||||||
field_id: field_id.to_owned(),
|
field_id: field_id.to_owned(),
|
||||||
type_cell_data,
|
type_cell_data,
|
||||||
};
|
};
|
||||||
self.block_manager.update_cell(cell_changeset).await?;
|
self
|
||||||
self.view_manager.did_update_row(old_row_rev, row_id).await;
|
.database_block_manager
|
||||||
|
.update_cell(cell_changeset)
|
||||||
|
.await?;
|
||||||
|
self
|
||||||
|
.database_view_manager
|
||||||
|
.did_update_row(old_row_rev, row_id)
|
||||||
|
.await;
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -633,7 +651,7 @@ impl DatabaseRevisionEditor {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_block_meta_revs(&self) -> FlowyResult<Vec<Arc<GridBlockMetaRevision>>> {
|
pub async fn get_block_meta_revs(&self) -> FlowyResult<Vec<Arc<DatabaseBlockMetaRevision>>> {
|
||||||
let block_meta_revs = self.database_pad.read().await.get_block_meta_revs();
|
let block_meta_revs = self.database_pad.read().await.get_block_meta_revs();
|
||||||
Ok(block_meta_revs)
|
Ok(block_meta_revs)
|
||||||
}
|
}
|
||||||
@ -653,12 +671,15 @@ impl DatabaseRevisionEditor {
|
|||||||
.collect::<Vec<String>>(),
|
.collect::<Vec<String>>(),
|
||||||
Some(block_ids) => block_ids,
|
Some(block_ids) => block_ids,
|
||||||
};
|
};
|
||||||
let blocks = self.block_manager.get_blocks(Some(block_ids)).await?;
|
let blocks = self
|
||||||
|
.database_block_manager
|
||||||
|
.get_blocks(Some(block_ids))
|
||||||
|
.await?;
|
||||||
Ok(blocks)
|
Ok(blocks)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_rows(&self, block_rows: Vec<DatabaseBlockRow>) -> FlowyResult<()> {
|
pub async fn delete_rows(&self, block_rows: Vec<DatabaseBlockRow>) -> FlowyResult<()> {
|
||||||
let changesets = self.block_manager.delete_rows(block_rows).await?;
|
let changesets = self.database_block_manager.delete_rows(block_rows).await?;
|
||||||
for changeset in changesets {
|
for changeset in changesets {
|
||||||
self.update_block(changeset).await?;
|
self.update_block(changeset).await?;
|
||||||
}
|
}
|
||||||
@ -687,13 +708,13 @@ impl DatabaseRevisionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_setting(&self) -> FlowyResult<DatabaseViewSettingPB> {
|
pub async fn get_setting(&self) -> FlowyResult<DatabaseViewSettingPB> {
|
||||||
self.view_manager.get_setting().await
|
self.database_view_manager.get_setting().await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all_filters(&self) -> FlowyResult<Vec<FilterPB>> {
|
pub async fn get_all_filters(&self) -> FlowyResult<Vec<FilterPB>> {
|
||||||
Ok(
|
Ok(
|
||||||
self
|
self
|
||||||
.view_manager
|
.database_view_manager
|
||||||
.get_all_filters()
|
.get_all_filters()
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -703,23 +724,26 @@ impl DatabaseRevisionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_filters(&self, filter_id: FilterType) -> FlowyResult<Vec<Arc<FilterRevision>>> {
|
pub async fn get_filters(&self, filter_id: FilterType) -> FlowyResult<Vec<Arc<FilterRevision>>> {
|
||||||
self.view_manager.get_filters(&filter_id).await
|
self.database_view_manager.get_filters(&filter_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_or_update_filter(&self, params: AlterFilterParams) -> FlowyResult<()> {
|
pub async fn create_or_update_filter(&self, params: AlterFilterParams) -> FlowyResult<()> {
|
||||||
self.view_manager.create_or_update_filter(params).await?;
|
self
|
||||||
|
.database_view_manager
|
||||||
|
.create_or_update_filter(params)
|
||||||
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_filter(&self, params: DeleteFilterParams) -> FlowyResult<()> {
|
pub async fn delete_filter(&self, params: DeleteFilterParams) -> FlowyResult<()> {
|
||||||
self.view_manager.delete_filter(params).await?;
|
self.database_view_manager.delete_filter(params).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_all_sorts(&self, view_id: &str) -> FlowyResult<Vec<SortPB>> {
|
pub async fn get_all_sorts(&self, view_id: &str) -> FlowyResult<Vec<SortPB>> {
|
||||||
Ok(
|
Ok(
|
||||||
self
|
self
|
||||||
.view_manager
|
.database_view_manager
|
||||||
.get_all_sorts(view_id)
|
.get_all_sorts(view_id)
|
||||||
.await?
|
.await?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -729,25 +753,31 @@ impl DatabaseRevisionEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_all_sorts(&self, view_id: &str) -> FlowyResult<()> {
|
pub async fn delete_all_sorts(&self, view_id: &str) -> FlowyResult<()> {
|
||||||
self.view_manager.delete_all_sorts(view_id).await
|
self.database_view_manager.delete_all_sorts(view_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_sort(&self, params: DeleteSortParams) -> FlowyResult<()> {
|
pub async fn delete_sort(&self, params: DeleteSortParams) -> FlowyResult<()> {
|
||||||
self.view_manager.delete_sort(params).await?;
|
self.database_view_manager.delete_sort(params).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_or_update_sort(&self, params: AlterSortParams) -> FlowyResult<SortRevision> {
|
pub async fn create_or_update_sort(&self, params: AlterSortParams) -> FlowyResult<SortRevision> {
|
||||||
let sort_rev = self.view_manager.create_or_update_sort(params).await?;
|
let sort_rev = self
|
||||||
|
.database_view_manager
|
||||||
|
.create_or_update_sort(params)
|
||||||
|
.await?;
|
||||||
Ok(sort_rev)
|
Ok(sort_rev)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn insert_group(&self, params: InsertGroupParams) -> FlowyResult<()> {
|
pub async fn insert_group(&self, params: InsertGroupParams) -> FlowyResult<()> {
|
||||||
self.view_manager.insert_or_update_group(params).await
|
self
|
||||||
|
.database_view_manager
|
||||||
|
.insert_or_update_group(params)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn delete_group(&self, params: DeleteGroupParams) -> FlowyResult<()> {
|
pub async fn delete_group(&self, params: DeleteGroupParams) -> FlowyResult<()> {
|
||||||
self.view_manager.delete_group(params).await
|
self.database_view_manager.delete_group(params).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn move_row(&self, params: MoveRowParams) -> FlowyResult<()> {
|
pub async fn move_row(&self, params: MoveRowParams) -> FlowyResult<()> {
|
||||||
@ -757,17 +787,21 @@ impl DatabaseRevisionEditor {
|
|||||||
to_row_id,
|
to_row_id,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
match self.block_manager.get_row_rev(&from_row_id).await? {
|
match self
|
||||||
|
.database_block_manager
|
||||||
|
.get_row_rev(&from_row_id)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
None => tracing::warn!("Move row failed, can not find the row:{}", from_row_id),
|
None => tracing::warn!("Move row failed, can not find the row:{}", from_row_id),
|
||||||
Some((_, row_rev)) => {
|
Some((_, row_rev)) => {
|
||||||
match (
|
match (
|
||||||
self.block_manager.index_of_row(&from_row_id).await,
|
self.database_block_manager.index_of_row(&from_row_id).await,
|
||||||
self.block_manager.index_of_row(&to_row_id).await,
|
self.database_block_manager.index_of_row(&to_row_id).await,
|
||||||
) {
|
) {
|
||||||
(Some(from_index), Some(to_index)) => {
|
(Some(from_index), Some(to_index)) => {
|
||||||
tracing::trace!("Move row from {} to {}", from_index, to_index);
|
tracing::trace!("Move row from {} to {}", from_index, to_index);
|
||||||
self
|
self
|
||||||
.block_manager
|
.database_block_manager
|
||||||
.move_row(row_rev.clone(), from_index, to_index)
|
.move_row(row_rev.clone(), from_index, to_index)
|
||||||
.await?;
|
.await?;
|
||||||
},
|
},
|
||||||
@ -787,12 +821,16 @@ impl DatabaseRevisionEditor {
|
|||||||
to_row_id,
|
to_row_id,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
match self.block_manager.get_row_rev(&from_row_id).await? {
|
match self
|
||||||
|
.database_block_manager
|
||||||
|
.get_row_rev(&from_row_id)
|
||||||
|
.await?
|
||||||
|
{
|
||||||
None => tracing::warn!("Move row failed, can not find the row:{}", from_row_id),
|
None => tracing::warn!("Move row failed, can not find the row:{}", from_row_id),
|
||||||
Some((_, row_rev)) => {
|
Some((_, row_rev)) => {
|
||||||
let block_manager = self.block_manager.clone();
|
let block_manager = self.database_block_manager.clone();
|
||||||
self
|
self
|
||||||
.view_manager
|
.database_view_manager
|
||||||
.move_group_row(row_rev, to_group_id, to_row_id.clone(), |row_changeset| {
|
.move_group_row(row_rev, to_group_id, to_row_id.clone(), |row_changeset| {
|
||||||
to_fut(async move {
|
to_fut(async move {
|
||||||
tracing::trace!("Row data changed: {:?}", row_changeset);
|
tracing::trace!("Row data changed: {:?}", row_changeset);
|
||||||
@ -830,42 +868,40 @@ impl DatabaseRevisionEditor {
|
|||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
self
|
self
|
||||||
.modify(|grid_pad| {
|
.modify(|pad| Ok(pad.move_field(&field_id, from_index as usize, to_index as usize)?))
|
||||||
Ok(grid_pad.move_field(&field_id, from_index as usize, to_index as usize)?)
|
|
||||||
})
|
|
||||||
.await?;
|
.await?;
|
||||||
if let Some((index, field_rev)) = self.database_pad.read().await.get_field_rev(&field_id) {
|
if let Some((index, field_rev)) = self.database_pad.read().await.get_field_rev(&field_id) {
|
||||||
let delete_field_order = FieldIdPB::from(field_id);
|
let delete_field_order = FieldIdPB::from(field_id);
|
||||||
let insert_field = IndexFieldPB::from_field_rev(field_rev, index);
|
let insert_field = IndexFieldPB::from_field_rev(field_rev, index);
|
||||||
let notified_changeset = DatabaseFieldChangesetPB {
|
let notified_changeset = DatabaseFieldChangesetPB {
|
||||||
database_id: self.database_id.clone(),
|
view_id: self.database_id.clone(),
|
||||||
inserted_fields: vec![insert_field],
|
inserted_fields: vec![insert_field],
|
||||||
deleted_fields: vec![delete_field_order],
|
deleted_fields: vec![delete_field_order],
|
||||||
updated_fields: vec![],
|
updated_fields: vec![],
|
||||||
};
|
};
|
||||||
|
|
||||||
self.notify_did_update_grid(notified_changeset).await?;
|
self.notify_did_update_database(notified_changeset).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn duplicate_grid(&self) -> FlowyResult<BuildDatabaseContext> {
|
pub async fn duplicate_database(&self) -> FlowyResult<BuildDatabaseContext> {
|
||||||
let grid_pad = self.database_pad.read().await;
|
let database_pad = self.database_pad.read().await;
|
||||||
let grid_view_revision_data = self.view_manager.duplicate_database_view().await?;
|
let database_view_data = self.database_view_manager.duplicate_database_view().await?;
|
||||||
let original_blocks = grid_pad.get_block_meta_revs();
|
let original_blocks = database_pad.get_block_meta_revs();
|
||||||
let (duplicated_fields, duplicated_blocks) = grid_pad.duplicate_grid_block_meta().await;
|
let (duplicated_fields, duplicated_blocks) = database_pad.duplicate_database_block_meta().await;
|
||||||
|
|
||||||
let mut blocks_meta_data = vec![];
|
let mut blocks_meta_data = vec![];
|
||||||
if original_blocks.len() == duplicated_blocks.len() {
|
if original_blocks.len() == duplicated_blocks.len() {
|
||||||
for (index, original_block_meta) in original_blocks.iter().enumerate() {
|
for (index, original_block_meta) in original_blocks.iter().enumerate() {
|
||||||
let grid_block_meta_editor = self
|
let database_block_meta_editor = self
|
||||||
.block_manager
|
.database_block_manager
|
||||||
.get_block_editor(&original_block_meta.block_id)
|
.get_or_create_block_editor(&original_block_meta.block_id)
|
||||||
.await?;
|
.await?;
|
||||||
let duplicated_block_id = &duplicated_blocks[index].block_id;
|
let duplicated_block_id = &duplicated_blocks[index].block_id;
|
||||||
|
|
||||||
tracing::trace!("Duplicate block:{} meta data", duplicated_block_id);
|
tracing::trace!("Duplicate block:{} meta data", duplicated_block_id);
|
||||||
let duplicated_block_meta_data = grid_block_meta_editor
|
let duplicated_block_meta_data = database_block_meta_editor
|
||||||
.duplicate_block(duplicated_block_id)
|
.duplicate_block(duplicated_block_id)
|
||||||
.await;
|
.await;
|
||||||
blocks_meta_data.push(duplicated_block_meta_data);
|
blocks_meta_data.push(duplicated_block_meta_data);
|
||||||
@ -873,19 +909,19 @@ impl DatabaseRevisionEditor {
|
|||||||
} else {
|
} else {
|
||||||
debug_assert_eq!(original_blocks.len(), duplicated_blocks.len());
|
debug_assert_eq!(original_blocks.len(), duplicated_blocks.len());
|
||||||
}
|
}
|
||||||
drop(grid_pad);
|
drop(database_pad);
|
||||||
|
|
||||||
Ok(BuildDatabaseContext {
|
Ok(BuildDatabaseContext {
|
||||||
field_revs: duplicated_fields.into_iter().map(Arc::new).collect(),
|
field_revs: duplicated_fields.into_iter().map(Arc::new).collect(),
|
||||||
block_metas: duplicated_blocks,
|
block_metas: duplicated_blocks,
|
||||||
blocks: blocks_meta_data,
|
blocks: blocks_meta_data,
|
||||||
grid_view_revision_data,
|
database_view_data,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
pub async fn load_groups(&self) -> FlowyResult<RepeatedGroupPB> {
|
pub async fn load_groups(&self) -> FlowyResult<RepeatedGroupPB> {
|
||||||
self.view_manager.load_groups().await
|
self.database_view_manager.load_groups().await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn create_row_rev(&self) -> FlowyResult<RowRevision> {
|
async fn create_row_rev(&self) -> FlowyResult<RowRevision> {
|
||||||
@ -906,10 +942,13 @@ impl DatabaseRevisionEditor {
|
|||||||
let block_id = row_rev.block_id.clone();
|
let block_id = row_rev.block_id.clone();
|
||||||
|
|
||||||
// insert the row
|
// insert the row
|
||||||
let row_count = self.block_manager.create_row(row_rev, start_row_id).await?;
|
let row_count = self
|
||||||
|
.database_block_manager
|
||||||
|
.create_row(row_rev, start_row_id)
|
||||||
|
.await?;
|
||||||
|
|
||||||
// update block row count
|
// update block row count
|
||||||
let changeset = GridBlockMetaRevisionChangeset::from_row_count(block_id, row_count);
|
let changeset = DatabaseBlockMetaRevisionChangeset::from_row_count(block_id, row_count);
|
||||||
self.update_block(changeset).await?;
|
self.update_block(changeset).await?;
|
||||||
Ok(row_pb)
|
Ok(row_pb)
|
||||||
}
|
}
|
||||||
@ -938,24 +977,25 @@ impl DatabaseRevisionEditor {
|
|||||||
|
|
||||||
async fn block_id(&self) -> FlowyResult<String> {
|
async fn block_id(&self) -> FlowyResult<String> {
|
||||||
match self.database_pad.read().await.get_block_meta_revs().last() {
|
match self.database_pad.read().await.get_block_meta_revs().last() {
|
||||||
None => Err(FlowyError::internal().context("There is no grid block in this grid")),
|
None => Err(FlowyError::internal().context("There is no block in this database")),
|
||||||
Some(grid_block) => Ok(grid_block.block_id.clone()),
|
Some(database_block) => Ok(database_block.block_id.clone()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
async fn notify_did_insert_grid_field(&self, field_id: &str) -> FlowyResult<()> {
|
async fn notify_did_insert_database_field(&self, field_id: &str) -> FlowyResult<()> {
|
||||||
if let Some((index, field_rev)) = self.database_pad.read().await.get_field_rev(field_id) {
|
if let Some((index, field_rev)) = self.database_pad.read().await.get_field_rev(field_id) {
|
||||||
let index_field = IndexFieldPB::from_field_rev(field_rev, index);
|
let index_field = IndexFieldPB::from_field_rev(field_rev, index);
|
||||||
|
//TODO(nathan): broadcast the changeset to views that reference to this database
|
||||||
let notified_changeset =
|
let notified_changeset =
|
||||||
DatabaseFieldChangesetPB::insert(&self.database_id, vec![index_field]);
|
DatabaseFieldChangesetPB::insert(&self.database_id, vec![index_field]);
|
||||||
self.notify_did_update_grid(notified_changeset).await?;
|
self.notify_did_update_database(notified_changeset).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(level = "trace", skip_all, err)]
|
#[tracing::instrument(level = "trace", skip_all, err)]
|
||||||
async fn notify_did_update_grid_field(&self, field_id: &str) -> FlowyResult<()> {
|
async fn notify_did_update_database_field(&self, field_id: &str) -> FlowyResult<()> {
|
||||||
if let Some((_, field_rev)) = self
|
if let Some((_, field_rev)) = self
|
||||||
.database_pad
|
.database_pad
|
||||||
.read()
|
.read()
|
||||||
@ -966,7 +1006,7 @@ impl DatabaseRevisionEditor {
|
|||||||
let updated_field = FieldPB::from(field_rev);
|
let updated_field = FieldPB::from(field_rev);
|
||||||
let notified_changeset =
|
let notified_changeset =
|
||||||
DatabaseFieldChangesetPB::update(&self.database_id, vec![updated_field.clone()]);
|
DatabaseFieldChangesetPB::update(&self.database_id, vec![updated_field.clone()]);
|
||||||
self.notify_did_update_grid(notified_changeset).await?;
|
self.notify_did_update_database(notified_changeset).await?;
|
||||||
|
|
||||||
send_notification(field_id, DatabaseNotification::DidUpdateField)
|
send_notification(field_id, DatabaseNotification::DidUpdateField)
|
||||||
.payload(updated_field)
|
.payload(updated_field)
|
||||||
@ -976,7 +1016,10 @@ impl DatabaseRevisionEditor {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn notify_did_update_grid(&self, changeset: DatabaseFieldChangesetPB) -> FlowyResult<()> {
|
async fn notify_did_update_database(
|
||||||
|
&self,
|
||||||
|
changeset: DatabaseFieldChangesetPB,
|
||||||
|
) -> FlowyResult<()> {
|
||||||
send_notification(&self.database_id, DatabaseNotification::DidUpdateFields)
|
send_notification(&self.database_id, DatabaseNotification::DidUpdateFields)
|
||||||
.payload(changeset)
|
.payload(changeset)
|
||||||
.send();
|
.send();
|
||||||
@ -990,13 +1033,13 @@ impl DatabaseRevisionEditor {
|
|||||||
self.rev_manager.clone()
|
self.rev_manager.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn grid_pad(&self) -> Arc<RwLock<DatabaseRevisionPad>> {
|
pub fn database_pad(&self) -> Arc<RwLock<DatabaseRevisionPad>> {
|
||||||
self.database_pad.clone()
|
self.database_pad.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridRevisionSerde();
|
pub struct DatabaseRevisionSerde();
|
||||||
impl RevisionObjectDeserializer for GridRevisionSerde {
|
impl RevisionObjectDeserializer for DatabaseRevisionSerde {
|
||||||
type Output = DatabaseRevisionPad;
|
type Output = DatabaseRevisionPad;
|
||||||
|
|
||||||
fn deserialize_revisions(
|
fn deserialize_revisions(
|
||||||
@ -1011,25 +1054,25 @@ impl RevisionObjectDeserializer for GridRevisionSerde {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl RevisionObjectSerializer for GridRevisionSerde {
|
impl RevisionObjectSerializer for DatabaseRevisionSerde {
|
||||||
fn combine_revisions(revisions: Vec<Revision>) -> FlowyResult<Bytes> {
|
fn combine_revisions(revisions: Vec<Revision>) -> FlowyResult<Bytes> {
|
||||||
let operations = make_operations_from_revisions::<EmptyAttributes>(revisions)?;
|
let operations = make_operations_from_revisions::<EmptyAttributes>(revisions)?;
|
||||||
Ok(operations.json_bytes())
|
Ok(operations.json_bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridRevisionCloudService {
|
pub struct DatabaseRevisionCloudService {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
token: String,
|
token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GridRevisionCloudService {
|
impl DatabaseRevisionCloudService {
|
||||||
pub fn new(token: String) -> Self {
|
pub fn new(token: String) -> Self {
|
||||||
Self { token }
|
Self { token }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RevisionCloudService for GridRevisionCloudService {
|
impl RevisionCloudService for DatabaseRevisionCloudService {
|
||||||
#[tracing::instrument(level = "trace", skip(self))]
|
#[tracing::instrument(level = "trace", skip(self))]
|
||||||
fn fetch_object(
|
fn fetch_object(
|
||||||
&self,
|
&self,
|
||||||
@ -1040,11 +1083,11 @@ impl RevisionCloudService for GridRevisionCloudService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct GridRevisionMergeable();
|
pub struct DatabaseRevisionMergeable();
|
||||||
|
|
||||||
impl RevisionMergeable for GridRevisionMergeable {
|
impl RevisionMergeable for DatabaseRevisionMergeable {
|
||||||
fn combine_revisions(&self, revisions: Vec<Revision>) -> FlowyResult<Bytes> {
|
fn combine_revisions(&self, revisions: Vec<Revision>) -> FlowyResult<Bytes> {
|
||||||
GridRevisionSerde::combine_revisions(revisions)
|
DatabaseRevisionSerde::combine_revisions(revisions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
mod block_editor;
|
||||||
|
mod block_manager;
|
||||||
|
mod database_editor;
|
||||||
|
mod retry;
|
||||||
|
mod trait_impl;
|
||||||
|
|
||||||
|
pub use block_editor::*;
|
||||||
|
pub use block_manager::*;
|
||||||
|
pub use database_editor::*;
|
||||||
|
pub use trait_impl::*;
|
@ -1,6 +1,6 @@
|
|||||||
use flowy_client_sync::client_database::GridBlockRevisionPad;
|
use database_model::RowRevision;
|
||||||
|
use flowy_client_sync::client_database::DatabaseBlockRevisionPad;
|
||||||
use flowy_error::FlowyError;
|
use flowy_error::FlowyError;
|
||||||
use grid_model::RowRevision;
|
|
||||||
use lib_infra::retry::Action;
|
use lib_infra::retry::Action;
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
@ -9,7 +9,7 @@ use tokio::sync::RwLock;
|
|||||||
|
|
||||||
pub struct GetRowDataRetryAction {
|
pub struct GetRowDataRetryAction {
|
||||||
pub row_id: String,
|
pub row_id: String,
|
||||||
pub pad: Arc<RwLock<GridBlockRevisionPad>>,
|
pub pad: Arc<RwLock<DatabaseBlockRevisionPad>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Action for GetRowDataRetryAction {
|
impl Action for GetRowDataRetryAction {
|
@ -1,25 +1,26 @@
|
|||||||
use crate::entities::FieldType;
|
use crate::entities::FieldType;
|
||||||
use crate::services::block_manager::DatabaseBlockManager;
|
|
||||||
use crate::services::cell::AtomicCellDataCache;
|
use crate::services::cell::AtomicCellDataCache;
|
||||||
|
use crate::services::database::DatabaseBlockManager;
|
||||||
|
use crate::services::database_view::DatabaseViewEditorDelegate;
|
||||||
use crate::services::field::{TypeOptionCellDataHandler, TypeOptionCellExt};
|
use crate::services::field::{TypeOptionCellDataHandler, TypeOptionCellExt};
|
||||||
use crate::services::row::DatabaseBlockRowRevision;
|
use crate::services::row::DatabaseBlockRowRevision;
|
||||||
use crate::services::view_editor::DatabaseViewEditorDelegate;
|
|
||||||
|
|
||||||
|
use database_model::{FieldRevision, RowRevision};
|
||||||
use flowy_client_sync::client_database::DatabaseRevisionPad;
|
use flowy_client_sync::client_database::DatabaseRevisionPad;
|
||||||
use flowy_task::TaskDispatcher;
|
use flowy_task::TaskDispatcher;
|
||||||
use grid_model::{FieldRevision, RowRevision};
|
|
||||||
use lib_infra::future::{to_fut, Fut};
|
use lib_infra::future::{to_fut, Fut};
|
||||||
|
use std::any::type_name;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub(crate) struct GridViewEditorDelegateImpl {
|
pub struct DatabaseViewEditorDelegateImpl {
|
||||||
pub(crate) pad: Arc<RwLock<DatabaseRevisionPad>>,
|
pub(crate) pad: Arc<RwLock<DatabaseRevisionPad>>,
|
||||||
pub(crate) block_manager: Arc<DatabaseBlockManager>,
|
pub(crate) block_manager: Arc<DatabaseBlockManager>,
|
||||||
pub(crate) task_scheduler: Arc<RwLock<TaskDispatcher>>,
|
pub(crate) task_scheduler: Arc<RwLock<TaskDispatcher>>,
|
||||||
pub(crate) cell_data_cache: AtomicCellDataCache,
|
pub(crate) cell_data_cache: AtomicCellDataCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseViewEditorDelegate for GridViewEditorDelegateImpl {
|
impl DatabaseViewEditorDelegate for DatabaseViewEditorDelegateImpl {
|
||||||
fn get_field_revs(&self, field_ids: Option<Vec<String>>) -> Fut<Vec<Arc<FieldRevision>>> {
|
fn get_field_revs(&self, field_ids: Option<Vec<String>>) -> Fut<Vec<Arc<FieldRevision>>> {
|
||||||
let pad = self.pad.clone();
|
let pad = self.pad.clone();
|
||||||
to_fut(async move {
|
to_fut(async move {
|
||||||
@ -27,7 +28,8 @@ impl DatabaseViewEditorDelegate for GridViewEditorDelegateImpl {
|
|||||||
Ok(field_revs) => field_revs,
|
Ok(field_revs) => field_revs,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::error!(
|
tracing::error!(
|
||||||
"[GridViewRevisionDelegate] get field revisions failed: {}",
|
"[{}] get field revisions failed: {}",
|
||||||
|
type_name::<DatabaseViewEditorDelegateImpl>(),
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
vec![]
|
vec![]
|
@ -1,7 +1,10 @@
|
|||||||
use crate::entities::*;
|
use crate::entities::*;
|
||||||
use crate::notification::{send_notification, DatabaseNotification};
|
use crate::notification::{send_notification, DatabaseNotification};
|
||||||
use crate::services::block_manager::DatabaseBlockEvent;
|
|
||||||
use crate::services::cell::{AtomicCellDataCache, TypeCellData};
|
use crate::services::cell::{AtomicCellDataCache, TypeCellData};
|
||||||
|
use crate::services::database::DatabaseBlockEvent;
|
||||||
|
use crate::services::database_view::notifier::DatabaseViewChangedNotifier;
|
||||||
|
use crate::services::database_view::trait_impl::*;
|
||||||
|
use crate::services::database_view::DatabaseViewChangedReceiverRunner;
|
||||||
use crate::services::field::{RowSingleCellData, TypeOptionCellDataHandler};
|
use crate::services::field::{RowSingleCellData, TypeOptionCellDataHandler};
|
||||||
use crate::services::filter::{
|
use crate::services::filter::{
|
||||||
FilterChangeset, FilterController, FilterTaskHandler, FilterType, UpdatedFilterType,
|
FilterChangeset, FilterController, FilterTaskHandler, FilterType, UpdatedFilterType,
|
||||||
@ -14,20 +17,17 @@ use crate::services::row::DatabaseBlockRowRevision;
|
|||||||
use crate::services::sort::{
|
use crate::services::sort::{
|
||||||
DeletedSortType, SortChangeset, SortController, SortTaskHandler, SortType,
|
DeletedSortType, SortChangeset, SortController, SortTaskHandler, SortType,
|
||||||
};
|
};
|
||||||
use crate::services::view_editor::changed_notifier::GridViewChangedNotifier;
|
use database_model::{
|
||||||
use crate::services::view_editor::trait_impl::*;
|
gen_database_filter_id, gen_database_sort_id, FieldRevision, FieldTypeRevision, FilterRevision,
|
||||||
use crate::services::view_editor::GridViewChangedReceiverRunner;
|
LayoutRevision, RowChangeset, RowRevision, SortRevision,
|
||||||
|
};
|
||||||
use flowy_client_sync::client_database::{
|
use flowy_client_sync::client_database::{
|
||||||
make_grid_view_operations, GridViewRevisionChangeset, GridViewRevisionPad,
|
make_grid_view_operations, DatabaseViewRevisionPad, GridViewRevisionChangeset,
|
||||||
};
|
};
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_revision::RevisionManager;
|
use flowy_revision::RevisionManager;
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use flowy_task::TaskDispatcher;
|
use flowy_task::TaskDispatcher;
|
||||||
use grid_model::{
|
|
||||||
gen_grid_filter_id, gen_grid_sort_id, FieldRevision, FieldTypeRevision, FilterRevision,
|
|
||||||
LayoutRevision, RowChangeset, RowRevision, SortRevision,
|
|
||||||
};
|
|
||||||
use lib_infra::async_trait::async_trait;
|
use lib_infra::async_trait::async_trait;
|
||||||
use lib_infra::future::Fut;
|
use lib_infra::future::Fut;
|
||||||
use lib_infra::ref_map::RefCountValue;
|
use lib_infra::ref_map::RefCountValue;
|
||||||
@ -76,13 +76,13 @@ pub trait DatabaseViewEditorDelegate: Send + Sync + 'static {
|
|||||||
pub struct DatabaseViewRevisionEditor {
|
pub struct DatabaseViewRevisionEditor {
|
||||||
user_id: String,
|
user_id: String,
|
||||||
view_id: String,
|
view_id: String,
|
||||||
pad: Arc<RwLock<GridViewRevisionPad>>,
|
pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
||||||
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
group_controller: Arc<RwLock<Box<dyn GroupController>>>,
|
group_controller: Arc<RwLock<Box<dyn GroupController>>>,
|
||||||
filter_controller: Arc<FilterController>,
|
filter_controller: Arc<FilterController>,
|
||||||
sort_controller: Arc<RwLock<SortController>>,
|
sort_controller: Arc<RwLock<SortController>>,
|
||||||
pub notifier: GridViewChangedNotifier,
|
pub notifier: DatabaseViewChangedNotifier,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DatabaseViewRevisionEditor {
|
impl DatabaseViewRevisionEditor {
|
||||||
@ -96,7 +96,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
mut rev_manager: RevisionManager<Arc<ConnectionPool>>,
|
mut rev_manager: RevisionManager<Arc<ConnectionPool>>,
|
||||||
) -> FlowyResult<Self> {
|
) -> FlowyResult<Self> {
|
||||||
let (notifier, _) = broadcast::channel(100);
|
let (notifier, _) = broadcast::channel(100);
|
||||||
tokio::spawn(GridViewChangedReceiverRunner(Some(notifier.subscribe())).run());
|
tokio::spawn(DatabaseViewChangedReceiverRunner(Some(notifier.subscribe())).run());
|
||||||
let cloud = Arc::new(GridViewRevisionCloudService {
|
let cloud = Arc::new(GridViewRevisionCloudService {
|
||||||
token: token.to_owned(),
|
token: token.to_owned(),
|
||||||
});
|
});
|
||||||
@ -109,8 +109,11 @@ impl DatabaseViewRevisionEditor {
|
|||||||
Err(err) => {
|
Err(err) => {
|
||||||
// It shouldn't be here, because the snapshot should come to recue.
|
// It shouldn't be here, because the snapshot should come to recue.
|
||||||
tracing::error!("Deserialize grid view revisions failed: {}", err);
|
tracing::error!("Deserialize grid view revisions failed: {}", err);
|
||||||
let view =
|
let view = DatabaseViewRevisionPad::new(
|
||||||
GridViewRevisionPad::new(view_id.to_owned(), view_id.to_owned(), LayoutRevision::Grid);
|
view_id.to_owned(),
|
||||||
|
view_id.to_owned(),
|
||||||
|
LayoutRevision::Grid,
|
||||||
|
);
|
||||||
let bytes = make_grid_view_operations(&view).json_bytes();
|
let bytes = make_grid_view_operations(&view).json_bytes();
|
||||||
let reset_revision = Revision::initial_revision(&view_id, bytes);
|
let reset_revision = Revision::initial_revision(&view_id, bytes);
|
||||||
let _ = rev_manager.reset_object(vec![reset_revision]).await;
|
let _ = rev_manager.reset_object(vec![reset_revision]).await;
|
||||||
@ -460,7 +463,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
let sort_type = SortType::from(¶ms);
|
let sort_type = SortType::from(¶ms);
|
||||||
let is_exist = params.sort_id.is_some();
|
let is_exist = params.sort_id.is_some();
|
||||||
let sort_id = match params.sort_id {
|
let sort_id = match params.sort_id {
|
||||||
None => gen_grid_sort_id(),
|
None => gen_database_sort_id(),
|
||||||
Some(sort_id) => sort_id,
|
Some(sort_id) => sort_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -559,7 +562,7 @@ impl DatabaseViewRevisionEditor {
|
|||||||
let filter_type = FilterType::from(¶ms);
|
let filter_type = FilterType::from(¶ms);
|
||||||
let is_exist = params.filter_id.is_some();
|
let is_exist = params.filter_id.is_some();
|
||||||
let filter_id = match params.filter_id {
|
let filter_id = match params.filter_id {
|
||||||
None => gen_grid_filter_id(),
|
None => gen_database_filter_id(),
|
||||||
Some(filter_id) => filter_id,
|
Some(filter_id) => filter_id,
|
||||||
};
|
};
|
||||||
let filter_rev = FilterRevision {
|
let filter_rev = FilterRevision {
|
||||||
@ -756,8 +759,9 @@ impl DatabaseViewRevisionEditor {
|
|||||||
|
|
||||||
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
async fn modify<F>(&self, f: F) -> FlowyResult<()>
|
||||||
where
|
where
|
||||||
F:
|
F: for<'a> FnOnce(
|
||||||
for<'a> FnOnce(&'a mut GridViewRevisionPad) -> FlowyResult<Option<GridViewRevisionChangeset>>,
|
&'a mut DatabaseViewRevisionPad,
|
||||||
|
) -> FlowyResult<Option<GridViewRevisionChangeset>>,
|
||||||
{
|
{
|
||||||
let mut write_guard = self.pad.write().await;
|
let mut write_guard = self.pad.write().await;
|
||||||
match f(&mut write_guard)? {
|
match f(&mut write_guard)? {
|
||||||
@ -839,7 +843,7 @@ impl RefCountValue for DatabaseViewRevisionEditor {
|
|||||||
async fn new_group_controller(
|
async fn new_group_controller(
|
||||||
user_id: String,
|
user_id: String,
|
||||||
view_id: String,
|
view_id: String,
|
||||||
view_rev_pad: Arc<RwLock<GridViewRevisionPad>>,
|
view_rev_pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
||||||
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
) -> FlowyResult<Box<dyn GroupController>> {
|
) -> FlowyResult<Box<dyn GroupController>> {
|
||||||
@ -879,7 +883,7 @@ async fn new_group_controller(
|
|||||||
async fn new_group_controller_with_field_rev(
|
async fn new_group_controller_with_field_rev(
|
||||||
user_id: String,
|
user_id: String,
|
||||||
view_id: String,
|
view_id: String,
|
||||||
view_rev_pad: Arc<RwLock<GridViewRevisionPad>>,
|
view_rev_pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
||||||
field_rev: Arc<FieldRevision>,
|
field_rev: Arc<FieldRevision>,
|
||||||
row_revs: Vec<Arc<RowRevision>>,
|
row_revs: Vec<Arc<RowRevision>>,
|
||||||
@ -903,9 +907,9 @@ async fn new_group_controller_with_field_rev(
|
|||||||
async fn make_filter_controller(
|
async fn make_filter_controller(
|
||||||
view_id: &str,
|
view_id: &str,
|
||||||
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
notifier: GridViewChangedNotifier,
|
notifier: DatabaseViewChangedNotifier,
|
||||||
cell_data_cache: AtomicCellDataCache,
|
cell_data_cache: AtomicCellDataCache,
|
||||||
pad: Arc<RwLock<GridViewRevisionPad>>,
|
pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
) -> Arc<FilterController> {
|
) -> Arc<FilterController> {
|
||||||
let field_revs = delegate.get_field_revs(None).await;
|
let field_revs = delegate.get_field_revs(None).await;
|
||||||
let filter_revs = pad.read().await.get_all_filters(&field_revs);
|
let filter_revs = pad.read().await.get_all_filters(&field_revs);
|
||||||
@ -939,9 +943,9 @@ async fn make_filter_controller(
|
|||||||
async fn make_sort_controller(
|
async fn make_sort_controller(
|
||||||
view_id: &str,
|
view_id: &str,
|
||||||
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
notifier: GridViewChangedNotifier,
|
notifier: DatabaseViewChangedNotifier,
|
||||||
filter_controller: Arc<FilterController>,
|
filter_controller: Arc<FilterController>,
|
||||||
pad: Arc<RwLock<GridViewRevisionPad>>,
|
pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
cell_data_cache: AtomicCellDataCache,
|
cell_data_cache: AtomicCellDataCache,
|
||||||
) -> Arc<RwLock<SortController>> {
|
) -> Arc<RwLock<SortController>> {
|
||||||
let handler_id = gen_handler_id();
|
let handler_id = gen_handler_id();
|
@ -3,19 +3,19 @@ use crate::entities::{
|
|||||||
DeleteGroupParams, DeleteSortParams, InsertGroupParams, MoveGroupParams, RepeatedGroupPB, RowPB,
|
DeleteGroupParams, DeleteSortParams, InsertGroupParams, MoveGroupParams, RepeatedGroupPB, RowPB,
|
||||||
};
|
};
|
||||||
use crate::manager::DatabaseUser;
|
use crate::manager::DatabaseUser;
|
||||||
use crate::services::block_manager::DatabaseBlockEvent;
|
|
||||||
use crate::services::cell::AtomicCellDataCache;
|
use crate::services::cell::AtomicCellDataCache;
|
||||||
|
use crate::services::database::DatabaseBlockEvent;
|
||||||
|
use crate::services::database_view::notifier::*;
|
||||||
|
use crate::services::database_view::trait_impl::GridViewRevisionMergeable;
|
||||||
|
use crate::services::database_view::{DatabaseViewEditorDelegate, DatabaseViewRevisionEditor};
|
||||||
use crate::services::filter::FilterType;
|
use crate::services::filter::FilterType;
|
||||||
use crate::services::persistence::rev_sqlite::{
|
use crate::services::persistence::rev_sqlite::{
|
||||||
SQLiteDatabaseRevisionSnapshotPersistence, SQLiteGridViewRevisionPersistence,
|
SQLiteDatabaseRevisionSnapshotPersistence, SQLiteGridViewRevisionPersistence,
|
||||||
};
|
};
|
||||||
use crate::services::view_editor::changed_notifier::*;
|
use database_model::{FieldRevision, FilterRevision, RowChangeset, RowRevision, SortRevision};
|
||||||
use crate::services::view_editor::trait_impl::GridViewRevisionMergeable;
|
|
||||||
use crate::services::view_editor::{DatabaseViewEditorDelegate, DatabaseViewRevisionEditor};
|
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
|
use flowy_revision::{RevisionManager, RevisionPersistence, RevisionPersistenceConfiguration};
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use grid_model::{FieldRevision, FilterRevision, RowChangeset, RowRevision, SortRevision};
|
|
||||||
use lib_infra::future::Fut;
|
use lib_infra::future::Fut;
|
||||||
use lib_infra::ref_map::RefCountHashMap;
|
use lib_infra::ref_map::RefCountHashMap;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
@ -23,7 +23,7 @@ use std::sync::Arc;
|
|||||||
use tokio::sync::{broadcast, RwLock};
|
use tokio::sync::{broadcast, RwLock};
|
||||||
|
|
||||||
pub struct DatabaseViewManager {
|
pub struct DatabaseViewManager {
|
||||||
view_id: String,
|
database_id: String,
|
||||||
user: Arc<dyn DatabaseUser>,
|
user: Arc<dyn DatabaseUser>,
|
||||||
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
view_editors: Arc<RwLock<RefCountHashMap<Arc<DatabaseViewRevisionEditor>>>>,
|
view_editors: Arc<RwLock<RefCountHashMap<Arc<DatabaseViewRevisionEditor>>>>,
|
||||||
@ -32,7 +32,7 @@ pub struct DatabaseViewManager {
|
|||||||
|
|
||||||
impl DatabaseViewManager {
|
impl DatabaseViewManager {
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
view_id: String,
|
database_id: String,
|
||||||
user: Arc<dyn DatabaseUser>,
|
user: Arc<dyn DatabaseUser>,
|
||||||
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
cell_data_cache: AtomicCellDataCache,
|
cell_data_cache: AtomicCellDataCache,
|
||||||
@ -41,7 +41,7 @@ impl DatabaseViewManager {
|
|||||||
let view_editors = Arc::new(RwLock::new(RefCountHashMap::default()));
|
let view_editors = Arc::new(RwLock::new(RefCountHashMap::default()));
|
||||||
listen_on_database_block_event(block_event_rx, view_editors.clone());
|
listen_on_database_block_event(block_event_rx, view_editors.clone());
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
view_id,
|
database_id,
|
||||||
user,
|
user,
|
||||||
delegate,
|
delegate,
|
||||||
cell_data_cache,
|
cell_data_cache,
|
||||||
@ -260,7 +260,7 @@ impl DatabaseViewManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_default_view_editor(&self) -> FlowyResult<Arc<DatabaseViewRevisionEditor>> {
|
async fn get_default_view_editor(&self) -> FlowyResult<Arc<DatabaseViewRevisionEditor>> {
|
||||||
self.get_view_editor(&self.view_id).await
|
self.get_view_editor(&self.database_id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn make_view_editor(&self, view_id: &str) -> FlowyResult<DatabaseViewRevisionEditor> {
|
async fn make_view_editor(&self, view_id: &str) -> FlowyResult<DatabaseViewRevisionEditor> {
|
@ -1,8 +1,8 @@
|
|||||||
mod changed_notifier;
|
|
||||||
mod editor;
|
mod editor;
|
||||||
mod editor_manager;
|
mod editor_manager;
|
||||||
|
mod notifier;
|
||||||
mod trait_impl;
|
mod trait_impl;
|
||||||
|
|
||||||
pub use changed_notifier::*;
|
|
||||||
pub use editor::*;
|
pub use editor::*;
|
||||||
pub use editor_manager::*;
|
pub use editor_manager::*;
|
||||||
|
pub use notifier::*;
|
@ -13,12 +13,13 @@ pub enum DatabaseViewChanged {
|
|||||||
ReorderSingleRowNotification(ReorderSingleRowResult),
|
ReorderSingleRowNotification(ReorderSingleRowResult),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type GridViewChangedNotifier = broadcast::Sender<DatabaseViewChanged>;
|
pub type DatabaseViewChangedNotifier = broadcast::Sender<DatabaseViewChanged>;
|
||||||
|
|
||||||
pub(crate) struct GridViewChangedReceiverRunner(
|
pub(crate) struct DatabaseViewChangedReceiverRunner(
|
||||||
pub(crate) Option<broadcast::Receiver<DatabaseViewChanged>>,
|
pub(crate) Option<broadcast::Receiver<DatabaseViewChanged>>,
|
||||||
);
|
);
|
||||||
impl GridViewChangedReceiverRunner {
|
|
||||||
|
impl DatabaseViewChangedReceiverRunner {
|
||||||
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");
|
||||||
let stream = stream! {
|
let stream = stream! {
|
@ -1,12 +1,16 @@
|
|||||||
use crate::entities::{DatabaseViewSettingPB, LayoutTypePB, ViewLayoutPB};
|
use crate::entities::{DatabaseViewSettingPB, LayoutTypePB, ViewLayoutPB};
|
||||||
|
use crate::services::database_view::{get_cells_for_field, DatabaseViewEditorDelegate};
|
||||||
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};
|
||||||
use crate::services::row::DatabaseBlockRowRevision;
|
use crate::services::row::DatabaseBlockRowRevision;
|
||||||
use crate::services::sort::{SortDelegate, SortType};
|
use crate::services::sort::{SortDelegate, SortType};
|
||||||
use crate::services::view_editor::{get_cells_for_field, DatabaseViewEditorDelegate};
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use flowy_client_sync::client_database::{GridViewRevisionChangeset, GridViewRevisionPad};
|
use database_model::{
|
||||||
|
FieldRevision, FieldTypeRevision, FilterRevision, GroupConfigurationRevision, RowRevision,
|
||||||
|
SortRevision,
|
||||||
|
};
|
||||||
|
use flowy_client_sync::client_database::{DatabaseViewRevisionPad, GridViewRevisionChangeset};
|
||||||
use flowy_client_sync::make_operations_from_revisions;
|
use flowy_client_sync::make_operations_from_revisions;
|
||||||
use flowy_error::{FlowyError, FlowyResult};
|
use flowy_error::{FlowyError, FlowyResult};
|
||||||
use flowy_revision::{
|
use flowy_revision::{
|
||||||
@ -14,10 +18,6 @@ use flowy_revision::{
|
|||||||
RevisionObjectSerializer,
|
RevisionObjectSerializer,
|
||||||
};
|
};
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use grid_model::{
|
|
||||||
FieldRevision, FieldTypeRevision, FilterRevision, GroupConfigurationRevision, RowRevision,
|
|
||||||
SortRevision,
|
|
||||||
};
|
|
||||||
use lib_infra::future::{to_fut, Fut, FutureResult};
|
use lib_infra::future::{to_fut, Fut, FutureResult};
|
||||||
use lib_ot::core::EmptyAttributes;
|
use lib_ot::core::EmptyAttributes;
|
||||||
use revision_model::Revision;
|
use revision_model::Revision;
|
||||||
@ -41,10 +41,13 @@ impl RevisionCloudService for GridViewRevisionCloudService {
|
|||||||
|
|
||||||
pub(crate) struct GridViewRevisionSerde();
|
pub(crate) struct GridViewRevisionSerde();
|
||||||
impl RevisionObjectDeserializer for GridViewRevisionSerde {
|
impl RevisionObjectDeserializer for GridViewRevisionSerde {
|
||||||
type Output = GridViewRevisionPad;
|
type Output = DatabaseViewRevisionPad;
|
||||||
|
|
||||||
fn deserialize_revisions(object_id: &str, revisions: Vec<Revision>) -> FlowyResult<Self::Output> {
|
fn deserialize_revisions(
|
||||||
let pad = GridViewRevisionPad::from_revisions(object_id, revisions)?;
|
_object_id: &str,
|
||||||
|
revisions: Vec<Revision>,
|
||||||
|
) -> FlowyResult<Self::Output> {
|
||||||
|
let pad = DatabaseViewRevisionPad::from_revisions(revisions)?;
|
||||||
Ok(pad)
|
Ok(pad)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +71,7 @@ impl RevisionMergeable for GridViewRevisionMergeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct GroupConfigurationReaderImpl {
|
pub(crate) struct GroupConfigurationReaderImpl {
|
||||||
pub(crate) pad: Arc<RwLock<GridViewRevisionPad>>,
|
pub(crate) pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
pub(crate) view_editor_delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
pub(crate) view_editor_delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +99,7 @@ impl GroupConfigurationReader for GroupConfigurationReaderImpl {
|
|||||||
pub(crate) struct GroupConfigurationWriterImpl {
|
pub(crate) struct GroupConfigurationWriterImpl {
|
||||||
pub(crate) user_id: String,
|
pub(crate) user_id: String,
|
||||||
pub(crate) rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
pub(crate) rev_manager: Arc<RevisionManager<Arc<ConnectionPool>>>,
|
||||||
pub(crate) view_pad: Arc<RwLock<GridViewRevisionPad>>,
|
pub(crate) view_pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GroupConfigurationWriter for GroupConfigurationWriterImpl {
|
impl GroupConfigurationWriter for GroupConfigurationWriterImpl {
|
||||||
@ -140,7 +143,7 @@ pub(crate) async fn apply_change(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_grid_setting(
|
pub fn make_grid_setting(
|
||||||
view_pad: &GridViewRevisionPad,
|
view_pad: &DatabaseViewRevisionPad,
|
||||||
field_revs: &[Arc<FieldRevision>],
|
field_revs: &[Arc<FieldRevision>],
|
||||||
) -> DatabaseViewSettingPB {
|
) -> DatabaseViewSettingPB {
|
||||||
let layout_type: LayoutTypePB = view_pad.layout.clone().into();
|
let layout_type: LayoutTypePB = view_pad.layout.clone().into();
|
||||||
@ -158,7 +161,7 @@ pub fn make_grid_setting(
|
|||||||
|
|
||||||
pub(crate) struct GridViewFilterDelegateImpl {
|
pub(crate) struct GridViewFilterDelegateImpl {
|
||||||
pub(crate) editor_delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
pub(crate) editor_delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
pub(crate) view_revision_pad: Arc<RwLock<GridViewRevisionPad>>,
|
pub(crate) view_revision_pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FilterDelegate for GridViewFilterDelegateImpl {
|
impl FilterDelegate for GridViewFilterDelegateImpl {
|
||||||
@ -198,7 +201,7 @@ impl FilterDelegate for GridViewFilterDelegateImpl {
|
|||||||
|
|
||||||
pub(crate) struct GridViewSortDelegateImpl {
|
pub(crate) struct GridViewSortDelegateImpl {
|
||||||
pub(crate) editor_delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
pub(crate) editor_delegate: Arc<dyn DatabaseViewEditorDelegate>,
|
||||||
pub(crate) view_revision_pad: Arc<RwLock<GridViewRevisionPad>>,
|
pub(crate) view_revision_pad: Arc<RwLock<DatabaseViewRevisionPad>>,
|
||||||
pub(crate) filter_controller: Arc<FilterController>,
|
pub(crate) filter_controller: Arc<FilterController>,
|
||||||
}
|
}
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::entities::{FieldPB, FieldType};
|
|||||||
|
|
||||||
use crate::services::field::{default_type_option_builder_from_type, TypeOptionBuilder};
|
use crate::services::field::{default_type_option_builder_from_type, TypeOptionBuilder};
|
||||||
|
|
||||||
use grid_model::FieldRevision;
|
use database_model::FieldRevision;
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
|
|
||||||
pub struct FieldBuilder {
|
pub struct FieldBuilder {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
use crate::services::database::DatabaseRevisionEditor;
|
||||||
use crate::services::field::{MultiSelectTypeOptionPB, SingleSelectTypeOptionPB};
|
use crate::services::field::{MultiSelectTypeOptionPB, SingleSelectTypeOptionPB};
|
||||||
use crate::services::grid_editor::DatabaseRevisionEditor;
|
use database_model::{TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use grid_model::{TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub async fn edit_field_type_option<T>(
|
pub async fn edit_field_type_option<T>(
|
||||||
@ -23,7 +23,7 @@ where
|
|||||||
action(&mut type_option);
|
action(&mut type_option);
|
||||||
let bytes = type_option.protobuf_bytes().to_vec();
|
let bytes = type_option.protobuf_bytes().to_vec();
|
||||||
editor
|
editor
|
||||||
.update_field_type_option(&editor.database_id, field_id, bytes, old_field_rev)
|
.update_field_type_option(field_id, bytes, old_field_rev)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::entities::FieldType;
|
use crate::entities::FieldType;
|
||||||
use crate::services::field::type_options::*;
|
use crate::services::field::type_options::*;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use grid_model::TypeOptionDataSerializer;
|
use database_model::TypeOptionDataSerializer;
|
||||||
|
|
||||||
pub trait TypeOptionBuilder {
|
pub trait TypeOptionBuilder {
|
||||||
/// Returns the type of the type-option data
|
/// Returns the type of the type-option data
|
||||||
|
@ -5,7 +5,7 @@ mod tests {
|
|||||||
use crate::services::field::type_options::checkbox_type_option::*;
|
use crate::services::field::type_options::checkbox_type_option::*;
|
||||||
use crate::services::field::FieldBuilder;
|
use crate::services::field::FieldBuilder;
|
||||||
|
|
||||||
use grid_model::FieldRevision;
|
use database_model::FieldRevision;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn checkout_box_description_test() {
|
fn checkout_box_description_test() {
|
||||||
|
@ -6,9 +6,9 @@ use crate::services::field::{
|
|||||||
TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter, TypeOptionTransform,
|
TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter, TypeOptionTransform,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
@ -7,7 +7,7 @@ mod tests {
|
|||||||
// use crate::services::field::{DateCellChangeset, DateCellData, DateFormat, DateTypeOptionPB, TimeFormat};
|
// use crate::services::field::{DateCellChangeset, DateCellData, DateFormat, DateTypeOptionPB, TimeFormat};
|
||||||
use chrono::format::strftime::StrftimeItems;
|
use chrono::format::strftime::StrftimeItems;
|
||||||
use chrono::{FixedOffset, NaiveDateTime};
|
use chrono::{FixedOffset, NaiveDateTime};
|
||||||
use grid_model::FieldRevision;
|
use database_model::FieldRevision;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -9,9 +9,9 @@ use crate::services::field::{
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use chrono::format::strftime::StrftimeItems;
|
use chrono::format::strftime::StrftimeItems;
|
||||||
use chrono::{NaiveDateTime, Timelike};
|
use chrono::{NaiveDateTime, Timelike};
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
use flowy_error::{ErrorCode, FlowyError, FlowyResult};
|
||||||
use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ mod tests {
|
|||||||
use crate::services::field::FieldBuilder;
|
use crate::services::field::FieldBuilder;
|
||||||
|
|
||||||
use crate::services::field::{strip_currency_symbol, NumberFormat, NumberTypeOptionPB};
|
use crate::services::field::{strip_currency_symbol, NumberFormat, NumberTypeOptionPB};
|
||||||
use grid_model::FieldRevision;
|
use database_model::FieldRevision;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
/// Testing when the input is not a number.
|
/// Testing when the input is not a number.
|
||||||
|
@ -7,10 +7,10 @@ use crate::services::field::{
|
|||||||
TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter, TypeOptionTransform,
|
TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter, TypeOptionTransform,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
@ -7,9 +7,9 @@ use crate::services::field::{
|
|||||||
TypeOptionBuilder, TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter,
|
TypeOptionBuilder, TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ use crate::services::field::{
|
|||||||
TypeOptionBuilder, TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter,
|
TypeOptionBuilder, TypeOptionCellData, TypeOptionCellDataCompare, TypeOptionCellDataFilter,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// Multiple select
|
// Multiple select
|
||||||
|
@ -11,9 +11,9 @@ use crate::services::field::{
|
|||||||
TypeOption, TypeOptionCellData, TypeOptionTransform,
|
TypeOption, TypeOptionCellData, TypeOptionTransform,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataSerializer};
|
||||||
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
|
||||||
use flowy_error::{internal_error, ErrorCode, FlowyResult};
|
use flowy_error::{internal_error, ErrorCode, FlowyResult};
|
||||||
use grid_model::{FieldRevision, TypeOptionDataSerializer};
|
|
||||||
use nanoid::nanoid;
|
use nanoid::nanoid;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ use crate::services::field::{
|
|||||||
SelectOptionCellChangeset, SelectOptionIds, SelectOptionPB, SelectTypeOptionSharedAction,
|
SelectOptionCellChangeset, SelectOptionIds, SelectOptionPB, SelectTypeOptionSharedAction,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
// Single select
|
// Single select
|
||||||
|
@ -5,7 +5,7 @@ use crate::services::field::{
|
|||||||
SelectTypeOptionSharedAction, SingleSelectTypeOptionPB, TypeOption, CHECK, UNCHECK,
|
SelectTypeOptionSharedAction, SingleSelectTypeOptionPB, TypeOption, CHECK, UNCHECK,
|
||||||
};
|
};
|
||||||
|
|
||||||
use grid_model::TypeOptionDataDeserializer;
|
use database_model::TypeOptionDataDeserializer;
|
||||||
|
|
||||||
/// Handles how to transform the cell data when switching between different field types
|
/// Handles how to transform the cell data when switching between different field types
|
||||||
pub(crate) struct SelectOptionTypeOptionTransformHelper();
|
pub(crate) struct SelectOptionTypeOptionTransformHelper();
|
||||||
|
@ -9,9 +9,9 @@ use crate::services::field::{
|
|||||||
TypeOptionCellDataCompare, TypeOptionCellDataFilter, TypeOptionTransform,
|
TypeOptionCellDataCompare, TypeOptionCellDataFilter, TypeOptionTransform,
|
||||||
};
|
};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
||||||
use flowy_derive::ProtoBuf;
|
use flowy_derive::ProtoBuf;
|
||||||
use flowy_error::{FlowyError, FlowyResult};
|
use flowy_error::{FlowyError, FlowyResult};
|
||||||
use grid_model::{FieldRevision, TypeOptionDataDeserializer, TypeOptionDataSerializer};
|
|
||||||
use protobuf::ProtobufError;
|
use protobuf::ProtobufError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
@ -5,8 +5,8 @@ use crate::services::cell::{
|
|||||||
|
|
||||||
use crate::services::filter::FromFilterString;
|
use crate::services::filter::FromFilterString;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
|
use database_model::FieldRevision;
|
||||||
use flowy_error::FlowyResult;
|
use flowy_error::FlowyResult;
|
||||||
use grid_model::FieldRevision;
|
|
||||||
use protobuf::ProtobufError;
|
use protobuf::ProtobufError;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user