From 6aca22b758c32f583ab93108095a748b2924e442 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Fri, 30 Apr 2021 20:03:34 +0200 Subject: [PATCH] service update generation + sections list display in detail --- lib/Models/managerContext.dart | 3 +- .../configuration_detail_screen.dart | 73 ++++++++++++++++--- lib/Screens/login_screen.dart | 10 +-- manager_api/.openapi-generator/FILES | 2 - manager_api/README.md | 1 + manager_api/doc/SectionApi.md | 44 +++++++++++ manager_api/lib/api/section_api.dart | 66 +++++++++++++++++ manager_api/swagger.yaml | 42 +++++++++++ 8 files changed, 224 insertions(+), 17 deletions(-) diff --git a/lib/Models/managerContext.dart b/lib/Models/managerContext.dart index e0201b5..a3845fc 100644 --- a/lib/Models/managerContext.dart +++ b/lib/Models/managerContext.dart @@ -10,12 +10,13 @@ class ManagerAppContext with ChangeNotifier{ Client clientAPI; String currentRoute; ConfigurationDTO selectedConfiguration; + SectionDTO selectedSection; ManagerAppContext({this.email, this.token, this.currentRoute}); // Implement toString to make it easier to see information about @override String toString() { - return 'ManagerAppContext{email: $email, token: $token, currentRoute: $currentRoute}, selectedConfiguration: $selectedConfiguration}'; + return 'ManagerAppContext{email: $email, token: $token, currentRoute: $currentRoute}, selectedConfiguration: $selectedConfiguration, selectedSection: $selectedSection}'; } } \ No newline at end of file diff --git a/lib/Screens/Configurations/configuration_detail_screen.dart b/lib/Screens/Configurations/configuration_detail_screen.dart index 0366d31..8ff7965 100644 --- a/lib/Screens/Configurations/configuration_detail_screen.dart +++ b/lib/Screens/Configurations/configuration_detail_screen.dart @@ -29,6 +29,7 @@ class ConfigurationDetailScreen extends StatefulWidget { class _ConfigurationDetailScreenState extends State { ConfigurationDTO configurationDTO; + SectionDTO selectedSection; @override Widget build(BuildContext context) { @@ -176,8 +177,23 @@ class _ConfigurationDetailScreenState extends State { ], ), Align( - alignment: AlignmentDirectional.centerStart, - child: Text("Sections :", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) + alignment: AlignmentDirectional.centerStart, + child: Text("Sections :", style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) + ), + FutureBuilder( + future: getSections(configurationDTO, appContext.getContext().clientAPI), + builder: (context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done) { + var tempOutput = new List.from(snapshot.data); + print(tempOutput); + tempOutput.add(SectionDTO(id: null)); + return bodyGrid(tempOutput, size, appContext); + } else if (snapshot.connectionState == ConnectionState.none) { + return Text("No data"); + } else { + return Center(child: Container(height: size.height * 0.2, child: Text('LOADING TODO FRAISE'))); + } + } ), ], ), @@ -238,8 +254,8 @@ class _ConfigurationDetailScreenState extends State { ); } - getElement(ConfigurationDTO configuration, Size size) { - if (configuration.id != null) { + getElement(dynamic element, Size size) { + if (element.id != null) { return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -247,7 +263,7 @@ class _ConfigurationDetailScreenState extends State { Align( alignment: Alignment.centerLeft, child: AutoSizeText( - configuration.label, + element.label, style: new TextStyle(fontSize: 25), maxLines: 1, ), @@ -255,7 +271,7 @@ class _ConfigurationDetailScreenState extends State { Align( alignment: Alignment.bottomRight, child: AutoSizeText( - DateFormat('dd/MM/yyyy').format(configuration.dateCreation), + DateFormat('dd/MM/yyyy').format(element.dateCreation), style: new TextStyle(fontSize: 18, fontFamily: ""), maxLines: 1, ), @@ -266,11 +282,44 @@ class _ConfigurationDetailScreenState extends State { return Icon( Icons.add, color: kTextLightColor, - size: 100.0, + size: 50.0, ); } } + Widget bodyGrid(data, Size size, AppContext appContext) { + return GridView.builder( + shrinkWrap: true, + gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 8), + itemCount: data.length, + itemBuilder: (BuildContext context, int index) { + return + InkWell( + onTap: () { + if (data[index].id == null) { + print("open modal to create new section !"); + } else { + setState(() { + ManagerAppContext managerAppContext = appContext.getContext(); + managerAppContext.selectedSection = data[index]; + selectedSection = data[index]; + }); + } + }, + child: Container( + decoration: boxDecoration(data[index]), + padding: const EdgeInsets.all(15), + margin: EdgeInsets.symmetric(vertical: 15, horizontal: 15), + child: Align( + alignment: Alignment.center, + child: getElement(data[index], size) + ), + ), + ); + } + ); + } + Future save(ConfigurationDTO configurationDTO, AppContext appContext) async { ConfigurationDTO configuration = await appContext.getContext().clientAPI.configurationApi.configurationUpdate(configurationDTO); ManagerAppContext managerAppContext = appContext.getContext(); @@ -315,11 +364,17 @@ class _ConfigurationDetailScreenState extends State { return configuration; } + + Future> getSections(ConfigurationDTO configurationDTO, Client client) async { + List sections = await client.sectionApi.sectionGetFromConfiguration(configurationDTO.id); + print(sections); + return sections; + } } -boxDecoration(ConfigurationDTO configurationDTO) { +boxDecoration(dynamic element) { return BoxDecoration( - color: configurationDTO.id == null ? Colors.lightGreen : kTextLightColor, + color: element.id == null ? Colors.lightGreen : kTextLightColor, shape: BoxShape.rectangle, borderRadius: BorderRadius.circular(25.0), boxShadow: [ diff --git a/lib/Screens/login_screen.dart b/lib/Screens/login_screen.dart index 386f05f..747bc28 100644 --- a/lib/Screens/login_screen.dart +++ b/lib/Screens/login_screen.dart @@ -63,8 +63,8 @@ class _LoginScreenState extends State { print("error auth"); } - /*if (!isError) { - UserDetailDTO user = await clientAPI.userApi.userGetDetail("6071f74aaf542f03116f2b9b"); + if (!isError) { + /*UserDetailDTO user = await clientAPI.userApi.userGetDetail("6071f74aaf542f03116f2b9b"); print("user values ??"); print(user.email); print(user.id); @@ -75,7 +75,7 @@ class _LoginScreenState extends State { print(element); }); - List sections = await clientAPI.sectionApi.sectionGet(); + List sections = await clientAPI.sectionApi.sectionGetFromConfiguration(id); print("number of sections " + sections.length.toString()); sections.forEach((element) { print(element); @@ -85,8 +85,8 @@ class _LoginScreenState extends State { print("number of ressources " + ressources.length.toString()); ressources.forEach((element) { print(element); - }); - }*/ + });*/ + } } void setAccessToken(String accessToken) { diff --git a/manager_api/.openapi-generator/FILES b/manager_api/.openapi-generator/FILES index 0511881..478eaba 100644 --- a/manager_api/.openapi-generator/FILES +++ b/manager_api/.openapi-generator/FILES @@ -42,5 +42,3 @@ lib/model/token_dto.dart lib/model/user.dart lib/model/user_detail_dto.dart pubspec.yaml -test/configuration_api_test.dart -test/configuration_dto_test.dart diff --git a/manager_api/README.md b/manager_api/README.md index 010988a..6881bfc 100644 --- a/manager_api/README.md +++ b/manager_api/README.md @@ -82,6 +82,7 @@ Class | Method | HTTP request | Description *SectionApi* | [**sectionGet**](doc\/SectionApi.md#sectionget) | **GET** /api/Section | *SectionApi* | [**sectionGetAllSectionSubSections**](doc\/SectionApi.md#sectiongetallsectionsubsections) | **GET** /api/Section/{id}/subsections | *SectionApi* | [**sectionGetDetail**](doc\/SectionApi.md#sectiongetdetail) | **GET** /api/Section/{id} | +*SectionApi* | [**sectionGetFromConfiguration**](doc\/SectionApi.md#sectiongetfromconfiguration) | **GET** /api/Section/configuration/{id} | *SectionApi* | [**sectionUpdate**](doc\/SectionApi.md#sectionupdate) | **PUT** /api/Section | *UserApi* | [**userCreateUser**](doc\/UserApi.md#usercreateuser) | **POST** /api/User | *UserApi* | [**userDeleteUser**](doc\/UserApi.md#userdeleteuser) | **DELETE** /api/User/{id} | diff --git a/manager_api/doc/SectionApi.md b/manager_api/doc/SectionApi.md index f3df477..1636a66 100644 --- a/manager_api/doc/SectionApi.md +++ b/manager_api/doc/SectionApi.md @@ -14,6 +14,7 @@ Method | HTTP request | Description [**sectionGet**](SectionApi.md#sectionget) | **GET** /api/Section | [**sectionGetAllSectionSubSections**](SectionApi.md#sectiongetallsectionsubsections) | **GET** /api/Section/{id}/subsections | [**sectionGetDetail**](SectionApi.md#sectiongetdetail) | **GET** /api/Section/{id} | +[**sectionGetFromConfiguration**](SectionApi.md#sectiongetfromconfiguration) | **GET** /api/Section/configuration/{id} | [**sectionUpdate**](SectionApi.md#sectionupdate) | **PUT** /api/Section | @@ -228,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) +# **sectionGetFromConfiguration** +> List sectionGetFromConfiguration(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 = SectionApi(); +final id = id_example; // String | + +try { + final result = api_instance.sectionGetFromConfiguration(id); + print(result); +} catch (e) { + print('Exception when calling SectionApi->sectionGetFromConfiguration: $e\n'); +} +``` + +### Parameters + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **id** | **String**| | + +### Return type + +[**List**](SectionDTO.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) + # **sectionUpdate** > SectionDTO sectionUpdate(sectionDTO) diff --git a/manager_api/lib/api/section_api.dart b/manager_api/lib/api/section_api.dart index 4d0bb9a..098a470 100644 --- a/manager_api/lib/api/section_api.dart +++ b/manager_api/lib/api/section_api.dart @@ -326,6 +326,72 @@ class SectionApi { return Future.value(null); } + /// Performs an HTTP 'GET /api/Section/configuration/{id}' operation and returns the [Response]. + /// Parameters: + /// + /// * [String] id (required): + Future sectionGetFromConfigurationWithHttpInfo(String id) async { + // Verify required params are set. + if (id == null) { + throw ApiException(HttpStatus.badRequest, 'Missing required param: id'); + } + + final path = r'/api/Section/configuration/{id}' + .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> sectionGetFromConfiguration(String id) async { + final response = await sectionGetFromConfigurationWithHttpInfo(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), 'List') as List) + .cast() + .toList(growable: false); + } + return Future>.value(null); + } + /// Performs an HTTP 'PUT /api/Section' operation and returns the [Response]. /// Parameters: /// diff --git a/manager_api/swagger.yaml b/manager_api/swagger.yaml index f69c724..da62419 100644 --- a/manager_api/swagger.yaml +++ b/manager_api/swagger.yaml @@ -482,6 +482,42 @@ paths: type: string security: - bearer: [] + '/api/Section/configuration/{id}': + get: + tags: + - Section + operationId: Section_GetFromConfiguration + parameters: + - name: id + in: path + required: true + schema: + type: string + nullable: true + x-position: 1 + responses: + '200': + description: '' + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/SectionDTO' + '400': + description: '' + content: + application/json: + schema: + type: string + '500': + description: '' + content: + application/json: + schema: + type: string + security: + - bearer: [] '/api/Section/{id}/subsections': get: tags: @@ -503,6 +539,12 @@ paths: schema: type: array items: {} + '400': + description: '' + content: + application/json: + schema: + type: string '500': description: '' content: