@@ -17,6 +17,7 @@ import com.coder.gateway.sdk.CoderCLIManager
1717import com.coder.gateway.sdk.CoderRestClientService
1818import com.coder.gateway.sdk.OS
1919import com.coder.gateway.sdk.ex.AuthenticationResponseException
20+ import com.coder.gateway.sdk.ex.TemplateResponseException
2021import com.coder.gateway.sdk.ex.WorkspaceResponseException
2122import com.coder.gateway.sdk.getOS
2223import com.coder.gateway.sdk.toURL
@@ -107,13 +108,15 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
107108
108109 private val startWorkspaceAction = StartWorkspaceAction ()
109110 private val stopWorkspaceAction = StopWorkspaceAction ()
111+ private val updateWorkspaceTemplateAction = UpdateWorkspaceTemplateAction ()
110112
111113 private val toolbar = ToolbarDecorator .createDecorator(tableOfWorkspaces)
112114 .disableAddAction()
113115 .disableRemoveAction()
114116 .disableUpDownActions()
115117 .addExtraAction(startWorkspaceAction)
116118 .addExtraAction(stopWorkspaceAction)
119+ .addExtraAction(updateWorkspaceTemplateAction)
117120
118121 private var poller: Job ? = null
119122
@@ -175,6 +178,26 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
175178 }
176179 }
177180
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+
178201 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 ) {
179202 override fun actionPerformed (p0 : AnActionEvent ) {
180203 if (tableOfWorkspaces.selectedObject != null ) {
@@ -203,16 +226,26 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
203226 RUNNING -> {
204227 startWorkspaceAction.isEnabled = false
205228 stopWorkspaceAction.isEnabled = true
229+ when (tableOfWorkspaces.selectedObject?.status) {
230+ WorkspaceVersionStatus .OUTDATED -> updateWorkspaceTemplateAction.isEnabled = true
231+ else -> updateWorkspaceTemplateAction.isEnabled = false
232+ }
233+
206234 }
207235
208236 STOPPED , FAILED -> {
209237 startWorkspaceAction.isEnabled = true
210238 stopWorkspaceAction.isEnabled = false
239+ when (tableOfWorkspaces.selectedObject?.status) {
240+ WorkspaceVersionStatus .OUTDATED -> updateWorkspaceTemplateAction.isEnabled = true
241+ else -> updateWorkspaceTemplateAction.isEnabled = false
242+ }
211243 }
212244
213245 else -> {
214246 startWorkspaceAction.isEnabled = false
215247 stopWorkspaceAction.isEnabled = false
248+ updateWorkspaceTemplateAction.isEnabled = false
216249 }
217250 }
218251 ActivityTracker .getInstance().inc()
@@ -342,9 +375,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
342375 this .id,
343376 this .name,
344377 this .name,
378+ this .templateID,
345379 this .templateName,
346380 WorkspaceVersionStatus .from(this ),
347381 WorkspaceAgentStatus .from(this ),
382+ this .latestBuild.workspaceTransition.name.toLowerCase(),
348383 null ,
349384 null ,
350385 null
@@ -358,9 +393,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
358393 this .id,
359394 this .name,
360395 workspaceWithAgentName,
396+ this .templateID,
361397 this .templateName,
362398 WorkspaceVersionStatus .from(this ),
363399 WorkspaceAgentStatus .from(this ),
400+ this .latestBuild.workspaceTransition.name.toLowerCase(),
364401 OS .from(agent.operatingSystem),
365402 Arch .from(agent.architecture),
366403 agent.directory
@@ -374,9 +411,11 @@ class CoderWorkspacesStepView(val enableNextButtonCallback: (Boolean) -> Unit) :
374411 this .id,
375412 this .name,
376413 this .name,
414+ this .templateID,
377415 this .templateName,
378416 WorkspaceVersionStatus .from(this ),
379417 WorkspaceAgentStatus .from(this ),
418+ this .latestBuild.workspaceTransition.name.toLowerCase(),
380419 null ,
381420 null ,
382421 null
0 commit comments