diff --git a/lib/Components/image_input_container.dart b/lib/Components/image_input_container.dart index 81ca685..15fe508 100644 --- a/lib/Components/image_input_container.dart +++ b/lib/Components/image_input_container.dart @@ -125,12 +125,12 @@ class _ImageInputContainerState extends State { } } - Future getResource(String resourceIdToShow, dynamic appContext) async { - ResourceDetailDTO resource = await appContext.getContext().clientAPI.resourceApi.resourceGetDetail(resourceIdToShow); + Future getResource(String resourceIdToShow, dynamic appContext) async { + ResourceDTO resource = await appContext.getContext().clientAPI.resourceApi.resourceGetDetail(resourceIdToShow); return resource; } - boxDecoration(ResourceDetailDTO resourceDetailDTO, appContext) { + boxDecoration(ResourceDTO resourceDTO, appContext) { return BoxDecoration( shape: BoxShape.rectangle, color: kWhite, @@ -138,7 +138,7 @@ class _ImageInputContainerState extends State { image: new DecorationImage( fit: widget.imageFit, image: new NetworkImage( - resourceDetailDTO.type == ResourceType.image ? appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDetailDTO.id : resourceDetailDTO.data, + resourceDTO.type == ResourceType.image ? appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resourceDTO.id : resourceDTO.data, ), ), boxShadow: [ diff --git a/lib/Components/message_notification.dart b/lib/Components/message_notification.dart index 444a590..5e738a4 100644 --- a/lib/Components/message_notification.dart +++ b/lib/Components/message_notification.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; -showNotification (Color backgroundColor, Color textColor, String text, BuildContext context) { +showNotification (Color backgroundColor, Color textColor, String text, BuildContext context, int duration) { final snackBar = SnackBar( behavior: SnackBarBehavior.floating, - duration: const Duration(milliseconds: 1500), + duration: duration == null ? Duration(milliseconds: 1500) : Duration(milliseconds: duration), width: 280.0, // Width of the SnackBar. backgroundColor: backgroundColor, shape: RoundedRectangleBorder( diff --git a/lib/Components/multi_select_container.dart b/lib/Components/multi_select_container.dart index c7d0f6f..8834f36 100644 --- a/lib/Components/multi_select_container.dart +++ b/lib/Components/multi_select_container.dart @@ -82,7 +82,7 @@ class _MultiSelectChipState extends State { onSelected: (selected) { setState(() { if (widget.isAtLeastOne && widget.selectedValues.length == 1 && widget.selectedValues[0] == item) { - showNotification(Colors.orange, kWhite, 'Au moins une valeur doit être sélectionnée', context); + showNotification(Colors.orange, kWhite, 'Au moins une valeur doit être sélectionnée', context, null); } else { if (widget.isMultiple) { widget.selectedValues.contains(item) diff --git a/lib/Components/resource_tab.dart b/lib/Components/resource_tab.dart index c05152b..6aee23f 100644 --- a/lib/Components/resource_tab.dart +++ b/lib/Components/resource_tab.dart @@ -6,11 +6,11 @@ import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaF import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; class ResourceTab extends StatefulWidget { - final ResourceDetailDTO resourceDetailDTO; + final ResourceDTO resourceDTO; final Function onFileUpload; const ResourceTab({ Key key, - this.resourceDetailDTO, + this.resourceDTO, this.onFileUpload, }) : super(key: key); @@ -51,7 +51,7 @@ class _ResourceTabState extends State with SingleTickerProviderStat ), Expanded( child: TabBarView( - children: getContent(widget.resourceDetailDTO, widget.onFileUpload), + children: getContent(widget.resourceDTO, widget.onFileUpload), controller: _tabController, ), ), @@ -65,27 +65,27 @@ class _ResourceTabState extends State with SingleTickerProviderStat switch(_tabController.index) { case 0: setState(() { - widget.resourceDetailDTO.data = null; - widget.resourceDetailDTO.type = ResourceType.image; + widget.resourceDTO.data = null; + widget.resourceDTO.type = ResourceType.image; }); break; case 1: setState(() { - widget.resourceDetailDTO.data = null; - widget.resourceDetailDTO.type = ResourceType.imageUrl; + widget.resourceDTO.data = null; + widget.resourceDTO.type = ResourceType.imageUrl; }); break; case 2: setState(() { - widget.resourceDetailDTO.data = null; - widget.resourceDetailDTO.type = ResourceType.videoUrl; + widget.resourceDTO.data = null; + widget.resourceDTO.type = ResourceType.videoUrl; }); break; } } } -getContent(ResourceDetailDTO resourceDetailDTO, Function onFileUpload) { +getContent(ResourceDTO resourceDTO, Function onFileUpload) { List tabsToShow = new List(); // Local Image @@ -95,7 +95,7 @@ getContent(ResourceDetailDTO resourceDetailDTO, Function onFileUpload) { child: UploadImageContainer( onChanged: (File file) { onFileUpload(file); - resourceDetailDTO.type = ResourceType.image; + resourceDTO.type = ResourceType.image; } ), ) @@ -106,9 +106,9 @@ getContent(ResourceDetailDTO resourceDetailDTO, Function onFileUpload) { new Padding( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16), child: UploadOnlineResourceContainer( - resourceDetailDTO: resourceDetailDTO, - onChanged: (ResourceDetailDTO value) { - resourceDetailDTO = value; + resourceDTO: resourceDTO, + onChanged: (ResourceDTO value) { + resourceDTO = value; }, ), ) @@ -119,9 +119,9 @@ getContent(ResourceDetailDTO resourceDetailDTO, Function onFileUpload) { new Padding( padding: EdgeInsets.symmetric(horizontal: 8, vertical: 16), child: UploadOnlineResourceContainer( - resourceDetailDTO: resourceDetailDTO, - onChanged: (ResourceDetailDTO value) { - resourceDetailDTO = value; + resourceDTO: resourceDTO, + onChanged: (ResourceDTO value) { + resourceDTO = value; }, ), ) diff --git a/lib/Components/upload_image_container.dart b/lib/Components/upload_image_container.dart index b1df58d..75370be 100644 --- a/lib/Components/upload_image_container.dart +++ b/lib/Components/upload_image_container.dart @@ -143,7 +143,7 @@ class _UploadImageContainerState extends State with Single shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))), child: InkWell( onTap: () async { - filePicker(); + filePicker(); }, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, diff --git a/lib/Components/upload_online_resources_container.dart b/lib/Components/upload_online_resources_container.dart index f46df99..8f54757 100644 --- a/lib/Components/upload_online_resources_container.dart +++ b/lib/Components/upload_online_resources_container.dart @@ -5,11 +5,11 @@ import 'package:managerapi/api.dart'; import 'package:flutter/material.dart'; class UploadOnlineResourceContainer extends StatefulWidget { - final ResourceDetailDTO resourceDetailDTO; - final ValueChanged onChanged; + final ResourceDTO resourceDTO; + final ValueChanged onChanged; const UploadOnlineResourceContainer({ Key key, - this.resourceDetailDTO, + this.resourceDTO, this.onChanged, }) : super(key: key); @@ -33,7 +33,7 @@ class _UploadOnlineResourceContainerState extends StatevCGrj3T8]yG6E'); final iv = IV.fromLength(16); @@ -34,6 +38,36 @@ class SessionHelper { return file.writeAsString(jsonEncode(session.toMap())); } + Future storeConfiguration(ExportConfigurationDTO exportConfigurationDTO) async { + final path = await _localPath; + new File('$path/'+exportConfigurationDTO.label+'.json').createSync(recursive: true); + + // Write the file + File file = File('$path/'+exportConfigurationDTO.label+'.json'); + return file.writeAsString(jsonEncode(exportConfigurationDTO.toJson())); + } + + Future importConfiguration(String path, Client client, context) async { + // Gets the file + File file = File(path); + + final contents = await file.readAsString(); + + ExportConfigurationDTO export = ExportConfigurationDTO.fromJson(jsonDecode(contents)); + try { + String test = await client.configurationApi.configurationImport(export); + if (test.contains("successfully")) { + showNotification(kSuccess, kWhite, 'La configuration a été importée avec succès', context, null); + } else { + showNotification(kPrimaryColor, kWhite, 'Une erreur est survenue lors de l''import de la configuration', context, null); + } + } catch (e) { + if (e.toString().contains('409')) { + showNotification(kSecond, kWhite, 'La configuration existe déjà dans le système', context, null); + } + } + } + Future readSession() async { try { final file = await _localFile; diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index dc192af..89b45c9 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -299,9 +299,9 @@ class _SectionDetailScreenState extends State { appContext.setContext(managerAppContext); if (isTraduction) { - showNotification(Colors.green, kWhite, 'Les traductions de la section ont été sauvegardées avec succès', context); + showNotification(Colors.green, kWhite, 'Les traductions de la section ont été sauvegardées avec succès', context, null); } else { - showNotification(Colors.green, kWhite, 'La section a été sauvegardée avec succès', context); + showNotification(Colors.green, kWhite, 'La section a été sauvegardée avec succès', context, null); } } } diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index f7f4e47..cd73014 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/painting.dart'; @@ -8,6 +10,7 @@ import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/multi_select_container.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; +import 'package:manager_app/Helpers/FileHelper.dart'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Configurations/section_reorderList.dart'; import 'package:manager_app/app_context.dart'; @@ -70,7 +73,28 @@ class _ConfigurationDetailScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(configurationDTO.label, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), + Row( + children: [ + Text(configurationDTO.label, style: TextStyle(fontSize: 30, fontWeight: FontWeight.w400)), + InkWell( + onTap: () async { + try { + // Export config + Client clientAPI = appContext.getContext().clientAPI; + ExportConfigurationDTO export = await clientAPI.configurationApi.configurationExport(configurationDTO.id); + File test = await FileHelper().storeConfiguration(export); + showNotification(Colors.green, kWhite, "l'export de la configuration a réussi, le document se trouve là : " + test.path, context, 3000); + } catch(e) { + showNotification(kPrimaryColor, kWhite, "l'export de la configuration a échoué", context, null); + } + }, + child: Padding( + padding: const EdgeInsets.only(left: 5.0), + child: Icon(Icons.cloud_download, color: kPrimaryColor) + ), + ), + ], + ), Padding( padding: const EdgeInsets.all(5.0), child: Text(DateFormat('dd/MM/yyyy').format(configurationDTO.dateCreation), style: TextStyle(fontSize: 15, fontWeight: FontWeight.w200)), @@ -184,7 +208,7 @@ class _ConfigurationDetailScreenState extends State { } else { return Center( child: Container( - height: size.height * 0.2, + height: size.height * 0.15, child: Loading() ) ); @@ -308,7 +332,7 @@ class _ConfigurationDetailScreenState extends State { managerAppContext.selectedConfiguration = configuration; appContext.setContext(managerAppContext); - showNotification(Colors.green, kWhite, 'La configuration a été sauvegardée avec succès', context); + showNotification(Colors.green, kWhite, 'La configuration a été sauvegardée avec succès', context, null); } Future getConfiguration(ConfigurationDetailScreen widget, Client client) async { diff --git a/lib/Screens/Configurations/configurations_screen.dart b/lib/Screens/Configurations/configurations_screen.dart index eacef42..8f0ce78 100644 --- a/lib/Screens/Configurations/configurations_screen.dart +++ b/lib/Screens/Configurations/configurations_screen.dart @@ -43,7 +43,7 @@ class _ConfigurationsScreenState extends State { if (snapshot.connectionState == ConnectionState.done) { var tempOutput = new List.from(snapshot.data); tempOutput.add(ConfigurationDTO(id: null)); - return bodyGrid(tempOutput, size, appContext); + return bodyGrid(tempOutput, size, appContext, context); } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); } else { @@ -60,7 +60,7 @@ class _ConfigurationsScreenState extends State { } } - Widget bodyGrid(data, Size size, AppContext appContext) { + Widget bodyGrid(data, Size size, AppContext appContext, BuildContext mainContext) { return GridView.builder( shrinkWrap: true, gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6), @@ -70,7 +70,13 @@ class _ConfigurationsScreenState extends State { InkWell( onTap: () { if (data[index].id == null) { - showNewConfiguration(appContext, context); + showNewConfiguration(appContext, (bool) { + if (bool) { + setState(() { + // Thanks future builder for the refresh.. + }); + } + }, context, mainContext); } else { setState(() { ManagerAppContext managerAppContext = appContext.getContext(); diff --git a/lib/Screens/Configurations/new_configuration_popup.dart b/lib/Screens/Configurations/new_configuration_popup.dart index a3d71e7..9cdc0b2 100644 --- a/lib/Screens/Configurations/new_configuration_popup.dart +++ b/lib/Screens/Configurations/new_configuration_popup.dart @@ -1,13 +1,15 @@ +import 'package:filepicker_windows/filepicker_windows.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; +import 'package:manager_app/Helpers/FileHelper.dart'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; -void showNewConfiguration(AppContext appContext, BuildContext context) { +void showNewConfiguration(AppContext appContext, ValueChanged isImport, BuildContext context, BuildContext mainContext) { ConfigurationDTO configurationDTO = new ConfigurationDTO(); showDialog( builder: (BuildContext context) => AlertDialog( @@ -29,6 +31,33 @@ void showNewConfiguration(AppContext appContext, BuildContext context) { ), ], ), + Text("ou"), + Column( + children: [ + Padding( + padding: const EdgeInsets.only(bottom: 5.0), + child: Text("Importer", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)), + ), + InkWell( + onTap: () async { + String result = filePicker(); + if (result != null) { + await FileHelper().importConfiguration(result, appContext.getContext().clientAPI, mainContext); + isImport(true); + Navigator.of(context).pop(); + } + }, + child: Padding( + padding: const EdgeInsets.all(10.0), + child: Icon( + Icons.file_upload, + color: kPrimaryColor, + size: 30 + ), + ), + ) + ] + ) ], ), ), @@ -76,6 +105,21 @@ void showNewConfiguration(AppContext appContext, BuildContext context) { ); } +String filePicker() { + final file = OpenFilePicker() + ..filterSpecification = { + 'Fichier (*.json)': '*.json', + //'Video (*.mp4)': '*.mp4', + //'All Files': '*.*' + } + ..defaultFilterIndex = 0 + ..title = 'Sélectionner un fichier'; + + final result = file.getFile(); + + return result != null ? result.path : null; +} + void create(ConfigurationDTO configurationDTO, AppContext appContext, context) async { if (configurationDTO.label != null) { @@ -84,7 +128,7 @@ void create(ConfigurationDTO configurationDTO, AppContext appContext, context) a managerAppContext.selectedConfiguration = null; appContext.setContext(managerAppContext); - showNotification(Colors.green, kWhite, 'La configuration a été créée avec succès', context); + showNotification(Colors.green, kWhite, 'La configuration a été créée avec succès', context, null); Navigator.of(context).pop(); } diff --git a/lib/Screens/Configurations/new_section_popup.dart b/lib/Screens/Configurations/new_section_popup.dart index 4b4dcdc..f78bd18 100644 --- a/lib/Screens/Configurations/new_section_popup.dart +++ b/lib/Screens/Configurations/new_section_popup.dart @@ -103,7 +103,7 @@ void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context, } managerAppContext.selectedConfiguration.sectionIds.add(newSection.id);*/ appContext.setContext(managerAppContext); - showNotification(Colors.green, kWhite, 'La section a été créée avec succès !', context); + showNotification(Colors.green, kWhite, 'La section a été créée avec succès !', context, null); } else { sendSubSection(newSection); } diff --git a/lib/Screens/Resources/new_resource_popup.dart b/lib/Screens/Resources/new_resource_popup.dart index c51fa0b..e5075fb 100644 --- a/lib/Screens/Resources/new_resource_popup.dart +++ b/lib/Screens/Resources/new_resource_popup.dart @@ -10,7 +10,7 @@ import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; dynamic showNewResource(AppContext appContext, BuildContext context) async { - ResourceDetailDTO resourceDetailDTO = new ResourceDetailDTO(); + ResourceDTO resourceDetailDTO = new ResourceDTO(); Size size = MediaQuery.of(context).size; var fileName; File fileToSend; @@ -42,7 +42,7 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { width: size.width *0.5, height: size.height *0.5, child: ResourceTab( - resourceDetailDTO: resourceDetailDTO, + resourceDTO: resourceDetailDTO, onFileUpload: (File file) { fileToSend = file; }, @@ -87,10 +87,10 @@ dynamic showNewResource(AppContext appContext, BuildContext context) async { if (fileToSend != null) { Navigator.pop(context, [resourceDetailDTO, fileToSend]); } else { - showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context); + showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context, null); } } else { - showNotification(Colors.orange, kWhite, 'Veuillez donner un nom à la ressource', context); + showNotification(Colors.orange, kWhite, 'Veuillez donner un nom à la ressource', context, null); } //Navigator.of(context).pop(); //create(resourceDetailDTO, fileToSend, appContext, context); diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 345e065..e166923 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -85,8 +85,8 @@ Future> getResources(Function onGetResult, bool isImage, dynam return resources; } -Future create(ResourceDetailDTO resourceDetailDTO, File file, AppContext appContext, context) async { - switch(resourceDetailDTO.type) { +Future create(ResourceDTO resourceDTO, File file, AppContext appContext, context) async { + switch(resourceDTO.type) { case ResourceType.image: case ResourceType.video: var request = http.MultipartRequest('POST', Uri.parse(appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/upload")); @@ -101,7 +101,7 @@ Future create(ResourceDetailDTO resourceDetailDTO, File file, AppCo ManagerAppContext managerAppContext = appContext.getContext(); request.headers["authorization"]="Bearer ${managerAppContext.token.accessToken}"; - request.fields['label'] = resourceDetailDTO.label; + request.fields['label'] = resourceDTO.label; request.fields['type'] = ResourceType.image.toString(); var res = await request.send(); @@ -109,35 +109,35 @@ Future create(ResourceDetailDTO resourceDetailDTO, File file, AppCo if (res.statusCode == 200) { var result = ResourceDTO.fromJson(jsonDecode(respStr)); - showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context); + showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context, null); return result; } else { - showNotification(kPrimaryColor, kWhite, 'Une erreur est survenue lors de la création de la ressource', context); + showNotification(kPrimaryColor, kWhite, 'Une erreur est survenue lors de la création de la ressource', context, null); } break; case ResourceType.imageUrl: case ResourceType.videoUrl: - if (resourceDetailDTO.data != null) { + if (resourceDTO.data != null) { // test if Correct url - bool _validURL = Uri.parse(resourceDetailDTO.data).isAbsolute; + bool _validURL = Uri.parse(resourceDTO.data).isAbsolute; if(_validURL) { Navigator.of(context).pop(); - ResourceDTO newResource = await appContext.getContext().clientAPI.resourceApi.resourceCreate(resourceDetailDTO); + ResourceDTO newResource = await appContext.getContext().clientAPI.resourceApi.resourceCreate(resourceDTO); // To refresh only (UGLY COOOOODE) /*ManagerAppContext managerAppContext = appContext.getContext(); appContext.setContext(managerAppContext);*/ - showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context); + showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context, null); return newResource; } else { - showNotification(Colors.orange, kWhite, 'L\'url est invalide', context); + showNotification(Colors.orange, kWhite, 'L\'url est invalide', context, null); } } else { - showNotification(Colors.orange, kWhite, 'Veuillez remplir le champ URL', context); + showNotification(Colors.orange, kWhite, 'Veuillez remplir le champ URL', context, null); } break; } diff --git a/lib/Screens/Resources/show_resource_popup.dart b/lib/Screens/Resources/show_resource_popup.dart index 54c3ec3..144c8dd 100644 --- a/lib/Screens/Resources/show_resource_popup.dart +++ b/lib/Screens/Resources/show_resource_popup.dart @@ -97,7 +97,7 @@ Future delete(ResourceDTO resourceDTO, AppContext appContext, context) asy appContext.setContext(managerAppContext); Navigator.of(context).pop(); - showNotification(Colors.green, kWhite, 'La ressource a été supprimée avec succès', context); + showNotification(Colors.green, kWhite, 'La ressource a été supprimée avec succès', context, null); }, context ); diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index 52c1097..7843ec5 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -4,7 +4,7 @@ import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/rounded_input_field.dart'; import 'package:manager_app/Components/rounded_password_field.dart'; -import 'package:manager_app/Helpers/SessionHelper.dart'; +import 'package:manager_app/Helpers/FileHelper.dart'; import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Models/session.dart'; import 'package:manager_app/Screens/Main/main_screen.dart'; @@ -55,10 +55,10 @@ class _LoginScreenState extends State { Session updatedSession = new Session(rememberMe: isRememberMe, host: host, email: email, password: password); print("REMBER ME TEST SESSIOn"); // update JSON FILE - SessionHelper().writeSession(updatedSession); + FileHelper().writeSession(updatedSession); } - showNotification(Colors.lightGreen, kWhite, 'Connexion réussie', context); + showNotification(Colors.lightGreen, kWhite, 'Connexion réussie', context, null); // Set the appContext if (appContext.getContext() == null) { @@ -89,7 +89,7 @@ class _LoginScreenState extends State { catch (e) { print("error auth"); print(e); - showNotification(Colors.orange, kWhite, 'Un problème est survenu lors de la connexion', context); + showNotification(Colors.orange, kWhite, 'Un problème est survenu lors de la connexion', context, null); setState(() { isLoading = false; diff --git a/lib/constants.dart b/lib/constants.dart index 760a0d2..86d616b 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -11,6 +11,7 @@ const kTextLightColor = Color(0xFFFCFDFD); const kSecond = Color(0xFFC2C9D6); const kWhite = Color(0xFFFFFFFF); const kBlack = Color(0xFF000000); +const kSuccess = Color(0xFF8bc34a); const List section_types = ["Map", "Slider", "Video", "Web", "Menu"]; const List map_types = ["none", "normal", "satellite", "terrain", "hybrid"]; diff --git a/lib/main.dart b/lib/main.dart index 3fec71b..7be27dc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,7 +4,7 @@ import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Main/main_screen.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; -import 'Helpers/SessionHelper.dart'; +import 'Helpers/FileHelper.dart'; import 'Models/session.dart'; import 'Screens/login_screen.dart'; import 'app_context.dart'; @@ -75,7 +75,7 @@ class _MyAppState extends State { } Future loadJsonSessionFile() async { - Session session = await SessionHelper().readSession(); + Session session = await FileHelper().readSession(); print(session); return session; } diff --git a/manager_api/.openapi-generator/FILES b/manager_api/.openapi-generator/FILES index 5767340..9e91dd4 100644 --- a/manager_api/.openapi-generator/FILES +++ b/manager_api/.openapi-generator/FILES @@ -8,6 +8,8 @@ doc/DeviceApi.md doc/DeviceDTO.md doc/DeviceDetailDTO.md doc/DeviceDetailDTOAllOf.md +doc/ExportConfigurationDTO.md +doc/ExportConfigurationDTOAllOf.md doc/GeoPointDTO.md doc/ImageDTO.md doc/ImageGeoPoint.md @@ -18,7 +20,6 @@ doc/MenuDTO.md doc/PlayerMessageDTO.md doc/ResourceApi.md doc/ResourceDTO.md -doc/ResourceDetailDTO.md doc/ResourceType.md doc/SectionApi.md doc/SectionDTO.md @@ -51,6 +52,8 @@ lib/model/configuration_dto.dart lib/model/device_detail_dto.dart lib/model/device_detail_dto_all_of.dart lib/model/device_dto.dart +lib/model/export_configuration_dto.dart +lib/model/export_configuration_dto_all_of.dart lib/model/geo_point_dto.dart lib/model/image_dto.dart lib/model/image_geo_point.dart @@ -59,7 +62,6 @@ lib/model/map_dto.dart lib/model/map_type_app.dart lib/model/menu_dto.dart lib/model/player_message_dto.dart -lib/model/resource_detail_dto.dart lib/model/resource_dto.dart lib/model/resource_type.dart lib/model/section_dto.dart @@ -72,3 +74,5 @@ lib/model/user_detail_dto.dart lib/model/video_dto.dart lib/model/web_dto.dart pubspec.yaml +test/export_configuration_dto_all_of_test.dart +test/export_configuration_dto_test.dart diff --git a/manager_api/README.md b/manager_api/README.md index 269c300..cbc1dd4 100644 --- a/manager_api/README.md +++ b/manager_api/README.md @@ -68,8 +68,10 @@ Class | Method | HTTP request | Description *AuthenticationApi* | [**authenticationAuthenticateWithJson**](doc\/AuthenticationApi.md#authenticationauthenticatewithjson) | **POST** /api/Authentication/Authenticate | *ConfigurationApi* | [**configurationCreate**](doc\/ConfigurationApi.md#configurationcreate) | **POST** /api/Configuration | *ConfigurationApi* | [**configurationDelete**](doc\/ConfigurationApi.md#configurationdelete) | **DELETE** /api/Configuration/{id} | +*ConfigurationApi* | [**configurationExport**](doc\/ConfigurationApi.md#configurationexport) | **GET** /api/Configuration/{id}/export | *ConfigurationApi* | [**configurationGet**](doc\/ConfigurationApi.md#configurationget) | **GET** /api/Configuration | *ConfigurationApi* | [**configurationGetDetail**](doc\/ConfigurationApi.md#configurationgetdetail) | **GET** /api/Configuration/{id} | +*ConfigurationApi* | [**configurationImport**](doc\/ConfigurationApi.md#configurationimport) | **POST** /api/Configuration/import | *ConfigurationApi* | [**configurationUpdate**](doc\/ConfigurationApi.md#configurationupdate) | **PUT** /api/Configuration | *DeviceApi* | [**deviceCreate**](doc\/DeviceApi.md#devicecreate) | **POST** /api/Device | *DeviceApi* | [**deviceDelete**](doc\/DeviceApi.md#devicedelete) | **DELETE** /api/Device/{id} | @@ -112,6 +114,8 @@ Class | Method | HTTP request | Description - [DeviceDTO](doc\/DeviceDTO.md) - [DeviceDetailDTO](doc\/DeviceDetailDTO.md) - [DeviceDetailDTOAllOf](doc\/DeviceDetailDTOAllOf.md) + - [ExportConfigurationDTO](doc\/ExportConfigurationDTO.md) + - [ExportConfigurationDTOAllOf](doc\/ExportConfigurationDTOAllOf.md) - [GeoPointDTO](doc\/GeoPointDTO.md) - [ImageDTO](doc\/ImageDTO.md) - [ImageGeoPoint](doc\/ImageGeoPoint.md) @@ -121,7 +125,6 @@ Class | Method | HTTP request | Description - [MenuDTO](doc\/MenuDTO.md) - [PlayerMessageDTO](doc\/PlayerMessageDTO.md) - [ResourceDTO](doc\/ResourceDTO.md) - - [ResourceDetailDTO](doc\/ResourceDetailDTO.md) - [ResourceType](doc\/ResourceType.md) - [SectionDTO](doc\/SectionDTO.md) - [SectionType](doc\/SectionType.md) diff --git a/manager_api/doc/ConfigurationApi.md b/manager_api/doc/ConfigurationApi.md index 7eed9f1..437bf84 100644 --- a/manager_api/doc/ConfigurationApi.md +++ b/manager_api/doc/ConfigurationApi.md @@ -11,8 +11,10 @@ Method | HTTP request | Description ------------- | ------------- | ------------- [**configurationCreate**](ConfigurationApi.md#configurationcreate) | **POST** /api/Configuration | [**configurationDelete**](ConfigurationApi.md#configurationdelete) | **DELETE** /api/Configuration/{id} | +[**configurationExport**](ConfigurationApi.md#configurationexport) | **GET** /api/Configuration/{id}/export | [**configurationGet**](ConfigurationApi.md#configurationget) | **GET** /api/Configuration | [**configurationGetDetail**](ConfigurationApi.md#configurationgetdetail) | **GET** /api/Configuration/{id} | +[**configurationImport**](ConfigurationApi.md#configurationimport) | **POST** /api/Configuration/import | [**configurationUpdate**](ConfigurationApi.md#configurationupdate) | **PUT** /api/Configuration | @@ -102,6 +104,49 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **configurationExport** +> ExportConfigurationDTO configurationExport(id) + + + +### Example +```dart +import 'package:managerapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: bearer +//defaultApiClient.getAuthentication('bearer').accessToken = 'YOUR_ACCESS_TOKEN'; + +final api_instance = ConfigurationApi(); +final id = id_example; // String | + +try { + final result = api_instance.configurationExport(id); + print(result); +} catch (e) { + print('Exception when calling ConfigurationApi->configurationExport: $e\n'); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **id** | **String**| | + +### Return type + +[**ExportConfigurationDTO**](ExportConfigurationDTO.md) + +### Authorization + +[bearer](../README.md#bearer) + +### HTTP request headers + + - **Content-Type**: Not defined + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **configurationGet** > List configurationGet() @@ -184,6 +229,49 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **configurationImport** +> String configurationImport(exportConfigurationDTO) + + + +### Example +```dart +import 'package:managerapi/api.dart'; +// TODO Configure OAuth2 access token for authorization: bearer +//defaultApiClient.getAuthentication('bearer').accessToken = 'YOUR_ACCESS_TOKEN'; + +final api_instance = ConfigurationApi(); +final exportConfigurationDTO = ExportConfigurationDTO(); // ExportConfigurationDTO | + +try { + final result = api_instance.configurationImport(exportConfigurationDTO); + print(result); +} catch (e) { + print('Exception when calling ConfigurationApi->configurationImport: $e\n'); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **exportConfigurationDTO** | [**ExportConfigurationDTO**](ExportConfigurationDTO.md)| | + +### Return type + +**String** + +### Authorization + +[bearer](../README.md#bearer) + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + # **configurationUpdate** > ConfigurationDTO configurationUpdate(configurationDTO) diff --git a/manager_api/doc/ExportConfigurationDTO.md b/manager_api/doc/ExportConfigurationDTO.md new file mode 100644 index 0000000..7c7c3f9 --- /dev/null +++ b/manager_api/doc/ExportConfigurationDTO.md @@ -0,0 +1,22 @@ +# managerapi.model.ExportConfigurationDTO + +## Load the model package +```dart +import 'package:managerapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **String** | | [optional] +**label** | **String** | | [optional] +**primaryColor** | **String** | | [optional] +**secondaryColor** | **String** | | [optional] +**languages** | **List** | | [optional] [default to const []] +**dateCreation** | [**DateTime**](DateTime.md) | | [optional] +**sections** | [**List**](SectionDTO.md) | | [optional] [default to const []] +**resources** | [**List**](ResourceDTO.md) | | [optional] [default to const []] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/manager_api/doc/ExportConfigurationDTOAllOf.md b/manager_api/doc/ExportConfigurationDTOAllOf.md new file mode 100644 index 0000000..e369543 --- /dev/null +++ b/manager_api/doc/ExportConfigurationDTOAllOf.md @@ -0,0 +1,16 @@ +# managerapi.model.ExportConfigurationDTOAllOf + +## Load the model package +```dart +import 'package:managerapi/api.dart'; +``` + +## Properties +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**sections** | [**List**](SectionDTO.md) | | [optional] [default to const []] +**resources** | [**List**](ResourceDTO.md) | | [optional] [default to const []] + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/manager_api/doc/ResourceApi.md b/manager_api/doc/ResourceApi.md index c7a88e8..455ec34 100644 --- a/manager_api/doc/ResourceApi.md +++ b/manager_api/doc/ResourceApi.md @@ -19,7 +19,7 @@ Method | HTTP request | Description # **resourceCreate** -> ResourceDetailDTO resourceCreate(resourceDetailDTO) +> ResourceDTO resourceCreate(resourceDTO) @@ -30,10 +30,10 @@ import 'package:managerapi/api.dart'; //defaultApiClient.getAuthentication('bearer').accessToken = 'YOUR_ACCESS_TOKEN'; final api_instance = ResourceApi(); -final resourceDetailDTO = ResourceDetailDTO(); // ResourceDetailDTO | +final resourceDTO = ResourceDTO(); // ResourceDTO | try { - final result = api_instance.resourceCreate(resourceDetailDTO); + final result = api_instance.resourceCreate(resourceDTO); print(result); } catch (e) { print('Exception when calling ResourceApi->resourceCreate: $e\n'); @@ -44,11 +44,11 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **resourceDetailDTO** | [**ResourceDetailDTO**](ResourceDetailDTO.md)| | + **resourceDTO** | [**ResourceDTO**](ResourceDTO.md)| | ### Return type -[**ResourceDetailDTO**](ResourceDetailDTO.md) +[**ResourceDTO**](ResourceDTO.md) ### Authorization @@ -144,7 +144,7 @@ This endpoint does not need any parameter. [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **resourceGetDetail** -> ResourceDetailDTO resourceGetDetail(id) +> ResourceDTO resourceGetDetail(id) @@ -173,7 +173,7 @@ Name | Type | Description | Notes ### Return type -[**ResourceDetailDTO**](ResourceDetailDTO.md) +[**ResourceDTO**](ResourceDTO.md) ### Authorization @@ -230,7 +230,7 @@ Name | Type | Description | Notes [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **resourceUpdate** -> ResourceDetailDTO resourceUpdate(resourceDetailDTO) +> ResourceDTO resourceUpdate(resourceDTO) @@ -241,10 +241,10 @@ import 'package:managerapi/api.dart'; //defaultApiClient.getAuthentication('bearer').accessToken = 'YOUR_ACCESS_TOKEN'; final api_instance = ResourceApi(); -final resourceDetailDTO = ResourceDetailDTO(); // ResourceDetailDTO | +final resourceDTO = ResourceDTO(); // ResourceDTO | try { - final result = api_instance.resourceUpdate(resourceDetailDTO); + final result = api_instance.resourceUpdate(resourceDTO); print(result); } catch (e) { print('Exception when calling ResourceApi->resourceUpdate: $e\n'); @@ -255,11 +255,11 @@ try { Name | Type | Description | Notes ------------- | ------------- | ------------- | ------------- - **resourceDetailDTO** | [**ResourceDetailDTO**](ResourceDetailDTO.md)| | + **resourceDTO** | [**ResourceDTO**](ResourceDTO.md)| | ### Return type -[**ResourceDetailDTO**](ResourceDetailDTO.md) +[**ResourceDTO**](ResourceDTO.md) ### Authorization diff --git a/manager_api/doc/ResourceDTO.md b/manager_api/doc/ResourceDTO.md index 91f91a8..d2acd16 100644 --- a/manager_api/doc/ResourceDTO.md +++ b/manager_api/doc/ResourceDTO.md @@ -11,6 +11,7 @@ Name | Type | Description | Notes **id** | **String** | | [optional] **type** | [**ResourceType**](ResourceType.md) | | [optional] **label** | **String** | | [optional] +**dateCreation** | [**DateTime**](DateTime.md) | | [optional] **data** | **String** | | [optional] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/manager_api/lib/api.dart b/manager_api/lib/api.dart index ad57cca..13f6dd1 100644 --- a/manager_api/lib/api.dart +++ b/manager_api/lib/api.dart @@ -38,6 +38,8 @@ part 'model/configuration_dto.dart'; part 'model/device_dto.dart'; part 'model/device_detail_dto.dart'; part 'model/device_detail_dto_all_of.dart'; +part 'model/export_configuration_dto.dart'; +part 'model/export_configuration_dto_all_of.dart'; part 'model/geo_point_dto.dart'; part 'model/image_dto.dart'; part 'model/image_geo_point.dart'; @@ -47,7 +49,6 @@ part 'model/map_type_app.dart'; part 'model/menu_dto.dart'; part 'model/player_message_dto.dart'; part 'model/resource_dto.dart'; -part 'model/resource_detail_dto.dart'; part 'model/resource_type.dart'; part 'model/section_dto.dart'; part 'model/section_type.dart'; diff --git a/manager_api/lib/api/configuration_api.dart b/manager_api/lib/api/configuration_api.dart index dfa4bd8..342f0f0 100644 --- a/manager_api/lib/api/configuration_api.dart +++ b/manager_api/lib/api/configuration_api.dart @@ -142,6 +142,70 @@ class ConfigurationApi { return Future.value(null); } + /// Performs an HTTP 'GET /api/Configuration/{id}/export' operation and returns the [Response]. + /// Parameters: + /// + /// * [String] id (required): + Future configurationExportWithHttpInfo(String id) async { + // Verify required params are set. + if (id == null) { + throw ApiException(HttpStatus.badRequest, 'Missing required param: id'); + } + + final path = r'/api/Configuration/{id}/export' + .replaceAll('{' + 'id' + '}', id.toString()); + + Object postBody; + + final queryParams = []; + final headerParams = {}; + final formParams = {}; + + final contentTypes = []; + final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; + final authNames = ['bearer']; + + if ( + nullableContentType != null && + nullableContentType.toLowerCase().startsWith('multipart/form-data') + ) { + bool hasFields = false; + final mp = MultipartRequest(null, null); + if (hasFields) { + postBody = mp; + } + } else { + } + + return await apiClient.invokeAPI( + path, + 'GET', + queryParams, + postBody, + headerParams, + formParams, + nullableContentType, + authNames, + ); + } + + /// Parameters: + /// + /// * [String] id (required): + Future configurationExport(String id) async { + final response = await configurationExportWithHttpInfo(id); + if (response.statusCode >= HttpStatus.badRequest) { + throw ApiException(response.statusCode, _decodeBodyBytes(response)); + } + // When a remote server returns no body with a status of 204, we shall not decode it. + // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" + // FormatException when trying to decode an empty string. + if (response.body != null && response.statusCode != HttpStatus.noContent) { + return apiClient.deserialize(_decodeBodyBytes(response), 'ExportConfigurationDTO') as ExportConfigurationDTO; + } + return Future.value(null); + } + /// Performs an HTTP 'GET /api/Configuration' operation and returns the [Response]. Future configurationGetWithHttpInfo() async { final path = r'/api/Configuration'; @@ -260,6 +324,69 @@ class ConfigurationApi { return Future.value(null); } + /// Performs an HTTP 'POST /api/Configuration/import' operation and returns the [Response]. + /// Parameters: + /// + /// * [ExportConfigurationDTO] exportConfigurationDTO (required): + Future configurationImportWithHttpInfo(ExportConfigurationDTO exportConfigurationDTO) async { + // Verify required params are set. + if (exportConfigurationDTO == null) { + throw ApiException(HttpStatus.badRequest, 'Missing required param: exportConfigurationDTO'); + } + + final path = r'/api/Configuration/import'; + + Object postBody = exportConfigurationDTO; + + final queryParams = []; + final headerParams = {}; + final formParams = {}; + + final contentTypes = ['application/json']; + final nullableContentType = contentTypes.isNotEmpty ? contentTypes[0] : null; + final authNames = ['bearer']; + + if ( + nullableContentType != null && + nullableContentType.toLowerCase().startsWith('multipart/form-data') + ) { + bool hasFields = false; + final mp = MultipartRequest(null, null); + if (hasFields) { + postBody = mp; + } + } else { + } + + return await apiClient.invokeAPI( + path, + 'POST', + queryParams, + postBody, + headerParams, + formParams, + nullableContentType, + authNames, + ); + } + + /// Parameters: + /// + /// * [ExportConfigurationDTO] exportConfigurationDTO (required): + Future configurationImport(ExportConfigurationDTO exportConfigurationDTO) async { + final response = await configurationImportWithHttpInfo(exportConfigurationDTO); + if (response.statusCode >= HttpStatus.badRequest) { + throw ApiException(response.statusCode, _decodeBodyBytes(response)); + } + // When a remote server returns no body with a status of 204, we shall not decode it. + // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" + // FormatException when trying to decode an empty string. + if (response.body != null && response.statusCode != HttpStatus.noContent) { + return apiClient.deserialize(_decodeBodyBytes(response), 'String') as String; + } + return Future.value(null); + } + /// Performs an HTTP 'PUT /api/Configuration' operation and returns the [Response]. /// Parameters: /// diff --git a/manager_api/lib/api/resource_api.dart b/manager_api/lib/api/resource_api.dart index 60376c1..6423466 100644 --- a/manager_api/lib/api/resource_api.dart +++ b/manager_api/lib/api/resource_api.dart @@ -18,16 +18,16 @@ class ResourceApi { /// Performs an HTTP 'POST /api/Resource' operation and returns the [Response]. /// Parameters: /// - /// * [ResourceDetailDTO] resourceDetailDTO (required): - Future resourceCreateWithHttpInfo(ResourceDetailDTO resourceDetailDTO) async { + /// * [ResourceDTO] resourceDTO (required): + Future resourceCreateWithHttpInfo(ResourceDTO resourceDTO) async { // Verify required params are set. - if (resourceDetailDTO == null) { - throw ApiException(HttpStatus.badRequest, 'Missing required param: resourceDetailDTO'); + if (resourceDTO == null) { + throw ApiException(HttpStatus.badRequest, 'Missing required param: resourceDTO'); } final path = r'/api/Resource'; - Object postBody = resourceDetailDTO; + Object postBody = resourceDTO; final queryParams = []; final headerParams = {}; @@ -63,9 +63,9 @@ class ResourceApi { /// Parameters: /// - /// * [ResourceDetailDTO] resourceDetailDTO (required): - Future resourceCreate(ResourceDetailDTO resourceDetailDTO) async { - final response = await resourceCreateWithHttpInfo(resourceDetailDTO); + /// * [ResourceDTO] resourceDTO (required): + Future resourceCreate(ResourceDTO resourceDTO) async { + final response = await resourceCreateWithHttpInfo(resourceDTO); if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } @@ -73,9 +73,9 @@ class ResourceApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ResourceDetailDTO') as ResourceDetailDTO; + return apiClient.deserialize(_decodeBodyBytes(response), 'ResourceDTO') as ResourceDTO; } - return Future.value(null); + return Future.value(null); } /// Performs an HTTP 'DELETE /api/Resource/{id}' operation and returns the [Response]. @@ -246,7 +246,7 @@ class ResourceApi { /// Parameters: /// /// * [String] id (required): - Future resourceGetDetail(String id) async { + Future resourceGetDetail(String id) async { final response = await resourceGetDetailWithHttpInfo(id); if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); @@ -255,9 +255,9 @@ class ResourceApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ResourceDetailDTO') as ResourceDetailDTO; + return apiClient.deserialize(_decodeBodyBytes(response), 'ResourceDTO') as ResourceDTO; } - return Future.value(null); + return Future.value(null); } /// Performs an HTTP 'GET /api/Resource/{id}' operation and returns the [Response]. @@ -327,16 +327,16 @@ class ResourceApi { /// Performs an HTTP 'PUT /api/Resource' operation and returns the [Response]. /// Parameters: /// - /// * [ResourceDetailDTO] resourceDetailDTO (required): - Future resourceUpdateWithHttpInfo(ResourceDetailDTO resourceDetailDTO) async { + /// * [ResourceDTO] resourceDTO (required): + Future resourceUpdateWithHttpInfo(ResourceDTO resourceDTO) async { // Verify required params are set. - if (resourceDetailDTO == null) { - throw ApiException(HttpStatus.badRequest, 'Missing required param: resourceDetailDTO'); + if (resourceDTO == null) { + throw ApiException(HttpStatus.badRequest, 'Missing required param: resourceDTO'); } final path = r'/api/Resource'; - Object postBody = resourceDetailDTO; + Object postBody = resourceDTO; final queryParams = []; final headerParams = {}; @@ -372,9 +372,9 @@ class ResourceApi { /// Parameters: /// - /// * [ResourceDetailDTO] resourceDetailDTO (required): - Future resourceUpdate(ResourceDetailDTO resourceDetailDTO) async { - final response = await resourceUpdateWithHttpInfo(resourceDetailDTO); + /// * [ResourceDTO] resourceDTO (required): + Future resourceUpdate(ResourceDTO resourceDTO) async { + final response = await resourceUpdateWithHttpInfo(resourceDTO); if (response.statusCode >= HttpStatus.badRequest) { throw ApiException(response.statusCode, _decodeBodyBytes(response)); } @@ -382,9 +382,9 @@ class ResourceApi { // At the time of writing this, `dart:convert` will throw an "Unexpected end of input" // FormatException when trying to decode an empty string. if (response.body != null && response.statusCode != HttpStatus.noContent) { - return apiClient.deserialize(_decodeBodyBytes(response), 'ResourceDetailDTO') as ResourceDetailDTO; + return apiClient.deserialize(_decodeBodyBytes(response), 'ResourceDTO') as ResourceDTO; } - return Future.value(null); + return Future.value(null); } /// Performs an HTTP 'POST /api/Resource/upload' operation and returns the [Response]. diff --git a/manager_api/lib/api_client.dart b/manager_api/lib/api_client.dart index 4fe0d20..834e473 100644 --- a/manager_api/lib/api_client.dart +++ b/manager_api/lib/api_client.dart @@ -164,6 +164,10 @@ class ApiClient { return DeviceDetailDTO.fromJson(value); case 'DeviceDetailDTOAllOf': return DeviceDetailDTOAllOf.fromJson(value); + case 'ExportConfigurationDTO': + return ExportConfigurationDTO.fromJson(value); + case 'ExportConfigurationDTOAllOf': + return ExportConfigurationDTOAllOf.fromJson(value); case 'GeoPointDTO': return GeoPointDTO.fromJson(value); case 'ImageDTO': @@ -183,8 +187,6 @@ class ApiClient { return PlayerMessageDTO.fromJson(value); case 'ResourceDTO': return ResourceDTO.fromJson(value); - case 'ResourceDetailDTO': - return ResourceDetailDTO.fromJson(value); case 'ResourceType': return ResourceTypeTypeTransformer().decode(value); diff --git a/manager_api/lib/model/export_configuration_dto.dart b/manager_api/lib/model/export_configuration_dto.dart new file mode 100644 index 0000000..3e2a8a2 --- /dev/null +++ b/manager_api/lib/model/export_configuration_dto.dart @@ -0,0 +1,138 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.0 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: lines_longer_than_80_chars + +part of openapi.api; + +class ExportConfigurationDTO { + /// Returns a new [ExportConfigurationDTO] instance. + ExportConfigurationDTO({ + this.id, + this.label, + this.primaryColor, + this.secondaryColor, + this.languages, + this.dateCreation, + this.sections, + this.resources, + }); + + String id; + + String label; + + String primaryColor; + + String secondaryColor; + + List languages; + + DateTime dateCreation; + + List sections; + + List resources; + + @override + bool operator ==(Object other) => identical(this, other) || other is ExportConfigurationDTO && + other.id == id && + other.label == label && + other.primaryColor == primaryColor && + other.secondaryColor == secondaryColor && + other.languages == languages && + other.dateCreation == dateCreation && + other.sections == sections && + other.resources == resources; + + @override + int get hashCode => + (id == null ? 0 : id.hashCode) + + (label == null ? 0 : label.hashCode) + + (primaryColor == null ? 0 : primaryColor.hashCode) + + (secondaryColor == null ? 0 : secondaryColor.hashCode) + + (languages == null ? 0 : languages.hashCode) + + (dateCreation == null ? 0 : dateCreation.hashCode) + + (sections == null ? 0 : sections.hashCode) + + (resources == null ? 0 : resources.hashCode); + + @override + String toString() => 'ExportConfigurationDTO[id=$id, label=$label, primaryColor=$primaryColor, secondaryColor=$secondaryColor, languages=$languages, dateCreation=$dateCreation, sections=$sections, resources=$resources]'; + + Map toJson() { + final json = {}; + if (id != null) { + json[r'id'] = id; + } + if (label != null) { + json[r'label'] = label; + } + if (primaryColor != null) { + json[r'primaryColor'] = primaryColor; + } + if (secondaryColor != null) { + json[r'secondaryColor'] = secondaryColor; + } + if (languages != null) { + json[r'languages'] = languages; + } + if (dateCreation != null) { + json[r'dateCreation'] = dateCreation.toUtc().toIso8601String(); + } + if (sections != null) { + json[r'sections'] = sections; + } + if (resources != null) { + json[r'resources'] = resources; + } + return json; + } + + /// Returns a new [ExportConfigurationDTO] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static ExportConfigurationDTO fromJson(Map json) => json == null + ? null + : ExportConfigurationDTO( + id: json[r'id'], + label: json[r'label'], + primaryColor: json[r'primaryColor'], + secondaryColor: json[r'secondaryColor'], + languages: json[r'languages'] == null + ? null + : (json[r'languages'] as List).cast(), + dateCreation: json[r'dateCreation'] == null + ? null + : DateTime.parse(json[r'dateCreation']), + sections: SectionDTO.listFromJson(json[r'sections']), + resources: ResourceDTO.listFromJson(json[r'resources']), + ); + + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => + json == null || json.isEmpty + ? true == emptyIsNull ? null : [] + : json.map((v) => ExportConfigurationDTO.fromJson(v)).toList(growable: true == growable); + + static Map mapFromJson(Map json) { + final map = {}; + if (json != null && json.isNotEmpty) { + json.forEach((String key, dynamic v) => map[key] = ExportConfigurationDTO.fromJson(v)); + } + return map; + } + + // maps a json object with a list of ExportConfigurationDTO-objects as value to a dart map + static Map> mapListFromJson(Map json, {bool emptyIsNull, bool growable,}) { + final map = >{}; + if (json != null && json.isNotEmpty) { + json.forEach((String key, dynamic v) { + map[key] = ExportConfigurationDTO.listFromJson(v, emptyIsNull: emptyIsNull, growable: growable); + }); + } + return map; + } +} + diff --git a/manager_api/lib/model/export_configuration_dto_all_of.dart b/manager_api/lib/model/export_configuration_dto_all_of.dart new file mode 100644 index 0000000..4d93a48 --- /dev/null +++ b/manager_api/lib/model/export_configuration_dto_all_of.dart @@ -0,0 +1,80 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.0 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: lines_longer_than_80_chars + +part of openapi.api; + +class ExportConfigurationDTOAllOf { + /// Returns a new [ExportConfigurationDTOAllOf] instance. + ExportConfigurationDTOAllOf({ + this.sections, + this.resources, + }); + + List sections; + + List resources; + + @override + bool operator ==(Object other) => identical(this, other) || other is ExportConfigurationDTOAllOf && + other.sections == sections && + other.resources == resources; + + @override + int get hashCode => + (sections == null ? 0 : sections.hashCode) + + (resources == null ? 0 : resources.hashCode); + + @override + String toString() => 'ExportConfigurationDTOAllOf[sections=$sections, resources=$resources]'; + + Map toJson() { + final json = {}; + if (sections != null) { + json[r'sections'] = sections; + } + if (resources != null) { + json[r'resources'] = resources; + } + return json; + } + + /// Returns a new [ExportConfigurationDTOAllOf] instance and imports its values from + /// [json] if it's non-null, null if [json] is null. + static ExportConfigurationDTOAllOf fromJson(Map json) => json == null + ? null + : ExportConfigurationDTOAllOf( + sections: SectionDTO.listFromJson(json[r'sections']), + resources: ResourceDTO.listFromJson(json[r'resources']), + ); + + static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => + json == null || json.isEmpty + ? true == emptyIsNull ? null : [] + : json.map((v) => ExportConfigurationDTOAllOf.fromJson(v)).toList(growable: true == growable); + + static Map mapFromJson(Map json) { + final map = {}; + if (json != null && json.isNotEmpty) { + json.forEach((String key, dynamic v) => map[key] = ExportConfigurationDTOAllOf.fromJson(v)); + } + return map; + } + + // maps a json object with a list of ExportConfigurationDTOAllOf-objects as value to a dart map + static Map> mapListFromJson(Map json, {bool emptyIsNull, bool growable,}) { + final map = >{}; + if (json != null && json.isNotEmpty) { + json.forEach((String key, dynamic v) { + map[key] = ExportConfigurationDTOAllOf.listFromJson(v, emptyIsNull: emptyIsNull, growable: growable); + }); + } + return map; + } +} + diff --git a/manager_api/lib/model/resource_dto.dart b/manager_api/lib/model/resource_dto.dart index f5d5447..81f6382 100644 --- a/manager_api/lib/model/resource_dto.dart +++ b/manager_api/lib/model/resource_dto.dart @@ -15,6 +15,7 @@ class ResourceDTO { this.id, this.type, this.label, + this.dateCreation, this.data, }); @@ -24,6 +25,8 @@ class ResourceDTO { String label; + DateTime dateCreation; + String data; @override @@ -31,6 +34,7 @@ class ResourceDTO { other.id == id && other.type == type && other.label == label && + other.dateCreation == dateCreation && other.data == data; @override @@ -38,10 +42,11 @@ class ResourceDTO { (id == null ? 0 : id.hashCode) + (type == null ? 0 : type.hashCode) + (label == null ? 0 : label.hashCode) + + (dateCreation == null ? 0 : dateCreation.hashCode) + (data == null ? 0 : data.hashCode); @override - String toString() => 'ResourceDTO[id=$id, type=$type, label=$label, data=$data]'; + String toString() => 'ResourceDTO[id=$id, type=$type, label=$label, dateCreation=$dateCreation, data=$data]'; Map toJson() { final json = {}; @@ -54,6 +59,9 @@ class ResourceDTO { if (label != null) { json[r'label'] = label; } + if (dateCreation != null) { + json[r'dateCreation'] = dateCreation.toUtc().toIso8601String(); + } if (data != null) { json[r'data'] = data; } @@ -68,6 +76,9 @@ class ResourceDTO { id: json[r'id'], type: ResourceType.fromJson(json[r'type']), label: json[r'label'], + dateCreation: json[r'dateCreation'] == null + ? null + : DateTime.parse(json[r'dateCreation']), data: json[r'data'], ); diff --git a/manager_api/swagger.yaml b/manager_api/swagger.yaml index e6e57ee..fb333d9 100644 --- a/manager_api/swagger.yaml +++ b/manager_api/swagger.yaml @@ -176,6 +176,92 @@ paths: type: string security: - bearer: [] + /api/Configuration/{id}/export: + get: + tags: + - Configuration + operationId: Configuration_Export + parameters: + - name: id + in: path + required: true + schema: + type: string + nullable: true + x-position: 1 + responses: + '200': + description: '' + content: + application/json: + schema: + $ref: '#/components/schemas/ExportConfigurationDTO' + '400': + description: '' + content: + application/json: + schema: + type: string + '404': + description: '' + content: + application/json: + schema: + type: string + '500': + description: '' + content: + application/json: + schema: + type: string + security: + - bearer: [] + /api/Configuration/import: + post: + tags: + - Configuration + operationId: Configuration_Import + requestBody: + x-name: exportConfiguration + content: + application/json: + schema: + $ref: '#/components/schemas/ExportConfigurationDTO' + required: true + x-position: 1 + responses: + '202': + description: '' + content: + application/json: + schema: + type: string + '400': + description: '' + content: + application/json: + schema: + type: string + '404': + description: '' + content: + application/json: + schema: + type: string + '409': + description: '' + content: + application/json: + schema: + type: string + '500': + description: '' + content: + application/json: + schema: + type: string + security: + - bearer: [] /api/Device: get: tags: @@ -423,7 +509,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ResourceDetailDTO' + $ref: '#/components/schemas/ResourceDTO' required: true x-position: 1 responses: @@ -432,7 +518,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ResourceDetailDTO' + $ref: '#/components/schemas/ResourceDTO' '400': description: '' content: @@ -462,7 +548,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ResourceDetailDTO' + $ref: '#/components/schemas/ResourceDTO' required: true x-position: 1 responses: @@ -471,7 +557,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ResourceDetailDTO' + $ref: '#/components/schemas/ResourceDTO' '400': description: '' content: @@ -511,7 +597,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/ResourceDetailDTO' + $ref: '#/components/schemas/ResourceDTO' '404': description: '' content: @@ -1305,103 +1391,22 @@ components: dateCreation: type: string format: date-time - DeviceDTO: - type: object - additionalProperties: false - properties: - id: - type: string - nullable: true - identifier: - type: string - nullable: true - name: - type: string - nullable: true - ipAddressWLAN: - type: string - nullable: true - ipAddressETH: - type: string - nullable: true - configurationId: - type: string - nullable: true - configuration: - type: string - nullable: true - connected: - type: boolean - dateCreation: - type: string - format: date-time - dateUpdate: - type: string - format: date-time - DeviceDetailDTO: + ExportConfigurationDTO: allOf: - - $ref: '#/components/schemas/DeviceDTO' + - $ref: '#/components/schemas/ConfigurationDTO' - type: object additionalProperties: false properties: - connectionLevel: - type: string + sections: + type: array nullable: true - lastConnectionLevel: - type: string - format: date-time - batteryLevel: - type: string + items: + $ref: '#/components/schemas/SectionDTO' + resources: + type: array nullable: true - lastBatteryLevel: - type: string - format: date-time - ResourceDTO: - type: object - additionalProperties: false - properties: - id: - type: string - nullable: true - type: - $ref: '#/components/schemas/ResourceType' - label: - type: string - nullable: true - data: - type: string - nullable: true - ResourceType: - type: string - description: '' - x-enumNames: - - Image - - Video - - ImageUrl - - VideoUrl - enum: - - Image - - Video - - ImageUrl - - VideoUrl - ResourceDetailDTO: - type: object - additionalProperties: false - properties: - id: - type: string - nullable: true - type: - $ref: '#/components/schemas/ResourceType' - label: - type: string - nullable: true - dateCreation: - type: string - format: date-time - data: - type: string - nullable: true + items: + $ref: '#/components/schemas/ResourceDTO' SectionDTO: type: object additionalProperties: false @@ -1472,6 +1477,88 @@ components: - Video - Web - Menu + ResourceDTO: + type: object + additionalProperties: false + properties: + id: + type: string + nullable: true + type: + $ref: '#/components/schemas/ResourceType' + label: + type: string + nullable: true + dateCreation: + type: string + format: date-time + data: + type: string + nullable: true + ResourceType: + type: string + description: '' + x-enumNames: + - Image + - Video + - ImageUrl + - VideoUrl + enum: + - Image + - Video + - ImageUrl + - VideoUrl + DeviceDTO: + type: object + additionalProperties: false + properties: + id: + type: string + nullable: true + identifier: + type: string + nullable: true + name: + type: string + nullable: true + ipAddressWLAN: + type: string + nullable: true + ipAddressETH: + type: string + nullable: true + configurationId: + type: string + nullable: true + configuration: + type: string + nullable: true + connected: + type: boolean + dateCreation: + type: string + format: date-time + dateUpdate: + type: string + format: date-time + DeviceDetailDTO: + allOf: + - $ref: '#/components/schemas/DeviceDTO' + - type: object + additionalProperties: false + properties: + connectionLevel: + type: string + nullable: true + lastConnectionLevel: + type: string + format: date-time + batteryLevel: + type: string + nullable: true + lastBatteryLevel: + type: string + format: date-time MapDTO: type: object additionalProperties: false diff --git a/manager_api/test/export_configuration_dto_all_of_test.dart b/manager_api/test/export_configuration_dto_all_of_test.dart new file mode 100644 index 0000000..b497052 --- /dev/null +++ b/manager_api/test/export_configuration_dto_all_of_test.dart @@ -0,0 +1,31 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.0 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: lines_longer_than_80_chars + +import 'package:managerapi/api.dart'; +import 'package:test/test.dart'; + +// tests for ExportConfigurationDTOAllOf +void main() { + final instance = ExportConfigurationDTOAllOf(); + + group('test ExportConfigurationDTOAllOf', () { + // List sections (default value: const []) + test('to test the property `sections`', () async { + // TODO + }); + + // List resources (default value: const []) + test('to test the property `resources`', () async { + // TODO + }); + + + }); + +} diff --git a/manager_api/test/export_configuration_dto_test.dart b/manager_api/test/export_configuration_dto_test.dart new file mode 100644 index 0000000..adc2fb5 --- /dev/null +++ b/manager_api/test/export_configuration_dto_test.dart @@ -0,0 +1,61 @@ +// +// AUTO-GENERATED FILE, DO NOT MODIFY! +// +// @dart=2.0 + +// ignore_for_file: unused_element, unused_import +// ignore_for_file: always_put_required_named_parameters_first +// ignore_for_file: lines_longer_than_80_chars + +import 'package:managerapi/api.dart'; +import 'package:test/test.dart'; + +// tests for ExportConfigurationDTO +void main() { + final instance = ExportConfigurationDTO(); + + group('test ExportConfigurationDTO', () { + // String id + test('to test the property `id`', () async { + // TODO + }); + + // String label + test('to test the property `label`', () async { + // TODO + }); + + // String primaryColor + test('to test the property `primaryColor`', () async { + // TODO + }); + + // String secondaryColor + test('to test the property `secondaryColor`', () async { + // TODO + }); + + // List languages (default value: const []) + test('to test the property `languages`', () async { + // TODO + }); + + // DateTime dateCreation + test('to test the property `dateCreation`', () async { + // TODO + }); + + // List sections (default value: const []) + test('to test the property `sections`', () async { + // TODO + }); + + // List resources (default value: const []) + test('to test the property `resources`', () async { + // TODO + }); + + + }); + +}