Skip to content

Commit

Permalink
Merge branch 'main' into intro-course
Browse files Browse the repository at this point in the history
  • Loading branch information
mikrise2 authored Jan 25, 2024
2 parents e9865f5 + 66b9378 commit f7f4633
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class TaskContentConfig(val tasks: List<ProgrammingTask>) : BaseConfig {
config.tasks.forEach { task ->
task.language?.let {
task.files.forEach { fileInfo ->
fileInfo.extension = it
fileInfo.extension = fileInfo.extension ?: it
fileInfo.relativePath = getRelativePath(task, fileInfo)
fileInfo.content = fileInfo.gatherContent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ enum class Extension(val ext: String) {
JAVA(".java"),
KOTLIN(".kt"),
CPP(".cpp"),
CSV(".csv")
CSV(".csv"),
NO_EXTENSION("")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.openapi.diagnostic.Logger
import io.ktor.client.*
import io.ktor.client.engine.cio.*
import io.ktor.client.request.forms.*
import io.ktor.client.statement.*
import io.ktor.http.*
import org.apache.http.client.utils.URIBuilder
import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig.Companion.getRoute
Expand All @@ -22,7 +23,7 @@ object FileRequests {
?: error("ResearchId is undefined")
val url = URIBuilder(getRoute("upload-log-file")).addParameter("logFileType", logFileType)
.addParameter("id", researchId.toString()).build().toString()
client.submitFormWithBinaryData(
val response = client.submitFormWithBinaryData(
url = url,
formData = formData {
append(
Expand All @@ -36,7 +37,7 @@ object FileRequests {
)
}
)
return true
return response.status.isSuccess()
} catch (e: IllegalStateException) {
logger.warn(e.localizedMessage)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ object TaskFileHandler {
}

private fun getPath(project: Project, taskFile: ITaskFileInfo, task: TaskWithFiles): String = buildString {
append("${project.basePath}/")
append("${project.basePath}")
if (taskFile.isInternal) {
append("$PLUGIN_NAME/${taskFile.extension?.getDirectoryName() ?: ""}")
append("/$PLUGIN_NAME/${taskFile.extension?.getDirectoryName() ?: ""}")
append("${task.root.pathOrEmpty()}/${taskFile.sourceSet.path}")
}
append("${taskFile.relativePath.toPackageName().pathOrEmpty()}/")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.jetbrains.research.tasktracker.tracking

import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import kotlinx.coroutines.runBlocking
import org.jetbrains.research.tasktracker.tracking.activity.ActivityTracker
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorTracker
import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowTracker

@Service(Service.Level.PROJECT)
class TrackingService : Disposable {

private val trackers: MutableList<BaseTracker> = mutableListOf()

fun startTracking(project: Project) {
if (trackers.isNotEmpty()) { // Otherwise we can lose data
return
}
trackers.addAll(
listOf(
ActivityTracker(project),
ToolWindowTracker(project),
FileEditorTracker(project)
)
)
trackers.forEach { it.startTracking() }
}

/**
* Stops the tracking process by calling the stopTracking method of each tracker.
* After stopping the tracking, it invokes the send method of each tracker to send the tracked data.
*
* @param success A lambda that will be executed after the tracking is stopped and the data is sent successfully.
* @param failure A lambda that will be executed if there is a failure in stopping the tracking or sending the data.
*/
fun stopTracking(success: () -> Unit = {}, failure: () -> Unit = {}) {
trackers.forEach {
it.stopTracking()
}
ApplicationManager.getApplication().invokeAndWait {
runBlocking {
val result = trackers.all {
it.send()
}
trackers.clear()
if (result) success.invoke() else failure.invoke()
}
}
}

override fun dispose() {
stopTracking()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.jetbrains.research.tasktracker.models.Extension
import java.util.*

fun String.toPackageName() =
listOf(" ", "-", "_").fold(this) { acc, s -> acc.replace(s, "") }.lowercase(Locale.getDefault())
listOf(" ", "-", "_").fold(this) { acc, s -> acc.replace(s, "") }

fun Extension.getDirectoryName() = this.name.lowercase(Locale.getDefault())
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@ 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.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json
import org.jetbrains.concurrency.Promise
import org.jetbrains.research.tasktracker.TaskTrackerPlugin
import org.jetbrains.research.tasktracker.config.content.task.base.Task
import org.jetbrains.research.tasktracker.tracking.BaseTracker
import org.jetbrains.research.tasktracker.tracking.TaskFileHandler
import org.jetbrains.research.tasktracker.tracking.activity.ActivityTracker
import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorTracker
import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowTracker
import org.jetbrains.research.tasktracker.tracking.TrackingService
import org.jetbrains.research.tasktracker.tracking.webcam.collectAllDevices
import org.jetbrains.research.tasktracker.ui.main.panel.models.AgreementChecker
import org.jetbrains.research.tasktracker.ui.main.panel.models.ButtonState
Expand Down Expand Up @@ -51,15 +46,15 @@ class MainPluginPanelFactory : ToolWindowFactory {
private val backButton = createJButton("ui.button.back", isVisibleProp = false)
private val logger: Logger = Logger.getInstance(MainPluginPanelFactory::class.java)

val trackers: MutableList<BaseTracker> = mutableListOf()

lateinit var trackingService: TrackingService
lateinit var mainWindow: MainPluginWindow
lateinit var project: Project

override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
TaskTrackerPlugin.initPlugin()
this.project = project
mainWindow = project.getService(MainWindowService::class.java).mainWindow
trackingService = project.getService(TrackingService::class.java)
mainWindow.jComponent.size = JBUI.size(toolWindow.component.width, toolWindow.component.height)
agreementAcceptance()
val buttonPanel = JBPanel<JBPanel<*>>(FlowLayout()).apply {
Expand All @@ -76,31 +71,6 @@ class MainPluginPanelFactory : ToolWindowFactory {

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

fun startTracking() {
if (trackers.isNotEmpty()) { // Otherwise we can lose data
return
}
trackers.addAll(
listOf(
ActivityTracker(project),
ToolWindowTracker(project),
FileEditorTracker(project)
)
)
trackers.forEach { it.startTracking() }
}

fun stopTracking() {
trackers.forEach {
it.stopTracking()
}
GlobalScope.launch {
trackers.forEach {
it.send()
}
}
}

fun loadBasePage(
template: HtmlTemplate,
buttonTextKey: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fun Panel.agreementAcceptance() {
GlobalPluginStorage.userId = IdRequests.getUserId(agreement.name, agreement.email).alsoIfNull {
notifyError(
project,
"Connection problems with the server, check tour connection or try later"
UIBundle.message("ui.connection.lose")
)
}
}
Expand All @@ -54,7 +54,7 @@ fun Panel.welcomePage() {
loadBasePage(MainPageTemplate.loadCurrentTemplate(), "ui.button.next", false)
setNextAction {
TaskTrackerPlugin.initializationHandler.setupEnvironment(project)
startTracking()
trackingService.startTracking(project)
processScenario()
}
}
Expand Down Expand Up @@ -128,7 +128,6 @@ fun Panel.survey(id: String) {
}

fun Panel.serverErrorPage() {
trackers.clear()
loadBasePage(ServerErrorPage(), "ui.button.welcome", false)
}

Expand Down Expand Up @@ -174,8 +173,10 @@ fun Panel.processScenario() {

null -> {
scenario.reset()
stopTracking()
finalPage()
loadBasePage(LoadTemplate())
GlobalScope.launch {
trackingService.stopTracking(::finalPage, ::serverErrorPage)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.jetbrains.research.tasktracker.ui.main.panel.template

class LoadTemplate : HtmlBaseFileTemplate() {
override val contentFilename: String
get() = "load"
override val cssFilename: String
get() = "load"
}
2 changes: 2 additions & 0 deletions ij-plugin/src/main/resources/messages/UIBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ ui.button.welcome=welcome screen
ui.progress.webcam.title=Making Photos Via All Available Devices

ui.please.fill=Please fill all required fields

ui.connection.lose=Connection problems with the server, check your connection or try later
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.lds-default {
display: inline-block;
position: relative;
width: 80px;
height: 80px;
}

.lds-default div {
position: absolute;
width: 6px;
height: 6px;
background: #fff;
border-radius: 50%;
animation: lds-default 1.2s linear infinite;
}

.lds-default div:nth-child(1) {
animation-delay: 0s;
top: 37px;
left: 66px;
}

.lds-default div:nth-child(2) {
animation-delay: -0.1s;
top: 22px;
left: 62px;
}

.lds-default div:nth-child(3) {
animation-delay: -0.2s;
top: 11px;
left: 52px;
}

.lds-default div:nth-child(4) {
animation-delay: -0.3s;
top: 7px;
left: 37px;
}

.lds-default div:nth-child(5) {
animation-delay: -0.4s;
top: 11px;
left: 22px;
}

.lds-default div:nth-child(6) {
animation-delay: -0.5s;
top: 22px;
left: 11px;
}

.lds-default div:nth-child(7) {
animation-delay: -0.6s;
top: 37px;
left: 7px;
}

.lds-default div:nth-child(8) {
animation-delay: -0.7s;
top: 52px;
left: 11px;
}

.lds-default div:nth-child(9) {
animation-delay: -0.8s;
top: 62px;
left: 22px;
}

.lds-default div:nth-child(10) {
animation-delay: -0.9s;
top: 66px;
left: 37px;
}

.lds-default div:nth-child(11) {
animation-delay: -1s;
top: 62px;
left: 52px;
}

.lds-default div:nth-child(12) {
animation-delay: -1.1s;
top: 52px;
left: 62px;
}

@keyframes lds-default {
0%, 20%, 80%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.5);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="container">
<div class="lds-default">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<br>
<p class="small-font">
Please wait while the data is being sent
</p>
</div>

0 comments on commit f7f4633

Please sign in to comment.