diff --git a/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart b/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart index d3ddadb..ddea924 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/geopoint_image_list.dart @@ -46,12 +46,12 @@ class _GeoPointImageListState extends State { @override Widget build(BuildContext context) { final appContext = Provider.of(context); - Size size = MediaQuery.of(context).size; + //Size size = MediaQuery.of(context).size; return Stack( children: [ Padding( - padding: const EdgeInsets.only(left: 10.0, right: 10.0, bottom: 10.0, top: 15.0), + padding: const EdgeInsets.only(left: 15.0, right: 15.0, bottom: 15.0, top: 15.0), child: ReorderableListView( onReorder: _onReorder, scrollDirection: Axis.horizontal, @@ -88,19 +88,23 @@ class _GeoPointImageListState extends State { bottom: 10, right: 10, child: InkWell( - onTap: () { - showSelectResourceModal( + onTap: () async { + var result = await showSelectResourceModal( "Sélectionner une ressource", - (ResourceDTO resource) { - setState(() { - ImageGeoPoint newImage = new ImageGeoPoint( imageResourceId: resource.id, imageSource: resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id); - imagesGeo.add(newImage); - }); - }, 1, true, context ); + if (result != null) { + setState(() { + ImageGeoPoint newImage = new ImageGeoPoint(imageResourceId: result.id, imageSource: result.type == ResourceType.imageUrl ? result.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ result.id); + print("REULT IMAGES = "); + print(newImage); + imagesGeo.add(newImage); + print(imagesGeo); + widget.onChanged(imagesGeo); + }); + } }, child: Container( height: MediaQuery.of(context).size.width * 0.04, diff --git a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart index 40eb66d..d99f44d 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/map_config.dart @@ -5,7 +5,7 @@ import 'package:manager_app/Components/fetch_section_icon.dart'; import 'package:manager_app/Components/image_input_container.dart'; import 'package:manager_app/Components/multi_select_container.dart'; import 'package:manager_app/Components/slider_input_container.dart'; -import 'file:///C:/Users/Thomas%20Fransolet/Documents/Documents/Perso/MuseeDeLaFraise/manager-app/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart'; +import 'package:manager_app/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; @@ -71,6 +71,7 @@ class _MapConfigState extends State { mapDTO.iconResourceId = resource.id; widget.onChanged(jsonEncode(mapDTO).toString()); }, + isSmall: true ), // Map Type MultiSelectContainer( diff --git a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart index f624a14..a0387fd 100644 --- a/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart +++ b/lib/Screens/Configurations/Section/SubSection/Map/showNewOrUpdateGeoPoint.dart @@ -133,8 +133,10 @@ void showNewOrUpdateGeoPoint(GeoPointDTO inputGeoPointDTO, Function getResult, A color: kPrimaryColor, textColor: kWhite, press: () { - getResult(geoPointDTO); - Navigator.of(context).pop(); + if (geoPointDTO.latitude != null && geoPointDTO.longitude != null) { + getResult(geoPointDTO); + Navigator.of(context).pop(); + } }, fontSize: 20, ), diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart b/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart index a9535e5..b48e8b4 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/listView_card_image.dart @@ -71,18 +71,19 @@ class _ListViewCard extends State { child: Row( children: [ InkWell( - onTap: () { - showNewOrUpdateImageSlider( + onTap: () async { + var result = await showNewOrUpdateImageSlider( widget.listItems[widget.index], - (value) { - setState(() { - widget.listItems[widget.index] = value; - widget.onChanged(widget.listItems); - }); - }, widget.appContext, context ); + + if (result != null) { + setState(() { + widget.listItems[widget.index] = result; + widget.onChanged(widget.listItems); + }); + } }, child: Padding( padding: const EdgeInsets.all(8.0), @@ -122,7 +123,7 @@ boxDecoration(ImageDTO imageDTO, appContext) { shape: BoxShape.rectangle, border: Border.all(width: 1.5, color: kSecond), borderRadius: BorderRadius.circular(10.0), - image: imageDTO.title != null ? new DecorationImage( + image: imageDTO.title != null && imageDTO.source_ != null ? new DecorationImage( fit: BoxFit.scaleDown, image: new NetworkImage( imageDTO.source_, diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart b/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart index b554f14..c11df3a 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/new_update_image_slider.dart @@ -8,7 +8,7 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; -void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppContext appContext, BuildContext context) { +Future showNewOrUpdateImageSlider(ImageDTO inputImageDTO, AppContext appContext, BuildContext context) async { ImageDTO imageDTO = new ImageDTO(); if (inputImageDTO != null) { @@ -28,7 +28,7 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC } Size size = MediaQuery.of(context).size; - showDialog( + var result = await showDialog( builder: (BuildContext dialogContext) => AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) @@ -49,8 +49,9 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC initialValue: imageDTO.resourceId, color: kPrimaryColor, onChanged: (ResourceDTO resource) { - imageDTO.source_ = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; - imageDTO.resourceId = resource.id; + var result = resource; + imageDTO.source_ = result.type == ResourceType.imageUrl ? result.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ result.id; + imageDTO.resourceId = result.id; }, ), ), @@ -82,7 +83,7 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC icon: Icons.undo, color: kSecond, press: () { - Navigator.of(dialogContext).pop(); + Navigator.pop(dialogContext); }, fontSize: 20, ), @@ -100,8 +101,7 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC textColor: kWhite, press: () { if (imageDTO.resourceId != null) { - getResult(imageDTO); - Navigator.of(dialogContext).pop(); + Navigator.pop(dialogContext, imageDTO); } }, fontSize: 20, @@ -113,6 +113,8 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC ], ), context: context ); + + return result; } getTranslations(BuildContext context, AppContext appContext, ImageDTO imageDTO) { diff --git a/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart b/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart index aad6eec..51ff1ff 100644 --- a/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/Slider/slider_config.dart @@ -42,7 +42,7 @@ class _SliderConfigState extends State { @override Widget build(BuildContext context) { final appContext = Provider.of(context); - Size size = MediaQuery.of(context).size; + //Size size = MediaQuery.of(context).size; void _onReorder(int oldIndex, int newIndex) { setState( @@ -97,23 +97,16 @@ class _SliderConfigState extends State { bottom: 0, right: 0, child: InkWell( - onTap: () { - showNewOrUpdateImageSlider( - null, - (ImageDTO image) { - print("get result bébé showNewOrUpdateImageSlider"); - if (this.mounted) { - setState(() { - image.order = sliderDTO.images.length; - sliderDTO.images.add(image); - widget.onChanged(jsonEncode(sliderDTO).toString()); - }); - } else { - print("DISPOSE MEEEEERDE"); - } - }, - appContext, - context); + onTap: () async { + var result = await showNewOrUpdateImageSlider(null, appContext, context); + if (result != null) + { + setState(() { + result.order = sliderDTO.images.length; + sliderDTO.images.add(result); + widget.onChanged(jsonEncode(sliderDTO).toString()); + }); + } }, child: Container( height: MediaQuery.of(context).size.width * 0.04, diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 9796991..6fee942 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -40,7 +40,18 @@ class _SectionDetailScreenState extends State { future: getSection(widget.id, appContext.getContext().clientAPI), builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { - return bodySection(snapshot.data, size, appContext, context); + return Stack( + children: [ + bodySection(snapshot.data, size, appContext, context), + Align( + alignment: AlignmentDirectional.bottomCenter, + child: Container( + height: 80, + child: getButtons(sectionDTO, appContext), + ), + ) + ], + ); } else if (snapshot.connectionState == ConnectionState.none) { return Text("No data"); } else { @@ -57,10 +68,10 @@ class _SectionDetailScreenState extends State { Widget bodySection(SectionDTO sectionDTO, Size size, AppContext appContext, BuildContext context) { return Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Container( - height: size.height *0.13, + //height: size.height *0.13, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -117,9 +128,6 @@ class _SectionDetailScreenState extends State { ), ), // TITLE Container( - /*height: size.height*0.4, - color: Colors.lightBlue,*/ - //height: size.height *0.1, child: Padding( padding: const EdgeInsets.all(10.0), child: Container( @@ -142,24 +150,8 @@ class _SectionDetailScreenState extends State { sectionDTO.label = value; }, ), - ImageInputContainer( - label: "Image :", - initialValue: sectionDTO != null ? sectionDTO.imageId : "", - color: kPrimaryColor, - onChanged: (ResourceDTO resource) { - print("received value in grant older"); - sectionDTO.imageId = resource.id; - sectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; - }, - ), - ], - ), - Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ MultiStringContainer( - label: "Titre :", + label: "Titre affiché:", modalLabel: "Titre", color: kPrimaryColor, initialValue: sectionDTO != null ? sectionDTO.title : [], @@ -172,7 +164,7 @@ class _SectionDetailScreenState extends State { maxLines: 1, ), MultiStringContainer( - label: "Description :", + label: "Description affichée:", modalLabel: "Description", color: kPrimaryColor, initialValue: sectionDTO != null ? sectionDTO.description : [], @@ -183,6 +175,22 @@ class _SectionDetailScreenState extends State { } }, maxLines: 2, + ), + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ImageInputContainer( + label: "Image :", + initialValue: sectionDTO != null ? sectionDTO.imageId : "", + color: kPrimaryColor, + onChanged: (ResourceDTO resource) { + print("received value in grant older"); + sectionDTO.imageId = resource.id; + sectionDTO.imageSource = resource.type == ResourceType.imageUrl ? resource.data : appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/"+ resource.id; + }, ) ], ) @@ -195,8 +203,8 @@ class _SectionDetailScreenState extends State { ), ),// FIELDS SECTION Container( - height: size.height * 0.305, - width: size.width * 0.8, + //height: size.height * 0.305, + //width: size.width * 0.8, child: Padding( padding: const EdgeInsets.all(10.0), child: sectionDTO != null ? getSpecificData(sectionDTO, appContext) : null, @@ -206,7 +214,9 @@ class _SectionDetailScreenState extends State { border: Border.all(width: 1.5, color: kSecond) ), ), - getButtons(sectionDTO, appContext), + SizedBox( + height: size.height*0.1, + ) ], ); } @@ -285,15 +295,18 @@ class _SectionDetailScreenState extends State { Future save(bool isTraduction, SectionDTO sectionDTO, AppContext appContext) async { print("SAVE"); print(sectionDTO); - SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionUpdate(sectionDTO); - ManagerAppContext managerAppContext = appContext.getContext(); - managerAppContext.selectedSection = section; - appContext.setContext(managerAppContext); - if (isTraduction) { - showNotification(Colors.green, kWhite, 'Les traductions de la section ont été sauvegardées avec succès', context); - } else { - showNotification(Colors.green, kWhite, 'La section a été sauvegardée avec succès', context); + if (sectionDTO != null) { + SectionDTO section = await appContext.getContext().clientAPI.sectionApi.sectionUpdate(sectionDTO); + ManagerAppContext managerAppContext = appContext.getContext(); + managerAppContext.selectedSection = section; + appContext.setContext(managerAppContext); + + if (isTraduction) { + showNotification(Colors.green, kWhite, 'Les traductions de la section ont été sauvegardées avec succès', context); + } else { + showNotification(Colors.green, kWhite, 'La section a été sauvegardée avec succès', context); + } } } @@ -303,17 +316,15 @@ class _SectionDetailScreenState extends State { return MapConfig( initialValue: sectionDTO.data, onChanged: (String data) { - print("Received info in parent"); print(data); sectionDTO.data = data; + save(false, sectionDTO, appContext); }, ); case SectionType.slider: return SliderConfig( initialValue: sectionDTO.data, onChanged: (String data) { - print("Received info in parent"); - print(data); sectionDTO.data = data; }, ); diff --git a/lib/Screens/Devices/change_device_info_modal.dart b/lib/Screens/Devices/change_device_info_modal.dart index 0987923..25d7791 100644 --- a/lib/Screens/Devices/change_device_info_modal.dart +++ b/lib/Screens/Devices/change_device_info_modal.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:manager_app/Components/loading.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Components/string_input_container.dart'; import 'package:manager_app/constants.dart'; @@ -7,10 +6,10 @@ import 'package:managerapi/api.dart'; import 'dropDown_configuration.dart'; -showChangeInfo (String text, DeviceDTO inputDevice, Function onGetResult, int maxLines, BuildContext mainContext, dynamic appContext) { +showChangeInfo (String text, DeviceDTO inputDevice, Function onGetResult, int maxLines, BuildContext mainContext, dynamic appContext) async { Size size = MediaQuery.of(mainContext).size; - showDialog( + var result = await showDialog( builder: (BuildContext context) => AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) diff --git a/lib/Screens/Resources/new_resource_popup.dart b/lib/Screens/Resources/new_resource_popup.dart index feb951f..c51fa0b 100644 --- a/lib/Screens/Resources/new_resource_popup.dart +++ b/lib/Screens/Resources/new_resource_popup.dart @@ -1,24 +1,21 @@ import 'dart:io'; +import 'package:manager_app/Components/message_notification.dart'; import 'package:manager_app/Components/resource_tab.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/Models/managerContext.dart'; import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; -import 'package:http/http.dart' as http; - -void showNewResource(AppContext appContext, BuildContext context) { +dynamic showNewResource(AppContext appContext, BuildContext context) async { ResourceDetailDTO resourceDetailDTO = new ResourceDetailDTO(); Size size = MediaQuery.of(context).size; var fileName; File fileToSend; - showDialog( + var result = await showDialog( builder: (BuildContext context) => AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) @@ -86,7 +83,17 @@ void showNewResource(AppContext appContext, BuildContext context) { color: kPrimaryColor, textColor: kWhite, press: () { - create(resourceDetailDTO, fileToSend, appContext, context); + if (resourceDetailDTO.label != null) { + if (fileToSend != null) { + Navigator.pop(context, [resourceDetailDTO, fileToSend]); + } else { + showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context); + } + } else { + showNotification(Colors.orange, kWhite, 'Veuillez donner un nom à la ressource', context); + } + //Navigator.of(context).pop(); + //create(resourceDetailDTO, fileToSend, appContext, context); }, fontSize: 20, ), @@ -97,71 +104,6 @@ void showNewResource(AppContext appContext, BuildContext context) { ], ), context: context ); + + return result; } - -void create(ResourceDetailDTO resourceDetailDTO, File file, AppContext appContext, context) async { - if (resourceDetailDTO.label != null) { - switch(resourceDetailDTO.type) { - case ResourceType.image: - case ResourceType.video: - if (file != null) { - var request = http.MultipartRequest('POST', Uri.parse(appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/upload")); - request.files.add( - await http.MultipartFile( - 'picture', - file.readAsBytes().asStream(), - file.lengthSync(), - filename: file.path.toString().split("/").last - ) - ); - - ManagerAppContext managerAppContext = appContext.getContext(); - request.headers["authorization"]="Bearer ${managerAppContext.token.accessToken}"; - request.fields['label'] = resourceDetailDTO.label; - request.fields['type'] = ResourceType.image.toString(); - - var res = await request.send(); - - if (res.statusCode == 200) { - // 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); - } else { - showNotification(kPrimaryColor, kWhite, 'Une erreur est survenue lors de la création de la ressource', context); - } - - } else { - showNotification(Colors.orange, kWhite, 'Aucun fichier n\'a été chargé', context); - } - Navigator.of(context).pop(); - break; - case ResourceType.imageUrl: - case ResourceType.videoUrl: - if (resourceDetailDTO.data != null) { - // test if Correct url - bool _validURL = Uri.parse(resourceDetailDTO.data).isAbsolute; - if(_validURL) { - Navigator.of(context).pop(); - - ResourceDetailDTO newResource = await appContext.getContext().clientAPI.resourceApi.resourceCreate(resourceDetailDTO); - - // 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); - } else { - showNotification(Colors.orange, kWhite, 'L\'url est invalide', context); - } - } else { - showNotification(Colors.orange, kWhite, 'Veuillez remplir le champ URL', context); - } - break; - } - } else { - showNotification(Colors.orange, kWhite, 'Veuillez donner un nom à la ressource', context); - } -} - diff --git a/lib/Screens/Resources/resource_body_grid.dart b/lib/Screens/Resources/resource_body_grid.dart index 869ef7d..cc5efc8 100644 --- a/lib/Screens/Resources/resource_body_grid.dart +++ b/lib/Screens/Resources/resource_body_grid.dart @@ -12,11 +12,13 @@ class ResourceBodyGrid extends StatefulWidget { final List resources; //return ResourceDTO final Function onSelect; final bool isImage; + final bool isAddButton; const ResourceBodyGrid({ Key key, this.resources, this.onSelect, this.isImage, + this.isAddButton, }) : super(key: key); @override @@ -78,35 +80,39 @@ class _ResourceBodyGridState extends State { }, ), ), - InkWell( - onTap: () { - widget.onSelect(ResourceDTO(id: null)); - }, - child: Container( - height: size.height *0.08, - width: size.height *0.08, - decoration: BoxDecoration( - color: Colors.lightGreen, - shape: BoxShape.rectangle, - borderRadius: BorderRadius.circular(25.0), - boxShadow: [ - BoxShadow( - color: kSecond, - spreadRadius: 0.5, - blurRadius: 5, - offset: Offset(0, 1.5), // changes position of shadow + if (widget.isAddButton) + InkWell( + onTap: () { + widget.onSelect(ResourceDTO(id: null)); + }, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Container( + height: size.height *0.08, + width: size.height *0.08, + decoration: BoxDecoration( + color: Colors.lightGreen, + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(25.0), + boxShadow: [ + BoxShadow( + color: kSecond, + spreadRadius: 0.5, + blurRadius: 5, + offset: Offset(0, 1.5), // changes position of shadow + ), + ], ), - ], - ), - child: - Padding( - padding: const EdgeInsets.all(10.0), - child: LayoutBuilder(builder: (context, constraint) { - return new Icon(Icons.add, size: constraint.biggest.height, color: kTextLightColor); - }), + child: + Padding( + padding: const EdgeInsets.all(10.0), + child: LayoutBuilder(builder: (context, constraint) { + return new Icon(Icons.add, size: constraint.biggest.height, color: kTextLightColor); + }), + ), ), - ), - ) + ), + ) ], ), Expanded( diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 416c81e..345e065 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -1,8 +1,10 @@ -import 'package:auto_size_text/auto_size_text.dart'; +import 'dart:convert'; +import 'dart:io'; + import 'package:flutter/material.dart'; -import 'package:manager_app/Components/fetch_resource_icon.dart'; import 'package:manager_app/Components/loading.dart'; -import 'package:manager_app/Components/string_input_container.dart'; +import 'package:manager_app/Components/message_notification.dart'; +import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Resources/new_resource_popup.dart'; import 'package:manager_app/Screens/Resources/resource_body_grid.dart'; import 'package:manager_app/Screens/Resources/show_resource_popup.dart'; @@ -10,14 +12,17 @@ import 'package:manager_app/app_context.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; import 'package:provider/provider.dart'; +import 'package:http/http.dart' as http; class ResourcesScreen extends StatefulWidget { final Function onGetResult; //return ResourceDTO final bool isImage; + final bool isAddButton; const ResourcesScreen({ Key key, this.isImage = false, this.onGetResult, + this.isAddButton = true, }) : super(key: key); @override @@ -26,6 +31,7 @@ class ResourcesScreen extends StatefulWidget { class _ResourcesScreenState extends State { String filter; + bool isLoading; @override Widget build(BuildContext context) { @@ -38,21 +44,22 @@ class _ResourcesScreenState extends State { if (snapshot.connectionState == ConnectionState.done) { var tempOutput = new List.from(snapshot.data); // tempOutput.add(ResourceDTO(id: null)); - return ResourceBodyGrid(resources: tempOutput, isImage: widget.isImage, onSelect: (value) { + return ResourceBodyGrid(resources: tempOutput, isImage: widget.isImage, isAddButton: widget.isAddButton, onSelect: (value) async { if (widget.onGetResult == null) { // Main screen if (value.id == null) { - showNewResource(appContext, context); + var result = await showNewResource(appContext, context); + if (result != null) + { + var newResource = await create(result[0], result[1], appContext, context); + setState(() {}); // For refresh + } } else { showResource(value, appContext, context, size); } } else { - if (value.id == null) { - showNewResource(appContext, context); - } else { // Result for select modal widget.onGetResult(value); - } } },);//bodyGrid(tempOutput, size, appContext); } else if (snapshot.connectionState == ConnectionState.none) { @@ -77,3 +84,61 @@ Future> getResources(Function onGetResult, bool isImage, dynam } return resources; } + +Future create(ResourceDetailDTO resourceDetailDTO, File file, AppContext appContext, context) async { + switch(resourceDetailDTO.type) { + case ResourceType.image: + case ResourceType.video: + var request = http.MultipartRequest('POST', Uri.parse(appContext.getContext().clientAPI.resourceApi.apiClient.basePath+"/api/Resource/upload")); + request.files.add( + await http.MultipartFile( + 'picture', + file.readAsBytes().asStream(), + file.lengthSync(), + filename: file.path.toString().split("/").last + ) + ); + + ManagerAppContext managerAppContext = appContext.getContext(); + request.headers["authorization"]="Bearer ${managerAppContext.token.accessToken}"; + request.fields['label'] = resourceDetailDTO.label; + request.fields['type'] = ResourceType.image.toString(); + + var res = await request.send(); + final respStr = await res.stream.bytesToString(); + + if (res.statusCode == 200) { + var result = ResourceDTO.fromJson(jsonDecode(respStr)); + showNotification(Colors.green, kWhite, 'La ressource a été créée avec succès', context); + + return result; + } else { + showNotification(kPrimaryColor, kWhite, 'Une erreur est survenue lors de la création de la ressource', context); + } + break; + case ResourceType.imageUrl: + case ResourceType.videoUrl: + if (resourceDetailDTO.data != null) { + // test if Correct url + bool _validURL = Uri.parse(resourceDetailDTO.data).isAbsolute; + if(_validURL) { + Navigator.of(context).pop(); + + ResourceDTO newResource = await appContext.getContext().clientAPI.resourceApi.resourceCreate(resourceDetailDTO); + + // 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); + + return newResource; + } else { + showNotification(Colors.orange, kWhite, 'L\'url est invalide', context); + } + } else { + showNotification(Colors.orange, kWhite, 'Veuillez remplir le champ URL', context); + } + break; + } +} \ No newline at end of file diff --git a/lib/Screens/Resources/select_resource_modal.dart b/lib/Screens/Resources/select_resource_modal.dart index 9940c15..efcdc1b 100644 --- a/lib/Screens/Resources/select_resource_modal.dart +++ b/lib/Screens/Resources/select_resource_modal.dart @@ -5,10 +5,10 @@ import 'package:manager_app/Screens/Resources/resources_screen.dart'; import 'package:manager_app/constants.dart'; import 'package:managerapi/api.dart'; -showSelectResourceModal (String text, Function onGetResult, int maxLines, bool onlyImage, BuildContext mainContext) { /*Function onSelect,*/ +dynamic showSelectResourceModal (String text, int maxLines, bool onlyImage, BuildContext mainContext) async { /*Function onSelect,*/ Size size = MediaQuery.of(mainContext).size; - showDialog( + var result = await showDialog( builder: (BuildContext context) => AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) @@ -21,10 +21,13 @@ showSelectResourceModal (String text, Function onGetResult, int maxLines, bool o width: size.width * 0.7, height: size.height * 0.75, child: ResourcesScreen( + isAddButton: false, onGetResult: (ResourceDTO resource) { + print("SELECT RESOURCE"); + print(resource); if (resource != null) { - onGetResult(resource); - Navigator.of(mainContext).pop(); + var result = resource; + Navigator.pop(context, result); } }, isImage: onlyImage, @@ -55,6 +58,7 @@ showSelectResourceModal (String text, Function onGetResult, int maxLines, bool o ], ), context: mainContext ); + return result; } showValues(List newValues) { diff --git a/lib/main.dart b/lib/main.dart index c13e4af..b6d7c6f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:manager_app/Models/managerContext.dart'; import 'package:manager_app/Screens/Main/main_screen.dart'; import 'package:flutter/material.dart'; @@ -5,10 +7,18 @@ import 'package:provider/provider.dart'; import 'Screens/login_screen.dart'; import 'app_context.dart'; import 'constants.dart'; +import 'package:window_size/window_size.dart'; -void main() { +Future main() async { String initialRoute; + WidgetsFlutterBinding.ensureInitialized(); + if (Platform.isWindows) { + setWindowTitle("My Desktop App"); + setWindowMinSize(Size(1100, 900)); + setWindowMaxSize(Size(3840, 2160)); + } + initialRoute = '/welcome'; final MyApp myApp = MyApp( diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 0e8ad7e..08653c4 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -7,9 +7,13 @@ #include "generated_plugin_registrant.h" #include +#include void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) dart_vlc_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "DartVlcPlugin"); dart_vlc_plugin_register_with_registrar(dart_vlc_registrar); + g_autoptr(FlPluginRegistrar) window_size_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "WindowSizePlugin"); + window_size_plugin_register_with_registrar(window_size_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 0ec9fa0..53f2011 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST dart_vlc + window_size ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 7ce0a99..e29c053 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,7 +8,9 @@ import FlutterMacOS import Foundation import path_provider_macos +import window_size func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + WindowSizePlugin.register(with: registry.registrar(forPlugin: "WindowSizePlugin")) } diff --git a/pubspec.lock b/pubspec.lock index 379700f..b7c1413 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -385,6 +385,15 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.5" + window_size: + dependency: "direct main" + description: + path: "plugins/window_size" + ref: "927f8cbc09b35d85245c095f2db8df9b186f6618" + resolved-ref: "927f8cbc09b35d85245c095f2db8df9b186f6618" + url: "git://github.com/google/flutter-desktop-embedding.git" + source: git + version: "0.1.0" xdg_directories: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index bc534fa..0725e13 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,6 +37,11 @@ dependencies: dart_vlc: ^0.0.6 video_player: ^2.1.1 drag_and_drop_lists: ^0.3.2 + window_size: + git: + url: git://github.com/google/flutter-desktop-embedding.git + path: plugins/window_size + ref: 927f8cbc09b35d85245c095f2db8df9b186f6618 managerapi: path: manager_api diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 869167c..36f9252 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,8 +7,11 @@ #include "generated_plugin_registrant.h" #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { DartVlcPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("DartVlcPlugin")); + WindowSizePluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("WindowSizePlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 8385b22..bb61159 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST dart_vlc + window_size ) set(PLUGIN_BUNDLED_LIBRARIES)