'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
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
) ) {
)
) {
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<String>, 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<String, String>): 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,6 +515,10 @@ 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,
@ -522,6 +532,14 @@ fun formulairePage(onAnnulerClick: () -> Unit) {
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(