Added JSON saving of Glossaire
parent
12255f2986
commit
9a911e9352
|
@ -42,3 +42,7 @@ bin/
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.run/*
|
.run/*
|
||||||
|
|
||||||
|
/glossaire.json
|
||||||
|
```
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ dependencies {
|
||||||
// With compose.desktop.common you will also lose @Preview functionality
|
// With compose.desktop.common you will also lose @Preview functionality
|
||||||
implementation(compose.desktop.currentOs)
|
implementation(compose.desktop.currentOs)
|
||||||
implementation(kotlin("stdlib"))
|
implementation(kotlin("stdlib"))
|
||||||
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0")
|
||||||
implementation("mysql:mysql-connector-java:8.0.23")
|
implementation("mysql:mysql-connector-java:8.0.23")
|
||||||
implementation("org.jetbrains.compose.material:material:1.0.0-beta-02")
|
implementation("org.jetbrains.compose.material:material:1.0.0-beta-02")
|
||||||
implementation("org.jetbrains.compose.ui:ui:1.0.0-beta-02")
|
implementation("org.jetbrains.compose.ui:ui:1.0.0-beta-02")
|
||||||
|
|
|
@ -23,6 +23,13 @@ import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.window.*
|
import androidx.compose.ui.window.*
|
||||||
import database.DatabaseManager
|
import database.DatabaseManager
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
import kotlinx.serialization.json.buildJsonObject
|
||||||
|
import kotlinx.serialization.json.put
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileWriter
|
||||||
|
import java.io.IOException
|
||||||
|
|
||||||
|
|
||||||
val connection = DatabaseManager.getConnection()
|
val connection = DatabaseManager.getConnection()
|
||||||
val customRedColor = Color(0xFFB70D1B)
|
val customRedColor = Color(0xFFB70D1B)
|
||||||
|
@ -326,9 +333,9 @@ fun glossairePage(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FormulairePage(onAnnulerClick: () -> Unit) {
|
fun FormulairePage(onAnnulerClick: () -> Unit) {
|
||||||
|
|
||||||
MaterialTheme {
|
MaterialTheme {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(16.dp),
|
modifier = Modifier.padding(16.dp),
|
||||||
|
@ -423,19 +430,47 @@ fun FormulairePage(onAnnulerClick: () -> Unit) {
|
||||||
colors = ButtonDefaults.buttonColors(
|
colors = ButtonDefaults.buttonColors(
|
||||||
backgroundColor = customRedColor,
|
backgroundColor = customRedColor,
|
||||||
contentColor = Color.White
|
contentColor = Color.White
|
||||||
)) {
|
)
|
||||||
|
) {
|
||||||
Icon(imageVector = Icons.Default.Close, contentDescription = null)
|
Icon(imageVector = Icons.Default.Close, contentDescription = null)
|
||||||
Text("Annuler")
|
Text("Annuler")
|
||||||
}
|
}
|
||||||
Button(onClick = { /* Action de validation */ },
|
Button(
|
||||||
|
onClick = {
|
||||||
|
// Validation du formulaire
|
||||||
|
|
||||||
|
// Create a JsonObject to represent your Mot
|
||||||
|
val motJson = buildJsonObject {
|
||||||
|
put("nom", nom.value)
|
||||||
|
put("description", description.value)
|
||||||
|
put("contextePrincipal", contextePrincipal.value)
|
||||||
|
put("contexte2", contexte2.value)
|
||||||
|
put("lieA", lieA.value)
|
||||||
|
put("synonyme", synonyme.value)
|
||||||
|
put("antonyme", antonyme.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append the JsonObject to the glossaire.json file
|
||||||
|
try {
|
||||||
|
FileWriter("glossaire.json", true).use { fileWriter ->
|
||||||
|
fileWriter.appendLine(motJson.toString())
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reste de la logique de validation ou de navigation
|
||||||
|
},
|
||||||
colors = ButtonDefaults.buttonColors(
|
colors = ButtonDefaults.buttonColors(
|
||||||
backgroundColor = customRedColor,
|
backgroundColor = customRedColor,
|
||||||
contentColor = Color.White
|
contentColor = Color.White
|
||||||
)) {
|
)
|
||||||
|
) {
|
||||||
Icon(imageVector = Icons.Default.Check, contentDescription = null)
|
Icon(imageVector = Icons.Default.Check, contentDescription = null)
|
||||||
Text("Valider")
|
Text("Valider")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue