diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 6b0b722..707b19d 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -111,9 +111,6 @@ public static void main(String[] args) throws IOException, ClassNotFoundExceptio InstructorChooseTaskCreateScreen chooseInstructortask = new InstructorChooseTaskCreateScreen(screens, cardLayout); screens.add("instructorTaskCreate", chooseInstructortask); - CalendarScreen calendarScreen = new CalendarScreen(screens, cardLayout); - screens.add("calendar", calendarScreen); - ScheduleCTScreen scheduleCTScreen = new ScheduleCTScreen(scheduleCTController, screens, cardLayout); screens.add("scheduleCT", scheduleCTScreen); screens.add("scheduleCTView", (Component) scheduleCTOutputView); diff --git a/src/main/java/screens/StudentMainScreen.java b/src/main/java/screens/StudentMainScreen.java index 2762ac3..deed5da 100644 --- a/src/main/java/screens/StudentMainScreen.java +++ b/src/main/java/screens/StudentMainScreen.java @@ -1,5 +1,9 @@ package screens; +import screens.calendar_scheduler.WorkingHoursController; +import screens.calendar_scheduler.CalendarPresenter; +import screens.calendar_scheduler.CalendarScreen; +import screens.calendar_scheduler.WorkingHoursPresenter; import screens.login_registration.LogoutController; import screens.task_management.todolist_screens.ToDoListPresenter; import screens.task_management.todolist_screens.ToDoListScreen; @@ -99,6 +103,17 @@ public void actionPerformed(ActionEvent evt) { cardLayout.show(screens, "toDoList"); } if (evt.getSource() == calendar) { + // Refresh calendar screen + CalendarPresenter calendarPresenter = new CalendarPresenter(); + WorkingHoursPresenter workingHoursPresenter = new WorkingHoursPresenter(); + WorkingHoursController workingHoursController = new WorkingHoursController(); + ToDoListInteractor toDoListInteractor = new ToDoListInteractor(calendarPresenter); + calendarPresenter.setToDoListInput(toDoListInteractor); + + CalendarScreen calendarScreen = new CalendarScreen(screens, cardLayout, calendarPresenter, + workingHoursController, workingHoursPresenter); + screens.add("calendar", calendarScreen); + cardLayout.show(screens, "calendar"); } if (evt.getSource() == progressTracker) { diff --git a/src/main/java/screens/calendar_scheduler/CalendarPresenter.java b/src/main/java/screens/calendar_scheduler/CalendarPresenter.java new file mode 100644 index 0000000..7e700b5 --- /dev/null +++ b/src/main/java/screens/calendar_scheduler/CalendarPresenter.java @@ -0,0 +1,71 @@ +package screens.calendar_scheduler; + +import screens.task_management.todolist_screens.ToDoListFail; +import use_cases.task_management.todolist_use_case.*; + +import java.util.ArrayList; + +public class CalendarPresenter implements ToDoListOutputBoundary { + + private ToDoListInputBoundary toDoListInput; + + public void setToDoListInput(ToDoListInputBoundary toDoListInput) { + this.toDoListInput = toDoListInput; + } + + public ArrayList> getToDoList() { + ToDoListResponseModel responseModel = toDoListInput.getToDoList(); + return responseModel.getToDoListView(); + } + + @Override + public ToDoListResponseModel display(ToDoListResponseModel responseModel) { + + // Initialise task list array + ArrayList> taskList = new ArrayList<>(); + + // Iterate through each task in to-do list + for (ToDoListItem item : responseModel.getToDoList()) { + + // Intialise task item array + ArrayList taskItem = new ArrayList<>(); + + // Get title, task type, start time, end time, recurrence and frequency of task item + if (item.getTaskType().equals(TaskType.TEST)) { + taskItem.add(item.getTaskTitle()); + taskItem.add("Test"); + taskItem.add(item.getStartTime().toString()); + taskItem.add(item.getEndTime().toString()); + taskItem.add(null); + taskItem.add(null); + } else if (item.getTaskType().equals(TaskType.EVENT)) { + taskItem.add(item.getTaskTitle()); + taskItem.add("Event"); + taskItem.add(item.getStartTime().toString()); + taskItem.add(item.getEndTime().toString()); + taskItem.add(item.isRecurring()); + taskItem.add(item.getFrequency()); + } else { + taskItem.add(item.getTaskTitle()); + taskItem.add("Assignment"); + taskItem.add(null); + taskItem.add(null); + taskItem.add(null); + taskItem.add(null); + } + + // Add task item to task list array + taskList.add(taskItem); + } + + responseModel.setToDoListView(taskList); + + return responseModel; + + } + + @Override + public ToDoListResponseModel failView(String error) { + throw new ToDoListFail(error); + } +} diff --git a/src/main/java/screens/calendar_scheduler/CalendarScreen.java b/src/main/java/screens/calendar_scheduler/CalendarScreen.java index e957ea8..670a70f 100644 --- a/src/main/java/screens/calendar_scheduler/CalendarScreen.java +++ b/src/main/java/screens/calendar_scheduler/CalendarScreen.java @@ -1,9 +1,6 @@ package screens.calendar_scheduler; -import entities.CurrentUser; -import entities.StudentUser; -import entities.Task; -import entities.TaskMap; +import use_cases.task_management.todolist_use_case.ToDoListResponseModel; import javax.swing.*; import java.awt.*; @@ -12,8 +9,6 @@ import java.time.LocalDate; import java.time.LocalTime; import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; import java.util.Objects; public class CalendarScreen extends JPanel implements ActionListener { @@ -33,30 +28,23 @@ public class CalendarScreen extends JPanel implements ActionListener { JPanel screens; CardLayout screenLayout; - /** - * The current entities - */ - StudentUser user; - ArrayList allTasks; + CalendarPresenter presenter; + WorkingHoursController workingHoursController; + WorkingHoursPresenter workingHoursPresenter; /** * The window of the screen for the Calendar view */ - public CalendarScreen(JPanel screens, CardLayout screenLayout) { + public CalendarScreen(JPanel screens, CardLayout screenLayout, CalendarPresenter presenter, + WorkingHoursController workingHoursController, WorkingHoursPresenter workingHoursPresenter) { - this.user = (StudentUser) CurrentUser.getCurrentUser(); + this.presenter = presenter; + this.workingHoursController = workingHoursController; + this.workingHoursPresenter = workingHoursPresenter; this.screens = screens; this.screenLayout = screenLayout; - // Get the user's existing tasks - ArrayList taskIDs = user.getToDoList(); - ArrayList allTasks = new ArrayList<>(); - for (String taskID : taskIDs) { - //get the Task object for this task from the entity TaskMap static variable - Task existingTask = TaskMap.getTaskMap().get(taskID); - allTasks.add(existingTask); - } - this.allTasks = allTasks; + ArrayList> taskList = presenter.getToDoList(); // Create label for title of screen JLabel title = new JLabel("Calendar"); @@ -76,11 +64,11 @@ public CalendarScreen(JPanel screens, CardLayout screenLayout) { LocalDate currDate = LocalDate.now(); cardLayout = new CardLayout(); viewPanel = new JPanel(cardLayout); - DayViewPanel dayViewPanel = new DayViewPanel(currDate, this.user, this.allTasks); + DayViewPanel dayViewPanel = new DayViewPanel(currDate, taskList, this.workingHoursPresenter); viewPanel.add("day", dayViewPanel); - WeekViewPanel weekViewPanel = new WeekViewPanel(currDate, this.user, this.allTasks); + WeekViewPanel weekViewPanel = new WeekViewPanel(currDate, taskList, this.workingHoursPresenter); viewPanel.add("week", weekViewPanel); - MonthViewPanel monthViewPanel = new MonthViewPanel(currDate, this.allTasks); + MonthViewPanel monthViewPanel = new MonthViewPanel(currDate, taskList); viewPanel.add("month", monthViewPanel); @@ -118,7 +106,8 @@ public void actionPerformed(ActionEvent e) { // Get current working hours LocalTime currStartTime; LocalTime currEndTime; - ArrayList currWorkingHours = user.getWorkingHours(); + ArrayList currWorkingHours = workingHoursPresenter.getWorkingHours(); + if (currWorkingHours.size() == 0) { currStartTime = LocalTime.now(); currEndTime = LocalTime.now(); @@ -181,7 +170,8 @@ public void actionPerformed(ActionEvent e) { ArrayList workingHours = new ArrayList<>(); workingHours.add(LocalTime.of(startHour, startMinute)); workingHours.add(LocalTime.of(endHour, endMinute)); - this.user.setWorkingHours(workingHours); + + this.workingHoursController.setWorkingHours(workingHours); } // Trigger button to return to main dashboard diff --git a/src/main/java/screens/calendar_scheduler/DayViewPanel.java b/src/main/java/screens/calendar_scheduler/DayViewPanel.java index 1ae1796..b538aa8 100644 --- a/src/main/java/screens/calendar_scheduler/DayViewPanel.java +++ b/src/main/java/screens/calendar_scheduler/DayViewPanel.java @@ -11,14 +11,16 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalField; import java.time.temporal.WeekFields; import java.util.ArrayList; import java.util.Locale; +import java.util.Objects; public class DayViewPanel extends JPanel { - public DayViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) { + public DayViewPanel(LocalDate date, ArrayList> allTasks, WorkingHoursPresenter workingHoursPresenter) { // Get date details int day = date.getDayOfMonth(); @@ -26,14 +28,12 @@ public DayViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) // Get working hours DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); - LocalTime startTime = LocalTime.parse("07:00", formatter); - LocalTime endTime = LocalTime.parse("23:00", formatter); - if (user != null) { - ArrayList workingHours = user.getWorkingHours(); - if (workingHours.size() != 0) { - startTime = workingHours.get(0); - endTime = workingHours.get(1); - } + LocalTime workingStartTime = LocalTime.parse("07:00", formatter); + LocalTime workingEndTime = LocalTime.parse("23:00", formatter); + ArrayList workingHours = workingHoursPresenter.getWorkingHours(); + if (workingHours != null) { + workingStartTime = workingHours.get(0); + workingEndTime = workingHours.get(1); } // Create title panel @@ -84,14 +84,14 @@ public DayViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) datePanel.add(dayPanel, dayConstraint); // Create hour panels - int startTimeHour = startTime.getHour(); - int endTimeHour = endTime.getHour(); + int workingStartTimeHour = workingStartTime.getHour(); + int workingEndTimeHour = workingEndTime.getHour(); ArrayList hours = new ArrayList<>(); hours.add(""); - for (int i = startTimeHour; i <= endTimeHour; i++) { + for (int i = workingStartTimeHour; i <= workingEndTimeHour; i++) { hours.add(Integer.toString(i)); } - for (int i = 0; i <= endTimeHour - startTimeHour; i++) { + for (int i = 0; i <= workingEndTimeHour - workingStartTimeHour; i++) { GridBagConstraints c = new GridBagConstraints(); JPanel hourPanel = new JPanel(); hourPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); @@ -103,33 +103,68 @@ public DayViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) } // Create task panels - for (Task task : allTasks) { - if (task instanceof Timeblockable) { + for (ArrayList task : allTasks) { + if (!Objects.equals(task.get(1), "Assignment")) { - LocalDateTime taskStartTime = ((Timeblockable) task).getTimeBlock()[0]; - LocalDateTime taskEndTime = ((Timeblockable) task).getTimeBlock()[1]; + ArrayList startTimes = new ArrayList<>(); + ArrayList endTimes = new ArrayList<>(); + LocalDateTime taskStartTime = LocalDateTime.parse(task.get(2)); + LocalDateTime taskEndTime = LocalDateTime.parse(task.get(3)); + long taskDuration = ChronoUnit.MINUTES.between(taskStartTime, taskEndTime); TemporalField field = WeekFields.of(Locale.US).dayOfWeek(); LocalDate startOfWeek = date.with(field, 1); - if (taskStartTime.compareTo(startOfWeek.atStartOfDay()) <= 0 - && startOfWeek.atStartOfDay().compareTo(taskStartTime.plusWeeks(1)) < 0) { - GridBagConstraints c = new GridBagConstraints(); - JPanel taskPanel = new JPanel(); - taskPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); - taskPanel.setBackground(Color.PINK); - JLabel taskLabel = new JLabel(task.getTitle()); - taskPanel.add(taskLabel); + // Convert recurring tasks into multiple start/end times + if (Objects.equals(task.get(4), "true")) { + if (Objects.equals(task.get(5), "daily")) { + LocalDateTime dateIterator = taskStartTime; + while (dateIterator.isBefore(taskStartTime.plusYears(1))) { + startTimes.add(dateIterator); + endTimes.add(dateIterator.plusMinutes(taskDuration)); + dateIterator = dateIterator.plusDays(1); + } + } else if (Objects.equals(task.get(5), "weekly")) { + LocalDateTime dateIterator = taskStartTime; + while (dateIterator.isBefore(taskStartTime.plusYears(1))) { + startTimes.add(dateIterator); + endTimes.add(dateIterator.plusMinutes(taskDuration)); + dateIterator = dateIterator.plusWeeks(1); + } + } else { + LocalDateTime dateIterator = taskStartTime; + while (dateIterator.isBefore(taskStartTime.plusYears(1))) { + startTimes.add(dateIterator); + endTimes.add(dateIterator.plusMinutes(taskDuration)); + dateIterator = dateIterator.plusMonths(1); + } + } + } else { + startTimes.add(taskStartTime); + endTimes.add(taskEndTime); + } + + for (int i = 0; i < startTimes.size(); i++) { + if (startTimes.get(i).isAfter(date.atStartOfDay()) + && startTimes.get(i).isBefore(date.plusDays(1).atStartOfDay())) { + GridBagConstraints c = new GridBagConstraints(); + JPanel taskPanel = new JPanel(); + taskPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + taskPanel.setBackground(Color.PINK); + JLabel taskLabel = new JLabel(task.get(0)); + taskPanel.add(taskLabel); + + int taskStartHour = startTimes.get(i).getHour(); + int taskEndHour = endTimes.get(i).getHour(); - int taskStartHour = taskStartTime.getHour(); - int taskEndHour = taskEndTime.getHour(); - c.gridy = taskStartHour - startTimeHour; - c.gridheight = taskEndHour - taskStartTime.getHour(); + c.gridy = taskStartHour - workingStartTimeHour +2; + c.gridheight = taskEndHour - taskStartHour; - int taskDayOfWeek = taskStartTime.getDayOfWeek().getValue(); - c.gridx = taskDayOfWeek + 1; + int taskDayOfWeek = startTimes.get(i).getDayOfWeek().getValue(); + c.gridx = taskDayOfWeek + 1; - datePanel.add(taskPanel, c); + datePanel.add(taskPanel, c); + } } } } diff --git a/src/main/java/screens/calendar_scheduler/MonthViewPanel.java b/src/main/java/screens/calendar_scheduler/MonthViewPanel.java index 3f5e5f5..1836974 100644 --- a/src/main/java/screens/calendar_scheduler/MonthViewPanel.java +++ b/src/main/java/screens/calendar_scheduler/MonthViewPanel.java @@ -7,13 +7,15 @@ import javax.swing.*; import java.awt.*; +import java.lang.reflect.Array; import java.time.LocalDate; import java.util.ArrayList; import java.util.Calendar; +import java.util.Objects; public class MonthViewPanel extends JPanel { - public MonthViewPanel(LocalDate date, ArrayList allTasks) { + public MonthViewPanel(LocalDate date, ArrayList> allTasks) { // Get date details int month = date.getMonthValue() - 1; @@ -78,14 +80,14 @@ public MonthViewPanel(LocalDate date, ArrayList allTasks) { int testCount = 0; int eventCount = 0; - for (Task task : allTasks) { - if (task instanceof Assignment) { + for (ArrayList task : allTasks) { + if (Objects.equals(task.get(1), "Assignment")) { assignmentCount += 1; } - if (task instanceof Test) { + if (Objects.equals(task.get(1), "Test")) { testCount += 1; } - if (task instanceof Event) { + if (Objects.equals(task.get(1), "Event")) { eventCount += 1; } } diff --git a/src/main/java/screens/calendar_scheduler/WeekViewPanel.java b/src/main/java/screens/calendar_scheduler/WeekViewPanel.java index 956f10d..76a0e6d 100644 --- a/src/main/java/screens/calendar_scheduler/WeekViewPanel.java +++ b/src/main/java/screens/calendar_scheduler/WeekViewPanel.java @@ -8,15 +8,17 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalField; import java.time.temporal.WeekFields; import java.util.ArrayList; import java.util.Calendar; import java.util.Locale; +import java.util.Objects; public class WeekViewPanel extends JPanel { - public WeekViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) { + public WeekViewPanel(LocalDate date, ArrayList> allTasks, WorkingHoursPresenter workingHoursPresenter) { // Get date details int day = date.getDayOfMonth(); @@ -26,14 +28,12 @@ public WeekViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) // Get working hours DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); - LocalTime startTime = LocalTime.parse("07:00", formatter); - LocalTime endTime = LocalTime.parse("23:00", formatter); - if (user != null) { - ArrayList workingHours = user.getWorkingHours(); - if (workingHours.size() != 0) { - startTime = workingHours.get(0); - endTime = workingHours.get(1); - } + LocalTime workingStartTime = LocalTime.parse("07:00", formatter); + LocalTime workingEndTime = LocalTime.parse("23:00", formatter); + ArrayList workingHours = workingHoursPresenter.getWorkingHours(); + if (workingHours != null) { + workingStartTime = workingHours.get(0); + workingEndTime = workingHours.get(1); } // Create title panel @@ -106,14 +106,14 @@ public WeekViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) } // Create hour panels - int startTimeHour = startTime.getHour(); - int endTimeHour = endTime.getHour(); + int workingStartTimeHour = workingStartTime.getHour(); + int workingEndTimeHour = workingEndTime.getHour(); ArrayList hours = new ArrayList<>(); hours.add(""); - for (int i = startTimeHour; i <= endTimeHour; i++) { + for (int i = workingStartTimeHour; i <= workingEndTimeHour; i++) { hours.add(Integer.toString(i)); } - for (int i = 0; i <= endTimeHour - startTimeHour; i++) { + for (int i = 0; i <= workingEndTimeHour - workingStartTimeHour; i++) { GridBagConstraints c = new GridBagConstraints(); JPanel hourPanel = new JPanel(); hourPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); @@ -125,33 +125,72 @@ public WeekViewPanel(LocalDate date, StudentUser user, ArrayList allTasks) } // Create task panels - for (Task task : allTasks) { - if (task instanceof Timeblockable ) { + for (ArrayList task : allTasks) { + + // Create Timeblockable task panels + if (!Objects.equals(task.get(1), "Assignment")) { - LocalDateTime taskStartTime = ((Timeblockable) task).getTimeBlock()[0]; - LocalDateTime taskEndTime = ((Timeblockable) task).getTimeBlock()[1]; + ArrayList startTimes = new ArrayList<>(); + ArrayList endTimes = new ArrayList<>(); + LocalDateTime taskStartTime = LocalDateTime.parse(task.get(2)); + LocalDateTime taskEndTime = LocalDateTime.parse(task.get(3)); + long taskDuration = ChronoUnit.MINUTES.between(taskStartTime, taskEndTime); TemporalField field = WeekFields.of(Locale.US).dayOfWeek(); LocalDate startOfWeek = date.with(field, 1); - if (taskStartTime.compareTo(startOfWeek.atStartOfDay()) <= 0 - && startOfWeek.atStartOfDay().compareTo(taskStartTime.plusWeeks(1)) < 0) { - GridBagConstraints c = new GridBagConstraints(); - JPanel taskPanel = new JPanel(); - taskPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); - taskPanel.setBackground(Color.PINK); - JLabel taskLabel = new JLabel(task.getTitle()); - taskPanel.add(taskLabel); + // Convert recurring tasks into multiple start/end times + if (Objects.equals(task.get(4), "true")) { + if (Objects.equals(task.get(5), "daily")) { + LocalDateTime dateIterator = taskStartTime; + while (dateIterator.isBefore(taskStartTime.plusYears(1))) { + startTimes.add(dateIterator); + endTimes.add(dateIterator.plusMinutes(taskDuration)); + dateIterator = dateIterator.plusDays(1); + } + } else if (Objects.equals(task.get(5), "weekly")) { + LocalDateTime dateIterator = taskStartTime; + while (dateIterator.isBefore(taskStartTime.plusYears(1))) { + startTimes.add(dateIterator); + endTimes.add(dateIterator.plusMinutes(taskDuration)); + dateIterator = dateIterator.plusWeeks(1); + } + } else { + LocalDateTime dateIterator = taskStartTime; + while (dateIterator.isBefore(taskStartTime.plusYears(1))) { + startTimes.add(dateIterator); + endTimes.add(dateIterator.plusMinutes(taskDuration)); + dateIterator = dateIterator.plusMonths(1); + } + } + } else { + startTimes.add(taskStartTime); + endTimes.add(taskEndTime); + } + + for (int i = 0; i < startTimes.size(); i++) { + + if (startTimes.get(i).isAfter(startOfWeek.atStartOfDay()) + && startTimes.get(i).isBefore(startOfWeek.plusWeeks(1).atStartOfDay())) { + + GridBagConstraints c = new GridBagConstraints(); + JPanel taskPanel = new JPanel(); + taskPanel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); + taskPanel.setBackground(Color.PINK); + JLabel taskLabel = new JLabel(task.get(0)); + taskPanel.add(taskLabel); + + int taskStartHour = startTimes.get(i).getHour(); + int taskEndHour = endTimes.get(i).getHour(); - int taskStartHour = taskStartTime.getHour(); - int taskEndHour = taskEndTime.getHour(); - c.gridy = taskStartHour - startTimeHour; - c.gridheight = taskEndHour - taskStartTime.getHour(); + c.gridy = taskStartHour - workingStartTimeHour +2; + c.gridheight = taskEndHour - taskStartHour; - int taskDayOfWeek = taskStartTime.getDayOfWeek().getValue(); - c.gridx = taskDayOfWeek + 1; + int taskDayOfWeek = startTimes.get(i).getDayOfWeek().getValue(); + c.gridx = taskDayOfWeek + 1; - datePanel.add(taskPanel, c); + datePanel.add(taskPanel, c); + } } } } diff --git a/src/main/java/screens/calendar_scheduler/WorkingHoursController.java b/src/main/java/screens/calendar_scheduler/WorkingHoursController.java new file mode 100644 index 0000000..82694ab --- /dev/null +++ b/src/main/java/screens/calendar_scheduler/WorkingHoursController.java @@ -0,0 +1,22 @@ +package screens.calendar_scheduler; + +import use_cases.calendar_scheduler.working_hours_use_case.*; + +import java.time.LocalTime; +import java.util.ArrayList; + +public class WorkingHoursController { + + WorkingHoursInputBoundary workingHoursInteractor; + + public WorkingHoursController() { + this.workingHoursInteractor = new WorkingHoursInteractor(); + } + + void setWorkingHours(ArrayList workingHours) { + + WorkingHoursRequestModel requestModel = new WorkingHoursRequestModel(workingHours); + workingHoursInteractor.setWorkingHours(requestModel); + } + +} diff --git a/src/main/java/screens/calendar_scheduler/WorkingHoursPresenter.java b/src/main/java/screens/calendar_scheduler/WorkingHoursPresenter.java new file mode 100644 index 0000000..744ebb9 --- /dev/null +++ b/src/main/java/screens/calendar_scheduler/WorkingHoursPresenter.java @@ -0,0 +1,21 @@ +package screens.calendar_scheduler; + +import use_cases.calendar_scheduler.working_hours_use_case.WorkingHoursInteractor; +import use_cases.calendar_scheduler.working_hours_use_case.WorkingHoursOutputBoundary; +import use_cases.calendar_scheduler.working_hours_use_case.WorkingHoursResponseModel; + +import java.time.LocalTime; +import java.util.ArrayList; + +; +public class WorkingHoursPresenter implements WorkingHoursOutputBoundary { + + @Override + public ArrayList getWorkingHours() { + + WorkingHoursInteractor interactor = new WorkingHoursInteractor(); + WorkingHoursResponseModel responseModel = interactor.getWorkingHours(); + + return responseModel.getWorkingHours(); + } +} diff --git a/src/main/java/screens/task_management/todolist_screens/ToDoListPresenter.java b/src/main/java/screens/task_management/todolist_screens/ToDoListPresenter.java index 5fdfe81..7b721bb 100644 --- a/src/main/java/screens/task_management/todolist_screens/ToDoListPresenter.java +++ b/src/main/java/screens/task_management/todolist_screens/ToDoListPresenter.java @@ -14,8 +14,9 @@ public void setToDoListInput(ToDoListInputBoundary toDoListInput) { this.toDoListInput = toDoListInput; } - public ToDoListResponseModel getToDoList() { - return toDoListInput.getToDoList(); + public ArrayList> getToDoList() { + ToDoListResponseModel responseModel = toDoListInput.getToDoList(); + return responseModel.getToDoListView(); } @Override diff --git a/src/main/java/screens/task_management/todolist_screens/ToDoListScreen.java b/src/main/java/screens/task_management/todolist_screens/ToDoListScreen.java index 08725ea..614093a 100644 --- a/src/main/java/screens/task_management/todolist_screens/ToDoListScreen.java +++ b/src/main/java/screens/task_management/todolist_screens/ToDoListScreen.java @@ -57,8 +57,8 @@ public ToDoListScreen(ToDoListPresenter presenter, JPanel screens, CardLayout sc toDoList.setLayout(new BoxLayout(toDoList, BoxLayout.PAGE_AXIS)); try { - ToDoListResponseModel rsp = presenter.getToDoList(); - ArrayList> tasks = rsp.getToDoListView(); + + ArrayList> tasks = presenter.getToDoList(); for (ArrayList task: tasks) { JButton editDelete = new JButton("Edit/Delete"); diff --git a/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursInputBoundary.java b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursInputBoundary.java new file mode 100644 index 0000000..d4b35d4 --- /dev/null +++ b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursInputBoundary.java @@ -0,0 +1,8 @@ +package use_cases.calendar_scheduler.working_hours_use_case; + +import use_cases.course_tracker.grade_calculator_use_case.GradeCalculatorRequestModel; + +public interface WorkingHoursInputBoundary { + + void setWorkingHours(WorkingHoursRequestModel requestModel); +} diff --git a/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursInteractor.java b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursInteractor.java new file mode 100644 index 0000000..a5731a8 --- /dev/null +++ b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursInteractor.java @@ -0,0 +1,26 @@ +package use_cases.calendar_scheduler.working_hours_use_case; + +import entities.CurrentUser; +import entities.StudentUser; + +import java.time.LocalTime; +import java.util.ArrayList; + +public class WorkingHoursInteractor implements WorkingHoursInputBoundary { + + private StudentUser user; + + public WorkingHoursInteractor() { + this.user = (StudentUser) CurrentUser.getCurrentUser(); + } + + @Override + public void setWorkingHours(WorkingHoursRequestModel requestModel) { + user.setWorkingHours(requestModel.getWorkingHours()); + } + + public WorkingHoursResponseModel getWorkingHours() { + WorkingHoursResponseModel responseModel = new WorkingHoursResponseModel(user.getWorkingHours()); + return responseModel; + } +} diff --git a/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursOutputBoundary.java b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursOutputBoundary.java new file mode 100644 index 0000000..3985c94 --- /dev/null +++ b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursOutputBoundary.java @@ -0,0 +1,9 @@ +package use_cases.calendar_scheduler.working_hours_use_case; + +import java.time.LocalTime; +import java.util.ArrayList; + +public interface WorkingHoursOutputBoundary { + + ArrayList getWorkingHours(); +} diff --git a/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursRequestModel.java b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursRequestModel.java new file mode 100644 index 0000000..0b0c25d --- /dev/null +++ b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursRequestModel.java @@ -0,0 +1,19 @@ +package use_cases.calendar_scheduler.working_hours_use_case; + +import entities.StudentUser; + +import java.time.LocalTime; +import java.util.ArrayList; + +public class WorkingHoursRequestModel { + + private ArrayList workingHours; + + public WorkingHoursRequestModel(ArrayList workingHours) { + this.workingHours = workingHours; + } + + public ArrayList getWorkingHours() { + return workingHours; + } +} diff --git a/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursResponseModel.java b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursResponseModel.java new file mode 100644 index 0000000..f62e362 --- /dev/null +++ b/src/main/java/use_cases/calendar_scheduler/working_hours_use_case/WorkingHoursResponseModel.java @@ -0,0 +1,19 @@ +package use_cases.calendar_scheduler.working_hours_use_case; + +import java.time.LocalTime; +import java.util.ArrayList; + +public class WorkingHoursResponseModel { + + private ArrayList workingHours; + + public WorkingHoursResponseModel(ArrayList workingHours) { + + this.workingHours = workingHours; + + } + + public ArrayList getWorkingHours() { + return workingHours; + } +} diff --git a/src/main/java/use_cases/task_management/todolist_use_case/ToDoListInteractor.java b/src/main/java/use_cases/task_management/todolist_use_case/ToDoListInteractor.java index c4fa978..9eda5a8 100644 --- a/src/main/java/use_cases/task_management/todolist_use_case/ToDoListInteractor.java +++ b/src/main/java/use_cases/task_management/todolist_use_case/ToDoListInteractor.java @@ -2,6 +2,7 @@ import entities.*; +import java.time.LocalDateTime; import java.util.ArrayList; /** @@ -41,19 +42,31 @@ public ToDoListResponseModel getToDoList() { Task task = TaskMap.findTask(taskId); String taskItemTitle = task.getTitle(); String taskItemId = task.getId(); + LocalDateTime startTime = null; + LocalDateTime endTime = null; + boolean recurring = false; + String frequency = null; TaskType taskItemType; if (task instanceof Event) { taskItemType = TaskType.EVENT; + LocalDateTime[] timeBlock = ((Event) task).getTimeBlock(); + startTime = timeBlock[0]; + endTime = timeBlock[1]; + recurring = ((Event) task).getRecurring(); + frequency = ((Event) task).getFrequency(); } else if (task instanceof Test) { taskItemType = TaskType.TEST; + LocalDateTime[] timeBlock = ((Test) task).getTimeBlock(); + startTime = timeBlock[0]; + endTime = timeBlock[1]; } else if (task instanceof Assignment) { taskItemType = TaskType.ASSIGNMENT; } else { throw new RuntimeException("Some of your tasks are an invalid Task Type!"); } - ToDoListItem toDoListItem = new ToDoListItem(taskItemTitle, taskItemId, taskItemType); + ToDoListItem toDoListItem = new ToDoListItem(taskItemTitle, taskItemId, taskItemType, startTime, endTime, recurring, frequency); toDoList.add(toDoListItem); } diff --git a/src/main/java/use_cases/task_management/todolist_use_case/ToDoListItem.java b/src/main/java/use_cases/task_management/todolist_use_case/ToDoListItem.java index 3eadf4c..f252ece 100644 --- a/src/main/java/use_cases/task_management/todolist_use_case/ToDoListItem.java +++ b/src/main/java/use_cases/task_management/todolist_use_case/ToDoListItem.java @@ -1,5 +1,7 @@ package use_cases.task_management.todolist_use_case; +import java.time.LocalDateTime; + public class ToDoListItem { private final String taskTitle; @@ -8,10 +10,23 @@ public class ToDoListItem { private final TaskType taskType; - public ToDoListItem(String taskTitle, String taskId, TaskType taskType) { + private final LocalDateTime startTime; + + private final LocalDateTime endTime; + + private final boolean recurring; + + private final String frequency; + + public ToDoListItem(String taskTitle, String taskId, TaskType taskType, LocalDateTime startTime, LocalDateTime endTime, + boolean recurring, String frequency) { this.taskTitle = taskTitle; this.taskId = taskId; this.taskType = taskType; + this.startTime = startTime; + this.endTime = endTime; + this.recurring = recurring; + this.frequency = frequency; } public String getTaskTitle() { @@ -25,4 +40,24 @@ public String getTaskId() { public TaskType getTaskType() { return taskType; } + + public LocalDateTime getStartTime() { + return startTime; + } + + public LocalDateTime getEndTime() { + return endTime; + } + + public String isRecurring() { + if (recurring) { + return "true"; + } else { + return "false"; + } + } + + public String getFrequency() { + return frequency; + } } diff --git a/src/test/java/scheduler_use_case/SchedulerInteractorTest.java b/src/test/java/calendar_scheduler_use_case/SchedulerInteractorTest.java similarity index 91% rename from src/test/java/scheduler_use_case/SchedulerInteractorTest.java rename to src/test/java/calendar_scheduler_use_case/SchedulerInteractorTest.java index 65c3858..3adb9ec 100644 --- a/src/test/java/scheduler_use_case/SchedulerInteractorTest.java +++ b/src/test/java/calendar_scheduler_use_case/SchedulerInteractorTest.java @@ -1,4 +1,4 @@ -package scheduler_use_case; +package calendar_scheduler_use_case; import entities.*; import org.junit.jupiter.api.Test; @@ -6,7 +6,6 @@ import use_cases.calendar_scheduler.schedule_conflict_use_case.*; import use_cases.calendar_scheduler.scheduler_use_case.*; -import javax.swing.*; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; @@ -21,7 +20,7 @@ class SchedulerInteractorTest { @Test void testConflictSchedule() { - ScheduleConflictOutputBoundary scheduleConflictOutputBoundary = new ScheduleConflictPresenter() { + ScheduleConflictOutputBoundary scheduleConflictPresenter = new ScheduleConflictPresenter() { @Override public ScheduleConflictResponseModel alertConflict(ScheduleConflictRequestModel requestModel) { assertEquals("testEvent1", requestModel.getConflictingTask().getTitle()); @@ -31,7 +30,7 @@ public ScheduleConflictResponseModel alertConflict(ScheduleConflictRequestModel }; // Create interactor and test entities - SchedulerInputBoundary interactor = new SchedulerInteractor(scheduleConflictOutputBoundary); + SchedulerInputBoundary interactor = new SchedulerInteractor(scheduleConflictPresenter); StudentUser user = new StudentUser("testUser", "testPassword"); Event event1 = new Event("testEvent1", "testid1", 0, LocalDateTime.of(2022, 12, 10, 14, 0), @@ -55,7 +54,7 @@ public ScheduleConflictResponseModel alertConflict(ScheduleConflictRequestModel @Test void testPrepTimeScheduling() { // Create anonymous implementing class for the output boundary - ScheduleConflictOutputBoundary scheduleConflictOutputBoundary = new ScheduleConflictPresenter() { + ScheduleConflictOutputBoundary scheduleConflictPresenter = new ScheduleConflictPresenter() { @Override public ScheduleConflictResponseModel alertConflict(ScheduleConflictRequestModel requestModel) { ScheduleConflictResponseModel responseModel = new ScheduleConflictResponseModel(false); @@ -64,7 +63,7 @@ public ScheduleConflictResponseModel alertConflict(ScheduleConflictRequestModel }; // Create interactor and test entities - SchedulerInputBoundary interactor = new SchedulerInteractor(scheduleConflictOutputBoundary); + SchedulerInputBoundary interactor = new SchedulerInteractor(scheduleConflictPresenter); StudentUser user = new StudentUser("testUser", "testPassword"); LocalDateTime currDateTime = LocalDateTime.now(); @@ -101,6 +100,8 @@ public ScheduleConflictResponseModel alertConflict(ScheduleConflictRequestModel prepTime.add(prepEnd); expectedPrepTime.add(prepTime); + System.out.println(expectedPrepTime); + System.out.println((assignment.getPrepTimeScheduled())); assertEquals(expectedPrepTime, (assignment.getPrepTimeScheduled())); } diff --git a/src/test/java/calendar_scheduler_use_case/WorkingHoursInteractorTest.java b/src/test/java/calendar_scheduler_use_case/WorkingHoursInteractorTest.java new file mode 100644 index 0000000..0e4bfe9 --- /dev/null +++ b/src/test/java/calendar_scheduler_use_case/WorkingHoursInteractorTest.java @@ -0,0 +1,67 @@ +package calendar_scheduler_use_case; + +import entities.*; +import org.junit.jupiter.api.Test; +import screens.calendar_scheduler.ScheduleConflictPresenter; +import screens.calendar_scheduler.WorkingHoursPresenter; +import use_cases.calendar_scheduler.schedule_conflict_use_case.ScheduleConflictOutputBoundary; +import use_cases.calendar_scheduler.schedule_conflict_use_case.ScheduleConflictRequestModel; +import use_cases.calendar_scheduler.schedule_conflict_use_case.ScheduleConflictResponseModel; +import use_cases.calendar_scheduler.scheduler_use_case.SchedulerInputBoundary; +import use_cases.calendar_scheduler.scheduler_use_case.SchedulerInteractor; +import use_cases.calendar_scheduler.scheduler_use_case.SchedulerRequestModel; +import use_cases.calendar_scheduler.working_hours_use_case.WorkingHoursInteractor; +import use_cases.calendar_scheduler.working_hours_use_case.WorkingHoursOutputBoundary; +import use_cases.calendar_scheduler.working_hours_use_case.WorkingHoursRequestModel; +import use_cases.calendar_scheduler.working_hours_use_case.WorkingHoursResponseModel; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.*; + +class WorkingHoursInteractorTest { + + @Test + void testWorkingHours() { + WorkingHoursOutputBoundary workingHoursPresenter = new WorkingHoursPresenter() { + @Override + public ArrayList getWorkingHours() { + + WorkingHoursInteractor interactor = new WorkingHoursInteractor(); + WorkingHoursResponseModel responseModel = interactor.getWorkingHours(); + + ArrayList expectedWorkingHours = new ArrayList<>(); + expectedWorkingHours.add(LocalTime.parse("08:00")); + expectedWorkingHours.add(LocalTime.parse("21:00")); + + assertEquals(expectedWorkingHours, responseModel.getWorkingHours()); + + return null; + } + }; + + // Create interactor and test entities + StudentUser user = new StudentUser("testUser", "testPassword"); + CurrentUser.setCurrentUser(user); + WorkingHoursInteractor interactor = new WorkingHoursInteractor(); + + ArrayList workingHours = new ArrayList<>(); + workingHours.add(LocalTime.parse("08:00")); + workingHours.add(LocalTime.parse("21:00")); + + // Test changing working hours + WorkingHoursRequestModel requestModel = new WorkingHoursRequestModel(workingHours); + interactor.setWorkingHours(requestModel); + + ArrayList expectedWorkingHours = new ArrayList<>(); + expectedWorkingHours.add(LocalTime.parse("08:00")); + expectedWorkingHours.add(LocalTime.parse("21:00")); + WorkingHoursResponseModel responseModel = interactor.getWorkingHours(); + + assertEquals(expectedWorkingHours, responseModel.getWorkingHours()); + } + +} \ No newline at end of file