Remove readJsonFile function
parent
7806821abc
commit
be34fb6254
|
@ -16,26 +16,17 @@ import java.awt.FileDialog
|
||||||
import java.awt.Frame
|
import java.awt.Frame
|
||||||
import androidx.compose.material.Button
|
import androidx.compose.material.Button
|
||||||
import androidx.compose.material.MaterialTheme
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
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.window.*
|
import androidx.compose.ui.window.*
|
||||||
import database.DatabaseManager
|
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import kotlinx.serialization.json.buildJsonObject
|
|
||||||
import kotlinx.serialization.json.put
|
|
||||||
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
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.JsonObject
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val connection = DatabaseManager.getConnection()
|
|
||||||
val customRedColor = Color(0xFFB70D1B)
|
val customRedColor = Color(0xFFB70D1B)
|
||||||
val glossaireList = mutableListOf<JsonObject>()
|
|
||||||
|
|
||||||
@OptIn(ExperimentalComposeUiApi::class)
|
@OptIn(ExperimentalComposeUiApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -43,7 +34,6 @@ fun HomePage(
|
||||||
onGlossaireClick: () -> Unit,
|
onGlossaireClick: () -> Unit,
|
||||||
onCodeAVerifierClick: () -> Unit
|
onCodeAVerifierClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
var isHover by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
@ -133,9 +123,8 @@ fun App() {
|
||||||
val selectedDirectory = fileDialog.directory
|
val selectedDirectory = fileDialog.directory
|
||||||
if (selectedFile != null) {
|
if (selectedFile != null) {
|
||||||
val csvFilePath = "$selectedDirectory$selectedFile"
|
val csvFilePath = "$selectedDirectory$selectedFile"
|
||||||
val jsonFilePath = "glossaire.json" // Replace with the actual path to your JSON file
|
|
||||||
println("Exporting to: $csvFilePath")
|
println("Exporting to: $csvFilePath")
|
||||||
exportToCSV(jsonFilePath, csvFilePath)
|
exportToCSV(csvFilePath)
|
||||||
} else {
|
} else {
|
||||||
println("Export command cancelled by user.")
|
println("Export command cancelled by user.")
|
||||||
}
|
}
|
||||||
|
@ -207,14 +196,14 @@ fun App() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun exportToCSV(jsonFilePath: String, csvFilePath: String) {
|
fun exportToCSV(csvFilePath: String) {
|
||||||
val glossary = readJsonFile(jsonFilePath)
|
val glossary = chargerDonneesDepuisFichier()
|
||||||
val csvContent = buildString {
|
val csvContent = buildString {
|
||||||
appendLine("Mot;Description;Contexte principal;Contexte 2;Lié à;Synonyme;Antonyme;")
|
appendLine("Mot;Description;Contexte principal;Contexte 2;Lié à;Synonyme;Antonyme;")
|
||||||
glossary.forEach { entry ->
|
glossary.forEach { entry ->
|
||||||
appendLine(
|
appendLine(
|
||||||
"${entry["nom"]};${entry["description"]};${entry["contextePrincipal"]};" +
|
"${entry.nom};${entry.description};${entry.contextePrincipal};" +
|
||||||
"${entry["contexte2"]};${entry["lieA"]};${entry["synonyme"]};${entry["antonyme"]}"
|
"${entry.contexte2};${entry.lieA};${entry.synonyme};${entry.antonyme}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,15 +215,6 @@ fun exportToCSV(jsonFilePath: String, csvFilePath: String) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fun readJsonFile(filePath: String): List<Map<String, String>> {
|
|
||||||
return try {
|
|
||||||
val content = File(filePath).readText(Charsets.UTF_8)
|
|
||||||
Json.decodeFromString(content)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun importCSV(cheminFichier: String) {
|
fun importCSV(cheminFichier: String) {
|
||||||
val file = File(cheminFichier).readText(Charsets.UTF_8)
|
val file = File(cheminFichier).readText(Charsets.UTF_8)
|
||||||
|
@ -587,12 +567,12 @@ fun chargerDonneesDepuisFichier(): List<Mot> {
|
||||||
if (!File("glossaire.json").exists() || File("glossaire.json").length() == 0L) {
|
if (!File("glossaire.json").exists() || File("glossaire.json").length() == 0L) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
try {
|
return try {
|
||||||
val content = File("glossaire.json").readText()
|
val content = File("glossaire.json").readText()
|
||||||
return Json.decodeFromString<List<Mot>>(content)
|
Json.decodeFromString<List<Mot>>(content)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
return emptyList() // Handle the exception as needed
|
emptyList() // Handle the exception as needed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue