'Mot' and 'Contexte principal' are now required

main
CAPEL Maxime 2023-12-07 11:09:49 +01:00
parent 96999dff8b
commit 7aa1bb2759
1 changed files with 58 additions and 40 deletions

View File

@ -1,29 +1,27 @@
package main package main
import androidx.compose.desktop.ui.tooling.preview.Preview import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.*
import androidx.compose.material.* import androidx.compose.material.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check import androidx.compose.material.icons.filled.Check
import androidx.compose.material.icons.filled.Close import androidx.compose.material.icons.filled.Close
import java.awt.FileDialog import androidx.compose.runtime.Composable
import java.awt.Frame import androidx.compose.runtime.mutableStateOf
import androidx.compose.material.Button import androidx.compose.runtime.remember
import androidx.compose.material.MaterialTheme import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.* import androidx.compose.ui.window.*
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import java.awt.FileDialog
import java.awt.Frame
import java.io.File import java.io.File
import java.io.FileWriter import java.io.FileWriter
import java.io.IOException import java.io.IOException
import kotlinx.serialization.encodeToString
val customRedColor = Color(0xFFB70D1B) val customRedColor = Color(0xFFB70D1B)
@ -56,15 +54,18 @@ fun homePage(
Text("Glossaire") Text("Glossaire")
} }
Button(onClick = onCodeAVerifierClick, Button(
onClick = onCodeAVerifierClick,
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
) ) { )
) {
Text("Code à Vérifier") Text("Code à Vérifier")
} }
Button(onClick = { /* Action de Comparer */ }, Button(
onClick = { /* Action de Comparer */ },
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
@ -89,6 +90,7 @@ fun app() {
onCodeAVerifierClick = { currentPage.value = "choixLangage" } onCodeAVerifierClick = { currentPage.value = "choixLangage" }
) )
} }
"glossaire" -> { "glossaire" -> {
glossairePage( glossairePage(
onAjouterMotClick = { currentPage.value = "formulaire" }, onAjouterMotClick = { currentPage.value = "formulaire" },
@ -115,9 +117,11 @@ fun app() {
onRetourClick = { currentPage.value = "accueil" } onRetourClick = { currentPage.value = "accueil" }
) )
} }
"formulaire" -> { "formulaire" -> {
formulairePage(onAnnulerClick = { currentPage.value = "glossaire" }) formulairePage(onAnnulerClick = { currentPage.value = "glossaire" })
} }
"choixLangage" -> { "choixLangage" -> {
val pythonExtensions = setOf("py") val pythonExtensions = setOf("py")
val javaExtensions = setOf("java") val javaExtensions = setOf("java")
@ -127,7 +131,8 @@ fun app() {
onPythonClick = { onPythonClick = {
selectFile(pythonExtensions) { filePath -> selectFile(pythonExtensions) { filePath ->
println("Python file selected: $filePath") // Change by parser functions println("Python file selected: $filePath") // Change by parser functions
} }, }
},
onJavaClick = { onJavaClick = {
selectFile(javaExtensions) { filePath -> selectFile(javaExtensions) { filePath ->
println("Java file selected: $filePath") // Change by parser functions println("Java file selected: $filePath") // Change by parser functions
@ -152,7 +157,6 @@ fun selectFile(extensions: Set<String>, onFileSelected: (String) -> Unit) {
fileDialog.isVisible = true fileDialog.isVisible = true
val selectedFile = fileDialog.file val selectedFile = fileDialog.file
val selectedDirectory = fileDialog.directory val selectedDirectory = fileDialog.directory
@ -233,7 +237,6 @@ fun importCSV(cheminFichier: String) {
} }
fun verifierChampsRequis(mot: Map<String, String>): Boolean { fun verifierChampsRequis(mot: Map<String, String>): Boolean {
//Vérifier que les headers sont égales aux champs requis //Vérifier que les headers sont égales aux champs requis
val champsRequis = listOf( val champsRequis = listOf(
@ -299,7 +302,8 @@ fun choixLangagePage(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
)) { )
) {
Text("Java") Text("Java")
} }
@ -308,7 +312,8 @@ fun choixLangagePage(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
)) { )
) {
Text("JavaScript") Text("JavaScript")
} }
} }
@ -324,7 +329,8 @@ fun choixLangagePage(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
)) { )
) {
Text("Retour") Text("Retour")
} }
} }
@ -361,7 +367,8 @@ fun glossairePage(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
)) { )
) {
Text("Ajouter un mot") Text("Ajouter un mot")
} }
@ -370,7 +377,8 @@ fun glossairePage(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
)) { )
) {
Text("Importer un fichier CSV") Text("Importer un fichier CSV")
} }
@ -379,7 +387,8 @@ fun glossairePage(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
)) { )
) {
Text("Exporter un fichier CSV") Text("Exporter un fichier CSV")
} }
@ -396,7 +405,8 @@ fun glossairePage(
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(
backgroundColor = customRedColor, backgroundColor = customRedColor,
contentColor = Color.White contentColor = Color.White
)) { )
) {
Text("Retour") Text("Retour")
} }
} }
@ -413,17 +423,13 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
verticalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally horizontalAlignment = Alignment.CenterHorizontally
) { ) {
Text(text = "Nouveau contexte métier", style = MaterialTheme.typography.h5) Text(text = "Nouveau mot", style = MaterialTheme.typography.h5)
val nom = remember { mutableStateOf("") } val nom = remember { mutableStateOf("") }
TextField( TextField(
value = nom.value, value = nom.value,
onValueChange = { nom.value = it }, onValueChange = { nom.value = it },
label = { Text("Mot") }, label = { Text("Mot *") },
colors = TextFieldDefaults.textFieldColors(
focusedIndicatorColor = customRedColor, // Change this to the color you want
unfocusedIndicatorColor = Color.Gray // Change this to the color you want
)
) )
val description = remember { mutableStateOf("") } val description = remember { mutableStateOf("") }
@ -441,7 +447,7 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
TextField( TextField(
value = contextePrincipal.value, value = contextePrincipal.value,
onValueChange = { contextePrincipal.value = it }, onValueChange = { contextePrincipal.value = it },
label = { Text("Contexte principal") }, label = { Text("Contexte principal *") },
colors = TextFieldDefaults.textFieldColors( colors = TextFieldDefaults.textFieldColors(
focusedIndicatorColor = customRedColor, // Change this to the color you want focusedIndicatorColor = customRedColor, // Change this to the color you want
unfocusedIndicatorColor = Color.Gray // Change this to the color you want unfocusedIndicatorColor = Color.Gray // Change this to the color you want
@ -509,6 +515,10 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
Button( Button(
onClick = { onClick = {
// Validation du formulaire // Validation du formulaire
if (nom.value.isBlank() || contextePrincipal.value.isBlank()) {
println("Les champs 'Mot' et 'Contexte principal' sont obligatoires.")
return@Button
}
val nouveauMot = Mot( val nouveauMot = Mot(
nom = nom.value, nom = nom.value,
@ -522,6 +532,14 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
ajouterMotAuGlossaire(nouveauMot) ajouterMotAuGlossaire(nouveauMot)
// Réinitialiser les champs après l'ajout
nom.value = ""
description.value = ""
contextePrincipal.value = ""
contexte2.value = ""
lieA.value = ""
synonyme.value = ""
antonyme.value = ""
}, },
colors = ButtonDefaults.buttonColors( colors = ButtonDefaults.buttonColors(