Skip to content

Commit

Permalink
Merge pull request #113 from hengyu95/Birthdate_TAB
Browse files Browse the repository at this point in the history
Birthdate tab.
  • Loading branch information
ritchielq authored Nov 1, 2017
2 parents 644e36f + 4863638 commit 9982209
Show file tree
Hide file tree
Showing 19 changed files with 358 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/team/hengyu.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ AddressBook - Level 4 is a desktop address book application used for teaching So

*Code contributed*: [https://github.com[Functional code]] [https://github.com[Test code]] {give links to collated code files}

=== Enhancement Added: Birthdate Field
=== Enhancement Added: Birthdate Field/Tab
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<ReadOnlyPerson> getFilteredPersonList();

ObservableList<ReadOnlyPerson> getFilteredPersonListBirthdate();

/** Returns the list of input entered by the user, encapsulated in a {@code ListElementPointer} object */
ListElementPointer getHistorySnapshot();
}
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public ObservableList<ReadOnlyPerson> getFilteredPersonList() {
return model.getFilteredPersonList();
}

@Override
public ObservableList<ReadOnlyPerson> getFilteredPersonListBirthdate() {
return model.getFilteredPersonListBirthdate();
}

@Override
public ListElementPointer getHistorySnapshot() {
return new ListElementPointer(history.getHistory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ListCommand() {
new ListCommand(0);
}

//@@author hengyu95
public ListCommand(int sortOrder) {
this.sortOrder = sortOrder;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ void updatePerson(ReadOnlyPerson target, ReadOnlyPerson editedPerson) throws Dup
/** Returns an unmodifiable view of the filtered person list */
ObservableList<ReadOnlyPerson> getFilteredPersonList();

/** Returns an unmodifiable view of the filtered person list sorted by upcoming birthdays*/
ObservableList<ReadOnlyPerson> getFilteredPersonListBirthdate();

/**
* Updates the filter of the filtered person list to filter by the given {@code predicate}.
* @throws NullPointerException if {@code predicate} is null.
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -51,6 +54,7 @@ public class ModelManager extends ComponentManager implements Model {
private final AddressBook addressBook;
private final FilteredList<ReadOnlyPerson> filteredPersons;
private final SortedList<ReadOnlyPerson> sortedPersonsList;
private final SortedList<ReadOnlyPerson> sortedPersonsListBirthdate;

/**
* Initializes a ModelManager with the given addressBook and userPrefs.
Expand All @@ -64,7 +68,10 @@ public ModelManager(ReadOnlyAddressBook addressBook, UserPrefs userPrefs, Email
this.email = email;
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
sortedPersonsList = new SortedList<ReadOnlyPerson>(filteredPersons);
sortedPersonsListBirthdate = new SortedList<ReadOnlyPerson>(filteredPersons);
sortFilteredPersons(0);
sortBirthdate();

}

public ModelManager() {
Expand Down Expand Up @@ -165,7 +172,16 @@ public ObservableList<ReadOnlyPerson> getFilteredPersonList() {
return FXCollections.unmodifiableObservableList(sortedPersonsList);
}

//@@author hengyu95
@Override
public ObservableList<ReadOnlyPerson> getFilteredPersonListBirthdate() {
return FXCollections.unmodifiableObservableList(sortedPersonsListBirthdate);
}
//@@author


//@@author awarenessxz

/**
* @param: int
* 0 = sort by name ascending
Expand Down Expand Up @@ -222,7 +238,54 @@ public int compare(ReadOnlyPerson o1, ReadOnlyPerson o2) {

sortedPersonsList.setComparator(sort);
}
//@@author hengyu95

/**
* Returns a sorted unmodifiable view of the list {@code ReadOnlyPerson} backed by the internal list of
* {@code addressBook} sorted by upcoming birthdays
*/
public void sortBirthdate() {

Comparator<ReadOnlyPerson> sort = new Comparator<ReadOnlyPerson>() {

public int compare(ReadOnlyPerson o1, ReadOnlyPerson o2) {
String birthdate1 = o1.getBirthdate().value;

String birthdate2 = o2.getBirthdate().value;
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy");

LocalDate today = LocalDate.now();
LocalDate date1;
LocalDate date2;

try {
date1 = LocalDate.parse(birthdate1, format).withYear(today.getYear());
} catch (DateTimeParseException e) {
date1 = LocalDate.of(9999, 12, 30);
}

try {
date2 = LocalDate.parse(birthdate2, format).withYear(today.getYear());
} catch (DateTimeParseException e) {
date2 = LocalDate.of(9999, 12, 30);
}

if (date1.isBefore(today)) {
date1 = date1.withYear(date1.getYear() + 1);
}

if (date2.isBefore(today)) {
date2 = date2.withYear(date2.getYear() + 1);
}

return date1.compareTo(date2);
}
};

sortedPersonsListBirthdate.setComparator(sort);
}

//@@author
@Override
public void updateFilteredPersonList(Predicate<ReadOnlyPerson> predicate) {
requireNonNull(predicate);
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/seedu/address/model/person/Birthdate.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
//@@author hengyu95

package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.exceptions.IllegalValueException;


/**
* Represents a Person's phone number in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidBirthdate(String)}
Expand All @@ -12,12 +15,12 @@ public class Birthdate {


public static final String MESSAGE_BIRTHDATE_CONSTRAINTS =
"Birthdate should contain valid date entries separated by . - /";
public static final String BIRTHDATE_VALIDATION_REGEX = "([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([0]?[1-9]|[1]"
+ "[0-2])[./-]([0-9]{4}|[0-9]{2})"; // dd/mm/yyyy or d/m/yy or d.m.yyyy with separators: . - /
"A valid date entry is in the form of dd/mm/yyyy";

public static final String BIRTHDATE_VALIDATION_REGEX2 = "([0]?[1-9]|[1|2][0-9]|[3][0|1])[./-]([1][0-2]|[0]?[1-9])";
// dd/mm or d/m or d.m with separators: . - /
public static final String BIRTHDATE_VALIDATION_REGEX = "(((0[1-9]|[12]\\d|3[01])\\/(0[13578]|1[02])\\/((1[6-9]|"
+ "[2-9]\\d)\\d{2}))|((0[1-9]|[12]\\d|30)\\/(0[13456789]|1[012])\\/((1[6-9]|[2-9]\\d)\\d{2}))"
+ "|((0[1-9]|1\\d|2[0-8])\\/02\\/((1[6-9]|[2-9]\\d)\\d{2}))|(29\\/02\\/((1[6-9]|[2-9]\\d)"
+ "(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))";

public final String value;

Expand All @@ -29,6 +32,7 @@ public class Birthdate {
public Birthdate(String birthdate) throws IllegalValueException {
requireNonNull(birthdate);
String trimmedBirthdate = birthdate.trim();

if (!trimmedBirthdate.equals("-")) {
if (!isValidBirthdate(trimmedBirthdate)) {
throw new IllegalValueException(MESSAGE_BIRTHDATE_CONSTRAINTS);
Expand All @@ -41,8 +45,9 @@ public Birthdate(String birthdate) throws IllegalValueException {
/**
* Returns true if a given string is a valid person phone number.
*/

public static boolean isValidBirthdate(String test) {
return test.matches(BIRTHDATE_VALIDATION_REGEX) || test.matches(BIRTHDATE_VALIDATION_REGEX2);
return test.matches(BIRTHDATE_VALIDATION_REGEX);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static Person[] getSamplePersons() {
getTagSet("family"), new Birthdate("01/01/1995")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new EmailAddress("[email protected]"),
new Address("Blk 47 Tampines Street 20, #17-35"), new Photo("data/images/default.jpeg"),
getTagSet("classmates"), new Birthdate("01/01")),
getTagSet("classmates"), new Birthdate("01/01/1990")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new EmailAddress("[email protected]"),
new Address("Blk 45 Aljunied Street 85, #11-31"), new Photo("data/images/default.jpeg"),
getTagSet("colleagues"), new Birthdate("01/02/1995")),
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/seedu/address/ui/LeftDisplayPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@

//@@author awarenessxz
/**
* Tab Panel containing personListPanel and EmailDraftPanel
* Tab Panel containing personListPanel, EmailDraftPanel, and BirthdateTab
*/
public class LeftDisplayPanel extends UiPart<Region> {
private static final String FXML = "LeftDisplayPanel.fxml";
private final Logger logger = LogsCenter.getLogger(LeftDisplayPanel.class);

//Independent UI parts residing in this UI container
private PersonListPanel personListPanel;
private PersonListBirthdatePanel birthdayListPanel;
private MessageDisplay messageDisplay;

private boolean toggle;
private boolean toggle2;

@FXML
private TabPane leftDisplayPanel;
Expand All @@ -34,34 +35,52 @@ public class LeftDisplayPanel extends UiPart<Region> {
@FXML
private Tab emailDraftTab;

@FXML
private Tab birthdateTab;

@FXML
private StackPane personListPanelPlaceholder;

@FXML
private StackPane messageDraftPanelPlaceholder;

public LeftDisplayPanel(ObservableList<ReadOnlyPerson> personList) {
@FXML
private StackPane birthdatePanelPlaceholder;

public LeftDisplayPanel(ObservableList<ReadOnlyPerson> personList,
ObservableList<ReadOnlyPerson> personListBirthdate) {
super(FXML);

personListPanel = new PersonListPanel(personList);
personListPanelPlaceholder.getChildren().add(personListPanel.getRoot());

birthdayListPanel = new PersonListBirthdatePanel(personListBirthdate);
birthdatePanelPlaceholder.getChildren().add(birthdayListPanel.getRoot());

messageDisplay = new MessageDisplay();
messageDraftPanelPlaceholder.getChildren().add(messageDisplay.getRoot());

toggle = true;
toggle2 = true;
}

/**
* Toggle Tabs
*/
public void toggleTabs() {
if (toggle) {
if (toggle && toggle2) {
leftDisplayPanel.getSelectionModel().select(emailDraftTab);
} else {
toggle2 = !toggle2;
}
else if (toggle && !toggle2) {
leftDisplayPanel.getSelectionModel().select(birthdateTab);
toggle2 = !toggle2;
toggle = false;
}
else {
leftDisplayPanel.getSelectionModel().select(personListTab);
toggle = true;
}
toggle = !toggle;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ void fillInnerParts() {
browserPanel = new BrowserPanel(config);
browserPlaceholder.getChildren().add(browserPanel.getRoot());

leftDisplayPanel = new LeftDisplayPanel(logic.getFilteredPersonList());
//@@author hengyu95
leftDisplayPanel = new LeftDisplayPanel(logic.getFilteredPersonList(), logic.getFilteredPersonListBirthdate());
leftDisplayPanelPlacedholder.getChildren().add(leftDisplayPanel.getRoot());
//@@author

ResultDisplay resultDisplay = new ResultDisplay();
resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot());
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package seedu.address.ui;

import java.io.FileInputStream;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.HashMap;
import java.util.Random;

Expand Down Expand Up @@ -59,6 +62,7 @@ public PersonCard(ReadOnlyPerson person, int displayedIndex) {
id.setText(displayedIndex + ". ");
initTags(person);
bindListeners(person);

}

/**
Expand All @@ -72,6 +76,19 @@ private void bindListeners(ReadOnlyPerson person) {
emailAddress.textProperty().bind(Bindings.convert(person.emailAddressProperty()));
birthdate.textProperty().bind(Bindings.convert(person.birthdateProperty()));

setColor(person);


try {
StringExpression filePath = Bindings.convert(person.photoProperty());
FileInputStream imageInputStream = new FileInputStream(filePath.getValue());
Image image = new Image(imageInputStream, 100, 200, true, true);
photo.setImage(image);
imageInputStream.close();
} catch (Exception e) {
System.out.println(e);
}

getPhoto();

person.tagProperty().addListener((observable, oldValue, newValue) -> {
Expand All @@ -80,6 +97,24 @@ private void bindListeners(ReadOnlyPerson person) {
});
}

//@@author hengyu95
private void setColor(ReadOnlyPerson person) {

LocalDate date1;
LocalDate now = LocalDate.now();
DateTimeFormatter format = DateTimeFormatter.ofPattern("dd/MM/yyyy");

try {
date1 = LocalDate.parse(person.getBirthdate().value, format).withYear(now.getYear());
} catch (DateTimeParseException e) {
date1 = LocalDate.of(9999, 12, 30);
}

if (date1.equals(now)) {
cardPane.setStyle("-fx-background-color: #336699;");
}
}
//@@author
/**
* Initializes all the Tags for a given person
* @param person
Expand Down
Loading

0 comments on commit 9982209

Please sign in to comment.