-
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.
Signed-off-by: Oleksii Orel <oorel@codenvy.com>
- Loading branch information
Oleksii Orel
committed
Dec 27, 2016
1 parent
9a0c537
commit a6f8443
Showing
14 changed files
with
657 additions
and
34 deletions.
There are no files selected for viewing
127 changes: 127 additions & 0 deletions
127
dashboard/src/app/stacks/list-stacks/import-stack/import-stack.controller.ts
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,127 @@ | ||
/* | ||
* 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'; | ||
import {CheEnvironmentRegistry} from '../../../../components/api/environment/che-environment-registry.factory'; | ||
import {ImportStackService} from '../../stack-details/import-stack.service'; | ||
import {CheStack} from '../../../../components/api/che-stack.factory'; | ||
import {StackValidationService} from '../../stack-details/stack-validation.service'; | ||
|
||
|
||
/** | ||
* @ngdoc controller | ||
* @name stacks.list-stacks.import-stack.controller:ImportStackController | ||
* @description This class is handling the controller for a dialog box with different types of recipe for target stack. | ||
* @author Oleksii Orel | ||
*/ | ||
export class ImportStackController { | ||
private $mdDialog: ng.material.IDialogService; | ||
private $location: ng.ILocationService; | ||
private cheStack: CheStack; | ||
private importStackService: ImportStackService; | ||
private stackValidationService: StackValidationService; | ||
private cheEnvironmentRegistry: CheEnvironmentRegistry; | ||
private recipeScript: string; | ||
private recipeFormat: string; | ||
private COMPOSE: string = 'compose'; | ||
private DOCKERFILE: string = 'dockerfile'; | ||
private environmentValidation: che.IValidation; | ||
private editorOptions: che.IEditorOptions = { | ||
lineNumbers: true, | ||
lineWrapping: true, | ||
matchBrackets: true, | ||
mode: 'text/x-dockerfile' | ||
}; | ||
|
||
/** | ||
* Default constructor that is using resource | ||
* @ngInject for Dependency injection | ||
*/ | ||
constructor($mdDialog: ng.material.IDialogService, $location: ng.ILocationService, stackValidationService: StackValidationService, cheStack: CheStack, importStackService: ImportStackService, cheEnvironmentRegistry: CheEnvironmentRegistry) { | ||
this.$mdDialog = $mdDialog; | ||
this.$location = $location; | ||
this.cheStack = cheStack; | ||
this.importStackService = importStackService; | ||
this.stackValidationService = stackValidationService; | ||
this.cheEnvironmentRegistry = cheEnvironmentRegistry; | ||
|
||
// set default values | ||
this.environmentValidation = {isValid: false, errors: []}; | ||
this.recipeFormat = this.DOCKERFILE; | ||
this.updateType(); | ||
} | ||
|
||
/** | ||
* It will hide the dialog box. | ||
*/ | ||
cancel(): void { | ||
this.importStackService.setStack({}); | ||
this.$mdDialog.cancel(); | ||
} | ||
|
||
/** | ||
* It will hide the dialog box and redirect to '/stack/import'. | ||
*/ | ||
onImport(): void { | ||
this.$mdDialog.hide(); | ||
this.$location.path('/stack/import'); | ||
} | ||
|
||
/** | ||
* Update editor options for needed recipe type. | ||
*/ | ||
updateType(): void { | ||
if (this.DOCKERFILE === this.recipeFormat) { | ||
this.editorOptions.mode = 'text/x-dockerfile'; | ||
} else if (this.COMPOSE === this.recipeFormat) { | ||
this.editorOptions.mode = 'text/x-yaml'; | ||
} | ||
this.recipeScript = ''; | ||
this.updateImportedStack(); | ||
} | ||
|
||
/** | ||
* Update imported stack if it is valid. | ||
*/ | ||
updateImportedStack(): void { | ||
let stack = angular.copy(this.cheStack.getStackTemplate()); | ||
let environments: che.IWorkspaceEnvironments = stack.workspaceConfig.environments; | ||
let defaultEnv: che.IWorkspaceEnvironment = angular.copy(environments[stack.workspaceConfig.defaultEnv]); | ||
let recipe: che.IRecipe = {content: this.recipeScript, type: this.recipeFormat}; | ||
|
||
if (this.COMPOSE === this.recipeFormat) { | ||
recipe.contentType = 'application/x-yaml'; | ||
} | ||
defaultEnv.recipe = recipe; | ||
let environmentManager = this.cheEnvironmentRegistry.getEnvironmentManager(defaultEnv.recipe.type); | ||
// add ws-agent to default dev-machine for dockerfile recipe format | ||
defaultEnv.machines = this.DOCKERFILE === this.recipeFormat ? { | ||
'dev-machine': { | ||
'agents': [], | ||
'attributes': { | ||
'memoryLimitBytes': 2147483648 | ||
} | ||
} | ||
} : {}; | ||
let machines = environmentManager.getMachines(defaultEnv); | ||
// add ws-agent to a machine if it one | ||
if (machines.length === 1) { | ||
environmentManager.setDev(machines[0], true); | ||
} | ||
let environment = environmentManager.getEnvironment(defaultEnv, machines); | ||
// check environment correctness | ||
this.environmentValidation = this.stackValidationService.getEnvironmentValidation(environment); | ||
if (!this.environmentValidation.isValid) { | ||
return; | ||
} | ||
environments[stack.workspaceConfig.defaultEnv] = environment; | ||
this.importStackService.setStack(stack); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
dashboard/src/app/stacks/list-stacks/import-stack/import-stack.html
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,41 @@ | ||
<!-- | ||
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-popup title="Import stack" on-close="importStackController.cancel()"> | ||
<div class="import-stack"> | ||
<span class="header-label">Select type of stack's recipe and match them:</span> | ||
<div class="toggle-button-area"> | ||
<che-toggle ng-model="importStackController.recipeFormat" ng-change="importStackController.updateType()" | ||
md-theme="default"> | ||
<che-toggle-button che-title="Dockerfile" che-value="{{importStackController.DOCKERFILE}}"></che-toggle-button> | ||
<che-toggle-button che-title="Composefile" | ||
che-value="{{importStackController.COMPOSE}}"></che-toggle-button> | ||
</che-toggle> | ||
</div> | ||
<ui-codemirror ng-model-options="{ updateOn: 'default blur', debounce: { 'default': 1000, 'blur': 0 } }" | ||
ui-codemirror="importStackController.editorOptions" | ||
ng-model="importStackController.recipeScript" | ||
ng-change="importStackController.updateImportedStack()"></ui-codemirror> | ||
<div class="errors-container"> | ||
<span ng-repeat="error in importStackController.environmentValidation.errors | orderBy:'':'reverse'"> | ||
{{error}} | ||
</span> | ||
</div> | ||
<che-button-notice che-button-title="Cancel" | ||
ng-click="importStackController.cancel()"> | ||
</che-button-notice> | ||
<che-button-primary che-button-title="Ok" | ||
ng-disabled="!importStackController.environmentValidation.isValid" | ||
ng-click="importStackController.onImport()"> | ||
</che-button-primary> | ||
</div> | ||
</che-popup> |
71 changes: 71 additions & 0 deletions
71
dashboard/src/app/stacks/list-stacks/import-stack/import-stack.styl
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,71 @@ | ||
.import-stack | ||
min-width 800px | ||
user-select none | ||
|
||
ui-codemirror | ||
display block | ||
float none | ||
width 800px | ||
max-width 800px | ||
margin-top 15px | ||
margin-bottom 2px | ||
|
||
.CodeMirror | ||
max-height 200px | ||
width inherit | ||
|
||
.CodeMirror-sizer | ||
margin-left 26px | ||
|
||
.CodeMirror-gutter-wrapper | ||
left 0 !important | ||
|
||
.CodeMirror-gutter-elt, | ||
.CodeMirror-linenumber | ||
margin-left -55px | ||
|
||
.CodeMirror-scroll | ||
margin-left -20px | ||
|
||
div.CodeMirror | ||
border 1px solid $list-separator-color | ||
height 250px !important | ||
min-height 250px !important | ||
|
||
.errors-container | ||
color $error-color | ||
min-height 20px | ||
margin-right 2px | ||
|
||
span | ||
margin-right 2px | ||
|
||
.header-label | ||
line-height 30px | ||
|
||
.toggle-button-area | ||
position relative | ||
margin-left 0 | ||
|
||
button | ||
margin-left 0 | ||
margin-bottom 0 | ||
|
||
md-switch | ||
height 100% | ||
margin auto | ||
overflow visible | ||
|
||
.footer-label | ||
display inline-block | ||
line-height 30px | ||
margin-top 10px | ||
float right | ||
|
||
.import-stack che-button-primary, | ||
.import-stack che-button-notice | ||
float right | ||
|
||
button | ||
margin-right 0 | ||
margin-bottom 0 |
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
Oops, something went wrong.