Skip to content

Commit

Permalink
[ML4SE-234] Scenario config is ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrise2 committed Nov 21, 2023
1 parent ddc6a35 commit 036cf5f
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import java.io.File

@Serializable
data class SettingsConfig(
val enableCodeCompletion: SettingMode,
val enableZenMode: SettingMode,
val theme: Theme
val enableCodeCompletion: SettingMode = SettingMode.DEFAULT,
val enableZenMode: SettingMode = SettingMode.DEFAULT,
val theme: Theme = Theme.DEFAULT
) : BaseProjectConfig {

override val configName: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ package org.jetbrains.research.tasktracker.config.scenario.models
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.jetbrains.research.tasktracker.config.ide.MainIdeConfig
import org.jetbrains.research.tasktracker.config.survey.SurveyConfig

@Serializable
sealed interface ScenarioUnit

@Serializable
@SerialName("List")
class TaskListUnit(val tasks: List<String>) : ScenarioUnit
class TaskListUnit(val taskIds: List<String>) : ScenarioUnit

@Serializable
@SerialName("SingleList")
class TaskListWithSingleChoiceUnit(val tasks: List<String>) : ScenarioUnit
class TaskListWithSingleChoiceUnit(val taskIds: List<String>) : ScenarioUnit

@Serializable
@SerialName("Task")
Expand All @@ -26,7 +25,7 @@ class IdeSettingUnit(val mainIdeConfig: MainIdeConfig) : ScenarioUnit

@Serializable
@SerialName("Survey")
class SurveyUnit(val surveyConfig: SurveyConfig) : ScenarioUnit
class SurveyUnit(val id: String) : ScenarioUnit

@Serializable
@SerialName("External")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.tasktracker.config.survey

import kotlinx.serialization.Serializable

@Serializable
data class Survey(val id: String, val htmlQuestions: List<HtmlQuestion>) {
fun toHtml() = htmlQuestions.joinToString(System.lineSeparator()) { it.toHtml() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import java.io.File

@Serializable
class SurveyConfig : BaseConfig {
val htmlQuestions: List<HtmlQuestion> = emptyList()
val surveys: List<Survey> = emptyList()
override val configName: String
get() = CONFIG_FILE_PREFIX

fun toHtml() = htmlQuestions.joinToString(System.lineSeparator()) { it.toHtml() }

companion object {
const val CONFIG_FILE_PREFIX: String = "survey"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ private fun Panel.solveTask(id: String, nextTasks: List<String> = emptyList()) {
}

@OptIn(DelicateCoroutinesApi::class)
fun Panel.survey() {
loadBasePage(SurveyTemplate.loadCurrentTemplate())
fun Panel.survey(id: String) {
val survey = TaskTrackerPlugin.mainConfig.surveyConfig?.surveys?.find { it.id == id }
?: error("Survey with id `$id` hasn't been found.")
loadBasePage(SurveyTemplate(survey))
setNextAction {
val surveyParser = SurveyParser(mainWindow, project)
GlobalScope.launch {
surveyParser.parseAndLog()
surveyParser.parseAndLog(survey)
}
processScenario()
}
Expand All @@ -121,6 +123,9 @@ fun Panel.serverErrorPage() {

fun Panel.finalPage() {
loadBasePage(FinalPageTemplate.loadCurrentTemplate(), "ui.button.welcome")
setNextAction {
welcomePage()
}
}

fun Panel.processScenario() {
Expand All @@ -129,11 +134,11 @@ fun Panel.processScenario() {
?: error("Unexpected error, Scenario config must exist!")
when (val unit = scenario.getNextUnit(project)) {
is TaskListUnit -> {
selectTask(unit.tasks)
selectTask(unit.taskIds)
}

is TaskListWithSingleChoiceUnit -> {
selectTask(unit.tasks, allRequired = false)
selectTask(unit.taskIds, allRequired = false)
}

is TaskUnit -> {
Expand All @@ -149,7 +154,7 @@ fun Panel.processScenario() {
}

is SurveyUnit -> {
survey()
survey(unit.id)
}

is ExternalSourceUnit -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package org.jetbrains.research.tasktracker.ui.main.panel.template

import org.jetbrains.research.tasktracker.TaskTrackerPlugin
import org.jetbrains.research.tasktracker.config.survey.SurveyConfig
import org.jetbrains.research.tasktracker.config.survey.Survey
import org.jetbrains.research.tasktracker.requests.FileRequests
import org.jetbrains.research.tasktracker.ui.main.panel.storage.MainPanelStorage

class SurveyTemplate(val config: SurveyConfig) : HtmlBaseFileTemplate() {
class SurveyTemplate(val survey: Survey) : HtmlBaseFileTemplate() {
override val contentFilename: String
get() = "survey"

override val cssFilename: String
get() = "survey"

override val arguments: Array<String>
get() = arrayOf(request(), config.toHtml())
get() = arrayOf(request(), survey.toHtml())

private fun request() = "${FileRequests.DOMAIN}/confirm-survey?id=${MainPanelStorage.currentResearchId}"

companion object {
fun loadCurrentTemplate(): SurveyTemplate {
val config = TaskTrackerPlugin.mainConfig.surveyConfig ?: error("surveyConfig has not initialized yet!")
return SurveyTemplate(config)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.jetbrains.research.tasktracker.util.survey

import com.intellij.openapi.project.Project
import org.jetbrains.concurrency.await
import org.jetbrains.research.tasktracker.TaskTrackerPlugin
import org.jetbrains.research.tasktracker.config.survey.*
import org.jetbrains.research.tasktracker.tracking.Loggable
import org.jetbrains.research.tasktracker.ui.main.panel.MainPluginWindow
Expand All @@ -11,9 +10,8 @@ import java.io.File
class SurveyParser(private val mainWindow: MainPluginWindow, project: Project) : Loggable {
private val surveyLogger = SurveyLogger(project)

private val items = TaskTrackerPlugin.mainConfig.surveyConfig?.htmlQuestions ?: emptyList()

suspend fun parseAndLog() = items.forEachIndexed { index, surveyItem -> parseAndLog(surveyItem, index) }
suspend fun parseAndLog(survey: Survey) =
survey.htmlQuestions.forEachIndexed { index, surveyItem -> parseAndLog(surveyItem, index) }

private suspend fun parseAndLog(item: HtmlQuestion, id: Int) {
when (item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ scenario:
- units:
- !<Task>
id: "hello"
- !<Survey>
id: "default"
mode: SHUFFLED
- units:
- !<Setting>
mainIdeConfig:
settingsConfig:
theme: LIGHT
- !<List>
taskIds:
- "hello"
- "example"
- units:
- !<SingleList>
tasks:
taskIds:
- "hello"
- "example"
- "style"
- "style"
- !<External>
url: "https://github.com/JetBrains-Research/tasktracker-3"
Loading

0 comments on commit 036cf5f

Please sign in to comment.