From 12bf0a11de46a344eaaa19b570bfac8a5692d442 Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Wed, 25 Jan 2017 16:06:13 +0200 Subject: [PATCH] CHE-3797 fix project import in case when workspace is running Signed-off-by: Oleksii Orel --- .../create-project.controller.ts | 21 ++++++++++++------- .../components/api/che-workspace.factory.ts | 18 +++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/dashboard/src/app/projects/create-project/create-project.controller.ts b/dashboard/src/app/projects/create-project/create-project.controller.ts index 26d72b1e15..a120b18c15 100755 --- a/dashboard/src/app/projects/create-project/create-project.controller.ts +++ b/dashboard/src/app/projects/create-project/create-project.controller.ts @@ -950,13 +950,20 @@ export class CreateProjectController { */ checkExistingWorkspaceState(workspace: any): void { if (workspace.status === 'RUNNING') { - let websocketUrl = this.cheAPI.getWorkspace().getWebsocketUrl(workspace.id); - // get bus - let websocketStream = this.$websocket(websocketUrl); - // on success, create project - websocketStream.onOpen(() => { - let bus = this.cheAPI.getWebsocket().getExistingBus(websocketStream); - this.createProjectInWorkspace(workspace.id, this.projectName, this.importProjectData, bus); + this.cheAPI.getWorkspace().fetchWorkspaceDetails(workspace.id).finally(() => { + let websocketUrl = this.cheAPI.getWorkspace().getWebsocketUrl(workspace.id); + if (!websocketUrl) { + this.getCreationSteps()[this.getCurrentProgressStep()].hasError = true; + this.$log.error('Unable to create project in workspace. Error when trying to get websocket URL.'); + return; + } + // get bus + let websocketStream = this.$websocket(websocketUrl); + // on success, create project + websocketStream.onOpen(() => { + let bus = this.cheAPI.getWebsocket().getExistingBus(websocketStream); + this.createProjectInWorkspace(workspace.id, this.projectName, this.importProjectData, bus); + }); }); } else { this.subscribeStatusChannel(workspace); diff --git a/dashboard/src/components/api/che-workspace.factory.ts b/dashboard/src/components/api/che-workspace.factory.ts index 3a70cafb43..71a03754c4 100644 --- a/dashboard/src/components/api/che-workspace.factory.ts +++ b/dashboard/src/components/api/che-workspace.factory.ts @@ -45,7 +45,7 @@ export class CheWorkspace { workspaces: Array; subscribedWorkspacesIds: Array; workspaceAgents: Map; - workspacesByNamespace: Map; + workspacesByNamespace: Map>; workspacesById: Map; remoteWorkspaceAPI: ICHELicenseResource; lodash: any; @@ -75,7 +75,7 @@ export class CheWorkspace { // per namespace this.workspacesByNamespace = new Map(); - //Workspace agents per workspace id: + // workspace agents per workspace id: this.workspaceAgents = new Map(); // listeners if workspaces are changed/updated @@ -177,7 +177,7 @@ export class CheWorkspace { }); } - getWorkspacesByNamespace(namespace) { + getWorkspacesByNamespace(namespace: string): Array { return this.workspacesByNamespace.get(namespace); } @@ -201,11 +201,6 @@ export class CheWorkspace { let updatedPromise = promise.then((data: Array) => { let remoteWorkspaces = []; this.workspaces.length = 0; - // todo It's a fix used not to loose account ID of the workspace. - // can be removed, when API will return accountId in the list of user workspaces response: - let copyWorkspaceById = new Map(); - angular.copy(this.workspacesById, copyWorkspaceById); - this.workspacesById.clear(); this.workspacesByNamespace.clear(); // add workspace if not temporary @@ -226,6 +221,11 @@ export class CheWorkspace { this.startUpdateWorkspaceStatus(workspace.id); }); return this.workspaces; + }, (error: any) => { + if (error.status === 304) { + return this.workspaces; + } + return this.$q.reject(error); }); let callbackPromises = updatedPromise.then((data: any) => { @@ -237,6 +237,8 @@ export class CheWorkspace { promises.push(promise); }); return this.$q.all(promises); + }, (error: any) => { + return this.$q.reject(error); }); return callbackPromises;