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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"git-transport-protocol": "^0.1.0",
"globby": "^10.0.1",
"js-yaml": "^3.13.1",
"minimatch": "^3.0.4",
"mkdirp": "^0.5.1",
"openshift-rest-client": "^4.0.0",
"rxjs": "^6.5.3",
Expand Down
5 changes: 1 addition & 4 deletions src/oc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ export class Oc {
if (message) {
window.showWarningMessage(message);
} else {
const project = await OpenShiftItem.getOpenShiftCmdData(
undefined,
'Select a Project where to create a new resource',
);
const project = await OpenShiftItem.getOpenShiftCmdData(undefined);
if (!project) return null;
const result = await CliChannel.getInstance().execute(
`${toolLocation} create -f ${document.fileName} --namespace ${project.getName()}`,
Expand Down
51 changes: 31 additions & 20 deletions src/odo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {Collapsed} = TreeItemCollapsibleState;
export interface OpenShiftObject extends QuickPickItem {
getChildren(): ProviderResult<OpenShiftObject[]>;
removeChild(item: OpenShiftObject): Promise<void>;
addChild(item: OpenShiftObject): Promise<OpenShiftObject>;
getParent(): OpenShiftObject;
getName(): string;
contextValue: ContextType;
Expand All @@ -60,6 +61,21 @@ export enum ContextType {
COMPONENT_ROUTE = 'componentRoute'
}

function compareNodes(a: OpenShiftObject, b: OpenShiftObject): number {
if (!a.contextValue) return -1;
if (!b.contextValue) return 1;
const acontext = a.contextValue.includes('_') ? a.contextValue.substr(0, a.contextValue.indexOf('_')) : a.contextValue;
const bcontext = b.contextValue.includes('_') ? b.contextValue.substr(0, b.contextValue.indexOf('_')) : b.contextValue;
const t = acontext.localeCompare(bcontext);
return t || a.label.localeCompare(b.label);
}

function insert(array: OpenShiftObject[], item: OpenShiftObject): OpenShiftObject {
const i = bs(array, item, compareNodes);
array.splice(Math.abs(i)-1, 0, item);
return item;
}

export abstract class OpenShiftObjectImpl implements OpenShiftObject {

private explorerPath: string;
Expand Down Expand Up @@ -129,6 +145,11 @@ export abstract class OpenShiftObjectImpl implements OpenShiftObject {
array.splice(array.indexOf(item), 1);
}

public async addChild(item: OpenShiftObject): Promise<OpenShiftObject> {
const array = await item.getChildren();
return insert(array, item);
}

getParent(): OpenShiftObject {
return this.parent;
}
Expand All @@ -150,13 +171,19 @@ export class OpenShiftCluster extends OpenShiftObjectImpl {
}

async getChildren(): Promise<OpenShiftObject[]> {
return [(await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active)];
const activeProject = (await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active)
return activeProject ? [activeProject] : [];
}

public async removeChild(item: OpenShiftObject): Promise<void> {
const array = await this.odo.getProjects();
array.splice(array.indexOf(item), 1);
}

public async addChild(item: OpenShiftObject): Promise<OpenShiftObject> {
const array = await this.odo.getProjects();
return insert(array, item);
}
}

export class OpenShiftProject extends OpenShiftObjectImpl {
Expand Down Expand Up @@ -336,15 +363,6 @@ export interface Odo {
readonly subject: Subject<OdoEvent>;
}

function compareNodes(a: OpenShiftObject, b: OpenShiftObject): number {
if (!a.contextValue) return -1;
if (!b.contextValue) return 1;
const acontext = a.contextValue.includes('_') ? a.contextValue.substr(0, a.contextValue.indexOf('_')) : a.contextValue;
const bcontext = b.contextValue.includes('_') ? b.contextValue.substr(0, b.contextValue.indexOf('_')) : b.contextValue;
const t = acontext.localeCompare(bcontext);
return t || a.label.localeCompare(b.label);
}

class OdoModel {
private parentToChildren: Map<OpenShiftObject, OpenShiftObject[]> = new Map();

Expand Down Expand Up @@ -756,21 +774,15 @@ export class OdoImpl implements Odo {
return this.odoLoginMessages.some((msg) => result.stderr.includes(msg));
}

private insert(array: OpenShiftObject[], item: OpenShiftObject): OpenShiftObject {
const i = bs(array, item, compareNodes);
array.splice(Math.abs(i)-1, 0, item);
return item;
}

private async insertAndReveal(item: OpenShiftObject): Promise<OpenShiftObject> {
// await OpenShiftExplorer.getInstance().reveal(this.insert(await item.getParent().getChildren(), item));
this.subject.next(new OdoEventImpl('inserted', this.insert(await item.getParent().getChildren(), item), true));
this.subject.next(new OdoEventImpl('inserted', await item.getParent().addChild(item), true));
return item;
}

private async insertAndRefresh(item: OpenShiftObject): Promise<OpenShiftObject> {
// await OpenShiftExplorer.getInstance().refresh(this.insert(await item.getParent().getChildren(), item).getParent());
this.subject.next(new OdoEventImpl('changed', this.insert(await item.getParent().getChildren(), item).getParent()));
this.subject.next(new OdoEventImpl('changed', (await item.getParent().addChild(item)).getParent()));
return item;
}

Expand All @@ -789,8 +801,7 @@ export class OdoImpl implements Odo {
public async createProject(projectName: string): Promise<OpenShiftObject> {
await OdoImpl.instance.execute(Command.createProject(projectName));
const clusters = await this.getClusters();
this.subject.next(new OdoEventImpl('inserted', clusters[0], false));
return new OpenShiftProject(clusters[0], projectName, true);
return this.insertAndReveal(new OpenShiftProject(clusters[0], projectName, true));
}

public async deleteApplication(app: OpenShiftObject): Promise<OpenShiftObject> {
Expand Down
2 changes: 0 additions & 2 deletions src/openshift/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ export class Application extends OpenShiftItem {
@vsCommand('openshift.app.describe', true)
static async describe(treeItem: OpenShiftObject): Promise<void> {
const application = await Application.getOpenShiftCmdData(treeItem,
"From which project you want to describe Application",
"Select Application you want to describe");
if (application) Application.odo.executeInTerminal(Command.describeApplication(application.getParent().getName(), application.getName()), undefined, `OpenShift: Describe '${application.getName()}' Application`);
}

@vsCommand('openshift.app.delete', true)
static async del(treeItem: OpenShiftObject): Promise<string> {
const application = await Application.getOpenShiftCmdData(treeItem,
"From which Project you want to delete Application",
"Select Application to delete");
if (application) {
const appName = application.getName();
Expand Down
21 changes: 1 addition & 20 deletions src/openshift/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,12 @@ export class Component extends OpenShiftItem {

static async getOpenshiftData(context: OpenShiftObject): Promise<OpenShiftObject> {
return Component.getOpenShiftCmdData(context,
"In which Project you want to create a Component",
"In which Application you want to create a Component"
);
}

@vsCommand('openshift.component.create')
@selectTargetApplication(
"In which Project you want to create a Component",
"In which Application you want to create a Component"
)
static async create(application: OpenShiftObject): Promise<string> {
Expand Down Expand Up @@ -125,7 +123,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.delete', true)
@selectTargetComponent(
"From which Project do you want to delete Component",
"From which Application you want to delete Component",
"Select Component to delete"
)
Expand All @@ -150,7 +147,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.undeploy', true)
@selectTargetComponent(
"From which Project do you want to undeploy Component",
"From which Application you want to undeploy Component",
"Select Component to undeploy",
(target) => target.contextValue === ContextType.COMPONENT_PUSHED
Expand Down Expand Up @@ -202,7 +198,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.describe', true)
@selectTargetComponent(
"From which Project you want to describe Component",
"From which Application you want to describe Component",
"Select Component you want to describe"
)
Expand All @@ -223,7 +218,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.log', true)
@selectTargetComponent(
"In which Project you want to see Log",
"In which Application you want to see Log",
"For which Component you want to see Log",
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED
Expand All @@ -242,7 +236,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.followLog', true)
@selectTargetComponent(
"In which Project you want to follow Log",
"In which Application you want to follow Log",
"For which Component you want to follow Log",
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED
Expand Down Expand Up @@ -291,7 +284,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.unlinkComponent.palette')
@selectTargetComponent(
'Select a Project',
'Select an Application',
'Select a Component',
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED
Expand Down Expand Up @@ -323,7 +315,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.unlinkService.palette')
@selectTargetComponent(
'Select a Project',
'Select an Application',
'Select a Component',
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED
Expand All @@ -349,7 +340,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.linkComponent')
@selectTargetComponent(
'Select a Project',
'Select an Application',
'Select a Component',
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED
Expand Down Expand Up @@ -391,7 +381,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.linkService')
@selectTargetComponent(
'Select a Project',
'Select an Application',
'Select a Component',
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED
Expand Down Expand Up @@ -419,7 +408,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.push', true)
@selectTargetComponent(
'In which Project you want to push the changes',
'In which Application you want to push the changes',
'For which Component you want to push the changes',
(target) => target.contextValue === ContextType.COMPONENT_PUSHED || target.contextValue === ContextType.COMPONENT
Expand Down Expand Up @@ -454,7 +442,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.watch', true)
@selectTargetComponent(
'Select a Project',
'Select an Application',
'Select a Component you want to watch',
(target) => target.contextValue === ContextType.COMPONENT_PUSHED
Expand Down Expand Up @@ -491,7 +478,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.openUrl', true)
@selectTargetComponent(
'Select a Project',
'Select an Application',
'Select a Component to open in browser',
(target) => target.contextValue === ContextType.COMPONENT_PUSHED
Expand Down Expand Up @@ -533,8 +519,7 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.createFromLocal')
@selectTargetApplication(
"In which Project you want to create a Component",
"In which Application you want to create a Component"
"Select an Application where you want to create a Component"
)
static async createFromLocal(application: OpenShiftObject): Promise<string | null> {
if (!application) return null;
Expand All @@ -559,7 +544,6 @@ export class Component extends OpenShiftItem {

static async createFromFolder(folder: Uri): Promise<string | null> {
const application = await Component.getOpenShiftCmdData(undefined,
"In which Project you want to create a Component",
"In which Application you want to create a Component"
);
if (!application) return null;
Expand All @@ -582,7 +566,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.createFromGit')
@selectTargetApplication(
"In which Project you want to create a Component",
"In which Application you want to create a Component"
)
static async createFromGit(application: OpenShiftObject): Promise<string | null> {
Expand Down Expand Up @@ -630,7 +613,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.createFromBinary')
@selectTargetApplication(
"In which Project you want to create a Component",
"In which Application you want to create a Component"
)
static async createFromBinary(application: OpenShiftObject): Promise<string | null> {
Expand Down Expand Up @@ -670,7 +652,6 @@ export class Component extends OpenShiftItem {

@vsCommand('openshift.component.debug', true)
@selectTargetComponent(
'Select a Project',
'Select an Application',
'Select a Component you want to debug (showing only Components pushed to the cluster)',
(value: OpenShiftObject) => value.contextValue === ContextType.COMPONENT_PUSHED
Expand Down
20 changes: 13 additions & 7 deletions src/openshift/openshiftItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

import { window, QuickPickItem } from 'vscode';
import * as validator from 'validator';
import { Odo, OdoImpl, OpenShiftObject, ContextType, OpenShiftApplication } from '../odo';
import { Odo, OdoImpl, OpenShiftObject, ContextType, OpenShiftApplication, OpenShiftProject } from '../odo';
import { OpenShiftExplorer } from '../explorer';
import { VsCommandError } from '../vscommand';

const errorMessage = {
Project: 'You need at least one Project available. Please create new OpenShift Project and try again.',
Expand Down Expand Up @@ -125,10 +126,15 @@ export default class OpenShiftItem {
return urlList;
}

static async getOpenShiftCmdData(treeItem: OpenShiftObject, projectPlaceholder: string, appPlaceholder?: string, compPlaceholder?: string, condition?: (value: OpenShiftObject) => boolean): Promise<OpenShiftObject | null> {
static async getOpenShiftCmdData(treeItem: OpenShiftObject, appPlaceholder?: string, compPlaceholder?: string, condition?: (value: OpenShiftObject) => boolean): Promise<OpenShiftObject | null> {
let context: OpenShiftObject | QuickPickCommand = treeItem;
let project: OpenShiftObject;
if (!context) context = await window.showQuickPick(OpenShiftItem.getProjectNames(), {placeHolder: projectPlaceholder, ignoreFocusOut: true});
if (!context) {
context = (await this.odo.getProjects()).find((prj:OpenShiftProject)=>prj.active);
if (!context) {
throw new VsCommandError(errorMessage.Project);
}
}
if (context && context.contextValue === ContextType.PROJECT && appPlaceholder ) {
project = context;
context = await window.showQuickPick<OpenShiftObject | QuickPickCommand>(OpenShiftItem.getApplicationNames(project, appPlaceholder.includes('create') && compPlaceholder === undefined), {placeHolder: appPlaceholder, ignoreFocusOut: true});
Expand Down Expand Up @@ -165,10 +171,10 @@ function selectTargetDecoratorFactory(decorator: (...args:any[]) => Promise<Open
};
}

export function selectTargetComponent(prjPlaceHolder, appPlaceHolder, cmpPlaceHolder, condition?: (value: OpenShiftObject) => boolean) {
return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, prjPlaceHolder, appPlaceHolder, cmpPlaceHolder, condition));
export function selectTargetComponent(appPlaceHolder, cmpPlaceHolder, condition?: (value: OpenShiftObject) => boolean) {
return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, appPlaceHolder, cmpPlaceHolder, condition));
}

export function selectTargetApplication(prjPlaceHolder, appPlaceHolder) {
return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, prjPlaceHolder, appPlaceHolder));
export function selectTargetApplication(appPlaceHolder) {
return selectTargetDecoratorFactory(async (context) => OpenShiftItem.getOpenShiftCmdData(context, appPlaceHolder));
}
4 changes: 1 addition & 3 deletions src/openshift/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ export class Project extends OpenShiftItem {
@vsCommand('openshift.project.delete', true)
static async del(context: OpenShiftObject): Promise<string> {
let result: Promise<string> = null;
const project = await Project.getOpenShiftCmdData(context,
"Select Project to delete"
);
const project = await Project.getOpenShiftCmdData(context);
if (project) {
const value = await window.showWarningMessage(`Do you want to delete Project '${project.getName()}'?`, 'Yes', 'Cancel');
if (value === 'Yes') {
Expand Down
Loading