forked from nus-cs2103-AY2223S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from yixiann/finalise-ui-tags-2
Add UI for tags
- Loading branch information
Showing
27 changed files
with
498 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/seedu/foodrem/logic/commands/tagcommands/TagCommandUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package seedu.foodrem.logic.commands.tagcommands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.foodrem.commons.core.index.Index; | ||
import seedu.foodrem.logic.commands.exceptions.CommandException; | ||
import seedu.foodrem.model.Model; | ||
import seedu.foodrem.model.item.Item; | ||
import seedu.foodrem.model.tag.Tag; | ||
|
||
/** | ||
* Handles validation for tag commands | ||
*/ | ||
public class TagCommandUtil { | ||
private TagCommandUtil() {} | ||
|
||
/** | ||
* Checks if a model has a tag and if the index is valid before getting the item. | ||
* | ||
* @param model the current model | ||
* @param tag the tag to be validated | ||
* @param index the index of the item | ||
*/ | ||
public static Item validateAndGetItem(Model model, Tag tag, Index index) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (!model.hasTag(tag)) { | ||
throw new CommandException("This tag does not exist"); | ||
} | ||
|
||
List<Item> lastShownList = model.getCurrentList(); | ||
if (index.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException("The item index does not exist"); | ||
} | ||
|
||
return lastShownList.get(index.getZeroBased()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package seedu.foodrem.viewmodels; | ||
|
||
import java.util.Objects; | ||
|
||
import seedu.foodrem.model.tag.Tag; | ||
|
||
/** | ||
* A view model for generating a view with tags as well as two messages. | ||
* @author Tan Yi Xian | ||
*/ | ||
public class FilterByTag { | ||
private final Tag tag; | ||
private final String primaryMessage; | ||
private final String secondaryMessage; | ||
|
||
/** | ||
* Creates a view model containing the message and the tags to rename. | ||
* @param tag the tag. | ||
* @param primaryMessage the message to be displayed above the tags. | ||
* @param secondaryMessage the message to displayed under the tags. | ||
*/ | ||
public FilterByTag(Tag tag, String primaryMessage, String secondaryMessage) { | ||
this.tag = tag; | ||
this.primaryMessage = primaryMessage; | ||
this.secondaryMessage = secondaryMessage; | ||
} | ||
|
||
public Tag getTag() { | ||
return tag; | ||
} | ||
|
||
public String getPrimaryMessage() { | ||
return primaryMessage; | ||
} | ||
|
||
public String getSecondaryMessage() { | ||
return secondaryMessage; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return this == other | ||
|| (other instanceof FilterByTag | ||
&& tag.equals(((FilterByTag) other).tag) | ||
&& primaryMessage.equals(((FilterByTag) other).primaryMessage) | ||
&& secondaryMessage.equals(((FilterByTag) other).secondaryMessage)); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(tag, primaryMessage, secondaryMessage); | ||
} | ||
} |
Oops, something went wrong.