generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregateTags.ts
80 lines (69 loc) · 2.68 KB
/
aggregateTags.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { App, Modal, Setting, getAllTags } from "obsidian";
export class AggregateModal extends Modal {
include: string;
exclude: string;
onSubmit: (include: string, exclude: string) => void;
constructor(app: App, onSubmit: (include: string, exclude: string) => void) {
super(app);
this.onSubmit = onSubmit;
this.app = app;
}
onOpen() {
// Load tags
let listTags: string[] = [];
let listFiles = this.app.vault.getMarkdownFiles();
listFiles.forEach((file) => {
const cache = this.app.metadataCache.getFileCache(file);
listTags = listTags.concat(getAllTags(cache));
});
// Remove duplicates and sort tags
const tagsSet = new Set(listTags);
listTags = Array.from(tagsSet).sort();
// Get list of tags to exclude (Including the None option)
const tagsToExclude = ["None"].concat(listTags);
let { contentEl } = this;
contentEl.createEl("h1", { text: "Add Summary" });
if (listTags.length <= 0) {
contentEl.setText("There are no tags in your notes");
} else {
this.include = listTags[0];
new Setting(contentEl)
.setName("Select tag to include in the summary")
.addDropdown((menu) => {
for (let i=0; i<listTags.length; i++) {
menu.addOption(listTags[i], listTags[i]);
}
menu.setValue(listTags[0]);
menu.onChange((value) => {
this.include = value;
});
});
this.exclude = tagsToExclude[0];
new Setting(contentEl)
.setName("Select tag to exclude from the summary")
.addDropdown((menu) => {
for (let i=0; i<tagsToExclude.length; i++) {
menu.addOption(tagsToExclude[i], tagsToExclude[i]);
}
menu.setValue(tagsToExclude[0]);
menu.onChange((value) => {
this.exclude = value;
});
});
new Setting(contentEl)
.addButton((button) => {
button
.setButtonText("Add Summary")
.setCta()
.onClick(() => {
this.close();
this.onSubmit(this.include, this.exclude);
});
})
}
}
onClose() {
let { contentEl } = this;
contentEl.empty();
}
}