From 3f5b6cc938ee34ce33cd0a29067f34eeff789314 Mon Sep 17 00:00:00 2001 From: Anna Shumilova Date: Mon, 22 Apr 2019 13:22:35 +0300 Subject: [PATCH] Add devfile support in UD Signed-off-by: Anna Shumilova --- .../recent-workspaces.controller.ts | 6 +-- .../recent-workspaces/recent-workspaces.html | 2 +- .../workspace-item.controller.ts | 8 ++- .../workspace-item/workspace-item.html | 10 ++-- .../workspace-details.controller.ts | 14 ----- .../workspace-details-overview.controller.ts | 25 +++++---- .../workspace-details-overview.html | 2 +- .../src/app/workspaces/workspaces.service.ts | 15 +++--- .../api/workspace/che-workspace.factory.ts | 12 ++++- .../api/workspace/workspace-data-manager.ts | 54 +++++++++++++++++++ dashboard/src/components/typings/che.d.ts | 3 +- 11 files changed, 108 insertions(+), 43 deletions(-) create mode 100644 dashboard/src/components/api/workspace/workspace-data-manager.ts diff --git a/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.controller.ts b/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.controller.ts index e657da9035d..857d006dfcb 100644 --- a/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.controller.ts +++ b/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.controller.ts @@ -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'; } /** @@ -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'); } /** @@ -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); } /** diff --git a/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.html b/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.html index f98e7d2e799..2cab6dde761 100644 --- a/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.html +++ b/dashboard/src/app/navbar/recent-workspaces/recent-workspaces.html @@ -39,7 +39,7 @@ - {{workspace.config.name}} + {{navbarRecentWorkspacesController.getWorkspaceName(workspace.id)}} diff --git a/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.controller.ts b/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.controller.ts index 57ae0c29395..fbb1cf568ed 100644 --- a/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.controller.ts +++ b/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.controller.ts @@ -29,6 +29,7 @@ export class WorkspaceItemCtrl { workspacesService: WorkspacesService; workspace: che.IWorkspace; + workspaceName: string; /** * Default constructor that is using resource @@ -41,6 +42,7 @@ export class WorkspaceItemCtrl { this.lodash = lodash; this.cheWorkspace = cheWorkspace; this.workspacesService = workspacesService; + this.workspaceName = this.cheWorkspace.getWorkspaceDataManager().getName(this.workspace); } /** @@ -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 { @@ -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'); diff --git a/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.html b/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.html index bb1632c28bc..64a581cd77c 100644 --- a/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.html +++ b/dashboard/src/app/workspaces/list-workspaces/workspace-item/workspace-item.html @@ -13,7 +13,7 @@ -->
Name
-
+
- {{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspace.config.name}} + {{workspaceItemCtrl.workspace.namespace}}/{{workspaceItemCtrl.workspaceName}}
@@ -86,7 +86,7 @@ - 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 ca77e233dc7..e6e7d084d82 100644 --- a/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts +++ b/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts @@ -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 = ` 0 || this.unsavedChangesToApply || this.workspaceDetailsService.getRestartToApply(this.workspaceId); @@ -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. */ diff --git a/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.controller.ts b/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.controller.ts index 794596ea8fd..34dce30e2f6 100644 --- a/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.controller.ts +++ b/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.controller.ts @@ -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]; @@ -45,10 +46,12 @@ export class WorkspaceDetailsOverviewController { private workspaceDetailsService: WorkspaceDetailsService; private namespaceId: string; private workspaceName: string; + private name: string; private usedNamesList: Array; private inputmodel: ng.INgModelController; private isLoading: boolean; private isEphemeralMode: boolean; + private attributes: che.IWorkspaceConfigAttributes; private attributesCopy: che.IWorkspaceConfigAttributes; /** @@ -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(); } @@ -187,9 +193,9 @@ export class WorkspaceDetailsOverviewController { */ buildInListOfUsedNames(workspaces: Array): Array { 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); }); } @@ -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); @@ -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(); @@ -283,6 +289,7 @@ export class WorkspaceDetailsOverviewController { */ onNameChange() { this.$timeout(() => { + this.cheWorkspace.getWorkspaceDataManager().setName(this.workspaceDetails, this.name); this.onChange(); }); } diff --git a/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.html b/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.html index 0d69c2212a9..5fec462ccd7 100644 --- a/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.html +++ b/dashboard/src/app/workspaces/workspace-details/workspace-overview/workspace-details-overview.html @@ -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" diff --git a/dashboard/src/app/workspaces/workspaces.service.ts b/dashboard/src/app/workspaces/workspaces.service.ts index c0912cd600d..2c4bb7152b6 100644 --- a/dashboard/src/app/workspaces/workspaces.service.ts +++ b/dashboard/src/app/workspaces/workspaces.service.ts @@ -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; + } } - } diff --git a/dashboard/src/components/api/workspace/che-workspace.factory.ts b/dashboard/src/components/api/workspace/che-workspace.factory.ts index a8a9be41080..2e1a9f93519 100644 --- a/dashboard/src/components/api/workspace/che-workspace.factory.ts +++ b/dashboard/src/components/api/workspace/che-workspace.factory.ts @@ -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'; @@ -89,6 +90,10 @@ export class CheWorkspace { * Map with promises. */ private workspacePromises: Map> = new Map(); + /** + * + */ + private workspaceDataManager: WorkspaceDataManager; /** * Default constructor that is using resource @@ -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 = []; @@ -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; }); } @@ -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); diff --git a/dashboard/src/components/api/workspace/workspace-data-manager.ts b/dashboard/src/components/api/workspace/workspace-data-manager.ts new file mode 100644 index 00000000000..507d474c652 --- /dev/null +++ b/dashboard/src/components/api/workspace/workspace-data-manager.ts @@ -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; + } + } + +} diff --git a/dashboard/src/components/typings/che.d.ts b/dashboard/src/components/typings/che.d.ts index 49930e5d058..a74afd2ec9e 100755 --- a/dashboard/src/components/typings/che.d.ts +++ b/dashboard/src/components/typings/che.d.ts @@ -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;