Skip to content

Commit

Permalink
Added survey for AI hints (#102)
Browse files Browse the repository at this point in the history
* [ML4SE-591] Added survey for AI hints. Fixed some issues related to the survey

* [ML4SE-591] Fix detekt

* [ML4SE-591] Fix text of the pause button

* [ML4SE-591] Added checkbox type, fixed borders in html. Deleted index from the database for survey table
  • Loading branch information
mikrise2 authored Apr 5, 2024
1 parent b57ccd1 commit c9af873
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 216 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ data class Scenario(

fun reset() {
currentSteps = LinkedList(steps)
currentStepIterator = null
}

private fun Iterator<ScenarioUnit>?.notNullAndHasNext() = this?.hasNext() != true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.serialization.Transient
* Radio button id and value
*/
@Serializable
data class RadioInfo(val id: String, val value: String)
data class ValueInfo(val id: String, val value: String)

/**
* This is a class that constructs an input field of a specified type in HTML.
Expand Down Expand Up @@ -102,14 +102,34 @@ data class RadioHtmlQuestion(
* **ElementId** here is radio button **name**!!!.
*/
override val elementId: String,
@SerialName("info") val infos: List<RadioInfo>
@SerialName("info") val infos: List<ValueInfo>
) : HtmlQuestion() {
override fun toHtml(): String = buildString {
append(htmlText())
infos.forEach { (id, value) ->
append("<input type=\"radio\" id=\"$id\" ${elementId.asParameter("name")} ")
append("<label for=\"$id\"><input type=\"radio\" id=\"$id\" ${elementId.asParameter("name")} ")
append("value=\"$value\" ${isRequiredString()}>")
append("<label for=\"$id\">$value</label><br>")
append("$value</label><br>")
}
}
}

@Serializable
@SerialName("Checkbox")
data class CheckboxHtmlQuestion(
override val text: String,
/**
* **ElementId** here is checkbox button **name**!!!.
*/
override val elementId: String,
@SerialName("info") val infos: List<ValueInfo>
) : HtmlQuestion() {
override fun toHtml(): String = buildString {
append(htmlText())
infos.forEach { (id, value) ->
append("<label for=\"$id\"><input type=\"checkbox\" id=\"$id\" ${elementId.asParameter("name")} ")
append("value=\"$value\" ${isRequiredString()}>")
append("$value</label><br>")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.jetbrains.research.tasktracker.ui.main.panel.models.AgreementChecker
import org.jetbrains.research.tasktracker.ui.main.panel.models.ButtonState
import org.jetbrains.research.tasktracker.ui.main.panel.models.LinkType
import org.jetbrains.research.tasktracker.ui.main.panel.panelStates.agreementAcceptance
import org.jetbrains.research.tasktracker.ui.main.panel.panelStates.stopTracking
import org.jetbrains.research.tasktracker.ui.main.panel.storage.GlobalPluginStorage
import org.jetbrains.research.tasktracker.ui.main.panel.template.HtmlTemplate
import org.jetbrains.research.tasktracker.ui.main.panel.template.WebcamChoicePageTemplate
Expand All @@ -43,6 +44,7 @@ class MainPluginPanelFactory : ToolWindowFactory {
// TODO: init in other place, states can be saved between sessions
private val nextButton = createJButton("ui.button.next")
private val backButton = createJButton("ui.button.back", isVisibleProp = false)
private val pauseButton = createJButton("ui.button.pause", isVisibleProp = false)
private val logger: Logger = Logger.getInstance(MainPluginPanelFactory::class.java)

lateinit var trackingService: TrackingService
Expand All @@ -56,13 +58,15 @@ class MainPluginPanelFactory : ToolWindowFactory {
mainWindow = project.getService(MainWindowService::class.java).mainWindow
trackingService = project.getService(TrackingService::class.java)
mainWindow.jComponent.size = JBUI.size(toolWindow.component.width, toolWindow.component.height)
pauseButton.setListener { stopTracking() }
mainWindow.onError {
nextButton.text = UIBundle.message("ui.button.welcome")
setNextAction { agreementAcceptance() }
}
agreementAcceptance()
val buttonPanel = JBPanel<JBPanel<*>>(FlowLayout()).apply {
add(backButton)
add(pauseButton)
add(nextButton)
}
val panel = JBPanel<JBPanel<*>>(BorderLayout()).apply {
Expand All @@ -75,21 +79,28 @@ class MainPluginPanelFactory : ToolWindowFactory {

override fun isApplicable(project: Project) = super.isApplicable(project) && JBCefApp.isSupported()

@Suppress("LongParameterList")
fun loadBasePage(
template: HtmlTemplate,
buttonTextKey: String? = null,
isVisibleBackButton: Boolean = false,
backButtonText: String? = null,
isVisibleNextButton: Boolean = true
isVisibleNextButton: Boolean = true,
pauseButtonText: String? = null,
isVisiblePauseButton: Boolean = true
) {
mainWindow.loadHtmlTemplate(template)
backButton.isVisible = isVisibleBackButton
nextButton.isVisible = isVisibleNextButton
pauseButton.isVisible = isVisiblePauseButton
backButtonText?.let {
backButton.text = backButtonText
backButton.text = UIBundle.message(it)
}
buttonTextKey?.let {
nextButton.text = UIBundle.message(buttonTextKey)
nextButton.text = UIBundle.message(it)
}
pauseButtonText?.let {
pauseButton.text = UIBundle.message(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typealias Panel = MainPluginPanelFactory
*/
fun Panel.agreementAcceptance() {
GlobalPluginStorage.resetSession()
loadBasePage(AgreementTemplate.loadCurrentTemplate(), "ui.button.next", false)
loadBasePage(AgreementTemplate.loadCurrentTemplate(), "ui.button.next", false, isVisiblePauseButton = false)
setNextAction {
checkAgreementInputs().runOnSuccess {
if (!it) {
Expand All @@ -53,7 +53,7 @@ fun Panel.agreementAcceptance() {
* Switches the panel to the plugin description window.
*/
fun Panel.welcomePage() {
loadBasePage(MainPageTemplate.loadCurrentTemplate(), "ui.button.next", false)
loadBasePage(MainPageTemplate.loadCurrentTemplate(), "ui.button.next", false, isVisiblePauseButton = false)
setNextAction {
TaskTrackerPlugin.initializationHandler.setupEnvironment(project)
trackingService.startTracking(project)
Expand All @@ -64,10 +64,9 @@ fun Panel.welcomePage() {
/**
* Switches the panel to the task selection window.
*/
@Suppress("UnusedPrivateMember")
private fun Panel.selectTask(taskIds: List<String>, allRequired: Boolean = true) {
val tasks = TaskTrackerPlugin.mainConfig.taskContentConfig?.tasks?.filter { it.id in taskIds } ?: emptyList()
loadBasePage(TasksPageTemplate(tasks))
loadBasePage(TasksPageTemplate(tasks), isVisiblePauseButton = false)
setNextAction {
mainWindow.getElementValue("tasks").runOnSuccess { name ->
solveTask(name.toString(), if (allRequired) taskIds.filter { it != name } else emptyList())
Expand Down Expand Up @@ -130,14 +129,14 @@ fun Panel.survey(id: String) {
}

fun Panel.serverErrorPage() {
loadBasePage(ServerErrorPage(), "ui.button.welcome", false)
loadBasePage(ServerErrorPage(), "ui.button.welcome", false, isVisiblePauseButton = false)
setNextAction {
agreementAcceptance()
}
}

fun Panel.finalPage() {
loadBasePage(FinalPageTemplate.loadCurrentTemplate(), "ui.button.welcome", false)
loadBasePage(FinalPageTemplate.loadCurrentTemplate(), "ui.button.welcome", false, isVisiblePauseButton = false)
setNextAction {
agreementAcceptance()
}
Expand Down Expand Up @@ -177,11 +176,15 @@ fun Panel.processScenario() {
}

null -> {
scenario.reset()
loadBasePage(LoadTemplate())
ApplicationManager.getApplication().invokeLater {
trackingService.stopTracking(::finalPage, ::serverErrorPage)
}
stopTracking()
}
}
}

fun Panel.stopTracking() {
TaskTrackerPlugin.mainConfig.scenarioConfig?.scenario?.reset()
loadBasePage(LoadTemplate())
ApplicationManager.getApplication().invokeLater {
trackingService.stopTracking(::finalPage, ::serverErrorPage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ class SurveyParser(private val mainWindow: MainPluginWindow, project: Project) :
when (item) {
is InputHtmlQuestion -> {
val result = mainWindow.getElementValue(item.elementId).await()
surveyLogger.log(item.text, result.toString(), questionId = id)
surveyLogger.log(item.text, result.toString(), option = item.elementId, questionId = id)
}

is TextAreaHtmlQuestion -> {
val result = mainWindow.getElementValue(item.elementId).await()
surveyLogger.log(item.text, result.toString(), questionId = id)
surveyLogger.log(item.text, result.toString(), option = item.elementId, questionId = id)
}

is RadioHtmlQuestion -> item.infos.forEach { info ->
Expand All @@ -33,6 +33,10 @@ class SurveyParser(private val mainWindow: MainPluginWindow, project: Project) :
is HtmlQuestionContainer -> item.subQuestions.forEach {
parseAndLog(it, id)
}
is CheckboxHtmlQuestion -> item.infos.forEach { info ->
val result = mainWindow.checkIfRadioButtonChecked(info.id).await()
surveyLogger.log(item.text, result.toString(), option = info.id, questionId = id)
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ij-plugin/src/main/resources/messages/UIBundle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ui.button.select=select
ui.button.next=next
ui.button.pause=pause
ui.button.back=back
ui.button.submit=submit
ui.button.welcome=welcome screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ scenario:
- units:
- !<Task>
id: "main"
- !<Survey>
id: "default"
Loading

0 comments on commit c9af873

Please sign in to comment.