From 799c2469223c2c5322402406a636c04f90b1e90c Mon Sep 17 00:00:00 2001 From: Anna Shumilova Date: Mon, 3 Jun 2019 16:33:49 +0300 Subject: [PATCH] Create workspace from devfile Signed-off-by: Anna Shumilova --- .../create-workspace.controller.ts | 98 ++++------------ .../create-workspace/create-workspace.html | 17 +-- .../create-workspace.service.ts | 19 +++- .../devfile-selector.controller.ts | 64 +++++++++++ .../devfile-selector.directive.ts | 42 +++++++ .../devfile-selector/devfile-selector.html | 66 +++++++++++ .../devfile-selector/devfile-selector.styl | 106 ++++++++++++++++++ .../workspace-editors.controller.ts | 1 - .../src/app/workspaces/workspaces-config.ts | 4 + .../src/components/api/che-api-config.ts | 2 + .../api/devfile-registry.factory.ts | 72 ++++++++++++ .../api/workspace/che-workspace.factory.ts | 16 ++- .../api/workspace/workspace-data-manager.ts | 1 + dashboard/src/components/typings/che.d.ts | 1 + 14 files changed, 406 insertions(+), 103 deletions(-) create mode 100644 dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.controller.ts create mode 100644 dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.directive.ts create mode 100644 dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.html create mode 100644 dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.styl create mode 100644 dashboard/src/components/api/devfile-registry.factory.ts diff --git a/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts b/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts index 041f7f64f7ec..99415db7ecc8 100644 --- a/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts +++ b/dashboard/src/app/workspaces/create-workspace/create-workspace.controller.ts @@ -23,6 +23,7 @@ import { ICheButtonDropdownMainAction, ICheButtonDropdownOtherAction } from '../../../components/widget/button-dropdown/che-button-dropdown.directive'; +import {DevfileRegistry} from '../../../components/api/devfile-registry.factory'; /** * This class is handling the controller for workspace creation. @@ -31,8 +32,8 @@ import { */ export class CreateWorkspaceController { - static $inject = ['$mdDialog', '$timeout', 'cheEnvironmentRegistry', 'createWorkspaceSvc', 'namespaceSelectorSvc', 'stackSelectorSvc', - 'randomSvc', '$log', 'cheNotification']; + static $inject = ['$mdDialog', '$timeout', 'cheEnvironmentRegistry', 'createWorkspaceSvc', 'namespaceSelectorSvc', + 'randomSvc', '$log', 'cheNotification', 'devfileRegistry']; /** * Dropdown button config. @@ -58,10 +59,6 @@ export class CreateWorkspaceController { * Namespace selector service. */ private namespaceSelectorSvc: NamespaceSelectorSvc; - /** - * Stack selector service. - */ - private stackSelectorSvc: StackSelectorSvc; /** * Generator for random strings. */ @@ -75,29 +72,21 @@ export class CreateWorkspaceController { */ private cheNotification: CheNotification; /** - * The environment manager. + * Devfile registry. */ - private environmentManager: EnvironmentManager; + private devfileRegistry: DevfileRegistry; /** - * The selected stack. + * The environment manager. */ - private stack: che.IStack; + private environmentManager: EnvironmentManager; /** - * The workspace config of the current stack. + * The selected devfile. */ - private workspaceConfig: che.IWorkspaceConfig; + private selectedDevfile: che.IWorkspaceDevfile; /** * The selected namespace ID. */ private namespaceId: string; - /** - * The list of machines of selected stack. - */ - private stackMachines: Array; - /** - * Desired memory limit by machine name. - */ - private memoryByMachine: {[name: string]: number}; /** * The map of forms. */ @@ -122,23 +111,21 @@ export class CreateWorkspaceController { cheEnvironmentRegistry: CheEnvironmentRegistry, createWorkspaceSvc: CreateWorkspaceSvc, namespaceSelectorSvc: NamespaceSelectorSvc, - stackSelectorSvc: StackSelectorSvc, randomSvc: RandomSvc, $log: ng.ILogService, - cheNotification: CheNotification) { + cheNotification: CheNotification, + devfileRegistry: DevfileRegistry) { this.$mdDialog = $mdDialog; this.$timeout = $timeout; this.cheEnvironmentRegistry = cheEnvironmentRegistry; this.createWorkspaceSvc = createWorkspaceSvc; this.namespaceSelectorSvc = namespaceSelectorSvc; - this.stackSelectorSvc = stackSelectorSvc; this.randomSvc = randomSvc; this.$log = $log; this.cheNotification = cheNotification; + this.devfileRegistry = devfileRegistry; this.usedNamesList = []; - this.stackMachines = []; - this.memoryByMachine = {}; this.forms = new Map(); this.namespaceId = this.namespaceSelectorSvc.getNamespaceId(); @@ -150,7 +137,8 @@ export class CreateWorkspaceController { // loader should be hidden and page content shown // when stacks selector is rendered // and default stack is selected - this.hideLoader = false; + //TODO + this.hideLoader = true; // header toolbar // dropdown button config @@ -182,43 +170,12 @@ export class CreateWorkspaceController { * * @param {string} stackId the stack ID */ - onStackSelected(stackId: string): void { + onDevfileSelected(devfile: che.IWorkspaceDevfile): void { // tiny timeout for templates selector to be rendered this.$timeout(() => { this.hideLoader = true; }, 10); - - this.stack = this.stackSelectorSvc.getStackById(stackId); - this.workspaceConfig = angular.copy(this.stack.workspaceConfig); - - if (!this.stack.workspaceConfig || !this.stack.workspaceConfig.defaultEnv) { - this.memoryByMachine = {}; - this.stackMachines = []; - return; - } - - const environmentName = this.stack.workspaceConfig.defaultEnv; - const environment = this.stack.workspaceConfig.environments[environmentName]; - const recipeType = environment.recipe.type; - this.environmentManager = this.cheEnvironmentRegistry.getEnvironmentManager(recipeType); - if (!this.environmentManager) { - const errorMessage = `Unsupported recipe type '${recipeType}'`; - this.$log.error(errorMessage); - this.cheNotification.showError(errorMessage); - return; - } - this.memoryByMachine = {}; - this.stackMachines = this.environmentManager.getMachines(environment); - } - - /** - * Callback which is called when machine's memory limit is changes. - * - * @param {string} name a machine name - * @param {number} memoryLimitBytes a machine's memory limit in bytes - */ - onRamChanged(name: string, memoryLimitBytes: number): void { - this.memoryByMachine[name] = memoryLimitBytes; + this.selectedDevfile = devfile } /** @@ -267,7 +224,7 @@ export class CreateWorkspaceController { * @return {boolean} */ isCreateButtonDisabled(): boolean { - if (!this.namespaceId || (this.stack && !this.stack.workspaceConfig)) { + if (!this.namespaceId || !this.selectedDevfile) { return true; } @@ -312,7 +269,7 @@ export class CreateWorkspaceController { this.usedNamesList = workspaces.filter((workspace: che.IWorkspace) => { return workspace.namespace === this.namespaceId; }).map((workspace: che.IWorkspace) => { - return workspace.config.name; + return this.createWorkspaceSvc.getWorkspaceName(workspace); }); }); } @@ -342,23 +299,8 @@ export class CreateWorkspaceController { */ createWorkspace(): ng.IPromise { // update workspace name - this.workspaceConfig.name = this.workspaceName; - - // update memory limits of machines - if (Object.keys(this.memoryByMachine).length !== 0) { - this.stackMachines.forEach((machine: IEnvironmentManagerMachine) => { - if (this.memoryByMachine[machine.name]) { - this.environmentManager.setMemoryLimit(machine, this.memoryByMachine[machine.name]); - } - }); - const environmentName = this.workspaceConfig.defaultEnv; - const environment = this.workspaceConfig.environments[environmentName]; - const newEnvironment = this.environmentManager.getEnvironment(environment, this.stackMachines); - this.workspaceConfig.environments[environmentName] = newEnvironment; - } - let attributes = {stackId: this.stack.id}; - - return this.createWorkspaceSvc.createWorkspaceFromConfig(this.workspaceConfig, attributes); + this.selectedDevfile.name = this.workspaceName; + return this.createWorkspaceSvc.createWorkspaceFromDevfile(this.selectedDevfile, null); } /** diff --git a/dashboard/src/app/workspaces/create-workspace/create-workspace.html b/dashboard/src/app/workspaces/create-workspace/create-workspace.html index f967b5432eaa..34083aa61688 100644 --- a/dashboard/src/app/workspaces/create-workspace/create-workspace.html +++ b/dashboard/src/app/workspaces/create-workspace/create-workspace.html @@ -51,22 +51,11 @@ on-namespace-change="createWorkspaceController.onNamespaceChanged(namespaceId)"> - - - - - - - - - - + + + diff --git a/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts b/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts index 3673ff17f47d..25d7fddde289 100644 --- a/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts +++ b/dashboard/src/app/workspaces/create-workspace/create-workspace.service.ts @@ -189,7 +189,7 @@ export class CreateWorkspaceSvc { }); } - /*createWorkspaceFromDevfile(workspaceDevfile: che.IWorkspaceDevfile, attributes: any): ng.IPromise { + createWorkspaceFromDevfile(workspaceDevfile: che.IWorkspaceDevfile, attributes: any): ng.IPromise { const namespaceId = this.namespaceSelectorSvc.getNamespaceId(), projectTemplates = this.projectSourceSelectorService.getProjectTemplates(); @@ -220,7 +220,7 @@ export class CreateWorkspaceSvc { return this.$q.reject(error); }); }); - }*/ + } /** * Show confirmation dialog when project editing is not completed. @@ -244,7 +244,8 @@ export class CreateWorkspaceSvc { * @param {che.IWorkspace} workspace the workspace to open in IDE */ redirectToIDE(workspace: che.IWorkspace): void { - const path = `/ide/${workspace.namespace}/${workspace.config.name}`; + let name = this.cheWorkspace.getWorkspaceDataManager().getName(workspace); + const path = `/ide/${workspace.namespace}/${name}`; this.$location.path(path); } @@ -254,7 +255,8 @@ export class CreateWorkspaceSvc { * @param {che.IWorkspace} workspace the workspace to open in IDE */ redirectToDetails(workspace: che.IWorkspace): void { - const path = `/workspace/${workspace.namespace}/${workspace.config.name}`; + let name = this.cheWorkspace.getWorkspaceDataManager().getName(workspace); + const path = `/workspace/${workspace.namespace}/${name}`; this.$location.path(path); } @@ -273,4 +275,13 @@ export class CreateWorkspaceSvc { }); }); } + + /** + * Returns name of the pointed workspace. + * + * @param workspace workspace + */ + getWorkspaceName(workspace: che.IWorkspace): string { + return this.cheWorkspace.getWorkspaceDataManager().getName(workspace); + } } diff --git a/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.controller.ts b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.controller.ts new file mode 100644 index 000000000000..f8a545827228 --- /dev/null +++ b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.controller.ts @@ -0,0 +1,64 @@ +/* + * 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'; +import {CheWorkspace} from '../../../../components/api/workspace/che-workspace.factory'; +import {DevfileRegistry, IDevfileMetaData} from '../../../../components/api/devfile-registry.factory'; + +/** + * @description This class is handling the controller of devfile selector. + * @author Ann Shumilova + */ +export class DevfileSelectorController { + + static $inject = ['devfileRegistry', 'cheWorkspace']; + + private devfileRegistry: DevfileRegistry; + private cheWorkspace: CheWorkspace; + private devfiles: Array; + onDevfileSelect: Function; + selectedDevfile: any; + + /** + * Default constructor that is using resource injection + */ + constructor(devfileRegistry: DevfileRegistry, cheWorkspace: CheWorkspace) { + this.devfileRegistry = devfileRegistry; + this.cheWorkspace = cheWorkspace; + this.loadDevfiles(); + } + + loadDevfiles(): void { + let location = this.cheWorkspace.getWorkspaceSettings().devfileRegistry; + this.devfileRegistry.fetchDevfiles(location).then((data: Array) => { + this.devfiles = data; + + if (this.devfiles && this.devfiles.length > 0) { + this.devfileOnClick(this.devfiles[0]); + } + }); + } + + devfileOnClick(devfile: any): void { + this.selectedDevfile = devfile; + + let location = this.cheWorkspace.getWorkspaceSettings().devfileRegistry; + + let devfileContent = this.devfileRegistry.getDevfile(location, devfile.links.self); + if (devfileContent) { + this.onDevfileSelect({devfile: devfileContent}); + } else { + this.devfileRegistry.fetchDevfile(location, devfile.links.self).then((devfileContent: che.IWorkspaceDevfile) => { + this.onDevfileSelect({devfile: devfileContent}); + }); + } + } +} diff --git a/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.directive.ts b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.directive.ts new file mode 100644 index 000000000000..efe0834d8d64 --- /dev/null +++ b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.directive.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2018-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'; + +/** + * Defines a directive for displaying devfile selector widget. + * + * @author Ann Shumilova + */ +export class DevfileSelector implements ng.IDirective { + restrict: string = 'E'; + templateUrl: string = 'app/workspaces/create-workspace/devfile-selector/devfile-selector.html'; + replace: boolean = true; + + controller: string = 'DevfileSelectorController'; + controllerAs: string = 'devfileSelectorController'; + + bindToController: boolean = true; + + scope: { + [propName: string]: string + }; + + /** + * Default constructor that is using resource + */ + constructor() { + this.scope = { + devfileIdSelected: '=', + onDevfileSelect: '&' + }; + } +} diff --git a/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.html b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.html new file mode 100644 index 000000000000..c40937f6666a --- /dev/null +++ b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.html @@ -0,0 +1,66 @@ +
+
+
+
+
+ +
+
+ + + +
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+ {{devfile.displayName}} +
+ +
+ {{devfile.description}} +
+
+
+
+
+
+
+
+
+
+ There are no devfiles. +
+ +
diff --git a/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.styl b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.styl new file mode 100644 index 000000000000..d6ae4cd74e24 --- /dev/null +++ b/dashboard/src/app/workspaces/create-workspace/devfile-selector/devfile-selector.styl @@ -0,0 +1,106 @@ +.devfile-selector + width 100% + + $devfile-selector-list-header-border = lighten($very-light-grey-color, 4%) + $devfile-selector-list-header-background = lighten($very-light-grey-color, 28%) + + .devfile-selector-list + background-color $devfile-selector-list-header-background + border-top 1px solid $devfile-selector-list-header-border + border-radius 2px + width 100% + + & > div + position relative + margin-top 40px + che-box-shadow() + + & > div + overflow-y auto + max-height 307px + + .che-list-header + .che-list-header-additional + display none + .che-list-item-row + margin -40px 0 0 0 + .che-list-header-column > * + position absolute + line-height 40px + top -40px + + .che-list-content + .devfile-selector-item-icon + line-height inherit + + .devfile-selector-icon-column + width 100px !important + + .devfile-selector-devfile-list + margin 0 + + .che-list + margin 0 + +.devfile-selector-item + $devfile-selected-background-color = #F2F7FD + + position relative + background-color $che-white-color + border 1px solid lighten($very-light-grey-color, 4%) + border-top-color lighten($list-separator-color, 7%) + z-index 0 + + * + outline none + + &:not(:first-of-type) + margin-top -1px + + &:last-of-type + border-radius 0 0 2px 2px + + .devfile-selector-item-icon + line-height 38px + font-size 30px + width 55px + text-align center + filter grayscale(100%) opacity(50%) + + img + height 30px + vertical-align top + + div + width 50px + + .devfile-selector-item-components > div + display inline-block + margin-right 10px + padding 0 11px + border 1px solid darken($che-white-color, 9%) + border-radius 2px + font-size 9px + line-height 14px + color $default-color + + // selected state + &.devfile-selector-item-selected + background-color $devfile-selected-background-color + border-color $primary-color + z-index 1 !important + + .devfile-selector-item-name + color $primary-color + +.devfile-selector-item + md-item.che-list-item + border none + + md-item-content + display block + border none + + .che-list-item-row + line-height 25px + diff --git a/dashboard/src/app/workspaces/workspace-details/workspace-editors/workspace-editors.controller.ts b/dashboard/src/app/workspaces/workspace-details/workspace-editors/workspace-editors.controller.ts index b9a65d2aa2a2..17c8ab88339d 100644 --- a/dashboard/src/app/workspaces/workspace-details/workspace-editors/workspace-editors.controller.ts +++ b/dashboard/src/app/workspaces/workspace-details/workspace-editors/workspace-editors.controller.ts @@ -29,7 +29,6 @@ export class WorkspaceEditorsController { workspace: che.IWorkspace; pluginRegistryLocation: string; - pluginRegistry: PluginRegistry; cheNotification: CheNotification; cheWorkspace: CheWorkspace; diff --git a/dashboard/src/app/workspaces/workspaces-config.ts b/dashboard/src/app/workspaces/workspaces-config.ts index e716538b5804..d735d8b5e515 100644 --- a/dashboard/src/app/workspaces/workspaces-config.ts +++ b/dashboard/src/app/workspaces/workspaces-config.ts @@ -84,6 +84,8 @@ import {WorkspaceWarningsController} from './workspace-details/warnings/workspac import {WorkspacesService} from './workspaces.service'; import {WorkspacePluginsConfig} from './workspace-details/workspace-plugins/workspace-plugins-config'; import {WorkspaceEditorsConfig} from './workspace-details/workspace-editors/workspace-editors-config'; +import {DevfileSelector} from './create-workspace/devfile-selector/devfile-selector.directive'; +import {DevfileSelectorController} from './create-workspace/devfile-selector/devfile-selector.controller'; /** * @ngdoc controller @@ -122,6 +124,8 @@ export class WorkspacesConfig { register.service('stackSelectorSvc', StackSelectorSvc); register.directive('stackSelector', StackSelector); register.directive('stackSelectorItem', StackSelectorItem); + register.directive('devfileSelector', DevfileSelector); + register.controller('DevfileSelectorController', DevfileSelectorController); register.controller('RamSettingsController', RamSettingsController); register.directive('ramSettings', RamSettings); register.controller('RamSettingsMachineItemController', RamSettingsMachineItemController); diff --git a/dashboard/src/components/api/che-api-config.ts b/dashboard/src/components/api/che-api-config.ts index 2f234c534de2..47f4b78acbef 100644 --- a/dashboard/src/components/api/che-api-config.ts +++ b/dashboard/src/components/api/che-api-config.ts @@ -43,6 +43,7 @@ import {CheTeamEventsManager} from './che-team-events-manager.factory'; import {CheInvite} from './che-invite.factory'; import {NpmRegistry} from './npm-registry.factory'; import {PluginRegistry} from './plugin-registry.factory'; +import {DevfileRegistry} from './devfile-registry.factory'; export class ApiConfig { @@ -79,5 +80,6 @@ export class ApiConfig { register.factory('cheInvite', CheInvite); register.factory('npmRegistry', NpmRegistry); register.factory('pluginRegistry', PluginRegistry); + register.factory('devfileRegistry', DevfileRegistry); } } diff --git a/dashboard/src/components/api/devfile-registry.factory.ts b/dashboard/src/components/api/devfile-registry.factory.ts new file mode 100644 index 000000000000..8cd432fb807b --- /dev/null +++ b/dashboard/src/components/api/devfile-registry.factory.ts @@ -0,0 +1,72 @@ +import { stringify } from "querystring"; + +/* + * 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'; + +export interface IDevfileMetaData { + displayName: string; + description?: string; + icon: string; + links: any; +} + + +/** + * This class is handling devfile registry api + * @author Ann Shumilova + */ +export class DevfileRegistry { + static $inject = ['$http']; + + /** + * Angular Http service. + */ + private $http: ng.IHttpService; + + private devfilesMap: Map; + + /** + * Default constructor that is using resource + */ + constructor($http: ng.IHttpService) { + this.$http = $http; + this.devfilesMap = new Map(); + } + + fetchDevfiles(location: string): ng.IPromise> { + let promise = this.$http({ 'method': 'GET', 'url': location + '/devfiles/' }); + return promise.then((result: any) => { + return result.data; + }); + } + + fetchDevfile(location: string, link: string): ng.IPromise { + let promise = this.$http({ 'method': 'GET', 'url': location + link }); + return promise.then((result: any) => { + let devfile = this.devfileYamlToJson(result.data) + this.devfilesMap.set(location + link, devfile); + return devfile; + }); + } + + getDevfile(location: string, link: string): che.IWorkspaceDevfile { + return this.devfilesMap.get(location + link); + } + + private devfileYamlToJson(yaml: string): che.IWorkspaceDevfile { + try { + return jsyaml.load(yaml); + } catch (e) { + } + } +} diff --git a/dashboard/src/components/api/workspace/che-workspace.factory.ts b/dashboard/src/components/api/workspace/che-workspace.factory.ts index f76f7a118cd7..aca6cd07fd09 100644 --- a/dashboard/src/components/api/workspace/che-workspace.factory.ts +++ b/dashboard/src/components/api/workspace/che-workspace.factory.ts @@ -28,6 +28,8 @@ const WS_AGENT_WS_LINK: string = 'wsagent/ws'; interface ICHELicenseResource extends ng.resource.IResourceClass { create: any; createWithNamespace: any; + createDevfile: any; + createDevfileWithNamespace: any; deleteWorkspace: any; updateWorkspace: any; addProject: any; @@ -142,7 +144,7 @@ export class CheWorkspace { 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'}, + createDevfileWithNamespace: {method: 'POST', url: '/api/workspace/devfile?namespace=:namespace'}, deleteWorkspace: {method: 'DELETE', url: '/api/workspace/:workspaceId'}, updateWorkspace: {method: 'PUT', url: '/api/workspace/:workspaceId'}, addProject: {method: 'POST', url: '/api/workspace/:workspaceId/project'}, @@ -531,16 +533,16 @@ export class CheWorkspace { this.remoteWorkspaceAPI.create({attribute: attrs}, workspaceConfig).$promise; } - /*createWorkspaceFromDevfile(namespace: string, devfile: che.IWorkspaceDevfile, attributes: any): ng.IPromise { + createWorkspaceFromDevfile(namespace: string, devfile: che.IWorkspaceDevfile, attributes: any): ng.IPromise { let attrs = this.lodash.map(this.lodash.pairs(attributes || {}), (item: any) => { return item[0] + ':' + item[1]; }); - return namespace ? this.remoteWorkspaceAPI.createWithNamespace({ + return namespace ? this.remoteWorkspaceAPI.createDevfileWithNamespace({ namespace: namespace, attribute: attrs - }, workspaceDev).$promise : - this.remoteWorkspaceAPI.create({attribute: attrs}, workspaceDevfile).$promise; - }*/ + }, devfile).$promise : + this.remoteWorkspaceAPI.createDevfile({attribute: attrs}, devfile).$promise; + } /** * Add a command into the workspace @@ -757,6 +759,8 @@ export class CheWorkspace { const promise = this.remoteWorkspaceAPI.getSettings().$promise; return promise.then((settings: che.IWorkspaceSettings) => { this.workspaceSettings = settings; + //TODO remove next line + this.workspaceSettings.devfileRegistry = 'http://che-devfile-registry-default.192.168.39.13.nip.io'; return this.workspaceSettings; }, (error: any) => { if (error.status === 304) { diff --git a/dashboard/src/components/api/workspace/workspace-data-manager.ts b/dashboard/src/components/api/workspace/workspace-data-manager.ts index 1c37f449a73f..c68665da8035 100644 --- a/dashboard/src/components/api/workspace/workspace-data-manager.ts +++ b/dashboard/src/components/api/workspace/workspace-data-manager.ts @@ -114,6 +114,7 @@ export class WorkspaceDataManager { if (workspace.config) { workspace.config.commands.push(command); } else if (workspace.devfile) { + workspace.devfile.commands = workspace.devfile.commands || []; workspace.devfile.commands.push(command); } } diff --git a/dashboard/src/components/typings/che.d.ts b/dashboard/src/components/typings/che.d.ts index 32fdad7d4094..93e027e45130 100755 --- a/dashboard/src/components/typings/che.d.ts +++ b/dashboard/src/components/typings/che.d.ts @@ -304,6 +304,7 @@ declare namespace che { export interface IWorkspaceSettings { supportedRecipeTypes: string; cheWorkspacePluginRegistryUrl: string; + devfileRegistry?: string; [propName: string]: string | boolean; }