diff --git a/docs/DeveloperGuide.adoc b/docs/DeveloperGuide.adoc index 23a96df2a..8eeb60f9a 100644 --- a/docs/DeveloperGuide.adoc +++ b/docs/DeveloperGuide.adoc @@ -516,7 +516,7 @@ FindCommand will be enhanced by using Levenshtein Distance to generate an ordere ** Cons: Large amount of additional operations. ==== Future Implementation - +// to be edited The month/week/day view mechanism is facilitated by `PlannerView`. It extends `Planner` with different calendar views, stored internally as `monthView`, `weekView` and `dayView`. Additionally, it implements the following operations: diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index 43f4d0918..6ba70f16c 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -344,24 +344,26 @@ image::Find_Command_Output_1.png[width="790"] View the planner in a month/week/day view. 1. View the monthly calendar view of the current academic semester. + -Format: `view month [MONTH]` +Format: `view month` 2. View the weekly calendar view of the current academic week. + Format: `view week [WEEK]` 3. View the day view of a particular day in the academic semester. + -Format: `view day [DATE]` +Format: `view day [DATE_OR_DAY_OF_WEEK]` 4. View all the details in the planner. + Format: `view all` [TIP] -You may omit `[MONTH]`/`[WEEK]`/`[DATE]` to view the format chosen in respect to the current day! + -E.g. `view month` will allow you to view the current month and `view day` will allow you to view the current day! +You may omit `[WEEK]`/`[DATE_OR_DAY_OF_WEEK]` to view the calendar with respect to the current date! + +E.g. `view week` will allow you to view the current week and `view day` will allow you to view the current day! Examples: * `view day` + View planner for the current date. -* `view day 01/03/2019` + +* `view day 01-03-2019` + View planner for the first of March. +* `view day monday` + +View planner for the upcoming Monday. * `view week 7` + View planner for week 7 of the academic calendar. * `view week recess` + diff --git a/src/planmysem/logic/commands/HelpCommand.java b/src/planmysem/logic/commands/HelpCommand.java index 773f580ca..87212fe01 100644 --- a/src/planmysem/logic/commands/HelpCommand.java +++ b/src/planmysem/logic/commands/HelpCommand.java @@ -18,7 +18,7 @@ public class HelpCommand extends Command { + "\n\n" + DeleteCommand.MESSAGE_USAGE + "\n\n" + ListCommand.MESSAGE_USAGE + "\n\n" + FindCommand.MESSAGE_USAGE - // + "\n\n" + ViewCommand.MESSAGE_USAGE + + "\n\n" + ViewCommand.MESSAGE_USAGE // + "\n\n" + ViewAllCommand.MESSAGE_USAGE + "\n\n" + ClearCommand.MESSAGE_USAGE + "\n\n" + HelpCommand.MESSAGE_USAGE diff --git a/src/planmysem/logic/commands/ViewCommand.java b/src/planmysem/logic/commands/ViewCommand.java index febbfd811..bad9ee31f 100644 --- a/src/planmysem/logic/commands/ViewCommand.java +++ b/src/planmysem/logic/commands/ViewCommand.java @@ -1,15 +1,27 @@ package planmysem.logic.commands; +import static planmysem.common.Utils.getNearestDayOfWeek; + import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.WeekFields; +import java.util.ArrayList; +import java.util.Comparator; import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import planmysem.common.Clock; +import planmysem.common.Utils; import planmysem.logic.CommandHistory; import planmysem.model.Model; import planmysem.model.semester.Day; import planmysem.model.semester.Semester; +import planmysem.model.slot.Slot; /** - * Adds a person to the address book. + * View the planner. */ public class ViewCommand extends Command { @@ -17,8 +29,10 @@ public class ViewCommand extends Command { public static final String COMMAND_WORD_SHORT = "v"; public static final String MESSAGE_USAGE = COMMAND_WORD + ": View month/week/day view or all details of planner." - + "\n\tParameters: " - + "\n\t\tMandatory: [viewType] [specifier]" + + "\n\tFormat: view [viewType] [specifier]" + + "\n\tParameters:" + + "\n\t\tMandatory: [viewType]" + + "\n\t\tOptional: [specifier]" + "\n\tExample 1: " + COMMAND_WORD + " month" + "\n\tExample 2: " + COMMAND_WORD @@ -26,8 +40,14 @@ public class ViewCommand extends Command { + "\n\tExample 3: " + COMMAND_WORD + " week recess" + "\n\tExample 4: " + COMMAND_WORD - + " day 01/03/2019" + + " week" + "\n\tExample 5: " + COMMAND_WORD + + " day 01/03/2019" + + "\n\tExample 6: " + COMMAND_WORD + + " day monday" + + "\n\tExample 7: " + COMMAND_WORD + + " day" + + "\n\tExample 8: " + COMMAND_WORD + " all"; private final String viewArgs; @@ -39,7 +59,7 @@ public ViewCommand(String viewArgs) { @Override public CommandResult execute(Model model, CommandHistory commandHistory) { String viewType; - //String viewSpecifier; + String viewSpecifier; final Semester currentSemester = model.getPlanner().getSemester(); String output = null; @@ -48,19 +68,20 @@ public CommandResult execute(Model model, CommandHistory commandHistory) { output = "all"; } else if ("month".equals(viewArgs)) { output = displayMonthView(currentSemester); + } else if ("week".equals(viewArgs)) { + output = displayWeekView(currentSemester, null); + } else if ("day".equals(viewArgs)) { + output = displayDayView(currentSemester, null); } else { viewType = viewArgs.split(" ")[0]; - //viewSpecifier = viewArgs.split(" ")[1]; + viewSpecifier = viewArgs.split(" ")[1]; switch (viewType) { - case "month": - //TODO: month view - break; case "week": - //TODO: week view + output = displayWeekView(currentSemester, viewSpecifier); break; case "day": - //TODO: day view + output = displayDayView(currentSemester, viewSpecifier); break; default: break; @@ -136,4 +157,127 @@ private String displayMonthView(Semester currentSemester) { return sb.toString(); } + /** + * Display all slots for a given week. + */ + private String displayWeekView(Semester currentSemester, String week) { + HashMap allDays = currentSemester.getDays(); + StringBuilder sb = new StringBuilder(); + + if (week == null) { + System.out.println(allDays.get(LocalDate.now()).getType()); + + } else { + HashMap acadCal = currentSemester.getAcadCal(); + //System.out.println(currentSemester.getAcadCal()); + String key; + int[] weekOfYear = {0, 0}; + List datesList; + + if ("Recess".equals(week) || "Reading".equals(week) || "Examination".equals(week) + || "Orientation".equals(week)) { + key = week + " Week" + "_" + currentSemester.getName(); + sb.append(week + "Week" + " of " + currentSemester.getName() + "\n"); + } else { + key = "Week " + week + "_" + currentSemester.getName(); + sb.append("Week " + week + " of " + currentSemester.getName() + "\n"); + } + //System.out.println(key); + + for (Map.Entry entry: acadCal.entrySet()) { + if (key.equals(entry.getValue())) { + if (weekOfYear[0] == 0) { + weekOfYear[0] = entry.getKey(); + } else { + weekOfYear[1] = entry.getKey(); + } + } + } + //System.out.println(weekOfYear[0] + ", " + weekOfYear[1]); + + LocalDate weekStart = LocalDate.now().with(WeekFields.ISO.weekOfWeekBasedYear(), weekOfYear[0]); + weekStart = weekStart.with(WeekFields.ISO.dayOfWeek(), 1); + LocalDate weekEnd = weekStart.with(WeekFields.ISO.weekOfWeekBasedYear(), weekOfYear[0] + 1); + datesList = weekStart.datesUntil(weekEnd).collect(Collectors.toList()); + //System.out.println(datesList); + + sb.append("__________________________________________________________________________\n\n"); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + for (LocalDate date : datesList) { + sb.append(displayDayView(currentSemester, date.format(formatter))); + sb.append("__________________________________________________________________________\n\n"); + } + + // get acad cal map + // swap key and value + // find week of year from acad week + // get all dates for week of year + // get all slots for all dates found + // format and print out all slots + } + + return sb.toString(); + } + + /** + * Display all slots for a given day/date. + */ + private String displayDayView(Semester currentSemester, String dateOrDay) { + HashMap allDays = currentSemester.getDays(); + StringBuilder sb = new StringBuilder(); + + // Parse different formats of given day/date. + LocalDate givenDate; + if (dateOrDay == null) { + givenDate = LocalDate.now(); + } else { + int day = -1; + givenDate = Utils.parseDate(dateOrDay); + if (givenDate == null) { + day = Utils.parseDay(dateOrDay); + } + if (day == -1 && givenDate == null) { + return MESSAGE_USAGE; + } + if (day != -1) { + givenDate = getNearestDayOfWeek(LocalDate.now(Clock.get()), day); + } + } + sb.append(givenDate.getDayOfWeek().name() + " , " + givenDate + "\n\n"); + + // Retrieve all slots for given day/date in sorted order. + ArrayList allSlotsInDay = allDays.get(givenDate).getSlots(); + Comparator comparator = new Comparator() { + @Override + public int compare(final Slot o1, final Slot o2) { + return o1.getStartTime().compareTo(o2.getStartTime()); + } + }; + allSlotsInDay.sort(comparator); + + // Print each slot. + for (Slot slot : allSlotsInDay) { + sb.append("* " + slot.getStartTime()); + sb.append(" to "); + sb.append(Utils.getEndTime(slot.getStartTime(), slot.getDuration())); + + sb.append("\n\t" + slot.getName() + "\n"); + sb.append("\t" + "Location: " + slot.getLocation() + "\n"); + sb.append("\t" + "Description: " + slot.getDescription() + "\n"); + sb.append("\n\tTags: \n"); + + int count = 1; + for (String tag : slot.getTags()) { + sb.append("\t"); + sb.append(count); + sb.append(". "); + sb.append(tag); + count++; + } + + sb.append("\n\n"); + } + + return sb.toString(); + } } diff --git a/src/planmysem/logic/parser/ViewCommandParser.java b/src/planmysem/logic/parser/ViewCommandParser.java index 5fc2a392d..f2242baf1 100644 --- a/src/planmysem/logic/parser/ViewCommandParser.java +++ b/src/planmysem/logic/parser/ViewCommandParser.java @@ -27,6 +27,10 @@ public ViewCommand parse(String args) throws ParseException { return new ViewCommand(viewArgs[1]); } else if ("month".equals(viewArgs[1]) && viewArgs.length == 2) { return new ViewCommand(viewArgs[1]); + } else if ("week".equals(viewArgs[1]) && viewArgs.length == 2) { + return new ViewCommand(viewArgs[1]); + } else if ("day".equals(viewArgs[1]) && viewArgs.length == 2) { + return new ViewCommand(viewArgs[1]); } else if ("month".equals(viewArgs[1]) && viewArgs.length == 3) { //TODO: ensure month arguments return new ViewCommand(viewArgs[1] + " " + viewArgs[2]); diff --git a/src/planmysem/model/semester/ReadOnlySemester.java b/src/planmysem/model/semester/ReadOnlySemester.java index a7f679602..4c97d05fd 100644 --- a/src/planmysem/model/semester/ReadOnlySemester.java +++ b/src/planmysem/model/semester/ReadOnlySemester.java @@ -16,6 +16,7 @@ public interface ReadOnlySemester { LocalDate getStartDate(); LocalDate getEndDate(); int getNoOfWeeks(); + HashMap getAcadCal(); // These variables aid in making searches more effective Set getRecessDays(); diff --git a/src/planmysem/model/semester/Semester.java b/src/planmysem/model/semester/Semester.java index a6cf8751a..4bbe76a10 100644 --- a/src/planmysem/model/semester/Semester.java +++ b/src/planmysem/model/semester/Semester.java @@ -24,6 +24,7 @@ * @see Day#equals(Object) */ public class Semester implements ReadOnlySemester { + private static HashMap acadCal = new HashMap<>(); private final String name; private final String academicYear; private final HashMap days = new HashMap<>(); @@ -107,6 +108,7 @@ public static Semester generateSemester(LocalDate currentDate) { Set examDays = new HashSet<>(); acadCalMap = generateAcadCalMap(currentDate); + acadCal = acadCalMap; semesterDetails = getSemesterDetails(currentDate, acadCalMap); acadSem = semesterDetails[1]; acadYear = semesterDetails[2]; @@ -242,6 +244,7 @@ private static HashMap generateAcadCalMap(LocalDate date) { acadCalMap.put(vacationWeekNo++, "Vacation_Sem 2"); } + //System.out.println(acadCalMap); //why does this print twice? return acadCalMap; } @@ -467,11 +470,6 @@ public void setDays(HashMap days) { this.days.putAll(days); } - @Override - public HashMap getDays() { - return days; - } - @Override public LocalDate getStartDate() { return startDate; @@ -507,6 +505,16 @@ public Set getExamDays() { return examDays; } + @Override + public HashMap getDays() { + return days; + } + + @Override + public HashMap getAcadCal() { + return acadCal; + } + @Override public boolean equals(Object other) { return other == this // short circuit if same object