mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-06 03:31:02 -06:00
[client] ResourceMkdirAction
This commit is contained in:
7
client/lib/libphylum/actions/deserializers.dart
Normal file
7
client/lib/libphylum/actions/deserializers.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/actions/resource_mkdir_action.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
|
||||
const actionDeserializers = <String, ApiActionDeserializer<PhylumAccount>>{
|
||||
ResourceMkdirAction.actionName: ResourceMkdirAction.fromMap,
|
||||
};
|
||||
69
client/lib/libphylum/actions/resource_mkdir_action.dart
Normal file
69
client/lib/libphylum/actions/resource_mkdir_action.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class ResourceMkdirAction extends ApiAction<PhylumAccount> with JsonApiAction {
|
||||
static const actionName = 'resourceMkdir';
|
||||
@override
|
||||
String get name => actionName;
|
||||
|
||||
@override
|
||||
String get method => 'POST';
|
||||
|
||||
@override
|
||||
String get endpoint => '/v1/resources/mkdir/$id';
|
||||
|
||||
@override
|
||||
dynamic get tag => 'resourceDetails';
|
||||
|
||||
final String id;
|
||||
final String parent;
|
||||
final String dirName;
|
||||
|
||||
ResourceMkdirAction._({
|
||||
required this.id,
|
||||
required this.parent,
|
||||
required this.dirName,
|
||||
});
|
||||
|
||||
ResourceMkdirAction({
|
||||
required String parent,
|
||||
required String dirName,
|
||||
}) : this._(id: (const Uuid()).v4(), parent: parent, dirName: dirName);
|
||||
|
||||
static ResourceMkdirAction fromMap(Map<String, dynamic> map, dynamic data) {
|
||||
return ResourceMkdirAction._(
|
||||
id: map['id'],
|
||||
parent: map['parent'],
|
||||
dirName: map['dirName'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String generateDescription(PhylumAccount account) {
|
||||
return "Creating Directory $dirName";
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, dynamic>? generateRequestBody() {
|
||||
return {
|
||||
'parent_id': parent,
|
||||
'name': dirName,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
FutureOr<void> applyOptimisticUpdate(PhylumAccount account) {}
|
||||
|
||||
@override
|
||||
FutureOr<void> revertOptimisticUpdate(PhylumAccount account) {}
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toMap() => {
|
||||
'id': id,
|
||||
'dirName': dirName,
|
||||
'parent': parent,
|
||||
};
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:offtheline/offtheline.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:phylum/app.dart';
|
||||
import 'package:phylum/libphylum/actions/deserializers.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/ui/login_page.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -22,6 +23,7 @@ void main() async {
|
||||
|
||||
await appDir.create();
|
||||
Hive.init(appDir.path);
|
||||
Hive.registerAdapter(ApiActionTypeAdapter(actionDeserializers));
|
||||
|
||||
final accountManager = await AccountManager.restore((id) async {
|
||||
final account = PhylumAccount(id: id);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_state_notifier/flutter_state_notifier.dart';
|
||||
import 'package:phylum/libphylum/actions/resource_mkdir_action.dart';
|
||||
import 'package:phylum/libphylum/phylum_account.dart';
|
||||
import 'package:phylum/ui/common/expandable_fab.dart';
|
||||
import 'package:phylum/ui/folder/folder_contents_view.dart';
|
||||
import 'package:phylum/util/dialogs.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'folder_navigator_stack.dart';
|
||||
@@ -37,7 +40,12 @@ class FolderScaffold extends StatelessWidget {
|
||||
children: [
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.folder),
|
||||
onPressed: () {},
|
||||
onPressed: () async {
|
||||
final account = context.read<PhylumAccount>();
|
||||
final dirName = await showInputDialog(context, title: 'Create New Folder', labelText: 'Folder Name');
|
||||
if (dirName == null || dirName == "") return;
|
||||
account.addAction(ResourceMkdirAction(parent: folderId, dirName: dirName));
|
||||
},
|
||||
),
|
||||
ActionButton(
|
||||
icon: const Icon(Icons.insert_drive_file),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
Future showProgressDialog(
|
||||
BuildContext context, {
|
||||
@@ -73,3 +74,65 @@ Future<bool?> showAlertDialog(
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> showInputDialog(
|
||||
BuildContext context, {
|
||||
String? title,
|
||||
String? labelText,
|
||||
String? hintText,
|
||||
String? preset,
|
||||
TextCapitalization capitalization = TextCapitalization.sentences,
|
||||
int minLines = 1,
|
||||
int maxLines = 1,
|
||||
bool autocorrect = false,
|
||||
TextInputType keyboardType = TextInputType.text,
|
||||
bool Function(String)? validate,
|
||||
List<TextInputFormatter>? formatters,
|
||||
}) {
|
||||
TextEditingController controller = TextEditingController()..text = (preset ?? '');
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => StatefulBuilder(builder: (context, setState) {
|
||||
return AlertDialog(
|
||||
title: (title == null) ? null : Text(title),
|
||||
content: SizedBox(
|
||||
width: 360,
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: labelText,
|
||||
hintText: hintText,
|
||||
),
|
||||
autofocus: true,
|
||||
controller: controller,
|
||||
textCapitalization: capitalization,
|
||||
autocorrect: autocorrect,
|
||||
minLines: minLines,
|
||||
maxLines: maxLines,
|
||||
keyboardType: keyboardType,
|
||||
inputFormatters: formatters,
|
||||
onChanged: (value) {
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('CANCEL'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(null);
|
||||
},
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: (validate == null || validate(controller.text))
|
||||
? () {
|
||||
Navigator.of(context).pop(controller.text);
|
||||
}
|
||||
: null,
|
||||
child: const Text('OK'),
|
||||
)
|
||||
],
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -641,6 +641,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.10.0"
|
||||
sprintf:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: sprintf
|
||||
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "7.0.0"
|
||||
sqlite3:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -745,6 +753,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
uuid:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: uuid
|
||||
sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.4.2"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -9,6 +9,8 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
drift: ^2.19.1+1
|
||||
drift_flutter: ^0.1.0
|
||||
flutter_state_notifier:
|
||||
go_router:
|
||||
hive:
|
||||
@@ -20,8 +22,7 @@ dependencies:
|
||||
path_provider:
|
||||
provider:
|
||||
uri:
|
||||
drift: ^2.19.1+1
|
||||
drift_flutter: ^0.1.0
|
||||
uuid:
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user