generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsettingsTab.ts
164 lines (143 loc) · 5.17 KB
/
settingsTab.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import { App, PluginSettingTab, Setting, ButtonComponent, DropdownComponent, ToggleComponent } from "obsidian";
import ConfluenceSyncPlugin from "./main";
import { ConfluenceAPIClient } from "./modules/apiClient";
import { ConfluenceSpace } from "./definition/confluenceTypes";
import { FolderSuggest } from "./modules/suggester";
import { SpaceConfig } from "./settings";
export class ConfluenceSyncSettingTab extends PluginSettingTab {
plugin: ConfluenceSyncPlugin;
confluenceClient: ConfluenceAPIClient;
constructor(app: App, plugin: ConfluenceSyncPlugin) {
super(app, plugin);
this.plugin = plugin;
this.confluenceClient = new ConfluenceAPIClient(
this.plugin.settings.confluenceBaseURL,
this.plugin.settings.apiToken,
this.plugin.settings.username
);
}
display(): void {
const { containerEl } = this;
containerEl.empty();
new Setting(containerEl)
.setName('Enable Sync')
.setDesc('Toggle the active Status of the SyncManager (Warning: active syncs won`t be terminated)')
.addToggle(toggle =>
toggle
.setValue(this.plugin.settings.start)
.onChange(async (value) => {
console.log(value)
this.plugin.settings.start = value
await this.plugin.saveSettings();
if (value === true) {
this.plugin.initializeSyncManagers()
console.info('Sync initialized')
} else {
this.plugin.stopInitializedSyncManagers()
console.info('Sync stopped')
}
})
)
new Setting(containerEl)
.setName("Confluence Base URL")
.setDesc("The base URL of your Confluence instance.")
.addText(text =>
text
.setPlaceholder("https://your-confluence-domain.atlassian.net/wiki")
.setValue(this.plugin.settings.confluenceBaseURL)
.onChange(async (value) => {
this.plugin.settings.confluenceBaseURL = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("API Token")
.setDesc("Your Confluence API token.")
.addText(text =>
text
.setPlaceholder("Enter API token")
.setValue(this.plugin.settings.apiToken)
.onChange(async (value) => {
this.plugin.settings.apiToken = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Username")
.setDesc("Your Confluence username (usually an email address).")
.addText(text =>
text
.setPlaceholder("Enter username")
.setValue(this.plugin.settings.username)
.onChange(async (value) => {
this.plugin.settings.username = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Sync Interval (in minutes)")
.setDesc("How often should the sync run (in minutes)?")
.addText(text =>
text
.setPlaceholder("15")
.setValue(this.plugin.settings.syncInterval.toString())
.onChange(async (value) => {
const numValue = parseInt(value);
if (!isNaN(numValue)) {
this.plugin.settings.syncInterval = numValue;
await this.plugin.saveSettings();
}
})
);
new Setting(containerEl).setName('Spaces to Sync').setHeading()
this.plugin.settings.spaces.forEach((space, index) => {
this.createSpaceSetting(containerEl, space, index);
});
new Setting(containerEl)
.addButton((button: ButtonComponent) => {
button
.setButtonText("Add Space")
.setCta()
.onClick(() => {
this.plugin.settings.spaces.push({ spaceKey: "", targetFolderPath: "" });
this.plugin.saveSettings();
this.display();
});
});
}
async createSpaceSetting(containerEl: HTMLElement, space: SpaceConfig, index: number) {
const spaceDiv = containerEl.createDiv({ cls: 'space-setting-row' });
const dropdown = new DropdownComponent(spaceDiv);
const spaces = await this.confluenceClient.fetchSpaces();
spaces.results.forEach((space: ConfluenceSpace) => {
dropdown.addOption(space.key, space.name);
});
dropdown.setValue(space.spaceKey);
dropdown.onChange(async (value) => {
space.spaceKey = value;
await this.plugin.saveSettings();
});
const textComponent = new Setting(spaceDiv)
.setName('<- From Space to Target Folder ->')
.addSearch((component) => {
new FolderSuggest(component.inputEl, this.app);
component
.setPlaceholder("Target Folder Path")
.setValue(space.targetFolderPath)
.onChange(async (value) => {
space.targetFolderPath = value;
await this.plugin.saveSettings();
})
});
const deleteButton = new ButtonComponent(spaceDiv);
deleteButton
.setIcon("trash")
.setWarning()
.setTooltip("Delete Space")
.onClick(async () => {
this.plugin.settings.spaces.splice(index, 1);
await this.plugin.saveSettings();
this.display();
});
}
}