Skip to content

Commit

Permalink
Issues #1, #3, #9 resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Apr 13, 2021
1 parent d45f430 commit 3a6f62e
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 91 deletions.
74 changes: 44 additions & 30 deletions dist/main.js

Large diffs are not rendered by default.

74 changes: 44 additions & 30 deletions main.js

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { App, Plugin, PluginManifest, TFile, WorkspaceLeaf, } from 'obsidian';
import { VIEW_TYPE_TODO } from './constants';
import { TodoItemView, TodoItemViewProps } from './ui/TodoItemView';
import { TodoItem, TodoItemStatus } from './model/TodoItem';
import { TodoIndex } from './model/TodoIndex';
import { TodoIndex,TodoItemIndexProps } from './model/TodoIndex';
import {DEFAULT_SETTINGS, ActionTrackerSettings, ActionTrackerSettingTab} from './settings';


Expand All @@ -15,22 +15,24 @@ export default class ActionTrackerPlugin extends Plugin {
super(app, manifest);
}

async onload(): Promise<void> {
console.log('loading plugin');

await this.loadSettings();

const props = {
private getTodoItemIndexProps() : TodoItemIndexProps {
return {
personRegexp: new RegExp (this.getSettingValue('personRegexpString')),
projectRegexp: new RegExp (this.getSettingValue('projectRegexpString')),
dateRegexp: new RegExp (this.getSettingValue('dateRegexpString')),
discussWithRegexp: new RegExp (this.getSettingValue('discussWithRegexpString')),
waitingForRegexp: new RegExp (this.getSettingValue('waitingForRegexpString')),
promisedToRegexp: new RegExp (this.getSettingValue('promisedToRegexpString')),
somedayMaybeRegexp: new RegExp (this.getSettingValue('somedayMaybeRegexpString')),
}
};
}

async onload(): Promise<void> {
console.log('loading plugin');

await this.loadSettings();

this.todoIndex = new TodoIndex(this.app.vault, this.tick.bind(this),props);
this.todoIndex = new TodoIndex(this.app.vault, this.tick.bind(this),this.getTodoItemIndexProps());

this.registerView(VIEW_TYPE_TODO, (leaf: WorkspaceLeaf) => {
const todos: TodoItem[] = [];
Expand Down Expand Up @@ -91,6 +93,7 @@ export default class ActionTrackerPlugin extends Plugin {

async saveSettings() {
await this.saveData(this.settings);
await this.todoIndex.reloadIndex(this.getTodoItemIndexProps());
}

getSettingValue<K extends keyof ActionTrackerSettings>(setting: K): ActionTrackerSettings[K] {
Expand Down
5 changes: 5 additions & 0 deletions model/TodoIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export class TodoIndex {
this.listeners = [listener];
}

async reloadIndex(props: TodoItemIndexProps) {
this.props = props;
await this.initialize();
}

async initialize(): Promise<void> {
// TODO: persist index & last sync timestamp; only parse files that changed since then.
const todoMap = new Map<string, TodoItem[]>();
Expand Down
12 changes: 6 additions & 6 deletions settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ActionTrackerSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Person regexp pattern')
.setDesc('This is the regular expression to identify the action party in the action.')
.setDesc('This is the regular expression to identify the action party in the action. Used for filtering todos by person.')
.addText(text => text
.setPlaceholder('\\[{2}People\\/(.*?)\\]{2}')
.setValue(this.plugin.settings.personRegexpString)
Expand All @@ -49,7 +49,7 @@ export class ActionTrackerSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Project regexp pattern')
.setDesc('This is the regular expression to identify the project in the action.')
.setDesc('This is the regular expression to identify the project in the action. Used for filtering todos by project name.')
.addText(text => text
.setPlaceholder('\\[{2}Projects\\/(.*?)\\]{2}')
.setValue(this.plugin.settings.projectRegexpString)
Expand All @@ -71,7 +71,7 @@ export class ActionTrackerSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Discuss With regexp pattern')
.setDesc('This is the regexp pattern you use to mark topics you want to discuss with someone.')
.setDesc('This is the regexp pattern you use to mark topics you want to discuss with someone. "Discuss with", "Promised to", and "Waiting for" actions show up under the Stakeholder Actions tab.')
.addText(text => text
.setPlaceholder('#(discussWith)')
.setValue(this.plugin.settings.discussWithRegexpString)
Expand All @@ -82,7 +82,7 @@ export class ActionTrackerSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Waiting For regexp pattern')
.setDesc('This is the regexp pattern you use to mark topics someone has promised to deliver to me.')
.setDesc('This is the regexp pattern you use to mark topics someone has promised to deliver to me. "Discuss with", "Promised to", and "Waiting for" actions show up under the Stakeholder Actions tab.')
.addText(text => text
.setPlaceholder('#(waitingFor)')
.setValue(this.plugin.settings.waitingForRegexpString)
Expand All @@ -93,7 +93,7 @@ export class ActionTrackerSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Promised To regexp pattern')
.setDesc('This is the regexp pattern you use to mark topics someone has promised to deliver to me.')
.setDesc('This is the regexp pattern you use to mark topics someone has promised to deliver to me. "Discuss with", "Promised to", and "Waiting for" actions show up under the Stakeholder Actions tab.')
.addText(text => text
.setPlaceholder('#(promisedTo)')
.setValue(this.plugin.settings.promisedToRegexpString)
Expand All @@ -104,7 +104,7 @@ export class ActionTrackerSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setName('Someday Maybe regexp pattern')
.setDesc('This is the regexp pattern you use to mark actions without a deadline.')
.setDesc('This is the regexp pattern you use to mark actions deliberately without a deadline - i.e. bucket list. Actions without a valid tag and without a deadline will show up in the Inbox.')
.addText(text => text
.setPlaceholder('#(someday)')
.setValue(this.plugin.settings.somedayMaybeRegexpString)
Expand Down
41 changes: 25 additions & 16 deletions ui/TodoItemView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class TodoItemView extends ItemView {
};
this.filter = '';
}

getViewType(): string {
return VIEW_TYPE_TODO;
}
Expand Down Expand Up @@ -124,31 +124,35 @@ export class TodoItemView extends ItemView {
this.setViewState(newState);
};

container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Inbox)}`, (el) => {
el.appendChild(RenderIcon(Icon.Inbox, 'Inbox: No date set, no stakeholder action set, not a someday / maybe item.'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Inbox));
});

container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Aging)}`, (el) => {
el.appendChild(RenderIcon(Icon.Aging, 'Aging'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Aging));
});

container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Today)}`, (el) => {
el.appendChild(RenderIcon(Icon.Today, 'Today'));
el.appendChild(RenderIcon(Icon.Today, 'Scheduled for Today'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Today));
});

container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Scheduled)}`, (el) => {
el.appendChild(RenderIcon(Icon.Scheduled, 'Scheduled'));
el.appendChild(RenderIcon(Icon.Scheduled, 'Scheduled for a future date'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Scheduled));
});
container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Inbox)}`, (el) => {
el.appendChild(RenderIcon(Icon.Inbox, 'Inbox'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Inbox));

container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Stakeholder)}`, (el) => {
el.appendChild(RenderIcon(Icon.Stakeholder, 'Stakeholder actions: discussWith, promisedTo, waitingFor. Only items that have a valid project or person will show up here. Stakeholder actions without project or person are in the Inbox.'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Stakeholder));
});

container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Someday)}`, (el) => {
el.appendChild(RenderIcon(Icon.Someday, 'Someday / Maybe'));
el.appendChild(RenderIcon(Icon.Someday, 'Tagged as Someday / Maybe'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Someday));
});
container.createDiv(`todo-item-view-toolbar-item${activeClass(TodoItemViewPane.Stakeholder)}`, (el) => {
el.appendChild(RenderIcon(Icon.Stakeholder, 'Stakeholder actions'));
el.onClickEvent(() => setActivePane(TodoItemViewPane.Stakeholder));
});
}

private renderItems(container: HTMLDivElement) {
Expand All @@ -158,8 +162,11 @@ export class TodoItemView extends ItemView {
todosToRender
.forEach((todo,index) => {
if(index>0) {
if((todo.isWaitingForNote && todosToRender[index-1].isDiscussWithNote) ||
(todo.isPromisedToNote && (todosToRender[index-1].isWaitingForNote || todosToRender[index-1].isDiscussWithNote))) {
if( (todo.isWaitingForNote && todosToRender[index-1].isDiscussWithNote) ||
(todo.isPromisedToNote &&
(todosToRender[index-1].isWaitingForNote || todosToRender[index-1].isDiscussWithNote)) ||
(!todo.isPromisedToNote && !todo.isWaitingForNote && !todo.isDiscussWithNote &&
(todosToRender[index-1].isWaitingForNote || todosToRender[index-1].isDiscussWithNote || todosToRender[index-1].isPromisedToNote)) ) {
container.createEl('hr', {} ,(el) => {
el.addClass('todo-item-view-divider');
});
Expand Down Expand Up @@ -189,8 +196,10 @@ export class TodoItemView extends ItemView {

private filterForState(value: TodoItem, _index: number, _array: TodoItem[]): boolean {
const isPersonMatch = value.person.match(this.filterRegexp) != null;
const isProjectMatch = value.project.match(this.filterRegexp) != null;
const isProjectMatch = value.project.match(this.filterRegexp) != null;
const isFilterSet = this.filter!="";
const hasPersonOrProject = value.person!='' || value.project!='';
const isPeopleActionNote = value.isDiscussWithNote || value.isWaitingForNote || value.isPromisedToNote;
if (!isFilterSet || isPersonMatch || isProjectMatch) {
const isToday = (date: Date) => {
let today = new Date();
Expand All @@ -213,7 +222,7 @@ export class TodoItemView extends ItemView {

switch (this.state.activePane) {
case TodoItemViewPane.Inbox:
return !value.isSomedayMaybeNote && !isTodayNote && !isScheduledNote && !isAgingNote;
return !value.isSomedayMaybeNote && !isTodayNote && !isScheduledNote && !isAgingNote && !(isPeopleActionNote && hasPersonOrProject);
case TodoItemViewPane.Scheduled:
return isScheduledNote;
case TodoItemViewPane.Someday:
Expand All @@ -223,7 +232,7 @@ export class TodoItemView extends ItemView {
case TodoItemViewPane.Aging:
return isAgingNote;
case TodoItemViewPane.Stakeholder:
return isFilterSet;
return hasPersonOrProject && isPeopleActionNote;
}
} else return false;
}
Expand Down

0 comments on commit 3a6f62e

Please sign in to comment.