-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
653 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:logging/logging.dart'; | ||
import '../api/token.dart'; | ||
import '../api/user.dart'; | ||
import '../globals.dart'; | ||
import '../main.dart'; | ||
|
||
final _log = Logger("SessionCard"); | ||
|
||
Future<void> _deleteSession(int id, String errmsg) async { | ||
try { | ||
(await api.deleteTokenById(id)).unwrap(); | ||
listener.tryEmit("delete_session", id); | ||
} catch (e) { | ||
_log.severe("Failed to delete session $id: $e"); | ||
final snack = SnackBar(content: Text("$errmsg$e")); | ||
rootScaffoldMessengerKey.currentState?.showSnackBar(snack); | ||
} | ||
} | ||
|
||
class SessionCard extends StatelessWidget { | ||
const SessionCard(this.token, {this.user, super.key}); | ||
final BUser? user; | ||
final TokenWithoutToken token; | ||
String get device { | ||
var s = ""; | ||
if (token.device != null) { | ||
s = token.device!; | ||
} | ||
var c = ""; | ||
if (token.client != null) { | ||
c = token.client!; | ||
} | ||
if (token.clientPlatform != null) { | ||
if (c.isNotEmpty) { | ||
c += " ${token.clientPlatform!}"; | ||
} | ||
} | ||
if (token.clientVersion != null) { | ||
if (c.isNotEmpty) { | ||
c += " ${token.clientVersion!}"; | ||
} | ||
} | ||
if (s.isEmpty) { | ||
s = c; | ||
} else if (c.isNotEmpty) { | ||
s = "$s($c)"; | ||
} | ||
return s; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final i18n = AppLocalizations.of(context)!; | ||
final expiredTime = | ||
DateFormat.yMd(MainApp.of(context).lang.toLocale().toString()) | ||
.add_jms() | ||
.format(token.expired); | ||
final lastUsed = | ||
DateFormat.yMd(MainApp.of(context).lang.toLocale().toString()) | ||
.add_jms() | ||
.format(token.lastUsed); | ||
return Card.outlined( | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(horizontal: 16), | ||
child: Row(children: [ | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: [ | ||
Text("${i18n.sessionId}${i18n.colon}${token.id}"), | ||
Text("${i18n.expireTime}${i18n.colon}$expiredTime"), | ||
Text("${i18n.lastUsedTime}${i18n.colon}$lastUsed"), | ||
device.isEmpty | ||
? Container() | ||
: Text("${i18n.device}${i18n.colon}$device"), | ||
user != null | ||
? Text("${i18n.username}${i18n.colon}${user!.username}") | ||
: Container(), | ||
], | ||
)), | ||
IconButton( | ||
onPressed: token.id != auth.token?.id | ||
? () => showDialog( | ||
context: context, | ||
builder: (context) { | ||
return AlertDialog( | ||
title: Text(i18n.deleteSession), | ||
content: Text(user != null | ||
? i18n.deleteSessionForUserConfirm( | ||
user!.username) | ||
: i18n.deleteSessionConfirm), | ||
actions: [ | ||
TextButton( | ||
onPressed: () { | ||
_deleteSession( | ||
token.id, i18n.failedDeleteSession); | ||
context.pop(); | ||
}, | ||
child: Text(i18n.yes)), | ||
TextButton( | ||
onPressed: () { | ||
context.pop(); | ||
}, | ||
child: Text(i18n.no)), | ||
]); | ||
}) | ||
: null, | ||
tooltip: i18n.delete, | ||
icon: const Icon(Icons.delete)) | ||
]))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.