-
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.
- Loading branch information
1 parent
22baf6e
commit e0c361d
Showing
17 changed files
with
476 additions
and
90 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
114 changes: 114 additions & 0 deletions
114
...board/src/app/workspaces/workspace-details/devfile/workspace-devfile-editor.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,114 @@ | ||
/* | ||
* Copyright (c) 2015-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
'use strict'; | ||
/** | ||
* @ngdoc controller | ||
* @name workspaces.devfile-editor.controller:WorkspaceDevfileEditorController | ||
* @description This class is handling the controller for the workspace devfile editor widget | ||
* @author Anna Shumilova | ||
*/ | ||
export class WorkspaceDevfileEditorController { | ||
|
||
static $inject = ['$log', '$scope', '$timeout']; | ||
|
||
$log: ng.ILogService; | ||
$scope: ng.IScope; | ||
$timeout: ng.ITimeoutService; | ||
|
||
editorOptions: { | ||
lineWrapping: boolean, | ||
lineNumbers: boolean, | ||
matchBrackets: boolean, | ||
mode: string, | ||
onLoad: Function | ||
}; | ||
devfileValidationMessages: string[] = []; | ||
isActive: boolean; | ||
workspaceDevfile: any; | ||
devfileYaml: string; | ||
newWorkspaceDevfile: any; | ||
workspaceDevfileOnChange: Function; | ||
private saveTimeoutPromise: ng.IPromise<any>; | ||
private isSaving: boolean; | ||
|
||
|
||
/** | ||
* Default constructor that is using resource | ||
*/ | ||
constructor($log: ng.ILogService, $scope: ng.IScope, $timeout: ng.ITimeoutService) { | ||
this.$log = $log; | ||
this.$scope = $scope; | ||
this.$timeout = $timeout; | ||
this.isSaving = false; | ||
this.devfileYaml = jsyaml.dump(this.workspaceDevfile); | ||
|
||
$scope.$watch(() => { | ||
return this.workspaceDevfile; | ||
}, () => { | ||
let editedWorkspaceDevfile; | ||
try { | ||
editedWorkspaceDevfile = jsyaml.load(this.devfileYaml); | ||
angular.extend(editedWorkspaceDevfile, this.workspaceDevfile); | ||
} catch (e) { | ||
editedWorkspaceDevfile = this.workspaceDevfile; | ||
} | ||
this.devfileYaml = jsyaml.dump(this.workspaceDevfile); | ||
const validateOnly = true; | ||
this.onChange(validateOnly); | ||
}, true); | ||
|
||
} | ||
|
||
/** | ||
* Callback when editor content is changed. | ||
*/ | ||
onChange(validateOnly?: boolean): void { | ||
if (!this.devfileYaml) { | ||
this.devfileValidationMessages = ['The config is required.']; | ||
return; | ||
} | ||
|
||
try { | ||
let devfile = jsyaml.load(this.devfileYaml); | ||
|
||
if (validateOnly || !this.isActive) { | ||
return; | ||
} | ||
this.isSaving = (this.devfileValidationMessages.length === 0) && !angular.equals(devfile, this.workspaceDevfile); | ||
|
||
if (this.saveTimeoutPromise) { | ||
this.$timeout.cancel(this.saveTimeoutPromise); | ||
} | ||
|
||
this.saveTimeoutPromise = this.$timeout(() => { | ||
// immediately apply config on IU | ||
this.newWorkspaceDevfile = angular.copy(devfile); | ||
this.isSaving = false; | ||
this.applyChanges(); | ||
}, 2000); | ||
|
||
|
||
} catch (e) { | ||
if (this.devfileValidationMessages.length === 0) { | ||
this.devfileValidationMessages = ['Devfile is invalid.']; | ||
} | ||
this.$log.error(e); | ||
} | ||
} | ||
|
||
/** | ||
* Callback when user applies new config. | ||
*/ | ||
applyChanges(): void { | ||
this.workspaceDevfileOnChange({devfile: this.newWorkspaceDevfile}); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
dashboard/src/app/workspaces/workspace-details/devfile/workspace-devfile-editor.directive.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,44 @@ | ||
/* | ||
* Copyright (c) 2015-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
'use strict'; | ||
|
||
/** | ||
* Defines a directive for displaying devfile editor widget. | ||
* @author Anna Shumilova | ||
*/ | ||
export class WorkspaceDevfileEditor { | ||
restrict: string = 'E'; | ||
templateUrl: string = 'app/workspaces/workspace-details/devfile/workspace-devfile-editor.html'; | ||
replace: boolean = false; | ||
|
||
controller: string = 'WorkspaceDevfileEditorController'; | ||
controllerAs: string = 'workspaceDevfileEditorController'; | ||
|
||
bindToController: boolean = true; | ||
|
||
scope: { | ||
[paramName: string]: string; | ||
}; | ||
|
||
/** | ||
* Default constructor that is using resource | ||
*/ | ||
constructor() { | ||
// scope values | ||
this.scope = { | ||
isActive: '=', | ||
workspaceDevfile: '=', | ||
workspaceDevfileOnChange: '&' | ||
}; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
dashboard/src/app/workspaces/workspace-details/devfile/workspace-devfile-editor.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,38 @@ | ||
<div layout="column" class="config-import"> | ||
<div class="saving-message"> | ||
<span ng-if="workspaceDevfileEditorController.isSaving">Saving workspace devfile...</span> | ||
</div> | ||
<div class="config-editor"> | ||
<che-editor editor-content="workspaceDevfileEditorController.devfileYaml" | ||
editor-state="editorState" | ||
on-content-change="workspaceDevfileEditorController.onChange()" | ||
editor-mode="text/x-yaml" | ||
required> | ||
<div ng-message="required">A reference is required.</div> | ||
</che-editor> | ||
</div> | ||
<div layout="column"> | ||
<!-- Other errors --> | ||
<div ng-if="workspaceConfigImportController.devfileValidationMessages.length===0"> | ||
<!-- Settings tab errors --> | ||
<div | ||
ng-if="workspaceConfigImportController.otherValidationMessages[workspaceConfigImportController.errorsScopeSettings].length>0"> | ||
<div>Settings tab contains error(s):</div> | ||
<div class="error-message" | ||
ng-repeat="settingsValidationMessage in workspaceConfigImportController.otherValidationMessages[workspaceConfigImportController.errorsScopeSettings]"> | ||
{{settingsValidationMessage}} | ||
</div> | ||
</div> | ||
<!-- Runtime tab errors --> | ||
<div | ||
ng-if="workspaceConfigImportController.otherValidationMessages[workspaceConfigImportController.errorsScopeEnvironment].length>0"> | ||
<div>Runtime tab contains error(s):</div> | ||
<div class="error-message" | ||
ng-repeat="envValidationMessage in workspaceConfigImportController.otherValidationMessages[workspaceConfigImportController.errorsScopeEnvironment]"> | ||
{{envValidationMessage}} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
26 changes: 26 additions & 0 deletions
26
dashboard/src/app/workspaces/workspace-details/devfile/workspace-devfile-editor.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,26 @@ | ||
.config-import | ||
margin-left 10px | ||
|
||
.config-editor | ||
min-width 500px | ||
max-width 1000px | ||
margin-top 20px | ||
margin-right 8px | ||
|
||
.config-editor .CodeMirror | ||
border 1px solid $list-separator-color | ||
height 300px | ||
min-height 300px | ||
font-size 12px | ||
|
||
.config-docs-link | ||
margin-top 5px | ||
|
||
.error-message | ||
color $error-color | ||
|
||
.saving-message | ||
color $label-info-color | ||
height 18px | ||
top 12px | ||
position absolute |
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.