Skip to content

Commit

Permalink
Merge pull request #24 from dartungar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dartungar authored Jan 14, 2023
2 parents dd27440 + 3df4dc9 commit 81b1bec
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 59 deletions.
128 changes: 80 additions & 48 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,61 +22,17 @@ export default class SimpleNoteReviewPlugin extends Plugin {

await this.loadSettings();

//addSimpleNoteReviewIcon();

this.service.updateNoteSetDisplayNames();

this.addRibbonIcon(this.openModalIconName, "Simple Note Review", (evt: MouseEvent) => {
this.addRibbonIcon(this.openModalIconName, "Simple Note Review: Select Note Set", (evt: MouseEvent) => {
new SelectNoteSetModal(this.app, this).open();
})

this.addCommand({
id: "open-modal",
name: "Select Note Set For Reviewing",
callback: () => {
new SelectNoteSetModal(this.app, this).open();
},
this.addRibbonIcon("play-circle", "Simple Note Review: Start Reviewing", (evt: MouseEvent) => {
this.startReview();
});

this.addCommand({
id: "set-reviewed-date",
name: "Mark Note As Reviewed Today",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.reviewNote(view.file);
})
});

this.addCommand({
id: "set-review-frequency-high",
name: "Set review frequency to high",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.high);
})
});

this.addCommand({
id: "set-review-frequency-normal",
name: "Set review frequency to normal",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.normal);
})
});

this.addCommand({
id: "set-review-frequency-low",
name: "Set review frequency to low",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.low);
})
});

this.addCommand({
id: "set-review-frequency-ignore",
name: "Set review frequency to none (ignore this note)",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.ignore);
})
});
this.addCommands();

this.registerEvent(
this.app.workspace.on("editor-menu", (menu, editor, view) => {
Expand Down Expand Up @@ -104,13 +60,27 @@ export default class SimpleNoteReviewPlugin extends Plugin {
})
);



this.addSettingTab(new SimpleNoteReviewPluginSettingsTab(this, this.app));
}

onunload() {

}


public async startReview(): Promise<void> {
let currentNoteSet = this.settings.currentNoteSet;
if (!currentNoteSet) {
new SelectNoteSetModal(this.app, this).open();
return;
}

this.showNotice(`Reviewing note set "${this.settings.currentNoteSet.displayName}"`);
this.service.openNextFile(currentNoteSet);
}

async loadSettings() {
this.settings = Object.assign(
{},
Expand All @@ -130,4 +100,66 @@ export default class SimpleNoteReviewPlugin extends Plugin {
private dataviewIsInstalled(): boolean {
return !!getAPI();
}

private addCommands(): void {
this.addCommand({
id: "start-review",
name: "Start reviewing notes",
callback: () => this.startReview(),
});

this.addCommand({
id: "continue-review",
name: "Continue reviewing notes",
callback: () => this.startReview(),
});

this.addCommand({
id: "open-modal",
name: "Select Note Set For Reviewing",
callback: () => {
new SelectNoteSetModal(this.app, this).open();
},
});

this.addCommand({
id: "set-reviewed-date",
name: "Mark Note As Reviewed Today",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.reviewNote(view.file);
})
});

this.addCommand({
id: "set-review-frequency-high",
name: "Set review frequency to high",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.high);
})
});

this.addCommand({
id: "set-review-frequency-normal",
name: "Set review frequency to normal",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.normal);
})
});

this.addCommand({
id: "set-review-frequency-low",
name: "Set review frequency to low",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.low);
})
});

this.addCommand({
id: "set-review-frequency-ignore",
name: "Set review frequency to none (ignore this note)",
editorCallback: (async (editor: Editor, view: MarkdownView) => {
await this.service.setReviewedFrequency(view.file, ReviewFrequency.ignore);
})
});
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "simple-note-review",
"name": "Simple Note Review",
"version": "0.5.10",
"version": "0.6.0",
"minAppVersion": "0.12.0",
"description": "Simple, customizable plugin for easy note review, resurfacing & repetition.",
"author": "dartungar",
Expand Down
1 change: 1 addition & 0 deletions src/UI/noteSetInfoModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class NoteSetInfoModal extends Modal {
}

onOpen() {
this.service.updateNoteSetDisplayNameAndDescription(this.noteSet);
this.service.updateNoteSetStats(this.noteSet);
const { contentEl } = this;
contentEl.createEl("h3", {text: `Note set "${this.noteSet.displayName}"`});
Expand Down
11 changes: 9 additions & 2 deletions src/dataview/dataviewService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DataArray } from "obsidian-dataview";
import { DataviewFacade, DataviewNotInstalledError } from "src/dataview/dataviewFacade";
import { getDateOffsetByNDays } from "src/utils/dateUtils";
import { INoteSet } from "../noteSet/INoteSet";
import { DataviewQueryError } from "../noteSet/noteSetService";

Expand All @@ -8,10 +9,16 @@ export class DataviewService {
private _dataviewApi = new DataviewFacade();

public async getNoteSetFiles(noteSet: INoteSet): Promise<DataArray<Record<string, any>>> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const query = this.getOrCreateBaseDataviewQuery(noteSet);
try {
return await this._dataviewApi.pages(query);
let pages = await this._dataviewApi.pages(query);
if (noteSet.createdInLastNDays) {
pages = pages.where(p => p.file.cday > getDateOffsetByNDays(noteSet.createdInLastNDays));
}
if (noteSet.modifiedInLastNDays) {
pages = pages.where(p => p.file.mday > getDateOffsetByNDays(noteSet.modifiedInLastNDays));
}
return pages;
} catch (error) {
if (error instanceof DataviewNotInstalledError) {
throw error;
Expand Down
4 changes: 4 additions & 0 deletions src/noteSet/INoteSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export interface INoteSet {
tagsJoinType: JoinLogicOperators
folders: string[]
foldersToTagsJoinType: JoinLogicOperators
createdInLastNDays: number | undefined
modifiedInLastNDays: number | undefined
dataviewQuery: string
stats: INoteSetStats
}
Expand All @@ -26,6 +28,8 @@ export class EmptyNoteSet implements INoteSet {
tagsJoinType: JoinLogicOperators.OR
folders: []
foldersToTagsJoinType: JoinLogicOperators.OR
createdInLastNDays: undefined
modifiedInLastNDays: undefined
dataviewQuery: ""
stats: INoteSetStats

Expand Down
34 changes: 26 additions & 8 deletions src/noteSet/noteSetInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,41 @@ export class NoteSetInfoService {

private getNoteSetDescription(noteSet: INoteSet): string {

if (!this._dataviewService.getOrCreateBaseDataviewQuery(noteSet)) {
if (this.queryMatchesAllNotes(noteSet)) {
return "matches all notes"
}

let desc = "matches notes that ";
let desc: string[] = [];

if (noteSet.dataviewQuery && noteSet.dataviewQuery !== "") {
desc += `are matched with dataviewJS query ${noteSet.dataviewQuery}`;
return desc;
desc.push(`are matched with dataviewJS query ${noteSet.dataviewQuery}; `);
}

if (noteSet.tags && noteSet.tags?.length > 0) {
desc += `contain ${noteSet.tagsJoinType === JoinLogicOperators.AND ? "all" : "any"} of these tags: ${noteSet.tags.join(", ")}`;
if (noteSet.folders && noteSet.folders?.length > 0) desc += ` ${noteSet.foldersToTagsJoinType === JoinLogicOperators.AND ? "and" : "or"} `;
let tagString = `contain ${noteSet.tagsJoinType === JoinLogicOperators.AND ? "all" : "any"} of these tags: ${noteSet.tags.join(", ")}`;
if (noteSet.folders && noteSet.folders?.length > 0) {
tagString += ` ${noteSet.foldersToTagsJoinType === JoinLogicOperators.AND ? "and" : "or"} `;
}
desc.push(tagString);
}

if (noteSet.folders && noteSet.folders?.length > 0) {
desc += `are inside any of these folders (including nested folders): ${noteSet.folders.join(", ")}`;
desc.push(`are inside any of these folders (including nested folders): ${noteSet.folders.join(", ")}`);
}

if (noteSet.createdInLastNDays) {
desc.push(`are created in the last ${noteSet.createdInLastNDays} days`);
}
return desc;

if (noteSet.modifiedInLastNDays) {
desc.push(`are modified in the last ${noteSet.modifiedInLastNDays} days`);
}

return `matches notes that: ` + desc.join("; ");
}

private queryMatchesAllNotes(noteset: INoteSet): boolean {
return !(this._dataviewService.getOrCreateBaseDataviewQuery(noteset) || noteset.createdInLastNDays || noteset.createdInLastNDays);
}


Expand Down
2 changes: 2 additions & 0 deletions src/noteSet/noteSetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export class NoteSetService {
}




/** Open next file in noteSet.
* @param {INoteSet} noteSet
* @returns Promise
Expand Down
29 changes: 29 additions & 0 deletions src/settings/settingsTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,35 @@ export class SimpleNoteReviewPluginSettingsTab extends PluginSettingTab {
});
});

const createdDateSetting = new Setting(settingBodyEl);
createdDateSetting.setName("Created in last N days");
createdDateSetting.setDesc(`Number of days`);
createdDateSetting.addText(text => {
text.inputEl.type = 'number';
text.setValue(`${noteSet.createdInLastNDays}`);
text.onChange(async (val) => {
noteSet.createdInLastNDays = parseInt(val);
this._plugin.saveSettings();
updateNoteSetDisplayName();
} );
});

const modifiedDateSetting = new Setting(settingBodyEl);
modifiedDateSetting.setName("Modified in last N days");
modifiedDateSetting.setDesc(`Number of days`);
modifiedDateSetting.addText(text => {
text.inputEl.type = 'number';
text.setValue(`${noteSet.modifiedInLastNDays}`);
text.onChange(async (val) => {
noteSet.modifiedInLastNDays = parseInt(val);
this._plugin.saveSettings();
updateNoteSetDisplayName();
} );
});




// Advanced Settings

const advancedSectionHeader = new Setting(settingBodyEl);
Expand Down

0 comments on commit 81b1bec

Please sign in to comment.