mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-05 19:21:23 -06:00
[client] Use name as id for publinks
This commit is contained in:
@@ -18,7 +18,7 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction {
|
||||
|
||||
@override
|
||||
Map<String, dynamic>? get requestBody => {
|
||||
'name': publinkName,
|
||||
'id': publinkId,
|
||||
if (password.isNotEmpty) 'password': password,
|
||||
if (expires != null) 'expires': expires!.toIso8601String(),
|
||||
if (accessLimit != 0) 'access_limit': accessLimit,
|
||||
@@ -31,20 +31,20 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction {
|
||||
List<LocalChange> get localChanges => [];
|
||||
|
||||
@override
|
||||
String get description => 'Creating Public Share: $publinkName';
|
||||
String get description => 'Creating Public Share: $publinkId';
|
||||
|
||||
@override
|
||||
Map<String, dynamic> get props => {
|
||||
'resourceId': resourceId,
|
||||
'publinkName': _publinkName,
|
||||
'publinkId': _publinkId,
|
||||
'password': password,
|
||||
'expires': expires?.millisecondsSinceEpoch,
|
||||
'accessLimit': accessLimit,
|
||||
'timestamp': timestamp.millisecondsSinceEpoch,
|
||||
};
|
||||
|
||||
String _publinkName;
|
||||
String get publinkName => _publinkName;
|
||||
String _publinkId;
|
||||
String get publinkId => _publinkId;
|
||||
final String password;
|
||||
final DateTime? expires;
|
||||
final int accessLimit;
|
||||
@@ -52,19 +52,19 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction {
|
||||
|
||||
ResourcePublinkCreateAction({
|
||||
required super.resourceId,
|
||||
required String publinkName,
|
||||
required String publinkId,
|
||||
required this.password,
|
||||
required DateTime? expires,
|
||||
required this.accessLimit,
|
||||
DateTime? timestamp,
|
||||
}) : _publinkName = publinkName,
|
||||
}) : _publinkId = publinkId,
|
||||
expires = expires?.toUtc(),
|
||||
timestamp = timestamp ?? DateTime.now();
|
||||
|
||||
factory ResourcePublinkCreateAction.fromMap(Map<String, dynamic> map) {
|
||||
return ResourcePublinkCreateAction(
|
||||
resourceId: map['resourceId'],
|
||||
publinkName: map['publinkName'],
|
||||
publinkId: map['publinkId'],
|
||||
password: map['password'],
|
||||
expires: map['expires'] == null ? null : DateTime.fromMillisecondsSinceEpoch(map['expires']),
|
||||
accessLimit: map['accessLimit'],
|
||||
@@ -78,10 +78,10 @@ class ResourcePublinkCreateAction extends ResourceAction with JsonApiAction {
|
||||
(action is ResourceCreateAction || action is ResourcePublinkCreateAction) &&
|
||||
action.resourceId == resourceId;
|
||||
|
||||
Future<void> updatePublinkName(String publinkName) {
|
||||
Future<void> updatePublinkId(String publinkId) {
|
||||
return account.actionQueue.updateActions(
|
||||
(action) => action == this,
|
||||
(action) => (action as ResourcePublinkCreateAction)._publinkName = publinkName,
|
||||
(action) => (action as ResourcePublinkCreateAction)._publinkId = publinkId,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ import 'package:flutter/services.dart';
|
||||
import 'package:phylum/util/time.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
final TextInputFormatter validNameFormatter = FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9_\-]'));
|
||||
final TextInputFormatter validIdFormatter = FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z0-9_\-]'));
|
||||
|
||||
class PublinkInfo with ChangeNotifier {
|
||||
String _name = '';
|
||||
String get name => _name.trim();
|
||||
set name(String value) {
|
||||
_name = value;
|
||||
String _id = '';
|
||||
String get id => _id.trim();
|
||||
set id(String value) {
|
||||
_id = value;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class CreatePublinkView extends StatefulWidget {
|
||||
child: Text('Cancel'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: context.select<PublinkInfo, bool>((info) => info.name.isNotEmpty)
|
||||
onPressed: context.select<PublinkInfo, bool>((info) => info.id.isNotEmpty)
|
||||
? () => Navigator.of(context).pop(context.read<PublinkInfo>())
|
||||
: null,
|
||||
child: Text('OK'),
|
||||
@@ -98,12 +98,12 @@ class _CreatePublinkViewState extends State<CreatePublinkView> {
|
||||
ListTile(
|
||||
leading: const Icon(Icons.public),
|
||||
title: TextField(
|
||||
decoration: InputDecoration(label: Text('Name')),
|
||||
inputFormatters: [validNameFormatter],
|
||||
decoration: InputDecoration(label: Text('ID')),
|
||||
inputFormatters: [validIdFormatter],
|
||||
enableSuggestions: false,
|
||||
autocorrect: false,
|
||||
autofocus: true,
|
||||
onChanged: (value) => context.read<PublinkInfo>().name = value,
|
||||
onChanged: (value) => context.read<PublinkInfo>().id = value,
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
|
||||
@@ -119,7 +119,7 @@ class ResourceInfoView extends StatelessWidget {
|
||||
if (info == null) return;
|
||||
account.addAction(ResourcePublinkCreateAction(
|
||||
resourceId: resource.id,
|
||||
publinkName: info.name,
|
||||
publinkId: info.id,
|
||||
password: info.password,
|
||||
expires: info.expiration,
|
||||
accessLimit: info.accessLimit,
|
||||
|
||||
@@ -100,14 +100,13 @@ class ActionView extends StatelessWidget {
|
||||
tooltip: 'Rename',
|
||||
onPressed: () async {
|
||||
if (action is! ResourcePublinkCreateAction) return;
|
||||
final preset = action.publinkName;
|
||||
final name = await showInputDialog(context,
|
||||
title: 'Edit Name',
|
||||
preset: preset,
|
||||
title: 'Edit ID',
|
||||
preset: action.publinkId,
|
||||
capitalization: TextCapitalization.words,
|
||||
validate: (name) => name.trim().isNotEmpty);
|
||||
if (name == null || !context.mounted) return;
|
||||
action.updatePublinkName(name);
|
||||
action.updatePublinkId(name);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
|
||||
Reference in New Issue
Block a user