diff --git a/lib/Components/image_input_container.dart b/lib/Components/image_input_container.dart index db1fc7c..685e507 100644 --- a/lib/Components/image_input_container.dart +++ b/lib/Components/image_input_container.dart @@ -11,7 +11,7 @@ class ImageInputContainer extends StatefulWidget { final Color color; final String label; final String initialValue; - final ValueChanged onChanged; + final ValueChanged onChanged; const ImageInputContainer({ Key key, this.color = kSecond, @@ -50,16 +50,16 @@ class _ImageInputContainerState extends State { child: InkWell( onTap: () { showSelectResourceModal( - "Sélectionner une ressource", - (String resourceId) { - widget.onChanged(resourceId); - setState(() { - resourceIdToShow = resourceId; - }); - }, - 1, - true, - context + "Sélectionner une ressource", + (ResourceDTO resource) { + widget.onChanged(resource); + setState(() { + resourceIdToShow = resource.id; + }); + }, + 1, + true, + context ); }, child: getElement(widget.initialValue, context), diff --git a/lib/Screens/Configurations/Section/SubSection/listViewcard.dart b/lib/Screens/Configurations/Section/SubSection/listViewcard.dart index 1d82c2b..a286357 100644 --- a/lib/Screens/Configurations/Section/SubSection/listViewcard.dart +++ b/lib/Screens/Configurations/Section/SubSection/listViewcard.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/new_update_image_slider.dart'; @@ -29,75 +27,90 @@ class ListViewCard extends StatefulWidget { class _ListViewCard extends State { @override Widget build(BuildContext context) { - Size size = MediaQuery.of(context).size; - return Card( margin: EdgeInsets.all(4), - color: Colors.white, - child: Container( - width: 200, - height: 200, - child: InkWell( - splashColor: kPrimaryColor, - onTap: () { - print("Item ${widget.listItems[widget.index]} selected."); - showNewOrUpdateImageSlider( - widget.listItems[widget.index], - (value) { - print("get result bébé"); - setState(() { - //List test = new List.from(sliderDTO.images); - - widget.listItems.add(value); - widget.onChanged(widget.listItems); - }); - }, - widget.appContext, - context); - }, - child: Container( - decoration: boxDecoration(widget.listItems[widget.index], widget.appContext), - padding: const EdgeInsets.all(15), - margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), - child: Align( - alignment: Alignment.center, - child: getElement(widget.listItems[widget.index], size, widget.appContext) + child: Stack( + children: [ + Container( + width: 200, + height: 250, + decoration: BoxDecoration( + color: kWhite, + border: Border.all(width: 0.5, color: kSecond), + ), + child: Padding( + padding: const EdgeInsets.only(right: 20.0), + child: Column( + children: [ + AutoSizeText( + widget.listItems[widget.index].title == null ? "" : widget.listItems[widget.index].title[0].value, + style: new TextStyle(fontSize: 20), + maxLines: 1, + ), + Container( + height: MediaQuery.of(context).size.height * 0.1, + decoration: boxDecoration(widget.listItems[widget.index], widget.appContext), + padding: const EdgeInsets.all(15), + margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: AutoSizeText( + widget.listItems[widget.index].description == null ? "" : widget.listItems[widget.index].description[0].value, + style: new TextStyle(fontSize: 20), + maxLines: 3, + ), + ), + ], + ), ), ), - ), - ), - ); - } -} - -getElement(ImageDTO imageDTO, Size size, AppContext appContext) { - if (imageDTO.title != null) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - SizedBox( - height: size.width *0.01, - ), - Align( - alignment: Alignment.center, - child: AutoSizeText( - imageDTO.title == null ? "" : imageDTO.title[0].value, - style: new TextStyle(fontSize: 20), - maxLines: 1, + Positioned( + right: 0, + bottom: 0, + child: Row( + children: [ + InkWell( + onTap: () { + showNewOrUpdateImageSlider( + widget.listItems[widget.index], + (value) { + setState(() { + widget.listItems[widget.index] = value; + widget.onChanged(widget.listItems); + }); + }, + widget.appContext, + context); + }, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Icon( + Icons.edit, + color: kPrimaryColor, + size: 25.0, + ), + ) + ), + InkWell( + onTap: () { + widget.listItems.removeAt(widget.index); + widget.onChanged(widget.listItems); + }, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Icon( + Icons.delete, + color: kPrimaryColor, + size: 25.0, + ), + ) + ), + ], + ) ), - ), - Align( - alignment: Alignment.bottomRight, - child: Text("TODO") - ), - ], - ); - } else { - return Icon( - Icons.add, - color: kTextLightColor, - size: 80.0, + ], + ), ); } } @@ -106,10 +119,10 @@ boxDecoration(ImageDTO imageDTO, appContext) { return BoxDecoration( color: imageDTO.title == null ? Colors.lightGreen : kBackgroundColor, shape: BoxShape.rectangle, - borderRadius: BorderRadius.circular(30.0), + border: Border.all(width: 1.5, color: kSecond), + borderRadius: BorderRadius.circular(10.0), image: imageDTO.title != null ? new DecorationImage( - fit: BoxFit.cover, - colorFilter: new ColorFilter.mode(Colors.black.withOpacity(0.3), BlendMode.dstATop), + fit: BoxFit.scaleDown, image: new NetworkImage( imageDTO.source_, ), diff --git a/lib/Screens/Configurations/Section/SubSection/new_update_image_slider.dart b/lib/Screens/Configurations/Section/SubSection/new_update_image_slider.dart index ff6fd9f..067c1ff 100644 --- a/lib/Screens/Configurations/Section/SubSection/new_update_image_slider.dart +++ b/lib/Screens/Configurations/Section/SubSection/new_update_image_slider.dart @@ -10,12 +10,12 @@ import 'package:managerapi/api.dart'; void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppContext appContext, BuildContext context) { ImageDTO imageDTO = new ImageDTO(); - if (inputImageDTO.source_ != null) { + if (inputImageDTO != null) { print("inputImageDTO.source_ != null NOT NULLLLL"); imageDTO = inputImageDTO; } else { - imageDTO.title = new List(); - imageDTO.description = new List(); + imageDTO.title = []; + imageDTO.description = []; ManagerAppContext managerAppContext = appContext.getContext(); managerAppContext.selectedConfiguration.languages.forEach((element) { @@ -25,7 +25,6 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC imageDTO.title.add(translationDTO); imageDTO.description.add(translationDTO); }); - } print(imageDTO); @@ -46,11 +45,11 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC children: [ ImageInputContainer( label: "Image :", - initialValue: imageDTO.source_, + initialValue: imageDTO.resourceId, color: kPrimaryColor, - onChanged: (value) { - print("received value in grant older"); - imageDTO.source_ = value; + 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; }, ), MultiStringContainer( @@ -78,7 +77,6 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC imageDTO.description = value; } print(imageDTO.description); - }, maxLines: 1, ), @@ -111,10 +109,10 @@ void showNewOrUpdateImageSlider(ImageDTO inputImageDTO, Function getResult, AppC Align( alignment: AlignmentDirectional.bottomEnd, child: Container( - width: inputImageDTO.source_ != null ? 200: 150, + width: inputImageDTO != null ? 220: 150, height: 70, child: RoundedButton( - text: inputImageDTO.source_ != null ? "Sauvegarder" : "Créer", + text: inputImageDTO != null ? "Sauvegarder" : "Créer", icon: Icons.check, color: kPrimaryColor, textColor: kWhite, diff --git a/lib/Screens/Configurations/Section/SubSection/slider_config.dart b/lib/Screens/Configurations/Section/SubSection/slider_config.dart index 735315c..69e7a5e 100644 --- a/lib/Screens/Configurations/Section/SubSection/slider_config.dart +++ b/lib/Screens/Configurations/Section/SubSection/slider_config.dart @@ -35,17 +35,12 @@ class _SliderConfigState extends State { @override void initState() { - - super.initState(); sliderDTO = SliderDTO.fromJson(json.decode(widget.initialValue)); - List test = new List.from(sliderDTO.images); - test.add(ImageDTO(title: null)); - sliderDTO.images = test; - print(sliderDTO); + sliderDTO.images.sort((a, b) => a.order.compareTo(b.order)); } @override @@ -61,73 +56,94 @@ class _SliderConfigState extends State { } final ImageDTO item = sliderDTO.images.removeAt(oldIndex); sliderDTO.images.insert(newIndex, item); + + var i = 0; + sliderDTO.images.forEach((image) { + image.order = i; + i++; + }); + + widget.onChanged(jsonEncode(sliderDTO).toString()); }, ); } - return ReorderableListView( - onReorder: _onReorder, - scrollDirection: Axis.horizontal, - padding: const EdgeInsets.symmetric(vertical: 25.0), - children: List.generate( - sliderDTO.images.length, - (index) { - return ListViewCard( - sliderDTO.images, - index, - Key('$index'), - appContext, - (images) { - print(images); - print("ONCHANEGDE"); - - setState(() { - List test = new List.from(images); - sliderDTO.images = test; - List testToSend = new List.from(images); - testToSend = testToSend.where((element) => element.source_ != null).toList(); - var sliderToSend = new SliderDTO(); - sliderToSend.images = testToSend; - widget.onChanged(jsonEncode(sliderToSend).toString()); - }); - } - ); - }, - ), - ); - - return GridView.builder( - shrinkWrap: true, - gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8), - itemCount: sliderDTO.images.length, - itemBuilder: (BuildContext context, int index) { - return - InkWell( - onTap: () { - // Main screen - showNewOrUpdateImageSlider( - sliderDTO.images[index], - (value) { - print("get result bébé"); + return Stack( + children: [ + ReorderableListView( + onReorder: _onReorder, + scrollDirection: Axis.horizontal, + padding: const EdgeInsets.symmetric(vertical: 20.0), + children: List.generate( + sliderDTO.images.length, + (index) { + return ListViewCard( + sliderDTO.images, + index, + Key('$index'), + appContext, + (images) { + setState(() { + List test = new List.from(images); + sliderDTO.images = test; + List testToSend = new List.from(images); + testToSend = testToSend.where((element) => element.source_ != null).toList(); + var sliderToSend = new SliderDTO(); + sliderToSend.images = testToSend; + widget.onChanged(jsonEncode(sliderToSend).toString()); + }); + } + ); + }, + ), + ), + Positioned( + bottom: 0, + right: 0, + child: InkWell( + onTap: () { + showNewOrUpdateImageSlider( + null, + (ImageDTO image) { + print("get result bébé showNewOrUpdateImageSlider"); + if (this.mounted) { setState(() { - sliderDTO.images.add(value); + image.order = sliderDTO.images.length; + sliderDTO.images.add(image); widget.onChanged(jsonEncode(sliderDTO).toString()); }); - }, - appContext, - context); - }, - child: Container( - decoration: boxDecoration(sliderDTO.images[index], appContext), - padding: const EdgeInsets.all(15), - margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), - child: Align( - alignment: Alignment.center, - child: getElement(sliderDTO.images[index], size, appContext) - ), + } else { + print("DISPOSE MEEEEERDE"); + } + }, + appContext, + context); + }, + child: Container( + height: MediaQuery.of(context).size.width * 0.04, + width: MediaQuery.of(context).size.width * 0.04, + child: Icon( + Icons.add, + color: kTextLightColor, + size: 30.0, ), - ); - } + decoration: BoxDecoration( + color: Colors.lightGreen, + shape: BoxShape.rectangle, + borderRadius: BorderRadius.circular(20.0), + boxShadow: [ + BoxShadow( + color: kSecond, + spreadRadius: 0.5, + blurRadius: 5, + offset: Offset(0, 1.5), // changes position of shadow + ), + ], + ), + ), + ), + ), + ], ); } } \ No newline at end of file diff --git a/lib/Screens/Configurations/Section/section_detail_screen.dart b/lib/Screens/Configurations/Section/section_detail_screen.dart index 6f359af..e4e42d6 100644 --- a/lib/Screens/Configurations/Section/section_detail_screen.dart +++ b/lib/Screens/Configurations/Section/section_detail_screen.dart @@ -147,9 +147,9 @@ class _SectionDetailScreenState extends State { label: "Image :", initialValue: sectionDTO.imageId, color: kPrimaryColor, - onChanged: (value) { + onChanged: (ResourceDTO resource) { print("received value in grant older"); - sectionDTO.imageId = value; + sectionDTO.imageId = resource.id; }, ), ], diff --git a/lib/Screens/Resources/resources_screen.dart b/lib/Screens/Resources/resources_screen.dart index 9604826..fd98205 100644 --- a/lib/Screens/Resources/resources_screen.dart +++ b/lib/Screens/Resources/resources_screen.dart @@ -9,7 +9,7 @@ import 'package:managerapi/api.dart'; import 'package:provider/provider.dart'; class ResourcesScreen extends StatefulWidget { - final Function onGetResult; + final Function onGetResult; //return ResourceDTO final bool isImage; const ResourcesScreen({ Key key, @@ -71,7 +71,7 @@ class _ResourcesScreenState extends State { showNewResource(appContext, context); } else { // Result for select modal - widget.onGetResult(data[index].id); + widget.onGetResult(data[index]); } } diff --git a/lib/Screens/Resources/select_resource_modal.dart b/lib/Screens/Resources/select_resource_modal.dart index defd645..6c97ef5 100644 --- a/lib/Screens/Resources/select_resource_modal.dart +++ b/lib/Screens/Resources/select_resource_modal.dart @@ -19,11 +19,11 @@ showSelectResourceModal (String text, Function onGetResult, int maxLines, bool o children: [ Container( width: size.width * 0.6, - height: size.height * 0.6, + height: size.height * 0.75, child: ResourcesScreen( - onGetResult: (String resourceId) { - if (resourceId != null) { - onGetResult(resourceId); + onGetResult: (ResourceDTO resource) { + if (resource != null) { + onGetResult(resource); Navigator.of(mainContext).pop(); } }, diff --git a/manager_api/.openapi-generator/FILES b/manager_api/.openapi-generator/FILES index 3bf1b25..da64256 100644 --- a/manager_api/.openapi-generator/FILES +++ b/manager_api/.openapi-generator/FILES @@ -68,11 +68,3 @@ lib/model/user_detail_dto.dart lib/model/video_dto.dart lib/model/web_dto.dart pubspec.yaml -test/geo_point_dto_test.dart -test/image_dto_test.dart -test/map_dto_test.dart -test/map_type_test.dart -test/menu_dto_test.dart -test/slider_dto_test.dart -test/video_dto_test.dart -test/web_dto_test.dart diff --git a/manager_api/doc/ImageDTO.md b/manager_api/doc/ImageDTO.md index 9da8ff7..1f2c7b5 100644 --- a/manager_api/doc/ImageDTO.md +++ b/manager_api/doc/ImageDTO.md @@ -10,7 +10,9 @@ Name | Type | Description | Notes ------------ | ------------- | ------------- | ------------- **title** | [**List**](TranslationDTO.md) | | [optional] [default to const []] **description** | [**List**](TranslationDTO.md) | | [optional] [default to const []] +**resourceId** | **String** | | [optional] **source_** | **String** | | [optional] +**order** | **int** | | [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/model/image_dto.dart b/manager_api/lib/model/image_dto.dart index 1949a98..8ea812c 100644 --- a/manager_api/lib/model/image_dto.dart +++ b/manager_api/lib/model/image_dto.dart @@ -14,29 +14,39 @@ class ImageDTO { ImageDTO({ this.title, this.description, + this.resourceId, this.source_, + this.order, }); List title; List description; + String resourceId; + String source_; + int order; + @override bool operator ==(Object other) => identical(this, other) || other is ImageDTO && other.title == title && other.description == description && - other.source_ == source_; + other.resourceId == resourceId && + other.source_ == source_ && + other.order == order; @override int get hashCode => (title == null ? 0 : title.hashCode) + (description == null ? 0 : description.hashCode) + - (source_ == null ? 0 : source_.hashCode); + (resourceId == null ? 0 : resourceId.hashCode) + + (source_ == null ? 0 : source_.hashCode) + + (order == null ? 0 : order.hashCode); @override - String toString() => 'ImageDTO[title=$title, description=$description, source_=$source_]'; + String toString() => 'ImageDTO[title=$title, description=$description, resourceId=$resourceId, source_=$source_, order=$order]'; Map toJson() { final json = {}; @@ -46,9 +56,15 @@ class ImageDTO { if (description != null) { json[r'description'] = description; } + if (resourceId != null) { + json[r'resourceId'] = resourceId; + } if (source_ != null) { json[r'source'] = source_; } + if (order != null) { + json[r'order'] = order; + } return json; } @@ -59,7 +75,9 @@ class ImageDTO { : ImageDTO( title: TranslationDTO.listFromJson(json[r'title']), description: TranslationDTO.listFromJson(json[r'description']), + resourceId: json[r'resourceId'], source_: json[r'source'], + order: json[r'order'], ); static List listFromJson(List json, {bool emptyIsNull, bool growable,}) => diff --git a/manager_api/swagger.yaml b/manager_api/swagger.yaml index a7f5910..01e30c1 100644 --- a/manager_api/swagger.yaml +++ b/manager_api/swagger.yaml @@ -1450,9 +1450,15 @@ components: nullable: true items: $ref: '#/components/schemas/TranslationDTO' + resourceId: + type: string + nullable: true source: type: string nullable: true + order: + type: integer + format: int32 VideoDTO: type: object additionalProperties: false