Skip to content

Commit

Permalink
Implement UI for tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayushe committed Oct 28, 2019
1 parent 5bc2f4e commit 26227ae
Show file tree
Hide file tree
Showing 21 changed files with 398 additions and 108 deletions.
11 changes: 11 additions & 0 deletions src/main/java/seedu/algobase/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.nio.file.Path;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import seedu.algobase.commons.core.GuiSettings;
import seedu.algobase.logic.commands.CommandResult;
Expand Down Expand Up @@ -54,6 +56,15 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of tasks */
ObservableList<Task> getProcessedTaskList();

/** Returns the current plan. */
StringProperty getCurrentPlan();

/** Returns the number of solved tasks in current plan. */
IntegerProperty getCurrentSolvedCount();

/** Returns the number of solved tasks in current plan. */
IntegerProperty getCurrentUnsolvedCount();

/**
* Returns an unmodifiable view of the filtered list of find rules.
*/
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/seedu/algobase/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.nio.file.Path;
import java.util.logging.Logger;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import seedu.algobase.commons.core.GuiSettings;
import seedu.algobase.commons.core.LogsCenter;
Expand Down Expand Up @@ -72,6 +74,7 @@ public GuiState getGuiState() {
return model.getGuiState();
}

@Override
public ObservableList<Problem> getProcessedProblemList() {
return model.getFilteredProblemList();
}
Expand All @@ -91,6 +94,21 @@ public ObservableList<Task> getProcessedTaskList() {
return model.getCurrentTaskList();
}

@Override
public StringProperty getCurrentPlan() {
return model.getCurrentPlan();
}

@Override
public IntegerProperty getCurrentSolvedCount() {
return model.getCurrentSolvedCount();
}

@Override
public IntegerProperty getCurrentUnsolvedCount() {
return model.getCurrentUnsolvedCount();
}

@Override
public ObservableList<ProblemSearchRule> getProcessedFindRuleList() {
return model.getFilteredFindRuleList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public CommandResult execute(Model model) throws CommandException {
Plan editedPlan = createEditedPlan(planToEdit, editPlanDescriptor);

if (!planToEdit.isSamePlan(editedPlan) && model.hasPlan(editedPlan)) {
throw new CommandException(String.format(MESSAGE_DUPLICATE_PLAN, planToEdit.getPlanName()));
throw new CommandException(String.format(MESSAGE_DUPLICATE_PLAN, editedPlan.getPlanName()));
}

model.setPlan(planToEdit, editedPlan);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/algobase/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,4 @@ public static Format parseFileFormat(String format) throws ParseException {
throw new ParseException(e.toString());
}
}

}
17 changes: 17 additions & 0 deletions src/main/java/seedu/algobase/model/AlgoBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Iterator;
import java.util.List;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import seedu.algobase.commons.exceptions.IllegalValueException;
import seedu.algobase.model.commandhistory.CommandHistory;
Expand Down Expand Up @@ -235,6 +237,21 @@ public ObservableList<Task> getCurrentTaskList() {
return plans.getUnmodifiableObservableTaskList();
}

@Override
public StringProperty getCurrentPlan() {
return plans.getCurrentPlan();
}

@Override
public IntegerProperty getCurrentSolvedCount() {
return plans.getCurrentSolvedCount();
}

@Override
public IntegerProperty getCurrentUnsolvedCount() {
return plans.getCurrentUnsolvedCount();
}

//========== Find Rules =============================================================

@Override
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/seedu/algobase/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Set;
import java.util.function.Predicate;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import seedu.algobase.commons.core.GuiSettings;
import seedu.algobase.model.commandhistory.CommandHistory;
Expand Down Expand Up @@ -55,7 +57,7 @@ public interface Model {
*/
void setAlgoBaseFilePath(Path algoBaseFilePath);

//=========== GUI state =============================================================
//=========== UI ====================================================================

/**
* Returns the state of the GUI.
Expand Down Expand Up @@ -205,9 +207,26 @@ public interface Model {

//=========== Task ==================================================================

/** Returns an unmodifiable view of the filtered Plan list */
/**
* Returns an unmodifiable view of the filtered Plan list
*/
ObservableList<Task> getCurrentTaskList();

/**
* Returns the current {@code Plan}.
*/
StringProperty getCurrentPlan();

/**
* Returns the number of solved tasks in current plan.
*/
IntegerProperty getCurrentSolvedCount();

/**
* Returns the number of solved tasks in current plan.
*/
IntegerProperty getCurrentUnsolvedCount();

//========== Find Rules =============================================================

/**
Expand Down
39 changes: 24 additions & 15 deletions src/main/java/seedu/algobase/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.function.Predicate;
import java.util.logging.Logger;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
Expand Down Expand Up @@ -293,27 +295,20 @@ public ObservableList<Task> getCurrentTaskList() {
return filteredTasks;
}

//========== Rewind =================================================================

/**
* Returns an unmodifiable view of the list of {@code CommandHistory}.
*/
@Override
public ObservableList<CommandHistory> getCommandHistoryList() {
return filteredCommandHistories;
public StringProperty getCurrentPlan() {
return this.algoBase.getCurrentPlan();
}

/**
* Adds the given {@code CommandHistory}.
*
* @param history the added history
*/
@Override
public void addCommandHistory(CommandHistory history) {
requireNonNull(history);
algoBase.addCommandHistory(history);
public IntegerProperty getCurrentSolvedCount() {
return this.algoBase.getCurrentSolvedCount();
}

@Override
public IntegerProperty getCurrentUnsolvedCount() {
return this.algoBase.getCurrentUnsolvedCount();
}

//========== Find Rules =============================================================

Expand Down Expand Up @@ -346,6 +341,20 @@ public ObservableList<ProblemSearchRule> getFilteredFindRuleList() {
return filteredFindRules;
}


//========== Rewind =================================================================

@Override
public ObservableList<CommandHistory> getCommandHistoryList() {
return filteredCommandHistories;
}

@Override
public void addCommandHistory(CommandHistory history) {
requireNonNull(history);
algoBase.addCommandHistory(history);
}

//========== Util ===================================================================

@Override
Expand Down
29 changes: 27 additions & 2 deletions src/main/java/seedu/algobase/model/ReadOnlyAlgoBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.algobase.model;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.ObservableList;
import seedu.algobase.model.commandhistory.CommandHistory;
import seedu.algobase.model.plan.Plan;
Expand All @@ -18,6 +20,11 @@ public interface ReadOnlyAlgoBase {
* This list will not contain any duplicate problems.
*/
ObservableList<Problem> getProblemList();

/**
* Returns an unmodifiable view of the tags list.
* This list will not contain any duplicate tags.
*/
ObservableList<Tag> getTagList();

/**
Expand All @@ -31,10 +38,28 @@ public interface ReadOnlyAlgoBase {
ObservableList<Task> getCurrentTaskList();

/**
* Returns an unmodifiable view of the command history.
* Returns current plan name.
*/
ObservableList<CommandHistory> getCommandHistoryList();
StringProperty getCurrentPlan();

/**
* Returns the number of solved tasks in current plan.
*/
IntegerProperty getCurrentSolvedCount();

/**
* Returns the number of solved tasks in current plan.
*/
IntegerProperty getCurrentUnsolvedCount();

/**
* Returns an unmodifiable view of the find rule list.
*/
ObservableList<ProblemSearchRule> getFindRules();

/**
* Returns an unmodifiable view of the command history.
*/
ObservableList<CommandHistory> getCommandHistoryList();

}
28 changes: 28 additions & 0 deletions src/main/java/seedu/algobase/model/plan/Plan.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,34 @@ public static Plan updateTasks(Plan planToUpdate, Set<Task> taskSet) {
return new Plan(id, name, description, startDate, endDate, taskSet);
}

/**
* Returns number of solved tasks within plan.
* @return number of solved tasks.
*/
public int getSolvedTaskCount() {
int solvedCount = 0;
for (Task task : this.getTasks()) {
if (task.getIsSolved()) {
solvedCount++;
}
}
return solvedCount;
}

/**
* Returns number of unsolved tasks within plan.
* @return number of unsolved tasks.
*/
public int getUnsolvedTaskCount() {
int unsolvedCount = 0;
for (Task task : this.getTasks()) {
if (!task.getIsSolved()) {
unsolvedCount++;
}
}
return unsolvedCount;
}

public long getId() {
return id;
}
Expand Down
43 changes: 42 additions & 1 deletion src/main/java/seedu/algobase/model/plan/PlanList.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.util.Iterator;
import java.util.List;

import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.algobase.model.plan.exceptions.PlanNotFoundException;
Expand All @@ -26,12 +30,18 @@ public class PlanList implements Iterable<Plan> {
private final ObservableList<Task> internalTaskList = FXCollections.observableArrayList();
private final ObservableList<Task> internalUnmodifiableTaskList =
FXCollections.unmodifiableObservableList(internalTaskList);
private final StringProperty currentPlan = new SimpleStringProperty();
private final IntegerProperty solvedCount = new SimpleIntegerProperty();
private final IntegerProperty unsolvedCount = new SimpleIntegerProperty();

/**
* Adds a Plan to the list.
*/
public void add(Plan toAdd) {
requireNonNull(toAdd);
currentPlan.set(toAdd.getPlanName().fullName);
solvedCount.set(toAdd.getSolvedTaskCount());
unsolvedCount.set(toAdd.getUnsolvedTaskCount());
internalList.add(toAdd);
internalTaskList.setAll(toAdd.getTasks());
}
Expand All @@ -48,6 +58,9 @@ public void setPlan(Plan target, Plan updatedPlan) {
throw new PlanNotFoundException();
}

currentPlan.set(updatedPlan.getPlanName().fullName);
solvedCount.set(updatedPlan.getSolvedTaskCount());
unsolvedCount.set(updatedPlan.getUnsolvedTaskCount());
internalList.set(index, updatedPlan);
internalTaskList.setAll(updatedPlan.getTasks());
}
Expand All @@ -61,6 +74,9 @@ public void remove(Plan toRemove) {
if (!internalList.remove(toRemove)) {
throw new PlanNotFoundException();
}
currentPlan.set("");
solvedCount.set(0);
unsolvedCount.set(0);
internalTaskList.setAll();
}

Expand All @@ -73,7 +89,11 @@ public void setPlans(List<Plan> plans) {

if (plans.size() > 0) {
// Default to first plan in list
internalTaskList.setAll(plans.get(1).getTasks());
Plan plan = plans.get(0);
currentPlan.set(plan.getPlanName().fullName);
solvedCount.set(plan.getSolvedTaskCount());
unsolvedCount.set(plan.getUnsolvedTaskCount());
internalTaskList.setAll(plan.getTasks());
}
}

Expand All @@ -86,6 +106,27 @@ public void setPlans(PlanList replacement) {
setPlans(plans);
}

/**
* Returns the current {@code Plan}.
*/
public StringProperty getCurrentPlan() {
return currentPlan;
}

/**
* Returns the number of solved tasks in current plan.
*/
public IntegerProperty getCurrentSolvedCount() {
return solvedCount;
}

/**
* Returns the number of solved tasks in current plan.
*/
public IntegerProperty getCurrentUnsolvedCount() {
return unsolvedCount;
}

/**
* Returns the backing list as an unmodifiable {@code ObservableList}.
*/
Expand Down
Loading

0 comments on commit 26227ae

Please sign in to comment.