ADDED: Template for Rendering Issues

This commit is contained in:
IJustDev 2019-04-09 21:22:33 +02:00
parent 32124c4f8c
commit afa09a9629
4 changed files with 92 additions and 20 deletions

View File

@ -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"

View File

@ -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 = "<h1>Issue #" + issue.issueId + "!</h1>";
panel.webview.html += "<p>Status: " + issue.issueState + "</p>";
panel.webview.html += "<p>Assignees: " + issue.assignees + "</p>";
panel.webview.html += "<p>" + issue.body + "</p>";
// panel.webview.html = "<h1>Issue #" + issue.issueId + "!</h1>";
// panel.webview.html += "<p>Status: " + issue.issueState + "</p>";
// panel.webview.html += "<p>Assignees: " + issue.assignee + "</p>";
// panel.webview.html += "<p>" + issue.body + "</p>";
panel.webview.html = html(issue);
});
// The command has been defined in the package.json file

View File

@ -3,24 +3,51 @@ import axios from "axios";
export class IssueProvider implements vscode.TreeDataProvider<Issue> {
private _onDidChangeTreeData: vscode.EventEmitter<Issue | undefined> = new vscode.EventEmitter<Issue | undefined>();
readonly onDidChangeTreeData: vscode.Event<Issue | undefined> = 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<vscode.TreeItem> {
return element;
}
getChildren(element?: Issue): vscode.ProviderResult<any[]> {
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"]);
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);
});
let issues = [new Issue("Test", 1, "Bring dich um", "open", ["IJustDev", "OjunbamO"], vscode.TreeItemCollapsibleState.None)];
return Promise.resolve(issues);
}
console.log(this.issueList);
}
getChildren(element?: Issue): vscode.ProviderResult<any[]> {
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';
}

43
src/template.html.ts Normal file
View File

@ -0,0 +1,43 @@
import { Issue } from "./issueProvider";
export function html(issue: Issue) {
return `<body>
<h1>{{label}}</h1>
<table>
<tr>
<td>
Title
</td>
<td >
{{label}}
</td>
</tr>
<tr>
<td>
State
</td>
<td>
{{state}}
</td>
</tr>
<tr >
<td>
Assignee
</td>
<td>
{{assignee}}
</td>
</tr>
<tr>
<td>
Description
</td>
<td>
{{description}}
</td>
</tr>
</table>
</body>
`.replace("{{label}}", issue.label).replace("{{state}}", issue.issueState).replace("{{assignee}}", issue.assignee).replace("{{description}}", issue.body).replace("{{label}}", issue.label);
}