Skip to content

Commit

Permalink
CHE-439: add stackId to workspace and respect it on project creation
Browse files Browse the repository at this point in the history
Signed-off-by: Ann Shumilova <ashumilova@codenvy.com>
  • Loading branch information
ashumilova committed Feb 22, 2016
1 parent 0235c85 commit 07bfac1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
27 changes: 17 additions & 10 deletions dashboard/src/app/projects/create-project/create-project.controller.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ export class CreateWorkspaceCtrl {
*/
createWorkspace() {
if (this.isCustomStack) {
this.stack = null;
if (this.recipeUrl && this.recipeUrl.length > 0) {
this.submitWorkspace();
} else {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/components/api/che-workspace.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 07bfac1

Please sign in to comment.