8fffafde47
Translations are provided in *.arb* format. Some keys have descriptions (indicated by leading @-symbol). Descriptions should not be copied into the translation itself. Currently only English is supported (app_en.arb), but German is planned. Apparently weblate merged .arb support at some time, so it would be nice to enable community translations at some point.
112 lines
3.4 KiB
Dart
112 lines
3.4 KiB
Dart
import 'dart:math';
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:outbag_app/backend/permissions.dart';
|
|
import 'package:outbag_app/backend/request.dart';
|
|
import 'package:outbag_app/backend/room.dart';
|
|
import 'package:outbag_app/backend/user.dart';
|
|
import 'package:outbag_app/tools/fetch_wrapper.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class EditRoomPermissionSetPage extends StatefulWidget {
|
|
final String server;
|
|
final String tag;
|
|
|
|
const EditRoomPermissionSetPage(this.server, this.tag, {super.key});
|
|
|
|
@override
|
|
State<StatefulWidget> createState() => _EditRoomPermissionSetPageState();
|
|
}
|
|
|
|
class _EditRoomPermissionSetPageState extends State<EditRoomPermissionSetPage> {
|
|
List<int> items = RoomPermission.asList;
|
|
int permissions = 0;
|
|
|
|
void fetchInfo() {
|
|
final router = GoRouter.of(context);
|
|
final sm = ScaffoldMessenger.of(context);
|
|
final user = context.read<User>();
|
|
|
|
doNetworkRequest(
|
|
sm,
|
|
req: () => postWithCreadentials(
|
|
path: 'getRoomInfo',
|
|
credentials: user,
|
|
target: user.server,
|
|
body: {'room': widget.tag, 'server': widget.server}),
|
|
onAnyErr: () {
|
|
// user should not be here
|
|
// close screen
|
|
router.pushReplacementNamed('home');
|
|
return false;
|
|
},
|
|
onOK: (body) async {
|
|
final info = RoomInfo.fromJSON(body['data']);
|
|
setState(() {
|
|
permissions = info.permissions;
|
|
});
|
|
return true;
|
|
},
|
|
);
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => fetchInfo());
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(AppLocalizations.of(context)!.roomDefaultPermissions),
|
|
),
|
|
body: ListView.builder(
|
|
itemCount: items.length,
|
|
itemBuilder: (context, index) {
|
|
final item = items[index];
|
|
|
|
final int col = pow(2, index + 1) as int;
|
|
|
|
return SwitchListTile(
|
|
title: Text(RoomPermission.name(item, context)),
|
|
subtitle: Text(RoomPermission.describe(item, context)),
|
|
onChanged: (state) {
|
|
setState(() {
|
|
permissions += (state ? 1 : -1) * col;
|
|
});
|
|
},
|
|
value: permissions & col != 0);
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
icon: const Icon(Icons.edit),
|
|
tooltip: AppLocalizations.of(context)!.updateRoomPermissionsHint,
|
|
label: Text(AppLocalizations.of(context)!.updateRoomPermissions),
|
|
onPressed: () {
|
|
final router = GoRouter.of(context);
|
|
final sm = ScaffoldMessenger.of(context);
|
|
final user = context.read<User>();
|
|
|
|
// update permissions
|
|
doNetworkRequest(sm,
|
|
req: () => postWithCreadentials(
|
|
path: 'setRoomRight',
|
|
credentials: user,
|
|
target: user.server,
|
|
body: {
|
|
'room': widget.tag,
|
|
'server': widget.server,
|
|
'rights': permissions
|
|
}),
|
|
onOK: (_) {
|
|
router.pop();
|
|
});
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|