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 2022/12/01 20:03:28 UTC

[camel-karavan] branch main updated: Fix #537

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 5b3a691  Fix #537
5b3a691 is described below

commit 5b3a69198d7763ed8a84fe3e21b7c1be04e6bd2a
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Thu Dec 1 14:30:14 2022 -0500

    Fix #537
---
 karavan-vscode/src/designerView.ts   | 25 +++++++++++++---------
 karavan-vscode/src/helpView.ts       |  5 +++--
 karavan-vscode/src/webviewContent.ts | 40 ++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 12 deletions(-)

diff --git a/karavan-vscode/src/designerView.ts b/karavan-vscode/src/designerView.ts
index 1be8c9d..61ccd86 100644
--- a/karavan-vscode/src/designerView.ts
+++ b/karavan-vscode/src/designerView.ts
@@ -14,12 +14,13 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-import { workspace, Uri, window, commands, WebviewPanel, ExtensionContext, ViewColumn, WebviewPanelOnDidChangeViewStateEvent, FileType } from "vscode";
+import {Uri, window, commands, WebviewPanel, ExtensionContext, ViewColumn, WebviewPanelOnDidChangeViewStateEvent } from "vscode";
 import * as path from "path";
 import * as utils from "./utils";
 import * as jbang from "./jbang";
 import { CamelDefinitionYaml } from "core/api/CamelDefinitionYaml";
 import { Integration } from "core/model/IntegrationDefinition";
+import { getWebviewContent } from "./webviewContent";
 
 const KARAVAN_LOADED = "karavan:loaded";
 const KARAVAN_PANELS: Map<string, WebviewPanel> = new Map<string, WebviewPanel>();
@@ -27,7 +28,7 @@ const extension = '.properties';
 
 export class DesignerView {
 
-    constructor(private context: ExtensionContext, private webviewContent: string, private rootPath?: string) {
+    constructor(private context: ExtensionContext, private rootPath?: string) {
 
     }
 
@@ -102,7 +103,6 @@ export class DesignerView {
     }
 
     openKaravanWebView(filename: string, relativePath: string, fullPath: string, yaml?: string, tab?: string) {
-        console.log("openKaravanWebView");
         if (!KARAVAN_PANELS.has(relativePath)) {
             // Karavan webview
             const panel = window.createWebviewPanel(
@@ -117,7 +117,7 @@ export class DesignerView {
                     ],
                 }
             );
-            panel.webview.html = this.webviewContent;
+            panel.webview.html = getWebviewContent(this.context, panel.webview);
             panel.iconPath = Uri.joinPath(
                 this.context.extensionUri,
                 "icons/karavan.svg"
@@ -128,8 +128,10 @@ export class DesignerView {
                 message => {
                     switch (message.command) {
                         case 'save':
-                            console.log("save", message);
-                            utils.save(message.relativePath, message.yaml);
+                            utils.save(message.relativePath, message.code);
+                            break;
+                        case 'saveCode':
+                            utils.saveCode(message.name, message.yamlFullPath, message.yamFileName, message.code);
                             break;
                         case 'getData':
                             this.sendData(panel, filename, relativePath, fullPath, message.reread === true, yaml, tab);
@@ -146,7 +148,6 @@ export class DesignerView {
 
             // Handle reopen
             panel.onDidChangeViewState((e: WebviewPanelOnDidChangeViewStateEvent) => {
-                console.log(e);
                 if (e.webviewPanel.active) {
                     e.webviewPanel.webview.postMessage({ command: 'activate', tab: tab });
                 } else {
@@ -168,12 +169,16 @@ export class DesignerView {
             // Read Kamelets
             utils.readKamelets(this.context),
             // Read components
-            utils.readComponents(this.context)
+            utils.readComponents(this.context),
+            // Read templates
+            utils.readTemplates(this.context)
         ]).then(results => {
             // Send Kamelets
             panel.webview.postMessage({ command: 'kamelets', kamelets: results[0] });
             // Send components
             panel.webview.postMessage({ command: 'components', components: results[1] });
+            // Send templates
+            panel.webview.postMessage({ command: 'templates', templates: Object.fromEntries(results[2]) });
             // Send integration
             this.sendIntegrationData(panel, filename, relativePath, fullPath, reread, yaml, tab);
         })
@@ -185,11 +190,11 @@ export class DesignerView {
             utils.readFile(path.resolve(fullPath)).then(readData => {
                 const yaml = Buffer.from(readData).toString('utf8');
                 // Send integration
-                panel.webview.postMessage({ command: 'open', page: "designer", filename: filename, relativePath: relativePath, yaml: yaml, tab: tab });
+                panel.webview.postMessage({ command: 'open', page: "designer", filename: filename, relativePath: relativePath, fullPath:fullPath, yaml: yaml, tab: tab });
             });
         } else {
             // Send integration
-            panel.webview.postMessage({ command: 'open', page: "designer", filename: filename, relativePath: relativePath, yaml: yaml, tab: tab });
+            panel.webview.postMessage({ command: 'open', page: "designer", filename: filename, relativePath: relativePath, fullPath:fullPath, yaml: yaml, tab: tab });
         }
 
     }
diff --git a/karavan-vscode/src/helpView.ts b/karavan-vscode/src/helpView.ts
index 70dec55..59fb58a 100644
--- a/karavan-vscode/src/helpView.ts
+++ b/karavan-vscode/src/helpView.ts
@@ -17,12 +17,13 @@
 import * as vscode from "vscode";
 import * as utils from "./utils";
 import { ThemeIcon } from "vscode";
+import { getWebviewContent } from "./webviewContent";
 
 const KARAVAN_PANELS: Map<string, vscode.WebviewPanel> = new Map<string, vscode.WebviewPanel>();
 
 export class HelpView implements vscode.TreeDataProvider<HelpItem> {
 
-	constructor(private context: vscode.ExtensionContext, private webviewContent: string) {
+	constructor(private context: vscode.ExtensionContext) {
 
 	}
 	private _onDidChangeTreeData: vscode.EventEmitter<HelpItem | undefined | void> = new vscode.EventEmitter<HelpItem | undefined | void>();
@@ -59,7 +60,7 @@ export class HelpView implements vscode.TreeDataProvider<HelpItem> {
 					],
 				}
 			);
-			panel.webview.html = this.webviewContent;
+			panel.webview.html = getWebviewContent(this.context, panel.webview);
 			panel.iconPath = vscode.Uri.joinPath(
 				this.context.extensionUri,
 				"icons/karavan.svg"
diff --git a/karavan-vscode/src/webviewContent.ts b/karavan-vscode/src/webviewContent.ts
new file mode 100644
index 0000000..5dbe210
--- /dev/null
+++ b/karavan-vscode/src/webviewContent.ts
@@ -0,0 +1,40 @@
+import { ExtensionContext, Uri, Webview } from "vscode";
+
+
+export function getWebviewContent(context: ExtensionContext, webview: Webview): string {
+    const styleUri = getUri(webview, context.extensionUri, "/dist/main.css").toString()
+        const scriptUri = getUri(webview, context.extensionUri, "/dist/webview.js").toString()
+        
+        return `<!DOCTYPE html>
+        <html lang="en">
+        
+        <head>
+          <meta charset="utf-8" />
+          <meta name="viewport" content="width=device-width, initial-scale=1" />
+          <link href="${styleUri}" rel="stylesheet" type="text/css" />
+        </head>
+        
+        <body>
+          <noscript>You need to enable JavaScript to run this app.</noscript>
+          <div id="root">
+            <div class="pf-c-page karavan">
+              <main class="pf-c-page__main" tabindex="-1">
+                <section class="pf-c-page__main-section pf-m-dark-200 loading-page"><svg
+                    class="pf-c-spinner pf-m-xl progress-stepper" role="progressbar" aria-valuetext="Loading..."
+                    viewBox="0 0 100 100" style="--pf-c-spinner--diameter:80px" aria-label="Loading...">
+                    <circle class="pf-c-spinner__path" cx="50" cy="50" r="45" fill="none"></circle>
+                  </svg></section>
+              </main>
+            </div>
+          </div>
+          <script>
+          </script>
+          <script src="${scriptUri}"></script>
+        </body>
+        
+        </html>`;
+}
+
+function getUri(webview: Webview, extensionUri: Uri, path: string) {
+    return webview.asWebviewUri(Uri.joinPath(extensionUri, path));
+}
\ No newline at end of file