Commit 4963f747 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

Calendar controller

parent 01837289
......@@ -32,85 +32,15 @@ public class CalendarController {
@Autowired
EventRepo eventRepo;
@GetMapping(value = "/month-view")
public String monthViewGet(Model models)
@GetMapping(value = "/calendar")
public String calendarGet(Model models)
{
models.addAttribute("currentTime", LocalTime.now());
models.addAttribute("currentDate", LocalDate.now());
models.addAttribute("currentMonth", LocalDate.now().getMonth());
models.addAttribute("currentDay", LocalDate.now().getDayOfWeek());
//1. Get currently logged in user
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
//Get currently logged in user
User currUser = userRepo.findByUsername(username);
//2. Get Calendar By User
Calendar c1 = calendarRepo.findByUser(currUser);
//3. Get Events By Calendar
ArrayList<Event> allEvents = eventRepo.findAllByCalendar(c1);
int totalDaysInCurrentMonth = LocalDate.now().lengthOfMonth();
int currentDayByIndex = LocalDate.now().getDayOfMonth();
int numberOfPreviousDaysNeedToGet = currentDayByIndex - 1;
int numberOfDaysAheadNeedToGet = totalDaysInCurrentMonth - currentDayByIndex;
//Sakumu un beigu datums pashreizeejam menesim.
LocalDate monthStartingDate = LocalDate.now().minusDays(numberOfPreviousDaysNeedToGet);
LocalDate monthEndingDate = LocalDate.now().plusDays(numberOfDaysAheadNeedToGet);
ArrayList<Event> monthEvents = new ArrayList<>();
//Get events in current week.
if(allEvents.isEmpty())
System.out.println("No events");
else
{
for (Event e : allEvents) {
LocalDate temp = e.getStartDate();
if(temp == null)
continue;
if(temp.isBefore(monthEndingDate.plusDays(1)) && temp.isAfter(monthStartingDate.minusDays(1)))
monthEvents.add(e);
}
}
Collections.sort(monthEvents, Event.eventDateComp);
//TODO If the dates are the same, sort By Time!!!!!!!!!!!!!!!!!
models.addAttribute("monthStartingDate", monthStartingDate);
models.addAttribute("monthEndingDate", monthEndingDate);
models.addAttribute("currentUser", currUser.getUsername());
models.addAttribute("monthEvents", monthEvents);
return "monthView";
}
@GetMapping(value = "/week-view")
public String weekViewGet(Model models)
{
models.addAttribute("currentTime", LocalTime.now());
models.addAttribute("currentDate", LocalDate.now());
models.addAttribute("currentMonth", LocalDate.now().getMonth());
models.addAttribute("currentDay", LocalDate.now().getDayOfWeek());
//1. Get currently logged in user
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
......@@ -122,102 +52,23 @@ public class CalendarController {
User currUser = userRepo.findByUsername(username);
//2. Get Calendar By User
Calendar c1 = calendarRepo.findByUser(currUser);
//3. Get Events By Calendar
//Get Events By Calendar
ArrayList<Event> allEvents = eventRepo.findAllByCalendar(c1);
int currentDayByIndex = LocalDate.now().getDayOfWeek().getValue();
int numberOfPreviousDaysNeedToGet = currentDayByIndex - 1;
int numberOfDaysAheadNeedToGet = 7 - currentDayByIndex;
//Sakumu un beigu datums pashreizeejai nedeelai.
LocalDate weekStartingDate = LocalDate.now().minusDays(numberOfPreviousDaysNeedToGet);
LocalDate weekEndingDate = LocalDate.now().plusDays(numberOfDaysAheadNeedToGet);
ArrayList<Event> weekEvents = new ArrayList<>();
//Get events in current week.
if(allEvents.isEmpty())
System.out.println("No events");
else
{
for (Event e : allEvents) {
LocalDate temp = e.getStartDate();
if(temp == null)
continue;
if(temp.isBefore(weekEndingDate.plusDays(1)) && temp.isAfter(weekStartingDate.minusDays(1)))
weekEvents.add(e);
}
}
Collections.sort(weekEvents, Event.eventDateComp);
//TODO If the dates are the same, sort By Time!!!!!!!!!!!!!!!!!
models.addAttribute("weekStartingDate", weekStartingDate);
models.addAttribute("weekEndingDate", weekEndingDate);
models.addAttribute("currentUser", currUser.getUsername());
models.addAttribute("weekEvents", weekEvents);
return "weekView";
}
@GetMapping(value = "/day-view")
public String dayViewGet(Model models)
{
models.addAttribute("currentTime", LocalTime.now());
models.addAttribute("currentDate", LocalDate.now());
models.addAttribute("currentTime", LocalTime.now().toString());
models.addAttribute("currentDate", LocalDate.now().toString());
models.addAttribute("currentMonth", LocalDate.now().getMonth());
models.addAttribute("currentDay", LocalDate.now().getDayOfWeek());
models.addAttribute("currentUser", currUser.getUsername());
models.addAttribute("allEvents", allEvents);
//1. Get currently logged in user
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
User currUser = userRepo.findByUsername(username);
//2. Get Calendar By User
Calendar c1 = calendarRepo.findByUser(currUser);
//3. Get Events By Calendar
ArrayList<Event> allEvents = eventRepo.findAllByCalendar(c1);
ArrayList<Event> todayEventsConfirmed = new ArrayList<>();
if(allEvents.isEmpty())
System.out.println("No events");
else
{
for (Event e : allEvents) {
if(e.getStartDate() == null)
continue;
if(e.getStartDate().equals(LocalDate.now()))
todayEventsConfirmed.add(e);
}
}
System.out.println(todayEventsConfirmed);
//Vajag sakartot hronologiski pec laikiem, lai vieglak izmantotu skataa.
//event klasee ir compareTo, kas salidzina pec laikiem
Collections.sort(todayEventsConfirmed, Event.eventTimeComp);
models.addAttribute("currentUser", currUser.getUsername());
models.addAttribute("todayEvents", todayEventsConfirmed);
return "dayView";
return "calendar";
}
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>This Month</title>
<title>Hello Test</title>
</head>
<h2 th:text = "'Hello, ' + ${currentUser}"></h2>
<body>
<table>
<tr>
<td th:text = "'Date: ' + ${currentDate}"></td>
<td th:text = "'Month start: ' + ${monthStartingDate}"></td>
<td th:text = "'Month end: ' + ${monthEndingDate}"></td>
<td th:text = "'Time ' + ${currentTime}"></td>
<td th:text = "'Month ' + ${currentMonth}"></td>
<td th:text = "'Day of the week ' + currentDay"></td>
</tr>
<tr th:each="temp: ${monthEvents}">
<tr th:each="temp: ${allEvents}">
<td th:text = "'Event ' + ${temp.getName()}"/>
<td th:text = "'Date: ' + ${temp.getStartDate()}"></td>
<td th:text = "'Time: ' + ${temp.getStartTime()}"></td>
......
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Today Date</title>
</head>
<h2 th:text = "'Hello, ' + ${currentUser}"></h2>
<body>
<table>
<tr>
<td th:text = "'Date: ' + ${currentDate}"></td>
<td th:text = "'Today is: ' + ${currentDay} + 'of ' + ${currentMonth}"></td>
<td th:text = "'The time is: ' + ${currentTime}"></td>
</tr>
<tr th:each="temp: ${todayEvents}">
<td th:text = "'Event ' + ${temp.getName()}"/>
<td th:text = "'Date: ' + ${temp.getStartDate()}"></td>
<td th:text = "'Time: ' + ${temp.getStartTime()}"></td>
</tr>
</table>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>This Week</title>
</head>
<h2 th:text = "'Hello, ' + ${currentUser}"></h2>
<body>
<table>
<tr>
<td th:text = "'Date: ' + ${currentDate}"></td>
<td th:text = "'Week start: ' + ${weekStartingDate}"></td>
<td th:text = "'Week end: ' + ${weekEndingDate}"></td>
</tr>
<tr th:each="temp: ${weekEvents}">
<td th:text = "'Event ' + ${temp.getName()}"/>
<td th:text = "'Date: ' + ${temp.getStartDate()}"></td>
<td th:text = "'Time: ' + ${temp.getStartTime()}"></td>
</tr>
</table>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment