X-Git-Url: http://git.scottworley.com/vopamoi/blobdiff_plain/b91a45d94a27021abdcaf8145d520df6da5758b5..f9aba985b1f9e1a7b76e2f2e605ee34bd23f153d:/vopamoi.ts?ds=inline diff --git a/vopamoi.ts b/vopamoi.ts index c72884e..f37ce2e 100644 --- a/vopamoi.ts +++ b/vopamoi.ts @@ -310,6 +310,11 @@ enum CommitOrAbort { Abort, } +interface TagFilter { + description: string; + include: (task: Element) => boolean; +} + function BrowserUI() { const viewColors: { [key: string]: string } = { all: "Gold", @@ -320,7 +325,7 @@ function BrowserUI() { todo: "White", waiting: "MediumOrchid", }; - var currentTagFilter: string | null = null; + var currentTagFilter: TagFilter | null = null; var currentViewState = "todo"; var taskFocusedBeforeJumpingToInput: HTMLElement | null = null; var lastTagNameEntered = ""; @@ -611,20 +616,14 @@ function BrowserUI() { return ui.setState(createTimestamp, newState, oldState); }, - setTagView: function (tag: string | null = null) { - if (tag === null) { - const target = this.currentTag(); - if (!target) return; - tag = target.textContent!; - } - + setTagFilter: function (filter: TagFilter) { if (currentTagFilter !== null) { this.resetTagView(); } const tasksWithTag = new Map(); for (const task of document.getElementsByClassName("task")) { - if (model.hasTag(task, tag)) { + if (filter.include(task)) { tasksWithTag.set(task.getElementsByClassName("desc")[0].textContent, [model.getPriority(task), task]); } } @@ -643,7 +642,7 @@ function BrowserUI() { } for (const task of Array.from(document.getElementsByClassName("task"))) { - if (model.hasTag(task, tag)) { + if (filter.include(task)) { task.classList.remove("hide"); } else { const superTask = highestPrioritySuperTask(task); @@ -655,12 +654,21 @@ function BrowserUI() { } } - currentTagFilter = tag; + currentTagFilter = filter; this.setTitle(); }, + setTagView: function (tag: string | null = null) { + if (tag === null) { + const target = this.currentTag(); + if (!target) return; + tag = target.textContent!; + } + this.setTagFilter({description: tag, include: task => !!model.hasTag(task, tag!)}); + }, + setTitle: function () { - document.title = "Vopamoi: " + currentViewState + (currentTagFilter ? ": " + currentTagFilter : ""); + document.title = "Vopamoi: " + currentViewState + (currentTagFilter ? ": " + currentTagFilter.description : ""); }, setView: function (state: string) { @@ -681,16 +689,7 @@ function BrowserUI() { }, setUntaggedView: function () { - if (currentTagFilter !== null) { - this.resetTagView(); - } - for (const task of document.getElementsByClassName("task")) { - if (task.getElementsByClassName("tag").length === 0) { - task.classList.remove("hide"); - } else { - task.classList.add("hide"); - } - } + this.setTagFilter({description: "(untagged)", include: task => task.getElementsByClassName("tag").length === 0}); }, undo: function () {