Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' into branch-summary-bar
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/seedu/address/model/Model.java
#	src/test/java/seedu/address/logic/commands/AddCommandTest.java
  • Loading branch information
joszx committed Mar 30, 2022
2 parents 64a7526 + c530f5a commit 90bf994
Show file tree
Hide file tree
Showing 24 changed files with 584 additions and 92 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ To display the new `details` field, modifications to the `applicationCard.java`

Below is an image of the UI after the changes were made:

![Ui-after-details-update](images/Ui-after-details-update.png)
![Ui-after-details-update](images/Ui.png)

#### Proposed improvements
1. As the colour of each `application card` alternates between each index, changes to the `Ui` have to be made as well to match the alternating colours. To achieve this change, implementing the css style in `DarkTheme.css` file, in particular `List-view` css should be made when implementing changes to the `applicationCard.fxml`
Expand Down
210 changes: 161 additions & 49 deletions docs/UserGuide.md

Large diffs are not rendered by default.

File renamed without changes
57 changes: 55 additions & 2 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_APPLICATIONS;

import java.util.Comparator;
import java.util.Optional;

import seedu.address.logic.sort.ApplicationStatusComparator;
import seedu.address.logic.sort.InterviewSlotComparator;
import seedu.address.logic.sort.NameComparator;
import seedu.address.logic.sort.PriorityComparator;
import seedu.address.model.Model;
import seedu.address.model.application.Application;

/**
* Lists all applications in InternApply to the user.
Expand All @@ -12,13 +20,58 @@ public class ListCommand extends Command {

public static final String COMMAND_WORD = "list";

public static final String MESSAGE_SUCCESS = "Listed all applications";
public static final String COMMAND_ORDER_WORD_ASCENDING = "ASC";

public static final String COMMAND_ORDER_WORD_DESCENDING = "DESC";

public static final String MESSAGE_SUCCESS = "Sorted applications by %1$s";

public static final String MESSAGE_NO_CHANGE = "last sorted method.";

public static final String MESSAGE_NO_CHANGE_FULL = String.format(MESSAGE_SUCCESS, MESSAGE_NO_CHANGE);

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Show a sorted list of all applications with the given sort parameter.\n"
+ "Parameters: [parameter "
+ NameComparator.COMMAND_WORD.toUpperCase() + "|"
+ InterviewSlotComparator.COMMAND_WORD.toUpperCase() + "|"
+ PriorityComparator.COMMAND_WORD.toUpperCase() + "|"
+ ApplicationStatusComparator.COMMAND_WORD.toUpperCase() + "] "
+ "[order " + COMMAND_ORDER_WORD_ASCENDING + "|" + COMMAND_ORDER_WORD_DESCENDING + "] \n"
+ "Example: " + COMMAND_WORD + " INTERVIEW " + COMMAND_ORDER_WORD_DESCENDING + "\n"
+ "Note: Using list without parameters will revert to the last sorted.";

private final Optional<Comparator<Application>> sortingComparator;
private final String orderBy;

/**
* Creates a ListCommand with the previous sorting order.
* Notes: the {@code sortingComparator} and {@code orderBy} are just placeholder values.
*/
public ListCommand() {
sortingComparator = Optional.empty();
orderBy = COMMAND_ORDER_WORD_ASCENDING;
}

/**
* Creates a ListCommand with a specified {@code sortingComparator} and {@code orderBy}
*/
public ListCommand(Comparator<Application> sortingComparator, String orderBy) {
this.sortingComparator = Optional.ofNullable(sortingComparator);
this.orderBy = orderBy;
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
sortingComparator.ifPresent(applicationComparator -> model.sortApplications(applicationComparator, orderBy));
model.updateFilteredApplicationList(PREDICATE_SHOW_ALL_APPLICATIONS);
return new CommandResult(MESSAGE_SUCCESS);
return new CommandResult(String.format(MESSAGE_SUCCESS, outputMsg()));
}

private String outputMsg() {
return sortingComparator.map(applicationComparator -> String.format(
"%s order by %s.", applicationComparator, orderBy.toLowerCase()))
.orElse(MESSAGE_NO_CHANGE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Command parseCommand(String userInput) throws ParseException {
return new FindCommandParser().parse(arguments);

case ListCommand.COMMAND_WORD:
return new ListCommand();
return new ListCommandParser().parse(arguments);

case ExitCommand.COMMAND_WORD:
return new ExitCommand();
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/seedu/address/logic/parser/ListCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.ListCommand.COMMAND_ORDER_WORD_ASCENDING;
import static seedu.address.logic.commands.ListCommand.COMMAND_ORDER_WORD_DESCENDING;

import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.logic.sort.ApplicationStatusComparator;
import seedu.address.logic.sort.InterviewSlotComparator;
import seedu.address.logic.sort.NameComparator;
import seedu.address.logic.sort.PriorityComparator;

/**
* Parses input arguments and creates a new ListCommand object
*/
public class ListCommandParser implements Parser<ListCommand> {

/**
* Parses the given {@code String} of arguments in the context of the ListCommand
* and returns a ListCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public ListCommand parse(String args) throws ParseException {
String trimmedArgs = args.trim();

if (trimmedArgs.isEmpty()) /* Handles default list */ {
return new ListCommand();
}

String[] sortingArgs = trimmedArgs.split("\\s+");

if (sortingArgs.length == 1) {
String keyword = sortingArgs[0];
if (keyword.equals(COMMAND_ORDER_WORD_DESCENDING)) {
return new ListCommand(null, COMMAND_ORDER_WORD_DESCENDING);
} else if (keyword.equals(COMMAND_ORDER_WORD_ASCENDING)) {
return new ListCommand();
}
} else {
String sortingField = sortingArgs[0].toLowerCase();
String orderBy = sortingArgs[1].toUpperCase();

if (validateOrderBy(orderBy)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE));
} else if (sortingField.equals(NameComparator.COMMAND_WORD)) {
return new ListCommand(new NameComparator(), orderBy);
} else if (sortingField.equals(InterviewSlotComparator.COMMAND_WORD)) {
return new ListCommand(new InterviewSlotComparator(), orderBy);
} else if (sortingField.equals(PriorityComparator.COMMAND_WORD)) {
return new ListCommand(new PriorityComparator(), orderBy);
} else if (sortingField.equals(ApplicationStatusComparator.COMMAND_WORD)) {
return new ListCommand(new ApplicationStatusComparator(), orderBy);
}
}

throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ListCommand.MESSAGE_USAGE));
}

private boolean validateOrderBy(String s) {
return !s.equals(COMMAND_ORDER_WORD_DESCENDING) && !s.equals(COMMAND_ORDER_WORD_ASCENDING);
}
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -214,6 +215,9 @@ public static Tag parsePriorityTag(String tag) throws ParseException {
*/
public static Set<Tag> parseTags(Collection<String> tags) throws ParseException {
requireNonNull(tags);
if (tags.equals(Collections.emptySet())) {
throw new ParseException(Tag.MESSAGE_CONSTRAINTS);
}
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(parseTag(tagName));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.sort;

import static seedu.address.model.tag.ApplicationStatusTagType.ACCEPTED;
import static seedu.address.model.tag.ApplicationStatusTagType.APPLIED;
import static seedu.address.model.tag.ApplicationStatusTagType.INTERVIEWED;
import static seedu.address.model.tag.ApplicationStatusTagType.NOT_APPLIED;
import static seedu.address.model.tag.ApplicationStatusTagType.REJECTED;

import java.util.Comparator;
import java.util.Optional;

import seedu.address.model.application.Application;
import seedu.address.model.tag.Tag;

public class ApplicationStatusComparator implements Comparator<Application> {

public static final String COMMAND_WORD = "status";

@Override
public int compare(Application o1, Application o2) {
return getStatusRanking(o1.getApplicationStatusTag()) - getStatusRanking(o2.getApplicationStatusTag());
}

/**
* Compares the two application's status tag field. Returns a negative integer, zero, or a positive integer as
* the first argument is less than, equal to, or greater than the second base on alphanumeric order.
* The default order from ascending to descend is as follows ACCEPTED, REJECTED, INTERVIEWED, APPLIE and
* NOT_APPLIED.
* An empty tag will be considered as the lowest ranking, ranked below NOT_APPLIED.
* */
private int getStatusRanking(Optional<Tag> t) {
if (t.isEmpty()) {
return 6;
} else if (t.get().toString().equals(NOT_APPLIED.toString())) {
return 5;
} else if (t.get().toString().equals(APPLIED.toString())) {
return 4;
} else if (t.get().toString().equals(INTERVIEWED.toString())) {
return 3;
} else if (t.get().toString().equals(REJECTED.toString())) {
return 2;
} else if (t.get().toString().equals(ACCEPTED.toString())) {
return 1;
} else {
return 0;
}
}

@Override
public String toString() {
return COMMAND_WORD;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.logic.sort;

import java.util.Comparator;

import seedu.address.model.application.Application;

public class InterviewSlotComparator implements Comparator<Application> {

public static final String COMMAND_WORD = "interview";

/**
* Compares the two application's interview slot field. Returns a negative integer, zero, or a positive integer as
* the first argument is less than, equal to, or greater than the second base on alphanumeric order.
* */
@Override
public int compare(Application o1, Application o2) {
return o1.getInterviewSlot().getValue().compareTo(o2.getInterviewSlot().getValue());
}

@Override
public String toString() {
return COMMAND_WORD;
}
}
24 changes: 24 additions & 0 deletions src/main/java/seedu/address/logic/sort/NameComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.logic.sort;

import java.util.Comparator;

import seedu.address.model.application.Application;

public class NameComparator implements Comparator<Application> {

public static final String COMMAND_WORD = "name";

/**
* Compares the two application's name field. Returns a negative integer, zero, or a positive integer as
* the first argument is less than, equal to, or greater than the second base on alphanumeric order.
* */
@Override
public int compare(Application o1, Application o2) {
return o1.getName().toString().compareTo(o2.getName().toString());
}

@Override
public String toString() {
return COMMAND_WORD;
}
}
53 changes: 53 additions & 0 deletions src/main/java/seedu/address/logic/sort/PriorityComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.sort;

import java.util.Comparator;
import java.util.Optional;

import seedu.address.model.application.Application;
import seedu.address.model.tag.PriorityTagType;
import seedu.address.model.tag.Tag;

public class PriorityComparator implements Comparator<Application> {

public static final String COMMAND_WORD = "priority";

private static final String PRIORITY_HIGH = "[" + PriorityTagType.HIGH + "]";
private static final String PRIORITY_LOW = "[" + PriorityTagType.LOW + "]";

/**
* Compares the two application's priority field. Returns a negative integer, zero, or a positive integer as
* the first argument is less than, equal to, or greater than the second base on alphanumeric order.
* The default order from ascending to descend is as follows HIGH, MEDIUM, LOW.
* An empty tag will be considered as the lowest ranking, ranked below LOW.
* */
@Override
public int compare(Application o1, Application o2) {
Optional<Tag> p1 = o1.getPriorityTag();
Optional<Tag> p2 = o2.getPriorityTag();

if (p1.isPresent() && p2.isEmpty()) {
return 1;
} else if (p1.isEmpty() && p2.isPresent()) {
return -1;
} else if (p1.isEmpty()) {
return o1.getName().toString().compareTo(o2.getName().toString());
} else {
if (p1.get().toString().equals(p2.get().toString())) {
return o1.getName().toString().compareTo(o2.getName().toString());
} else if (p1.get().toString().equals(PRIORITY_HIGH)) {
return 1;
} else if (p2.get().toString().equals(PRIORITY_HIGH)) {
return -1;
} else if (p2.get().toString().equals(PRIORITY_LOW)) {
return 1;
} else {
return -1;
}
}
}

@Override
public String toString() {
return COMMAND_WORD;
}
}
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/InternApplyMemory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.util.Objects.requireNonNull;

import java.util.Comparator;
import java.util.List;

import javafx.collections.ObservableList;
Expand Down Expand Up @@ -38,6 +39,14 @@ public InternApplyMemory(ReadOnlyInternApplyMemory toBeCopied) {
}

//// list overwrite operations
/**
* Replaces the order of the application list with {@code c} and order by {@code orderBy}.
* */
public void sortApplications(Comparator<Application> c, String orderBy) {
requireNonNull(c);
requireNonNull(orderBy);
this.applications.sort(c, orderBy);
}

/**
* Replaces the contents of the application list with {@code applications}.
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model;

import java.nio.file.Path;
import java.util.Comparator;
import java.util.function.Predicate;

import javafx.collections.ObservableList;
Expand All @@ -18,9 +19,7 @@ public interface Model {
/** {@code Predicate} that returns true if the application's interview slot falls with a week of the local date on
* the local machine.
*/
Predicate<Application> PREDICATE_SHOW_UPCOMING_APPLICATIONS_ONLY = application -> {
return application.isUpcomingInterview();
};
Predicate<Application> PREDICATE_SHOW_UPCOMING_APPLICATIONS_ONLY = Application::isUpcomingInterview;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
Expand Down Expand Up @@ -94,14 +93,18 @@ public interface Model {
*/
void updateFilteredApplicationList(Predicate<Application> predicate);

/** Returns an unmodifiable view of the upcoming application list */

/** Returns an unmodifiable view of the upcoming application list
*/
ObservableList<Application> getUpcomingApplicationList();

/**
* Updates the upcoming applications list using the given {@code predicate}
*/
void updateUpcomingApplicationList(Predicate<Application> predicate);

void sortApplications(Comparator<Application> c, String orderBy);

/** Returns a modifiable view of the list of summary boxes */
ObservableList<SummaryBox> getSummaryBoxList();

Expand Down
Loading

0 comments on commit 90bf994

Please sign in to comment.