Skip to content

Commit

Permalink
Add option to hide network tables metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Dec 22, 2023
1 parent 66eedbd commit 8b85678
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 25 deletions.
64 changes: 52 additions & 12 deletions lib/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:convert';
import 'dart:io';

import 'package:elastic_dashboard/widgets/dialog_widgets/dialog_toggle_switch.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
Expand All @@ -10,6 +11,7 @@ import 'package:dot_cast/dot_cast.dart';
import 'package:elegant_notification/elegant_notification.dart';
import 'package:elegant_notification/resources/arrays.dart';
import 'package:file_selector/file_selector.dart';
import 'package:popover/popover.dart';
import 'package:screen_retriever/screen_retriever.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down Expand Up @@ -1351,7 +1353,7 @@ class _DashboardPageState extends State<DashboardPage> with WindowListener {
}
}

class AddWidgetDialog extends StatelessWidget {
class AddWidgetDialog extends StatefulWidget {
final TabGrid Function() grid;
final bool visible;

Expand All @@ -1376,10 +1378,17 @@ class AddWidgetDialog extends StatelessWidget {
this.onClose,
});

@override
State<AddWidgetDialog> createState() => _AddWidgetDialogState();
}

class _AddWidgetDialogState extends State<AddWidgetDialog> {
bool hideMetadata = true;

@override
Widget build(BuildContext context) {
return Visibility(
visible: visible,
visible: widget.visible,
child: DraggableDialog(
dialog: Container(
decoration: const BoxDecoration(boxShadow: [
Expand Down Expand Up @@ -1413,21 +1422,23 @@ class AddWidgetDialog extends StatelessWidget {
NetworkTableTree(
listLayoutBuilder: (
{required title, required children}) {
return grid().createListLayout(
title: title,
children: children,
);
return widget.grid().createListLayout(
title: title,
children: children,
);
},
onDragUpdate: onNTDragUpdate,
onDragEnd: onNTDragEnd,
hideMetadata: hideMetadata,
onDragUpdate: widget.onNTDragUpdate,
onDragEnd: widget.onNTDragEnd,
),
ListView(
children: [
LayoutDragTile(
title: 'List Layout',
layoutBuilder: () => grid().createListLayout(),
onDragUpdate: onLayoutDragUpdate,
onDragEnd: onLayoutDragEnd,
layoutBuilder: () =>
widget.grid().createListLayout(),
onDragUpdate: widget.onLayoutDragUpdate,
onDragEnd: widget.onLayoutDragEnd,
),
],
),
Expand All @@ -1436,10 +1447,39 @@ class AddWidgetDialog extends StatelessWidget {
),
Row(
children: [
Builder(builder: (context) {
return IconButton(
icon: const Icon(Icons.settings),
onPressed: () {
showPopover(
context: context,
direction: PopoverDirection.top,
transitionDuration:
const Duration(milliseconds: 100),
backgroundColor:
Theme.of(context).colorScheme.background,
barrierColor: Colors.transparent,
width: 200.0,
bodyBuilder: (context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: DialogToggleSwitch(
label: 'Hide Metadata',
initialValue: hideMetadata,
onToggle: (value) {
setState(() => hideMetadata = value);
},
),
);
},
);
},
);
}),
const Spacer(),
TextButton(
onPressed: () {
onClose?.call();
widget.onClose?.call();
},
child: const Text('Close'),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/widgets/draggable_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class _DraggableDialogState extends State<DraggableDialog> {
@override
Widget build(BuildContext context) {
return TransformableBox(
constraints: BoxConstraints(
minWidth: Settings.gridSize.toDouble(),
minHeight: Settings.gridSize.toDouble(),
constraints: const BoxConstraints(
minWidth: 300,
minHeight: 400,
maxWidth: double.infinity,
maxHeight: double.infinity),
clampingRect: const Rect.fromLTWH(0, 0, double.infinity, double.infinity),
Expand Down
44 changes: 34 additions & 10 deletions lib/widgets/network_tree/networktables_tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ class NetworkTableTree extends StatefulWidget {
onDragUpdate;
final Function(WidgetContainerModel widget)? onDragEnd;

final bool hideMetadata;

const NetworkTableTree({
super.key,
required this.listLayoutBuilder,
required this.hideMetadata,
this.onDragUpdate,
this.onDragEnd,
});
Expand All @@ -51,7 +54,16 @@ class _NetworkTableTreeState extends State<NetworkTableTree> {
super.initState();

treeController = TreeController<NetworkTableTreeRow>(
roots: root.children, childrenProvider: (node) => node.children);
roots: root.children,
childrenProvider: (node) {
if (widget.hideMetadata) {
return node.children
.whereNot((element) => element.rowName.startsWith('.'));
} else {
return node.children;
}
},
);

ntConnection.nt4Client
.addTopicAnnounceListener(onNewTopicAnnounced = (topic) {
Expand All @@ -68,6 +80,14 @@ class _NetworkTableTreeState extends State<NetworkTableTree> {
super.dispose();
}

@override
void didUpdateWidget(NetworkTableTree oldWidget) {
if (widget.hideMetadata != oldWidget.hideMetadata) {
treeController.rebuild();
}
super.didUpdateWidget(oldWidget);
}

void createRows(NT4Topic nt4Topic) {
String topic = nt4Topic.name;

Expand Down Expand Up @@ -131,6 +151,9 @@ class _NetworkTableTreeState extends State<NetworkTableTree> {
onDragUpdate: onDragUpdate,
onDragEnd: onDragEnd,
onTap: () {
if (widget.hideMetadata && entry.node.containsOnlyMetadata()) {
return;
}
setState(() => treeController.toggleExpansion(entry.node));
},
);
Expand Down Expand Up @@ -213,15 +236,16 @@ class TreeTile extends StatelessWidget {
ListTile(
dense: true,
contentPadding: const EdgeInsets.only(right: 20.0),
leading: (entry.hasChildren)
? FolderButton(
openedIcon: const Icon(Icons.arrow_drop_down),
closedIcon: const Icon(Icons.arrow_right),
iconSize: 24,
isOpen: entry.hasChildren ? entry.isExpanded : null,
onPressed: entry.hasChildren ? onTap : null,
)
: const SizedBox(width: 8.0),
leading:
(entry.hasChildren || entry.node.containsOnlyMetadata())
? FolderButton(
openedIcon: const Icon(Icons.arrow_drop_down),
closedIcon: const Icon(Icons.arrow_right),
iconSize: 24,
isOpen: entry.hasChildren && entry.isExpanded,
onPressed: entry.hasChildren ? onTap : null,
)
: const SizedBox(width: 8.0),
title: Text(entry.node.rowName),
trailing: (entry.node.ntTopic != null)
? Text(entry.node.ntTopic!.type, style: trailingStyle)
Expand Down
8 changes: 8 additions & 0 deletions lib/widgets/network_tree/networktables_tree_row.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ class NetworkTableTreeRow {
return true;
}

bool containsOnlyMetadata() {
if (children.isEmpty) {
return false;
}

return !children.any((row) => !row.rowName.startsWith('.'));
}

void addRow(NetworkTableTreeRow row) {
if (hasRow(row.rowName)) {
return;
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.5.1"
popover:
dependency: "direct main"
description:
name: popover
sha256: "6a0928ccdcf12d46b407372b644a0d94400b316d0ee072a19dcef03c2bb88c3f"
url: "https://pub.dev"
source: hosted
version: "0.2.9"
provider:
dependency: "direct main"
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies:
path: ^1.8.3
path_provider: ^2.0.15
patterns_canvas: ^0.4.0
popover: ^0.2.9
provider: ^6.0.5
screen_retriever: ^0.1.9
searchable_listview: ^2.7.0
Expand Down

0 comments on commit 8b85678

Please sign in to comment.