From 7aa1bb2759c50b9db6ec20a28def90c8c2c3ce73 Mon Sep 17 00:00:00 2001 From: CAPEL Maxime <83071634+fortyup@users.noreply.github.com> Date: Thu, 7 Dec 2023 11:09:49 +0100 Subject: [PATCH] 'Mot' and 'Contexte principal' are now required --- src/main/kotlin/main/Main.kt | 98 +++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/src/main/kotlin/main/Main.kt b/src/main/kotlin/main/Main.kt index 50401d9..ca66af5 100644 --- a/src/main/kotlin/main/Main.kt +++ b/src/main/kotlin/main/Main.kt @@ -1,29 +1,27 @@ package main 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.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.filled.Check import androidx.compose.material.icons.filled.Close -import java.awt.FileDialog -import java.awt.Frame -import androidx.compose.material.Button -import androidx.compose.material.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.dp import androidx.compose.ui.window.* +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import java.awt.FileDialog +import java.awt.Frame import java.io.File import java.io.FileWriter import java.io.IOException -import kotlinx.serialization.encodeToString val customRedColor = Color(0xFFB70D1B) @@ -56,15 +54,18 @@ fun homePage( Text("Glossaire") } - Button(onClick = onCodeAVerifierClick, + Button( + onClick = onCodeAVerifierClick, colors = ButtonDefaults.buttonColors( - backgroundColor = customRedColor, - contentColor = Color.White - ) ) { + backgroundColor = customRedColor, + contentColor = Color.White + ) + ) { Text("Code à Vérifier") } - Button(onClick = { /* Action de Comparer */ }, + Button( + onClick = { /* Action de Comparer */ }, colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White @@ -89,6 +90,7 @@ fun app() { onCodeAVerifierClick = { currentPage.value = "choixLangage" } ) } + "glossaire" -> { glossairePage( onAjouterMotClick = { currentPage.value = "formulaire" }, @@ -115,9 +117,11 @@ fun app() { onRetourClick = { currentPage.value = "accueil" } ) } + "formulaire" -> { formulairePage(onAnnulerClick = { currentPage.value = "glossaire" }) } + "choixLangage" -> { val pythonExtensions = setOf("py") val javaExtensions = setOf("java") @@ -127,7 +131,8 @@ fun app() { onPythonClick = { selectFile(pythonExtensions) { filePath -> println("Python file selected: $filePath") // Change by parser functions - } }, + } + }, onJavaClick = { selectFile(javaExtensions) { filePath -> println("Java file selected: $filePath") // Change by parser functions @@ -152,7 +157,6 @@ fun selectFile(extensions: Set, onFileSelected: (String) -> Unit) { fileDialog.isVisible = true - val selectedFile = fileDialog.file val selectedDirectory = fileDialog.directory @@ -233,7 +237,6 @@ fun importCSV(cheminFichier: String) { } - fun verifierChampsRequis(mot: Map): Boolean { //Vérifier que les headers sont égales aux champs requis val champsRequis = listOf( @@ -299,7 +302,8 @@ fun choixLangagePage( colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White - )) { + ) + ) { Text("Java") } @@ -308,7 +312,8 @@ fun choixLangagePage( colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White - )) { + ) + ) { Text("JavaScript") } } @@ -324,7 +329,8 @@ fun choixLangagePage( colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White - )) { + ) + ) { Text("Retour") } } @@ -361,7 +367,8 @@ fun glossairePage( colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White - )) { + ) + ) { Text("Ajouter un mot") } @@ -370,7 +377,8 @@ fun glossairePage( colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White - )) { + ) + ) { Text("Importer un fichier CSV") } @@ -379,7 +387,8 @@ fun glossairePage( colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White - )) { + ) + ) { Text("Exporter un fichier CSV") } @@ -396,7 +405,8 @@ fun glossairePage( colors = ButtonDefaults.buttonColors( backgroundColor = customRedColor, contentColor = Color.White - )) { + ) + ) { Text("Retour") } } @@ -413,17 +423,13 @@ fun formulairePage(onAnnulerClick: () -> Unit) { verticalArrangement = Arrangement.spacedBy(8.dp), 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("") } TextField( value = nom.value, onValueChange = { nom.value = it }, - 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 - ) + label = { Text("Mot *") }, ) val description = remember { mutableStateOf("") } @@ -441,7 +447,7 @@ fun formulairePage(onAnnulerClick: () -> Unit) { TextField( value = contextePrincipal.value, onValueChange = { contextePrincipal.value = it }, - label = { Text("Contexte principal") }, + label = { Text("Contexte principal *") }, colors = TextFieldDefaults.textFieldColors( focusedIndicatorColor = customRedColor, // Change this to the color you want unfocusedIndicatorColor = Color.Gray // Change this to the color you want @@ -509,19 +515,31 @@ fun formulairePage(onAnnulerClick: () -> Unit) { Button( onClick = { // Validation du formulaire + if (nom.value.isBlank() || contextePrincipal.value.isBlank()) { + println("Les champs 'Mot' et 'Contexte principal' sont obligatoires.") + return@Button + } val nouveauMot = Mot( - nom=nom.value, - description=description.value, - contextePrincipal=contextePrincipal.value, - contexte2=contexte2.value, - lieA=lieA.value, - synonyme=synonyme.value, - antonyme=antonyme.value + nom = nom.value, + description = description.value, + contextePrincipal = contextePrincipal.value, + contexte2 = contexte2.value, + lieA = lieA.value, + synonyme = synonyme.value, + antonyme = antonyme.value ) 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(