You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
202 lines
22 KiB
202 lines
22 KiB
3 years ago
|
/*
|
||
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||
|
if you want to view the source, please visit the github repository of this plugin
|
||
|
*/
|
||
|
|
||
|
var __create = Object.create;
|
||
|
var __defProp = Object.defineProperty;
|
||
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||
|
var __getProtoOf = Object.getPrototypeOf;
|
||
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
||
|
var __export = (target, all) => {
|
||
|
__markAsModule(target);
|
||
|
for (var name in all)
|
||
|
__defProp(target, name, { get: all[name], enumerable: true });
|
||
|
};
|
||
|
var __reExport = (target, module2, desc) => {
|
||
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
||
|
for (let key of __getOwnPropNames(module2))
|
||
|
if (!__hasOwnProp.call(target, key) && key !== "default")
|
||
|
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
||
|
}
|
||
|
return target;
|
||
|
};
|
||
|
var __toModule = (module2) => {
|
||
|
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
||
|
};
|
||
|
var __async = (__this, __arguments, generator) => {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
var fulfilled = (value) => {
|
||
|
try {
|
||
|
step(generator.next(value));
|
||
|
} catch (e) {
|
||
|
reject(e);
|
||
|
}
|
||
|
};
|
||
|
var rejected = (value) => {
|
||
|
try {
|
||
|
step(generator.throw(value));
|
||
|
} catch (e) {
|
||
|
reject(e);
|
||
|
}
|
||
|
};
|
||
|
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
||
|
step((generator = generator.apply(__this, __arguments)).next());
|
||
|
});
|
||
|
};
|
||
|
|
||
|
// main.ts
|
||
|
__export(exports, {
|
||
|
DEFAULT_SETTINGS: () => DEFAULT_SETTINGS,
|
||
|
default: () => PackratPlugin
|
||
|
});
|
||
|
var import_obsidian = __toModule(require("obsidian"));
|
||
|
var DEFAULT_SETTINGS = {
|
||
|
deletion_trigger: "%%done_del%%",
|
||
|
bottom_trigger: "%%done_end%%",
|
||
|
archive_trigger: "%%done_log%%",
|
||
|
archive_filepath: "archive.md"
|
||
|
};
|
||
|
var PackratPlugin = class extends import_obsidian.Plugin {
|
||
|
onload() {
|
||
|
return __async(this, null, function* () {
|
||
|
console.log("Packrat: Loading...");
|
||
|
yield this.loadSettings();
|
||
|
this.addSettingTab(new PackratSettingTab(this.app, this));
|
||
|
this.addCommand({
|
||
|
id: "run",
|
||
|
name: "Process completed recurring Tasks within the active note",
|
||
|
checkCallback: (checking) => {
|
||
|
const { workspace } = this.app;
|
||
|
const activeFile = workspace.getActiveFile();
|
||
|
if (activeFile && activeFile.extension == "md") {
|
||
|
if (checking) {
|
||
|
return true;
|
||
|
}
|
||
|
this.ProcessCompletedRecurringTasks(activeFile);
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
onunload() {
|
||
|
console.log("Packrat: Unloading...");
|
||
|
}
|
||
|
loadSettings() {
|
||
|
return __async(this, null, function* () {
|
||
|
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
|
||
|
});
|
||
|
}
|
||
|
saveSettings() {
|
||
|
return __async(this, null, function* () {
|
||
|
yield this.saveData(this.settings);
|
||
|
});
|
||
|
}
|
||
|
ProcessCompletedRecurringTasks(activeFile) {
|
||
|
return __async(this, null, function* () {
|
||
|
try {
|
||
|
const { vault } = this.app;
|
||
|
const rruleSignifier = "\u{1F501}".normalize();
|
||
|
const deleteTrigger = this.settings.deletion_trigger;
|
||
|
const archiveTrigger = this.settings.archive_trigger;
|
||
|
const bottomTrigger = this.settings.bottom_trigger;
|
||
|
const archiveFilename = this.settings.archive_filepath;
|
||
|
const archiveFile = vault.getAbstractFileByPath(archiveFilename) || (yield vault.create(archiveFilename, ""));
|
||
|
let deletedTaskCount = 0;
|
||
|
let movedTaskCount = 0;
|
||
|
let archivedTaskCount = 0;
|
||
|
let thisLine = "";
|
||
|
let writebackLines = [];
|
||
|
let appendLines = [];
|
||
|
let archiveLines = [];
|
||
|
let results = [];
|
||
|
let fileContents = yield vault.read(activeFile);
|
||
|
fileContents = fileContents.split("\n");
|
||
|
for (let i = 0; i < fileContents.length; i++) {
|
||
|
thisLine = fileContents[i];
|
||
|
let firstFive = thisLine.substring(0, 5).toUpperCase();
|
||
|
if (firstFive === "- [X]" && thisLine.indexOf(rruleSignifier) != -1) {
|
||
|
if (0 < thisLine.indexOf(deleteTrigger)) {
|
||
|
deletedTaskCount += 1;
|
||
|
continue;
|
||
|
}
|
||
|
if (0 < thisLine.indexOf(archiveTrigger)) {
|
||
|
archiveLines.push(thisLine);
|
||
|
archivedTaskCount += 1;
|
||
|
continue;
|
||
|
}
|
||
|
if (0 < thisLine.indexOf(bottomTrigger)) {
|
||
|
appendLines.push(thisLine);
|
||
|
movedTaskCount += 1;
|
||
|
continue;
|
||
|
}
|
||
|
writebackLines.push(thisLine);
|
||
|
} else {
|
||
|
writebackLines.push(thisLine);
|
||
|
}
|
||
|
}
|
||
|
if (archivedTaskCount > 0) {
|
||
|
let archiveFileContents = yield vault.read(archiveFile);
|
||
|
archiveFileContents = archiveFileContents.split("\n");
|
||
|
archiveFileContents = archiveFileContents.concat(archiveLines);
|
||
|
vault.modify(archiveFile, archiveFileContents.join("\n"));
|
||
|
}
|
||
|
results = writebackLines.concat(appendLines);
|
||
|
vault.modify(activeFile, results.join("\n"));
|
||
|
var tdMsg = `${deletedTaskCount} tasks deleted
|
||
|
`;
|
||
|
var tmMsg = `${movedTaskCount} tasks moved to end of note
|
||
|
`;
|
||
|
var taMsg = `${archivedTaskCount} tasks archived
|
||
|
`;
|
||
|
const noticeText = tdMsg + tmMsg + taMsg;
|
||
|
new import_obsidian.Notice(noticeText);
|
||
|
} catch (err) {
|
||
|
new import_obsidian.Notice(err);
|
||
|
console.log(err);
|
||
|
return;
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
var PackratSettingTab = class extends import_obsidian.PluginSettingTab {
|
||
|
constructor(app, plugin) {
|
||
|
super(app, plugin);
|
||
|
this.defaultDeletionTrigger = "%%done_del%%";
|
||
|
this.defaultBottomTrigger = "%%done_move%%";
|
||
|
this.defaultArchiveTrigger = "%%done_log%%";
|
||
|
this.defaultArchiveFilepath = "logfile.md";
|
||
|
this.plugin = plugin;
|
||
|
}
|
||
|
display() {
|
||
|
const { containerEl } = this;
|
||
|
containerEl.empty();
|
||
|
containerEl.createEl("h2", { text: "Packrat plugin settings" });
|
||
|
new import_obsidian.Setting(containerEl).setName("Deletion trigger").setDesc("Text to trigger deletion of completed recurring Task instance").addText((text) => text.setPlaceholder(this.defaultDeletionTrigger).setValue(this.plugin.settings.deletion_trigger).onChange((value) => __async(this, null, function* () {
|
||
|
console.log("deletion_trigger: " + value);
|
||
|
this.plugin.settings.deletion_trigger = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
})));
|
||
|
new import_obsidian.Setting(containerEl).setName('"Move to end of file" trigger').setDesc("Text to trigger moving completed recurring Task instance to bottom of Active note").addText((text) => text.setPlaceholder(this.defaultbottomTrigger).setValue(this.plugin.settings.bottom_trigger).onChange((value) => __async(this, null, function* () {
|
||
|
console.log("bottom_trigger: " + value);
|
||
|
this.plugin.settings.bottom_trigger = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
})));
|
||
|
new import_obsidian.Setting(containerEl).setName("Archive trigger").setDesc("Text to trigger moving completed recurring Task instance to archive note").addText((text) => text.setPlaceholder(this.defaultarchiveTrigger).setValue(this.plugin.settings.archive_trigger).onChange((value) => __async(this, null, function* () {
|
||
|
console.log("archive_trigger: " + value);
|
||
|
this.plugin.settings.archive_trigger = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
})));
|
||
|
new import_obsidian.Setting(containerEl).setName("Archive file").setDesc('Relative filepath to archive file (include ".md" extension)').addText((text) => text.setPlaceholder(this.defaultArchiveFilepath).setValue(this.plugin.settings.archive_filepath).onChange((value) => __async(this, null, function* () {
|
||
|
console.log("archive_filepath: " + value);
|
||
|
this.plugin.settings.archive_filepath = value;
|
||
|
yield this.plugin.saveSettings();
|
||
|
})));
|
||
|
}
|
||
|
};
|
||
|
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsibWFpbi50cyJdLAogICJzb3VyY2VzQ29udGVudCI6IFsiaW1wb3J0IHsgQXBwLCBOb3RpY2UsIFBsdWdpbiwgUGx1Z2luU2V0dGluZ1RhYiwgU2V0dGluZywgVEZpbGUgfSBmcm9tICdvYnNpZGlhbic7XG5cbmV4cG9ydCBpbnRlcmZhY2UgUGFja3JhdFNldHRpbmdzIHtcblx0ZGVsZXRpb25fdHJpZ2dlcjogc3RyaW5nO1xuXHRib3R0b21fdHJpZ2dlcjogc3RyaW5nO1xuXHRhcmNoaXZlX3RyaWdnZXI6IHN0cmluZztcblx0YXJjaGl2ZV9maWxlcGF0aDogc3RyaW5nO1xufVxuXG5leHBvcnQgY29uc3QgREVGQVVMVF9TRVRUSU5HUzogUGFja3JhdFNldHRpbmdzID0ge1xuXHRkZWxldGlvbl90cmlnZ2VyOiAnJSVkb25lX2RlbCUlJyxcblx0Ym90dG9tX3RyaWdnZXI6ICclJWRvbmVfZW5kJSUnLFxuXHRhcmNoaXZlX3RyaWdnZXI6ICclJWRvbmVfbG9nJSUnLFxuXHRhcmNoaXZlX2ZpbGVwYXRoOiAnYXJjaGl2ZS5tZCcsXG59XG5cbmV4cG9ydCBkZWZhdWx0IGNsYXNzIFBhY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