Task editing

This commit is contained in:
Gordon
2021-04-05 02:02:03 +01:00
parent 708b130059
commit 29fca87a99
13 changed files with 509 additions and 57 deletions

View File

@ -126,7 +126,7 @@ export default class KanbnBoardPanel {
return;
// Create a task
case 'kanbn.create':
case 'kanbn.addTask':
KanbnTaskPanel.show(
this._extensionPath,
this._workspacePath,

View File

@ -18,9 +18,30 @@ export default class KanbnTaskPanel {
workspacePath: string,
kanbn: typeof import('@basementuniverse/kanbn/src/main'),
taskId: string|null,
columnName: string
columnName: string|null
) {
const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn : undefined;
let index: any;
try {
index = await kanbn.getIndex();
} catch (error) {
vscode.window.showErrorMessage(error instanceof Error ? error.message : error);
return;
}
let task: any = null;
if (taskId) {
try {
task = await kanbn.hydrateTask(index, await kanbn.getTask(taskId));
} catch (error) {
vscode.window.showErrorMessage(error instanceof Error ? error.message : error);
return;
}
}
// If no columnName is specified, use the first column
if (!columnName) {
columnName = Object.keys(index.columns)[0];
}
// Create a new panel
const taskPanel = new KanbnTaskPanel(
@ -33,24 +54,10 @@ export default class KanbnTaskPanel {
);
KanbnTaskPanel.panels.push(taskPanel);
let index: any;
try {
index = await kanbn.getIndex();
} catch (error) {
vscode.window.showErrorMessage(error instanceof Error ? error.message : error);
return;
}
let task: any = null;
if (taskId) {
try {
task = await kanbn.getTask(taskId);
} catch (error) {
vscode.window.showErrorMessage(error instanceof Error ? error.message : error);
return;
}
}
// Send task data to the webview
taskPanel._panel.webview.postMessage({
type: 'task',
index,
task,
columnName: taskPanel._columnName,
tasks: await kanbn.loadAllTrackedTasks(index),
@ -78,7 +85,7 @@ export default class KanbnTaskPanel {
enableScripts: true,
// Retain state even when hidden
// retainContextWhenHidden: true,
retainContextWhenHidden: true,
// Restrict the webview to only loading content from allowed paths
localResourceRoots: [
@ -111,16 +118,27 @@ export default class KanbnTaskPanel {
vscode.window.showErrorMessage(message.text);
return;
// Update the task webview panel title
case 'kanbn.updatePanelTitle':
this._panel.title = message.title;
return;
// Create a task
case 'kanbn.create':
// TODO create task
vscode.window.showInformationMessage('create task');
return;
// Update a task
case 'kanbn.update':
// TODO update task
vscode.window.showInformationMessage(`Updating task ${message.taskId}`);
vscode.window.showInformationMessage('update task');
return;
// Delete a task
case 'kanbn.delete':
// TODO delete task
vscode.window.showInformationMessage(`Deleting task ${message.taskId}`);
vscode.window.showInformationMessage('delete task');
return;
}
}, null, this._disposables);

View File

@ -1,6 +1,7 @@
import * as vscode from 'vscode';
import KanbnStatusBarItem from './KanbnStatusBarItem';
import KanbnBoardPanel from './KanbnBoardPanel';
import KanbnTaskPanel from './KanbnTaskPanel';
let kanbnStatusBarItem: KanbnStatusBarItem;
@ -73,6 +74,33 @@ export async function activate(context: vscode.ExtensionContext) {
}
}));
// Register a command to add a new kanbn task.
context.subscriptions.push(vscode.commands.registerCommand('kanbn.addTask', async () => {
// If no workspace folder is opened, we can't add a new task
if (vscode.workspace.workspaceFolders === undefined) {
vscode.window.showErrorMessage('You need to open a workspace before adding a new task.');
return;
}
// Set the node process directory and import kanbn
process.chdir(vscode.workspace.workspaceFolders[0].uri.fsPath);
const kanbn = await import('@basementuniverse/kanbn/src/main');
// If kanbn is initialised, open the task webview
if (await kanbn.initialised()) {
KanbnTaskPanel.show(
context.extensionPath,
vscode.workspace.workspaceFolders[0].uri.fsPath,
kanbn,
null,
null
);
} else {
vscode.window.showErrorMessage('You need to initialise kanbn before adding a new task.');
}
}));
// If a workspace folder is open, add a status bar item and start watching for file changes
if (vscode.workspace.workspaceFolders !== undefined) {