From 6503951dd8e47736f35c54a03ed848c74539fcc4 Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Wed, 4 Jan 2017 13:04:14 +0200 Subject: [PATCH 1/3] CHE-3209 add import and configure batch of projects on stack testing Signed-off-by: Oleksii Orel --- .../select-template.controller.ts | 11 +- .../stacks/stack-details/stack.controller.ts | 138 ++++++++++++++++-- .../workspace-details.controller.ts | 8 +- .../components/api/che-workspace.factory.ts | 12 +- dashboard/src/components/typings/che.d.ts | 15 +- 5 files changed, 156 insertions(+), 28 deletions(-) diff --git a/dashboard/src/app/stacks/stack-details/select-template/select-template.controller.ts b/dashboard/src/app/stacks/stack-details/select-template/select-template.controller.ts index 90d8fc67f6c..2022ec86135 100644 --- a/dashboard/src/app/stacks/stack-details/select-template/select-template.controller.ts +++ b/dashboard/src/app/stacks/stack-details/select-template/select-template.controller.ts @@ -52,8 +52,8 @@ export class SelectTemplateController { /** * Helper method used to get the length of keys of the given object - * @param projectTemplate: che.IProject - * @param isAdd: boolean + * @param projectTemplate {che.IProject} + * @param isAdd {boolean} */ updateSelectedTemplates(projectTemplate: che.IProject, isAdd: boolean): void { if (isAdd) { @@ -71,15 +71,16 @@ export class SelectTemplateController { */ startTest(): void { let stack: che.IStack = angular.copy(this.stack); + /* tslint:disable */ stack.workspaceConfig.name = 'test-wksp-' + (('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4)); - stack.workspaceConfig.projects = this.selectedTemplates; - this.callbackController.showStackTestPopup(stack); + /* tslint:enable */ + this.callbackController.showStackTestPopup(stack, this.selectedTemplates); this.hide(); } /** * Helper method used to get the length of keys of the given object - * @param items: Array + * @param items {Array} * @returns {number} - length of keys */ getItemsSize(items: Array): number { diff --git a/dashboard/src/app/stacks/stack-details/stack.controller.ts b/dashboard/src/app/stacks/stack-details/stack.controller.ts index 435253c21a4..0f3a31c3ad5 100644 --- a/dashboard/src/app/stacks/stack-details/stack.controller.ts +++ b/dashboard/src/app/stacks/stack-details/stack.controller.ts @@ -26,6 +26,7 @@ const STACK_TEST_POPUP_ID: string = 'stackTestPopup'; export class StackController { GENERAL_SCOPE: string = 'general'; ADVANCED_SCOPE: string = 'advanced'; + $q: ng.IQService; $log: ng.ILogService; $route: ng.route.IRoute; $scope: ng.IScope; @@ -60,13 +61,14 @@ export class StackController { * Default constructor that is using resource injection * @ngInject for Dependency injection */ - constructor($route: ng.route.IRoute, $location: ng.ILocationService, $log: ng.ILogService, $filter: ng.IFilterService, cheStack: CheStack, cheWorkspace: CheWorkspace, $mdDialog: ng.material.IDialogService, cheNotification: CheNotification, $timeout: ng.ITimeoutService, $document: ng.IDocumentService, cheUIElementsInjectorService: CheUIElementsInjectorService, $scope: ng.IScope, $window: ng.IWindowService, importStackService: ImportStackService) { + constructor($q: ng.IQService, $timeout: ng.ITimeoutService, $route: ng.route.IRoute, $location: ng.ILocationService, $log: ng.ILogService, $filter: ng.IFilterService, cheStack: CheStack, cheWorkspace: CheWorkspace, $mdDialog: ng.material.IDialogService, cheNotification: CheNotification, $document: ng.IDocumentService, cheUIElementsInjectorService: CheUIElementsInjectorService, $scope: ng.IScope, $window: ng.IWindowService, importStackService: ImportStackService) { + this.$q = $q; + this.$timeout = $timeout; this.$location = $location; this.$log = $log; this.$route = $route; this.$scope = $scope; this.$filter = $filter; - this.$timeout = $timeout; this.cheStack = cheStack; this.cheWorkspace = cheWorkspace; this.$mdDialog = $mdDialog; @@ -118,8 +120,9 @@ export class StackController { } $window.addEventListener('message', (event: {data: string}) => { - if ('show-ide' === event.data) { + if (!this.showIDE && 'show-ide' === event.data) { this.showIDE = true; + this.$scope.$digest(); } }, false); } @@ -129,8 +132,6 @@ export class StackController { */ updateData(): void { if (this.isCreation) { - this.copyStack = {}; - this.isStackChange = true; this.stack = this.getNewStackTemplate(); this.stackTags = angular.copy(this.stack.tags); this.stackName = angular.copy(this.stack.name); @@ -367,15 +368,128 @@ export class StackController { }); } + /** + * Add commands sequentially by iterating on the number of the commands. + * @param workspaceId{string} - the ID of the workspace to use for adding commands + * @param projectName{string} - the name that will be used to prefix the commands inserted + * @param commands{Array} - the array to follow + * @param index{number} - the index of the array of commands + * @param deferred{ng.IDeferred} + */ + addCommands(workspaceId: string, projectName: string, commands: Array, index: number, deferred: ng.IDeferred): void { + if (index < commands.length) { + let newCommand = angular.copy(commands[index]); + newCommand.name = projectName + ': ' + newCommand.name; + let addPromise = this.cheWorkspace.addCommand(workspaceId, newCommand); + addPromise.then(() => { + // call the method again + this.addCommands(workspaceId, projectName, commands, ++index, deferred); + }, (error: any) => { + deferred.reject(error); + }); + } else { + deferred.resolve(); + } + } + + /** + * Update projects sequentially by iterating on the number of the projects. + * @param workspaceId{string} - the ID of the workspace to use for adding commands + * @param projects{Array} - the array to follow + * @param index{number} - the index of the array of commands + * @param deferred{ng.IDeferred} + */ + updateProjects(workspaceId: string, projects: Array, index: number, deferred: ng.IDeferred): void { + if (index < projects.length) { + let project = angular.copy(projects[index]); + let projectService = this.cheWorkspace.getWorkspaceAgent(workspaceId).getProject(); + projectService.updateProject(project.name, project).then(() => { + let resolvePromise = projectService.fetchResolve(project.name); + resolvePromise.then(() => { + this.updateProjects(workspaceId, projects, ++index, deferred); + }, (error: any) => { + deferred.reject(error); + }); + if (project.commands && project.commands.length > 0) { + let deferredAddCommand = this.$q.defer(); + this.addCommands(workspaceId, project.name, project.commands, 0, deferredAddCommand); + deferredAddCommand.promise.then(() => { + this.updateProjects(workspaceId, projects, ++index, deferred); + }, (error: any) => { + deferred.reject(error); + }); + } else { + this.updateProjects(workspaceId, projects, ++index, deferred); + } + }, (error: any) => { + deferred.reject(error); + }); + } else { + deferred.resolve(); + } + } + + /** + * Add projects. + * @param workspaceId{string} - the ID of the workspace to use for adding projects + * @param projects{Array} - the adding projects + * + * @returns {ng.IPromise} + */ + addProjects(workspaceId: string, projects: Array): ng.IPromise { + let deferred = this.$q.defer(); + if (projects && projects.length) { + this.cheWorkspace.getWorkspaceAgent(workspaceId).getProject().createProjects(projects).then(() => { + this.updateProjects(workspaceId, projects, 0, deferred); + }, (error: any) => { + deferred.reject(error); + }); + } else { + deferred.resolve(); + } + + return deferred.promise; + } + /** * Show popup for stack's testing * @param stack {che.IStack} + * @param projects {Array} */ - showStackTestPopup(stack: che.IStack): void { + showStackTestPopup(stack: che.IStack, projects: Array): void { this.showIDE = false; - this.cheWorkspace.startTemporaryWorkspace(stack.workspaceConfig).then((workspace: any) => { + stack.workspaceConfig.projects = []; + let deferred = this.$q.defer(); + this.cheWorkspace.startTemporaryWorkspace(stack.workspaceConfig).then((workspace: che.IWorkspace) => { this.tmpWorkspaceId = workspace.id; - let tmpWorkspaceIdeUrl: string = ''; + this.cheWorkspace.getWorkspacesById().set(workspace.id, workspace); + this.cheWorkspace.fetchStatusChange(workspace.id, 'RUNNING').then(() => { + if (projects && projects.length) { + this.cheWorkspace.fetchWorkspaceDetails(workspace.id).then(() => { + this.showIDE = false; + this.addProjects(workspace.id, projects).then(() => { + deferred.resolve(); + }, (error: any) => { + deferred.reject(error); + }); + }, (error: any) => { + if (error.status === 304) { + this.showIDE = false; + this.addProjects(workspace.id, projects).then(() => { + deferred.resolve(); + }, (error: any) => { + deferred.reject(error); + }); + } else { + this.$log.error(error); + } + }); + } + }, (error: any) => { + this.$log.error(error); + }); + this.cheWorkspace.startUpdateWorkspaceStatus(workspace.id); + let tmpWorkspaceIdeUrl = ''; angular.forEach(workspace.links, (link: any) => { if (link.rel === 'ide url') { tmpWorkspaceIdeUrl = link.href; @@ -386,13 +500,19 @@ export class StackController { this.cheNotification.showError('Testing stack failed.'); return; } + let bodyEl = this.$document.find('body'); let testPopupEl: string = '' + '
' + '
' + '
'; - this.cheUIElementsInjectorService.injectAdditionalElement(this.$document.find('body'), testPopupEl, this.$scope); + this.cheUIElementsInjectorService.injectAdditionalElement(bodyEl, testPopupEl, this.$scope); + deferred.promise.then(() => { + this.cheUIElementsInjectorService.injectAdditionalElement(bodyEl, testPopupEl, this.$scope); + }, (error: any) => { + this.$log.error(error); + }); }, (error: any) => { this.cheNotification.showError(error.data.message !== null ? error.data.message : 'Testing stack failed.'); this.closeStackTestPopup(); diff --git a/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts b/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts index f0986d18668..2091c294d9b 100644 --- a/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts +++ b/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts @@ -412,10 +412,12 @@ export class WorkspaceDetailsController { * @returns {String} name of workspace */ generateWorkspaceName(): string { - let name, - iterations = 100; + let name: string, + iterations: number = 100; while (iterations--) { - name = 'wksp-' + (('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4)); // jshint ignore:line + /* tslint:disable */ + name = 'wksp-' + (('0000' + (Math.random() * Math.pow(36, 4) << 0).toString(36)).slice(-4)); + /* tslint:enable */ if (this.usedNamesList.indexOf(name) >= 0) { break; } diff --git a/dashboard/src/components/api/che-workspace.factory.ts b/dashboard/src/components/api/che-workspace.factory.ts index 562f4828401..7ace7e4e5cb 100644 --- a/dashboard/src/components/api/che-workspace.factory.ts +++ b/dashboard/src/components/api/che-workspace.factory.ts @@ -233,11 +233,13 @@ export class CheWorkspace { let promise = this.remoteWorkspaceAPI.getDetails({workspaceKey: workspaceKey}).$promise; promise.then((data: che.IWorkspace) => { this.workspacesById.set(data.id, data); - this.lodash.remove(this.workspaces, (workspace: che.IWorkspace) => { - return workspace.id === data.id; - }); - this.workspaces.push(data); - this.startUpdateWorkspaceStatus(data.id); + if (!data.temporary) { + this.lodash.remove(this.workspaces, (workspace: che.IWorkspace) => { + return workspace.id === data.id; + }); + this.workspaces.push(data); + this.startUpdateWorkspaceStatus(data.id); + } defer.resolve(); }, (error: any) => { if (error.status !== 304) { diff --git a/dashboard/src/components/typings/che.d.ts b/dashboard/src/components/typings/che.d.ts index d4ac9716e4f..bc9e9cf6c05 100644 --- a/dashboard/src/components/typings/che.d.ts +++ b/dashboard/src/components/typings/che.d.ts @@ -65,6 +65,9 @@ declare namespace _che { export interface IWorkspace { id?: string; + name: string; + projects?: any; + links?: Array; runtime?: any; temporary?: boolean; status?: string; @@ -72,7 +75,7 @@ declare namespace _che { attributes?: { updated?: number; created?: number; - [propName: string]: string; + [propName: string]: string | number; }; config: IWorkspaceConfig; } @@ -142,17 +145,17 @@ declare namespace _che { export interface IImportProject { source: { - type: string; + type?: string; location: string; parameters: Object; }; project: { name: string; - type: string; + type?: string; description: string; - commands: Array; - attributes: Array; - options: Array; + commands?: Array; + attributes?: Array; + options?: Array; }; } From bced665b39a79c63b0166d6a5005858e36df831e Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Wed, 4 Jan 2017 13:10:12 +0200 Subject: [PATCH 2/3] CHE-3141 update codemirror version to 5.19.0 Signed-off-by: Oleksii Orel --- dashboard/bower.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dashboard/bower.json b/dashboard/bower.json index 82dc60a305c..9aba842b9c3 100644 --- a/dashboard/bower.json +++ b/dashboard/bower.json @@ -35,7 +35,7 @@ "angular-file-upload": "2.0.0", "jquery": "2.1.3", "js-yaml": "3.6.1", - "codemirror": "5.10.0" + "codemirror": "5.19.0" }, "devDependencies": {}, "resolutions": { From d459b6b66cc9f4b87c71864dde262e670ab1fc1a Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Tue, 10 Jan 2017 15:58:20 +0200 Subject: [PATCH 3/3] improve machine label style Signed-off-by: Oleksii Orel --- .../org/eclipse/che/ide/extension/machine/client/machine.css | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/resources/org/eclipse/che/ide/extension/machine/client/machine.css b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/resources/org/eclipse/che/ide/extension/machine/client/machine.css index f9c56f3a0c6..0d3bcbb8bbd 100644 --- a/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/resources/org/eclipse/che/ide/extension/machine/client/machine.css +++ b/plugins/plugin-machine/che-plugin-machine-ext-client/src/main/resources/org/eclipse/che/ide/extension/machine/client/machine.css @@ -247,7 +247,7 @@ font-size: 9px; padding: 0; border-radius: 2px; - margin: 2px 5px 0 3px; + margin: 3px 5px 0 3px; box-shadow: 1px 1px 2px treeTextShadow; } @@ -262,13 +262,14 @@ .processTree .machineStatus { position: relative; float: left; - margin: 4px 4px; + margin: 0 4px; overflow: hidden; } .processTree .machineStatus .machineStatusRunning { width: 10px; height: 10px; + margin-top: 4px; background-color: #46af00; border: 1px solid #7ed321; border-radius: 5px;