Skip to content

Commit

Permalink
Merge pull request #141 from choaticman/branch-dylan-fix-status-ui-bug
Browse files Browse the repository at this point in the history
Fix UI bugs regarding Status and Date
  • Loading branch information
ZweZeya authored Oct 26, 2024
2 parents 56a167f + 4d0ebfa commit e77297a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
13 changes: 10 additions & 3 deletions src/main/java/seedu/hireme/logic/commands/StatusCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import static java.util.Objects.requireNonNull;

import java.util.List;
import java.util.function.Predicate;

import javafx.collections.transformation.FilteredList;
import seedu.hireme.commons.core.index.Index;
import seedu.hireme.logic.Messages;
import seedu.hireme.logic.commands.exceptions.CommandException;
Expand Down Expand Up @@ -64,14 +65,20 @@ public StatusCommand(Index targetIndex, Status newStatus) {
@Override
public CommandResult execute(Model<InternshipApplication> model) throws CommandException {
requireNonNull(model);
List<InternshipApplication> lastShownList = model.getFilteredList();
FilteredList<InternshipApplication> lastShownList =
(FilteredList<InternshipApplication>) model.getFilteredList();
Predicate prevPredicate = lastShownList.getPredicate() == null
? Model.PREDICATE_SHOW_ALL : lastShownList.getPredicate();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_INTERNSHIP_APPLICATION_DISPLAYED_INDEX);
}

InternshipApplication internshipApplicationToUpdate = lastShownList.get(targetIndex.getZeroBased());
internshipApplicationToUpdate.setStatus(newStatus);
InternshipApplication updatedInternshipApplication = internshipApplicationToUpdate.deepCopy();
updatedInternshipApplication.setStatus(newStatus);
model.setItem(internshipApplicationToUpdate, updatedInternshipApplication);
model.updateFilteredList(prevPredicate);
return new CommandResult(String.format(MESSAGE_STATUS_CHANGE_SUCCESS,
Messages.format(internshipApplicationToUpdate), newStatus.getValue()));
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/seedu/hireme/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ public static Role parseRole(String role) throws ParseException {
public static Date parseDate(String date) throws ParseException {
requireNonNull(date);
String trimmedDate = date.trim();
if (!DateValidator.of().validate(trimmedDate)) {
String[] args = trimmedDate.split(" ");
if (args.length > 1) {
throw new ParseException(Date.MESSAGE_TOO_MANY_ARGUMENTS);
}

if (!DateValidator.of().validate(args[0])) {
throw new ParseException(Date.MESSAGE_CONSTRAINTS);
}
return new Date(LocalDate.parse(trimmedDate, DateTimeFormatter.ofPattern("dd/MM/yy")));
return new Date(LocalDate.parse(args[0], DateTimeFormatter.ofPattern("dd/MM/yy")));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static DateValidator of() {
public boolean validate(String input) {
try {
LocalDate date = LocalDate.parse(input, FORMATTER);
return date.isBefore(LocalDate.now());
return !date.isAfter(LocalDate.now());
} catch (DateTimeParseException e) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class Date implements Comparable<Date> {
public static final String MESSAGE_CONSTRAINTS =
"Dates must not be in the future, should be in the format 'dd/MM/yy', and must be valid.";

public static final String MESSAGE_TOO_MANY_ARGUMENTS = "Date should only be DD/MM/YY with no other words";

private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd/MM/yy");

private final LocalDate date;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/view/InternshipApplicationListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="role" styleClass="cell_small_label" text="\$role" />
<Label fx:id="date" styleClass="cell_small_label" text="\$date" />
<Label fx:id="status" styleClass="status-label" text="\$status"/>
<Label fx:id="status" styleClass="status-label" />
</VBox>
</GridPane>
</HBox>

0 comments on commit e77297a

Please sign in to comment.