Skip to content

Commit

Permalink
Fix commands
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Shumilova <ashumilo@redhat.com>
  • Loading branch information
ashumilova committed May 20, 2019
1 parent e0c361d commit 6e9a199
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class CreateWorkspaceController {
}
let attributes = {stackId: this.stack.id};

return this.createWorkspaceSvc.createWorkspace(this.workspaceConfig, attributes);
return this.createWorkspaceSvc.createWorkspaceFromConfig(this.workspaceConfig, attributes);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,13 @@ export class CreateWorkspaceSvc {
return defer.promise;
}

/**
* Creates a workspace from config.
*
* @param {che.IWorkspaceConfig} workspaceConfig the config of workspace which will be created
* @param {any} attributes the attributes of the workspace
* @returns {ng.IPromise<che.IWorkspace>}
*/
createWorkspace(workspaceConfig: che.IWorkspaceConfig, attributes: any): ng.IPromise<che.IWorkspace> {
createWorkspaceFromConfig(workspaceConfig: che.IWorkspaceConfig, attributes: any): ng.IPromise<che.IWorkspace> {
const namespaceId = this.namespaceSelectorSvc.getNamespaceId(),
projectTemplates = this.projectSourceSelectorService.getProjectTemplates();

return this.checkEditingProgress().then(() => {
workspaceConfig.projects = projectTemplates;
//TODO
//this.addProjectCommands(workspaceConfig, projectTemplates);
this.addProjectCommands({config: workspaceConfig}, projectTemplates);
return this.cheWorkspace.createWorkspaceFromConfig(namespaceId, workspaceConfig, attributes).then((workspace: che.IWorkspace) => {
return this.cheWorkspace.fetchWorkspaces().then(() => this.cheWorkspace.getWorkspaceById(workspace.id));
})
Expand All @@ -197,6 +189,39 @@ export class CreateWorkspaceSvc {
});
}

/*createWorkspaceFromDevfile(workspaceDevfile: che.IWorkspaceDevfile, attributes: any): ng.IPromise<che.IWorkspace> {
const namespaceId = this.namespaceSelectorSvc.getNamespaceId(),
projectTemplates = this.projectSourceSelectorService.getProjectTemplates();
return this.checkEditingProgress().then(() => {
workspaceDevfile.projects = projectTemplates;
this.addProjectCommands({devfile: workspaceDevfile}, projectTemplates);
return this.cheWorkspace.createWorkspaceFromDevfile(namespaceId, workspaceDevfile, attributes).then((workspace: che.IWorkspace) => {
return this.cheWorkspace.fetchWorkspaces().then(() => this.cheWorkspace.getWorkspaceById(workspace.id));
})
.then((workspace: che.IWorkspace) => {
this.projectSourceSelectorService.clearTemplatesList();
const workspaces = this.cheWorkspace.getWorkspaces();
if (workspaces.findIndex((_workspace: che.IWorkspace) => {
return _workspace.id === workspace.id;
}) === -1) {
workspaces.push(workspace);
}
this.cheWorkspace.startUpdateWorkspaceStatus(workspace.id);
return workspace;
}, (error: any) => {
let errorMessage = 'Creation workspace failed.';
if (error && error.data && error.data.message) {
errorMessage = error.data.message;
}
this.cheNotification.showError(errorMessage);
return this.$q.reject(error);
});
});
}*/

/**
* Show confirmation dialog when project editing is not completed.
*
Expand Down Expand Up @@ -234,7 +259,7 @@ export class CreateWorkspaceSvc {
}

/**
* Adds commands from the bunch of project templates to provided workspace config.
* Adds commands from the bunch of project templates to provided workspace.
*
* @param {che.IWorkspace} workspace
* @param {Array<che.IProjectTemplate>} projectTemplates the list of project templates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class WorkspaceDevfileEditorController {
};
devfileValidationMessages: string[] = [];
isActive: boolean;
workspaceDevfile: any;
workspaceDevfile: che.IWorkspaceDevfile;
devfileYaml: string;
newWorkspaceDevfile: any;
newWorkspaceDevfile: che.IWorkspaceDevfile;
workspaceDevfileOnChange: Function;
private saveTimeoutPromise: ng.IPromise<any>;
private isSaving: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ export class WorkspaceDetailsController {
/**
* Callback when workspace devfile has been changed in editor.
*
* @param devfile workspace devfile
* @param {che.IWorkspaceDevfile} devfile workspace devfile
*/
updateWorkspaceDevfile(devfile: any): void {
updateWorkspaceDevfile(devfile: che.IWorkspaceDevfile): void {
if (!devfile) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {WorkspaceDetailsProjectsService} from './workspace-details-projects.serv
import {WorkspaceDetailsService} from '../workspace-details.service';
import {CreateWorkspaceSvc} from '../../create-workspace/create-workspace.service';
import {WorkspaceStatus} from '../../../../components/api/workspace/che-workspace.factory';
import { WorkspaceDataManager } from '../../../../components/api/workspace/workspace-data-manager';
import {WorkspaceDataManager} from '../../../../components/api/workspace/workspace-data-manager';

/**
* @ngdoc controller
Expand Down
15 changes: 14 additions & 1 deletion dashboard/src/components/api/workspace/che-workspace.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {CheBranding} from '../../branding/che-branding.factory';
import {CheEnvironmentManager} from '../environment/che-environment-manager.factory';
import {CheRecipeTypes} from '../recipe/che-recipe-types';
import {CheNotification} from '../../notification/che-notification.factory';
import { WorkspaceDataManager } from './workspace-data-manager';
import {WorkspaceDataManager} from './workspace-data-manager';

const WS_AGENT_HTTP_LINK: string = 'wsagent/http';
const WS_AGENT_WS_LINK: string = 'wsagent/ws';
Expand Down Expand Up @@ -146,6 +146,8 @@ export class CheWorkspace {
// having 2 methods for creation to ensure namespace parameter won't be send at all if value is null or undefined
create: {method: 'POST', url: '/api/workspace'},
createWithNamespace: {method: 'POST', url: '/api/workspace?namespace=:namespace'},
createDevfile: {method: 'POST', url: '/api/workspace/devfile'},
createDevWithNamespace: {method: 'POST', url: '/api/workspace?namespace=:namespace'},
deleteWorkspace: {method: 'DELETE', url: '/api/workspace/:workspaceId'},
updateWorkspace: {method: 'PUT', url: '/api/workspace/:workspaceId'},
addProject: {method: 'POST', url: '/api/workspace/:workspaceId/project'},
Expand Down Expand Up @@ -533,6 +535,17 @@ export class CheWorkspace {
this.remoteWorkspaceAPI.create({attribute: attrs}, workspaceConfig).$promise;
}

/*createWorkspaceFromDevfile(namespace: string, devfile: che.IWorkspaceDevfile, attributes: any): ng.IPromise<any> {
let attrs = this.lodash.map(this.lodash.pairs(attributes || {}), (item: any) => {
return item[0] + ':' + item[1];
});
return namespace ? this.remoteWorkspaceAPI.createWithNamespace({
namespace: namespace,
attribute: attrs
}, workspaceDev).$promise :
this.remoteWorkspaceAPI.create({attribute: attrs}, workspaceDevfile).$promise;
}*/

/**
* Add a command into the workspace
* @param workspaceId {string} the id of the workspace on which we want to add the command
Expand Down
66 changes: 63 additions & 3 deletions dashboard/src/components/api/workspace/workspace-data-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const PLUGIN_TYPE = 'chePlugin';


/**
*
*
*
* @author Ann Shumilova
*/
export class WorkspaceDataManager {
Expand All @@ -36,9 +37,10 @@ export class WorkspaceDataManager {
}

/**
* Returns the name of the pointed workspace.
* Sets the name of the pointed workspace.
*
* @param workspace workspace name
* @param workspace workspace
* @param name workspace name
*/
setName(workspace: che.IWorkspace, name: string): void {
if (workspace.config) {
Expand All @@ -48,6 +50,11 @@ export class WorkspaceDataManager {
}
}

/**
* Returns the attributes of the pointed workspace.
*
* @param workspace workspace
*/
getAttributes(workspace: che.IWorkspace): che.IWorkspaceConfigAttributes {
if (workspace.config) {
return workspace.config.attributes;
Expand All @@ -56,6 +63,11 @@ export class WorkspaceDataManager {
}
}

/**
* Returns the projects of the pointed workspace.
*
* @param workspace workspace
*/
getProjects(workspace: che.IWorkspace): Array <any> {
if (workspace.config) {
return workspace.config.projects;
Expand All @@ -64,6 +76,26 @@ export class WorkspaceDataManager {
}
}

/**
* Sets the projects of the pointed workspace.
*
* @param workspace workspace
* @param projects workspace projects
*/
setProjects(workspace: che.IWorkspace, projects: Array<any>): void {
if (workspace.config) {
workspace.config.projects = projects;
} else if (workspace.devfile) {
workspace.devfile.projects = projects;
}
}

/**
* Adds the project to the pointed workspace.
*
* @param workspace workspace
* @param project project to be added to pointed workspace
*/
addProject(workspace: che.IWorkspace, project: any): void {
if (workspace.config) {
workspace.config.projects.push(project);
Expand All @@ -72,6 +104,12 @@ export class WorkspaceDataManager {
}
}

/**
* Adds the command to the pointed workspace.
*
* @param workspace workspace
* @param command command to be added to pointed workspace
*/
addCommand(workspace: che.IWorkspace, command: any): void {
if (workspace.config) {
workspace.config.commands.push(command);
Expand All @@ -80,6 +118,11 @@ export class WorkspaceDataManager {
}
}

/**
* Returns the list of plugin ids of the pointed workspace.
*
* @param workspace workspace
*/
getPlugins(workspace: che.IWorkspace): Array<string> {
let plugins: Array<string> = [];
if (workspace.config) {
Expand All @@ -95,6 +138,12 @@ export class WorkspaceDataManager {
return plugins;
}

/**
* Sets the list of plugins of the pointed workspace.
*
* @param workspace workspace
* @param plugins the list of plugins
*/
setPlugins(workspace: che.IWorkspace, plugins: Array<string>): void {
if (workspace.config) {
workspace.config.attributes.plugins = plugins.join(',');
Expand All @@ -121,6 +170,11 @@ export class WorkspaceDataManager {
}
}

/**
* Returns editor's id.
*
* @param workspace workspace
*/
getEditor(workspace: che.IWorkspace): string {
if (workspace.config) {
return workspace.config.attributes && workspace.config.attributes.editor ?
Expand All @@ -136,6 +190,12 @@ export class WorkspaceDataManager {
}
}

/**
* Sets the editor of the pointed workspace.
*
* @param workspace workspace
* @param editor editor's id
*/
setEditor(workspace: che.IWorkspace, editor: string): void {
if (workspace.config) {
workspace.config.attributes.editor = editor;
Expand Down
11 changes: 10 additions & 1 deletion dashboard/src/components/typings/che.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ declare namespace che {
namespace?: string;
attributes?: IWorkspaceAttributes;
config?: IWorkspaceConfig;
devfile?: any;
devfile?: IWorkspaceDevfile;
runtime?: IWorkspaceRuntime;
isLocked?: boolean;
usedResources?: string;
Expand Down Expand Up @@ -326,6 +326,15 @@ declare namespace che {
plugins?: string;
}

export interface IWorkspaceDevfile {
specVersion: string;
name: string;
components: Array<any>;
projects?: Array <any>;
commands?: Array <any>;
attributes?: che.IWorkspaceConfigAttributes;
}

export interface IWorkspaceEnvironment {
machines: {
[machineName: string]: IEnvironmentMachine
Expand Down

0 comments on commit 6e9a199

Please sign in to comment.