Skip to content

Commit

Permalink
Merge pull request #6 from Paulanerus/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Paulanerus authored Jan 13, 2025
2 parents 9361033 + 452dd19 commit 9a9f7e2
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 143 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# TextExplorer
# TextExplorer
This is a tool designed for the exploration and comparison of variants of textual data.

## Usage

TODO

## Development

TODO

## Support

If you have any problems or questions about this project, please get in touch. You can also [open an issue](https://github.com/Paulanerus/TextExplorer/issues) on GitHub.
2 changes: 2 additions & 0 deletions api/src/main/kotlin/dev/paulee/api/data/IDataService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface IDataService : Closeable {

fun getSelectedPool(): String

fun hasSelectedPool(): Boolean

fun getAvailablePools(): Set<String>

fun getPage(query: String, pageCount: Int): Pair<List<Map<String, String>>, Map<String, List<Map<String, String>>>>
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/kotlin/dev/paulee/core/data/DataServiceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class DataServiceImpl(private val storageProvider: IStorageProvider) : IDataServ

override fun getSelectedPool(): String = "${this.currentPool}.${this.currentField}"

override fun hasSelectedPool(): Boolean = this.currentPool != null && this.currentField != null

override fun getAvailablePools(): Set<String> = dataPools.filter { it.value.fields.any { it.value } }
.flatMap { entry ->
entry.value.fields.filter { it.value }.map { "${entry.key}.${it.key.substringBefore(".")}" }
Expand Down
14 changes: 13 additions & 1 deletion core/src/main/kotlin/dev/paulee/core/plugin/PluginServiceImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlin.io.path.isDirectory
import kotlin.io.path.walk
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.functions
import kotlin.reflect.full.primaryConstructor

class PluginServiceImpl : IPluginService {

Expand Down Expand Up @@ -86,9 +87,20 @@ class PluginServiceImpl : IPluginService {

val func = taggable::class.functions.find { it.name == "tag" } ?: return null

return func.findAnnotation<ViewFilter>()
val annotation = func.findAnnotation<ViewFilter>() ?: return null

val fields = getAllFields(plugin)

if (fields.isEmpty()) return annotation

if (annotation.fields.none { it in fields }) return null

return annotation
}

private fun getAllFields(plugin: IPlugin): Set<String> = this.getDataInfo(plugin)?.sources.orEmpty()
.flatMap { it.primaryConstructor?.parameters.orEmpty().mapNotNull { it.name } }.toSet()

private fun getPluginEntryPoint(path: Path): String? =
JarFile(path.toFile()).use { return it.manifest.mainAttributes.getValue("Main-Class") }

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kotlin.version=2.1.0
compose.version=1.7.1
lucene.version=10.0.0

api.version=0.32.1
core.version=0.30.1
ui.version=0.21.0
app.version=1.6.0
api.version=0.32.2
core.version=0.30.3
ui.version=0.21.7
app.version=1.7.0
29 changes: 24 additions & 5 deletions ui/src/main/kotlin/dev/paulee/ui/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,35 @@ object Config {

var noWidthRestriction = false

var selectedPool = ""

private var configFile = "config"

private var configPath = Path(configFile)

private val hiddenColumns = mutableMapOf<String, Set<Int>>()

fun save() {
this.configPath.bufferedWriter().use { writer ->

this::class.memberProperties
.filter { it.visibility == KVisibility.PUBLIC && it is KMutableProperty<*> }
this::class.memberProperties.filter { it.visibility == KVisibility.PUBLIC && it is KMutableProperty<*> }
.forEach {
val value = it.getter.call(this)

writer.write("${it.name} = $value\n")
writer.newLine()
}

this.hiddenColumns.forEach {
writer.write("${it.key} = ${it.value}\n")
writer.newLine()
}
}
}

fun load(path: Path) {
this.configPath = path.resolve(configFile)

if(this.configPath.notExists()) return
if (this.configPath.notExists()) return

this.configPath.bufferedReader().useLines { lines ->
lines.filter { it.contains("=") }.forEach {
Expand All @@ -60,9 +67,21 @@ object Config {
)
}.onFailure { e -> println("Failed to set value for $field (${e.message}).") }
} else {
//TODO
value.takeIf { it.startsWith("[") && it.endsWith("]") }
?.trim('[', ']')
?.replace(" ", "")
?.split(",")
?.mapNotNull { it.toIntOrNull() }
?.toSet()
?.let { this.hiddenColumns[field] = it }
}
}
}
}

fun setHidden(id: String, ids: Set<Int>) {
this.hiddenColumns[id] = ids
}

fun getHidden(id: String): Set<Int> = this.hiddenColumns[id] ?: emptySet()
}
35 changes: 27 additions & 8 deletions ui/src/main/kotlin/dev/paulee/ui/TextExplorerUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import kotlin.io.path.*
class TextExplorerUI(
private val pluginService: IPluginService,
private val dataService: IDataService,
private val diffService: DiffService
private val diffService: DiffService,
) {

private val appDir = Path(System.getProperty("user.home")).resolve(".textexplorer")
Expand Down Expand Up @@ -62,6 +62,8 @@ class TextExplorerUI(
val size = this.dataService.loadDataPools(dataDir, this.pluginService.getAllDataInfos())

println("Loaded $size data pools")

if (Config.selectedPool.isNotEmpty()) this.dataService.selectDataPool(Config.selectedPool)
}

@Composable
Expand Down Expand Up @@ -109,6 +111,7 @@ class TextExplorerUI(
DropdownMenuItem(
onClick = {
dataService.selectDataPool(item.first)
Config.selectedPool = item.first
poolSelected = !poolSelected

if (selectedText != item.second) {
Expand All @@ -128,14 +131,18 @@ class TextExplorerUI(

DropDownMenu(
modifier = Modifier.align(Alignment.TopEnd),
items = listOf("Load Plugin", "Width Limit"),
items = listOf("Load Plugin", "Width Limit", "Plugin Info"),
clicked = {
when (it) {
"Load Plugin" -> isOpened = true
"Width Limit" -> {
Config.noWidthRestriction = !Config.noWidthRestriction
widthLimitWrapper = !widthLimitWrapper
}

"Plugin Info" -> {
println("Show plugin info")
}
}
})

Expand Down Expand Up @@ -207,7 +214,7 @@ class TextExplorerUI(
showTable = true
},
modifier = Modifier.height(70.dp).padding(horizontal = 10.dp),
enabled = text.isNotEmpty() && text.isNotBlank()
enabled = text.isNotBlank() && dataService.hasSelectedPool()
) {
Icon(Icons.Default.Search, contentDescription = "Search")
}
Expand All @@ -230,6 +237,7 @@ class TextExplorerUI(

TableView(
modifier = Modifier.weight(1f),
dataService.getSelectedPool(),
indexStrings = indexStrings,
columns = header,
data = data,
Expand Down Expand Up @@ -315,6 +323,8 @@ class TextExplorerUI(
}

private fun loadPlugin(path: Path): Boolean {
val parentPath = path.parent

val pluginPath = pluginsDir.resolve(path.name)

if (pluginPath.exists()) return true
Expand All @@ -325,13 +335,22 @@ class TextExplorerUI(

if (plugin == null) return false

this.pluginService.getDataInfo(plugin)?.let {
if (it.sources.isEmpty()) return@let
this.pluginService.getDataInfo(plugin)?.let { dataInfo ->
if (dataInfo.sources.isEmpty()) return@let

this.pluginService.getDataSources(dataInfo.name).forEach {
val name = it.let { if (it.endsWith(".csv")) it else "$it.csv" }

val dataSourcePath = parentPath.resolve(name)

if (dataSourcePath.exists()) dataSourcePath.copyTo(this.dataDir.resolve(name), true)
else println("No source file for '$it' in plugin dir.")
}

val poolsEmpty = this.dataService.getAvailablePools().isEmpty()

if (this.dataService.createDataPool(it, dataDir)) {
println("Created data pool for ${it.name}")
if (this.dataService.createDataPool(dataInfo, dataDir)) {
println("Created data pool for ${dataInfo.name}")

this.dataService.getAvailablePools().firstOrNull()?.let {
if (!poolsEmpty) return@let
Expand All @@ -340,7 +359,7 @@ class TextExplorerUI(
this.poolSelected = !this.poolSelected
}

} else println("Failed to create data pool for ${it.name}")
} else println("Failed to create data pool for ${dataInfo.name}")
}
return true
}
Expand Down
Loading

0 comments on commit 9a9f7e2

Please sign in to comment.