• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / task-explorer / 824f15ba-8287-41d1-bca5-4458539101bd

30 Nov 2023 02:10PM UTC coverage: 95.583% (-0.4%) from 96.002%
824f15ba-8287-41d1-bca5-4458539101bd

Pull #328

circleci

Prijic, Nikola (PPN)
feat: migrating to Vue3 fix css problem
Pull Request #328: Vue3

534 of 551 branches covered (0.0%)

Branch coverage included in aggregate %.

7 of 10 new or added lines in 1 file covered. (70.0%)

1089 of 1147 relevant lines covered (94.94%)

10.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.38
/packages/tasks_panel/src/panels/abstract-webview-panel.ts
1
import { join, sep } from "path";
1✔
2
import { WebviewPanel, window, ViewColumn, Uri, commands } from "vscode";
1✔
3
import { getExtensionPath } from "../extension";
1✔
4
import * as cheerio from "cheerio";
1✔
5

6
export abstract class AbstractWebviewPanel<T> {
1✔
7
  public viewType = "";
33✔
8
  protected mediaPath: string;
9
  protected viewTitle = "";
33✔
10
  protected webViewPanel: WebviewPanel | undefined;
11
  protected focusedKey = "";
33✔
12
  protected htmlFileName: string;
13
  protected state: any;
14

15
  protected constructor(protected readonly readResource: (file: string) => Promise<string>) {
33✔
16
    this.mediaPath = join(getExtensionPath(), "dist", "media");
33✔
17
    this.htmlFileName = "index.html";
33✔
18
  }
19

20
  protected abstract setWebviewPanel(webviewPanel: WebviewPanel, state?: T): void;
21

22
  public loadWebviewPanel(state?: T): void {
23
    if (this.webViewPanel) {
34✔
24
      this.dispose();
1✔
25
    }
26
    const webViewPanel = window.createWebviewPanel(this.viewType, this.viewTitle, ViewColumn.One, {
34✔
27
      // Enable javascript in the webview
28
      enableScripts: true,
29
      localResourceRoots: [Uri.file(this.mediaPath)],
30
    });
31
    this.setWebviewPanel(webViewPanel, state);
34✔
32
  }
33

34
  public async initWebviewPanel(): Promise<void> {
35
    // Set the webview's initial html content
36
    await this.initHtmlContent();
33✔
37

38
    if (this.webViewPanel === undefined) {
33✔
39
      return;
1✔
40
    }
41

42
    // Set the context (current panel is focused)
43
    this.setFocused(this.webViewPanel.active);
32✔
44

45
    // Update the content based on view changes
46
    this.webViewPanel.onDidChangeViewState(() => {
32✔
47
      if (this.webViewPanel) {
2✔
48
        this.setFocused(this.webViewPanel.active);
1✔
49
      }
50
    }, null);
51
  }
52

53
  protected setFocused(focusedValue: boolean): void {
54
    commands.executeCommand("setContext", this.focusedKey, focusedValue);
65✔
55
  }
56

57
  public dispose(): void {
58
    this.setFocused(false);
32✔
59

60
    // Clean up our resources
61
    if (this.webViewPanel) {
32✔
62
      this.webViewPanel.dispose();
31✔
63
      this.webViewPanel = undefined;
31✔
64
    }
65
  }
66

67
  public async initHtmlContent(): Promise<void> {
68
    if (this.webViewPanel === undefined) {
33✔
69
      return;
1✔
70
    }
71
    // Local path to main script run in the webview
72
    const scriptPathOnDisk = Uri.file(join(this.mediaPath, sep));
32✔
73
    const scriptUri = this.webViewPanel.webview.asWebviewUri(scriptPathOnDisk);
32✔
74
    const baseUrl = scriptUri.toString();
32✔
75
    const $ = cheerio.load(await this.readResource(join(this.mediaPath, this.htmlFileName)));
32✔
76

77
    function replaceAttributePaths(elements: any, attributeName: string) {
78
      elements.each((index: number, element: cheerio.Element) => {
64✔
NEW
79
        const currentAttr = $(element).attr(attributeName);
×
NEW
80
        if (currentAttr) {
×
NEW
81
          $(element).attr(attributeName, `${baseUrl}/${currentAttr}`);
×
82
        }
83
      });
84
    }
85

86
    replaceAttributePaths($("[src]"), "src");
32✔
87
    replaceAttributePaths($("[href]"), "href");
32✔
88

89
    this.webViewPanel.webview.html = $.html();
32✔
90
  }
91
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc