Skip to content

Impl: action to open dashboard in the browser #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- warning system when plugin might not be compatible with Coder REST API
- a `Create workspace` button which links to Coder's templates page
- workspace icons
- quick toolbar action to open Coder Dashboard in the browser

### Changed
- redesigned the information&warning banner. Messages can now include hyperlinks
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/coder/gateway/icons/CoderIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ object CoderIcons {

val OPEN_TERMINAL = IconLoader.getIcon("open_terminal.svg", javaClass)

val HOME = IconLoader.getIcon("homeFolder.svg", javaClass)
val CREATE = IconLoader.getIcon("create.svg", javaClass)
val RUN = IconLoader.getIcon("run.svg", javaClass)
val STOP = IconLoader.getIcon("stop.svg", javaClass)
Expand Down
23 changes: 7 additions & 16 deletions src/main/kotlin/com/coder/gateway/sdk/CoderRestClientService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import java.util.UUID

@Service(Service.Level.APP)
class CoderRestClientService {
var isReady: Boolean = false
private set
private lateinit var httpClient: OkHttpClient
private lateinit var retroRestClient: CoderV2RestFacade
private lateinit var sessionToken: String
Expand All @@ -40,21 +42,10 @@ class CoderRestClientService {
* @throws [AuthenticationResponseException] if authentication failed.
*/
fun initClientSession(url: URL, token: String): User {
val gson: Gson = GsonBuilder()
.registerTypeAdapter(Instant::class.java, InstantConverter())
.setPrettyPrinting()
.create()
httpClient = OkHttpClient.Builder()
.addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }
.addInterceptor(HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BASIC) })
.build()

retroRestClient = Retrofit.Builder()
.baseUrl(url.toString())
.client(httpClient)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
.create(CoderV2RestFacade::class.java)
val gson: Gson = GsonBuilder().registerTypeAdapter(Instant::class.java, InstantConverter()).setPrettyPrinting().create()
httpClient = OkHttpClient.Builder().addInterceptor { it.proceed(it.request().newBuilder().addHeader("Coder-Session-Token", token).build()) }.addInterceptor(HttpLoggingInterceptor().apply { setLevel(HttpLoggingInterceptor.Level.BASIC) }).build()

retroRestClient = Retrofit.Builder().baseUrl(url.toString()).client(httpClient).addConverterFactory(GsonConverterFactory.create(gson)).build().create(CoderV2RestFacade::class.java)

val userResponse = retroRestClient.me().execute()
if (!userResponse.isSuccessful) {
Expand All @@ -65,7 +56,7 @@ class CoderRestClientService {
sessionToken = token
me = userResponse.body()!!
buildVersion = buildInfo().version

isReady = true
return me
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
}
}

private val goToDashboardAction = GoToDashboardAction()
private val startWorkspaceAction = StartWorkspaceAction()
private val stopWorkspaceAction = StopWorkspaceAction()
private val updateWorkspaceTemplateAction = UpdateWorkspaceTemplateAction()
Expand All @@ -134,6 +135,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
.disableAddAction()
.disableRemoveAction()
.disableUpDownActions()
.addExtraAction(goToDashboardAction)
.addExtraAction(startWorkspaceAction)
.addExtraAction(stopWorkspaceAction)
.addExtraAction(updateWorkspaceTemplateAction)
Expand Down Expand Up @@ -183,6 +185,12 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
override val previousActionText = IdeBundle.message("button.back")
override val nextActionText = CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.next.text")

private inner class GoToDashboardAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.dashboard.text"), CoderIcons.HOME) {
override fun actionPerformed(p0: AnActionEvent) {
BrowserUtil.browse(coderClient.coderURL)
}
}

private inner class StartWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.start.text"), CoderIcons.RUN) {
override fun actionPerformed(p0: AnActionEvent) {
if (tableOfWorkspaces.selectedObject != null) {
Expand Down Expand Up @@ -221,12 +229,6 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
}
}

private inner class CreateWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderIcons.CREATE) {
override fun actionPerformed(p0: AnActionEvent) {
BrowserUtil.browse(coderClient.coderURL.toURI().resolve("/templates"))
}
}

private inner class StopWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.stop.text"), CoderIcons.STOP) {
override fun actionPerformed(p0: AnActionEvent) {
if (tableOfWorkspaces.selectedObject != null) {
Expand All @@ -245,6 +247,12 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
}
}

private inner class CreateWorkspaceAction : AnActionButton(CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderGatewayBundle.message("gateway.connector.view.coder.workspaces.create.text"), CoderIcons.CREATE) {
override fun actionPerformed(p0: AnActionEvent) {
BrowserUtil.browse(coderClient.coderURL.toURI().resolve("/templates"))
}
}

override fun onInit(wizardModel: CoderWorkspacesWizardModel) {
enableNextButtonCallback(false)
if (localWizardModel.coderURL.isNotBlank() && localWizardModel.token.isNotBlank()) {
Expand All @@ -265,8 +273,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
}

private fun updateWorkspaceActions() {
createWorkspaceAction.isEnabled = true

goToDashboardAction.isEnabled = coderClient.isReady
createWorkspaceAction.isEnabled = coderClient.isReady
when (tableOfWorkspaces.selectedObject?.agentStatus) {
RUNNING -> {
startWorkspaceAction.isEnabled = false
Expand Down Expand Up @@ -380,6 +388,7 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
cs.launch {
ProgressManager.getInstance().run(authTask)
}
updateWorkspaceActions()
triggerWorkspacePolling()
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/homeFolder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/main/resources/homeFolder_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/main/resources/messages/CoderGatewayBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gateway.connector.view.coder.workspaces.connect.text=Connect
gateway.connector.view.coder.workspaces.cli.downloader.dialog.title=Authenticate and setup Coder
gateway.connector.view.coder.workspaces.cli.configssh.dialog.title=Coder Config SSH
gateway.connector.view.coder.workspaces.next.text=Select IDE and Project
gateway.connector.view.coder.workspaces.dashboard.text=Open Dashboard
gateway.connector.view.coder.workspaces.start.text=Start Workspace
gateway.connector.view.coder.workspaces.stop.text=Stop Workspace
gateway.connector.view.coder.workspaces.update.text=Update Workspace Template
Expand Down