Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

date filter settings #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ repositories {

kotlin {
jvmToolchain(20)
// project.sourceSets.create("main")
project.sourceSets.create("commonTest")
sourceSets {
val main: KotlinSourceSet by getting {
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/org/reactome/lit_ball/common/QuerySetting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import java.io.File
data class QuerySetting(
var mandatoryKeyWords: MutableSet<String> = mutableSetOf(),
var forbiddenKeyWords: MutableSet<String> = mutableSetOf(),
var pubDateFilterFrom: String = "",
var pubDateFilterTo: String = "",
var classifier: String = "virus-EXP",
var annotationClasses: MutableSet<String> = mutableSetOf(),
) {
override fun toString(): String {
return "QuerySetting(posKeyWords=$mandatoryKeyWords, negKeyWords=$forbiddenKeyWords, classifier=$classifier), annotationClasses=$annotationClasses"
return "QuerySetting(posKeyWords=$mandatoryKeyWords, negKeyWords=$forbiddenKeyWords, pubDateFilterFrom/To=$pubDateFilterFrom/$pubDateFilterTo, classifier=$classifier), annotationClasses=$annotationClasses"
}

companion object {
Expand Down
90 changes: 50 additions & 40 deletions src/main/kotlin/org/reactome/lit_ball/dialog/QuerySettingsDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ package org.reactome.lit_ball.dialog
import androidx.compose.foundation.layout.Column
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.reactome.lit_ball.common.LitBallQuery
import org.reactome.lit_ball.common.QuerySetting
import org.reactome.lit_ball.common.LitBallQuery
import org.reactome.lit_ball.util.splitToSet

@Composable
Expand All @@ -26,71 +27,80 @@ fun QuerySettingsDialog(
rememberSaveable { mutableStateOf(item.setting?.mandatoryKeyWords?.joinToString(separator = ", ") ?: "") }
val field2Value =
rememberSaveable { mutableStateOf(item.setting?.forbiddenKeyWords?.joinToString(separator = ", ") ?: "") }
val field3Value = rememberSaveable { mutableStateOf(item.setting?.classifier ?: "") }
val field4Value =
val field3Value = rememberSaveable { mutableStateOf(item.setting?.pubDateFilterFrom ?: "") }
val field4Value = rememberSaveable { mutableStateOf(item.setting?.pubDateFilterTo ?: "") }
val field5Value = rememberSaveable { mutableStateOf(item.setting?.classifier ?: "") }
val field6Value =
rememberSaveable { mutableStateOf(item.setting?.annotationClasses?.joinToString(separator = ", ") ?: "") }

fun closeDialog() {
rootScope.launch { onCloseClicked() }
}

AlertDialog(
onDismissRequest = {
rootScope.launch { (onCloseClicked)() }
},
onDismissRequest = { closeDialog() },
confirmButton = {
TextButton(
onClick = {
item.setting!!.mandatoryKeyWords = field1Value.value.splitToSet(",")
item.setting!!.forbiddenKeyWords = field2Value.value.splitToSet(",")
item.setting!!.classifier = field3Value.value.trim()
item.setting!!.annotationClasses = field4Value.value.splitToSet(",")
item.setting!!.pubDateFilterFrom = field3Value.value.trim()
item.setting!!.pubDateFilterTo = field4Value.value.trim()
item.setting!!.classifier = field5Value.value.trim()
item.setting!!.classifier = field5Value.value.trim()
item.setting!!.annotationClasses = field6Value.value.splitToSet(",")
rootScope.launch(Dispatchers.IO) {
item.saveSettings()
}
rootScope.launch { (onCloseClicked)() }
closeDialog()
}
) {
Text("Confirm")
}
},
dismissButton = {
TextButton(
onClick = {
rootScope.launch { (onCloseClicked)() }
}
onClick = { closeDialog() }
) {
Text("Dismiss")
}
},
title = {
Text(
"Edit query settings",
)
},
title = { Text("Edit query settings") },
text = {
Column(horizontalAlignment = Alignment.Start) {
TextField(
value = field1Value.value,
onValueChange = { field1Value.value = it },
label = { Text("Mandatory keywords") },
placeholder = { Text("text1, text2, ...") }
)
TextField(
value = field2Value.value,
onValueChange = { field2Value.value = it },
label = { Text("Forbidden keywords") },
placeholder = { Text("text1, text2, ...") }
)
TextField(
value = field3Value.value,
onValueChange = { field3Value.value = it },
label = { Text("Classifier model name") },
)
TextField(
value = field4Value.value,
onValueChange = { field4Value.value = it },
label = { Text("Annotation classes") },
placeholder = { Text("text1, text2, ...") }
)
TextFieldWithPlaceholder(field1Value, "Mandatory keywords", "text1, text2, ...")
TextFieldWithPlaceholder(field2Value, "Forbidden keywords", "text1, text2, ...")
TextFieldWithPlaceholder(field3Value, "From (Date)", "1949-12-31")
TextFieldWithoutPlaceholder(field4Value, "To (Date)")
TextFieldWithoutPlaceholder(field5Value, "Classifier model name")
TextFieldWithPlaceholder(field6Value, "Annotation classes", "text1, text2, ...")
}
},
)
}

@Composable
fun TextFieldWithPlaceholder(
value: MutableState<String>,
label: String,
placeholder: String,
) {
TextField(
value = value.value,
onValueChange = { value.value = it },
label = { Text(label) },
placeholder = { Text(placeholder) }
)
}

@Composable
fun TextFieldWithoutPlaceholder(
value: MutableState<String>,
label: String,
) {
TextField(
value = value.value,
onValueChange = { value.value = it },
label = { Text(label) },
)
}