Skip to content

Commit

Permalink
- Misc: formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesb committed Oct 2, 2021
1 parent 471c8af commit 7add55a
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 107 deletions.
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export default class IW extends Plugin {
}

getDefaultQueuePath() {
return normalizePath([this.settings.queueFolderPath, this.settings.queueFileName].join(
"/"
));
return normalizePath(
[this.settings.queueFolderPath, this.settings.queueFileName].join("/")
);
}

createTagMap() {
Expand Down
17 changes: 13 additions & 4 deletions src/views/bulk-adding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ export class BulkAdderModal extends ModalBase {
}

protected getQueuePath() {
const queue = this.queueComponent.getValue() === ""
? path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath)
: this.queueComponent.getValue().withExtension(".md");
const queue =
this.queueComponent.getValue() === ""
? path.relative(
this.plugin.settings.queueFolderPath,
this.plugin.queue.queuePath
)
: this.queueComponent.getValue().withExtension(".md");

return normalizePath(
[this.plugin.settings.queueFolderPath, queue].join("/")
Expand All @@ -86,7 +90,12 @@ export class BulkAdderModal extends ModalBase {

contentEl.appendText("Queue: ");
this.queueComponent = new TextComponent(contentEl)
.setPlaceholder(path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath))
.setPlaceholder(
path.relative(
this.plugin.settings.queueFolderPath,
this.plugin.queue.queuePath
)
)
.onChange(
debounce(
(_: string) => {
Expand Down
141 changes: 70 additions & 71 deletions src/views/create-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import "../helpers/str-utils";
import { AFactorScheduler, Scheduler, SimpleScheduler } from "src/scheduler";

export class CreateQueueModal extends ModalBase {

private queueNameText: TextComponent;
private intervalText: TextComponent;
private afactorText: TextComponent;
Expand All @@ -31,34 +30,35 @@ export class CreateQueueModal extends ModalBase {
//
// Queue Name
contentEl.appendText("Queue Name: ");
this.queueNameText = new TextComponent(contentEl)
.setPlaceholder("Examples: queue, folder/queue");
this.queueNameText = new TextComponent(contentEl).setPlaceholder(
"Examples: queue, folder/queue"
);
contentEl.createEl("br");
this.queueNameText.inputEl.focus();
this.queueNameText.inputEl.select();

//
// Queue Type
contentEl.appendText("Scheduler: ")
contentEl.appendText("Scheduler: ");
this.schedulerDropdown = new DropdownComponent(contentEl)
.addOption("afactor", "A-Factor Scheduler")
.addOption("simple", "Simple Scheduler")
.setValue(this.plugin.settings.defaultQueueType)
.onChange((value: "afactor" | "simple") => this.showHideSchedulerSettings(value));
.addOption("afactor", "A-Factor Scheduler")
.addOption("simple", "Simple Scheduler")
.setValue(this.plugin.settings.defaultQueueType)
.onChange((value: "afactor" | "simple") =>
this.showHideSchedulerSettings(value)
);
contentEl.createEl("br");

//
// Interval
contentEl.appendText("Default Interval: ");
this.intervalText = new TextComponent(contentEl)
.setValue("1")
this.intervalText = new TextComponent(contentEl).setValue("1");
contentEl.createEl("br");

//
// Afactor
contentEl.appendText("Default A-Factor: ");
this.afactorText = new TextComponent(contentEl)
.setValue("2");
this.afactorText = new TextComponent(contentEl).setValue("2");
contentEl.createEl("br");

//
Expand All @@ -75,7 +75,7 @@ export class CreateQueueModal extends ModalBase {
this.subscribeToEvents();
}

subscribeToEvents() {
subscribeToEvents() {
this.contentEl.addEventListener("keydown", async (ev) => {
if (ev.key === "Enter") {
await this.create();
Expand All @@ -84,67 +84,66 @@ subscribeToEvents() {
});
}

createScheduler(): Scheduler {
if (this.schedulerDropdown.getValue() === "afactor") {
const interval = Number(this.intervalText.getValue());
if (!interval.isValidInterval()) {
LogTo.Debug("Invalid interval data.", true);
return;
}

const afactor = Number(this.afactorText.getValue());
if (!afactor.isValidAFactor()) {
LogTo.Debug("Invalid afactor data.", true);
return;
}

return new AFactorScheduler(afactor, interval);
}
else {
return new SimpleScheduler();
}
createScheduler(): Scheduler {
if (this.schedulerDropdown.getValue() === "afactor") {
const interval = Number(this.intervalText.getValue());
if (!interval.isValidInterval()) {
LogTo.Debug("Invalid interval data.", true);
return;
}

const afactor = Number(this.afactorText.getValue());
if (!afactor.isValidAFactor()) {
LogTo.Debug("Invalid afactor data.", true);
return;
}

return new AFactorScheduler(afactor, interval);
} else {
return new SimpleScheduler();
}
}

async create() {
const queueName = this.queueNameText.getValue();
if (!queueName || queueName.length === 0) {
LogTo.Debug("Invalid queue name.", true);
return;
}

async create() {
const queueName = this.queueNameText.getValue();
if (!queueName || queueName.length === 0) {
LogTo.Debug("Invalid queue name.", true);
return;
}

const queueNameWithExt = queueName.withExtension(".md");
const queueFile = normalizePath([this.plugin.settings.queueFolderPath, queueNameWithExt].join("/"));
if (await this.plugin.files.exists(queueFile)) {
LogTo.Debug("Queue already exists!", true);
return;
}

const schedulerData = this.createScheduler()?.toString();
if (!schedulerData || schedulerData.length === 0)
return;

LogTo.Debug("Creating queue: " + queueName, true);
await this.plugin.files.createIfNotExists(queueFile, schedulerData);
await this.plugin.loadQueue(queueFile);
const queueNameWithExt = queueName.withExtension(".md");
const queueFile = normalizePath(
[this.plugin.settings.queueFolderPath, queueNameWithExt].join("/")
);
if (await this.plugin.files.exists(queueFile)) {
LogTo.Debug("Queue already exists!", true);
return;
}

showHideSchedulerSettings(value: "simple" | "afactor") {
switch (value) {
case "simple":
this.intervalText.setDisabled(true);
this.afactorText.setDisabled(true);
this.intervalText.setValue("---");
this.afactorText.setValue("---");
return;
case "afactor":
this.intervalText.setDisabled(false);
this.afactorText.setDisabled(false);
this.intervalText.setValue("1");
this.afactorText.setValue("2");
return;
default:
throw new Error("Expected simple or afactor, got: " + value);
}
const schedulerData = this.createScheduler()?.toString();
if (!schedulerData || schedulerData.length === 0) return;

LogTo.Debug("Creating queue: " + queueName, true);
await this.plugin.files.createIfNotExists(queueFile, schedulerData);
await this.plugin.loadQueue(queueFile);
}

showHideSchedulerSettings(value: "simple" | "afactor") {
switch (value) {
case "simple":
this.intervalText.setDisabled(true);
this.afactorText.setDisabled(true);
this.intervalText.setValue("---");
this.afactorText.setValue("---");
return;
case "afactor":
this.intervalText.setDisabled(false);
this.afactorText.setDisabled(false);
this.intervalText.setValue("1");
this.afactorText.setValue("2");
return;
default:
throw new Error("Expected simple or afactor, got: " + value);
}
}
}
21 changes: 10 additions & 11 deletions src/views/file-suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ export class FileSuggest extends TextInputSuggest<TFile> {
const files: TFile[] = [];

for (const file of abstractFiles) {
if (!(file instanceof TFile))
continue;
if (!(file instanceof TFile)) continue;

if (!(this.plugin.files.isDescendantOf(file, this.folder())))
continue;

if (file.extension !== "md")
continue
if (!this.plugin.files.isDescendantOf(file, this.folder())) continue;

if (file.extension !== "md") continue;

const relPath = path.relative(this.folder().path, file.path);
if (relPath.contains(inputStr))
files.push(file);
}
if (relPath.contains(inputStr)) files.push(file);
}

return files;
}
Expand All @@ -45,7 +41,10 @@ export class FileSuggest extends TextInputSuggest<TFile> {
}

selectSuggestion(file: TFile): void {
this.inputEl.value = path.relative(this.plugin.settings.queueFolderPath, file.path)
this.inputEl.value = path.relative(
this.plugin.settings.queueFolderPath,
file.path
);
this.inputEl.trigger("input");
this.close();
}
Expand Down
18 changes: 13 additions & 5 deletions src/views/modals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ abstract class ReviewModal extends ModalBase {
// Queue

contentEl.appendText("Queue: ");
this.inputQueueField = new TextComponent(contentEl)
.setPlaceholder(path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath));
this.inputQueueField = new TextComponent(contentEl).setPlaceholder(
path.relative(
this.plugin.settings.queueFolderPath,
this.plugin.queue.queuePath
)
);
let folderFunc = () =>
this.plugin.app.vault.getAbstractFileByPath(
this.plugin.settings.queueFolderPath
Expand Down Expand Up @@ -114,9 +118,13 @@ abstract class ReviewModal extends ModalBase {
}

getQueuePath() {
const queue = this.inputQueueField.getValue() === ""
? path.relative(this.plugin.settings.queueFolderPath, this.plugin.queue.queuePath)
: this.inputQueueField.getValue().withExtension(".md");
const queue =
this.inputQueueField.getValue() === ""
? path.relative(
this.plugin.settings.queueFolderPath,
this.plugin.queue.queuePath
)
: this.inputQueueField.getValue().withExtension(".md");

return normalizePath(
[this.plugin.settings.queueFolderPath, queue].join("/")
Expand Down
12 changes: 7 additions & 5 deletions src/views/queue-modal.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { normalizePath, FuzzySuggestModal } from "obsidian";
import * as path from 'path';
import * as path from "path";
import { LogTo } from "src/logger";
import IW from "../main";

Expand All @@ -18,17 +18,19 @@ export class QueueLoadModal extends FuzzySuggestModal<string> {
}

getItems(): string[] {
const queueFolderPath = normalizePath(this.plugin.settings.queueFolderPath)
const defaultQueue = path.relative(queueFolderPath, this.plugin.getDefaultQueuePath());
const queueFolderPath = normalizePath(this.plugin.settings.queueFolderPath);
const defaultQueue = path.relative(
queueFolderPath,
this.plugin.getDefaultQueuePath()
);
const folder = this.plugin.files.getTFolder(queueFolderPath);
if (folder) {
let files = this.plugin.app.vault
.getMarkdownFiles()
.filter((file) => this.plugin.files.isDescendantOf(file, folder))
.map((file) => path.relative(queueFolderPath, file.path));

if (!files.some((f) => f === defaultQueue))
files.push(defaultQueue);
if (!files.some((f) => f === defaultQueue)) files.push(defaultQueue);
return files;
}

Expand Down
17 changes: 10 additions & 7 deletions src/views/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ export class IWSettingsTab extends PluginSettingTab {
}

const validDates: string[] = inputDates
.filter(([_, date]: [string, any]) => date != null && date.date)
.filter(
([_, date]: [string, any]) => date != null && date.date
)
.map(([s, _]: [string, Date]) => s);

if (inputDates.length !== validDates.length) {
Expand All @@ -134,12 +136,13 @@ export class IWSettingsTab extends PluginSettingTab {
);
}

const dateOptionsRecord: Record<string, string> = validDates
.reduce((acc, x) =>
{
acc[x] = x;
return acc;
}, {} as Record<string, string>);
const dateOptionsRecord: Record<
string,
string
> = validDates.reduce((acc, x) => {
acc[x] = x;
return acc;
}, {} as Record<string, string>);

LogTo.Debug(
"Setting dropdown date options to " +
Expand Down
4 changes: 3 additions & 1 deletion src/views/status-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export class StatusBar {

updateCurrentQueue(queuePath: string) {
const normalized = normalizePath(queuePath);
const name = path.relative(this.plugin.settings.queueFolderPath, normalized).rtrim(".md")
const name = path
.relative(this.plugin.settings.queueFolderPath, normalized)
.rtrim(".md");
this.queueText.innerText =
name && name.length > 0 ? "Queue: " + name : "Queue: None";
}
Expand Down

0 comments on commit 7add55a

Please sign in to comment.