Add TranslationDTO from service generation + MultiInputModal (translations)

This commit is contained in:
Thomas Fransolet 2021-05-06 18:28:19 +02:00
parent 6e2dac52d1
commit 69664c4bec
13 changed files with 294 additions and 11 deletions

View File

@ -0,0 +1,73 @@
import 'package:flutter/material.dart';
import 'package:manager_app/Components/rounded_button.dart';
import 'package:manager_app/Components/string_input_container.dart';
import 'package:manager_app/constants.dart';
import 'package:managerapi/api.dart';
showMultiStringInput (List<TranslationDTO> values, ValueChanged<List<TranslationDTO>> onChanged, BuildContext context) { /*Function onSelect,*/
List<TranslationDTO> newValues = new List<TranslationDTO>();
newValues = values;
showDialog(
builder: (BuildContext context) => AlertDialog(
content: SingleChildScrollView(
child: Column(
children: showValues(newValues),
)
),
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
width: 180,
height: 70,
child: RoundedButton(
text: "Annuler",
icon: Icons.undo,
color: kSecond,
press: () {
onChanged(values);
Navigator.of(context).pop();
},
fontSize: 20,
),
),
Container(
width: 180,
height: 70,
child: RoundedButton(
text: "Valider",
icon: Icons.check,
color: kPrimaryColor,
textColor: kWhite,
press: () {
onChanged(newValues);
Navigator.of(context).pop();
},
fontSize: 20,
),
),
],
),
],
), context: context
);
}
showValues(List<TranslationDTO> newValues) {
List<Widget> valuesToShow = new List<Widget>();
newValues.forEach((newValue) {
valuesToShow.add(
new StringContainer(
color: Colors.lightBlue,
label: newValue.language,
initialValue: newValue.value,
onChanged: (String value) {
newValue.value = value;
},
));
});
return valuesToShow;
}

View File

@ -0,0 +1,61 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:manager_app/Components/multi_input_modal.dart';
import 'package:manager_app/Components/rounded_input_field.dart';
import 'package:manager_app/constants.dart';
import 'package:managerapi/api.dart';
class MultiStringContainer extends StatelessWidget {
final Color color;
final String label;
final List<TranslationDTO> initialValue;
final ValueChanged<List<TranslationDTO>> onChanged;
const MultiStringContainer({
Key key,
this.color = kSecond,
this.label,
this.initialValue,
this.onChanged,
}) : super(key: key);
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Container(
child: Row(
children: [
Align(
alignment: AlignmentDirectional.centerStart,
child: Text(label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300))
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
width: size.width *0.15,
child: InkWell(
onTap: () {
showMultiStringInput(initialValue, onChanged, context);
},
child: Container(
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(50),
),
child: Padding(
padding: const EdgeInsets.only(left: 5, right: 5, top: 15, bottom: 15),
child: Center(
child: AutoSizeText(
"Changer les traductions",
maxLines: 2,
)
),
)
),
),
),
),
],
),
);
}
}

View File

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:manager_app/Components/confirmation_dialog.dart';
import 'package:manager_app/Components/fetch_section_icon.dart';
import 'package:manager_app/Components/multi_select_container.dart';
import 'package:manager_app/Components/multi_string_input_container.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';
@ -151,20 +152,20 @@ class _SectionDetailScreenState extends State<SectionDetailScreen> {
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
StringContainer(
MultiStringContainer(
label: "Titre :",
initialValue: sectionDTO.title,
onChanged: (value) {
sectionDTO.title = value;
},
),
StringContainer(
MultiStringContainer(
label: "Description :",
initialValue: sectionDTO.description,
onChanged: (value) {
sectionDTO.description = value;
},
),
)
],
)
],

View File

@ -17,6 +17,7 @@ doc/SectionApi.md
doc/SectionDTO.md
doc/SectionType.md
doc/TokenDTO.md
doc/TranslationDTO.md
doc/User.md
doc/UserApi.md
doc/UserDetailDTO.md
@ -47,6 +48,8 @@ lib/model/ressource_type.dart
lib/model/section_dto.dart
lib/model/section_type.dart
lib/model/token_dto.dart
lib/model/translation_dto.dart
lib/model/user.dart
lib/model/user_detail_dto.dart
pubspec.yaml
test/translation_dto_test.dart

View File

@ -110,6 +110,7 @@ Class | Method | HTTP request | Description
- [SectionDTO](doc\/SectionDTO.md)
- [SectionType](doc\/SectionType.md)
- [TokenDTO](doc\/TokenDTO.md)
- [TranslationDTO](doc\/TranslationDTO.md)
- [User](doc\/User.md)
- [UserDetailDTO](doc\/UserDetailDTO.md)

View File

@ -10,8 +10,8 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **String** | | [optional]
**label** | **String** | | [optional]
**title** | **String** | | [optional]
**description** | **String** | | [optional]
**title** | [**List<TranslationDTO>**](TranslationDTO.md) | | [optional] [default to const []]
**description** | [**List<TranslationDTO>**](TranslationDTO.md) | | [optional] [default to const []]
**imageId** | **String** | | [optional]
**configurationId** | **String** | | [optional]
**isSubSection** | **bool** | | [optional]

View File

@ -0,0 +1,16 @@
# managerapi.model.TranslationDTO
## Load the model package
```dart
import 'package:managerapi/api.dart';
```
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**language** | **String** | | [optional]
**value** | **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)

View File

@ -45,6 +45,7 @@ part 'model/ressource_type.dart';
part 'model/section_dto.dart';
part 'model/section_type.dart';
part 'model/token_dto.dart';
part 'model/translation_dto.dart';
part 'model/user.dart';
part 'model/user_detail_dto.dart';

View File

@ -180,6 +180,8 @@ class ApiClient {
case 'TokenDTO':
return TokenDTO.fromJson(value);
case 'TranslationDTO':
return TranslationDTO.fromJson(value);
case 'User':
return User.fromJson(value);
case 'UserDetailDTO':

View File

@ -29,9 +29,9 @@ class SectionDTO {
String label;
String title;
List<TranslationDTO> title;
String description;
List<TranslationDTO> description;
String imageId;
@ -123,8 +123,8 @@ class SectionDTO {
: SectionDTO(
id: json[r'id'],
label: json[r'label'],
title: json[r'title'],
description: json[r'description'],
title: TranslationDTO.listFromJson(json[r'title']),
description: TranslationDTO.listFromJson(json[r'description']),
imageId: json[r'imageId'],
configurationId: json[r'configurationId'],
isSubSection: json[r'isSubSection'],

View File

@ -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 TranslationDTO {
/// Returns a new [TranslationDTO] instance.
TranslationDTO({
this.language,
this.value,
});
String language;
String value;
@override
bool operator ==(Object other) => identical(this, other) || other is TranslationDTO &&
other.language == language &&
other.value == value;
@override
int get hashCode =>
(language == null ? 0 : language.hashCode) +
(value == null ? 0 : value.hashCode);
@override
String toString() => 'TranslationDTO[language=$language, value=$value]';
Map<String, dynamic> toJson() {
final json = <String, dynamic>{};
if (language != null) {
json[r'language'] = language;
}
if (value != null) {
json[r'value'] = value;
}
return json;
}
/// Returns a new [TranslationDTO] instance and imports its values from
/// [json] if it's non-null, null if [json] is null.
static TranslationDTO fromJson(Map<String, dynamic> json) => json == null
? null
: TranslationDTO(
language: json[r'language'],
value: json[r'value'],
);
static List<TranslationDTO> listFromJson(List<dynamic> json, {bool emptyIsNull, bool growable,}) =>
json == null || json.isEmpty
? true == emptyIsNull ? null : <TranslationDTO>[]
: json.map((v) => TranslationDTO.fromJson(v)).toList(growable: true == growable);
static Map<String, TranslationDTO> mapFromJson(Map<String, dynamic> json) {
final map = <String, TranslationDTO>{};
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic v) => map[key] = TranslationDTO.fromJson(v));
}
return map;
}
// maps a json object with a list of TranslationDTO-objects as value to a dart map
static Map<String, List<TranslationDTO>> mapListFromJson(Map<String, dynamic> json, {bool emptyIsNull, bool growable,}) {
final map = <String, List<TranslationDTO>>{};
if (json != null && json.isNotEmpty) {
json.forEach((String key, dynamic v) {
map[key] = TranslationDTO.listFromJson(v, emptyIsNull: emptyIsNull, growable: growable);
});
}
return map;
}
}

View File

@ -1200,11 +1200,15 @@ components:
type: string
nullable: true
title:
type: string
type: array
nullable: true
items:
$ref: '#/components/schemas/TranslationDTO'
description:
type: string
type: array
nullable: true
items:
$ref: '#/components/schemas/TranslationDTO'
imageId:
type: string
nullable: true
@ -1224,6 +1228,16 @@ components:
dateCreation:
type: string
format: date-time
TranslationDTO:
type: object
additionalProperties: false
properties:
language:
type: string
nullable: true
value:
type: string
nullable: true
SectionType:
type: string
description: ''

View File

@ -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 TranslationDTO
void main() {
final instance = TranslationDTO();
group('test TranslationDTO', () {
// String language
test('to test the property `language`', () async {
// TODO
});
// String value
test('to test the property `value`', () async {
// TODO
});
});
}