From cd2c4accaf1b086ead6c776818a6654d5ae15a6d Mon Sep 17 00:00:00 2001 From: quenousimporte Date: Wed, 13 Dec 2023 09:09:26 +0100 Subject: [PATCH] dropped: upcoming events feature --- handler.php | 13 ------ main.js | 112 --------------------------------------------- settingssample.php | 1 - 3 files changed, 126 deletions(-) diff --git a/handler.php b/handler.php index 5d726a7..17bd1e4 100644 --- a/handler.php +++ b/handler.php @@ -35,19 +35,6 @@ else if (isset($_POST['action'])) } 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': $result = array(); $str = file_get_contents($_POST['data']); diff --git a/main.js b/main.js index 269a2ce..3518f3e 100644 --- a/main.js +++ b/main.js @@ -237,12 +237,6 @@ var commands = [ hint: "Decrypt note", action: decryptnote }, -{ - hint: "Show upcoming events", - action: showupcomingevents, - remoteonly: true, - shortcut: "ctrl+e" -}, { hint: "Restore deleted note", 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() { 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) { var note = getnote(title); diff --git a/settingssample.php b/settingssample.php index 6a12dae..29fe1c6 100644 --- a/settingssample.php +++ b/settingssample.php @@ -1,5 +1,4 @@ \ No newline at end of file