From bdb004dff682fda190557ed2ae59207fcb1f9976 Mon Sep 17 00:00:00 2001 From: Oleksii Orel Date: Fri, 13 Sep 2019 10:58:04 +0300 Subject: [PATCH] Provide an ability to create workspaces from factories per user Signed-off-by: Oleksii Orel --- .../load-factory/load-factory.controller.ts | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/dashboard/src/app/factories/load-factory/load-factory.controller.ts b/dashboard/src/app/factories/load-factory/load-factory.controller.ts index 37c8c8042e..e48266ad1f 100644 --- a/dashboard/src/app/factories/load-factory/load-factory.controller.ts +++ b/dashboard/src/app/factories/load-factory/load-factory.controller.ts @@ -231,21 +231,26 @@ export class LoadFactoryController { * Detect workspace to start: create new one or get created one. */ getWorkspaceToStart(): void { - let createPolicy = (this.factory.policies) ? this.factory.policies.create : 'perClick'; + const createPolicy = this.factory.policies ? this.factory.policies.create : this.routeParams['policies.create'] || 'perClick'; let workspace = null; - switch (createPolicy) { - case 'perUser' : + switch (createPolicy.toLowerCase()) { + case 'peruser' : workspace = this.lodash.find(this.workspaces, (w: che.IWorkspace) => { - return this.factory.id === (w.attributes as any).factoryId; + if (this.factory.id) { + return this.factory.id === (w.attributes as any).factoryId; + } else if (this.routeParams.url){ + return this.routeParams.url === (w.attributes as any).factoryurl; + } + return false; }); break; - case 'perAccount' : + case 'peraccount' : // TODO when account is ready workspace = this.lodash.find(this.workspaces, (w: che.IWorkspace) => { return this.factory.workspace.name === w.config.name; }); break; - case 'perClick' : + case 'perclick' : break; } @@ -276,35 +281,27 @@ export class LoadFactoryController { * Create workspace from factory config. */ createWorkspace(): any { + let creationPromise: ng.IPromise; if (this.factory.workspace) { let config = this.factory.workspace; // set factory attribute: let attrs = {factoryId: this.factory.id}; config.name = this.getWorkspaceName(config.name); - // TODO: fix account when ready: - let creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromConfig(null, config, attrs); - creationPromise.then((data: any) => { - this.$timeout(() => { - this.startWorkspace(data); - }, 1000); - }, (error: any) => { - this.handleError(error); - }); + creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromConfig(null, config, attrs); } else if (this.factory.devfile) { let devfile = this.factory.devfile; - // set factory attribute: - let attrs = {factoryId: this.factory.id}; - - let creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromDevfile(null, devfile, attrs); - creationPromise.then((data: any) => { - this.$timeout(() => { - this.startWorkspace(data); - }, 1000); - }, (error: any) => { - this.handleError(error); - }); + // set devfile attribute: + let attrs = {factoryurl: this.routeParams.url}; + creationPromise = this.cheAPI.getWorkspace().createWorkspaceFromDevfile(null, devfile, attrs); } + creationPromise.then((data: any) => { + this.$timeout(() => { + this.startWorkspace(data); + }, 1000); + }, (error: any) => { + this.handleError(error); + }); } /**