-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathAskForDateForMeeting.js
60 lines (46 loc) · 1.55 KB
/
AskForDateForMeeting.js
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
// You have to export the function you wish to run.
// QuickAdd automatically passes a parameter, which is an object with the Obsidian app object
// and the QuickAdd API (see description further on this page).
module.exports = async (params) => {
// Object destructuring. We pull inputPrompt out of the QuickAdd API in params.
const { app } = params;
const activeFile = this.app.workspace.getActiveFile();
// Ask for meeting date
let inputDate = await params.quickAddApi.inputPrompt("Meeting date");
let parsedDate = moment(inputDate);
// Adjust year to future if needed
const dateNow = moment();
parsedDate.year(
parsedDate.dayOfYear() >= dateNow.dayOfYear()
? dateNow.year()
: dateNow.year() + 1
);
const dateFormatted = parsedDate.format("YYYY-MM-DD");
const todoDateFormatted = parsedDate.subtract(1, "days").format("YYYY-MM-DD");
// Ask for project
const meetingProject = await params.quickAddApi.suggester(
(file) => file.basename,
params.app.vault.getMarkdownFiles()
);
// Insert values
await params.quickAddApi.executeChoice("PasteMeetingInfo", {
DATE: dateFormatted,
PROJECT: meetingProject.basename,
TODODATE: todoDateFormatted,
});
// Change file name
await app.fileManager.renameFile(
activeFile,
activeFile.basename +
" " +
meetingProject.basename +
" - " +
dateFormatted +
".md"
);
// Move file to customer folder
await app.fileManager.renameFile(
activeFile,
"Customers/" + meetingProject.basename + "/" + activeFile.name
);
};