CHE-581 Code refactoring not applied on workspace import

Change-Id: I28e0b628e899bee96065a7850d69f7719999e991
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
6.19.x
Florent BENOIT 2016-02-29 17:56:04 +01:00
parent 2daf098293
commit c6c03be8bc
2 changed files with 16 additions and 4 deletions

View File

@ -52,6 +52,7 @@ export class CreateWorkspaceCtrl {
this.stack = null;
this.recipeUrl = null;
this.recipeScript = null;
this.importWorkspace = '';
}
/**
@ -114,6 +115,10 @@ export class CreateWorkspaceCtrl {
this.cheNotification.showError(error.data.message ? error.data.message : 'Error during recipe creation.');
});
}
} else if (this.selectSourceOption === 'select-source-import') {
let workspaceConfig = this.importWorkspace.length > 0 ? angular.fromJson(this.importWorkspace).config : {};
let creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromConfig(null, workspaceConfig);
this.redirectAfterSubmitWorkspace(creationPromise);
} else {
//check predefined recipe location
if (this.stack && this.stack.source && this.stack.source.type === 'location') {
@ -188,16 +193,23 @@ export class CreateWorkspaceCtrl {
*/
submitWorkspace() {
let attributes = this.stack ? {stackId: this.stack.id} : {};
let creationPromise = this.cheAPI.getWorkspace().createWorkspace(null, this.workspaceName, this.recipeUrl, this.workspaceRam, attributes);
creationPromise.then((workspaceData) => {
this.redirectAfterSubmitWorkspace(creationPromise);
}
/**
* Handle the redirect for the given promise after workspace has been created
* @param promise used to gather workspace data
*/
redirectAfterSubmitWorkspace(promise) {
promise.then((workspaceData) => {
let infoMessage = 'Workspace ' + workspaceData.name + ' successfully created.';
this.cheNotification.showInfo(infoMessage);
this.$location.path('/workspace/' + workspaceData.id);
}, (error) => {
let errorMessage = error.data.message ? error.data.message : 'Error during workspace creation.';
this.cheNotification.showError(errorMessage);
this.$location.path('/workspaces');
});
}

View File

@ -26,7 +26,7 @@
<che-panel che-title="Import workspace" ng-if="createWorkspaceCtrl.selectSourceOption === 'select-source-import'">
<ui-codemirror class="workspace-editor" ui-codemirror="createWorkspaceCtrl.editorOptions"
ng-model="createWorkspaceCtrl.workspaceConfig"></ui-codemirror>
ng-model="createWorkspaceCtrl.importWorkspace"></ui-codemirror>
</che-panel>
<che-workspace-select-stack ng-if="createWorkspaceCtrl.selectSourceOption === 'select-source-recipe'"