implemented ical exports
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -91,16 +91,21 @@ public class ApiEndpoint extends PathHandler {
|
||||
|
||||
@Override
|
||||
public boolean doGet(String path, HttpExchange ex) throws IOException {
|
||||
String hostname = "TODO"; // TODO
|
||||
String prodId = "TODO";
|
||||
return switch (path) {
|
||||
case "/event" -> sendContent(ex,getEvent(ex).map(ApiEndpoint::toJson).map(ApiEndpoint::httpError));
|
||||
case "/events/ical"-> sendContent(ex,eventList(ex).map(ApiEndpoint::toIcal).map(ApiEndpoint::httpError));
|
||||
case "/event/ical"-> sendContent(ex,getEvent(ex).map(event -> toIcal(event,hostname)).map(ical -> Util.wrapIcal(ical,prodId)).map(ApiEndpoint::httpError));
|
||||
case "/events/ical"-> sendContent(ex,eventList(ex).map(list -> toIcalList(list,hostname)).map(ical -> Util.wrapIcal(ical,prodId)).map(ApiEndpoint::httpError));
|
||||
case "/events/json" -> sendContent(ex,eventList(ex).map(ApiEndpoint::toJsonList).map(ApiEndpoint::httpError));
|
||||
case "/tags" -> listTags(ex);
|
||||
default -> unknownPath(ex, path);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
|
||||
@Override
|
||||
public boolean doPatch(String path, HttpExchange ex) throws IOException {
|
||||
if ("/event".equals(path)) return sendContent(ex, updateEvent(ex));
|
||||
return unknownPath(ex, path);
|
||||
@@ -260,10 +265,15 @@ public class ApiEndpoint extends PathHandler {
|
||||
return Payload.of(event);
|
||||
}
|
||||
|
||||
private static Result<String> toIcal(Result<List<Appointment>> res) {
|
||||
private static Result<String> toIcal(Result<Appointment> res, String hostname) {
|
||||
var opt = res.optional();
|
||||
return opt.isEmpty() ? transform(res) : Payload.of(opt.get().ical(hostname));
|
||||
}
|
||||
|
||||
private static Result<String> toIcalList(Result<List<Appointment>> res, String hostname) {
|
||||
var opt = res.optional();
|
||||
if (opt.isEmpty()) return transform(res);
|
||||
var list = opt.get().stream().map(Appointment::ical).collect(Collectors.joining("\n"));
|
||||
var list = opt.get().stream().map(event -> event.ical(hostname)).collect(Collectors.joining("\n"));
|
||||
return Payload.of(list);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,13 @@
|
||||
</head>
|
||||
<body class="event">
|
||||
<nav />
|
||||
<h1 id="title">Loading…</h1>
|
||||
<span id="buttons">
|
||||
<button title="create a copy of this event" onclick="window.top.location.href = location.href.replace('/static/event','/static/edit').replace('id=','copy=')">⧉ copy</button>
|
||||
<button title="edit the details of this event" onclick="window.top.location.href = location.href.replace('/static/event','/static/edit')">✍ edit</button>
|
||||
<button title="delete this event" onclick="confirmDelete()">🗑 delete</button>
|
||||
<button title="download this event" onclick="ical()"><u>⬇</u> download</button>
|
||||
</span>
|
||||
<h1 id="title">Loading…</h1>
|
||||
<div id="time">Loading time…</div>
|
||||
<div id="description">Loading description…</div>
|
||||
<div id="links">Loading links…</div>
|
||||
|
||||
@@ -159,4 +159,8 @@ table#eventlist{
|
||||
}
|
||||
.highlight{
|
||||
background: wheat;
|
||||
}
|
||||
|
||||
.event h1{
|
||||
margin-top: 40px;
|
||||
}
|
||||
@@ -20,10 +20,10 @@ async function handleEventData(response){
|
||||
if (response.ok){
|
||||
var event = await response.json();
|
||||
document.getElementsByTagName('h1')[0].innerHTML = event.title ? event.title : '';
|
||||
document.getElementById('time').innerHTML = event.start + (event.end ? '…'+event.end : '');
|
||||
element('time').innerHTML = '<b>'+event.start +'</b>'+ (event.end ? '…'+event.end : '') + ' @ '+event.location;
|
||||
addDescription(event);
|
||||
document.getElementById('tags').innerHTML = "Tags: "+event.tags.join(" ");
|
||||
var links = document.getElementById('links');
|
||||
element('tags').innerHTML = "Tags: "+event.tags.join(" ");
|
||||
var links = element('links');
|
||||
links.innerHTML = "";
|
||||
links.appendChild(linkList(event.links));
|
||||
attachmentList(event.attachments);
|
||||
@@ -78,4 +78,15 @@ function confirmDelete(){
|
||||
}
|
||||
}).then(handleDeleted);
|
||||
}
|
||||
}
|
||||
|
||||
function ical(){
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
var id = urlParams.get('id');
|
||||
if (id) {
|
||||
var elem = create('a');
|
||||
elem.setAttribute('href',location.href.replace('/static/event','/api/event/ical'));
|
||||
elem.setAttribute('download',`event-${id}.ics`);
|
||||
elem.click();
|
||||
}
|
||||
}
|
||||
@@ -115,19 +115,21 @@ function loadCurrentEvents(){
|
||||
function openIcal(){
|
||||
var url = location.href;
|
||||
var query = location.search;
|
||||
var params = new URLSearchParams(query);
|
||||
var tags = params.get('tags');
|
||||
var pos = url.indexOf('?');
|
||||
if (pos>1) url = url.substring(0,pos);
|
||||
if (!url.endsWith('/')) url += '/';
|
||||
url += 'api/events/ical'+query;
|
||||
var elem = create('a');
|
||||
elem.setAttribute('href',url);
|
||||
elem.setAttribute('download','calendar.ical');
|
||||
elem.setAttribute('download',(tags?tags.replace(',','+'):'calendar')+'.ics');
|
||||
elem.click();
|
||||
}
|
||||
|
||||
// shows the given url in an overlayed iframe
|
||||
function showOverlay(url){
|
||||
var div = document.getElementById('overlay');
|
||||
var div = element('overlay');
|
||||
div.innerHTML = '';
|
||||
var iframe = document.createElement('iframe');
|
||||
iframe.src = url;
|
||||
|
||||
Reference in New Issue
Block a user