From 6520922e46c73c2412f18432d897ffc92264c089 Mon Sep 17 00:00:00 2001 From: izruff Date: Fri, 18 Oct 2024 00:22:37 +0800 Subject: [PATCH 01/12] AddressBookParser.java: Add mark and unmark commands --- .../seedu/address/logic/parser/AddressBookParser.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 68fa9739bde..c67c5efb50e 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -19,6 +19,8 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.MarkAttendanceCommand; +import seedu.address.logic.commands.UnmarkAttendanceCommand; import seedu.address.logic.parser.exceptions.ParseException; /** @@ -85,6 +87,12 @@ public Command parseCommand(String userInput) throws ParseException { case DeleteGradeCommand.COMMAND_WORD: return new DeleteGradeCommandParser().parse(arguments); + case MarkAttendanceCommand.COMMAND_WORD: + return new MarkAttendanceCommandParser().parse(arguments); + + case UnmarkAttendanceCommand.COMMAND_WORD: + return new UnmarkAttendanceCommandParser().parse(arguments); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); From 1da6a506ed3c8c645c2378da98390c1888d940b8 Mon Sep 17 00:00:00 2001 From: izruff Date: Sat, 19 Oct 2024 20:00:26 +0800 Subject: [PATCH 02/12] Add JSON utilities for attendance --- .../java/seedu/address/logic/Messages.java | 3 ++ .../storage/JsonAdaptedAttendance.java | 31 +++++++++++++++++++ .../address/storage/JsonAdaptedPerson.java | 16 ++++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedAttendance.java diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index d81a8d766be..7a1ee091a14 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -48,6 +48,9 @@ public static String format(Person person) { // Append the GradeList (exams and scores) builder.append("; Exams: ") .append(person.getGradeList()); + // Append the AttendanceList (dates and attendance) + builder.append("; Attendances: ") + .append(person.getAttendanceList()); return builder.toString(); } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedAttendance.java b/src/main/java/seedu/address/storage/JsonAdaptedAttendance.java new file mode 100644 index 00000000000..0e6b384d773 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedAttendance.java @@ -0,0 +1,31 @@ +package seedu.address.storage; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import seedu.address.model.person.Attendance; + +/** + * Jackson-friendly version of {@link Attendance}. + */ +public class JsonAdaptedAttendance { + + public static final String MISSING_FIELD_MESSAGE_FORMAT = "Attendance's %s field is missing!"; + + private final boolean hasAttended; + + /** + * Constructs a {@code JsonAdaptedAttendance} with the given attendance details. + */ + @JsonCreator + public JsonAdaptedAttendance(@JsonProperty("hasAttended") boolean hasAttended) { + this.hasAttended = hasAttended; + } + + /** + * Converts this Jackson-friendly adapted attendance object into the model's {@code Attendance} object. + */ + public Attendance toModelType() { + return new Attendance(hasAttended); + } +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 690f7d80e6c..0272da96295 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -1,9 +1,13 @@ package seedu.address.storage; +import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.TreeMap; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonCreator; @@ -11,6 +15,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.person.Address; +import seedu.address.model.person.Attendance; import seedu.address.model.person.AttendanceList; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; @@ -33,6 +38,7 @@ class JsonAdaptedPerson { private final String address; private final List tags = new ArrayList<>(); private final List grades = new ArrayList<>(); + private final Map attendances = new HashMap<>(); /** * Constructs a {@code JsonAdaptedPerson} with the given person details. @@ -40,7 +46,8 @@ class JsonAdaptedPerson { @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags, @JsonProperty("grades") List grades) { + @JsonProperty("tags") List tags, @JsonProperty("grades") List grades, + @JsonProperty("attendances") Map attendances) { this.name = name; this.phone = phone; this.email = email; @@ -120,8 +127,11 @@ public Person toModelType() throws IllegalValueException { } final GradeList modelGradeList = new GradeList(convertedGrades); - // TODO: Store attendanceList properly - final AttendanceList modelAttendancelist = new AttendanceList(); + final Map convertedAttendances = new TreeMap<>(); + for (Map.Entry entry : attendances.entrySet()) { + convertedAttendances.put(entry.getKey(), entry.getValue().toModelType()); + } + final AttendanceList modelAttendancelist = new AttendanceList(convertedAttendances); return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, modelGradeList, modelAttendancelist); From 98dccfa94c24294bab71e0620e68cee95c9ac3d1 Mon Sep 17 00:00:00 2001 From: izruff Date: Sat, 19 Oct 2024 20:08:11 +0800 Subject: [PATCH 03/12] Display attendance list on UI --- src/main/java/seedu/address/ui/PersonCard.java | 10 ++++++++++ src/main/resources/view/PersonListCard.fxml | 1 + 2 files changed, 11 insertions(+) diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index ce53571db84..9fdc66929b6 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -42,6 +42,8 @@ public class PersonCard extends UiPart { private FlowPane tags; @FXML private Label grades; + @FXML + private Label attendances; /** * Creates a {@code PersonCode} with the given {@code Person} and index to display. @@ -58,6 +60,7 @@ public PersonCard(Person person, int displayedIndex) { .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); grades.setText(formatGrades(person.getGradeList().toString())); // Format and set grades + attendances.setText(formatAttendances(person.getAttendanceList().toString())); // Format and set attendances } /** @@ -66,4 +69,11 @@ public PersonCard(Person person, int displayedIndex) { private String formatGrades(String gradeList) { return "Grades:\n" + gradeList; } + + /** + * Formats the attendance list to display properly in the UI. + */ + private String formatAttendances(String attendanceList) { + return "Attendances:\n" + attendanceList; + } } diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index d7b0545fad9..a9f334f72ca 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -32,6 +32,7 @@