From 7d680444b0bbaa3444662e9419233a6d39151092 Mon Sep 17 00:00:00 2001 From: helderbetiol <37706737+helderbetiol@users.noreply.github.com> Date: Mon, 17 Jun 2024 16:38:34 +0200 Subject: [PATCH] feat(app) add graph view --- APP/lib/common/api_backend.dart | 21 ++++++++++++++++--- APP/lib/l10n/app_en.arb | 1 + APP/lib/l10n/app_es.arb | 1 + APP/lib/l10n/app_fr.arb | 1 + APP/lib/l10n/app_pt.arb | 3 ++- .../select_objects/tree_view/_node_chip.dart | 20 +++++++++++++++++- .../tree_view/tree_node_tile.dart | 1 + 7 files changed, 43 insertions(+), 5 deletions(-) diff --git a/APP/lib/common/api_backend.dart b/APP/lib/common/api_backend.dart index 077c4b7c5..8bbc1b717 100644 --- a/APP/lib/common/api_backend.dart +++ b/APP/lib/common/api_backend.dart @@ -456,6 +456,24 @@ Future, Exception>> fetchObject(String id, } } +Future, Exception>> fetchObjectChildren( + String id) async { + print("API fetch Object /all"); + try { + Uri url = Uri.parse('$apiUrl/api/hierarchy_objects/$id/all'); + final response = await http.get(url, headers: getHeader(token)); + if (response.statusCode == 200 || response.statusCode == 201) { + Map data = json.decode(response.body); + return Success(Map.from(data["data"])); + } else { + final Map data = json.decode(response.body); + return Failure(Exception(data["message"].toString())); + } + } on Exception catch (e) { + return Failure(e); + } +} + Future> updateObject( String objId, String category, Map object) async { print("API update object"); @@ -527,7 +545,6 @@ Future, Exception>> fetchGroupContent( print("API fetch GR content"); try { Uri url = Uri.parse('$apiUrl/api/objects?id=$id.*&category=$category'); - print('$apiUrl/api/objects?$id=$id.*&category=$category'); final response = await http.get(url, headers: getHeader(token)); if (response.statusCode == 200 || response.statusCode == 201) { Map data = json.decode(response.body); @@ -537,11 +554,9 @@ Future, Exception>> fetchGroupContent( return Failure(Exception("No object found for to this request")); } else { List content = []; - print("hey ya"); for (var item in list) { content.add(item["name"].toString()); } - print(content); return Success(content); } } else { diff --git a/APP/lib/l10n/app_en.arb b/APP/lib/l10n/app_en.arb index 2a47561f2..2075e48a5 100644 --- a/APP/lib/l10n/app_en.arb +++ b/APP/lib/l10n/app_en.arb @@ -190,6 +190,7 @@ "example": "Example:", "viewEditNode": "View and edit this node", "viewJSON": "View as JSON", + "viewGraph": "View as graph", "selectColor": "Select color", "colorPrimary": "Primary", diff --git a/APP/lib/l10n/app_es.arb b/APP/lib/l10n/app_es.arb index a139c1dc4..51ce0b953 100644 --- a/APP/lib/l10n/app_es.arb +++ b/APP/lib/l10n/app_es.arb @@ -190,6 +190,7 @@ "example": "Ejemplo:", "viewEditNode": "Ver y editar este nodo", "viewJSON": "Ver en JSON", + "viewGraph": "Ver como grafo", "selectColor": "Seleccionar color", "colorPrimary": "Primarios", diff --git a/APP/lib/l10n/app_fr.arb b/APP/lib/l10n/app_fr.arb index e2091ddb5..eb192e434 100644 --- a/APP/lib/l10n/app_fr.arb +++ b/APP/lib/l10n/app_fr.arb @@ -228,6 +228,7 @@ "example": "Exemple :", "viewEditNode": "Visualiser et modifier ce noeud", "viewJSON": "Afficher en JSON", + "viewGraph": "Afficher en graphe", "selectColor": "Choisir couleur", "colorPrimary": "Palette", diff --git a/APP/lib/l10n/app_pt.arb b/APP/lib/l10n/app_pt.arb index d5dcc66ed..98bedc6db 100644 --- a/APP/lib/l10n/app_pt.arb +++ b/APP/lib/l10n/app_pt.arb @@ -189,7 +189,8 @@ "filter": "Filtro", "example": "Exemplo:", "viewEditNode": "Visualizar e editar este nó", - "viewJSON": "Visualizar JSON", + "viewJSON": "Ver como JSON", + "viewGraph": "Ver como grafo", "selectColor": "Selecione a cor", "colorPrimary": "Primárias", diff --git a/APP/lib/widgets/select_objects/tree_view/_node_chip.dart b/APP/lib/widgets/select_objects/tree_view/_node_chip.dart index b503c0f31..384c0b458 100644 --- a/APP/lib/widgets/select_objects/tree_view/_node_chip.dart +++ b/APP/lib/widgets/select_objects/tree_view/_node_chip.dart @@ -61,6 +61,21 @@ class _NodeActionsChipState extends State<_NodeActionsChip> { } } + if (namespace == Namespace.Physical && + '.'.allMatches(widget.node.id).length >= 4) { + menuEntries.add( + PopupMenuItem( + value: 4, + child: ListTile( + dense: true, + title: Text(AppLocalizations.of(context)!.viewGraph), + contentPadding: const EdgeInsets.symmetric(horizontal: 4), + leading: const Icon(Icons.auto_graph, color: _kDarkBlue), + ), + ), + ); + } + return PopupMenuButton( key: _popupMenuKey, tooltip: AppLocalizations.of(context)!.selectionOptions, @@ -91,10 +106,13 @@ class _NodeActionsChipState extends State<_NodeActionsChip> { objId: widget.node.id, ), isDismissible: true); - } else { + } else if (selected == 3) { showCustomPopup(context, ViewObjectPopup(namespace: namespace, objId: widget.node.id), isDismissible: true); + } else { + showCustomPopup(context, ObjectGraphView(widget.node.id), + isDismissible: true); } }, child: RawChip( diff --git a/APP/lib/widgets/select_objects/tree_view/tree_node_tile.dart b/APP/lib/widgets/select_objects/tree_view/tree_node_tile.dart index c35b8cf9b..215aad437 100644 --- a/APP/lib/widgets/select_objects/tree_view/tree_node_tile.dart +++ b/APP/lib/widgets/select_objects/tree_view/tree_node_tile.dart @@ -5,6 +5,7 @@ import 'package:ogree_app/common/definitions.dart'; import 'package:ogree_app/common/popup_dialog.dart'; import 'package:ogree_app/common/snackbar.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:ogree_app/pages/layer_graph.dart'; import 'package:ogree_app/pages/tenant_page.dart'; import 'package:ogree_app/widgets/select_objects/view_object_popup.dart'; import 'package:ogree_app/widgets/select_objects/object_popup.dart';