Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export interface Config {
name: string;
backlog?: boolean;
}[];
display: {
markdown: string;
};
}

interface Column {
Expand Down Expand Up @@ -80,7 +83,7 @@ export function getMdTable(boardState: BoardState): string {
const rows: string[][] = [];
const numRows = Math.max(...boardState.columns.map((c) => c.notes.length));
for (let i = 0; i < numRows; i++) {
rows[i] = boardState.columns.map((col) => col.notes[i]?.title || "");
rows[i] = boardState.columns.map((col) => getMdLink(col.notes[i]));
}

const body = rows.map((r) => "| " + r.join(" | ") + " |").join("\n") + "\n";
Expand All @@ -89,6 +92,28 @@ export function getMdTable(boardState: BoardState): string {
return header + headerSep + body + timestamp;
}

export function getMdList(boardState: BoardState): string {
if (!boardState.columns) return "";

const numCols = boardState.columns.length;
const cols: string[] = [];
for (let i = 0; i < numCols; i++) {
cols[i] = ("## " + boardState.columns[i].name + "\n" +
boardState.columns[i].notes.map((note) => "- " + getMdLink(note)).join("\n"));
}

const body = cols.join("\n\n")
const timestamp = `\n\n_Last updated at ${new Date().toLocaleString()} by Kanban plugin_`;

return body + timestamp;
}

export function getMdLink(note: NoteData): string {
if ((note?.title !== undefined) && (note?.id !== undefined)) {
return "[" + note.title + "](:/" + note.id + ")";
} else return "";
}

export async function getBoardState(board?: Board): Promise<BoardState> {
if (!board) throw new Error("No open board");

Expand Down
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import createBoard, {
getBoardState,
parseConfigNote,
getMdTable,
getMdList
} from "./board";
import {
getConfigNote,
Expand Down Expand Up @@ -201,8 +202,16 @@ async function showBoard() {
);
}

if (msg.type !== "poll")
setAfterConfig(openBoard.configNoteId, getMdTable(newState));

if (msg.type !== "poll"){
if ((openBoard.isValid) && (openBoard.parsedConfig.display?.markdown == "list"))
setAfterConfig(openBoard.configNoteId, getMdList(newState));
else if ((openBoard.isValid) &&
(openBoard.parsedConfig.display?.markdown == "table" ||
openBoard.parsedConfig.display?.markdown == undefined))
setAfterConfig(openBoard.configNoteId, getMdTable(newState));
}


log(
`Sending back update to webview: \n${JSON.stringify(
Expand Down