@@ -17,6 +17,7 @@ import com.coder.gateway.sdk.CoderCLIManager
17
17
import com.coder.gateway.sdk.CoderRestClientService
18
18
import com.coder.gateway.sdk.OS
19
19
import com.coder.gateway.sdk.ex.AuthenticationResponseException
20
+ import com.coder.gateway.sdk.ex.WorkspaceResponseException
20
21
import com.coder.gateway.sdk.getOS
21
22
import com.coder.gateway.sdk.toURL
22
23
import com.coder.gateway.sdk.v2.models.Workspace
@@ -171,13 +172,37 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
171
172
172
173
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 ) {
173
174
override fun actionPerformed (p0 : AnActionEvent ) {
174
- TODO (" Not yet implemented" )
175
+ if (tableOfWorkspaces.selectedObject != null ) {
176
+ val workspace = tableOfWorkspaces.selectedObject as WorkspaceAgentModel
177
+ cs.launch {
178
+ withContext(Dispatchers .IO ) {
179
+ try {
180
+ coderClient.startWorkspace(workspace.workspaceID, workspace.workspaceName)
181
+ startWorkspaceAction.isEnabled = false
182
+ } catch (e: WorkspaceResponseException ) {
183
+ logger.warn(" Could not build workspace ${workspace.name} , reason: $e " )
184
+ }
185
+ }
186
+ }
187
+ }
175
188
}
176
189
}
177
190
178
191
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 ) {
179
192
override fun actionPerformed (p0 : AnActionEvent ) {
180
- TODO (" Not yet implemented" )
193
+ if (tableOfWorkspaces.selectedObject != null ) {
194
+ val workspace = tableOfWorkspaces.selectedObject as WorkspaceAgentModel
195
+ cs.launch {
196
+ withContext(Dispatchers .IO ) {
197
+ try {
198
+ coderClient.stopWorkspace(workspace.workspaceID, workspace.workspaceName)
199
+ stopWorkspaceAction.isEnabled = false
200
+ } catch (e: WorkspaceResponseException ) {
201
+ logger.warn(" Could not stop workspace ${workspace.name} , reason: $e " )
202
+ }
203
+ }
204
+ }
205
+ }
181
206
}
182
207
}
183
208
@@ -310,6 +335,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
310
335
0 -> {
311
336
listOf (
312
337
WorkspaceAgentModel (
338
+ this .id,
339
+ this .name,
313
340
this .name,
314
341
this .templateName,
315
342
WorkspaceVersionStatus .from(this ),
@@ -324,6 +351,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
324
351
1 -> {
325
352
listOf (
326
353
WorkspaceAgentModel (
354
+ this .id,
355
+ this .name,
327
356
this .name,
328
357
this .templateName,
329
358
WorkspaceVersionStatus .from(this ),
@@ -338,6 +367,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
338
367
else -> agents.map { agent ->
339
368
val workspaceName = " ${this .name} .${agent.name} "
340
369
WorkspaceAgentModel (
370
+ this .id,
371
+ this .name,
341
372
workspaceName,
342
373
this .templateName,
343
374
WorkspaceVersionStatus .from(this ),
@@ -353,6 +384,8 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
353
384
logger.warn(" Agent(s) for ${this .name} could not be retrieved. Reason: $e " )
354
385
listOf (
355
386
WorkspaceAgentModel (
387
+ this .id,
388
+ this .name,
356
389
this .name,
357
390
this .templateName,
358
391
WorkspaceVersionStatus .from(this ),
0 commit comments