che-7047: fix adding commands to workspace config
Signed-off-by: Anna Shumilova <ashumilo@redhat.com>6.19.x
parent
5fa11d820e
commit
6d06d10273
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,9 +162,10 @@ export class CreateWorkspaceSvc {
|
|||
createWorkspace(workspaceConfig: che.IWorkspaceConfig, attributes?: any): ng.IPromise<any> {
|
||||
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<che.IProjectTemplate>} projectTemplates the list of project templates
|
||||
* @return {IPromise<any>}
|
||||
*/
|
||||
addProjectCommands(workspaceId: string, projectTemplates: Array<che.IProjectTemplate>): ng.IPromise<any> {
|
||||
const defer = this.$q.defer();
|
||||
defer.resolve();
|
||||
let accumulatorPromise = defer.promise;
|
||||
addProjectCommands(workspaceConfig: che.IWorkspaceConfig, projectTemplates: Array<che.IProjectTemplate>): void {
|
||||
workspaceConfig.commands = workspaceConfig.commands || [];
|
||||
|
||||
const failedProjects = [];
|
||||
|
||||
accumulatorPromise = projectTemplates.reduce((_accumulatorPromise: ng.IPromise<any>, 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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue