@@ -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.TemplateResponseException
20
21
import com.coder.gateway.sdk.ex.WorkspaceResponseException
21
22
import com.coder.gateway.sdk.getOS
22
23
import com.coder.gateway.sdk.toURL
@@ -107,13 +108,15 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
107
108
108
109
private val startWorkspaceAction = StartWorkspaceAction ()
109
110
private val stopWorkspaceAction = StopWorkspaceAction ()
111
+ private val updateWorkspaceTemplateAction = UpdateWorkspaceTemplateAction ()
110
112
111
113
private val toolbar = ToolbarDecorator .createDecorator(tableOfWorkspaces)
112
114
.disableAddAction()
113
115
.disableRemoveAction()
114
116
.disableUpDownActions()
115
117
.addExtraAction(startWorkspaceAction)
116
118
.addExtraAction(stopWorkspaceAction)
119
+ .addExtraAction(updateWorkspaceTemplateAction)
117
120
118
121
private var poller: Job ? = null
119
122
@@ -175,6 +178,26 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
175
178
}
176
179
}
177
180
181
+ private inner class UpdateWorkspaceTemplateAction : AnActionButton (CoderGatewayBundle .message("gateway.connector.view.coder.workspaces.update.text"), CoderGatewayBundle .message("gateway.connector.view.coder.workspaces.update.text"), CoderIcons .UPDATE ) {
182
+ override fun actionPerformed (p0 : AnActionEvent ) {
183
+ if (tableOfWorkspaces.selectedObject != null ) {
184
+ val workspace = tableOfWorkspaces.selectedObject as WorkspaceAgentModel
185
+ cs.launch {
186
+ withContext(Dispatchers .IO ) {
187
+ try {
188
+ coderClient.updateWorkspace(workspace.workspaceID, workspace.workspaceName, workspace.lastBuildTransition, workspace.templateID)
189
+ loadWorkspaces()
190
+ } catch (e: WorkspaceResponseException ) {
191
+ logger.warn(" Could not update workspace ${workspace.name} , reason: $e " )
192
+ } catch (e: TemplateResponseException ) {
193
+ logger.warn(" Could not update workspace ${workspace.name} , reason: $e " )
194
+ }
195
+ }
196
+ }
197
+ }
198
+ }
199
+ }
200
+
178
201
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
202
override fun actionPerformed (p0 : AnActionEvent ) {
180
203
if (tableOfWorkspaces.selectedObject != null ) {
@@ -203,16 +226,26 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
203
226
RUNNING -> {
204
227
startWorkspaceAction.isEnabled = false
205
228
stopWorkspaceAction.isEnabled = true
229
+ when (tableOfWorkspaces.selectedObject?.status) {
230
+ WorkspaceVersionStatus .OUTDATED -> updateWorkspaceTemplateAction.isEnabled = true
231
+ else -> updateWorkspaceTemplateAction.isEnabled = false
232
+ }
233
+
206
234
}
207
235
208
236
STOPPED , FAILED -> {
209
237
startWorkspaceAction.isEnabled = true
210
238
stopWorkspaceAction.isEnabled = false
239
+ when (tableOfWorkspaces.selectedObject?.status) {
240
+ WorkspaceVersionStatus .OUTDATED -> updateWorkspaceTemplateAction.isEnabled = true
241
+ else -> updateWorkspaceTemplateAction.isEnabled = false
242
+ }
211
243
}
212
244
213
245
else -> {
214
246
startWorkspaceAction.isEnabled = false
215
247
stopWorkspaceAction.isEnabled = false
248
+ updateWorkspaceTemplateAction.isEnabled = false
216
249
}
217
250
}
218
251
ActivityTracker .getInstance().inc()
@@ -342,9 +375,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
342
375
this .id,
343
376
this .name,
344
377
this .name,
378
+ this .templateID,
345
379
this .templateName,
346
380
WorkspaceVersionStatus .from(this ),
347
381
WorkspaceAgentStatus .from(this ),
382
+ this .latestBuild.workspaceTransition.name.toLowerCase(),
348
383
null ,
349
384
null ,
350
385
null
@@ -358,9 +393,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
358
393
this .id,
359
394
this .name,
360
395
workspaceWithAgentName,
396
+ this .templateID,
361
397
this .templateName,
362
398
WorkspaceVersionStatus .from(this ),
363
399
WorkspaceAgentStatus .from(this ),
400
+ this .latestBuild.workspaceTransition.name.toLowerCase(),
364
401
OS .from(agent.operatingSystem),
365
402
Arch .from(agent.architecture),
366
403
agent.directory
@@ -374,9 +411,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
374
411
this .id,
375
412
this .name,
376
413
this .name,
414
+ this .templateID,
377
415
this .templateName,
378
416
WorkspaceVersionStatus .from(this ),
379
417
WorkspaceAgentStatus .from(this ),
418
+ this .latestBuild.workspaceTransition.name.toLowerCase(),
380
419
null ,
381
420
null ,
382
421
null
0 commit comments