Skip to content

Commit

Permalink
Throws error, no crash when no data on submit.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaeaton committed Jan 24, 2024
1 parent 810f059 commit b87e00f
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {

application
id("org.openjfx.javafxplugin") version "0.0.13"
kotlin("plugin.serialization") version "1.9.0"
kotlin("plugin.serialization") version "1.7.21"
id("org.jetbrains.dokka") version "1.6.10" // ./gradlew dokkaHtml
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package org.b12x.gfe.core.controller.tabstate

import org.b12x.gfe.core.controller.version.CreateNewHlaVersionObject
import org.b12x.gfe.core.controller.version.Version
import kotlin.properties.Delegates

class ComparisonState: TabState {

/* What tab */
override fun getTab(ctx: TabStateContext) = "COMP"

/* Version */
override fun getCurrentVersion(ctx: TabStateContext): String {
return "version"

override var version: String by Delegates.observable(PrefsTabSearch.currentVersionHla)
{ _, _, newValue ->
PrefsTabSearch.currentVersionHla = newValue
}

override var versionObject: Version by Delegates.observable(
CreateNewHlaVersionObject.createVersionObject("HLA", version)
) { _, _, _ -> }
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
package org.b12x.gfe.core.controller.tabstate

import org.b12x.gfe.core.controller.version.VersionList
import org.b12x.gfe.core.controller.version.CreateNewHlaVersionObject
import org.b12x.gfe.core.controller.version.Version
import kotlin.properties.Delegates

class GfeSearchState : TabState {

/* What tab */
override fun getTab(ctx: TabStateContext) = "GFE"

/* Version */
override fun getCurrentVersion(ctx: TabStateContext): String {
return "version"
}

// setting up so the core can identify which tab the version
// request is coming from.
// I can't remember why I care.
Expand All @@ -22,4 +15,40 @@ class GfeSearchState : TabState {
// I ended up putting the version initialization
// and generation in TabStateContext because
// it doesn't need to be reinitialized for each tab.

/* What tab */
override fun getTab(ctx: TabStateContext) = "GFE"

/* What Loci */

var loci: String by Delegates.observable(PrefsTabSearch.currentLociGroup)
{ _, _, newValue ->
PrefsTabSearch.currentLociGroup = newValue
}

/* Version */
// override fun getCurrentVersion(ctx: TabStateContext): String {
// return "version"
// }

override var version: String by Delegates.observable(PrefsTabSearch.currentVersionHla)
{ _, _, newValue ->
PrefsTabSearch.currentVersionHla = newValue
}

override var versionObject: Version by Delegates.observable(
CreateNewHlaVersionObject.createVersionObject("HLA", version)
) { _, _, _ -> }

// override fun updateVersions(ctx: LociStateContextGfeSearch) {
// var versionList = VersionList("HLA")
// var versions = versionList.allVersionNames
//
// val gfeMenuVersion = find(GfeMenuVersion::class)
//
// gfeMenuVersion.versionsList.clear()
// gfeMenuVersion.versionsList.addAll(versions)
//
// gfeMenuVersion.currentVersion = version
// }
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.b12x.gfe.core.controller.tabstate

import org.b12x.gfe.core.controller.version.CreateNewHlaVersionObject
import org.b12x.gfe.core.controller.version.Version
import org.b12x.gfe.core.controller.version.VersionList
import kotlin.properties.Delegates

Expand All @@ -9,7 +11,12 @@ class NameSearchState: TabState {
override fun getTab(ctx: TabStateContext) = "NAME"

/* Version */
override fun getCurrentVersion(ctx: TabStateContext): String {
return "version"
override var version: String by Delegates.observable(PrefsTabSearch.currentVersionHla)
{ _, _, newValue ->
PrefsTabSearch.currentVersionHla = newValue
}

override var versionObject: Version by Delegates.observable(
CreateNewHlaVersionObject.createVersionObject("HLA", version)
) { _, _, _ -> }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.b12x.gfe.core.controller.tabstate

import org.b12x.gfe.core.controller.version.CreateNewHlaVersionObject
import org.b12x.gfe.core.controller.version.Version
import kotlin.properties.Delegates

class OptionState : TabState {

/* What tab */
override fun getTab(ctx: TabStateContext) = "OPT"

/* Version */
override var version: String by Delegates.observable(PrefsTabSearch.currentVersionHla)
{ _, _, newValue ->
PrefsTabSearch.currentVersionHla = newValue
}

override var versionObject: Version by Delegates.observable(
CreateNewHlaVersionObject.createVersionObject("HLA", version)
) { _, _, _ -> }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.b12x.gfe.core.controller.tabstate

import org.b12x.gfe.GSG
import org.b12x.gfe.core.controller.PrefsCore
import org.b12x.gfe.utilities.DirectoryManagement
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.util.prefs.Preferences
import kotlin.io.path.exists
import kotlin.io.path.isDirectory
import kotlin.properties.Delegates

object PrefsTabSearch {

var prefs: Preferences = PrefsCore.prefs

var currentLociGroup: String by Delegates.observable(
prefs.get(
"currentLociGroup",
"HLA"
)
) { _, _, new ->
prefs.put("currentLociGroup", new)
}

var currentVersionHla: String by Delegates.observable(
prefs.get(
"currentVersionHla",
defaultHlaVersion()
)
) { _, _, new ->
prefs.put("currentVersionHla", new)
}

// checks for existing HLA directory, creates one if it doesn't exist
// This should allow it to boot on systems without data
private fun defaultHlaVersion() : String {
val directoryManagement = DirectoryManagement()
val gsgDataLocation = directoryManagement.setLociLocation("HLA")

if (Paths.get(gsgDataLocation).exists() and (File(gsgDataLocation).list()?.isNotEmpty() == true)) {
val fileList = File(gsgDataLocation).listFiles()
val directories = fileList!!.filter { it.isDirectory }.toMutableList() // !! - checked in the if statement above
directories.sort()
return directories.last().toString().split("/").last()
} else {
Files.createDirectories(Paths.get(gsgDataLocation))
}

// Files.createDirectories(Paths.get(gsgDataLocation))
return ""
}

var currentGfeSearchVersionKir: String by Delegates.observable(
prefs.get(
"currentVersionKir",
"2.7.0"
)
) { _, _, new ->
prefs.put("currentVersionKir", new)
}
}
15 changes: 13 additions & 2 deletions src/main/kotlin/org/b12x/gfe/core/controller/tabstate/TabState.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
package org.b12x.gfe.core.controller.tabstate

import org.b12x.gfe.plugins.gfesearch.controller.locistategfesearch.LociStateContextGfeSearch
import org.b12x.gfe.core.controller.loci.LociEnum
import org.b12x.gfe.core.controller.version.Version

interface TabState {

/* What Tab */
fun getTab(ctx: TabStateContext): String

/* Loci */
// var loci: String

/* Version */
fun getCurrentVersion(ctx: TabStateContext): String
var version: String
var versionObject: Version
// fun getCurrentVersion(ctx: TabStateContext): String

/* Locus*/
// var locus: String
// var locusEnum: LociEnum
// fun updateLocuses(ctx: TabStateContext)

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.b12x.gfe.core.controller.tabstate

import org.b12x.gfe.core.controller.version.Version
import org.b12x.gfe.core.controller.version.VersionList
import org.b12x.gfe.plugins.gfesearch.controller.locistategfesearch.LociStateContextGfeSearch
import kotlin.properties.Delegates

object TabStateContext {
Expand All @@ -20,6 +22,7 @@ object TabStateContext {
"GFE" -> GfeSearchState()
"NAME" -> NameSearchState()
"COMP" -> ComparisonState()
"OPT" -> OptionState()
else -> GfeSearchState()
}
println("Current Tab State: ${currentState.toString()}")
Expand All @@ -31,10 +34,30 @@ object TabStateContext {
?: GfeSearchState().getTab(this)
}

/* Loci */
// var loci: String by Delegates.observable(currentState?.loci.toString()) { _, _, newValue ->
// println("TabState: loci: ${newValue}")
// TabStateContext.currentState?.loci = newValue
// }

var loci: String by Delegates.observable(PrefsTabSearch.currentLociGroup)
{ _, _, newValue ->
PrefsTabSearch.currentLociGroup = newValue
}

/* Version */
fun getCurrentVersion() =
currentState?.getCurrentVersion(this)
?: GfeSearchState().getCurrentVersion(this)
var version: String by Delegates.observable(currentState?.version.toString()) { _, _, newValue ->
println("TabState: version: ${newValue}")
currentState?.version = newValue
}

var versionObject: Version by Delegates.observable(currentState?.versionObject as Version) { _, _, newValue ->
currentState?.versionObject = newValue
}

// fun getCurrentVersion() =
// currentState?.getCurrentVersion(this)
// ?: GfeSearchState().getCurrentVersion(this)

var versionList: List<String> by Delegates.observable(VersionList("HLA").allVersionNames) {
_, _, _ ->
Expand Down
12 changes: 5 additions & 7 deletions src/main/kotlin/org/b12x/gfe/main.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package org.b12x.gfe

import javafx.stage.Stage
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.*
import org.b12x.gfe.core.controller.PrefsCore
import org.b12x.gfe.core.model.datadownload.version.DownloadVersion
import org.b12x.gfe.core.view.MainView
Expand All @@ -28,6 +25,7 @@ import tornadofx.*
// internetAccess.printResults()
// }
//}
@OptIn(DelicateCoroutinesApi::class)
fun main() {

/* Prefs Reset */
Expand All @@ -37,9 +35,9 @@ fun main() {
/* Internet Access */
val internetAccess = InternetAccess()

runBlocking {
internetAndVersions(internetAccess)
}
// GlobalScope.async {
// internetAndVersions(internetAccess)
// }

/* Program start - nothing will be run past this point */
launch<GSG>()
Expand Down
Loading

0 comments on commit b87e00f

Please sign in to comment.