mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-05-04 11:19:55 -05:00
[client] Allow renaming publinks on conflict
This commit is contained in:
@@ -36,14 +36,15 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction {
|
||||
@override
|
||||
Map<String, dynamic> get props => {
|
||||
'resourceId': resourceId,
|
||||
'publinkName': resourceId,
|
||||
'publinkName': _publinkName,
|
||||
'password': password,
|
||||
'expires': expires?.millisecondsSinceEpoch,
|
||||
'accessLimit': accessLimit,
|
||||
'timestamp': timestamp.millisecondsSinceEpoch,
|
||||
};
|
||||
|
||||
final String publinkName;
|
||||
String _publinkName;
|
||||
String get publinkName => _publinkName;
|
||||
final String password;
|
||||
final DateTime? expires;
|
||||
final int accessLimit;
|
||||
@@ -51,12 +52,13 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction {
|
||||
|
||||
ResourcePublinkCreateAction({
|
||||
required super.resourceId,
|
||||
required this.publinkName,
|
||||
required String publinkName,
|
||||
required this.password,
|
||||
required DateTime? expires,
|
||||
required this.accessLimit,
|
||||
DateTime? timestamp,
|
||||
}) : expires = expires?.toUtc(),
|
||||
}) : _publinkName = publinkName,
|
||||
expires = expires?.toUtc(),
|
||||
timestamp = timestamp ?? DateTime.now();
|
||||
|
||||
factory ResourcePublinkCreateAction.fromMap(Map<String, dynamic> map) {
|
||||
@@ -75,4 +77,11 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction {
|
||||
action is ResourceAction &&
|
||||
(action is ResourceCreateAction || action is ResourcePublinkCreateAction) &&
|
||||
action.resourceId == resourceId;
|
||||
|
||||
Future<void> updatePublinkName(String publinkName) {
|
||||
return account.actionQueue.updateActions(
|
||||
(action) => action == this,
|
||||
(action) => (action as ResourcePublinkCreateAction)._publinkName = publinkName,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:offtheline/offtheline.dart';
|
||||
import 'package:phylum/libphylum/actions/action_resource_bind.dart';
|
||||
import 'package:phylum/libphylum/actions/action_resource_publink_create.dart';
|
||||
import 'package:phylum/libphylum/name_conflict.dart';
|
||||
import 'package:phylum/libphylum/phylum_api_types.dart';
|
||||
import 'package:phylum/libphylum/responses/responses.dart';
|
||||
@@ -48,15 +49,18 @@ class ActionView extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget buildErrorInfoTile(BuildContext context, PhylumAction action, ApiResult error) {
|
||||
final showRenameOptions = error is PhylumApiErrorResponse &&
|
||||
final showResourceRenameAction = error is PhylumApiErrorResponse &&
|
||||
(error.code == "resource_name_conflict" || error.code == "resource_name_invalid");
|
||||
final showResourceOverwriteAction = error is PhylumApiErrorResponse && (error.code == "resource_name_conflict");
|
||||
final showResourceAutoRenameAction = error is PhylumApiErrorResponse && (error.code == "resource_name_conflict");
|
||||
final showPublinkRenameAction = error is PhylumApiErrorResponse && (error.code == "publink_name_conflict");
|
||||
return ListTile(
|
||||
title: Text(action.description, overflow: TextOverflow.fade),
|
||||
subtitle: Text(error.description),
|
||||
subtitle: Text('Error: ${error.description}'),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (showRenameOptions)
|
||||
if (showResourceOverwriteAction)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.warning),
|
||||
tooltip: 'Overwrite',
|
||||
@@ -65,7 +69,7 @@ class ActionView extends StatelessWidget {
|
||||
action.updateConflictResolution(nameConflictOverwrite);
|
||||
},
|
||||
),
|
||||
if (showRenameOptions)
|
||||
if (showResourceAutoRenameAction)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.healing),
|
||||
tooltip: 'Auto Rename',
|
||||
@@ -74,7 +78,7 @@ class ActionView extends StatelessWidget {
|
||||
action.updateConflictResolution(nameConflictRename);
|
||||
},
|
||||
),
|
||||
if (showRenameOptions)
|
||||
if (showResourceRenameAction)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
tooltip: 'Rename',
|
||||
@@ -90,6 +94,22 @@ class ActionView extends StatelessWidget {
|
||||
action.updateResourceName(name);
|
||||
},
|
||||
),
|
||||
if (showPublinkRenameAction)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
tooltip: 'Rename',
|
||||
onPressed: () async {
|
||||
if (action is! ResourcePublinkCreateAction) return;
|
||||
final preset = action.publinkName;
|
||||
final name = await showInputDialog(context,
|
||||
title: 'Edit Name',
|
||||
preset: preset,
|
||||
capitalization: TextCapitalization.words,
|
||||
validate: (name) => name.trim().isNotEmpty);
|
||||
if (name == null || !context.mounted) return;
|
||||
action.updatePublinkName(name);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
tooltip: 'Retry',
|
||||
|
||||
+2
-2
@@ -604,8 +604,8 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "."
|
||||
ref: "5e1be5e344cbe1c6a4ef242c25a6c9afa8f042f0"
|
||||
resolved-ref: "5e1be5e344cbe1c6a4ef242c25a6c9afa8f042f0"
|
||||
ref: "24aa194b7ff0b475e2e77240813947aad1f112e5"
|
||||
resolved-ref: "24aa194b7ff0b475e2e77240813947aad1f112e5"
|
||||
url: "https://codeberg.org/shroff/offtheline.git"
|
||||
source: git
|
||||
version: "0.16.0"
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ dependencies:
|
||||
offtheline:
|
||||
git:
|
||||
url: https://codeberg.org/shroff/offtheline.git
|
||||
ref: 5e1be5e344cbe1c6a4ef242c25a6c9afa8f042f0
|
||||
ref: 24aa194b7ff0b475e2e77240813947aad1f112e5
|
||||
open_file:
|
||||
package_info_plus:
|
||||
path:
|
||||
@@ -56,4 +56,4 @@ flutter:
|
||||
uses-material-design: true
|
||||
|
||||
assets:
|
||||
- assets/images/logo.png
|
||||
- assets/images/logo.png
|
||||
Reference in New Issue
Block a user