]> git.proxmox.com Git - flutter/pve_flutter_frontend.git/commitdiff
add PveLxcPowerSettings widget
authorTim Marx <t.marx@proxmox.com>
Tue, 14 Apr 2020 23:31:13 +0000 (01:31 +0200)
committerTim Marx <t.marx@proxmox.com>
Tue, 14 Apr 2020 23:53:02 +0000 (01:53 +0200)
Signed-off-by: Tim Marx <t.marx@proxmox.com>
lib/widgets/pve_lxc_overview.dart
lib/widgets/pve_lxc_power_settings_widget.dart [new file with mode: 0644]

index 9447df47ce846c08245561cec4c6b29e63bfb25f..00342e623247e6015aafb625b76d859967025120 100644 (file)
@@ -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: <Widget>[
                             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 (file)
index 0000000..76e5e77
--- /dev/null
@@ -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<PveLxcOverviewBloc, PveLxcOverviewState>(
+      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: <Widget>[
+              Row(
+                mainAxisAlignment: MainAxisAlignment.center,
+                children: <Widget>[
+                  Text(
+                    "Power Settings",
+                    style: Theme.of(context)
+                        .textTheme
+                        .headline4
+                        .copyWith(color: Colors.white),
+                  ),
+                ],
+              ),
+              Expanded(
+                child: Column(
+                  mainAxisAlignment: MainAxisAlignment.center,
+                  children: <Widget>[
+                    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();
+  }
+}