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

Added clearing reminder, bug fix for #190 and #163, and changed date description for reminder deadline #203

12 changes: 10 additions & 2 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,25 @@ A graph is shown.
// end::graph[]

=== Adding a reminder: `reminder add`
Adds a reminder to the reminder list
Adds a reminder to the reminder list. Key information such as deadline and message are recorded.

*Format:* `reminder add d/DATE m/MESSAGE`

[NOTE]
The date of a deadline must be within 5 years from the current date. MoneyGoWhere will check if the given reminder message and deadline are valid. If it encounters invalid information such as an empty message, the application will display an error.

*Examples:*

* `reminder add d/30/08/2020 m/Pay school fees` +
* `reminder add d/3 days from now m/Pay phone bill` +

*Expected Output:*

A new reminder is added.
A new reminder is added according to the information provided.

=== Deleting a reminder: `reminder delete`
Deletes a reminder at the specified `INDEX`.

*Format:* `reminder delete INDEX`

****
Expand Down Expand Up @@ -613,6 +618,9 @@ The most recent undo command is reversed.
Clears all entries from the application. +
*Format:* `clear`

[NOTE]
This command clears all stored reminders and spending from the application, and sets the budget to a default value of $1000.

*Expected Output:*

All application data is cleared.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import static seedu.moneygowhere.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.moneygowhere.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.moneygowhere.logic.parser.CliSyntax.PREFIX_MESSAGE;
import static seedu.moneygowhere.logic.parser.ParserUtil.DEADLINE_INVALID_FAR_BEHIND;
import static seedu.moneygowhere.logic.parser.ParserUtil.DEADLINE_INVALID_TOO_FAR;

import java.time.LocalDate;
import java.util.stream.Stream;

import seedu.moneygowhere.logic.commands.reminder.AddReminderCommand;
Expand Down Expand Up @@ -31,8 +34,25 @@ public AddReminderCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddReminderCommand.MESSAGE_USAGE));
}

String reminderMessage = argMultimap.getValue(PREFIX_MESSAGE).get().trim();

if (reminderMessage.isEmpty()) {
throw new ParseException(ReminderMessage.MESSAGE_CONSTRAINTS);
}

Date date = ParserUtil.parseDate(argMultimap.getValue(PREFIX_DATE).get());
ReminderMessage message = ParserUtil.parseMessage(argMultimap.getValue(PREFIX_MESSAGE).get());
ReminderMessage message = ParserUtil.parseMessage(reminderMessage);

if (date.dateValue.isAfter(LocalDate.now())
&& date.dateValue.getYear() - LocalDate.now().getYear() > ParserUtil.DATE_TOO_FAR_RANGE) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably also limit this to past reminders. Reminders 5 years ago should not be added.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can. May be the spending as well?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good consideration, can create an issue

throw new ParseException(DEADLINE_INVALID_TOO_FAR);
}

if (date.dateValue.isBefore(LocalDate.now())
&& LocalDate.now().getYear() - date.dateValue.getYear() > ParserUtil.DATE_FAR_BEHIND_RANGE) {
throw new ParseException(DEADLINE_INVALID_FAR_BEHIND);
}


Reminder reminder = new Reminder(date, message);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/moneygowhere/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public class ParserUtil {

public static final String MESSAGE_INVALID_INDEX = "Index is not a non-zero unsigned integer.";
public static final String DATE_INVALID_TOO_FAR = "Date is 5 years too far from now.";
public static final String DEADLINE_INVALID_FAR_BEHIND = "Deadline is 1 year behind from now";
public static final String DEADLINE_INVALID_TOO_FAR = "Deadline must be within 5 years from now.";
public static final int DATE_TOO_FAR_RANGE = 5;
public static final int DATE_FAR_BEHIND_RANGE = 1;

/**
* Parses {@code oneBasedIndex} into an {@code Index} and returns it.
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/moneygowhere/model/SpendingBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ public void removeSpending(Spending key) {
* Replaces the contents of the Reminder list with {@code reminders}.
*/
public void setReminders(List<Reminder> reminders) {
for (Reminder r : reminders) {
this.reminders.add(r);
}
this.reminders.setReminders(reminders);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/moneygowhere/model/reminder/Reminder.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public String getDueDateDescription() {
} else if (remainingDays == 1) {
return "Tomorrow";
} else if (remainingDays < 0) {
return "Overdue";
return "Overdue\n" + DateUtil.twoDigitYearFormatDate(deadline.value);
} else {
return "in " + remainingDays + " days\n" + DateUtil.twoDigitYearFormatDate(deadline.value);
return "in \n" + remainingDays + " days " + DateUtil.twoDigitYearFormatDate(deadline.value);
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/moneygowhere/model/reminder/ReminderList.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package seedu.moneygowhere.model.reminder;

import static java.util.Objects.requireNonNull;
import static seedu.moneygowhere.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Iterator;
import java.util.List;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand Down Expand Up @@ -51,6 +53,14 @@ public ObservableList<Reminder> asUnmodifiableObservableList() {
return internalUnmodifiableList;
}

/**
* Replaces the contents of this list with {@code reminders}.
*/
public void setReminders(List<Reminder> reminders) {
requireAllNonNull(reminders);
internalList.setAll(reminders);
}

@Override
public Iterator<Reminder> iterator() {
return internalList.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
public class ReminderMessage implements Comparable<ReminderMessage> {

public static final String MESSAGE_CONSTRAINTS = "Message should not be blank";

public final String value;

public ReminderMessage(String message) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/moneygowhere/model/spending/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
public class Name implements Comparable<Name> {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
"Names should only contain alphanumeric characters, spaces, '-' and '_', and it should not be blank";

/**
* The first character of the name must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "^[ a-zA-Z0-9_-]*$*";

public final String fullName;

Expand All @@ -35,7 +35,7 @@ public Name(String name) {
* Returns true if a given string is a valid name.
*/
public static boolean isValidName(String test) {
return test.matches(VALIDATION_REGEX);
return test.matches(VALIDATION_REGEX) && !(test.trim().isEmpty());
}


Expand Down
29 changes: 15 additions & 14 deletions src/main/java/seedu/moneygowhere/ui/ReminderCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,23 @@ public ReminderCard(Reminder reminder, int displayedIndex) {
this.reminder = reminder;
id.setText(displayedIndex + ". ");

switch (reminder.getDueDateDescription()) {
case "Today":
deadline.setTextFill(Color.ORANGE);
deadline.setText("Due " + reminder.getDueDateDescription());
break;
case "Tomorrow":
deadline.setTextFill(Color.GREEN);
deadline.setText("Due " + reminder.getDueDateDescription());
break;
case "Overdue":
String reminderDueDateDescription = reminder.getDueDateDescription();

if (reminderDueDateDescription.contains("Overdue")) {
deadline.setTextFill(Color.RED);
deadline.setText(reminder.getDueDateDescription());
break;
default:
deadline.setText(reminderDueDateDescription);
} else {
switch (reminderDueDateDescription) {
case "Today":
deadline.setTextFill(Color.ORANGE);
break;
case "Tomorrow":
deadline.setTextFill(Color.valueOf("#7B9918"));
break;
default:
break;
}
deadline.setText("Due " + reminder.getDueDateDescription());
break;
}
message.setText(reminder.getReminderMessage().value);
}
Expand Down