Skip to content

Commit

Permalink
Add resource info panel (#136)
Browse files Browse the repository at this point in the history
* Add basic listener interface for selection events

* Add regime and schedule info panels

* Add RegimeInfoPanel

* Update RegimeInfoPanel fxml

* Add ScheduleInfoPanel

* Change initial displayed list to schedule list

* Change basic data and remove unused methods

* Remove NameContainsKeywordPredicate and related items

* Removed imports

* Add suggestion panel listener to display exercises

* Add no background logo

* Update user guide for resolve and schedule

* Update logo and resolve window text

* Fix minor bugs in undo redo and schedule command

* Fix bug for resolve window
  • Loading branch information
t-cheepeng authored Oct 30, 2019
1 parent 3bdf789 commit 5b3cf70
Show file tree
Hide file tree
Showing 50 changed files with 453 additions and 489 deletions.
51 changes: 0 additions & 51 deletions data/exercisedatabase.json

This file was deleted.

6 changes: 5 additions & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ Example:

* `schedule n/cardio d/19/9/2019`

Schedules the regime called `cardio` on the date `19/19/2019`. If there are no other regimes scheduled on `19/19/2019` then the command is successful. Otherwise, you will be prompted to resolve the scheduling conflict.

==== Completes a schedule regime

Once a scheduled regime is completed, users can add that regime to the exercise tracker. The schedule is then deleted from the scheduling list.
Expand All @@ -346,6 +348,7 @@ Example:

* `schedule i/2`

Completes all the exercises that are in the schedule at index `2`. All the exercises will be added to the exercise list and the schedule at index `2` is deleted.
[[resolve]]
=== Resolving scheduling conflicts: `resolve`

Expand All @@ -359,6 +362,7 @@ Example:

* `resolve n/cardio`

Takes the scheduled regime named `cardio` and schedule at the conflicting date.

==== Taking some exercises from some regime
Takes some exercises from the scheduled regime and some from the conflicting regime to make a brand new regime. The new regime that is a result of the combination will be added to the user’s collection and scheduled at the date of conflict. This new regime will also be added to the user’s collection of regimes
Expand All @@ -377,7 +381,7 @@ Format: `resolve n/REGIME_NAME [i/INDEX_OF_EXERCISE_IN_SCHEDULED]... [r/INDEX_OF

Example:

* `resolve d/date n/cardios i/1 i/2 i/3 r/4 r/2`
* `resolve n/cardios i/1 i/2 i/3 r/4 r/2`

Takes exercise 1, 2, 3 from scheduled regime and exercise 2, 4 from conflicting regime and adds them to a new regime called cardios

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_INDEX;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.exercise.logic.parser.predicate.PredicateUtil.PREDICATE_SHOW_ALL_REGIMES;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -105,7 +104,6 @@ private CommandResult addExercisesToExistingRegime(Model model) throws CommandEx
addToEventPayloadForEditRegime(originalRegime, editedRegime);

model.setRegime(originalRegime, editedRegime);
model.updateFilteredRegimeList(PREDICATE_SHOW_ALL_REGIMES);
return new CommandResult(MESSAGE_SUCCESS_ADD_EXERCISE_TO_REGIME, ListResourceType.REGIME);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_INDEX;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.exercise.logic.parser.predicate.PredicateUtil.PREDICATE_SHOW_ALL_REGIMES;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -106,7 +105,6 @@ private CommandResult deleteExercisesFromRegime(Regime originalRegime, Model mod

addToEventPayloadForEditRegime(originalRegime, editedRegime);
model.setRegime(originalRegime, editedRegime);
model.updateFilteredRegimeList(PREDICATE_SHOW_ALL_REGIMES);
return new CommandResult(String.format(MESSAGE_DELETE_EXERCISE_IN_REGIME_SUCCESS, editedRegime),
ListResourceType.REGIME);
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/exercise/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_QUANTITY;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_UNIT;
import static seedu.exercise.logic.parser.predicate.PredicateUtil.PREDICATE_SHOW_ALL_EXERCISES;

import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -100,7 +99,6 @@ public CommandResult execute(Model model) throws CommandException {
addToEventPayload(exerciseToEdit, editedExercise);
model.setExercise(exerciseToEdit, editedExercise);
EventHistory.getInstance().addCommandToUndoStack(this);
model.updateFilteredExerciseList(PREDICATE_SHOW_ALL_EXERCISES);
model.updateStatistic();
return new CommandResult(String.format(MESSAGE_EDIT_EXERCISE_SUCCESS, editedExercise),
ListResourceType.EXERCISE);
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/exercise/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Objects.requireNonNull;
import static seedu.exercise.logic.parser.CliSyntax.PREFIX_CATEGORY;
import static seedu.exercise.logic.parser.predicate.PredicateUtil.PREDICATE_SHOW_ALL_EXERCISES;

import seedu.exercise.model.Model;
import seedu.exercise.ui.ListResourceType;
Expand Down Expand Up @@ -31,9 +30,8 @@ public ListCommand(ListResourceType listResourceType) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredExerciseList(PREDICATE_SHOW_ALL_EXERCISES);
return new CommandResult(String.format(MESSAGE_SUCCESS, listResourceType.toString().toLowerCase()),
ListResourceType.EXERCISE);
listResourceType);
}

}
22 changes: 21 additions & 1 deletion src/main/java/seedu/exercise/logic/commands/RedoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import static java.util.Objects.requireNonNull;

import seedu.exercise.logic.commands.events.AddExerciseEvent;
import seedu.exercise.logic.commands.events.AddRegimeEvent;
import seedu.exercise.logic.commands.events.ClearEvent;
import seedu.exercise.logic.commands.events.DeleteExerciseEvent;
import seedu.exercise.logic.commands.events.DeleteRegimeEvent;
import seedu.exercise.logic.commands.events.EditEvent;
import seedu.exercise.logic.commands.events.EditRegimeEvent;
import seedu.exercise.logic.commands.events.Event;
import seedu.exercise.logic.commands.events.EventHistory;
import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.ui.ListResourceType;

/**
* Undoes the last executed command.
Expand All @@ -28,7 +36,19 @@ public CommandResult execute(Model model) throws CommandException {

Event eventToRedo = eventHistory.redo(model);
model.updateStatistic();


//TODO Refactor this out for v1.4!!!!!!!!!!!!!!!!!! I want to puke looking at this code.
ListResourceType type = ListResourceType.NULL;
if (eventToRedo instanceof AddExerciseEvent || eventToRedo instanceof DeleteExerciseEvent
|| eventToRedo instanceof EditEvent || eventToRedo instanceof ClearEvent) {
type = ListResourceType.EXERCISE;
} else if (eventToRedo instanceof AddRegimeEvent || eventToRedo instanceof DeleteRegimeEvent
|| eventToRedo instanceof EditRegimeEvent) {
type = ListResourceType.REGIME;
}

return new CommandResult(
String.format(MESSAGE_SUCCESS, eventToRedo));
String.format(MESSAGE_SUCCESS, eventToRedo), type);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.exercise.model.conflict.Conflict;
import seedu.exercise.model.property.Name;
import seedu.exercise.model.resource.Regime;
import seedu.exercise.ui.ListResourceType;

/**
* Represents a Resolve Command that resolves scheduling conflicts.
Expand Down Expand Up @@ -76,7 +77,7 @@ public CommandResult execute(Model model) throws CommandException {
resolveConflict(model);
return new CommandResult(String.format(MESSAGE_SUCCESS,
conflict.getScheduledName(),
conflict.getConflictedName()));
conflict.getConflictedName()), ListResourceType.SCHEDULE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CommandResult execute(Model model) throws CommandException {
completeSchedule(model);

return new CommandResult(String.format(MESSAGE_SUCCESS, Integer.toString(index.getOneBased())),
ListResourceType.SCHEDULE);
ListResourceType.EXERCISE);
}

@Override
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/seedu/exercise/logic/commands/UndoCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import static java.util.Objects.requireNonNull;

import seedu.exercise.logic.commands.events.AddExerciseEvent;
import seedu.exercise.logic.commands.events.AddRegimeEvent;
import seedu.exercise.logic.commands.events.ClearEvent;
import seedu.exercise.logic.commands.events.DeleteExerciseEvent;
import seedu.exercise.logic.commands.events.DeleteRegimeEvent;
import seedu.exercise.logic.commands.events.EditEvent;
import seedu.exercise.logic.commands.events.EditRegimeEvent;
import seedu.exercise.logic.commands.events.Event;
import seedu.exercise.logic.commands.events.EventHistory;
import seedu.exercise.logic.commands.exceptions.CommandException;
import seedu.exercise.model.Model;
import seedu.exercise.ui.ListResourceType;

/**
* Undoes the last executed command.
Expand All @@ -30,6 +38,17 @@ public CommandResult execute(Model model) throws CommandException {

Event eventToUndo = eventHistory.undo(model);
model.updateStatistic();
return new CommandResult(String.format(MESSAGE_SUCCESS, eventToUndo));

//TODO Refactor this out for v1.4!!!!!!!!!!!!!!!!!! I want to puke looking at this code.
ListResourceType type = ListResourceType.NULL;
if (eventToUndo instanceof AddExerciseEvent || eventToUndo instanceof DeleteExerciseEvent
|| eventToUndo instanceof EditEvent || eventToUndo instanceof ClearEvent) {
type = ListResourceType.EXERCISE;
} else if (eventToUndo instanceof AddRegimeEvent || eventToUndo instanceof DeleteRegimeEvent
|| eventToUndo instanceof EditRegimeEvent) {
type = ListResourceType.REGIME;
}

return new CommandResult(String.format(MESSAGE_SUCCESS, eventToUndo), type);
}
}
14 changes: 0 additions & 14 deletions src/main/java/seedu/exercise/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,6 @@ public interface Model {
*/
ObservableList<Schedule> getFilteredScheduleList();

/**
* Updates the filter of the filtered exercise list to filter by the given {@code predicate}.
*
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredExerciseList(Predicate<Exercise> predicate);

/**
* Returns the user prefs' regime book file path.
*/
Expand Down Expand Up @@ -164,13 +157,6 @@ public interface Model {
*/
int getRegimeIndex(Regime regime);

/**
* Updates the filter of the filtered exercise list to filter by the given {@code predicate}.
*
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredRegimeList(Predicate<Regime> predicate);

/**
* Returns true if another schedule has been scheduled on the same date as {@code schedule}.
*/
Expand Down
13 changes: 1 addition & 12 deletions src/main/java/seedu/exercise/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ public void deleteExercise(Exercise target) {
*/
public void addExercise(Exercise exercise) {
exerciseBook.addResource(exercise);
updateFilteredExerciseList(PREDICATE_SHOW_ALL_EXERCISES);
}

public void setExercise(Exercise target, Exercise editedExercise) {
Expand Down Expand Up @@ -261,8 +260,8 @@ public void resolveConflict(Name regimeName, List<Index> indexFromSchedule, List
UniqueResourceList<Exercise> resolvedExercises =
getResolvedExerciseList(indexFromSchedule, indexFromConflict);
Schedule resolvedSchedule = getResolvedSchedule(regimeName, resolvedExercises);
addResolvedSchedule(resolvedSchedule);
addCombinedRegime(resolvedSchedule.getRegime());
addResolvedSchedule(resolvedSchedule);
}
}

Expand Down Expand Up @@ -292,11 +291,6 @@ public ObservableList<Exercise> getFilteredExerciseList() {
return filteredExercises;
}

@Override
public void updateFilteredExerciseList(Predicate<Exercise> predicate) {
requireNonNull(predicate);
filteredExercises.setPredicate(predicate);
}

//=========== Filtered Regime List Accessors ===============================================================

Expand All @@ -308,11 +302,6 @@ public ObservableList<Regime> getFilteredRegimeList() {
return filteredRegimes;
}

@Override
public void updateFilteredRegimeList(Predicate<Regime> predicate) {
requireNonNull(predicate);
filteredRegimes.setPredicate(predicate);
}

//=========== Filtered Schedule List Accessors ===============================================================

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/exercise/model/ReadOnlyResourceBook.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ public boolean equals(Object other) {
public int hashCode() {
return resources.hashCode();
}


@Override
public String toString() {
return "" + resources.asUnmodifiableObservableList().size() + " exercises.";
}
}

This file was deleted.

8 changes: 8 additions & 0 deletions src/main/java/seedu/exercise/model/resource/Regime.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ public Regime deepCopy() {
return new Regime(newName, newRegimeExercises);
}

public int getTotalCalorieCount() {
int count = 0;
for (Exercise e : regimeExercises) {
count += Integer.parseInt(e.getCalories().value);
}
return count;
}

/**
* Returns true if both regimes have the same name.
*/
Expand Down
Loading

0 comments on commit 5b3cf70

Please sign in to comment.