From fc35cc0a47ae5b88aa13b9e26e4511a5fe8ff5fb Mon Sep 17 00:00:00 2001 From: mikrise2 Date: Wed, 25 Oct 2023 03:33:12 +0200 Subject: [PATCH] [ML4SE-185] check agreement conditions on agreement page. --- gradle/libs.versions.toml | 6 ++-- .../tasktracker/config/agreement/Agreement.kt | 4 +++ .../ui/main/panel/MainPluginPanelFactory.kt | 14 +++++++- .../ui/main/panel/MainPluginWindow.kt | 2 +- .../main/panel/panelStates/DefaultStates.kt | 15 ++++++-- .../main/panel/template/AgreementTemplate.kt | 5 ++- .../ui/main/panel/template/agreement.html | 35 +++++++++++++++++-- 7 files changed, 69 insertions(+), 12 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a12a1d7c..8390c542 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -34,9 +34,9 @@ ktor-client-json = { module = "io.ktor:ktor-client-json", version.ref = "ktor" } ktor-client-serialization = { module = "io.ktor:ktor-client-serialization", version.ref = "ktor" } ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" } ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" } -ktor-server-core = {module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor"} -ktor-server-netty = {module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor"} -ktor-server-tests = {module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor"} +ktor-server-core = { module = "io.ktor:ktor-server-core-jvm", version.ref = "ktor" } +ktor-server-netty = { module = "io.ktor:ktor-server-netty-jvm", version.ref = "ktor" } +ktor-server-tests = { module = "io.ktor:ktor-server-tests-jvm", version.ref = "ktor" } slf4j = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" } postgres = { module = "org.postgresql:postgresql", version.ref = "postgres" } diff --git a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/agreement/Agreement.kt b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/agreement/Agreement.kt index 55b43dda..11a65d6f 100644 --- a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/agreement/Agreement.kt +++ b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/config/agreement/Agreement.kt @@ -2,5 +2,9 @@ package org.jetbrains.research.tasktracker.config.agreement import kotlinx.serialization.Serializable +/** + * text can contain urls, which should be covered in tag. + */ + @Serializable data class Agreement(val text: String, val required: Boolean = true) diff --git a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt index d80f1381..25c3c6db 100644 --- a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt +++ b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt @@ -13,6 +13,8 @@ import com.intellij.openapi.wm.ToolWindowFactory import com.intellij.ui.components.JBPanel import com.intellij.ui.jcef.JBCefApp import com.intellij.util.ui.JBUI +import kotlinx.coroutines.runBlocking +import org.jetbrains.concurrency.await import org.jetbrains.research.tasktracker.TaskTrackerPlugin import org.jetbrains.research.tasktracker.config.content.task.base.Task import org.jetbrains.research.tasktracker.modelInference.model.EmoModel @@ -25,7 +27,8 @@ import org.jetbrains.research.tasktracker.tracking.webcam.WebCamTracker import org.jetbrains.research.tasktracker.tracking.webcam.collectAllDevices import org.jetbrains.research.tasktracker.ui.main.panel.panelStates.agreementAcceptance import org.jetbrains.research.tasktracker.ui.main.panel.storage.GlobalPluginStorage -import org.jetbrains.research.tasktracker.ui.main.panel.template.* +import org.jetbrains.research.tasktracker.ui.main.panel.template.HtmlTemplate +import org.jetbrains.research.tasktracker.ui.main.panel.template.WebcamChoicePageTemplate import org.jetbrains.research.tasktracker.util.UIBundle import java.awt.BorderLayout import java.awt.FlowLayout @@ -164,6 +167,15 @@ class MainPluginPanelFactory : ToolWindowFactory { } } + /** + * @return **true** if any required field is not filled. **false** otherwise. + */ + fun checkInputs(): Boolean { + return runBlocking { + return@runBlocking mainWindow.executeJavaScriptAsync("allChecked()").await().toBoolean() + } + } + fun setNextAction(listener: ActionListener) = nextButton.addListener(listener) fun setBackAction(listener: ActionListener) = backButton.addListener(listener) diff --git a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt index 38566340..97ce29f8 100644 --- a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt +++ b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginWindow.kt @@ -51,7 +51,7 @@ class MainPluginWindow(service: MainWindowService) { fun checkIfRadioButtonChecked(elementId: String): Promise = windowBrowser.executeJavaScriptAsync("${getJsElementByIdCommand(elementId)}.checked") - fun executeJavaScriptAsync(code: String) = windowBrowser.executeJavaScriptAsync(code) + fun executeJavaScriptAsync(@Language("JavaScript") code: String) = windowBrowser.executeJavaScriptAsync(code) fun executeJavascript( @Language("JavaScript") codeBeforeInject: String = "", diff --git a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt index 541a173b..56292fda 100644 --- a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt +++ b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/panelStates/DefaultStates.kt @@ -15,20 +15,29 @@ import org.jetbrains.research.tasktracker.util.survey.SurveyParser typealias Panel = MainPluginPanelFactory +/** + * A page for collecting user data, and checkboxes for user agreement acceptance. + */ fun Panel.agreementAcceptance() { loadBasePage(AgreementTemplate.loadCurrentTemplate(), "ui.button.next", false) + setNextAction { + if (!checkInputs()) { + welcomePage() + } + } } /** * Switches the panel to the plugin description window. */ fun Panel.welcomePage() { - loadBasePage( - MainPageTemplate.loadCurrentTemplate(), "ui.button.next", false - ) + loadBasePage(MainPageTemplate.loadCurrentTemplate(), "ui.button.next", true) setNextAction { selectTask() } + setBackAction { + agreementAcceptance() + } } // TODO refactor it for many configs diff --git a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/template/AgreementTemplate.kt b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/template/AgreementTemplate.kt index e4cdc182..afb7c497 100644 --- a/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/template/AgreementTemplate.kt +++ b/ijPlugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/template/AgreementTemplate.kt @@ -11,7 +11,10 @@ class AgreementTemplate(private val agreements: List) : HtmlBaseFileT get() = arrayOf(agreementsToHtml()) private fun agreementsToHtml() = agreements.mapIndexed { index, element -> - """

${element.text}

""" + buildString { + append("""

${element.text}

""") + } }.joinToString("") companion object { diff --git a/ijPlugin/src/main/resources/org/jetbrains/research/tasktracker/ui/main/panel/template/agreement.html b/ijPlugin/src/main/resources/org/jetbrains/research/tasktracker/ui/main/panel/template/agreement.html index 974ac25d..222346c3 100644 --- a/ijPlugin/src/main/resources/org/jetbrains/research/tasktracker/ui/main/panel/template/agreement.html +++ b/ijPlugin/src/main/resources/org/jetbrains/research/tasktracker/ui/main/panel/template/agreement.html @@ -1,9 +1,38 @@
- +
- +
%s -
\ No newline at end of file + + \ No newline at end of file