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: 6 additions & 0 deletions src/serverlessFunction/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export class ServerlessCommand {
return commandText
}

static getTemplates(): CommandText {
const commandText = new CommandText('func', 'templates');
commandText.addOption(new CommandOption('--json'))
return commandText
}

static getClusterVersion(): CommandText {
return new CommandText('oc get clusterversion', undefined, [
new CommandOption('-o', 'josn')
Expand Down
9 changes: 9 additions & 0 deletions src/serverlessFunction/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import validator from 'validator';
import { commands, EventEmitter, Terminal, Uri, window } from 'vscode';
import { CliChannel } from '../cli';
import { OdoImpl } from '../odo';
import { CliExitData } from '../util/childProcessUtil';
import { Platform } from '../util/platform';
import { Progress } from '../util/progress';
import { ServerlessCommand, Utils } from './commands';
Expand Down Expand Up @@ -229,6 +230,14 @@ export class Functions {
});
}

public async getTemplates(): Promise<CliExitData> {
const result = await OdoImpl.Instance.execute(ServerlessCommand.getTemplates(), undefined, false);
if (result.error) {
void window.showErrorMessage(result.error.message);
}
return JSON.parse(result.stdout);
}

public async deploy(context: FunctionObject) {
const currentNamespace: string = await OdoImpl.Instance.getActiveProject();
const yamlContent = await Utils.getFuncYamlContent(context.folderURI.fsPath);
Expand Down
23 changes: 13 additions & 10 deletions src/webview/serverless-function/app/createFunction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
helpText?: string
},
images: string[],
baseTemplates: string[],
templates: string[],
language: string,
template: string,
Expand All @@ -52,6 +53,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
helpText: `Image name should be in the form of '[registry]/[namespace]/[name]:[tag]'`
},
images: [],
baseTemplates: [],
templates: [],
language: '',
template: '',
Expand All @@ -60,7 +62,7 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
showLoadScreen: false
}
VSCodeMessage.postMessage({
action: 'selectFolder'
action: 'getTemplates'
});
}

Expand Down Expand Up @@ -98,6 +100,13 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {
wsFolderItems: message.data.wsFolderItems
});
}
} else if (message.data.action === 'getTemplates') {
this.setState({
baseTemplates: message.data.basicTemplates
});
VSCodeMessage.postMessage({
action: 'selectFolder'
});
}
});
}
Expand Down Expand Up @@ -129,15 +138,9 @@ export class CreateFunction extends React.Component<CreateFunctionPageProps, {

handleDropDownChange = (_event: any, value: string, isLang = false): void => {
if (isLang) {
if (value !== 'Python') {
this.setState({
templates: ['Cloud Events', 'HTTP']
});
} else {
this.setState({
templates: ['Cloud Events', 'Flask', 'HTTP', 'WSGI']
})
}
this.setState({
templates: this.state.baseTemplates[this.convert(value)]
});
this.setState({
language: value,
template: ''
Expand Down
6 changes: 6 additions & 0 deletions src/webview/serverless-function/serverlessFunctionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ async function messageListener(panel: vscode.WebviewPanel, event: any): Promise<
await Functions.getInstance().invoke(functionName, invokeFunData);
panel.dispose();
break;
case 'getTemplates':
const templates = await Functions.getInstance().getTemplates();
panel?.webview.postMessage({
action: eventName,
basicTemplates: templates
})
default:
break;
}
Expand Down