From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 0DA771FF16F
	for <inbox@lore.proxmox.com>; Tue, 29 Apr 2025 15:17:38 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 6D659E0DD;
	Tue, 29 Apr 2025 15:17:38 +0200 (CEST)
From: Alexander Abraham <a.abraham@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 29 Apr 2025 15:16:45 +0200
Message-Id: <20250429131645.106612-3-a.abraham@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250429131645.106612-1-a.abraham@proxmox.com>
References: <20250429131645.106612-1-a.abraham@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.113 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [colors.green]
Subject: [pve-devel] [PATCH flutter_frontend 1/1] fix #4976: ui: Nodes
 offline
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

This commit adds functionality for not letting users click on nodes
that are offline in the general overview screen. Furthermore,
functionality was added to send the user back to the general overview
screen if a node is suddenly offline while the user is viewing
information on that node.

Signed-off-by: Alexander Abraham <a.abraham@proxmox.com>
---
 lib/bloc/pve_node_overview_bloc.dart | 79 ++++++++++++++++++----------
 lib/main.dart                        |  3 ++
 lib/pages/main_layout_slim.dart      | 58 ++++++++++++++++----
 3 files changed, 101 insertions(+), 39 deletions(-)

diff --git a/lib/bloc/pve_node_overview_bloc.dart b/lib/bloc/pve_node_overview_bloc.dart
index 19d6563..98005fd 100644
--- a/lib/bloc/pve_node_overview_bloc.dart
+++ b/lib/bloc/pve_node_overview_bloc.dart
@@ -1,5 +1,5 @@
 import 'dart:async';
-
+import 'package:flutter/material.dart';
 import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart';
 import 'package:pve_flutter_frontend/bloc/proxmox_base_bloc.dart';
 import 'package:pve_flutter_frontend/states/pve_node_overview_state.dart';
@@ -8,12 +8,13 @@ class PveNodeOverviewBloc
     extends ProxmoxBaseBloc<PveNodeOverviewEvent, PveNodeOverviewState> {
   final ProxmoxApiClient apiClient;
   final String nodeID;
+  final BuildContext context;
   final PveNodeOverviewState init;
   @override
   PveNodeOverviewState get initialState => init;
 
   PveNodeOverviewBloc(
-      {required this.apiClient, required this.nodeID, required this.init});
+      {required this.apiClient, required this.nodeID, required this.init, required this.context});
 
   Timer? sTimer;
   @override
@@ -32,36 +33,56 @@ class PveNodeOverviewBloc
   @override
   Stream<PveNodeOverviewState> processEvents(
       PveNodeOverviewEvent event) async* {
-    if (event is UpdateNodeStatus) {
-      final status = await apiClient.getNodeStatus(nodeID);
-      yield latestState.rebuild((b) => b..status.replace(status));
-      final rrdData =
-          await apiClient.getNodeRRDdata(nodeID, PveRRDTimeframeType.hour);
-      yield latestState.rebuild((b) => b..rrdData.replace(rrdData));
-      final services = await apiClient.getNodeServices(nodeID);
-      yield latestState.rebuild((b) => b..services.replace(services));
-      try {
-        final updates = await apiClient.getNodeAptUpdate(nodeID);
-        yield latestState.rebuild((b) => b..updates.replace(updates));
-        yield latestState
-            .rebuild((b) => b..updatesQueryPermissionFailure = false);
-      } on ProxmoxApiException catch (e) {
-        // only throw on non permission related errors
-        if (e.statusCode != 403) {
-          rethrow;
-        } else {
+    PveNodeStatusModel? status;
+    try {
+      status = await apiClient.getNodeStatus(nodeID);
+      if (event is UpdateNodeStatus) {
+        yield latestState.rebuild((b) => b..status.replace(status!));
+        final rrdData =
+        await apiClient.getNodeRRDdata(nodeID, PveRRDTimeframeType.hour);
+        yield latestState.rebuild((b) => b..rrdData.replace(rrdData));
+        final services = await apiClient.getNodeServices(nodeID);
+        yield latestState.rebuild((b) => b..services.replace(services));
+        try {
+          final updates = await apiClient.getNodeAptUpdate(nodeID);
+          yield latestState.rebuild((b) => b..updates.replace(updates));
           yield latestState
-              .rebuild((b) => b..updatesQueryPermissionFailure = true);
+              .rebuild((b) => b..updatesQueryPermissionFailure = false);
+        } 
+        on ProxmoxApiException catch (e) {
+            // only throw on non permission related errors
+            if (e.statusCode != 403) {
+              rethrow;
+            } 
+            else {
+              yield latestState
+                .rebuild((b) => b..updatesQueryPermissionFailure = true);
+            }
+          }
+          final disks = await apiClient.getNodeDisksList(nodeID);
+          yield latestState.rebuild((b) => b..disks.replace(disks));
+        }
+
+        if (event is PerformNodeAction) {
+          await apiClient.doResourceAction(
+            nodeID,
+            '',
+            'node',
+            event.action,
+            parameters: <String, String>{});
+          yield latestState;
         }
       }
-      final disks = await apiClient.getNodeDisksList(nodeID);
-      yield latestState.rebuild((b) => b..disks.replace(disks));
-    }
-    if (event is PerformNodeAction) {
-      await apiClient.doResourceAction(nodeID, '', 'node', event.action,
-          parameters: <String, String>{});
-      yield latestState;
-    }
+      catch(e){
+        yield latestState.rebuild(
+          (b) => b
+            ..updatesQueryPermissionFailure = true
+        );
+        if (context.mounted){
+          Navigator.of(context).pop();
+        }
+        else {}
+      }
   }
 }
 
diff --git a/lib/main.dart b/lib/main.dart
index a985e3a..bbd3c97 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -330,15 +330,18 @@ class MyApp extends StatelessWidget {
                   final rbloc = Provider.of<PveResourceBloc>(context);
                   return MultiProvider(
                     providers: [
+
                       Provider<PveNodeOverviewBloc>(
                         create: (context) => PveNodeOverviewBloc(
                           apiClient: state.apiClient,
                           nodeID: nodeID,
+                          context: context,
                           init: PveNodeOverviewState.init(
                               rbloc.latestState.isStandalone),
                         )..events.add(UpdateNodeStatus()),
                         dispose: (context, bloc) => bloc.dispose(),
                       ),
+
                       Provider<PveTaskLogBloc>(
                         create: (context) => PveTaskLogBloc(
                             apiClient: state.apiClient,
diff --git a/lib/pages/main_layout_slim.dart b/lib/pages/main_layout_slim.dart
index 322bcac..5fa6199 100644
--- a/lib/pages/main_layout_slim.dart
+++ b/lib/pages/main_layout_slim.dart
@@ -254,7 +254,7 @@ class MobileDashboard extends StatelessWidget {
                                 fontWeight: FontWeight.bold,
                                 color: Colors.white),
                           ),
-                          onPressed: () => showDialog(
+                          onPressed: () => (
                             context: context,
                             builder: (c) => const PveSubscriptionAlertDialog(),
                           ),
@@ -556,7 +556,7 @@ class MobileDashboard extends StatelessWidget {
   }
 }
 
-class PveNodeListTile extends StatelessWidget {
+class PveNodeListTile extends StatelessWidget{
   final String name;
   final bool online;
   final String type;
@@ -564,21 +564,58 @@ class PveNodeListTile extends StatelessWidget {
   final String? ip;
   const PveNodeListTile(
       {super.key,
-      required this.name,
-      required this.online,
-      required this.type,
-      this.level,
-      this.ip = ''});
+        required this.name,
+        required this.online,
+        required this.type,
+        this.level,
+        this.ip = ''});
+
   @override
   Widget build(BuildContext context) {
+    late Color splashColor;
+    if (online){
+      splashColor = ProxmoxColors.greyShade40;
+    }
+    else {
+      splashColor = Colors.transparent;
+    }
     return ListTile(
       leading: Icon(
         Renderers.getDefaultResourceIcon(type),
       ),
       title: Text(name),
+      splashColor: splashColor,
       subtitle: Text(getNodeTileSubtitle(online, level, ip)),
       trailing: Icon(Icons.power, color: online ? Colors.green : Colors.grey),
-      onTap: () => Navigator.pushNamed(context, '/nodes/$name'),
+      onTap: () => {
+        if (online){
+          Navigator.pushNamed(context, '/nodes/$name')
+        }
+        else{
+          showDialog(
+            context: context,
+            builder: (context) {
+              return AlertDialog(
+                contentPadding: const EdgeInsets.fromLTRB(24.0, 12.0, 24.0, 16.0),
+                title: Row(
+                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
+                  children: <Widget>[
+                    Text('Error'),
+                    Icon(Icons.warning),
+                  ],
+                ),
+                content: Text("Node offline."),
+                actions: [
+                  TextButton(
+                    onPressed: () => Navigator.of(context).pop(false),
+                    child: const Text("Ok")
+                  ),
+                ],
+              );
+            }
+          )
+        }  
+      }
     );
   }
 
@@ -588,6 +625,7 @@ class PveNodeListTile extends StatelessWidget {
     }
     return 'offline';
   }
+
 }
 
 class MobileResourceOverview extends StatelessWidget {
@@ -621,7 +659,7 @@ class MobileResourceOverview extends StatelessWidget {
               separatorBuilder: (context, index) => const Divider(),
               itemBuilder: (context, index) {
                 final resource = fResources[index];
-                StatelessWidget listWidget = const ListTile(
+                Widget listWidget = const ListTile(
                   title: Text('Unkown resource type'),
                 );
                 if (const ['lxc', 'qemu'].contains(resource.type)) {
@@ -1191,7 +1229,7 @@ class MobileAccessManagement extends StatelessWidget {
                               borderRadius: BorderRadius.vertical(
                                   top: Radius.circular(10))),
                           context: context,
-                          builder: (context) {
+                          builder: (context) { 
                             return SizedBox(
                               height: MediaQuery.of(context).size.height * 0.5,
                               child: Column(
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel