manager-app/lib/Screens/Configurations/new_section_popup.dart

167 lines
7.0 KiB
Dart

import 'package:flutter/material.dart';
import 'package:manager_app/Components/dropDown_input_container.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:manager_api_new/api.dart';
Future<SectionDTO?> showNewSection(String configurationId,
AppContext appContext, BuildContext contextBuild, bool isSubSection) {
SectionDTO sectionDTO = new SectionDTO();
sectionDTO.label = "";
sectionDTO.configurationId = configurationId;
sectionDTO.isSubSection = isSubSection;
sectionDTO.isActive = true;
sectionDTO.parentId = isSubSection
? (appContext.getContext() as ManagerAppContext).selectedSection!.id
: null;
Size size = MediaQuery.of(contextBuild).size;
sectionDTO.type = SectionType.Map;
var section = showDialog<SectionDTO?>(
builder: (BuildContext context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
content: SingleChildScrollView(
child: SizedBox(
width: 750,
height: 250,
child: Container(
constraints: BoxConstraints(minHeight: 300, minWidth: 300),
child: Column(
children: [
Text(
isSubSection
? "Nouvelle sous section"
: "Nouvelle section",
style: new TextStyle(
fontSize: 25, fontWeight: FontWeight.w400)),
Column(
children: [
SizedBox(
height: 100,
child: StringInputContainer(
label: "Nom :",
initialValue: sectionDTO.label,
onChanged: (value) {
sectionDTO.label = value;
},
),
),
DropDownInputContainer(
label: "Type:",
values: isSubSection
? section_types
.where(
(sectionType) => sectionType != "Menu")
.toList()
: section_types
.toList(), // Todo get menu by enum type
initialValue: "Map",
onChange: (String? value) {
sectionDTO.type = SectionType.fromJson(value);
},
),
/*MultiSelectContainer(
label: "Type:",
initialValue: isMobile ? ["Article"] : ["Map"],
isMultiple: false,
values: isMobile ? section_types.where((sectionType) => sectionType == "Article" || sectionType == "Quizz").toList(): isSubSection ? section_types.where((sectionType) => sectionType != "Menu" && sectionType != "Article").toList(): section_types.where((sectionType) => sectionType != "Article").toList(), // Todo get menu by enum type
onChanged: (value) {
var tempOutput = new List<String>.from(value);
sectionDTO.type = SectionType.fromJson(tempOutput[0]);
},
),*/
],
),
],
),
),
),
),
actions: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Align(
alignment: AlignmentDirectional.bottomEnd,
child: Container(
width: 175,
height: 70,
child: RoundedButton(
text: "Annuler",
icon: Icons.undo,
color: kSecond,
press: () {
Navigator.of(context).pop();
},
fontSize: 20,
),
),
),
Align(
alignment: AlignmentDirectional.bottomEnd,
child: Container(
width: 150,
height: 70,
child: RoundedButton(
text: "Créer",
icon: Icons.check,
color: kPrimaryColor,
textColor: kWhite,
press: () {
if (sectionDTO.label != null &&
sectionDTO.label!.length > 2) {
//onYes();
Navigator.of(context).pop(sectionDTO);
//create(sectionDTO, appContext, context, isSubSection, sendSubSection);
} else {
showNotification(
Colors.orange,
kWhite,
'Veuillez spécifier un nom pour la nouvelle section',
context,
null);
}
},
fontSize: 20,
),
),
),
],
),
],
),
context: contextBuild);
return section;
}
void create(SectionDTO sectionDTO, AppContext appContext, BuildContext context,
bool isSubSection, Function? sendSubSection) async {
if (sectionDTO.label != null) {
ManagerAppContext managerAppContext = appContext.getContext();
sectionDTO.instanceId = managerAppContext.instanceId;
sectionDTO.isBeacon = false;
sectionDTO.dateCreation = DateTime.now();
SectionDTO? newSection = await managerAppContext.clientAPI!.sectionApi!
.sectionCreate(sectionDTO);
if (!isSubSection) {
/*if (managerAppContext.selectedConfiguration.sectionIds == null) {
managerAppContext.selectedConfiguration.sectionIds = <String>[];
}
managerAppContext.selectedConfiguration.sectionIds.add(newSection.id);*/
appContext.setContext(managerAppContext);
showNotification(kSuccess, kWhite, 'La section a été créée avec succès !',
context, null);
} else {
sendSubSection!(newSection);
}
Navigator.of(context).pop();
}
}