-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2465 from eclipse/CHE-2206
CHE-2206: add stacks list, edit and creation
- Loading branch information
Showing
23 changed files
with
1,283 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
261 changes: 261 additions & 0 deletions
261
dashboard/src/app/stacks/list-stacks/list-stacks.controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,261 @@ | ||
/* | ||
* Copyright (c) 2015-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc controller | ||
* @name stacks.list.controller:ListStacksCtrl | ||
* @description This class is handling the controller for listing the stacks | ||
* @author Ann Shumilova | ||
*/ | ||
export class ListStacksController { | ||
|
||
/** | ||
* Default constructor that is using resource | ||
* @ngInject for Dependency injection | ||
*/ | ||
constructor(cheStack, $log, $mdDialog, cheNotification, $rootScope, lodash, $q) { | ||
this.cheStack = cheStack; | ||
this.$log = $log; | ||
this.$mdDialog = $mdDialog; | ||
this.cheNotification = cheNotification; | ||
this.lodash = lodash; | ||
this.$q = $q; | ||
|
||
$rootScope.showIDE = false; | ||
|
||
this.stackFilter = {name: ''}; | ||
this.stackOrderBy = 'stack.name'; | ||
|
||
this.stackSelectionState = {}; | ||
this.isAllSelected = false; | ||
this.isNoSelected = true; | ||
|
||
this.stacks = []; | ||
this.getStacks(); | ||
} | ||
|
||
/** | ||
* Gets the list of stacks. | ||
*/ | ||
getStacks() { | ||
this.loading = true; | ||
this.updateSelectionState(); | ||
|
||
let promise = this.cheStack.fetchStacks(); | ||
promise.then(() => { | ||
this.loading = false | ||
this.stacks = this.cheStack.getStacks(); | ||
}, | ||
(error) => { | ||
if (error.status === 304) { | ||
this.stacks = this.cheStack.getStacks(); | ||
} | ||
this.state = 'error'; | ||
this.loading = false; | ||
}); | ||
} | ||
|
||
/** | ||
* Performs confirmation and deletion of pointed stack. | ||
* | ||
* @param stack stack to delete | ||
*/ | ||
deleteStack(stack) { | ||
let confirmationPromise = this.confirmStacksDeletion(1, stack.name); | ||
confirmationPromise.then(() => { | ||
this.loading = true; | ||
this.cheStack.deleteStack(stack.id).then(() => { | ||
delete this.stackSelectionState[stack.id]; | ||
this.cheNotification.showInfo('Stack ' + stack.name + ' has been successfully removed.'); | ||
this.getStacks(); | ||
}, (error) => { | ||
this.loading = false; | ||
let message = 'Failed to delete ' + stack.name + 'stack.' + (error && error.message) ? error.message : ""; | ||
this.cheNotification.showError(message); | ||
}); | ||
}); | ||
|
||
} | ||
|
||
/** | ||
* Make a copy of pointed stack with new name. | ||
* | ||
* @param stack stack to make copy of | ||
*/ | ||
duplicateStack(stack) { | ||
let newStack = angular.copy(stack); | ||
delete newStack.links; | ||
delete newStack.creator; | ||
delete newStack.id; | ||
newStack.name = this.generateStackName(stack.name + ' - Copy'); | ||
this.loading = true; | ||
this.cheStack.createStack(newStack).then(() => { | ||
this.getStacks(); | ||
}, (error) => { | ||
this.loading = false; | ||
let message = 'Failed to create ' + newStack.name + 'stack.' + (error && error.message) ? error.message : ""; | ||
this.cheNotification.showError(message); | ||
}); | ||
} | ||
|
||
/** | ||
* Generate new stack name - based on the provided one and existing. | ||
* | ||
* @param name | ||
* @returns {*} | ||
*/ | ||
generateStackName(name) { | ||
if (this.stacks.size === 0) { | ||
return name; | ||
} | ||
let existingNames = this.lodash.pluck(this.stacks, 'name'); | ||
|
||
if (existingNames.indexOf(name) < 0) { | ||
return name; | ||
} | ||
|
||
let generatedName = name; | ||
let counter = 1; | ||
while (existingNames.indexOf(generatedName) >= 0) { | ||
generatedName = name + counter++; | ||
} | ||
return generatedName; | ||
} | ||
|
||
/** | ||
* Returns whether all stacks are selected. | ||
* | ||
* @returns {*} <code>true</code> if all stacks are selected | ||
*/ | ||
isAllStacksSelected() { | ||
return this.isAllSelected; | ||
} | ||
|
||
/** | ||
* Returns whether there are no selected stacks. | ||
* | ||
* @returns {*} <code>true</code> if no stacks are selected | ||
*/ | ||
isNoStacksSelected() { | ||
return this.isNoSelected; | ||
} | ||
|
||
/** | ||
* Make all stacks selected. | ||
*/ | ||
selectAllStacks() { | ||
this.stacks.forEach((stack) => { | ||
this.stackSelectionState[stack.id] = true; | ||
}); | ||
} | ||
|
||
/** | ||
* Make all stacks deselected. | ||
*/ | ||
deselectAllStacks() { | ||
this.stacks.forEach((stack) => { | ||
this.stackSelectionState[stack.id] = false; | ||
}); | ||
} | ||
|
||
/** | ||
* Change the state of the stacks selection, | ||
*/ | ||
changeSelectionState() { | ||
if (this.isAllSelected) { | ||
this.deselectAllStacks(); | ||
} else { | ||
this.selectAllStacks(); | ||
} | ||
this.updateSelectionState(); | ||
} | ||
|
||
/** | ||
* Update stack selection state. | ||
*/ | ||
updateSelectionState() { | ||
this.isNoSelected = true; | ||
this.isAllSelected = true; | ||
|
||
Object.keys(this.stackSelectionState).forEach((key) => { | ||
if (this.stackSelectionState[key]) { | ||
this.isNoSelected = false; | ||
} else { | ||
this.isAllSelected = false; | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* Delete all selected stacks. | ||
*/ | ||
deleteSelectedStacks() { | ||
let selectedStackIds = []; | ||
|
||
|
||
Object.keys(this.stackSelectionState).forEach((key) => { | ||
if (this.stackSelectionState[key]) { | ||
selectedStackIds.push(key); | ||
} | ||
}); | ||
|
||
if (!selectedStackIds.length) { | ||
this.cheNotification.showError('No selected stacks.'); | ||
return; | ||
} | ||
|
||
let confirmationPromise = this.confirmStacksDeletion(selectedStackIds.length); | ||
confirmationPromise.then(() => { | ||
let deleteStackPromises = []; | ||
|
||
selectedStackIds.forEach((stackId) => { | ||
this.stackSelectionState[stackId] = false; | ||
deleteStackPromises.push(this.cheStack.deleteStack(stackId)); | ||
}); | ||
|
||
this.$q.all(deleteStackPromises).then(() => { | ||
this.cheNotification.showInfo('Selected stacks have been successfully removed.'); | ||
}) | ||
.catch(() => { | ||
this.cheNotification.showError('Failed to delete selected stack(s).'); | ||
}) | ||
.finally(() => { | ||
this.getStacks(); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Show confirm dialog for stacks deletion. | ||
* | ||
* @param numberToDelete number of stacks to be deleted | ||
* @param stackName name of stack to confirm (can be null) | ||
* @returns {*} | ||
*/ | ||
confirmStacksDeletion(numberToDelete, stackName) { | ||
let confirmTitle = 'Would you like to delete '; | ||
if (numberToDelete > 1) { | ||
confirmTitle += 'these ' + numberToDelete + ' stacks?'; | ||
} else { | ||
confirmTitle += stackName ? stackName + '?' : 'this selected stack?'; | ||
} | ||
let confirm = this.$mdDialog.confirm() | ||
.title(confirmTitle) | ||
.ariaLabel('Remove stacks') | ||
.ok('Delete!') | ||
.cancel('Cancel') | ||
.clickOutsideToClose(true); | ||
|
||
return this.$mdDialog.show(confirm); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<!-- | ||
Copyright (c) 2015 Codenvy, S.A. | ||
All rights reserved. This program and the accompanying materials | ||
are made available under the terms of the Eclipse Public License v1.0 | ||
which accompanies this distribution, and is available at | ||
http://www.eclipse.org/legal/epl-v10.html | ||
Contributors: | ||
Codenvy, S.A. - initial API and implementation | ||
--> | ||
<che-toolbar che-title="Stacks" border-none></che-toolbar> | ||
<che-description che-link-title="Learn more." che-link="https://eclipse-che.readme.io/docs/stack"> | ||
A stack is environment configuration for workspace defined by its runtime recipe. Create workspaces from stacks that define projects, runtimes | ||
and commands. | ||
</che-description> | ||
<md-content md-scroll-y flex layout="column" md-theme="maincontent-theme"> | ||
<md-progress-linear md-mode="indeterminate" class="stacks-list-progress" | ||
ng-show="listStacksController.isLoading"></md-progress-linear> | ||
<md-content flex class="stacks-list-content" ng-hide="listStacksController.isLoading"> | ||
<che-list-header che-input-placeholder="Search" | ||
che-search-model="listStacksController.stackFilter.name" | ||
che-hide-search="listStacksController.stacks.length === 0" | ||
che-add-button-title="Add Stack" | ||
che-add-button-href="#stack/create" | ||
che-delete-button-title="Delete" | ||
che-on-delete="listStacksController.deleteSelectedStacks()" | ||
che-hide-delete="listStacksController.isNoSelected" | ||
che-hide-header="(listStacksController.stacks | filter:listStacksController.stackFilter).length === 0"> | ||
<div flex="100" | ||
layout="row" | ||
layout-align="start stretch" | ||
class="che-list-item-row"> | ||
<div layout="column" layout-gt-xs="row" | ||
layout-align="start center" | ||
class="che-checkbox-area"> | ||
<div layout="row" layout-align="center center" class="che-list-item-checkbox-main"> | ||
<md-checkbox class="che-list-item-checkbox" | ||
aria-label="Stack list" | ||
ng-checked="listStacksController.isAllChecked" | ||
ng-click="listStacksController.changeSelectionState()"></md-checkbox> | ||
</div> | ||
</div> | ||
<div flex hide-xs layout-gt-xs="row" | ||
layout-align="start center" | ||
class="che-list-item-details"> | ||
<che-list-header-column flex-gt-xs="20" | ||
che-sort-value='listStacksController.stackOrderBy' | ||
che-sort-item='name' | ||
che-column-title='Name'></che-list-header-column> | ||
<che-list-header-column flex-gt-xs="35" | ||
che-column-title='Description'></che-list-header-column> | ||
<che-list-header-column flex-gt-xs="30" | ||
che-column-title='Components'></che-list-header-column> | ||
<che-list-header-column flex-gt-xs="18" | ||
che-column-title='Actions'></che-list-header-column> | ||
</div> | ||
</div> | ||
</che-list-header> | ||
<che-list ng-show="(listStacksController.stacks | filter:listStacksController.stackFilter).length > 0" class="stack-list"> | ||
<stack-item | ||
ng-repeat="stack in listStacksController.stacks | orderBy:[listStacksController.stackOrderBy, 'name'] | filter:listStacksController.stackFilter" | ||
ng-model="listStacksController.stackSelectionState[stack.id]" | ||
che-selectable="true" | ||
che-on-checkbox-click="listStacksController.updateSelectionState()" | ||
che-on-delete="listStacksController.deleteStack(stack)" | ||
che-on-duplicate="listStacksController.duplicateStack(stack)" | ||
che-stack="stack"></stack-item> | ||
</che-list> | ||
<div class="che-list-empty"> | ||
<span ng-show="listStacksController.stacks.length > 0 && (listStacksController.stacks | filter:listStacksController.stackFilter).length === 0"> | ||
No stacks found. | ||
</span> | ||
<span ng-show="listStacksController.stacks.length === 0">There are no stacks yet</span> | ||
</div> | ||
</md-content> | ||
</md-content> | ||
|
Oops, something went wrong.