From 582589de92b5ef15554048eea6585feb86d8e265 Mon Sep 17 00:00:00 2001 From: Tim Marx Date: Wed, 15 Apr 2020 01:31:13 +0200 Subject: [PATCH] add PveLxcPowerSettings widget Signed-off-by: Tim Marx --- lib/widgets/pve_lxc_overview.dart | 16 +++- .../pve_lxc_power_settings_widget.dart | 90 +++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 lib/widgets/pve_lxc_power_settings_widget.dart diff --git a/lib/widgets/pve_lxc_overview.dart b/lib/widgets/pve_lxc_overview.dart index 9447df4..00342e6 100644 --- a/lib/widgets/pve_lxc_overview.dart +++ b/lib/widgets/pve_lxc_overview.dart @@ -19,6 +19,7 @@ import 'package:pve_flutter_frontend/widgets/proxmox_stream_listener.dart'; import 'package:pve_flutter_frontend/widgets/pve_action_card_widget.dart'; import 'package:pve_flutter_frontend/widgets/pve_guest_migrate_widget.dart'; import 'package:pve_flutter_frontend/widgets/pve_guest_overview_header.dart'; +import 'package:pve_flutter_frontend/widgets/pve_lxc_power_settings_widget.dart'; import 'package:pve_flutter_frontend/widgets/pve_task_log_expansiontile_widget.dart'; import 'package:pve_flutter_frontend/widgets/pve_task_log_widget.dart'; @@ -94,7 +95,20 @@ class PveLxcOverview extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ ActionCard( - icon: Icon( + icon: Icon( + Icons.power_settings_new, + size: 55, + color: Colors.white24, + ), + title: 'Power Settings', + onTap: () => Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => PveLxcPowerSettings( + lxcBloc: lxcBloc, + ), + fullscreenDialog: true), + ), + ), FontAwesomeIcons.paperPlane, size: 55, color: Colors.white24, diff --git a/lib/widgets/pve_lxc_power_settings_widget.dart b/lib/widgets/pve_lxc_power_settings_widget.dart new file mode 100644 index 0000000..76e5e77 --- /dev/null +++ b/lib/widgets/pve_lxc_power_settings_widget.dart @@ -0,0 +1,90 @@ +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart'; +import 'package:pve_flutter_frontend/bloc/pve_lxc_overview_bloc.dart'; +import 'package:pve_flutter_frontend/states/pve_lxc_overview_state.dart'; +import 'package:pve_flutter_frontend/widgets/proxmox_stream_builder_widget.dart'; + +class PveLxcPowerSettings extends StatelessWidget { + final PveLxcOverviewBloc lxcBloc; + + const PveLxcPowerSettings({Key key, this.lxcBloc}) : super(key: key); + @override + Widget build(BuildContext context) { + return ProxmoxStreamBuilder( + bloc: lxcBloc, + builder: (context, state) { + final status = state.currentStatus; + final disableShutdown = + status?.getLxcStatus() != PveResourceStatusType.running; + return Scaffold( + backgroundColor: Color(0xFF00617F), + appBar: AppBar( + backgroundColor: Colors.transparent, + elevation: 0, + ), + body: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + "Power Settings", + style: Theme.of(context) + .textTheme + .headline4 + .copyWith(color: Colors.white), + ), + ], + ), + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (disableShutdown) + OutlineButton.icon( + onPressed: () => action( + context, PveClusterResourceAction.start, lxcBloc), + icon: Icon(Icons.play_arrow), + label: Text("Start"), + ), + OutlineButton.icon( + onPressed: disableShutdown + ? null + : () => action(context, + PveClusterResourceAction.shutdown, lxcBloc), + icon: Icon(Icons.power_settings_new), + label: Text("Shutdown"), + ), + OutlineButton.icon( + onPressed: disableShutdown + ? null + : () => action(context, + PveClusterResourceAction.reboot, lxcBloc), + icon: Icon(Icons.autorenew), + label: Text("Reboot"), + ), + OutlineButton.icon( + onPressed: disableShutdown + ? null + : () => action( + context, PveClusterResourceAction.stop, lxcBloc), + icon: Icon(Icons.stop), + label: Text("Stop"), + ), + ], + ), + ), + ], + ), + ); + }, + ); + } + + void action(BuildContext context, PveClusterResourceAction action, + PveLxcOverviewBloc bloc) { + bloc.events.add(PerformLxcAction(action)); + Navigator.of(context).pop(); + } +} -- 2.39.5