Skip to content

Commit

Permalink
MAK-53 IJ: Create custom tasks from tool window (#103)
Browse files Browse the repository at this point in the history
and also just calling the action
  • Loading branch information
bcosynot committed Jul 5, 2023
1 parent 506c47b commit 0546ba1
Show file tree
Hide file tree
Showing 10 changed files with 345 additions and 127 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ track of all your notifications.
- Close distracting apps with the Makerflow desktop app
- Added a tool window to see items in Unified Task List
- See all your notifications from GitHub/Bitbucket in your IDE
- Add new tasks
- Start Flow Mode for a task to focus on it

### Changed

Expand Down
171 changes: 106 additions & 65 deletions src/main/kotlin/co/makerflow/client/apis/TasksApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,124 +15,165 @@

package co.makerflow.client.apis

import co.makerflow.client.infrastructure.ApiClient
import co.makerflow.client.infrastructure.HttpResponse
import co.makerflow.client.infrastructure.RequestConfig
import co.makerflow.client.infrastructure.RequestMethod
import co.makerflow.client.infrastructure.wrap
import co.makerflow.client.models.AddCustomTask200Response
import co.makerflow.client.models.CalendarEvent
import co.makerflow.client.models.CustomTask
import co.makerflow.client.models.MarkDoneRequest
import co.makerflow.client.models.TypedTodo

import co.makerflow.client.infrastructure.*
import com.fasterxml.jackson.databind.ObjectMapper
import io.ktor.client.HttpClientConfig
import io.ktor.client.request.forms.formData
import io.ktor.client.engine.HttpClientEngine
import io.ktor.http.ParametersBuilder
import com.fasterxml.jackson.databind.ObjectMapper

open class TasksApi(
open class TasksApi(
baseUrl: String = ApiClient.BASE_URL,
httpClientEngine: HttpClientEngine? = null,
httpClientConfig: ((HttpClientConfig<*>) -> Unit)? = null,
jsonBlock: ObjectMapper.() -> Unit = ApiClient.JSON_DEFAULT,
) : ApiClient(baseUrl, httpClientEngine, httpClientConfig, jsonBlock) {
) : ApiClient(baseUrl, httpClientEngine, httpClientConfig, jsonBlock) {

/**
*
*
* @param source To specify source of request (optional)
* @param customTask Task to be added (optional)
* @return AddCustomTask200Response
*/
@Suppress("UNCHECKED_CAST")
open suspend fun addCustomTask(
source: kotlin.String?,
customTask: CustomTask?
): HttpResponse<AddCustomTask200Response> {

val localVariableAuthNames = listOf<String>("api_token")

Check notice on line 52 in src/main/kotlin/co/makerflow/client/apis/TasksApi.kt

View workflow job for this annotation

GitHub Actions / Build

Unnecessary type argument

Remove explicit type arguments

val localVariableBody = customTask

Check notice on line 54 in src/main/kotlin/co/makerflow/client/apis/TasksApi.kt

View workflow job for this annotation

GitHub Actions / Build

Unnecessary local variable

Variable is same as 'customTask' and can be inlined

val localVariableQuery = mutableMapOf<String, List<String>>()
source?.apply { localVariableQuery["source"] = listOf("$source") }

val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.POST,
"/custom_tasks",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)

return jsonRequest(
localVariableConfig,
localVariableBody,
localVariableAuthNames
).wrap()
}


/**
*
*
* @param source To specify source of request (optional)
* @return kotlin.collections.List<TypedTodo>
*/
@Suppress("UNCHECKED_CAST")
open suspend fun getTodos(source: kotlin.String?): HttpResponse<kotlin.collections.List<TypedTodo>> {
/**
*
*
* @param source To specify source of request (optional)
* @return kotlin.collections.List<TypedTodo>
*/
@Suppress("UNCHECKED_CAST")
open suspend fun getTodos(source: kotlin.String?): HttpResponse<kotlin.collections.List<TypedTodo>> {

val localVariableAuthNames = listOf<String>("api_token")
val localVariableAuthNames = listOf<String>("api_token")

Check notice on line 86 in src/main/kotlin/co/makerflow/client/apis/TasksApi.kt

View workflow job for this annotation

GitHub Actions / Build

Unnecessary type argument

Remove explicit type arguments

val localVariableBody =
io.ktor.client.utils.EmptyContent
val localVariableBody =
io.ktor.client.utils.EmptyContent

val localVariableQuery = mutableMapOf<String, List<String>>()
source?.apply { localVariableQuery["source"] = listOf("$source") }
val localVariableQuery = mutableMapOf<String, List<String>>()
source?.apply { localVariableQuery["source"] = listOf("$source") }

val localVariableHeaders = mutableMapOf<String, String>()
val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig = RequestConfig<kotlin.Any?>(
val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/tasks/todo",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
)

return request(
return request(
localVariableConfig,
localVariableBody,
localVariableAuthNames
).wrap()
}
).wrap()
}

/**
*
*
* @param source To specify source of request (optional)
* @param markDoneRequest Task to be marked as completed (optional)
* @return TypedTodo
*/
@Suppress("UNCHECKED_CAST")
open suspend fun markDone(source: kotlin.String?, markDoneRequest: MarkDoneRequest?): HttpResponse<TypedTodo> {
/**
*
*
* @param source To specify source of request (optional)
* @param markDoneRequest Task to be marked as completed (optional)
* @return TypedTodo
*/
@Suppress("UNCHECKED_CAST")
open suspend fun markDone(source: kotlin.String?, markDoneRequest: MarkDoneRequest?): HttpResponse<TypedTodo> {

val localVariableAuthNames = listOf<String>("api_token")
val localVariableAuthNames = listOf<String>("api_token")

Check notice on line 121 in src/main/kotlin/co/makerflow/client/apis/TasksApi.kt

View workflow job for this annotation

GitHub Actions / Build

Unnecessary type argument

Remove explicit type arguments

val localVariableBody = markDoneRequest
val localVariableBody = markDoneRequest

Check notice on line 123 in src/main/kotlin/co/makerflow/client/apis/TasksApi.kt

View workflow job for this annotation

GitHub Actions / Build

Unnecessary local variable

Variable is same as 'markDoneRequest' and can be inlined

val localVariableQuery = mutableMapOf<String, List<String>>()
source?.apply { localVariableQuery["source"] = listOf("$source") }
val localVariableQuery = mutableMapOf<String, List<String>>()
source?.apply { localVariableQuery["source"] = listOf("$source") }

val localVariableHeaders = mutableMapOf<String, String>()
val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig = RequestConfig<kotlin.Any?>(
val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.POST,
"/tasks/todo/done",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
)

return jsonRequest(
return jsonRequest(
localVariableConfig,
localVariableBody,
localVariableAuthNames
).wrap()
}
).wrap()
}

/**
*
*
* @param source To specify source of request (optional)
* @return kotlin.collections.List<CalendarEvent>
*/
@Suppress("UNCHECKED_CAST")
open suspend fun upcomingCalendarEvents(source: kotlin.String?): HttpResponse<kotlin.collections.List<CalendarEvent>> {
/**
*
*
* @param source To specify source of request (optional)
* @return kotlin.collections.List<CalendarEvent>
*/
@Suppress("UNCHECKED_CAST")
open suspend fun upcomingCalendarEvents(source: kotlin.String?): HttpResponse<kotlin.collections.List<CalendarEvent>> {

val localVariableAuthNames = listOf<String>("api_token")
val localVariableAuthNames = listOf<String>("api_token")

Check notice on line 154 in src/main/kotlin/co/makerflow/client/apis/TasksApi.kt

View workflow job for this annotation

GitHub Actions / Build

Unnecessary type argument

Remove explicit type arguments

val localVariableBody =
io.ktor.client.utils.EmptyContent
val localVariableBody =
io.ktor.client.utils.EmptyContent

val localVariableQuery = mutableMapOf<String, List<String>>()
source?.apply { localVariableQuery["source"] = listOf("$source") }
val localVariableQuery = mutableMapOf<String, List<String>>()
source?.apply { localVariableQuery["source"] = listOf("$source") }

val localVariableHeaders = mutableMapOf<String, String>()
val localVariableHeaders = mutableMapOf<String, String>()

val localVariableConfig = RequestConfig<kotlin.Any?>(
val localVariableConfig = RequestConfig<kotlin.Any?>(
RequestMethod.GET,
"/tasks/calendar/events",
query = localVariableQuery,
headers = localVariableHeaders,
requiresAuthentication = true,
)
)

return request(
return request(
localVariableConfig,
localVariableBody,
localVariableAuthNames
).wrap()
}
).wrap()
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/

@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)

package co.makerflow.client.models

import com.fasterxml.jackson.annotation.JsonProperty

/**
*
*
* @param `data`
* @param message
* @param success
*/


data class AddCustomTask200Response(

@field:JsonProperty("data")
val `data`: CustomTask? = null,

@field:JsonProperty("message")
val message: kotlin.String? = null,

@field:JsonProperty("success")
val success: kotlin.Boolean? = null

)

7 changes: 4 additions & 3 deletions src/main/kotlin/co/makerflow/client/models/TypedTodo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo
* @param pr
* @param meta
*/
@Suppress("ConvertSecondaryConstructorToPrimary")
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes(
JsonSubTypes.Type(value = PullRequestTodo::class, name = "bitbucket"),
Expand All @@ -50,13 +51,13 @@ open class TypedTodo {

/* The type of source that the todo is from */
@get:JsonProperty("sourceType")
val sourceType: TypedTodo.SourceType? = null
var sourceType: TypedTodo.SourceType? = null
/* The type of todo */
@get:JsonProperty("type")
val type: kotlin.String? = null
var type: kotlin.String? = null
/* Timestamp for when the todo was created */
@get:JsonProperty("createdAt")
val createdAt: kotlin.String? = null
var createdAt: kotlin.String? = null
/* Whether the todo has been completed */
@get:JsonProperty("done")
var done: kotlin.Boolean? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package co.makerflow.intellijplugin.actions.tasks

import co.makerflow.intellijplugin.dialogs.AddTaskDialog
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent

class AddCustomTaskAction : AnAction(
"Makerflow: Add Task",
"Add a new task to the Makerflow task list",
AllIcons.Actions.AddList
) {
override fun actionPerformed(e: AnActionEvent) {
AddTaskDialog().showAndGet()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package co.makerflow.intellijplugin.dialogs

import co.makerflow.intellijplugin.services.TasksService
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
import com.intellij.openapi.observable.properties.PropertyGraph
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.openapi.ui.ValidationInfo
import com.intellij.ui.components.JBTextField
import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.bindText
import com.intellij.ui.dsl.builder.panel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.swing.JComponent

class AddTaskDialog : DialogWrapper(false) {

private val propertyGraph = PropertyGraph()
private val taskName = propertyGraph.property("")
private lateinit var taskField: Cell<JBTextField>

init {
title = "Makerflow: Add Task"
init()
}

override fun createCenterPanel(): JComponent {
return panel {
row {
textField()
.bindText(taskName)
.apply { taskField = this }
.comment("What do you want to accomplish?")
}
}
}

override fun getPreferredFocusedComponent(): JComponent = taskField.component

override fun doValidate(): ValidationInfo? {
if (taskName.get().isBlank()) {
return ValidationInfo("Task cannot be empty", taskField.component)
}
return null
}

private val addTaskCoroutineScope = CoroutineScope(Dispatchers.IO)

override fun doOKAction() {
super.doOKAction()
ApplicationManager.getApplication().invokeLater {
addTaskCoroutineScope.launch {
service<TasksService>().addTask(taskName.get())?.let {
// send a message on the message bus so the panel knows to reload
ApplicationManager.getApplication().messageBus.syncPublisher(TasksService.TASKS_ADDED_TOPIC)
.taskAdded(it)
}
}
}
}
}
Loading

0 comments on commit 0546ba1

Please sign in to comment.