Commit ba349c41 authored by s7_spruge_k's avatar s7_spruge_k
Browse files

fixed index errors with calendar

parent 5744daf4
......@@ -90,7 +90,7 @@ public class CalendarController {
return "redirect:/add-new-calendar";
}
Calendar c1 = calendarRepo.findAllByUser(currUser).get(currUser.getActiveCalendar()); //TODO RIGHT NOW IT TAKES DEFAULT CALENDAR, IMPLEMENT DROPDOWN.
Calendar c1 = calendarRepo.findByName(currUser.getActiveCalendar());
//Get Events By Calendar
ArrayList<Event> allEvents = eventRepo.findAllByCalendar(c1);
......@@ -133,9 +133,10 @@ public class CalendarController {
calendar.setUser(currUser);
calendarRepo.save(calendar);
currUser.setActiveCalendar(currUser.getLastCalendar());
currUser.setActiveCalendar(calendar.getName());
userRepo.save(currUser);
return "redirect:/calendar"; //TODO redirect to new calendar
return "redirect:/calendar";
}
......@@ -172,9 +173,17 @@ public class CalendarController {
@PostMapping(value="/view-calendars", params="action=edit")
public String editCalendar(Model model, String currName, String newName){
Calendar c1 = calendarRepo.findByName(currName);
Calendar c1 = calendarRepo.findByName(currName);
User currUser = findCurrentUser();
if(c1.getName().equals(currUser.getActiveCalendar()))
{
currUser.setActiveCalendar(newName);
userRepo.save(currUser);
}
c1.setName(newName);
calendarRepo.save(c1);
return "redirect:/view-calendars";
}
......@@ -189,14 +198,14 @@ public class CalendarController {
public String viewCalendar(Model model, String calName){
User currUser = findCurrentUser();
ArrayList<Calendar> allUserCalendars = calendarRepo.findAllByUser(currUser);
int index = 0;
for (int i = 0; i < allUserCalendars.size(); i++){
if(allUserCalendars.get(i).getName() == calName) {
index = i;
}
}
currUser.setActiveCalendar(index);
// ArrayList<Calendar> allUserCalendars = calendarRepo.findAllByUser(currUser);
// int index = 0;
// for (int i = 0; i < allUserCalendars.size(); i++){
// if(allUserCalendars.get(i).getName() == calName) {
// index = i;
// }
// }
currUser.setActiveCalendar(calName);
userRepo.save(currUser);
return "redirect:/calendar";
......
......@@ -192,7 +192,7 @@ public class EventController {
User currUser = findCurrentUser();
Calendar c1 = calendarRepo.findAllByUser(currUser).get(currUser.getActiveCalendar());
Calendar c1 = calendarRepo.findByName(currUser.getActiveCalendar());
event.setCalendar(c1);
eventRepo.save(event);
......
......@@ -40,7 +40,7 @@ public class User {
private Collection<Calendar> calendar = new ArrayList<Calendar>();
@Column(name = "activeCalendar")
private int activeCalendar = 0;
private String activeCalendar = "";
public User() {
......@@ -58,12 +58,6 @@ public class User {
calendar.add(newCal);
}
public int getLastCalendar()
{
return calendar.size()-1;
}
//Set & get
public String getUsername() {
......@@ -110,11 +104,11 @@ public class User {
this.calendar = calendar;
}
public int getActiveCalendar() {
public String getActiveCalendar() {
return activeCalendar;
}
public void setActiveCalendar(int activeCalendar) {
public void setActiveCalendar(String activeCalendar) {
this.activeCalendar = activeCalendar;
}
......
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