generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
settings.ts
120 lines (102 loc) · 3.89 KB
/
settings.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import { App, Editor, MarkdownPostProcessorContext, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, SearchMatches, Setting } from 'obsidian';
import ReleaseTimeline from "./main";
export interface ReleaseTimelineSettings {
defaultSortOrder: string;
collapseEmptyYears: boolean;
bulletPoints: boolean;
collapseLimit: string;
collapseEmptyMonthsWeeklyTimeline: boolean;
weekDisplayFormat: string;
}
export const DEFAULT_SETTINGS: ReleaseTimelineSettings = {
defaultSortOrder: 'desc',
collapseEmptyYears: false,
bulletPoints: true,
collapseLimit: '2',
collapseEmptyMonthsWeeklyTimeline: true,
weekDisplayFormat: 'dateNames'
}
export class SampleSettingTab extends PluginSettingTab {
plugin: ReleaseTimeline;
constructor(app: App, plugin: ReleaseTimeline) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const {containerEl} = this;
containerEl.empty();
containerEl.createEl('h3', {text: 'Common settings'});
new Setting(containerEl)
.setName('Default sort order')
.setDesc('Used if sort order is not provided in a query')
.addDropdown( (dropdown) => {
dropdown.addOption("asc", "Ascending");
dropdown.addOption("desc", "Descending");
dropdown.setValue(this.plugin.settings.defaultSortOrder);
dropdown.onChange(async (value) => {
this.plugin.settings.defaultSortOrder = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Bullet points')
.setDesc('Improves readability for time periods with multiple entries')
.addToggle((toggle) => {
toggle.setValue(this.plugin.settings.bulletPoints);
toggle.onChange(async (value) => {
this.plugin.settings.bulletPoints = value;
await this.plugin.saveSettings();
this.updateCSS();
});
});
containerEl.createEl('h3', {text: 'Year timeline settings'});
new Setting(containerEl)
.setName('Collapse empty years')
.setDesc('Consecutive empty years will be collapsed into one range (2000-2018)')
.addToggle((toggle) => {
toggle.setValue(this.plugin.settings.collapseEmptyYears);
toggle.onChange(async (value) => {
this.plugin.settings.collapseEmptyYears = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Minimum number of years to be collapsed')
.addText(text => text.setPlaceholder('2')
.setValue(this.plugin.settings.collapseLimit)
.onChange(async (value) => {
this.plugin.settings.collapseLimit = value;
await this.plugin.saveSettings();
})
);
containerEl.createEl('h3', {text: 'Week timeline settings'});
new Setting(containerEl)
.setName('Collapse empty months')
.setDesc('Weeks will not be displayed for months without actual data')
.addToggle((toggle) => {
toggle.setValue(this.plugin.settings.collapseEmptyMonthsWeeklyTimeline);
toggle.onChange(async (value) => {
this.plugin.settings.collapseEmptyMonthsWeeklyTimeline = value;
await this.plugin.saveSettings();
});
});
new Setting(containerEl)
.setName('Week formatting')
.addDropdown( (dropdown) => {
dropdown.addOption("weekNames", 'Week names: "W15"');
dropdown.addOption("dateNames", 'Date names: "11-17"');
dropdown.setValue(this.plugin.settings.weekDisplayFormat);
dropdown.onChange(async (value) => {
this.plugin.settings.weekDisplayFormat = value;
await this.plugin.saveSettings();
});
});
}
updateCSS() {
let bulletOption = this.plugin.settings.bulletPoints;
let matches = document.querySelectorAll(".td-first, .td-next");
matches.forEach(function(match) {
match.classList.toggle('bullet-points', bulletOption);
});
}
}