dropped: upcoming events feature

This commit is contained in:
quenousimporte 2023-12-13 09:09:26 +01:00
parent 3816e7631b
commit cd2c4accaf
3 changed files with 0 additions and 126 deletions

View File

@ -35,19 +35,6 @@ else if (isset($_POST['action']))
} }
break; break;
case 'cal':
if ($icsfile)
{
$result = array();
$result["ics"] = file_get_contents($icsfile);
echo json_encode($result);
}
else
{
echo '{"error": "cannot load ics file"}';
}
break;
case 'title': case 'title':
$result = array(); $result = array();
$str = file_get_contents($_POST['data']); $str = file_get_contents($_POST['data']);

112
main.js
View File

@ -237,12 +237,6 @@ var commands = [
hint: "Decrypt note", hint: "Decrypt note",
action: decryptnote action: decryptnote
}, },
{
hint: "Show upcoming events",
action: showupcomingevents,
remoteonly: true,
shortcut: "ctrl+e"
},
{ {
hint: "Restore deleted note", hint: "Restore deleted note",
action: restoredeleted action: restoredeleted
@ -924,67 +918,6 @@ function changesetting()
}); });
} }
function showupcomingevents()
{
queryremote({action: "cal"})
.then(data =>
{
if (!data.ics)
{
throw "could not retrieve events";
}
// keep future only
var events = ics2json(data.ics)
.filter(e => e.DTSTART >= new Date);
// sort by years and months
var sorted = {};
events.forEach(event =>
{
var date = new Date(event.DTSTART);
if (date >= new Date)
{
event.readabledate = date.toLocaleDateString('fr-FR', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
var month = event.readabledate.split(" ")[2];
var year = event.readabledate.split(" ")[3];
sorted[year] = sorted[year] || {};
sorted[year][month] = sorted[year][month] || [];
sorted[year][month].push(event);
}
});
// build output
var content = "";
for (var year in sorted)
{
content += "# " + year + "\n";
for (var month in sorted[year])
{
content += "## " + month.charAt(0).toUpperCase() + month.slice(1) + "\n";
for (var i in sorted[year][month])
{
var event = sorted[year][month][i];
if (i > 0 && event.DTSTART.getDate() != sorted[year][month][i-1].DTSTART.getDate() && event.DTSTART.getDay() <= sorted[year][month][i-1].DTSTART.getDay())
{
content += "\n\n";
}
content += event.readabledate.split(" ")[0] + " " + event.readabledate.split(" ")[1] + ": " + event.SUMMARY + "\n";
}
}
}
bindfile(
{
title: "Upcoming events",
content
});
togglepreview();
})
.catch(remotecallfailed);
}
function decryptnote() function decryptnote()
{ {
decryptstring(md.value) decryptstring(md.value)
@ -1389,51 +1322,6 @@ function init()
} }
} }
function cvdt(text)
{
var day = text.substr(0,8);
var time = text.substr(9,6);
return new Date(
day.substr(0,4),
parseInt(day.substr(4,2)) - 1,
day.substr(6,2),
time.substr(0,2),
time.substr(2,2),
time.substr(4,2));
}
function ics2json(ics)
{
var events = [];
ics.split("BEGIN:VEVENT").forEach(block =>
{
var evt = {};
block.split("\r\n").forEach(line =>
{
var tuple = line.split(":");
if (tuple.length > 1)
{
var field = tuple.shift().split(";")[0];
var value = tuple.join(":");
if (field == "DTSTART")
{
evt.DTSTART = cvdt(value);
}
else if (field == "UID" || field == "SUMMARY")
{
evt[field] = value;
}
}
});
if (evt.UID && evt.SUMMARY && evt.DTSTART)
{
events.push(evt);
}
});
return events.sort( (a,b) => a.DTSTART - b.DTSTART);
}
function getorcreate(title, content) function getorcreate(title, content)
{ {
var note = getnote(title); var note = getnote(title);

View File

@ -1,5 +1,4 @@
<?php <?php
$datafile = '../data/data.acs'; $datafile = '../data/data.acs';
$icsfile = '';
$password = ''; $password = '';
?> ?>