mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 00:21:19 +00:00
update service generation + add create device request
This commit is contained in:
parent
234fc83cbd
commit
8e8e233189
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:managerapi/api.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tablet_app/Components/MainView/dropDown_configuration.dart';
|
||||
@ -9,12 +10,11 @@ import 'package:tablet_app/Components/Map/map_view.dart';
|
||||
import 'package:tablet_app/Components/loading.dart';
|
||||
import 'package:tablet_app/Components/webView.dart';
|
||||
import 'package:tablet_app/Models/map-marker.dart';
|
||||
import 'package:tablet_app/Models/section.dart';
|
||||
import 'package:tablet_app/Models/tabletContext.dart';
|
||||
import 'package:tablet_app/app_context.dart';
|
||||
import 'package:tablet_app/constants.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:auto_size_text/auto_size_text.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'language_selection.dart';
|
||||
|
||||
@ -212,11 +212,13 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
configurations: snapshot.data,
|
||||
onChange: (ConfigurationDTO configurationOut) {
|
||||
setState(() {
|
||||
// TODO STORE IT LOCALLY !!
|
||||
// TODO STORE IT LOCALLY !! + CREATE DEVICE REQUEST
|
||||
|
||||
TabletAppContext tabletAppContext = appContext.getContext();
|
||||
tabletAppContext.configuration = configurationOut;
|
||||
appContext.setContext(tabletAppContext);
|
||||
|
||||
createDevice(configurationOut, appContext);
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -329,6 +331,57 @@ class _MainViewWidget extends State<MainViewWidget> {
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
Future<void> createDevice(ConfigurationDTO configurationDTO, dynamic appContext) async {
|
||||
TabletAppContext tabletAppContext = appContext.getContext();
|
||||
DeviceDetailDTO newDevice = new DeviceDetailDTO();
|
||||
newDevice.configurationId = configurationDTO.id;
|
||||
newDevice.configuration = configurationDTO.label;
|
||||
newDevice.connected = true;
|
||||
newDevice.ipAddressWLAN = await getIP(true);
|
||||
newDevice.ipAddressETH = await getIP(false);
|
||||
|
||||
print(newDevice);
|
||||
|
||||
DeviceDetailDTO device = await tabletAppContext.clientAPI.deviceApi.deviceCreate(newDevice);
|
||||
|
||||
if (device != null) {
|
||||
Fluttertoast.showToast(
|
||||
msg: "La tablette a bien été créée",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
timeInSecForIosWeb: 1,
|
||||
backgroundColor: Colors.lightGreen,
|
||||
textColor: Colors.white,
|
||||
fontSize: 16.0
|
||||
);
|
||||
} else {
|
||||
Fluttertoast.showToast(
|
||||
msg: "Une erreur est survenue lors de la création de la tablette",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
timeInSecForIosWeb: 1,
|
||||
backgroundColor: Colors.deepOrangeAccent,
|
||||
textColor: Colors.white,
|
||||
fontSize: 16.0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getIP(bool isWLAN) async {
|
||||
for (var interface in await NetworkInterface.list()) {
|
||||
print('== Interface: ${interface.name} ==');
|
||||
if (interface.name == "wlan0" && isWLAN) {
|
||||
// wifi
|
||||
return interface.addresses.first.address;
|
||||
}
|
||||
if (interface.name == "eth0" && !isWLAN) {
|
||||
// wired
|
||||
return interface.addresses.first.address;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
boxDecoration(SectionDTO section) {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
.gitignore
|
||||
.openapi-generator-ignore
|
||||
.travis.yml
|
||||
README.md
|
||||
doc/AuthenticationApi.md
|
||||
@ -71,32 +70,3 @@ lib/model/user_detail_dto.dart
|
||||
lib/model/video_dto.dart
|
||||
lib/model/web_dto.dart
|
||||
pubspec.yaml
|
||||
test/authentication_api_test.dart
|
||||
test/configuration_api_test.dart
|
||||
test/configuration_dto_test.dart
|
||||
test/device_api_test.dart
|
||||
test/device_detail_dto_all_of_test.dart
|
||||
test/device_detail_dto_test.dart
|
||||
test/device_dto_test.dart
|
||||
test/geo_point_dto_test.dart
|
||||
test/image_dto_test.dart
|
||||
test/image_geo_point_test.dart
|
||||
test/login_dto_test.dart
|
||||
test/map_dto_test.dart
|
||||
test/map_type_test.dart
|
||||
test/menu_dto_test.dart
|
||||
test/resource_api_test.dart
|
||||
test/resource_detail_dto_test.dart
|
||||
test/resource_dto_test.dart
|
||||
test/resource_type_test.dart
|
||||
test/section_api_test.dart
|
||||
test/section_dto_test.dart
|
||||
test/section_type_test.dart
|
||||
test/slider_dto_test.dart
|
||||
test/token_dto_test.dart
|
||||
test/translation_dto_test.dart
|
||||
test/user_api_test.dart
|
||||
test/user_detail_dto_test.dart
|
||||
test/user_test.dart
|
||||
test/video_dto_test.dart
|
||||
test/web_dto_test.dart
|
||||
|
||||
@ -10,7 +10,8 @@ Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**id** | **String** | | [optional]
|
||||
**name** | **String** | | [optional]
|
||||
**ipAddress** | **String** | | [optional]
|
||||
**ipAddressWLAN** | **String** | | [optional]
|
||||
**ipAddressETH** | **String** | | [optional]
|
||||
**configurationId** | **String** | | [optional]
|
||||
**configuration** | **String** | | [optional]
|
||||
**connected** | **bool** | | [optional]
|
||||
|
||||
@ -10,7 +10,8 @@ Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**id** | **String** | | [optional]
|
||||
**name** | **String** | | [optional]
|
||||
**ipAddress** | **String** | | [optional]
|
||||
**ipAddressWLAN** | **String** | | [optional]
|
||||
**ipAddressETH** | **String** | | [optional]
|
||||
**configurationId** | **String** | | [optional]
|
||||
**configuration** | **String** | | [optional]
|
||||
**connected** | **bool** | | [optional]
|
||||
|
||||
@ -14,7 +14,8 @@ class DeviceDetailDTO {
|
||||
DeviceDetailDTO({
|
||||
this.id,
|
||||
this.name,
|
||||
this.ipAddress,
|
||||
this.ipAddressWLAN,
|
||||
this.ipAddressETH,
|
||||
this.configurationId,
|
||||
this.configuration,
|
||||
this.connected,
|
||||
@ -29,7 +30,9 @@ class DeviceDetailDTO {
|
||||
|
||||
String name;
|
||||
|
||||
String ipAddress;
|
||||
String ipAddressWLAN;
|
||||
|
||||
String ipAddressETH;
|
||||
|
||||
String configurationId;
|
||||
|
||||
@ -51,7 +54,8 @@ class DeviceDetailDTO {
|
||||
bool operator ==(Object other) => identical(this, other) || other is DeviceDetailDTO &&
|
||||
other.id == id &&
|
||||
other.name == name &&
|
||||
other.ipAddress == ipAddress &&
|
||||
other.ipAddressWLAN == ipAddressWLAN &&
|
||||
other.ipAddressETH == ipAddressETH &&
|
||||
other.configurationId == configurationId &&
|
||||
other.configuration == configuration &&
|
||||
other.connected == connected &&
|
||||
@ -65,7 +69,8 @@ class DeviceDetailDTO {
|
||||
int get hashCode =>
|
||||
(id == null ? 0 : id.hashCode) +
|
||||
(name == null ? 0 : name.hashCode) +
|
||||
(ipAddress == null ? 0 : ipAddress.hashCode) +
|
||||
(ipAddressWLAN == null ? 0 : ipAddressWLAN.hashCode) +
|
||||
(ipAddressETH == null ? 0 : ipAddressETH.hashCode) +
|
||||
(configurationId == null ? 0 : configurationId.hashCode) +
|
||||
(configuration == null ? 0 : configuration.hashCode) +
|
||||
(connected == null ? 0 : connected.hashCode) +
|
||||
@ -76,7 +81,7 @@ class DeviceDetailDTO {
|
||||
(lastBatteryLevel == null ? 0 : lastBatteryLevel.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'DeviceDetailDTO[id=$id, name=$name, ipAddress=$ipAddress, configurationId=$configurationId, configuration=$configuration, connected=$connected, dateCreation=$dateCreation, connectionLevel=$connectionLevel, lastConnectionLevel=$lastConnectionLevel, batteryLevel=$batteryLevel, lastBatteryLevel=$lastBatteryLevel]';
|
||||
String toString() => 'DeviceDetailDTO[id=$id, name=$name, ipAddressWLAN=$ipAddressWLAN, ipAddressETH=$ipAddressETH, configurationId=$configurationId, configuration=$configuration, connected=$connected, dateCreation=$dateCreation, connectionLevel=$connectionLevel, lastConnectionLevel=$lastConnectionLevel, batteryLevel=$batteryLevel, lastBatteryLevel=$lastBatteryLevel]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
@ -86,8 +91,11 @@ class DeviceDetailDTO {
|
||||
if (name != null) {
|
||||
json[r'name'] = name;
|
||||
}
|
||||
if (ipAddress != null) {
|
||||
json[r'ipAddress'] = ipAddress;
|
||||
if (ipAddressWLAN != null) {
|
||||
json[r'ipAddressWLAN'] = ipAddressWLAN;
|
||||
}
|
||||
if (ipAddressETH != null) {
|
||||
json[r'ipAddressETH'] = ipAddressETH;
|
||||
}
|
||||
if (configurationId != null) {
|
||||
json[r'configurationId'] = configurationId;
|
||||
@ -123,7 +131,8 @@ class DeviceDetailDTO {
|
||||
: DeviceDetailDTO(
|
||||
id: json[r'id'],
|
||||
name: json[r'name'],
|
||||
ipAddress: json[r'ipAddress'],
|
||||
ipAddressWLAN: json[r'ipAddressWLAN'],
|
||||
ipAddressETH: json[r'ipAddressETH'],
|
||||
configurationId: json[r'configurationId'],
|
||||
configuration: json[r'configuration'],
|
||||
connected: json[r'connected'],
|
||||
|
||||
@ -14,7 +14,8 @@ class DeviceDTO {
|
||||
DeviceDTO({
|
||||
this.id,
|
||||
this.name,
|
||||
this.ipAddress,
|
||||
this.ipAddressWLAN,
|
||||
this.ipAddressETH,
|
||||
this.configurationId,
|
||||
this.configuration,
|
||||
this.connected,
|
||||
@ -25,7 +26,9 @@ class DeviceDTO {
|
||||
|
||||
String name;
|
||||
|
||||
String ipAddress;
|
||||
String ipAddressWLAN;
|
||||
|
||||
String ipAddressETH;
|
||||
|
||||
String configurationId;
|
||||
|
||||
@ -39,7 +42,8 @@ class DeviceDTO {
|
||||
bool operator ==(Object other) => identical(this, other) || other is DeviceDTO &&
|
||||
other.id == id &&
|
||||
other.name == name &&
|
||||
other.ipAddress == ipAddress &&
|
||||
other.ipAddressWLAN == ipAddressWLAN &&
|
||||
other.ipAddressETH == ipAddressETH &&
|
||||
other.configurationId == configurationId &&
|
||||
other.configuration == configuration &&
|
||||
other.connected == connected &&
|
||||
@ -49,14 +53,15 @@ class DeviceDTO {
|
||||
int get hashCode =>
|
||||
(id == null ? 0 : id.hashCode) +
|
||||
(name == null ? 0 : name.hashCode) +
|
||||
(ipAddress == null ? 0 : ipAddress.hashCode) +
|
||||
(ipAddressWLAN == null ? 0 : ipAddressWLAN.hashCode) +
|
||||
(ipAddressETH == null ? 0 : ipAddressETH.hashCode) +
|
||||
(configurationId == null ? 0 : configurationId.hashCode) +
|
||||
(configuration == null ? 0 : configuration.hashCode) +
|
||||
(connected == null ? 0 : connected.hashCode) +
|
||||
(dateCreation == null ? 0 : dateCreation.hashCode);
|
||||
|
||||
@override
|
||||
String toString() => 'DeviceDTO[id=$id, name=$name, ipAddress=$ipAddress, configurationId=$configurationId, configuration=$configuration, connected=$connected, dateCreation=$dateCreation]';
|
||||
String toString() => 'DeviceDTO[id=$id, name=$name, ipAddressWLAN=$ipAddressWLAN, ipAddressETH=$ipAddressETH, configurationId=$configurationId, configuration=$configuration, connected=$connected, dateCreation=$dateCreation]';
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final json = <String, dynamic>{};
|
||||
@ -66,8 +71,11 @@ class DeviceDTO {
|
||||
if (name != null) {
|
||||
json[r'name'] = name;
|
||||
}
|
||||
if (ipAddress != null) {
|
||||
json[r'ipAddress'] = ipAddress;
|
||||
if (ipAddressWLAN != null) {
|
||||
json[r'ipAddressWLAN'] = ipAddressWLAN;
|
||||
}
|
||||
if (ipAddressETH != null) {
|
||||
json[r'ipAddressETH'] = ipAddressETH;
|
||||
}
|
||||
if (configurationId != null) {
|
||||
json[r'configurationId'] = configurationId;
|
||||
@ -91,7 +99,8 @@ class DeviceDTO {
|
||||
: DeviceDTO(
|
||||
id: json[r'id'],
|
||||
name: json[r'name'],
|
||||
ipAddress: json[r'ipAddress'],
|
||||
ipAddressWLAN: json[r'ipAddressWLAN'],
|
||||
ipAddressETH: json[r'ipAddressETH'],
|
||||
configurationId: json[r'configurationId'],
|
||||
configuration: json[r'configuration'],
|
||||
connected: json[r'connected'],
|
||||
|
||||
@ -27,8 +27,6 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- bearer: []
|
||||
post:
|
||||
tags:
|
||||
- Configuration
|
||||
@ -243,8 +241,6 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- bearer: []
|
||||
put:
|
||||
tags:
|
||||
- Device
|
||||
@ -771,8 +767,6 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
type: string
|
||||
security:
|
||||
- bearer: []
|
||||
delete:
|
||||
tags:
|
||||
- Section
|
||||
@ -1307,7 +1301,10 @@ components:
|
||||
name:
|
||||
type: string
|
||||
nullable: true
|
||||
ipAddress:
|
||||
ipAddressWLAN:
|
||||
type: string
|
||||
nullable: true
|
||||
ipAddressETH:
|
||||
type: string
|
||||
nullable: true
|
||||
configurationId:
|
||||
|
||||
21
pubspec.lock
21
pubspec.lock
@ -88,6 +88,18 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_web_plugins:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
fluttertoast:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: fluttertoast
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "8.0.7"
|
||||
google_maps_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -123,6 +135,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.16.1"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.6.3"
|
||||
managerapi:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -171,7 +190,7 @@ packages:
|
||||
name: plugin_platform_interface
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
version: "2.0.1"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@ -29,6 +29,7 @@ dependencies:
|
||||
provider: ^5.0.0
|
||||
http: ^0.12.2
|
||||
auto_size_text: ^2.1.0
|
||||
fluttertoast:
|
||||
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user