|
@@ -1,127 +1,12 @@
|
|
|
import 'package:flowy_infra/notifier.dart';
|
|
|
-import 'package:flowy_sdk/dispatch/dispatch.dart';
|
|
|
import 'package:flowy_sdk/protobuf/flowy-error/errors.pb.dart';
|
|
|
-import 'package:flowy_sdk/protobuf/flowy-grid/checkbox_type_option.pb.dart';
|
|
|
-import 'package:flowy_sdk/protobuf/flowy-grid/date_type_option.pb.dart';
|
|
|
import 'package:flowy_sdk/protobuf/flowy-grid/field_entities.pb.dart';
|
|
|
import 'package:app_flowy/plugins/grid/application/field/field_service.dart';
|
|
|
import 'package:dartz/dartz.dart';
|
|
|
-import 'package:flowy_sdk/protobuf/flowy-grid/number_type_option.pb.dart';
|
|
|
-import 'package:flowy_sdk/protobuf/flowy-grid/single_select_type_option.pb.dart';
|
|
|
-import 'package:flowy_sdk/protobuf/flowy-grid/text_type_option.pb.dart';
|
|
|
-import 'package:flowy_sdk/protobuf/flowy-grid/url_type_option.pb.dart';
|
|
|
import 'package:protobuf/protobuf.dart';
|
|
|
import 'package:flowy_sdk/log.dart';
|
|
|
|
|
|
-abstract class TypeOptionDataParser<T> {
|
|
|
- T fromBuffer(List<int> buffer);
|
|
|
-}
|
|
|
-
|
|
|
-typedef NumberTypeOptionContext = TypeOptionContext<NumberTypeOption>;
|
|
|
-typedef RichTextTypeOptionContext = TypeOptionContext<RichTextTypeOption>;
|
|
|
-typedef CheckboxTypeOptionContext = TypeOptionContext<CheckboxTypeOption>;
|
|
|
-typedef URLTypeOptionContext = TypeOptionContext<URLTypeOption>;
|
|
|
-typedef DateTypeOptionContext = TypeOptionContext<DateTypeOption>;
|
|
|
-
|
|
|
-typedef SingleSelectTypeOptionContext
|
|
|
- = TypeOptionContext<SingleSelectTypeOptionPB>;
|
|
|
-
|
|
|
-class TypeOptionContext<T extends GeneratedMessage> {
|
|
|
- T? _typeOptionObject;
|
|
|
- final TypeOptionDataParser<T> dataParser;
|
|
|
- final TypeOptionDataController _dataController;
|
|
|
-
|
|
|
- TypeOptionContext({
|
|
|
- required this.dataParser,
|
|
|
- required TypeOptionDataController dataController,
|
|
|
- }) : _dataController = dataController;
|
|
|
-
|
|
|
- String get gridId => _dataController.gridId;
|
|
|
-
|
|
|
- Future<void> loadTypeOptionData({
|
|
|
- required void Function(T) onCompleted,
|
|
|
- required void Function(FlowyError) onError,
|
|
|
- }) async {
|
|
|
- await _dataController.loadTypeOptionData().then((result) {
|
|
|
- result.fold((l) => null, (err) => onError(err));
|
|
|
- });
|
|
|
-
|
|
|
- onCompleted(typeOption);
|
|
|
- }
|
|
|
-
|
|
|
- T get typeOption {
|
|
|
- if (_typeOptionObject != null) {
|
|
|
- return _typeOptionObject!;
|
|
|
- }
|
|
|
-
|
|
|
- final T object = _dataController.getTypeOption(dataParser);
|
|
|
- _typeOptionObject = object;
|
|
|
- return object;
|
|
|
- }
|
|
|
-
|
|
|
- set typeOption(T typeOption) {
|
|
|
- _dataController.typeOptionData = typeOption.writeToBuffer();
|
|
|
- _typeOptionObject = typeOption;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-abstract class TypeOptionFieldDelegate {
|
|
|
- void onFieldChanged(void Function(String) callback);
|
|
|
- void dispose();
|
|
|
-}
|
|
|
-
|
|
|
-abstract class IFieldTypeOptionLoader {
|
|
|
- String get gridId;
|
|
|
- Future<Either<FieldTypeOptionDataPB, FlowyError>> load();
|
|
|
-
|
|
|
- Future<Either<FieldTypeOptionDataPB, FlowyError>> switchToField(
|
|
|
- String fieldId, FieldType fieldType) {
|
|
|
- final payload = EditFieldPayloadPB.create()
|
|
|
- ..gridId = gridId
|
|
|
- ..fieldId = fieldId
|
|
|
- ..fieldType = fieldType;
|
|
|
-
|
|
|
- return GridEventSwitchToField(payload).send();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class NewFieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
|
|
- @override
|
|
|
- final String gridId;
|
|
|
- NewFieldTypeOptionLoader({
|
|
|
- required this.gridId,
|
|
|
- });
|
|
|
-
|
|
|
- @override
|
|
|
- Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
|
|
|
- final payload = CreateFieldPayloadPB.create()
|
|
|
- ..gridId = gridId
|
|
|
- ..fieldType = FieldType.RichText;
|
|
|
-
|
|
|
- return GridEventCreateFieldTypeOption(payload).send();
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-class FieldTypeOptionLoader extends IFieldTypeOptionLoader {
|
|
|
- @override
|
|
|
- final String gridId;
|
|
|
- final GridFieldPB field;
|
|
|
-
|
|
|
- FieldTypeOptionLoader({
|
|
|
- required this.gridId,
|
|
|
- required this.field,
|
|
|
- });
|
|
|
-
|
|
|
- @override
|
|
|
- Future<Either<FieldTypeOptionDataPB, FlowyError>> load() {
|
|
|
- final payload = GridFieldTypeOptionIdPB.create()
|
|
|
- ..gridId = gridId
|
|
|
- ..fieldId = field.id
|
|
|
- ..fieldType = field.fieldType;
|
|
|
-
|
|
|
- return GridEventGetFieldTypeOption(payload).send();
|
|
|
- }
|
|
|
-}
|
|
|
+import 'type_option_context.dart';
|
|
|
|
|
|
class TypeOptionDataController {
|
|
|
final String gridId;
|