2025-11-27 15:47:21 +01:00

283 lines
11 KiB
Dart

import 'package:manager_app/Components/resource_input_container.dart';
import 'package:flutter/material.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/Screens/Configurations/Section/SubSection/Agenda/agenda_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Article/article_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Game/game_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Map/map_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/PDF/PDF_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Quizz/quizz_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Slider/slider_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Video/video_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Weather/weather_config.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/WebOrVideo/web_config.dart';
import 'package:manager_app/app_context.dart';
import 'package:manager_app/constants.dart';
import 'package:manager_api_new/api.dart';
import 'menu_config.dart';
void showEditSubSection(SectionDTO subSectionDTO, Function getResult, AppContext appContext, BuildContext context, Object rawSubSectionData) {
Object updatedRawSubSectionData = rawSubSectionData;
Size size = MediaQuery.of(context).size;
showDialog(
builder: (BuildContext context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))
),
content: Container(
width: size.width *0.85,
child: SingleChildScrollView(
child: Column(
children: [
Text("Modifier sous section", style: new TextStyle(fontSize: 25, fontWeight: FontWeight.w400)),
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
SizedBox(
height: 100,
child: StringInputContainer(
label: "Nom :",
initialValue: subSectionDTO.label,
onChanged: (String name) {
subSectionDTO.label = name;
},
),
),
ResourceInputContainer(
label: "Image :",
initialValue: subSectionDTO.imageId,
color: kPrimaryColor,
onChanged: (ResourceDTO resource) {
if(resource.id == null) {
subSectionDTO.imageId = null;
subSectionDTO.imageSource = null;
} else {
subSectionDTO.imageId = resource.id;
subSectionDTO.imageSource = resource.url;
}
},
isSmall: true,
),
],
),
Container(
height: size.height * 0.1,
width: double.infinity,
constraints: BoxConstraints(minHeight: 50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
constraints: BoxConstraints(minHeight: 50, maxHeight: 80),
child: MultiStringInputContainer(
label: "Titre affiché:",
modalLabel: "Titre",
fontSize: 20,
isHTML: true,
color: kPrimaryColor,
initialValue: subSectionDTO.title != null ? subSectionDTO.title! : [],
onGetResult: (value) {
if (subSectionDTO.title != value) {
subSectionDTO.title = value;
}
},
maxLines: 1,
isTitle: true
),
),
Container(
constraints: BoxConstraints(minHeight: 50, maxHeight: 80),
child: MultiStringInputContainer(
label: "Description affichée:",
modalLabel: "Description",
fontSize: 20,
isHTML: true,
color: kPrimaryColor,
initialValue: subSectionDTO.description != null ? subSectionDTO.description! : [],
isMandatory: false,
onGetResult: (value) {
if (subSectionDTO.description != value) {
subSectionDTO.description = value;
}
},
maxLines: 1,
isTitle: false
),
),
],
)
),
Container(
decoration: BoxDecoration(
color: kWhite,
borderRadius: BorderRadius.circular(20),
border: Border.all(width: 0.5, color: kSecond)
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: getSpecificData(
subSectionDTO,
rawSubSectionData,
rawSubSectionData,
appContext,
(updatedData) {
updatedRawSubSectionData = updatedData;
}),
),
),
],
),
],
),
),
),
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: subSectionDTO != null ? 220: 150,
height: 70,
child: RoundedButton(
text: "Sauvegarder",
icon: Icons.check,
color: kPrimaryColor,
textColor: kWhite,
press: () {
getResult(updatedRawSubSectionData);
Navigator.of(context).pop();
},
fontSize: 20,
),
),
),
],
),
],
), context: context
);
}
getSpecificData(SectionDTO subSectionDTO, Object? rawSectionData, Object sectionDetailDTO, AppContext appContext, Function(Object) onChanged) {
switch(subSectionDTO.type) {
case SectionType.Map:
MapDTO mapDTO = MapDTO.fromJson(rawSectionData)!;
sectionDetailDTO = mapDTO;
return MapConfig(
initialValue: mapDTO,
onChanged: (MapDTO changedMap) {
onChanged(changedMap);
},
);
case SectionType.Slider:
SliderDTO sliderDTO = SliderDTO.fromJson(rawSectionData)!;
sectionDetailDTO = sliderDTO;
return SliderConfig(
initialValue: sliderDTO,
onChanged: (SliderDTO changedSlider) {
onChanged(changedSlider);
},
);
case SectionType.Video:
VideoDTO videoDTO = VideoDTO.fromJson(rawSectionData)!;
sectionDetailDTO = videoDTO;
return VideoConfig(
label: "Url de la vidéo:",
initialValue: videoDTO,
onChanged: (VideoDTO updatedWebDTO) {
onChanged(updatedWebDTO);
},
);
case SectionType.Web:
WebDTO webDTO = WebDTO.fromJson(rawSectionData)!;
sectionDetailDTO = webDTO;
return WebConfig(
label: "Url du site web:",
initialValue: webDTO,
onChanged: (WebDTO updatedWebDTO) {
onChanged(updatedWebDTO);
},
);
case SectionType.Quiz:
QuizDTO quizDTO = QuizDTO.fromJson(rawSectionData)!;
sectionDetailDTO = quizDTO;
return QuizzConfig(
initialValue: quizDTO,
onChanged: (QuizDTO updatedQuiz) {
onChanged(updatedQuiz);
},
);
case SectionType.Article:
ArticleDTO articleDTO = ArticleDTO.fromJson(rawSectionData)!;
sectionDetailDTO = articleDTO;
return ArticleConfig(
initialValue: articleDTO,
onChanged: (ArticleDTO changedArticle)
{
onChanged(changedArticle);
},
);
case SectionType.Pdf:
PdfDTO pdfDTO = PdfDTO.fromJson(rawSectionData)!;
sectionDetailDTO = pdfDTO;
return PDFConfig(
initialValue: pdfDTO,
onChanged: (PdfDTO changedPDF) {
onChanged(changedPDF);
},
);
case SectionType.Game:
GameDTO gameDTO = GameDTO.fromJson(rawSectionData)!;
sectionDetailDTO = gameDTO;
return GameConfig(
initialValue: gameDTO,
onChanged: (GameDTO updatedGame) {
onChanged(updatedGame);
},
);
case SectionType.Agenda:
AgendaDTO agendaDTO = AgendaDTO.fromJson(rawSectionData)!;
sectionDetailDTO = agendaDTO;
return AgendaConfig(
initialValue: agendaDTO,
onChanged: (AgendaDTO updatedAgenda) {
onChanged(updatedAgenda);
},
);
case SectionType.Weather:
WeatherDTO weatherDTO = WeatherDTO.fromJson(rawSectionData)!;
sectionDetailDTO = weatherDTO;
return WeatherConfig(
initialValue: weatherDTO,
onChanged: (WeatherDTO updatedWeather) {
onChanged(updatedWeather);
},
);
}
}