Set the correct mime of imported ical content

as a bonus, this commit also includes a useful button:
duplicate an event into the next week
This commit is contained in:
FliegendeWurst 2021-05-07 12:09:48 +02:00
parent 79db3f6b4f
commit 76cdb42c21
7 changed files with 66 additions and 4 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
target target
.env

2
TODO.txt Normal file
View File

@ -0,0 +1,2 @@
- handle URL fields in ical files
- handle escape codes in ical files

View File

@ -1,6 +1,6 @@
{ {
"formatVersion": 1, "formatVersion": 1,
"appVersion": "0.46.9", "appVersion": "0.47.2",
"files": [ "files": [
{ {
"isClone": false, "isClone": false,
@ -378,6 +378,30 @@
} }
] ]
}, },
{
"isClone": false,
"noteId": "Q7KqwQ1693Bj",
"notePath": [
"vP5DkrdHVvv0",
"Q7KqwQ1693Bj"
],
"title": "duplicate into next week button",
"notePosition": 81,
"prefix": null,
"isExpanded": 0,
"type": "code",
"mime": "application/javascript;env=frontend",
"attributes": [
{
"type": "label",
"name": "run",
"value": "frontendStartup",
"isInheritable": false,
"position": 10
}
],
"dataFileName": "duplicate into next week button.js"
},
{ {
"isClone": false, "isClone": false,
"noteId": "X5pzYZriILAz", "noteId": "X5pzYZriILAz",

View File

@ -0,0 +1,30 @@
api.addButtonToToolbar({
title: 'Duplicate into next week',
icon: 'right-arrow-alt',
action: async () => {
await api.runOnBackend(async (noteId) => {
const note = await api.getNote(noteId);
const targetTemplate = await note.getRelation('template').value;
const startTime = await note.getLabelValue('startTime');
const location = await note.getLabelValue('location');
const date = new Date(startTime);
date.setTime(date.getTime() + (7*24*60*60*1000));
const todayDateStr = date.toISOString().substr(0,10);
const todayNote = await api.getDateNote(todayDateStr);
const newTime = todayDateStr + "T" + date.getHours().toString().padStart(2, '0') + ":" + date.getMinutes().toString().padStart(2, '0') + ":" + date.getSeconds().toString().padStart(2, '0');
const resp = await api.createNewNote({
parentNoteId: todayNote.noteId,
title: note.title,
content: '',
type: 'text'
});
await resp.note.setAttribute("relation", "template", targetTemplate);
await resp.note.setAttribute("label", "startTime", newTime);
if (location) {
await resp.note.setAttribute("label", "location", location);
}
}, [api.getActiveTabNote().noteId]);
}
});

View File

@ -7,6 +7,7 @@ const {req, res} = api;
const uid = req.body["uid"]; const uid = req.body["uid"];
const name = req.body["name"]; const name = req.body["name"];
const summary = req.body["summary"]; const summary = req.body["summary"];
const summaryHtml = req.body["summaryHtml"];
const location = req.body["location"]; const location = req.body["location"];
const fileName = req.body["fileName"]; const fileName = req.body["fileName"];
const fileData = req.body["fileData"]; const fileData = req.body["fileData"];
@ -31,8 +32,9 @@ const targetTemplate = await api.currentNote.getRelationValue('targetTemplate');
const options = { const options = {
"parentNoteId": dayNote.noteId, "parentNoteId": dayNote.noteId,
"title": name, "title": name,
"content": summary, "content": summaryHtml != "" ? summaryHtml : summary,
"type": "text" "type": "text",
"mime": summaryHtml != "" ? "text/html" : "text/plain"
}; };
const resp = await api.createNewNote(options); const resp = await api.createNewNote(options);
const note = resp.note; const note = resp.note;

View File

@ -35,6 +35,8 @@
</li> </li>
</ul> </ul>
</li> </li>
<li><a href="Implementation/duplicate%20into%20next%20week%20button.js" target="detail">duplicate into next week button</a>
</li>
<li><a href="Implementation/event%20template.html" target="detail">event template</a> <li><a href="Implementation/event%20template.html" target="detail">event template</a>
</li> </li>
<li><a href="Implementation/new_event%20handler.js" target="detail">new_event handler</a> <li><a href="Implementation/new_event%20handler.js" target="detail">new_event handler</a>

View File

@ -139,7 +139,8 @@ async fn process_one(update: Update, context: &mut Context) -> Result<(), Error>
if CLIENT.get(&trilium_url("/custom/new_event")).form(&json!({ if CLIENT.get(&trilium_url("/custom/new_event")).form(&json!({
"uid": calendar.events[0].uid, "uid": calendar.events[0].uid,
"name": calendar.events[0].summary, "name": calendar.events[0].summary,
"summary": calendar.events[0].description_html.as_deref().unwrap_or(&calendar.events[0].description), "summary": calendar.events[0].description,
"summaryHtml": calendar.events[0].description_html.as_deref().unwrap_or_default(),
"fileName": document.file_name, "fileName": document.file_name,
"fileData": text, "fileData": text,
"location": calendar.events[0].location, "location": calendar.events[0].location,