63 lines
2.2 KiB
TypeScript
63 lines
2.2 KiB
TypeScript
import { status } from '@basementuniverse/kanbn/src/main';
|
|
import { StatusBarItem, ExtensionContext, window, StatusBarAlignment, workspace } from 'vscode';
|
|
|
|
export default class KanbnStatusBarItem {
|
|
private readonly _statusBarItem: StatusBarItem;
|
|
private readonly _kanbn: typeof import('@basementuniverse/kanbn/src/main');
|
|
|
|
constructor(
|
|
context: ExtensionContext,
|
|
kanbn: typeof import('@basementuniverse/kanbn/src/main')
|
|
) {
|
|
this._statusBarItem = window.createStatusBarItem(StatusBarAlignment.Left, 0);
|
|
context.subscriptions.push(this._statusBarItem);
|
|
this._kanbn = kanbn;
|
|
}
|
|
|
|
async update(): Promise<void> {
|
|
if (this._statusBarItem === undefined) {
|
|
return;
|
|
}
|
|
if (await this._kanbn.initialised()) {
|
|
const status = (await this._kanbn.status(true)) as {
|
|
tasks: number,
|
|
columnTasks: Record<string, number>,
|
|
startedTasks?: number,
|
|
completedTasks?: number
|
|
};
|
|
const text = [
|
|
`$(project) ${status.tasks}`
|
|
];
|
|
let tooltip: any = [];
|
|
if (status.tasks > 0) {
|
|
tooltip = [
|
|
`${status.tasks} task${status.tasks === 1 ? '' : 's'}`
|
|
];
|
|
if ('startedTasks' in status && status.startedTasks! > 0) {
|
|
text.push(`$(play) ${status.startedTasks}`);
|
|
tooltip.push(`${status.startedTasks} started task${status.startedTasks === 1 ? '' : 's'}`);
|
|
}
|
|
if ('completedTasks' in status && status.completedTasks! > 0) {
|
|
text.push(`$(check) ${status.completedTasks}`);
|
|
tooltip.push(`${status.completedTasks} completed task${status.completedTasks === 1 ? '' : 's'}`);
|
|
}
|
|
} else {
|
|
tooltip.push('No tasks');
|
|
}
|
|
this._statusBarItem.text = text.join(' ');
|
|
this._statusBarItem.tooltip = tooltip.join('\n');
|
|
this._statusBarItem.command = 'kanbn.board';
|
|
this._statusBarItem.show();
|
|
} else {
|
|
this._statusBarItem.text = '$(project)';
|
|
this._statusBarItem.tooltip = 'Initialise Kanbn';
|
|
this._statusBarItem.command = 'kanbn.init';
|
|
if (workspace.getConfiguration('kanbn').get('showUninitialisedStatusBarItem')) {
|
|
this._statusBarItem.show();
|
|
} else {
|
|
this._statusBarItem.hide();
|
|
}
|
|
}
|
|
}
|
|
}
|