solved most pr comments and a bug
This commit is contained in:
parent
9803b06af1
commit
d8c72a5d28
lib/view/pages
@ -65,9 +65,7 @@ class SortOptions {
|
||||
)
|
||||
};
|
||||
|
||||
static BetterSortOption getOption(SortOption option) {
|
||||
return options[option]!;
|
||||
}
|
||||
static BetterSortOption getOption(SortOption option) => options[option]!;
|
||||
}
|
||||
|
||||
class _FilesState extends State<Files> {
|
||||
@ -99,7 +97,7 @@ class _FilesState extends State<Files> {
|
||||
);
|
||||
}
|
||||
|
||||
void mediaUpload(List<String>? paths) async {
|
||||
Future<void> mediaUpload(List<String>? paths) async {
|
||||
if(paths == null) return;
|
||||
|
||||
pushScreen(
|
||||
|
@ -43,21 +43,15 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
super.initState();
|
||||
|
||||
_uploadableFiles = widget.filePaths.map((filePath) {
|
||||
String fileName = filePath.split(Platform.pathSeparator).last;
|
||||
var fileName = filePath.split(Platform.pathSeparator).last;
|
||||
return UploadableFile(filePath, fileName);
|
||||
}).toList();
|
||||
|
||||
/*_uploadableFiles.addAll(widget.filePaths.map((filePath) {
|
||||
String fileName = filePath.split(Platform.pathSeparator).last;
|
||||
return UploadableFile(filePath, fileName);
|
||||
}));*/
|
||||
}
|
||||
|
||||
void showHttpErrorCode(int httpErrorCode){
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
builder: (BuildContext context) => AlertDialog(
|
||||
title: const Text('Ein Fehler ist aufgetreten'),
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
content: Text('Error code: $httpErrorCode'),
|
||||
@ -67,12 +61,11 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
child: const Text('Schließen', textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void uploadFiles({bool override = false}) async {
|
||||
Future<void> uploadFiles({bool override = false}) async {
|
||||
setState(() {
|
||||
_isUploading = true;
|
||||
_infoText = 'Vorbereiten';
|
||||
@ -81,41 +74,33 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
}
|
||||
});
|
||||
|
||||
WebDavClient webdavClient = await WebdavApi.webdav;
|
||||
var webdavClient = await WebdavApi.webdav;
|
||||
|
||||
if (!override) {
|
||||
List<WebDavResponse> result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses;
|
||||
List<UploadableFile> conflictingFiles = _uploadableFiles.where((file) {
|
||||
String fileName = file.fileName;
|
||||
if (result.any((element) => Uri.decodeComponent(element.href!).endsWith('/$fileName'))) {
|
||||
// konflikt
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
var result = (await webdavClient.propfind(PathUri.parse(widget.remotePath))).responses;
|
||||
var conflictingFiles = _uploadableFiles.where((file) {
|
||||
var fileName = file.fileName;
|
||||
return result.any((element) => Uri.decodeComponent(element.href!).endsWith('/$fileName'));
|
||||
}).toList();
|
||||
|
||||
if(conflictingFiles.isNotEmpty) {
|
||||
bool replaceFiles = await showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
builder: (context) => AlertDialog(
|
||||
contentPadding: const EdgeInsets.all(10),
|
||||
title: const Text('Konflikt', textAlign: TextAlign.center),
|
||||
content: conflictingFiles.length == 1 ?
|
||||
Text(
|
||||
'Eine Datei mit dem Namen "${conflictingFiles.map((e) => e.fileName).first}" existiert bereits.\n'
|
||||
'(Datei ${_uploadableFiles.indexOf(conflictingFiles.first)+1})',
|
||||
'Eine Datei mit dem Namen "${conflictingFiles.map((e) => e.fileName).first}" existiert bereits.',
|
||||
textAlign: TextAlign.left,
|
||||
) :
|
||||
SingleChildScrollView(
|
||||
child: Text(
|
||||
'${conflictingFiles.length} Dateien mit den Namen: ${conflictingFiles.map((e) => '\n${e.fileName}').join(', ')}\n existieren bereits.\n'
|
||||
'(Dateien ${conflictingFiles.map((e) => _uploadableFiles.indexOf(e)+1).join(', ')})',
|
||||
'${conflictingFiles.length} Dateien mit folgenden Namen existieren bereits: \n${conflictingFiles.map((e) => '\n - ${e.fileName}').join('')}',
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
),
|
||||
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
@ -127,55 +112,52 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return ConfirmDialog(
|
||||
title: 'Bestätigen',
|
||||
content: 'Bist du sicher, dass du ${conflictingFiles.map((e) => e.fileName).toList()} überschreiben möchtest?',
|
||||
onConfirm: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
confirmButton: 'Ja',
|
||||
cancelButton: 'Nein',
|
||||
);
|
||||
}
|
||||
builder: (context) => ConfirmDialog(
|
||||
title: 'Bestätigen?',
|
||||
content: 'Bist du sicher, dass du ${conflictingFiles.length} Dateien überschreiben möchtest?',
|
||||
onConfirm: () {
|
||||
Navigator.pop(context, true);
|
||||
},
|
||||
confirmButton: 'Ja',
|
||||
cancelButton: 'Nein',
|
||||
),
|
||||
);
|
||||
|
||||
},
|
||||
child: const Text('Überschreiben', textAlign: TextAlign.center),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
if(!replaceFiles) {
|
||||
for (var element in conflictingFiles) {
|
||||
element.isConflicting = true;
|
||||
}
|
||||
setState(() {
|
||||
_isUploading = false;
|
||||
_overallProgressValue = 0.0;
|
||||
_infoText = '';
|
||||
for (var element in conflictingFiles) {
|
||||
element.isConflicting = true;
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> uploadetFilePaths = [];
|
||||
var uploadetFilePaths = <String>[];
|
||||
for (var file in _uploadableFiles) {
|
||||
String fileName = file.fileName;
|
||||
String filePath = file.filePath;
|
||||
var fileName = file.fileName;
|
||||
var filePath = file.filePath;
|
||||
|
||||
if(widget.uniqueNames) fileName = '${fileName.split('.').first}-${const Uuid().v4()}.${fileName.split('.').last}';
|
||||
|
||||
String fullRemotePath = '${widget.remotePath}/$fileName';
|
||||
var fullRemotePath = '${widget.remotePath}/$fileName';
|
||||
|
||||
setState(() {
|
||||
_infoText = '${_uploadableFiles.indexOf(file) + 1}/${_uploadableFiles.length}';
|
||||
});
|
||||
|
||||
HttpClientResponse uploadTask = await webdavClient.putFile(
|
||||
var uploadTask = await webdavClient.putFile(
|
||||
File(filePath),
|
||||
FileStat.statSync(filePath),
|
||||
PathUri.parse(fullRemotePath),
|
||||
@ -211,8 +193,7 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Dateien hochladen'),
|
||||
automaticallyImplyLeading: false,
|
||||
@ -318,13 +299,25 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
onPressed: () => uploadFiles(override: widget.uniqueNames),
|
||||
child: const Text('Hochladen'),
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(value: _overallProgressValue),
|
||||
Center(child: Text(_infoText)),
|
||||
],
|
||||
child: Visibility(
|
||||
visible: _infoText.length < 5,
|
||||
replacement: Row(
|
||||
children: [
|
||||
Text(_infoText),
|
||||
const SizedBox(width: 15),
|
||||
CircularProgressIndicator(value: _overallProgressValue),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
CircularProgressIndicator(value: _overallProgressValue),
|
||||
Center(child: Text(_infoText)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -333,5 +326,4 @@ class _FilesUploadDialogState extends State<FilesUploadDialog> {
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
|
||||
void share(String shareFolder, List<String> filePaths) {
|
||||
for (var element in filePaths) {
|
||||
String fileName = element.split(Platform.pathSeparator).last;
|
||||
var fileName = element.split(Platform.pathSeparator).last;
|
||||
FileSharingApi().share(FileSharingApiParams(
|
||||
shareType: 10,
|
||||
shareWith: widget.sendToToken,
|
||||
@ -44,10 +44,10 @@ class _ChatTextfieldState extends State<ChatTextfield> {
|
||||
}
|
||||
}
|
||||
|
||||
void mediaUpload(List<String>? paths) async {
|
||||
Future<void> mediaUpload(List<String>? paths) async {
|
||||
if (paths == null) return;
|
||||
|
||||
String shareFolder = 'MarianumMobile';
|
||||
var shareFolder = 'MarianumMobile';
|
||||
WebdavApi.webdav.then((webdav) {
|
||||
webdav.mkcol(PathUri.parse('/$shareFolder'));
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user