CHE-439: add stackId to workspace and respect it on project creation

Signed-off-by: Ann Shumilova <ashumilova@codenvy.com>
6.19.x
Ann Shumilova 2016-02-22 13:48:32 +02:00
parent 0235c85ab9
commit 07bfac1940
5 changed files with 33 additions and 14 deletions

View File

@ -21,8 +21,9 @@ export class CreateProjectCtrl {
* Default constructor that is using resource
* @ngInject for Dependency injection
*/
constructor(cheAPI, $websocket, $routeParams, $filter, $timeout, $location, $mdDialog, $scope, $rootScope, createProjectSvc, lodash, $q) {
constructor(cheAPI, cheStack, $websocket, $routeParams, $filter, $timeout, $location, $mdDialog, $scope, $rootScope, createProjectSvc, lodash, $q) {
this.cheAPI = cheAPI;
this.cheStack = cheStack;
this.$websocket = $websocket;
this.$timeout = $timeout;
this.$location = $location;
@ -681,26 +682,26 @@ export class CreateProjectCtrl {
// logic to decide if we create workspace based on a stack or reuse existing workspace
var option;
var stack;
this.stack = null;
if (this.stackTab === 'ready-to-go') {
option = 'create-workspace';
stack = this.readyToGoStack;
this.stack = this.readyToGoStack;
} else if (this.stackTab === 'stack-library') {
if (this.stackLibraryOption === 'existing-workspace') {
option = 'reuse-workspace';
} else {
stack = this.stackLibraryUser;
this.stack = this.stackLibraryUser;
option = 'create-workspace';
}
} else if (this.stackTab === 'custom-stack') {
stack = null;
this.stack = null;
option = 'create-workspace';
}
// check workspace is selected
if (option === 'create-workspace') {
if (stack) {
if (this.stack) {
// needs to get recipe URL from stack
let promise = this.computeRecipeForStack(stack);
let promise = this.computeRecipeForStack(this.stack);
promise.then((recipe) => {
let findLink = this.lodash.find(recipe.links, function (link) {
return link.rel === 'get recipe script';
@ -774,8 +775,10 @@ export class CreateProjectCtrl {
*/
createWorkspace() {
this.createProjectSvc.setWorkspaceOfProject(this.workspaceName);
let attributes = this.stack ? {stackId : this.stack.id} : {};
//TODO: no account in che ? it's null when testing on localhost
let creationPromise = this.cheAPI.getWorkspace().createWorkspace(null, this.workspaceName, this.recipeUrl, this.workspaceRam);
let creationPromise = this.cheAPI.getWorkspace().createWorkspace(null, this.workspaceName, this.recipeUrl, this.workspaceRam, attributes);
creationPromise.then((data) => {
// init message bus if not there
@ -961,8 +964,12 @@ export class CreateProjectCtrl {
this.workspaceSelected = workspace;
this.workspaceName = workspace.config.name;
this.stackLibraryOption = 'existing-workspace';
this.updateCurrentStack(null);
let stack = null;
if (workspace.attributes && workspace.attributes.stackId) {
let stackId = workspace.attributes.stackId;
stack = this.cheStack.getStackById(stackId);
}
this.updateCurrentStack(stack);
this.generateProjectName(true);
this.checkDisabledWorkspace();
}

View File

@ -95,6 +95,7 @@ export class CreateWorkspaceCtrl {
*/
createWorkspace() {
if (this.isCustomStack) {
this.stack = null;
if (this.recipeUrl && this.recipeUrl.length > 0) {
this.submitWorkspace();
} else {
@ -186,7 +187,9 @@ export class CreateWorkspaceCtrl {
* Submit a new workspace from current workspace name, recipe url and workspace ram
*/
submitWorkspace() {
let creationPromise = this.cheAPI.getWorkspace().createWorkspace(null, this.workspaceName, this.recipeUrl, this.workspaceRam);
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) => {
let infoMessage = 'Workspace ' + workspaceData.name + ' successfully created.';
this.cheNotification.showInfo(infoMessage);

View File

@ -9,6 +9,9 @@
<div class="chefont cheico-icon-wkps icon"></div>
<div>{{workspace.config.name}}</div>
</div>
<div class="che-stack-library-workspace-selecter-workspace-stack" layout="row" layout-align="start center" ng-if="workspace.attributes && workspace.attributes.stackId">
<div>Stack: {{workspace.attributes.stackId}}</div>
</div>
<div class="che-stack-library-workspace-selecter-text"
ng-if="workspace">{{getWorkspaceStackDetails()}}</div>
<div layout="row" layout-align="end end" flex>

View File

@ -52,6 +52,12 @@ $che-stack-library-workspace-selecter-color = $label-info-color
margin-top 4px
color $secondary-color
.che-stack-library-workspace-selecter-workspace-stack
font-size 0.8em
border-bottom 1px solid $form-element-border-color
color $label-primary-color
padding 5px 10px
.che-stack-library-workspace-selecter md-icon
font-size 60px
text-align center

View File

@ -154,14 +154,14 @@ export class CheWorkspace {
}
createWorkspace(accountId, workspaceName, recipeUrl, ram) {
createWorkspace(accountId, workspaceName, recipeUrl, ram, attributes) {
// /api/workspace/config?account=accountId
let attr = attributes ? attributes : {};
let data = {
'environments': [],
'name': workspaceName,
'attributes': {},
'attributes': attributes,
'projects': [],
'defaultEnv': workspaceName,
'description': null,