Commit 3b16aef6 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

Day view controller update + basic view

parent 7e174459
......@@ -6,6 +6,8 @@ import java.util.ArrayList;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import com.example.calendar.models.Calendar;
import com.example.calendar.models.Event;
import com.example.calendar.models.User;
import com.example.calendar.repo.CalendarRepo;
import com.example.calendar.repo.EventRepo;
import com.example.calendar.repo.UserRepo;
......@@ -61,27 +64,38 @@ public class CalendarController {
//TODO how to pass User?
// //1. Get currently logged in user
//
//
// //2. Get Calendar By User
// Calendar c1 = calendarRepo.findByUser(user);
//
//
// //3. Get Events By Calendar
// ArrayList<Event> todayEvents = eventRepo.findAllByCalendar(c1);
//
// //4. Get Events By currentDay.
// for (Event e : todayEvents) {
// if(!e.getStartDate().equals(LocalDate.now()))
// todayEvents.remove(e); //Neesmu parliecinats vai shitaa strada, ja nu kas var veidot jaunu arrayList
// } //Kura uzglaba vertibas
//
// //Vajag sakartot hronologiski pec laikiem, lai vieglak izmantotu skataa.
// //event klasee ir compareTo, kas salidzina pec laikiem
// Collections.sort(todayEvents);
//
// models.addAttribute("todayEvents", todayEvents);
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
//1. 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> todayEvents = eventRepo.findAllByCalendar(c1);
//4. Get Events By currentDay.
for (Event e : todayEvents) {
if(!e.getStartDate().equals(LocalDate.now()))
todayEvents.remove(e); //Neesmu parliecinats vai shitaa strada, ja nu kas var veidot jaunu arrayList
} //Kura uzglaba vertibas
//Vajag sakartot hronologiski pec laikiem, lai vieglak izmantotu skataa.
//event klasee ir compareTo, kas salidzina pec laikiem
Collections.sort(todayEvents);
models.addAttribute("currentUser", currUser.getUsername());
models.addAttribute("todayEvents", todayEvents);
return "dayView";
}
......
<!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>
</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