Skip to content

Commit

Permalink
Merge pull request #3445 from eclipse/CHE-3209
Browse files Browse the repository at this point in the history
CHE-3209 add import and configure batch of projects on stack testing
  • Loading branch information
Oleksii Orel authored Jan 10, 2017
2 parents d394e33 + d459b6b commit bc571b6
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dashboard/bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<any>
* @param items {Array<any>}
* @returns {number} - length of keys
*/
getItemsSize(items: Array<any>): number {
Expand Down
138 changes: 129 additions & 9 deletions dashboard/src/app/stacks/stack-details/stack.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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<any>} - the array to follow
* @param index{number} - the index of the array of commands
* @param deferred{ng.IDeferred<any>}
*/
addCommands(workspaceId: string, projectName: string, commands: Array<any>, index: number, deferred: ng.IDeferred<any>): 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<any>} - the array to follow
* @param index{number} - the index of the array of commands
* @param deferred{ng.IDeferred<any>}
*/
updateProjects(workspaceId: string, projects: Array<any>, index: number, deferred: ng.IDeferred<any>): 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<che.IProject>} - the adding projects
*
* @returns {ng.IPromise<any>}
*/
addProjects(workspaceId: string, projects: Array<che.IProject>): ng.IPromise<any> {
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<che.IProject>}
*/
showStackTestPopup(stack: che.IStack): void {
showStackTestPopup(stack: che.IStack, projects: Array<che.IProject>): 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;
Expand All @@ -386,13 +500,19 @@ export class StackController {
this.cheNotification.showError('Testing stack failed.');
return;
}
let bodyEl = this.$document.find('body');
let testPopupEl: string = '<che-modal-popup id="' + STACK_TEST_POPUP_ID + '" ' +
'title="Testing Stack: ' + stack.name + '" on-close="stackController.closeStackTestPopup()">' +
'<div ng-hide="stackController.showIDE" class="main-page-loader">' +
'<div class="ide-page-loader-content"><img ng-src="{{branding.loaderURL}}"></div></div>' +
'<iframe ng-show="stackController.showIDE" class="ide-page-frame" ' +
'src="' + tmpWorkspaceIdeUrl.toString() + '"></iframe></che-modal-popup>';
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 7 additions & 5 deletions dashboard/src/components/api/che-workspace.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 9 additions & 6 deletions dashboard/src/components/typings/che.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,17 @@ declare namespace _che {

export interface IWorkspace {
id?: string;
name: string;
projects?: any;
links?: Array<any>;
runtime?: any;
temporary?: boolean;
status?: string;
namespace?: string;
attributes?: {
updated?: number;
created?: number;
[propName: string]: string;
[propName: string]: string | number;
};
config: IWorkspaceConfig;
}
Expand Down Expand Up @@ -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<any>;
attributes: Array<any>;
options: Array<any>;
commands?: Array<any>;
attributes?: Array<any>;
options?: Array<any>;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down

0 comments on commit bc571b6

Please sign in to comment.