Skip to content

Commit

Permalink
Add devfile support in UD
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Shumilova <ashumilo@redhat.com>
  • Loading branch information
ashumilova committed Apr 22, 2019
1 parent 2981f29 commit 3f5b6cc
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class NavbarRecentWorkspacesController {
*/
getWorkspaceName(workspaceId: string): string {
let workspace = this.cheWorkspace.getWorkspaceById(workspaceId);
return workspace ? workspace.config.name : 'unknown';
return workspace ? this.cheWorkspace.getWorkspaceDataManager().getName(workspace) : 'unknown';
}

/**
Expand Down Expand Up @@ -256,7 +256,7 @@ export class NavbarRecentWorkspacesController {
* @returns {string}
*/
getIdeLink(workspace: che.IWorkspace): string {
return '#/ide/' + (workspace ? (workspace.namespace + '/' + workspace.config.name) : 'unknown');
return '#/ide/' + (workspace ? (workspace.namespace + '/' + this.cheWorkspace.getWorkspaceDataManager().getName(workspace)) : 'unknown');
}

/**
Expand All @@ -265,7 +265,7 @@ export class NavbarRecentWorkspacesController {
* @returns {string}
*/
getWorkspaceDetailsLink(workspace: che.IWorkspace): string {
return '#/workspace/' + workspace.namespace + '/' + workspace.config.name;
return '#/workspace/' + workspace.namespace + '/' + this.cheWorkspace.getWorkspaceDataManager().getName(workspace);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<span title="{{navbarRecentWorkspacesController.getWorkspaceName(workspace.id)}}"
class="recent-workspace-name-container"
ng-class="{'recent-workspaces-stopped-workspace': navbarRecentWorkspacesController.getWorkspaceStatus(workspace.id) === 'STOPPED'}">
<span che-clip-the-middle>{{workspace.config.name}}</span>
<span che-clip-the-middle>{{navbarRecentWorkspacesController.getWorkspaceName(workspace.id)}}</span>
</span>
</div>
</md-button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class WorkspaceItemCtrl {
workspacesService: WorkspacesService;

workspace: che.IWorkspace;
workspaceName: string;

/**
* Default constructor that is using resource
Expand All @@ -41,6 +42,7 @@ export class WorkspaceItemCtrl {
this.lodash = lodash;
this.cheWorkspace = cheWorkspace;
this.workspacesService = workspacesService;
this.workspaceName = this.cheWorkspace.getWorkspaceDataManager().getName(this.workspace);
}

/**
Expand All @@ -57,7 +59,7 @@ export class WorkspaceItemCtrl {
* @param tab {string}
*/
redirectToWorkspaceDetails(tab?: string): void {
this.$location.path('/workspace/' + this.workspace.namespace + '/' + this.workspace.config.name).search({tab: tab ? tab : 'Overview'});
this.$location.path('/workspace/' + this.workspace.namespace + '/' + this.workspaceName).search({tab: tab ? tab : 'Overview'});
}

getDefaultEnvironment(workspace: che.IWorkspace): che.IWorkspaceEnvironment {
Expand All @@ -68,6 +70,10 @@ export class WorkspaceItemCtrl {
}

getMemoryLimit(workspace: che.IWorkspace): string {
if (!workspace.config && workspace.devfile) {
return '-';
}

let environment = this.getDefaultEnvironment(workspace);
if (environment) {
let limits = this.lodash.pluck(environment.machines, 'attributes.memoryLimitBytes');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-->
<che-list-item flex ng-mouseover="hover=true" ng-mouseout="hover=false">
<div flex="100"
id="ws-name-{{workspaceItemCtrl.workspace.config.name}}"
id="ws-name-{{workspaceItemCtrl.workspaceName}}"
data-ws-status="{{workspaceItemCtrl.getWorkspaceStatus()}}"
layout="row"
layout-align="start stretch"
Expand All @@ -24,7 +24,7 @@
ng-if="workspaceItemCtrl.isSelectable === true">
<che-list-item-checked ng-model="workspaceItemCtrl.isSelect"
ng-show="('RUNNING' === workspaceItemCtrl.getWorkspaceStatus() || 'STOPPED' === workspaceItemCtrl.getWorkspaceStatus())"
che-aria-label-checkbox="Workspace {{workspaceItemCtrl.workspace.config.name}}"
che-aria-label-checkbox="Workspace {{workspaceItemCtrl.workspaceName}}"
ng-click="workspaceItemCtrl.onCheckboxClick()"></che-list-item-checked>
</div>
<div flex
Expand All @@ -41,10 +41,10 @@
<span class="che-xs-header noselect" hide-gt-xs>Name</span>
<div layout="row" flex>
<workspace-status-indicator flex="none" che-status="workspaceItemCtrl.getWorkspaceStatus()"></workspace-status-indicator>
<div class="workspace-name-clip" id="ws-full-name-{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspace.config.name}}">
<div class="workspace-name-clip" id="ws-full-name-{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspaceName}}">
<span uib-tooltip="{{'RUNNING' === workspaceItemCtrl.getWorkspaceStatus() ? 'Running' : 'Last modified: ' + (workspaceItemCtrl.workspace.attributes.updated | amTimeAgo)}}"
class="che-hover">
<che-clip-the-middle>{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspace.config.name}}</che-clip-the-middle>
<che-clip-the-middle>{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspaceName}}</che-clip-the-middle>
</span>
</div>
</div>
Expand Down Expand Up @@ -86,7 +86,7 @@
<che-workspace-status workspace-id="workspaceItemCtrl.workspace.id"
name="workspace-stop-start-button"
is-request-pending="workspaceItemCtrl.isRequestPending"></che-workspace-status>
<a href="#/workspace/{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspace.config.name}}?tab=Config"
<a href="#/workspace/{{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspaceName}}?tab=Config"
name="configure-workspace-button"
uib-tooltip="Configure workspace">
<span class="fa fa-cog"></span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,6 @@ export class WorkspaceDetailsController {
return `Current infrastructure doesn't support this workspace recipe type.`;
}

if (this.isSwitchToPlugins()) {
return 'Installers and plugins are different concepts, which are not compatible between each others. Enabling plugins causes disabling all installers.';
}

if (failedTabs && failedTabs.length > 0) {
const url = this.$location.absUrl().split('?')[0];
let message = `<i class="error fa fa-exclamation-circle"
Expand Down Expand Up @@ -377,7 +373,6 @@ export class WorkspaceDetailsController {

// message visibility
this.editOverlayConfig.message.visible = !this.isSupported
|| this.isSwitchToPlugins()
|| failedTabs.length > 0
|| this.unsavedChangesToApply
|| this.workspaceDetailsService.getRestartToApply(this.workspaceId);
Expand Down Expand Up @@ -548,15 +543,6 @@ export class WorkspaceDetailsController {
return tabs.some((tabKey: string) => this.checkFormsNotValid(tabKey));
}

/**
* Checks whether "plugins" were disabled in origin workspace config and are enabled now.
*/
isSwitchToPlugins(): boolean {
let originEditor = this.originWorkspaceDetails.config.attributes.editor || '';
let originPlugins = this.originWorkspaceDetails.config.attributes.plugins || '';
return this.isPluginsEnabled() && (originEditor.length === 0 && originPlugins.length === 0);
}

/**
* Checks whether "plugins" are enabled in workspace config.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {CheNotification} from '../../../../components/notification/che-notificat
import {ConfirmDialogService} from '../../../../components/service/confirm-dialog/confirm-dialog.service';
import {NamespaceSelectorSvc} from '../../create-workspace/namespace-selector/namespace-selector.service';
import {WorkspaceDetailsService} from '../workspace-details.service';
import {WorkspacesService} from '../../workspaces.service';

const STARTING = WorkspaceStatus[WorkspaceStatus.STARTING];
const RUNNING = WorkspaceStatus[WorkspaceStatus.RUNNING];
Expand Down Expand Up @@ -45,10 +46,12 @@ export class WorkspaceDetailsOverviewController {
private workspaceDetailsService: WorkspaceDetailsService;
private namespaceId: string;
private workspaceName: string;
private name: string;
private usedNamesList: Array<string>;
private inputmodel: ng.INgModelController;
private isLoading: boolean;
private isEphemeralMode: boolean;
private attributes: che.IWorkspaceConfigAttributes;
private attributesCopy: che.IWorkspaceConfigAttributes;

/**
Expand All @@ -70,9 +73,12 @@ export class WorkspaceDetailsOverviewController {
const routeParams = $route.current.params;
this.namespaceId = routeParams.namespace;
this.workspaceName = routeParams.workspaceName;

this.isEphemeralMode = this.workspaceDetails && this.workspaceDetails.config && this.workspaceDetails.config.attributes && this.workspaceDetails.config.attributes.persistVolumes ? !JSON.parse(this.workspaceDetails.config.attributes.persistVolumes) : false;
this.attributesCopy = angular.copy(this.workspaceDetails.config.attributes);

this.attributes = this.cheWorkspace.getWorkspaceDataManager().getAttributes(this.workspaceDetails);
this.name = this.cheWorkspace.getWorkspaceDataManager().getName(this.workspaceDetails);
this.isEphemeralMode = this.attributes && this.attributes.persistVolumes ? !JSON.parse(this.attributes.persistVolumes) : false;

this.attributesCopy = angular.copy(this.cheWorkspace.getWorkspaceDataManager().getAttributes(this.workspaceDetails));

this.fillInListOfUsedNames();
}
Expand Down Expand Up @@ -187,9 +193,9 @@ export class WorkspaceDetailsOverviewController {
*/
buildInListOfUsedNames(workspaces: Array<che.IWorkspace>): Array<string> {
return workspaces.filter((workspace: che.IWorkspace) => {
return workspace.namespace === this.namespaceId && workspace.config.name !== this.workspaceName;
return workspace.namespace === this.namespaceId && this.cheWorkspace.getWorkspaceDataManager().getName(workspace) !== this.workspaceName;
}).map((workspace: che.IWorkspace) => {
return workspace.config.name;
return this.cheWorkspace.getWorkspaceDataManager().getName(workspace);
});
}

Expand Down Expand Up @@ -247,7 +253,7 @@ export class WorkspaceDetailsOverviewController {
* Removes current workspace.
*/
deleteWorkspace(): void {
const content = 'Would you like to delete workspace \'' + this.workspaceDetails.config.name + '\'?';
const content = 'Would you like to delete workspace \'' + this.cheWorkspace.getWorkspaceDataManager().getName(this.workspaceDetails) + '\'?';
this.confirmDialogService.showConfirmDialog('Delete workspace', content, 'Delete').then(() => {
if ([RUNNING, STARTING].indexOf(this.getWorkspaceStatus()) !== -1) {
this.cheWorkspace.stopWorkspace(this.workspaceDetails.id);
Expand All @@ -267,12 +273,12 @@ export class WorkspaceDetailsOverviewController {
*/
onEphemeralModeChange(): void {
if (this.isEphemeralMode) {
this.workspaceDetails.config.attributes.persistVolumes = 'false';
this.attributes.persistVolumes = 'false';
} else {
if (this.attributesCopy.persistVolumes) {
this.workspaceDetails.config.attributes.persistVolumes = 'true';
this.attributes.persistVolumes = 'true';
} else {
delete this.workspaceDetails.config.attributes.persistVolumes;
delete this.attributes.persistVolumes;
}
}
this.onChange();
Expand All @@ -283,6 +289,7 @@ export class WorkspaceDetailsOverviewController {
*/
onNameChange() {
this.$timeout(() => {
this.cheWorkspace.getWorkspaceDataManager().setName(this.workspaceDetails, this.name);
this.onChange();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
che-place-holder="Name of the workspace"
aria-label="Name of the workspace"
ng-model-options="{ allowInvalid: true }"
ng-model="workspaceDetailsOverviewController.workspaceDetails.config.name"
ng-model="workspaceDetailsOverviewController.name"
che-on-change="workspaceDetailsOverviewController.onNameChange()"
required
ng-minlength="3"
Expand Down
15 changes: 8 additions & 7 deletions dashboard/src/app/workspaces/workspaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ export class WorkspacesService {
* @returns {boolean}
*/
isSupported(workspace: che.IWorkspace, envName?: string): boolean {
envName = envName || workspace.config.defaultEnv;

const supportedRecipeTypes = this.cheWorkspace.getSupportedRecipeTypes(),
envRecipeType = envName ? workspace.config.environments[envName].recipe.type : 'no-environment';

return supportedRecipeTypes.indexOf(envRecipeType) !== -1;
if (workspace.config) {
envName = envName || workspace.config.defaultEnv;
const supportedRecipeTypes = this.cheWorkspace.getSupportedRecipeTypes(),
envRecipeType = envName ? workspace.config.environments[envName].recipe.type : 'no-environment';
return supportedRecipeTypes.indexOf(envRecipeType) !== -1;
} else if (workspace.devfile) {
return true;
}
}

}
12 changes: 11 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,6 +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';

const WS_AGENT_HTTP_LINK: string = 'wsagent/http';
const WS_AGENT_WS_LINK: string = 'wsagent/ws';
Expand Down Expand Up @@ -89,6 +90,10 @@ export class CheWorkspace {
* Map with promises.
*/
private workspacePromises: Map<string, ng.IHttpPromise<any>> = new Map();
/**
*
*/
private workspaceDataManager: WorkspaceDataManager;

/**
* Default constructor that is using resource
Expand All @@ -115,6 +120,7 @@ export class CheWorkspace {
this.$websocket = $websocket;
this.lodash = lodash;
this.cheNotification = cheNotification;
this.workspaceDataManager = new WorkspaceDataManager();

// current list of workspaces
this.workspaces = [];
Expand Down Expand Up @@ -284,7 +290,7 @@ export class CheWorkspace {

getWorkspaceByName(namespace: string, name: string): che.IWorkspace {
return this.lodash.find(this.workspaces, (workspace: che.IWorkspace) => {
return workspace.namespace === namespace && workspace.config.name === name;
return workspace.namespace === namespace && this.workspaceDataManager.getName(workspace) === name;
});
}

Expand Down Expand Up @@ -777,6 +783,10 @@ export class CheWorkspace {
return this.jsonRpcApiLocation;
}

getWorkspaceDataManager(): WorkspaceDataManager {
return this.workspaceDataManager;
}

private updateWorkspacesList(workspace: che.IWorkspace): void {
if (workspace.temporary) {
this.workspacesById.set(workspace.id, workspace);
Expand Down
54 changes: 54 additions & 0 deletions dashboard/src/components/api/workspace/workspace-data-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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';

/**
*
* @author Ann Shumilova
*/
export class WorkspaceDataManager {

/**
* Returns the name of the pointed workspace.
*
* @param workspace workspace name
*/
getName(workspace: che.IWorkspace): string {
if (workspace.config) {
return workspace.config.name;
} else if (workspace.devfile) {
return workspace.devfile.name;
}
}

/**
* Returns the name of the pointed workspace.
*
* @param workspace workspace name
*/
setName(workspace: che.IWorkspace, name: string): void {
if (workspace.config) {
workspace.config.name = name;
} else if (workspace.devfile) {
workspace.devfile.name = name;
}
}

getAttributes(workspace: che.IWorkspace): che.IWorkspaceConfigAttributes {
if (workspace.config) {
return workspace.config.attributes;
} else if (workspace.devfile) {
return workspace.devfile.attributes;
}
}

}
3 changes: 2 additions & 1 deletion dashboard/src/components/typings/che.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ declare namespace che {
status?: string;
namespace?: string;
attributes?: IWorkspaceAttributes;
config: IWorkspaceConfig;
config?: IWorkspaceConfig;
devfile?: any;
runtime?: IWorkspaceRuntime;
isLocked?: boolean;
usedResources?: string;
Expand Down

0 comments on commit 3f5b6cc

Please sign in to comment.