Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,9 +806,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<OpenShiftObject> {
public async createComponentFromFolder(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise<OpenShiftObject> {
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 });
OdoImpl.data.addContexts([workspace.getWorkspaceFolder(location)]);
const targetApplication = (await this.getApplications(application.getParent())).find((value) => value === application);
if (!targetApplication) {
Expand All @@ -833,7 +834,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<OpenShiftObject> {
public async createComponentFromBinary(application: OpenShiftObject, type: string, version: string, name: string, location: Uri): Promise<OpenShiftObject> {
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'));
}
Expand Down
53 changes: 34 additions & 19 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ 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() { }

get label(): string { return `$(plus) Add new workspace folder.`; }
get description(): string { return 'Folder which does not have an openshift context'; }

}
export class Component extends OpenShiftItem {

static async getOpenshiftData(context: OpenShiftObject): Promise<OpenShiftObject> {
Expand Down Expand Up @@ -272,30 +278,39 @@ export class Component extends OpenShiftItem {

static async createFromLocal(context: OpenShiftObject): Promise<string> {
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<WorkspaceFolderItem[]> => 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<OpenShiftObject> = await Component.odo.getComponents(application);
const componentName = await Component.getName('Component name', componentList, application.getName());

Expand All @@ -308,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`;
}

Expand Down