diff --git a/package.json b/package.json index 1bb9fa3..7e2b6d7 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "Gitea Issue Tracker for vs-code", "version": "0.0.1", "engines": { - "vscode": "^1.33.0" + "vscode": "^1.32.0" }, "categories": [ "Other" diff --git a/src/extension.ts b/src/extension.ts index 9b24500..62325f8 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,8 +1,8 @@ +import { html } from './template.html'; // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below import * as vscode from 'vscode'; import { IssueProvider, Issue } from './issueProvider'; - // this method is called when your extension is activated // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { @@ -11,13 +11,14 @@ export function activate(context: vscode.ExtensionContext) { // This line of code will only be executed once when your extension is activated vscode.window.registerTreeDataProvider('open-issues', issueProvider); vscode.commands.registerCommand('giteaIssues.openIssue', (issue: Issue) => { - const panel = vscode.window.createWebviewPanel('issue', 'Issue #1', + const panel = vscode.window.createWebviewPanel('issue', issue.label, vscode.ViewColumn.Active, {}); - panel.webview.html = "

Issue #" + issue.issueId + "!

"; - panel.webview.html += "

Status: " + issue.issueState + "

"; - panel.webview.html += "

Assignees: " + issue.assignees + "

"; - panel.webview.html += "

" + issue.body + "

"; + // panel.webview.html = "

Issue #" + issue.issueId + "!

"; + // panel.webview.html += "

Status: " + issue.issueState + "

"; + // panel.webview.html += "

Assignees: " + issue.assignee + "

"; + // panel.webview.html += "

" + issue.body + "

"; + panel.webview.html = html(issue); }); // The command has been defined in the package.json file diff --git a/src/issueProvider.ts b/src/issueProvider.ts index 7e7d631..d137abe 100644 --- a/src/issueProvider.ts +++ b/src/issueProvider.ts @@ -3,24 +3,51 @@ import axios from "axios"; export class IssueProvider implements vscode.TreeDataProvider { + private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); + readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + + issueList: any[] = []; + constructor() { + this.getChildrenAsync(); + const id = setInterval(() => { + if (this.issueList.length === 0) { + this._onDidChangeTreeData.fire(); + } else { + clearInterval(id); + } + }, 1 * 10); + setInterval(() => { + this._onDidChangeTreeData.fire(); + }, 10 * 1000); } getTreeItem(element: Issue): vscode.TreeItem | Thenable { return element; } + + async getChildrenAsync() { + this.issueList = []; + for (let i = 0; i !== 10; i++) { + await axios.get("http://git.mypenink.com/api/v1/repos/MyPenInk/Frontend/issues?page=" + i, { headers: { Authorization: "token baab9fb94100c3a4f22213a0d0d0b8ce03c55bec" } }).then(res => { + for (const issue of res.data) { + const title = issue["title"]; + const id = issue["number"]; + const body = issue["body"]; + const state = issue["state"]; + const assignee = issue["assignee"] === null ? "None" : issue["assignee"]["username"]; + const issueForList = new Issue("#" + id + " - " + title, id, body, state, assignee, "Frontend", vscode.TreeItemCollapsibleState.None); + this.issueList.push(issueForList); + } + }).catch(err => { + console.log(err); + }); + } + + console.log(this.issueList); + } getChildren(element?: Issue): vscode.ProviderResult { - axios.get("http://git.mypenink.com/api/v1/repos/MyPenInk/Frontend/issues", { headers: { Authorization: "token baab9fb94100c3a4f22213a0d0d0b8ce03c55bec" } }).then(res => { - console.log(res.data); - for (const issue in res.data) { - console.log(issue); - vscode.window.showInformationMessage(issue["number"]); - } - }).catch(err => { - console.log(err); - }); - let issues = [new Issue("Test", 1, "Bring dich um", "open", ["IJustDev", "OjunbamO"], vscode.TreeItemCollapsibleState.None)]; - return Promise.resolve(issues); + return this.issueList; } @@ -32,14 +59,15 @@ export class Issue extends vscode.TreeItem { public issueId: number, public body: string, public issueState: string, - public assignees: string[], + public assignee: string, + public firstlabel: string, public readonly collapsibleState: vscode.TreeItemCollapsibleState, public readonly command?: vscode.Command) { super(label, collapsibleState); } get tooltip() { - return "Tooltip!"; + return this.label + " - " + this.assignee; } contextValue = 'issue'; } \ No newline at end of file diff --git a/src/template.html.ts b/src/template.html.ts new file mode 100644 index 0000000..876b6d4 --- /dev/null +++ b/src/template.html.ts @@ -0,0 +1,43 @@ +import { Issue } from "./issueProvider"; + +export function html(issue: Issue) { + + return ` +

{{label}}

+ + + + + + + + + + + + + + + + + +
+ Title + + {{label}} +
+ State + + {{state}} +
+ Assignee + + {{assignee}} +
+ Description + + {{description}} +
+ +`.replace("{{label}}", issue.label).replace("{{state}}", issue.issueState).replace("{{assignee}}", issue.assignee).replace("{{description}}", issue.body).replace("{{label}}", issue.label); +} \ No newline at end of file