From bc8b96812140d163112af3a231aea4d98c1ec108 Mon Sep 17 00:00:00 2001 From: Mohit Suman Date: Mon, 22 Jul 2019 22:53:37 +0530 Subject: [PATCH 1/2] provide context folder if no workspace present --- src/odo.ts | 5 +++-- src/openshift/component.ts | 31 ++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/odo.ts b/src/odo.ts index 0665befaa..96d3c3954 100644 --- a/src/odo.ts +++ b/src/odo.ts @@ -805,9 +805,10 @@ export class OdoImpl implements Odo { return this.insertAndReveal(new OpenShiftObjectImpl(project, applicationName, ContextType.APPLICATION, false, this)); } - public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, ref: string = 'master'): Promise { + public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise { await this.execute(Command.createLocalComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath), location.fsPath); await this.executeInTerminal(Command.pushComponent(), location.fsPath); + workspace.updateWorkspaceFolders(workspace.workspaceFolders? workspace.workspaceFolders.length : 0 , null, { uri: location }); return this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT_PUSHED, false, this, Collapsed, location, 'local')); } @@ -828,7 +829,7 @@ export class OdoImpl implements Odo { return null; } - public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri, ref: string = 'master'): Promise { + public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise { await this.execute(Command.createBinaryComponent(application.getParent().getName(), application.getName(), type, version, name, location.fsPath)); return this.insertAndReveal(new OpenShiftObjectImpl(application, name, ContextType.COMPONENT, false, this, Collapsed, undefined, 'binary')); } diff --git a/src/openshift/component.ts b/src/openshift/component.ts index d36ac957d..f97146ffc 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -5,7 +5,7 @@ import { OpenShiftItem } from './openshiftItem'; import { OpenShiftObject, Command, ContextType } from '../odo'; -import { window, commands, QuickPickItem, Uri } from 'vscode'; +import { window, commands, QuickPickItem, Uri, workspace, WorkspaceFolder } from 'vscode'; import { Progress } from '../util/progress'; import open = require('open'); import { ChildProcess } from 'child_process'; @@ -243,11 +243,30 @@ export class Component extends OpenShiftItem { static async createFromLocal(context: OpenShiftObject): Promise { let application: OpenShiftObject = context; + let folder: WorkspaceFolder | Uri[]; + let workspacePath: Uri; if (!application) application = await Component.getOpenshiftData(context); if (!application) return null; - const folder = await window.showWorkspaceFolderPick({ - placeHolder: 'Select the target workspace folder' - }); + if (workspace.workspaceFolders) { + folder = await window.showWorkspaceFolderPick({ + placeHolder: 'Select the target workspace folder' + }); + if (folder) { + workspacePath = folder.uri; + } + } else { + folder = await window.showOpenDialog({ + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: false, + defaultUri: Uri.file(Platform.getUserHomePath()), + openLabel: "Select Context Folder for Component" + }); + if (folder) { + workspacePath = folder[0]; + } + } + if (!folder) return null; const componentList: Array = await Component.odo.getComponents(application); const componentName = await Component.getName('Component name', componentList, application.getName()); @@ -261,7 +280,7 @@ export class Component extends OpenShiftItem { const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version"}); if (!componentTypeVersion) return null; - await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, folder.uri)); + await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, workspacePath)); return `Component '${componentName}' successfully created`; } @@ -333,6 +352,8 @@ export class Component extends OpenShiftItem { openLabel: "Select Context Folder for Component" }); + if (!folder) return null; + window.showInformationMessage('Do you want to clone git repository for created Component?', 'Yes', 'No').then((value) => { value === 'Yes' && commands.executeCommand('git.clone', repoURI); }); From 3d161b65851bf132f4ed2b6b62f9e9c09efd0a7f Mon Sep 17 00:00:00 2001 From: Mohit Suman Date: Thu, 25 Jul 2019 23:01:23 +0530 Subject: [PATCH 2/2] add workspace folder action if no workspace present --- src/openshift/component.ts | 48 +++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/openshift/component.ts b/src/openshift/component.ts index d7d7b9f73..9835efa8a 100644 --- a/src/openshift/component.ts +++ b/src/openshift/component.ts @@ -18,11 +18,9 @@ import { contextGlobalState } from '../extension'; import { Platform } from '../util/platform'; import path = require('path'); import fs = require('fs-extra'); - interface WorkspaceFolderItem extends QuickPickItem { uri: Uri; } - class CreateWorkspaceItem implements QuickPickItem { constructor() { } @@ -31,7 +29,6 @@ class CreateWorkspaceItem implements QuickPickItem { get description(): string { return 'Folder which does not have an openshift context'; } } - export class Component extends OpenShiftItem { static async getOpenshiftData(context: OpenShiftObject): Promise { @@ -281,30 +278,39 @@ export class Component extends OpenShiftItem { static async createFromLocal(context: OpenShiftObject): Promise { let application: OpenShiftObject = context; + let folder: WorkspaceFolderItem[]; + if (!application) application = await Component.getOpenshiftData(context); if (!application) return null; - let folder: WorkspaceFolderItem; if (workspace.workspaceFolders && workspace.workspaceFolders.length > 0) { - folder = await window.showQuickPick( - (async (): Promise => workspace.workspaceFolders.filter( - (value) => { - let result = true; - try { - result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile(); - } catch (ignore) { - } - return result; + folder = workspace.workspaceFolders.filter( + (value) => { + let result = true; + try { + result = !fs.statSync(path.join(value.uri.fsPath, '.odo', 'config.yaml')).isFile(); + } catch (ignore) { } - ).map( - (folder) => ({ label: folder.uri.fsPath, uri: folder.uri}) - ))(), { - placeHolder: 'Select workspace folder' + return result; } + ).map( + (folder) => ({ label: `$(file-directory) ${folder.uri.fsPath}`, uri: folder.uri }) ); - } else { - window.showInformationMessage('Workspace is empty. Please, add folder(s) to workspace and try again.'); } - if (!folder) return null; + const addWorkspaceFolder = new CreateWorkspaceItem(); + const choice = await window.showQuickPick([addWorkspaceFolder, ...folder], {placeHolder: "Select workspace folder"}); + + if (!choice) return null; + const workspacePath: Uri = (choice.label === addWorkspaceFolder.label) ? + await window.showOpenDialog({ + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: false, + defaultUri: Uri.file(Platform.getUserHomePath()), + openLabel: "Add workspace Folder for Component" + })[0] : folder[0].uri; + + if (!workspacePath) return null; + const componentList: Array = await Component.odo.getComponents(application); const componentName = await Component.getName('Component name', componentList, application.getName()); @@ -317,7 +323,7 @@ export class Component extends OpenShiftItem { const componentTypeVersion = await window.showQuickPick(Component.odo.getComponentTypeVersions(componentTypeName), {placeHolder: "Component type version"}); if (!componentTypeVersion) return null; - await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, folder.uri)); + await Progress.execFunctionWithProgress(`Creating new Component '${componentName}'`, () => Component.odo.createComponentFromFolder(application, componentTypeName, componentTypeVersion, componentName, workspacePath)); return `Component '${componentName}' successfully created`; }