From 6d06d10273c58d381c7aebda2f5f4c751e6643f2 Mon Sep 17 00:00:00 2001 From: Anna Shumilova Date: Wed, 1 Nov 2017 16:05:04 +0200 Subject: [PATCH] che-7047: fix adding commands to workspace config Signed-off-by: Anna Shumilova --- .../create-workspace.controller.ts | 3 +- .../create-workspace.service.ts | 46 +++++-------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts b/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts index a5b5e66f77..0ba39d728e 100644 --- a/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts +++ b/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts @@ -286,7 +286,8 @@ export class CreateWorkspaceController { this.stack.workspaceConfig.environments[environmentName] = newEnvironment; } let attributes = {stackId: this.stack.id}; - this.createWorkspaceSvc.createWorkspace(this.stack.workspaceConfig, attributes); + let workspaceConfig = angular.copy(this.stack.workspaceConfig); + this.createWorkspaceSvc.createWorkspace(workspaceConfig, attributes); } } diff --git a/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts b/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts index 2662ab8717..886550bb14 100644 --- a/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts +++ b/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts @@ -162,9 +162,10 @@ export class CreateWorkspaceSvc { createWorkspace(workspaceConfig: che.IWorkspaceConfig, attributes?: any): ng.IPromise { const namespaceId = this.namespaceSelectorSvc.getNamespaceId(), projectTemplates = this.projectSourceSelectorService.getProjectTemplates(); - workspaceConfig.projects = projectTemplates; + return this.checkEditingProgress().then(() => { workspaceConfig.projects = projectTemplates; + this.addProjectCommands(workspaceConfig, projectTemplates); return this.cheWorkspace.createWorkspaceFromConfig(namespaceId, workspaceConfig, attributes).then((workspace: che.IWorkspace) => { return this.cheWorkspace.startWorkspace(workspace.id, workspace.config.defaultEnv).then(() => { @@ -176,8 +177,6 @@ export class CreateWorkspaceSvc { return this.cheWorkspace.fetchStatusChange(workspace.id, 'RUNNING'); }).then(() => { return this.cheWorkspace.fetchWorkspaceDetails(workspace.id); - }).then(() => { - return this.addProjectCommands(workspace.id, projectTemplates); }); }, (error: any) => { let errorMessage = 'Creation workspace failed.'; @@ -236,43 +235,20 @@ export class CreateWorkspaceSvc { } /** - * Adds commands from the bunch of projects in row. - * Returns resolved promise if all commands are aded properly, otherwise returns rejected promise with list of names of failed projects. + * Adds commands from the bunch of project templates to provided workspace config. * - * @param {string} workspaceId the workspace ID + * @param {che.IWorkspaceConfig} workspaceConfig workspace config * @param {Array} projectTemplates the list of project templates - * @return {IPromise} */ - addProjectCommands(workspaceId: string, projectTemplates: Array): ng.IPromise { - const defer = this.$q.defer(); - defer.resolve(); - let accumulatorPromise = defer.promise; + addProjectCommands(workspaceConfig: che.IWorkspaceConfig, projectTemplates: Array): void { + workspaceConfig.commands = workspaceConfig.commands || []; - const failedProjects = []; - - accumulatorPromise = projectTemplates.reduce((_accumulatorPromise: ng.IPromise, project: che.IProjectTemplate) => { - return _accumulatorPromise.then(() => { - return this.addCommands(workspaceId, project.name, project.commands).catch(() => { - // adding commands errors, ignore them here - return this.$q.when(); - }).catch((error: any) => { - failedProjects.push(project.name); - if (error && error.message) { - this.$log.error(`Importing of project ${project.name} failed with error: ${error.message}`); - } - }); + projectTemplates.forEach((template: che.IProjectTemplate) => { + let projectName = template.name; + template.commands.forEach((command: any) => { + command.name = projectName + ':' + command.name; + workspaceConfig.commands.push(command); }); - }, accumulatorPromise); - - return accumulatorPromise.then(() => { - const IDE = this.getIDE(); - if (IDE && IDE.CommandManager && angular.isFunction(IDE.CommandManager.refresh)) { - IDE.CommandManager.refresh(); - } - if (failedProjects.length) { - return this.$q.reject(failedProjects); - } - return this.$q.when(); }); }