Skip to content
This repository has been archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6 from Panduza/model_view_change-with-worflow
Browse files Browse the repository at this point in the history
Model view change with worflow
  • Loading branch information
wardru authored May 2, 2024
2 parents ec12967 + b757104 commit 2f48acd
Show file tree
Hide file tree
Showing 45 changed files with 931 additions and 1,612 deletions.
40 changes: 40 additions & 0 deletions lib/after_setup_pages/add_cloud_or_self_managed.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:panduza_sandbox_flutter/after_setup_pages/add_connection_page.dart';

import 'package:panduza_sandbox_flutter/data/const.dart';
import 'package:panduza_sandbox_flutter/after_setup_pages/connections_page.dart';
import 'package:panduza_sandbox_flutter/forms/add_connection_form.dart';
import 'package:panduza_sandbox_flutter/setup_pages/cloud_config_auth_page.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart';

// Page to give the choice between use the panduza cloud or
// use a broker the user has himself init (self-managed broker)

class AddCloudOrSelfManaged extends StatelessWidget {

const AddCloudOrSelfManaged({super.key});

@override
Widget build(BuildContext context) {

return Scaffold(
// bar at the top of the application
appBar: getAppBar("Add self-mangaged broker or use cloud ?"),
body: getBasicLayoutDynamic(
context,
page: const CloudAuthPage(),
title: "Panduza Cloud",
icon: Icons.cloud_outlined,
buttonLabel: "Connect",
description: panduzaCloudInfo,

page2: const AddConnectionPage(),
title2: "Self-Managed Broker",
icon2: Icons.broadcast_on_personal_outlined,
buttonLabel2: "Append",
description2: selfManagedBrokerInfo
)
);
}
}
39 changes: 39 additions & 0 deletions lib/after_setup_pages/add_connection_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter/material.dart';
import 'package:panduza_sandbox_flutter/after_setup_pages/discovery_page.dart';
import 'package:panduza_sandbox_flutter/after_setup_pages/manual_connection_page.dart';
import 'package:auto_size_text/auto_size_text.dart';

import 'package:panduza_sandbox_flutter/data/const.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart';

// Page with the 2 choices of adding connection :
// with manual input, with discovery

class AddConnectionPage extends StatelessWidget {
const AddConnectionPage({
super.key,
});

@override
Widget build(BuildContext context) {
return Scaffold(
// bar at the top of the application
appBar: getAppBar("Add self-managed broker"),
body: getBasicLayoutDynamic(
context,
page: const ManualConnectionPage(),
title: "Add broker manually",
icon: Icons.keyboard_outlined,
buttonLabel: "Add my broker",
description: manualAddBrokerInfo,

page2: const DiscoveryPage(),
title2: "Local discovery broker",
icon2: Icons.wifi_find_outlined,
buttonLabel2: "Discover my brokers",
description2: localDiscoveryInfo
)
);
}
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
import 'package:flutter/material.dart';
import 'package:panduza_sandbox_flutter/after_setup_pages/add_cloud_or_self_managed.dart';
import 'package:panduza_sandbox_flutter/setup_pages/choice_cloud_self_managed_page.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_svg/flutter_svg.dart';

import 'package:panduza_sandbox_flutter/data/const.dart';
import 'package:panduza_sandbox_flutter/pages/add_connection_page.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/drawer.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/utils_widgets.dart';

// final List<String> equipments = ["LASER", "ROBOT O", "Quantique"];
// final List<String> brokers = ["Broker 1", "Broker 2", "Broker 3"];
// final List<String> ips = ["192.168.1.33", "192.168.1.32", "192.168.1.31"];
// final List<String> ports = ["1885", "1884", "1883"];

List<String> platformNames = [];
List<String> ips = [];
List<String> ports = [];

class HomePage extends StatefulWidget {
class ConnectionsPage extends StatefulWidget {
// get every connections existing on the disk

const HomePage({super.key, required this.title});

final String title;
const ConnectionsPage({
super.key,
});

// BrokerSniffing brokenSniffer = BrokerSniffing();

@override
State<HomePage> createState() => _HomePageState();
State<ConnectionsPage> createState() => _ConnectionsPageState();
}

class _HomePageState extends State<HomePage> {
class _ConnectionsPageState extends State<ConnectionsPage> {

// disk data
late final SharedPreferences _prefs;
late final _prefsFuture = SharedPreferences.getInstance().then((v) => _prefs = v);

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.

return Scaffold(
// bar at the top of the application
appBar: getAppBar("Connections"),
appBar: getConnectionsAppBar("Connections", context),
// Sliding menu
drawer: getDrawer(context),

Expand All @@ -65,20 +54,19 @@ class _HomePageState extends State<HomePage> {
return const CircularProgressIndicator();
},
),

// Button to add a connection
floatingActionButton: FloatingActionButton(
onPressed: () async {
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AddConnectionPage(),
builder: (context) => const AddCloudOrSelfManaged(),
),
);
setState(() {});
},
// foregroundColor: grey,
backgroundColor: grey,
backgroundColor: black,
shape: const CircleBorder(
eccentricity: 1.0,
),
Expand Down
File renamed without changes.
146 changes: 146 additions & 0 deletions lib/after_setup_pages/discovery_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import 'dart:io';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:auto_size_text/auto_size_text.dart';

import 'package:panduza_sandbox_flutter/data/utils.dart';
import 'package:panduza_sandbox_flutter/data/const.dart';
import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart';
import 'manual_connection_page.dart';


// Page who will discover the differents platforms on
// the network

class DiscoveryPage extends StatefulWidget {
const DiscoveryPage({super.key});

@override
State<DiscoveryPage> createState() => _DiscoveryPageState();
}

class _DiscoveryPageState extends State<DiscoveryPage> {

List<(InternetAddress, int)> platformsIpsPorts = [];
bool isLoading = false;

// List of button of local platform detected
Widget localDiscoveryConnections(List<(InternetAddress, int)> platformsIpsPorts, bool isLoading) {

if (isLoading) {
return Center(
child: CircularProgressIndicator(
color: blue,
)
);
}

return ListView.separated(
padding: const EdgeInsets.all(40),
itemCount: platformsIpsPorts.length,
itemBuilder: (BuildContext context, int index) {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: black,
),
child: Center(
child: Column (
children: <Widget>[
AutoSizeText(
// '${platformsIpsPorts[index].$1.host}',
"local",
style: TextStyle(
color: blue
),
),
AutoSizeText(
platformsIpsPorts[index].$1.address
),
const AutoSizeText(
'1883'
)
],
)
),
),
onTap: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => ManualConnectionPage(
ip: platformsIpsPorts[index].$1.address,
port: "1883"
),
),
);
},
),
);
},
separatorBuilder: (context, index) => const Divider(),
);
}


@override
void initState() {
super.initState();
platformDiscovery().then(
(value) {
platformsIpsPorts = value;
platformsIpsPorts.sort((a, b) => a.$1.host.compareTo(b.$1.host));
setState(() {});
}
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
// bar at the top of the application
appBar: getAppBar("Local Discovery"),
body: localDiscoveryConnections(platformsIpsPorts, isLoading),
bottomSheet: Wrap(
children: <Widget>[
SizedBox(
width: MediaQuery.sizeOf(context).width / 1.1,
height: MediaQuery.sizeOf(context).height / 12,
child: TextButton(
style: ButtonStyle (
backgroundColor: MaterialStateProperty.all<Color>(black)
),
onPressed: () {
// Resend a broadcast to detect every local plaform (get
// id and for each of them)
platformDiscovery().then(
(value) {
platformsIpsPorts = value;
platformsIpsPorts.sort((a, b) => a.$1.host.compareTo(b.$1.host));
setState(() {});
}
);
},
child: Text(
'REFRESH',
style: TextStyle(
color: white,
fontSize: 18
)
)
)
),
SizedBox(
width: MediaQuery.sizeOf(context).width / 1.1,
height: 20,
),
],
),
);
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:mqtt_client/mqtt_server_client.dart';

import 'package:panduza_sandbox_flutter/data/broker_connection_info.dart';
import 'package:panduza_sandbox_flutter/pages/userspace_page.dart';
import 'package:panduza_sandbox_flutter/after_setup_pages/userspace_page.dart';


class MqttConnectionForm extends StatefulWidget {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import 'package:panduza_sandbox_flutter/forms/add_connection_form.dart';

import 'package:panduza_sandbox_flutter/utils_widgets/appBar.dart';

// Page with the 3 choices of adding connection :
// with manual input, with discovery or with the cloud
// Page to add a new connection manually

class ManualConnectionPage extends StatelessWidget {
const ManualConnectionPage({
super.key,
required this.ip,
required this.port,
this.ip = "",
this.port = "",
});

final String ip;
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 7 additions & 1 deletion lib/data/const.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ Color grey = const Color(0xFF1E1E1E);
String connectionKey = "connectionName";

const int portLocalDiscovery = 53035;
const int portReceiveLocalDiscovery = 63008;
const int portReceiveLocalDiscovery = 63008;

// String of info panduza cloud and self managed broker
const String panduzaCloudInfo = "Use the power of Panduza Cloud";
const String selfManagedBrokerInfo = "Append a connection to your own broker";
const String localDiscoveryInfo = "Discover your brokers usings local platform";
const String manualAddBrokerInfo = "Enter your own broker info";
Loading

0 comments on commit 2f48acd

Please sign in to comment.