Skip to content

Commit

Permalink
Merge pull request #55 from dartungar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dartungar authored Dec 6, 2023
2 parents 7d83ad2 + 354a00e commit 4d800fb
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 82 deletions.
7 changes: 5 additions & 2 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Editor, MarkdownView, Notice, Plugin } from "obsidian";
import { Notice, Plugin } from "obsidian";
import { getAPI } from "obsidian-dataview";
import { addSimpleNoteReviewIcon } from "src/UI/icon";
import { NoteSetService } from "src/noteSet/noteSetService";
import { SelectNoteSetModal } from "src/UI/selectNoteSetModal";
import {
Expand Down Expand Up @@ -71,9 +70,13 @@ export default class SimpleNoteReviewPlugin extends Plugin {
new DefaultSettings(),
await this.loadData()
);

this.settings.noteSets = this.noteSetService.sortNoteSets(this.settings.noteSets);
await this.noteSetService.updateAllNotesetErrors();
}

async saveSettings() {
this.settings.noteSets = this.noteSetService.sortNoteSets(this.settings.noteSets);
await this.saveData(this.settings);
}

Expand Down
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": "1.1.0",
"version": "1.2.0",
"minAppVersion": "1.1.0",
"description": "Simple, customizable plugin for easy note review, resurfacing & repetition.",
"author": "dartungar",
Expand Down
4 changes: 2 additions & 2 deletions src/UI/noteset/noteSetEditModal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SimpleNoteReviewPlugin from "main";
import { ButtonComponent, Modal, Setting, debounce, setIcon } from "obsidian";
import { ButtonComponent, Modal, Setting } from "obsidian";
import { INoteSet } from "src/noteSet/INoteSet";
import { JoinLogicOperators } from "src/settings/joinLogicOperators";

Expand Down Expand Up @@ -157,7 +157,7 @@ export class NoteSetEditModal extends Modal {
this._plugin.noteSetService.updateNoteSetStats(this._noteSet);
await this._plugin.saveSettings();
await this._plugin.activateView();
this._plugin.showNotice(`Note set "${this._noteSet.displayName}" saved.`);
this._plugin.showNotice(`Saved note set "${this._noteSet.displayName}".`);
this.close();
}

Expand Down
60 changes: 48 additions & 12 deletions src/UI/settingsTab.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import SimpleNoteReviewPlugin from "main";
import { App, PluginSettingTab, Setting, setIcon, debounce } from "obsidian";
import { JoinLogicOperators } from "src/settings/joinLogicOperators";
import { App, PluginSettingTab, Setting } from "obsidian";
import { NoteSetDeleteModal } from "src/UI/noteset/noteSetDeleteModal";
import { NoteSetInfoModal } from "src/UI/noteset/noteSetInfoModal";
import { ReviewAlgorithm } from "../settings/reviewAlgorightms";
import { NoteSetEditModal } from "./noteset/noteSetEditModal";

export class SimpleNoteReviewPluginSettingsTab extends PluginSettingTab {
Expand All @@ -15,7 +13,7 @@ export class SimpleNoteReviewPluginSettingsTab extends PluginSettingTab {
this.display();
}

display(): void {
display(): void {
const { containerEl } = this;

containerEl.empty();
Expand Down Expand Up @@ -73,7 +71,7 @@ export class SimpleNoteReviewPluginSettingsTab extends PluginSettingTab {

this._plugin.settings &&
this._plugin.settings.noteSets &&
this._plugin.settings.noteSets.forEach((noteSet) => {
this._plugin.settings.noteSets.forEach((noteSet, index) => {
this._plugin.noteSetService.updateNoteSetDisplayNameAndDescription(
noteSet
);
Expand All @@ -89,14 +87,10 @@ export class SimpleNoteReviewPluginSettingsTab extends PluginSettingTab {

updateHeader(noteSet.displayName);

if (noteSet?.stats?.totalCount === 0) {
if (noteSet?.validationError) {
setting.addExtraButton((cb) => {
cb.setIcon("alert-triangle")
.setTooltip("this note set appears to be empty. if you're sure it's not, click this icon to refresh stats.")
.onClick(async () => {
await this._plugin.noteSetService.updateNoteSetStats(noteSet);
this.display();
});
.setTooltip(noteSet?.validationError);
});
}

Expand All @@ -112,11 +106,53 @@ export class SimpleNoteReviewPluginSettingsTab extends PluginSettingTab {
});
});

setting.addExtraButton((cb) => {
cb.setIcon("rotate-cw")
.setTooltip("Reset review queue and update stats for this note set")
.onClick(async () => {
await this._plugin.noteSetService.validateRules(noteSet);
await this._plugin.reviewService.resetNotesetQueue(noteSet);
await this._plugin.noteSetService.updateNoteSetStats(noteSet);
this.display();
}
);
});

setting.addExtraButton(cb => {
cb.setIcon('arrow-up')
.setTooltip("Move element up")
.setDisabled(index === 0)
.onClick(() => {
if (index > 0) {
const temp = this._plugin.settings.noteSets[index - 1].sortOrder;
this._plugin.settings.noteSets[index - 1].sortOrder = noteSet.sortOrder;
noteSet.sortOrder = temp;
this._plugin.saveSettings();
this.display();
}
})
});

setting.addExtraButton(cb => {
cb.setIcon('arrow-down')
.setTooltip("Move element down")
.setDisabled(index >= this._plugin.settings.noteSets.length - 1)
.onClick(() => {
if (index < this._plugin.settings.noteSets.length - 1) {
const temp = this._plugin.settings.noteSets[index + 1].sortOrder;
this._plugin.settings.noteSets[index + 1].sortOrder = noteSet.sortOrder;
noteSet.sortOrder = temp;
this._plugin.saveSettings();
this.display();
}
})
});

setting.addExtraButton((cb) => {
cb.setIcon("edit")
.setTooltip("Edit Note set")
.onClick(() => {
let modal = new NoteSetEditModal(noteSet, this._plugin);
const modal = new NoteSetEditModal(noteSet, this._plugin);
modal.open();
modal.onClose = () => {
this.refresh();
Expand Down
23 changes: 8 additions & 15 deletions src/UI/sidebar/sidebarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import SimpleNoteReviewPlugin from "main";
import {
ItemView,
Setting,
TAbstractFile,
WorkspaceLeaf,
setIcon,
} from "obsidian";
import { INoteSet } from "src/noteSet/INoteSet";
import { NoteSetInfoModal } from "../noteset/noteSetInfoModal";
import { ReviewFrequency } from "src/noteSet/reviewFrequency";
import { NoteSetEditModal } from "../noteset/noteSetEditModal";
import { NoteSetEmptyError } from "src/noteSet/noteSetService";

export class SimpleNoteReviewSidebarView extends ItemView {
Expand All @@ -29,7 +26,7 @@ export class SimpleNoteReviewSidebarView extends ItemView {
// Nothing to clean up.
}

async renderView(): Promise<any> {
async renderView(): Promise<void> {
this.contentEl.empty();

this.createGeneralActionsEl(this.contentEl);
Expand All @@ -44,7 +41,7 @@ export class SimpleNoteReviewSidebarView extends ItemView {
}

private createGeneralActionsEl(parentEl: HTMLElement): HTMLElement {
let actionsEl = new Setting(parentEl);
const actionsEl = new Setting(parentEl);

actionsEl.setDesc("general actions:");

Expand All @@ -60,7 +57,9 @@ export class SimpleNoteReviewSidebarView extends ItemView {
cb.setIcon("settings")
.setTooltip("open plugin settings")
.onClick(() => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this.app as any).setting.open();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(this.app as any).setting.openTabById("simple-note-review");
});
});
Expand All @@ -69,7 +68,7 @@ export class SimpleNoteReviewSidebarView extends ItemView {
}

private createCurrentFileActionsEl(parentEl: HTMLElement): HTMLElement {
let actionsEl = new Setting(parentEl);
const actionsEl = new Setting(parentEl);

actionsEl.setDesc("current file actions:");

Expand Down Expand Up @@ -162,16 +161,10 @@ export class SimpleNoteReviewSidebarView extends ItemView {
section.setDesc("");
}

if (noteSet?.stats?.totalCount === 0) {
if (noteSet?.validationError) {
section.addExtraButton((cb) => {
cb.setIcon("alert-triangle")
.setTooltip(
"this note set appears to be empty. if you're sure it's not, click this icon to refresh stats."
)
.onClick(async () => {
await this._plugin.noteSetService.updateNoteSetStats(noteSet);
await this.renderView();
});
.setTooltip(noteSet?.validationError);
});
}

Expand Down Expand Up @@ -203,7 +196,7 @@ export class SimpleNoteReviewSidebarView extends ItemView {
cb.setIcon("rotate-cw")
.setTooltip("reset review queue for this note set")
.onClick(async () =>
this._plugin.reviewService.resetNotesetQueue(noteSet)
await this._plugin.reviewService.resetNotesetQueue(noteSet)
);
});

Expand Down
9 changes: 5 additions & 4 deletions src/dataview/dataviewFacade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ export class DataviewFacade {
}

public async pages(query: string): Promise<DataArray<Record<string, any>>> {
// this.throwIfDataviewNotInstalled();
// return this._api.pages(query);
return await this.invokeAndReinitDvCacheOnError(() => this._api.pages(query));
}

public async page(filepath: string): Promise<Record<string, any>> {
// this.throwIfDataviewNotInstalled();
// return this._api.page(filepath);
return await this.invokeAndReinitDvCacheOnError(() => this._api.page(filepath));
}

public async validate(query: string): Promise<boolean> {
const result = await this.invokeAndReinitDvCacheOnError(() => this._api.query(`LIST FROM ${query}`));
return result.successful;
}

public async getMetadataFieldValue(filepath: string, fieldName: string): Promise<string> {
const page = await this.page(filepath);
return page[fieldName];
Expand Down
4 changes: 4 additions & 0 deletions src/dataview/dataviewService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class DataviewService {
return null;
}

public validateQuery(query: string): Promise<boolean> {
return this._dataviewApi.validate(query);
}

public getPageFromPath(filepath: string): Record<string, any> {
return this._dataviewApi.page(filepath);
}
Expand Down
4 changes: 4 additions & 0 deletions src/noteSet/INoteSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { INoteSetStats } from "./INoteSetStats"
// TODO: excluded tags, folders, frontmatter keys
export interface INoteSet {
id: number
sortOrder: number | undefined
name: string
displayName: string
description: string
Expand All @@ -17,10 +18,12 @@ export interface INoteSet {
dataviewQuery: string
stats: INoteSetStats
queue: INoteQueue
validationError: string | undefined
}

export class EmptyNoteSet implements INoteSet {
id: number
sortOrder: undefined
name: "new note set"
displayName: string
description: string
Expand All @@ -33,6 +36,7 @@ export class EmptyNoteSet implements INoteSet {
dataviewQuery: ""
stats: INoteSetStats
queue: INoteQueue
validationError: undefined

constructor(id: number) {
this.id = id;
Expand Down
5 changes: 3 additions & 2 deletions src/noteSet/noteSetInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { JoinLogicOperators } from "src/settings/joinLogicOperators";
import { INoteSet } from "./INoteSet";
import { DataviewService } from "../dataview/dataviewService";
import { getDateOffsetByNDays } from "src/utils/dateUtils";
import { NoteSetService } from "./noteSetService";

export class NoteSetInfoService {

Expand Down Expand Up @@ -33,10 +34,10 @@ export class NoteSetInfoService {
private getNoteSetDescription(noteSet: INoteSet): string {

if (this.queryMatchesAllNotes(noteSet)) {
return "matches all notes"
return NoteSetService.MATCHES_ALL_STRING;
}

let desc: string[] = [];
const desc: string[] = [];

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

0 comments on commit 4d800fb

Please sign in to comment.