Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update view command #124

Merged
merged 40 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
92cb2cd
Planner: Initialize weekType for each Day
dingheng4448 Mar 7, 2019
1a98449
Planner: Fix Codacy issue
dingheng4448 Mar 7, 2019
45f7915
Planner: Update code for initialisation of semester
dingheng4448 Mar 8, 2019
2c631df
Planner: Fix Codacy and checkstyle issues
dingheng4448 Mar 9, 2019
20b4abb
Merge branch 'master' into develop
dingheng4448 Mar 9, 2019
5ac6ca9
Planner: Fix build error
dingheng4448 Mar 9, 2019
7e5b58c
Planner: Dynamic generation of semester from date
dingheng4448 Mar 16, 2019
60d1cda
PlannerTest: Add JUnit test for generateSemester
dingheng4448 Mar 16, 2019
93b40ed
Merge remote-tracking branch 'origin/develop' into develop
dingheng4448 Mar 16, 2019
a8d57fe
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
a002fdc
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
dbcf1fd
Update documentation for view command
dingheng4448 Mar 17, 2019
f3ce309
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
8d35cfb
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
aa42b48
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 17, 2019
f0d916b
Add view command for monthly calendar view
dingheng4448 Mar 18, 2019
132bb01
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 18, 2019
1eded38
Fix Codacy issue
dingheng4448 Mar 18, 2019
db15e14
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 19, 2019
bfac078
UserGuide: Update user guide documentation
dingheng4448 Mar 19, 2019
936a880
UserGuide: Update user guide documentation
dingheng4448 Mar 19, 2019
6c679a2
UserGuide: Update user guide documentation
dingheng4448 Mar 20, 2019
a2c34fa
UserGuide: Update user guide documentation
dingheng4448 Mar 21, 2019
732c15e
Merge remote-tracking branch 'origin/develop' into develop
dingheng4448 Mar 21, 2019
e14f476
UserGuide: Update user guide documentation
dingheng4448 Mar 21, 2019
4b1781b
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 21, 2019
d7cb580
UserGuide: Update user guide documentation
dingheng4448 Mar 21, 2019
24ac7d5
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 21, 2019
9967d8d
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 23, 2019
17f1e8d
Moved Semester generation code
dingheng4448 Mar 24, 2019
48db5f1
Planner: remove unused imports
dingheng4448 Mar 24, 2019
fe1f0e4
Semester: undo minor change
dingheng4448 Mar 24, 2019
abcb88b
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 24, 2019
7a60cb4
DeveloperGuide: Update documentation on initialization of Semester
dingheng4448 Mar 24, 2019
eb4f062
Merge branch 'master' into develop
dingheng4448 Mar 24, 2019
997c9da
Merge branch 'master' of https://github.com/CS2113-AY1819S2-T08-3/mai…
dingheng4448 Mar 29, 2019
33b0875
Merge remote-tracking branch 'origin/develop' into develop
dingheng4448 Mar 29, 2019
dcc4a84
Merge commit
dingheng4448 Mar 29, 2019
f3d3b3a
Update view command for calendar day view
dingheng4448 Mar 30, 2019
0006b62
Update view command for calendar week view
dingheng4448 Mar 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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` +
Expand Down
2 changes: 1 addition & 1 deletion src/planmysem/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
166 changes: 155 additions & 11 deletions src/planmysem/logic/commands/ViewCommand.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
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 {

public static final String COMMAND_WORD = "view";
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
+ " week 7"
+ "\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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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<LocalDate, Day> allDays = currentSemester.getDays();
StringBuilder sb = new StringBuilder();

if (week == null) {
System.out.println(allDays.get(LocalDate.now()).getType());

} else {
HashMap<Integer, String> acadCal = currentSemester.getAcadCal();
//System.out.println(currentSemester.getAcadCal());
String key;
int[] weekOfYear = {0, 0};
List<LocalDate> 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<Integer, String> 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<LocalDate, Day> 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<Slot> allSlotsInDay = allDays.get(givenDate).getSlots();
Comparator<Slot> comparator = new Comparator<Slot>() {
@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();
}
}
4 changes: 4 additions & 0 deletions src/planmysem/logic/parser/ViewCommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions src/planmysem/model/semester/ReadOnlySemester.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface ReadOnlySemester {
LocalDate getStartDate();
LocalDate getEndDate();
int getNoOfWeeks();
HashMap<Integer, String> getAcadCal();

// These variables aid in making searches more effective
Set<LocalDate> getRecessDays();
Expand Down
18 changes: 13 additions & 5 deletions src/planmysem/model/semester/Semester.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @see Day#equals(Object)
*/
public class Semester implements ReadOnlySemester {
private static HashMap<Integer, String> acadCal = new HashMap<>();
private final String name;
private final String academicYear;
private final HashMap<LocalDate, Day> days = new HashMap<>();
Expand Down Expand Up @@ -107,6 +108,7 @@ public static Semester generateSemester(LocalDate currentDate) {
Set<LocalDate> examDays = new HashSet<>();

acadCalMap = generateAcadCalMap(currentDate);
acadCal = acadCalMap;
semesterDetails = getSemesterDetails(currentDate, acadCalMap);
acadSem = semesterDetails[1];
acadYear = semesterDetails[2];
Expand Down Expand Up @@ -242,6 +244,7 @@ private static HashMap<Integer, String> generateAcadCalMap(LocalDate date) {
acadCalMap.put(vacationWeekNo++, "Vacation_Sem 2");
}

//System.out.println(acadCalMap); //why does this print twice?
return acadCalMap;
}

Expand Down Expand Up @@ -467,11 +470,6 @@ public void setDays(HashMap<LocalDate, Day> days) {
this.days.putAll(days);
}

@Override
public HashMap<LocalDate, Day> getDays() {
return days;
}

@Override
public LocalDate getStartDate() {
return startDate;
Expand Down Expand Up @@ -507,6 +505,16 @@ public Set<LocalDate> getExamDays() {
return examDays;
}

@Override
public HashMap<LocalDate, Day> getDays() {
return days;
}

@Override
public HashMap<Integer, String> getAcadCal() {
return acadCal;
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down