You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2021/12/17 17:09:46 UTC
[camel-karavan] branch main updated: Fixed #148 (#149)
This is an automated email from the ASF dual-hosted git repository.
marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push:
new c6d8b42 Fixed #148 (#149)
c6d8b42 is described below
commit c6d8b42f34680f64efc2d6a0f7fe2f511441f98d
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Fri Dec 17 12:09:42 2021 -0500
Fixed #148 (#149)
---
karavan-vscode/src/extension.ts | 25 ++++++++++++++++---------
karavan-vscode/webview/App.tsx | 6 ------
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/karavan-vscode/src/extension.ts b/karavan-vscode/src/extension.ts
index 139e62a..5c01970 100644
--- a/karavan-vscode/src/extension.ts
+++ b/karavan-vscode/src/extension.ts
@@ -24,7 +24,7 @@ import { Integration } from "../designer/model/CamelModel";
import { homedir } from "os";
const KARAVAN_LOADED = "karavan:loaded";
-const KARAVAN_PANELS: Map<any, string> = new Map<string, string>();
+const KARAVAN_PANELS: Map<string, vscode.WebviewPanel> = new Map<string, vscode.WebviewPanel>();
const TERMINALS: Map<string, vscode.Terminal> = new Map<string, vscode.Terminal>();
export function activate(context: vscode.ExtensionContext) {
@@ -61,9 +61,10 @@ export function activate(context: vscode.ExtensionContext) {
if (args && args.length > 0) {
const yaml = fs.readFileSync(path.resolve(args[0].path)).toString('utf8');
const filename = path.basename(args[0].path);
+ const relativePath = getRalativePath(args[0].path);
const integration = parceYaml(filename, yaml);
if (integration[0]) {
- openKaravanWebView(context, webviewContent, filename || '', integration[1]);
+ openKaravanWebView(context, webviewContent, filename, relativePath, integration[1]);
} else {
vscode.window.showErrorMessage("File is not Camel Integration!")
}
@@ -78,16 +79,17 @@ export function activate(context: vscode.ExtensionContext) {
(...args: any[]) => {
if (args && args.length > 0) {
if (args[0].path.startsWith('webview-panel/webview')) {
- const filename = KARAVAN_PANELS.get(args[0].path);
+ const filename = Array.from(KARAVAN_PANELS.entries()).filter(({ 1: v }) => v.active).map(([k]) => k)[0];
if (filename) {
runCamelJbang(filename);
}
} else {
const yaml = fs.readFileSync(path.resolve(args[0].path)).toString('utf8');
+ const relativePath = getRalativePath(args[0].path);
const filename = path.basename(args[0].path);
const integration = parceYaml(filename, yaml);
if (integration[0]) {
- runCamelJbang(filename);
+ runCamelJbang(relativePath);
} else {
vscode.window.showErrorMessage("File is not Camel-K Integration!")
}
@@ -98,7 +100,7 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(run);
}
-function openKaravanWebView(context: vscode.ExtensionContext, webviewContent: string, filename: string, yaml?: string) {
+function openKaravanWebView(context: vscode.ExtensionContext, webviewContent: string, filename: string, relativePath: string, yaml?: string) {
// Karavan webview
const panel = vscode.window.createWebviewPanel(
"karavan",
@@ -112,7 +114,6 @@ function openKaravanWebView(context: vscode.ExtensionContext, webviewContent: st
],
}
);
-
panel.webview.html = webviewContent;
panel.iconPath = vscode.Uri.joinPath(
context.extensionUri,
@@ -142,13 +143,12 @@ function openKaravanWebView(context: vscode.ExtensionContext, webviewContent: st
});
}
return;
- case 'url-mapping':
- KARAVAN_PANELS.set('webview-panel/webview-' + message.pathId, message.filename);
}
},
undefined,
context.subscriptions
);
+ KARAVAN_PANELS.set(relativePath, panel);
vscode.commands.executeCommand("setContext", KARAVAN_LOADED, true);
}
@@ -171,11 +171,18 @@ function createIntegration(context: vscode.ExtensionContext, webviewContent: str
const i = Integration.createNew(name);
i.crd = crd;
const yaml = CamelYaml.integrationToYaml(i);
- openKaravanWebView(context, webviewContent, name + '.yaml', yaml);
+ const filename = name.toLocaleLowerCase().endsWith('.yaml') ? name : name + '.yaml';
+ openKaravanWebView(context, webviewContent, filename, filename, yaml);
}
});
}
+function getRalativePath(fullPath:string): string {
+ const root = vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0].uri.path : "";
+ const relativePath = path.resolve(fullPath).replace(root + path.sep, '');
+ return relativePath;
+}
+
function readKamelets(context: vscode.ExtensionContext): string[] {
const dir = path.join(context.extensionPath, 'kamelets');
const yamls: string[] = fs.readdirSync(dir).filter(file => file.endsWith("yaml")).map(file => fs.readFileSync(dir + "/" + file, 'utf-8'));
diff --git a/karavan-vscode/webview/App.tsx b/karavan-vscode/webview/App.tsx
index a7878f9..0b568e3 100644
--- a/karavan-vscode/webview/App.tsx
+++ b/karavan-vscode/webview/App.tsx
@@ -55,18 +55,12 @@ class App extends React.Component<Props, State> {
case 'open':
if (this.state.filename === '' && this.state.key === ''){
this.setState({filename: message.filename, yaml: message.yaml, key: Math.random().toString()});
- this.sendUrlMapping(message.filename)
}
break;
}
});
}
- sendUrlMapping(filename: string){
- const url = new URL(window.location.href)
- vscode.postMessage({ command: 'url-mapping', pathId: url.host, filename: filename })
- }
-
save(filename: string, yaml: string) {
vscode.postMessage({
command: 'save',