Skip to content

Commit

Permalink
added exclude filename and path
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Apr 16, 2021
1 parent 0707106 commit cfd3a6e
Show file tree
Hide file tree
Showing 6 changed files with 1,105 additions and 1,056 deletions.
2 changes: 1 addition & 1 deletion data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"personRegexpString":"\\[{2}People\\/(.*?)\\]{2}","projectRegexpString":"\\[{2}Projects\\/(.*?)\\]{2}","miscRegexpString":"","dateRegexpString":"#(\\d{4})\\/(\\d{2})\\/(\\d{2})","discussWithRegexpString":"#(discussWith)","waitingForRegexpString":"#(waitingFor)","promisedToRegexpString":"#(promisedTo)","somedayMaybeRegexpString":"#(someday)","isInboxVisible":true,"isAgingVisible":true,"isTodayVisible":true,"isScheduledVisible":true,"isStakeholderVisible":true,"isSomedayVisible":true,"inboxTooltip":"Inbox: No date set, no stakeholder action set, not a someday / maybe item.","agingTooltip":"Aging...","todayTooltip":"Scheduled for Today","scheduledTooltip":"Scheduled for a future date","stakeholderTooltip":"Stakeholder and Project 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.","somedayTooltip":"Tagged as Someday / Maybe"}
{"personRegexpString":"\\[{2}People\\/(.*?)\\]{2}","projectRegexpString":"\\[{2}Projects\\/(.*?)\\]{2}","miscRegexpString":"","dateRegexpString":"#(\\d{4})\\/(\\d{2})\\/(\\d{2})","discussWithRegexpString":"#(discussWith)","waitingForRegexpString":"#(waitingFor)","promisedToRegexpString":"#(promisedTo)","somedayMaybeRegexpString":"#(someday)","excludePath":"Templates/","excludeFilenameFragment":"checklist","isInboxVisible":true,"isAgingVisible":true,"isTodayVisible":true,"isScheduledVisible":true,"isStakeholderVisible":true,"isSomedayVisible":true,"inboxTooltip":"Inbox: No date set, no stakeholder action set, not a someday / maybe item.","agingTooltip":"Aging...","todayTooltip":"Scheduled for Today","scheduledTooltip":"Scheduled for a future date","stakeholderTooltip":"Stakeholder and Project 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.","somedayTooltip":"Tagged as Someday / Maybe"}
279 changes: 141 additions & 138 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,138 +1,141 @@
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,TodoItemIndexProps } from './model/TodoIndex';
import {DEFAULT_SETTINGS, ActionTrackerSettings, ActionTrackerSettingTab} from './settings';


export default class ActionTrackerPlugin extends Plugin {
private todoIndex: TodoIndex;
private view: TodoItemView;
settings: ActionTrackerSettings;

constructor(app: App, manifest: PluginManifest) {
super(app, manifest);
}

private getTodoItemIndexProps() : TodoItemIndexProps {
return {
personRegexp: new RegExp (this.getSettingValue('personRegexpString')),
projectRegexp: new RegExp (this.getSettingValue('projectRegexpString')),
miscRegexp: new RegExp (this.getSettingValue('miscRegexpString')),
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),this.getTodoItemIndexProps());

this.registerView(VIEW_TYPE_TODO, (leaf: WorkspaceLeaf) => {
const todos: TodoItem[] = [];
const props = {
todos: todos,
openFile: (filePath: string) => {
const file = this.app.vault.getAbstractFileByPath(filePath) as TFile;
this.app.workspace.splitActiveLeaf().openFile(file);
},
toggleTodo: (todo: TodoItem, newStatus: TodoItemStatus) => {
this.todoIndex.setStatus(todo, newStatus);
},
isInboxVisible: this.getSettingValue('isInboxVisible'),
isAgingVisible: this.getSettingValue('isAgingVisible'),
isTodayVisible: this.getSettingValue('isTodayVisible'),
isScheduledVisible: this.getSettingValue('isScheduledVisible'),
isStakeholderVisible: this.getSettingValue('isStakeholderVisible'),
isSomedayVisible: this.getSettingValue('isSomedayVisible'),
inboxTooltip: this.getSettingValue('inboxTooltip'),
agingTooltip: this.getSettingValue('agingTooltip'),
todayTooltip: this.getSettingValue('todayTooltip'),
scheduledTooltip: this.getSettingValue('scheduledTooltip'),
stakeholderTooltip: this.getSettingValue('stakeholderTooltip'),
somedayTooltip: this.getSettingValue('somedayTooltip'),
};
this.view = new TodoItemView(leaf, props);
return this.view;
});

this.addSettingTab(new ActionTrackerSettingTab(this.app, this));

if (this.app.workspace.layoutReady) {
this.initLeaf();
await this.prepareIndex();
} else {
this.registerEvent(this.app.workspace.on('layout-ready', this.initLeaf.bind(this)));
this.registerEvent(this.app.workspace.on('layout-ready', async () => await this.prepareIndex()));
}
}

onunload(): void {
this.app.workspace.getLeavesOfType(VIEW_TYPE_TODO).forEach((leaf) => leaf.detach());
}

initLeaf(): void {
if (this.app.workspace.getLeavesOfType(VIEW_TYPE_TODO).length) {
return;
}
this.app.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE_TODO,
});
}

async prepareIndex(): Promise<void> {
await this.todoIndex.initialize();
}

tick(todos: TodoItem[]): void {
this.view.setProps((currentProps: TodoItemViewProps) => {
return {
...currentProps,
todos: todos,
};
});
}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

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

async saveViewDisplaySettings() {
await this.saveData(this.settings);
this.view.setDisplayProps({
todos: null,
openFile: null,
toggleTodo: null,
isInboxVisible: this.getSettingValue('isInboxVisible'),
isAgingVisible: this.getSettingValue('isAgingVisible'),
isTodayVisible: this.getSettingValue('isTodayVisible'),
isScheduledVisible: this.getSettingValue('isScheduledVisible'),
isStakeholderVisible: this.getSettingValue('isStakeholderVisible'),
isSomedayVisible: this.getSettingValue('isSomedayVisible'),
inboxTooltip: this.getSettingValue('inboxTooltip'),
agingTooltip: this.getSettingValue('agingTooltip'),
todayTooltip: this.getSettingValue('todayTooltip'),
scheduledTooltip: this.getSettingValue('scheduledTooltip'),
stakeholderTooltip: this.getSettingValue('stakeholderTooltip'),
somedayTooltip: this.getSettingValue('somedayTooltip'),
});
}

getSettingValue<K extends keyof ActionTrackerSettings>(setting: K): ActionTrackerSettings[K] {
return this.settings[setting]
}
}


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,TodoItemIndexProps } from './model/TodoIndex';
import {DEFAULT_SETTINGS, ActionTrackerSettings, ActionTrackerSettingTab} from './settings';
import { stringify } from 'querystring';


export default class ActionTrackerPlugin extends Plugin {
private todoIndex: TodoIndex;
private view: TodoItemView;
settings: ActionTrackerSettings;

constructor(app: App, manifest: PluginManifest) {
super(app, manifest);
}

private getTodoItemIndexProps() : TodoItemIndexProps {
return {
personRegexp: new RegExp (this.getSettingValue('personRegexpString')),
projectRegexp: new RegExp (this.getSettingValue('projectRegexpString')),
miscRegexp: new RegExp (this.getSettingValue('miscRegexpString')),
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')),
excludePath: this.getSettingValue('excludePath'),
excludeFilenameFragment: this.getSettingValue('excludeFilenameFragment').toLowerCase(),
};
}

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

await this.loadSettings();

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

this.registerView(VIEW_TYPE_TODO, (leaf: WorkspaceLeaf) => {
const todos: TodoItem[] = [];
const props = {
todos: todos,
openFile: (filePath: string) => {
const file = this.app.vault.getAbstractFileByPath(filePath) as TFile;
this.app.workspace.splitActiveLeaf().openFile(file);
},
toggleTodo: (todo: TodoItem, newStatus: TodoItemStatus) => {
this.todoIndex.setStatus(todo, newStatus);
},
isInboxVisible: this.getSettingValue('isInboxVisible'),
isAgingVisible: this.getSettingValue('isAgingVisible'),
isTodayVisible: this.getSettingValue('isTodayVisible'),
isScheduledVisible: this.getSettingValue('isScheduledVisible'),
isStakeholderVisible: this.getSettingValue('isStakeholderVisible'),
isSomedayVisible: this.getSettingValue('isSomedayVisible'),
inboxTooltip: this.getSettingValue('inboxTooltip'),
agingTooltip: this.getSettingValue('agingTooltip'),
todayTooltip: this.getSettingValue('todayTooltip'),
scheduledTooltip: this.getSettingValue('scheduledTooltip'),
stakeholderTooltip: this.getSettingValue('stakeholderTooltip'),
somedayTooltip: this.getSettingValue('somedayTooltip'),
};
this.view = new TodoItemView(leaf, props);
return this.view;
});

this.addSettingTab(new ActionTrackerSettingTab(this.app, this));

if (this.app.workspace.layoutReady) {
this.initLeaf();
await this.prepareIndex();
} else {
this.registerEvent(this.app.workspace.on('layout-ready', this.initLeaf.bind(this)));
this.registerEvent(this.app.workspace.on('layout-ready', async () => await this.prepareIndex()));
}
}

onunload(): void {
this.app.workspace.getLeavesOfType(VIEW_TYPE_TODO).forEach((leaf) => leaf.detach());
}

initLeaf(): void {
if (this.app.workspace.getLeavesOfType(VIEW_TYPE_TODO).length) {
return;
}
this.app.workspace.getRightLeaf(false).setViewState({
type: VIEW_TYPE_TODO,
});
}

async prepareIndex(): Promise<void> {
await this.todoIndex.initialize();
}

tick(todos: TodoItem[]): void {
this.view.setProps((currentProps: TodoItemViewProps) => {
return {
...currentProps,
todos: todos,
};
});
}

async loadSettings() {
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData());
}

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

async saveViewDisplaySettings() {
await this.saveData(this.settings);
this.view.setDisplayProps({
todos: null,
openFile: null,
toggleTodo: null,
isInboxVisible: this.getSettingValue('isInboxVisible'),
isAgingVisible: this.getSettingValue('isAgingVisible'),
isTodayVisible: this.getSettingValue('isTodayVisible'),
isScheduledVisible: this.getSettingValue('isScheduledVisible'),
isStakeholderVisible: this.getSettingValue('isStakeholderVisible'),
isSomedayVisible: this.getSettingValue('isSomedayVisible'),
inboxTooltip: this.getSettingValue('inboxTooltip'),
agingTooltip: this.getSettingValue('agingTooltip'),
todayTooltip: this.getSettingValue('todayTooltip'),
scheduledTooltip: this.getSettingValue('scheduledTooltip'),
stakeholderTooltip: this.getSettingValue('stakeholderTooltip'),
somedayTooltip: this.getSettingValue('somedayTooltip'),
});
}

getSettingValue<K extends keyof ActionTrackerSettings>(setting: K): ActionTrackerSettings[K] {
return this.settings[setting]
}
}


Loading

0 comments on commit cfd3a6e

Please sign in to comment.