Skip to content

Commit

Permalink
[ML4SE-591] Added survey for AI hints. Fixed some issues related to t…
Browse files Browse the repository at this point in the history
…he survey
  • Loading branch information
mikrise2 committed Apr 4, 2024
1 parent b57ccd1 commit e97d1c4
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 210 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 @@ -107,9 +107,9 @@ data class RadioHtmlQuestion(
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>")
}
}
}
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 @@ -80,16 +84,22 @@ class MainPluginPanelFactory : ToolWindowFactory {
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 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=make 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 e97d1c4

Please sign in to comment.