serialized events
This commit is contained in:
@ -42,7 +42,7 @@ dependencies {
|
|||||||
implementation 'org.webjars:jquery-ui:1.13.2'
|
implementation 'org.webjars:jquery-ui:1.13.2'
|
||||||
implementation 'org.webjars:fullcalendar:5.11.3'
|
implementation 'org.webjars:fullcalendar:5.11.3'
|
||||||
|
|
||||||
implementation 'com.google.code.gson:gson:2.9.0';
|
implementation 'com.google.code.gson:gson:2.10.1';
|
||||||
|
|
||||||
implementation 'org.webjars.bowergithub.datatables:datatables:1.10.21'
|
implementation 'org.webjars.bowergithub.datatables:datatables:1.10.21'
|
||||||
|
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
package de.jottyfan.timetrack.modules.calendar;
|
package de.jottyfan.timetrack.modules.calendar;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jotty
|
* @author jotty
|
||||||
@ -9,23 +16,19 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CalendarService {
|
public class CalendarService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DummyRepository dummyRepository;
|
||||||
|
|
||||||
// TODO: implement a davical database reader as a repository
|
// TODO: implement a davical database reader as a repository
|
||||||
// TODO: implement a caldav client as repository
|
// TODO: implement a caldav client as repository
|
||||||
// TODO: implement a radicale file reader as repository
|
// TODO: implement a radicale file reader as repository
|
||||||
// TODO: create resource management database table for the calendar
|
// TODO: create resource management database table for the calendar credentials
|
||||||
|
|
||||||
public String getJsonEvents() {
|
public String getJsonEvents() {
|
||||||
StringBuilder buf = new StringBuilder("[");
|
Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new LocalDateAdapter())
|
||||||
|
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter()).create();
|
||||||
// TODO: use List<EventBean> instead
|
return gson.toJson(dummyRepository.getExamples());
|
||||||
|
|
||||||
buf.append(
|
|
||||||
"{ id: 'example3', title: 'all day event', start: '2023-05-08', allDay: true, backgroundColor: 'darkcyan'},");
|
|
||||||
buf.append(" { id: 'i1', title: 'overlapping', start: '2023-05-08T10:00', end: '2023-05-09T10:00'},");
|
|
||||||
buf.append(" { id: 'i2', title: 'developing', start: '2023-05-09T08:00', end: '2023-05-09T10:15'}");
|
|
||||||
buf.append("]");
|
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package de.jottyfan.timetrack.modules.calendar;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public class DummyRepository {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get example dates
|
||||||
|
*
|
||||||
|
* @return the example dates
|
||||||
|
*/
|
||||||
|
public List<EventBean> getExamples() {
|
||||||
|
List<EventBean> list = new ArrayList<>();
|
||||||
|
|
||||||
|
EventBean event1 = EventBean.ofAllDayEvent("e1", "all day event", LocalDate.of(2023, 5, 8));
|
||||||
|
event1.setBackgroundColor("darkcyan");
|
||||||
|
|
||||||
|
list.add(event1);
|
||||||
|
|
||||||
|
EventBean event2 = EventBean.ofEvent("e2", "overlapping", LocalDate.of(2023, 5, 8).atTime(10, 0),
|
||||||
|
LocalDate.of(2023, 5, 9).atTime(10, 0));
|
||||||
|
|
||||||
|
list.add(event2);
|
||||||
|
|
||||||
|
EventBean event3 = EventBean.ofEvent("e3", "developing", LocalDate.of(2023, 5, 10).atTime(8, 0),
|
||||||
|
LocalDate.of(2023, 5, 10).atTime(10, 0));
|
||||||
|
|
||||||
|
list.add(event3);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package de.jottyfan.timetrack.modules.calendar;
|
package de.jottyfan.timetrack.modules.calendar;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -42,24 +43,42 @@ public class EventBean implements Serializable {
|
|||||||
classNames = new ArrayList<>();
|
classNames = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public String toString() {
|
* create new all day event
|
||||||
StringBuilder buf = new StringBuilder("{");
|
*
|
||||||
buf.append("id:'").append(id).append("',");
|
* @param id the ID of the event
|
||||||
buf.append("groupId:'").append(groupId).append("',");
|
* @param title the title of the event
|
||||||
buf.append("allDay:'").append(allDay).append("',");
|
* @param start the day of the event
|
||||||
// TODO: extend; also, only on demand (not null), or better use Gson for the json conversion
|
* @return the event
|
||||||
// .append(", start=").append(start).append(", end=").append(end).append(", startStr=").append(startStr)
|
*/
|
||||||
// .append(", endStr=").append(endStr).append(", title=").append(title).append(", url=").append(url)
|
public static final EventBean ofAllDayEvent(String id, String title, LocalDate start) {
|
||||||
// .append(", classNames=").append(classNames).append(", editable=").append(editable).append(", startEditable=")
|
EventBean bean = new EventBean();
|
||||||
// .append(startEditable).append(", durationEditable=").append(durationEditable).append(", resourceEditable=")
|
bean.setId(id);
|
||||||
// .append(resourceEditable).append(", display=").append(display).append(", overlap=").append(overlap)
|
bean.setTitle(title);
|
||||||
// .append(", constraint=").append(constraint).append(", backgroundColor=").append(backgroundColor)
|
bean.setStart(start == null ? null : start.atStartOfDay());
|
||||||
// .append(", boderColor=").append(boderColor).append(", textColor=").append(textColor).append(", extendedProps=")
|
bean.setAllDay(true);
|
||||||
// .append(extendedProps).append(", source=").append(source).append("]");
|
return bean;
|
||||||
return buf.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create new event
|
||||||
|
*
|
||||||
|
* @param id the ID of the event
|
||||||
|
* @param title the title of the event
|
||||||
|
* @param start the datetime of the start
|
||||||
|
* @param end the datetime of the end
|
||||||
|
* @return the event
|
||||||
|
*/
|
||||||
|
public static final EventBean ofEvent(String id, String title, LocalDateTime start, LocalDateTime end) {
|
||||||
|
EventBean bean = new EventBean();
|
||||||
|
bean.setId(id);
|
||||||
|
bean.setTitle(title);
|
||||||
|
bean.setStart(start);
|
||||||
|
bean.setEnd(end);
|
||||||
|
bean.setAllDay(false);
|
||||||
|
return bean;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the id
|
* @return the id
|
||||||
*/
|
*/
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package de.jottyfan.timetrack.modules.calendar;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LocalDateAdapter implements JsonSerializer<LocalDate> {
|
||||||
|
|
||||||
|
public JsonElement serialize(LocalDate date, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
return new JsonPrimitive(date.format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package de.jottyfan.timetrack.modules.calendar;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import com.google.gson.JsonSerializationContext;
|
||||||
|
import com.google.gson.JsonSerializer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jotty
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class LocalDateTimeAdapter implements JsonSerializer<LocalDateTime> {
|
||||||
|
|
||||||
|
public JsonElement serialize(LocalDateTime date, Type typeOfSrc, JsonSerializationContext context) {
|
||||||
|
return new JsonPrimitive(date.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ server.port = 8083
|
|||||||
server.servlet.context-path=/timetrack
|
server.servlet.context-path=/timetrack
|
||||||
|
|
||||||
# keycloak
|
# keycloak
|
||||||
keycloak.auth-server-url = http://localhost:8080/
|
keycloak.auth-server-url = https://www.jottyfan.de/auth
|
||||||
keycloak.realm = jottyfan
|
keycloak.realm = jottyfan
|
||||||
keycloak.resource = timetrack
|
keycloak.resource = timetrack
|
||||||
keycloak.public-client = true
|
keycloak.public-client = true
|
||||||
|
Reference in New Issue
Block a user