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

Commit

Permalink
Merge pull request #140 from joszx/branch-summary-bar
Browse files Browse the repository at this point in the history
Feature - Summary Bar
  • Loading branch information
lchokhoe authored Mar 30, 2022
2 parents c530f5a + 7c24855 commit 8c49622
Show file tree
Hide file tree
Showing 20 changed files with 531 additions and 48 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![Java CI](https://github.com/AY2122S2-CS2103T-T11-3/tp/actions/workflows/gradle.yml/badge.svg)](https://github.com/AY2122S2-CS2103T-T11-3/tp/actions/workflows/gradle.yml)
[![codecov](https://codecov.io/gh/AY2122S2-CS2103T-T11-3/tp/branch/master/graph/badge.svg?token=OPX1FSESUJ)](https://codecov.io/gh/AY2122S2-CS2103T-T11-3/tp)

![Ui](docs/images/Ui.png)
![Ui](docs/images/MainWindowUi.png)

* This is SoC InternApply <br>
*
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: InternApply

[![CI Status](https://github.com/se-edu/addressbook-level3/workflows/Java%20CI/badge.svg)](https://github.com/AY2122S2-CS2103T-T11-3/tp/actions)
[![codecov](https://codecov.io/gh/AY2122S2-CS2103T-T11-3/tp/branch/master/graph/badge.svg?token=OPX1FSESUJ)](https://codecov.io/gh/AY2122S2-CS2103T-T11-3/tp)
![Ui](images/Ui.png)
![Ui](images/MainWindowUi.png)

**InternApply is a desktop application for managing your internship application.** While it has a GUI, most of the user interactions happen using a CLI (Command Line Interface).

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.ReadOnlyInternApplyMemory;
import seedu.address.model.application.Application;
import seedu.address.model.summarybar.SummaryBox;

/**
* API of the Logic component
Expand Down Expand Up @@ -36,6 +37,9 @@ public interface Logic {
/** Returns an unmodifiable view of the upcoming list of applications */
ObservableList<Application> getUpcomingApplicationsList();

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

/**
* Returns the user prefs' intern apply file path.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyInternApplyMemory;
import seedu.address.model.application.Application;
import seedu.address.model.summarybar.SummaryBox;
import seedu.address.storage.Storage;

/**
Expand Down Expand Up @@ -44,6 +45,7 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
CommandResult commandResult;
Command command = internApplyParser.parseCommand(commandText);
commandResult = command.execute(model);
model.updateSummaryBoxList();

try {
storage.saveInternApply(model.getInternApplyMemory());
Expand All @@ -69,6 +71,11 @@ public ObservableList<Application> getUpcomingApplicationsList() {
return model.getUpcomingApplicationList();
}

@Override
public ObservableList<SummaryBox> getSummaryBoxList() {
return model.getSummaryBoxList();
}

@Override
public Path getInternApplyFilePath() {
return model.getInternApplyMemoryFilePath();
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.application.Application;
import seedu.address.model.summarybar.SummaryBox;

/**
* The API of the Model component.
Expand Down Expand Up @@ -102,5 +103,13 @@ public interface Model {
*/
void updateUpcomingApplicationList(Predicate<Application> predicate);

/** Sorts the list of applications */
void sortApplications(Comparator<Application> c, String orderBy);

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

/** Updates the list of summary boxes */
void updateSummaryBoxList();

}
17 changes: 16 additions & 1 deletion src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.application.Application;
import seedu.address.model.summarybar.SummaryBox;
import seedu.address.model.summarybar.SummaryList;

/**
* Represents the in-memory model of InternApply data.
Expand All @@ -24,6 +26,7 @@ public class ModelManager implements Model {
private final UserPrefs userPrefs;
private final FilteredList<Application> filteredApplications;
private final FilteredList<Application> upcomingApplications;
private final SummaryList summaryList;

/**
* Initializes a ModelManager with the given internApplyMemory and userPrefs.
Expand All @@ -37,9 +40,9 @@ public ModelManager(ReadOnlyInternApplyMemory internApplyMemory, ReadOnlyUserPre
this.internApplyMemory = new InternApplyMemory(internApplyMemory);
this.userPrefs = new UserPrefs(userPrefs);
filteredApplications = new FilteredList<>(this.internApplyMemory.getApplicationList());

// Placeholder value for upcomingApplications is a copy of filteredApplications
upcomingApplications = new FilteredList<>(this.internApplyMemory.getApplicationList());
summaryList = new SummaryList(this.internApplyMemory.getApplicationList());
}

public ModelManager() {
Expand Down Expand Up @@ -158,6 +161,18 @@ public void updateUpcomingApplicationList(Predicate<Application> predicate) {
upcomingApplications.setPredicate(predicate);
}

//============ Summary Box List Accessors ===============================================================

@Override
public ObservableList<SummaryBox> getSummaryBoxList() {
return summaryList.getObservableList();
}

@Override
public void updateSummaryBoxList() {
summaryList.update(internApplyMemory.getApplicationList());
}

@Override
public boolean equals(Object obj) {
// short circuit if same object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ public ObservableList<Application> asUnmodifiableObservableList() {
return internalUnmodifiableList;
}

/**
* Returns the size of the list.
*/
public int getSize() {
return internalList.size();
}

@Override
public Iterator<Application> iterator() {
return internalList.iterator();
Expand Down
62 changes: 62 additions & 0 deletions src/main/java/seedu/address/model/summarybar/SummaryBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package seedu.address.model.summarybar;

import java.util.Objects;
import java.util.Optional;

/**
* Represents a SummaryBox in InternApply.
*/
public abstract class SummaryBox {

private String name;
private int totalApplications;

/**
* Constructs a {@Code SummaryBox}.
*
* @param name Name of the SummaryBox.
* @param totalApplications Total number of applications in InternApply.
*/
public SummaryBox(String name, int totalApplications) {
this.name = name;
this.totalApplications = totalApplications;
}

public String getName() {
return name;
}

public int getTotalApplications() {
return totalApplications;
}

public void setTotalApplications(int totalApplications) {
this.totalApplications = totalApplications;
}

/**
* Gets the number of applications this SummaryBox is tracking.
* Returns Optional.empty() for SummaryBoxes that are not tracking any applications.
*
* @return The number of applications this SummaryBox is tracking.
*/
public abstract Optional<Integer> getCurrApplications();

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
SummaryBox that = (SummaryBox) o;
return totalApplications == that.totalApplications
&& Objects.equals(name, that.name);
}

@Override
public int hashCode() {
return Objects.hash(name, totalApplications);
}
}
106 changes: 106 additions & 0 deletions src/main/java/seedu/address/model/summarybar/SummaryList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package seedu.address.model.summarybar;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.address.model.application.Application;
import seedu.address.model.tag.Tag;

/**
* A list of SummaryBoxes that keeps track of their respective indices and tags.
*
*/
public class SummaryList {

public static final int TOTAL_APPLICATIONS_INDEX = 0;
public static final int TOTAL_HIGH_PRIORITY_APPLICATIONS_INDEX = 1;
public static final int TOTAL_MEDIUM_PRIORITY_APPLICATIONS_INDEX = 2;
public static final int TOTAL_LOW_PRIORITY_APPLICATIONS_INDEX = 3;
public static final int TOTAL_APPLIED_APPLICATIONS_INDEX = 4;
public static final int TOTAL_NOT_APPLIED_APPLICATIONS_INDEX = 5;

private static final int SUMMARY_INFO_SIZE = 6;

private static final String HIGH_PRIORITY_TAG = "HIGH";
private static final String MEDIUM_PRIORITY_TAG = "MEDIUM";
private static final String LOW_PRIORITY_TAG = "LOW";
private static final String APPLIED_STATUS_TAG = "APPLIED";
private static final String NOT_APPLIED_STATUS_TAG = "NOT_APPLIED";

private ObservableList<SummaryBox> summaryList;
private ObservableList<Application> applications;

/**
* Constructs a SummaryList from the given list of applications.
*
* @param applications The list of applications to get the relevant statistics for the SummaryBoxes to hold.
*/
public SummaryList(ObservableList<Application> applications) {
this.applications = applications;
summaryList = FXCollections.observableArrayList();
int totalApplications = getTotalApplications();

summaryList.add(new TotalApplicationsBox("Total", totalApplications));
summaryList.add(new TagSummaryBox("High Priority", getTotalTagApplications(HIGH_PRIORITY_TAG),
totalApplications));
summaryList.add(new TagSummaryBox("Medium Priority", getTotalTagApplications(MEDIUM_PRIORITY_TAG),
totalApplications));
summaryList.add(new TagSummaryBox("Low Priority", getTotalTagApplications(LOW_PRIORITY_TAG),
totalApplications));
summaryList.add(new TagSummaryBox("Applied", getTotalTagApplications(APPLIED_STATUS_TAG),
totalApplications));
summaryList.add(new TagSummaryBox("Not Applied", getTotalTagApplications(NOT_APPLIED_STATUS_TAG),
totalApplications));
}

public ObservableList<SummaryBox> getObservableList() {
return summaryList;
}

/**
* Updates the SummaryList by replacing each SummaryBox with a new one holding the updated statistics passed from
* the given list of applications.
*
* @param applications The given list of applications to get statistics from.
*/
public void update(ObservableList<Application> applications) {
this.applications = applications;
int[] summaryInfo = new int[SUMMARY_INFO_SIZE];
summaryInfo[TOTAL_APPLICATIONS_INDEX] = getTotalApplications();
summaryInfo[TOTAL_HIGH_PRIORITY_APPLICATIONS_INDEX] = getTotalTagApplications(HIGH_PRIORITY_TAG);
summaryInfo[TOTAL_MEDIUM_PRIORITY_APPLICATIONS_INDEX] = getTotalTagApplications(MEDIUM_PRIORITY_TAG);
summaryInfo[TOTAL_LOW_PRIORITY_APPLICATIONS_INDEX] = getTotalTagApplications(LOW_PRIORITY_TAG);
summaryInfo[TOTAL_APPLIED_APPLICATIONS_INDEX] = getTotalTagApplications(APPLIED_STATUS_TAG);
summaryInfo[TOTAL_NOT_APPLIED_APPLICATIONS_INDEX] = getTotalTagApplications(NOT_APPLIED_STATUS_TAG);

String totalApplicationsBoxName = summaryList.get(TOTAL_APPLICATIONS_INDEX).getName();
summaryList.set(0, new TotalApplicationsBox(totalApplicationsBoxName, getTotalApplications()));

for (int i = 1; i < summaryList.size(); i++) {
String currSummaryBoxName = summaryList.get(i).getName();
summaryList.set(i, new TagSummaryBox(currSummaryBoxName, summaryInfo[i], getTotalApplications()));
}
}

private int getTotalApplications() {
return applications.size();
}

/**
* Gets the number of applications with the given tagName.
*
* @param tagName The given tagName of the applications search for and count.
* @return
*/
private int getTotalTagApplications(String tagName) {
int count = 0;
Tag toFind = new Tag(tagName);
for (Application application : applications) {
if (application.getTags().contains(toFind)) {
count++;
}
}
return count;
}


}
49 changes: 49 additions & 0 deletions src/main/java/seedu/address/model/summarybar/TagSummaryBox.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package seedu.address.model.summarybar;

import java.util.Objects;
import java.util.Optional;

/**
* Represents a SummaryBox in InternApply that keeps track of the number of applications with a specified tagName.
*/
public class TagSummaryBox extends SummaryBox {
private int currApplications;

/**
* Constructs a TagSummaryBox.
*
* @param name Given name of the TagSummaryBox.
* @param currApplications Number of applications this TagSummaryBox is tracking.
* @param totalApplications Total number of applications in InternApply.
*/
TagSummaryBox(String name, int currApplications, int totalApplications) {
super(name, totalApplications);
this.currApplications = currApplications;
}

@Override
public Optional<Integer> getCurrApplications() {
return Optional.of(currApplications);
}


@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
TagSummaryBox that = (TagSummaryBox) o;
return currApplications == that.currApplications;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), currApplications);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.model.summarybar;

import java.util.Optional;

/**
* Represents a SummaryBox that tracks the total number of applications in InternApply.
*/
public class TotalApplicationsBox extends SummaryBox {

/**
* Constructs a TotalApplicationsBox.
*
* @param name The name of this TotalApplicationsBox.
* @param totalApplications Total number of applications in InternApply.
*/
public TotalApplicationsBox(String name, int totalApplications) {
super(name, totalApplications);
}

@Override
public Optional<Integer> getCurrApplications() {
return Optional.empty();
}
}
Loading

0 comments on commit 8c49622

Please sign in to comment.