Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add List Layouts #4

Merged
merged 36 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ec47cfe
Added draggable list layout widget
Gold872 Aug 26, 2023
5fbd7e9
Added basic layout dragging in
Gold872 Aug 27, 2023
52d4d46
Added json saving and loading
Gold872 Aug 27, 2023
3e63bde
Removed random print statement
Gold872 Aug 27, 2023
d4b82aa
Added a condition to accept a widget and created foundation for expor…
Gold872 Aug 27, 2023
f94ffac
Adjusted parameters for drag end
Gold872 Aug 29, 2023
c35ddd6
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Aug 31, 2023
515c89f
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Sep 3, 2023
5024b4c
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Sep 3, 2023
b8931f2
Remove double refresh method call
Gold872 Sep 3, 2023
2270815
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Sep 9, 2023
251253a
Added preview when hovering over layout
Gold872 Sep 15, 2023
603a7aa
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Sep 15, 2023
466ed44
Added dragging into list layouts
Gold872 Sep 17, 2023
7b6259f
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Sep 17, 2023
d595525
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Sep 17, 2023
56e883b
Display 'List Layout' instead of 'List View' on add widget dialog
Gold872 Sep 17, 2023
0cdb85a
Added list layout loading
Gold872 Sep 17, 2023
4406888
Decreased resizing handle size
Gold872 Sep 18, 2023
77c80e4
Added reordering and edit properties for list layouts
Gold872 Sep 18, 2023
e3f9cc4
Allow dragging widgets out of list layout
Gold872 Sep 18, 2023
e6b982a
Unsubscribe and dispose when removing list layouts
Gold872 Sep 18, 2023
8606acb
Fixed widget sizing when creating nt4 widget
Gold872 Sep 18, 2023
b5422dd
Fixed dragging widget getting stuck
Gold872 Sep 19, 2023
fe8df07
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Oct 8, 2023
efa8664
Adjusted parameters for will accept widget
Gold872 Oct 8, 2023
c5e0f9a
Update drag location of widgets being dragged in
Gold872 Oct 8, 2023
ebc3b9f
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Oct 16, 2023
8a75c4a
Merge branch 'main' of https://github.com/Gold872/elastic-dashboard i…
Gold872 Oct 20, 2023
9b98fed
Major code refactor & cleanup
Gold872 Oct 21, 2023
23bc4f7
Fixed list layout children not being enabled on NT reconnect
Gold872 Oct 21, 2023
c0b085f
Added title editing to children in list layout
Gold872 Oct 21, 2023
bdaf55f
Prevent list layouts from removing widgets if dragged out to an inval…
Gold872 Oct 21, 2023
8f90d92
Fixed widgets being dragged into layouts from resizing
Gold872 Oct 21, 2023
9880039
Added Shuffleboard API compatibility with List Layouts
Gold872 Oct 23, 2023
dfa4b6d
Updated tests to test list layouts
Gold872 Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 88 additions & 35 deletions lib/pages/dashboard_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import 'package:elastic_dashboard/services/shuffleboard_nt_listener.dart';
import 'package:elastic_dashboard/services/update_checker.dart';
import 'package:elastic_dashboard/widgets/custom_appbar.dart';
import 'package:elastic_dashboard/widgets/dashboard_grid.dart';
import 'package:elastic_dashboard/widgets/dialog_widgets/layout_drag_tile.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_layout_container.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_nt4_widget_container.dart';
import 'package:elastic_dashboard/widgets/draggable_dialog.dart';
import 'package:elastic_dashboard/widgets/draggable_containers/draggable_widget_container.dart';
import 'package:elastic_dashboard/widgets/editable_tab_bar.dart';
import 'package:elastic_dashboard/widgets/network_tree/network_table_tree.dart';
import 'package:elastic_dashboard/widgets/settings_dialog.dart';
Expand Down Expand Up @@ -72,8 +74,14 @@ class _DashboardPageState extends State<DashboardPage> with WindowListener {
]);

grids.addAll([
DashboardGrid(key: GlobalKey(), jsonData: const {}),
DashboardGrid(key: GlobalKey(), jsonData: const {}),
DashboardGrid(
key: GlobalKey(),
onAddWidgetPressed: displayAddWidgetDialog,
),
DashboardGrid(
key: GlobalKey(),
onAddWidgetPressed: displayAddWidgetDialog,
),
]);
}

Expand Down Expand Up @@ -131,7 +139,10 @@ class _DashboardPageState extends State<DashboardPage> with WindowListener {

if (!tabNamesList.contains(tabName)) {
tabData.add(TabData(name: tabName));
grids.add(DashboardGrid(key: GlobalKey(), jsonData: const {}));
grids.add(DashboardGrid(
key: GlobalKey(),
onAddWidgetPressed: displayAddWidgetDialog,
));

tabNamesList.add(tabName);
}
Expand Down Expand Up @@ -897,13 +908,21 @@ class _DashboardPageState extends State<DashboardPage> with WindowListener {
tabViews: grids,
),
AddWidgetDialog(
grid: grids[currentTabIndex],
visible: addWidgetDialogVisible,
onDragUpdate: (globalPosition, widget) {
onNT4DragUpdate: (globalPosition, widget) {
grids[currentTabIndex]
.addDragInWidget(widget, globalPosition);
.addNT4DragInWidget(widget, globalPosition);
},
onDragEnd: (widget) {
grids[currentTabIndex].placeDragInWidget(widget);
onNT4DragEnd: (widget) {
grids[currentTabIndex].placeNT4DragInWidget(widget);
},
onLayoutDragUpdate: (globalPosition, widget) {
grids[currentTabIndex]
.addLayoutDragInWidget(widget, globalPosition);
},
onLayoutDragEnd: (widget) {
grids[currentTabIndex].placeLayoutDragInWidget(widget);
},
onClose: () {
setState(() => addWidgetDialogVisible = false);
Expand Down Expand Up @@ -956,17 +975,27 @@ class _DashboardPageState extends State<DashboardPage> with WindowListener {
}

class AddWidgetDialog extends StatelessWidget {
final DashboardGrid grid;
final bool visible;
final Function(Offset globalPosition, WidgetContainer widget)? onDragUpdate;
final Function(WidgetContainer widget)? onDragEnd;

final Function(Offset globalPosition, DraggableNT4WidgetContainer widget)?
onNT4DragUpdate;
final Function(DraggableNT4WidgetContainer widget)? onNT4DragEnd;

final Function(Offset globalPosition, DraggableLayoutContainer widget)?
onLayoutDragUpdate;
final Function(DraggableLayoutContainer widget)? onLayoutDragEnd;

final Function()? onClose;

const AddWidgetDialog({
super.key,
required this.grid,
required this.visible,
this.onDragUpdate,
this.onDragEnd,
this.onNT4DragUpdate,
this.onNT4DragEnd,
this.onLayoutDragUpdate,
this.onLayoutDragEnd,
this.onClose,
});

Expand All @@ -986,31 +1015,55 @@ class AddWidgetDialog extends StatelessWidget {
]),
child: Card(
margin: const EdgeInsets.all(10.0),
child: Column(
children: [
const Icon(Icons.drag_handle, color: Colors.grey),
const SizedBox(height: 10),
Text('Add Widget',
style: Theme.of(context).textTheme.titleMedium),
const Divider(),
Expanded(
child: NetworkTableTree(
onDragUpdate: onDragUpdate,
onDragEnd: onDragEnd,
child: DefaultTabController(
length: 2,
child: Column(
children: [
const Icon(Icons.drag_handle, color: Colors.grey),
const SizedBox(height: 10),
Text('Add Widget',
style: Theme.of(context).textTheme.titleMedium),
const TabBar(
tabs: [
Tab(text: 'Network Tables'),
Tab(text: 'Layouts'),
],
),
),
Row(
children: [
const Spacer(),
TextButton(
onPressed: () {
onClose?.call();
},
child: const Text('Close'),
const SizedBox(height: 5),
Expanded(
child: TabBarView(
children: [
NetworkTableTree(
onDragUpdate: onNT4DragUpdate,
onDragEnd: onNT4DragEnd,
widgetContainerBuilder: grid.createNT4WidgetContainer,
),
ListView(
children: [
LayoutDragTile(
title: 'List Layout',
layoutBuilder: () => grid.createListLayout(),
onDragUpdate: onLayoutDragUpdate,
onDragEnd: onLayoutDragEnd,
),
],
),
],
),
],
),
],
),
Row(
children: [
const Spacer(),
TextButton(
onPressed: () {
onClose?.call();
},
child: const Text('Close'),
),
],
),
],
),
),
),
),
Expand Down
6 changes: 4 additions & 2 deletions lib/services/nt4_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ class NT4Connection {
onDisconnectedListeners.add(callback);
}

Future<T?>? subscribeAndRetrieveData<T>(String topic, [period = 0.1]) async {
Future<T?>? subscribeAndRetrieveData<T>(String topic,
{period = 0.1,
timeout = const Duration(seconds: 2, milliseconds: 500)}) async {
NT4Subscription subscription = subscribe(topic, period);

T? value;
try {
value = await subscription
.periodicStream()
.firstWhere((element) => element != null && element is T)
.timeout(const Duration(seconds: 2, milliseconds: 500)) as T?;
.timeout(timeout) as T?;
} catch (e) {
value = null;
}
Expand Down
Loading