-
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: Anna Shumilova <ashumilo@redhat.com>
- Loading branch information
1 parent
6bc1d6e
commit be3a56c
Showing
29 changed files
with
703 additions
and
148 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
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
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
116 changes: 116 additions & 0 deletions
116
...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,116 @@ | ||
/* | ||
* 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: che.IWorkspaceDevfile; | ||
devfileYaml: string; | ||
newWorkspaceDevfile: che.IWorkspaceDevfile; | ||
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 { | ||
this.devfileValidationMessages = []; | ||
if (!this.devfileYaml) { | ||
return; | ||
} | ||
|
||
let devfile; | ||
try { | ||
devfile = jsyaml.load(this.devfileYaml); | ||
} catch (e) { | ||
if (e.name === 'YAMLException') { | ||
this.devfileValidationMessages = [e.message]; | ||
} | ||
if (this.devfileValidationMessages.length === 0) { | ||
this.devfileValidationMessages = ['Devfile is invalid.']; | ||
} | ||
this.$log.error(e); | ||
} | ||
|
||
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); | ||
} | ||
|
||
/** | ||
* 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: '&' | ||
}; | ||
} | ||
|
||
} |
Oops, something went wrong.