From d770ca6e6acbcf0f4c4479760b8a28fd49083cbb Mon Sep 17 00:00:00 2001 From: Lim Yu Yang <60053610+IronBiscuit@users.noreply.github.com> Date: Sun, 4 Oct 2020 15:21:00 +0800 Subject: [PATCH] Revert "List Inventory" --- docs/AboutUs.md | 4 +- docs/DeveloperGuide.md | 20 +++--- src/main/java/nustorage/logic/Logic.java | 3 - .../java/nustorage/logic/LogicManager.java | 5 -- .../logic/commands/AddInventoryCommand.java | 1 + .../logic/commands/CommandResult.java | 1 - .../logic/commands/ListInventoryCommand.java | 27 ------- .../logic/parser/AddressBookParser.java | 3 - src/main/java/nustorage/model/Model.java | 5 -- .../java/nustorage/model/ModelManager.java | 16 ----- .../java/nustorage/model/item/Inventory.java | 32 +++------ .../model/item/ReadOnlyInventory.java | 16 ----- .../java/nustorage/ui/InventoryPanel.java | 46 ------------ .../nustorage/ui/InventoryRecordCard.java | 70 ------------------- src/main/java/nustorage/ui/MainWindow.java | 18 ----- src/main/java/nustorage/ui/UiManager.java | 2 +- src/main/resources/view/InventoryCard.fxml | 34 --------- src/main/resources/view/InventoryPanel.fxml | 8 --- src/main/resources/view/MainWindow.fxml | 2 +- .../logic/commands/AddCommandTest.java | 12 ---- 20 files changed, 23 insertions(+), 302 deletions(-) delete mode 100644 src/main/java/nustorage/logic/commands/ListInventoryCommand.java delete mode 100644 src/main/java/nustorage/model/item/ReadOnlyInventory.java delete mode 100644 src/main/java/nustorage/ui/InventoryPanel.java delete mode 100644 src/main/java/nustorage/ui/InventoryRecordCard.java delete mode 100644 src/main/resources/view/InventoryCard.fxml delete mode 100644 src/main/resources/view/InventoryPanel.fxml diff --git a/docs/AboutUs.md b/docs/AboutUs.md index 48d61c620f7..0c5c45f0c99 100644 --- a/docs/AboutUs.md +++ b/docs/AboutUs.md @@ -3,7 +3,7 @@ layout: page title: About Us --- -We are a team based in the [School of Computing, National University of Singapore](http://www.comp.nus.edu.sg), formed +We are a team based in the [School of Computing, National University of Singapore](http://www.comp.nus.edu.sg), formed to fulfill the team project requirements of [CS2103T](https://nusmods.com/modules/CS2103T/software-engineering) You can reach us at the email `seer[at]comp.nus.edu.sg` @@ -64,7 +64,7 @@ You can reach us at the email `seer[at]comp.nus.edu.sg` -[[github](https://github.com/howtoosee)] +[[github](https://github.com/howtoosee)] [[portfolio](team/xihao.md)] * Role: Developer diff --git a/docs/DeveloperGuide.md b/docs/DeveloperGuide.md index a29b30efe2a..152dd878649 100644 --- a/docs/DeveloperGuide.md +++ b/docs/DeveloperGuide.md @@ -264,7 +264,7 @@ Priorities: High (must have) - `* * *`, Medium (nice to have) - `* *`, Low (unli ### Use cases For all use cases (unless specified otherwise): - The **System** is `NUStorage` -- The **Actor** is `User` +- The **Actor** is `User` **Use case: Add an inventory item** @@ -277,7 +277,7 @@ For all use cases (unless specified otherwise): 4. NUStorage adds the item to the list Use case ends. - + **Use case: Remove an inventory item** **MSS** @@ -330,7 +330,7 @@ For all use cases (unless specified otherwise): * 3a1. NUStorage shows an error message. Use case resumes at step 2. - + **Use case: List finance/inventory records** **MSS** @@ -341,7 +341,7 @@ For all use cases (unless specified otherwise): * 2a. The list is empty. Use case ends. - + **Use case: Save finance / inventory records** **MSS** @@ -356,7 +356,7 @@ For all use cases (unless specified otherwise): 1. User requests to exit NUStorage 2. NUStorage saves both finance and inventory records and shows a goodbye message 3. NUStorage terminates after 1.5 seconds - + ### Non-Functional Requirements @@ -371,7 +371,7 @@ For all use cases (unless specified otherwise): * **Mainstream OS**: Windows, Linux, Unix, OS-X * **Inventory**: An item that a user wishes to record. An inventory item can refer to any existing object -* **Finances**: A record that allows a user to monitor his earnings and spending. +* **Finances**: A record that allows a user to monitor his earnings and spending. -------------------------------------------------------------------------------------------------------------------- @@ -403,7 +403,7 @@ testers are expected to do more *exploratory* testing. 1. Shutting Down 1. If you would like to save your records prior to shutting down, remember to enter the `save` command - + 1. Close the app by simply clicking on the close button or enter the `exit` command. ### Deleting a record @@ -426,13 +426,13 @@ testers are expected to do more *exploratory* testing. 1. Adding a financial/inventory record. 1. Prerequisites: None - + 1. Test case: `add_inventory i/MacBook n/10`
Expected: An inventory item 'MacBook' is added with the quantity of 10. Details of the added record shown in the status message. - + 1. Test case: `add_finance op/in amt/1000` Expected: A finance record of an increase by $1000.00 is added. Details of the added record shown in status message. - + 1. Other incorrect add commands to try: `add`, `add_record`, `add_inventory i/MacBook`
Expected: No record is added. Error details shown in the status message. diff --git a/src/main/java/nustorage/logic/Logic.java b/src/main/java/nustorage/logic/Logic.java index 599f2898e76..bfb44c6dee9 100644 --- a/src/main/java/nustorage/logic/Logic.java +++ b/src/main/java/nustorage/logic/Logic.java @@ -9,7 +9,6 @@ import nustorage.logic.parser.exceptions.ParseException; import nustorage.model.ReadOnlyAddressBook; import nustorage.model.person.Person; -import nustorage.model.record.InventoryRecord; /** * API of the Logic component @@ -34,8 +33,6 @@ public interface Logic { /** Returns an unmodifiable view of the filtered list of persons */ ObservableList getFilteredPersonList(); - ObservableList getFilteredInventory(); - /** * Returns the user prefs' address book file path. */ diff --git a/src/main/java/nustorage/logic/LogicManager.java b/src/main/java/nustorage/logic/LogicManager.java index 3766c1b1259..14dfc160cae 100644 --- a/src/main/java/nustorage/logic/LogicManager.java +++ b/src/main/java/nustorage/logic/LogicManager.java @@ -15,7 +15,6 @@ import nustorage.model.Model; import nustorage.model.ReadOnlyAddressBook; import nustorage.model.person.Person; -import nustorage.model.record.InventoryRecord; import nustorage.storage.Storage; /** @@ -65,10 +64,6 @@ public ObservableList getFilteredPersonList() { return model.getFilteredPersonList(); } - public ObservableList getFilteredInventory() { - return model.getFilteredInventory(); - } - @Override public Path getAddressBookFilePath() { return model.getAddressBookFilePath(); diff --git a/src/main/java/nustorage/logic/commands/AddInventoryCommand.java b/src/main/java/nustorage/logic/commands/AddInventoryCommand.java index 29e155e2f3c..4d86036462f 100644 --- a/src/main/java/nustorage/logic/commands/AddInventoryCommand.java +++ b/src/main/java/nustorage/logic/commands/AddInventoryCommand.java @@ -33,6 +33,7 @@ public AddInventoryCommand(InventoryRecord newInventoryRecord, FinanceRecord new @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); + model.addInventoryRecord(newInventoryRecord); model.addFinanceRecord(newFinanceRecord); return new CommandResult(String.format(MESSAGE_SUCCESS, newInventoryRecord)); diff --git a/src/main/java/nustorage/logic/commands/CommandResult.java b/src/main/java/nustorage/logic/commands/CommandResult.java index 955fc75a2e8..e8fd7f9a450 100644 --- a/src/main/java/nustorage/logic/commands/CommandResult.java +++ b/src/main/java/nustorage/logic/commands/CommandResult.java @@ -17,7 +17,6 @@ public class CommandResult { /** The application should exit. */ private final boolean exit; - /** * Constructs a {@code CommandResult} with the specified fields. */ diff --git a/src/main/java/nustorage/logic/commands/ListInventoryCommand.java b/src/main/java/nustorage/logic/commands/ListInventoryCommand.java deleted file mode 100644 index 1f5449f3b7e..00000000000 --- a/src/main/java/nustorage/logic/commands/ListInventoryCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package nustorage.logic.commands; - -import static java.util.Objects.requireNonNull; -import static nustorage.model.Model.PREDICATE_SHOW_ALL_INVENTORY; - -import javafx.collections.ObservableList; -import nustorage.model.Model; -import nustorage.model.record.InventoryRecord; - -/** - * Lists all persons in the address book to the user. - */ -public class ListInventoryCommand extends Command { - - public static final String COMMAND_WORD = "list_inventory"; - - public static final String MESSAGE_SUCCESS = "Listed all inventory items!"; - - - @Override - public CommandResult execute(Model model) { - requireNonNull(model); - model.updateFilteredInventoryList(PREDICATE_SHOW_ALL_INVENTORY); - ObservableList inventory = model.getFilteredInventory(); - return new CommandResult(MESSAGE_SUCCESS); - } -} diff --git a/src/main/java/nustorage/logic/parser/AddressBookParser.java b/src/main/java/nustorage/logic/parser/AddressBookParser.java index 472a38cd54e..85c3b36b7ff 100644 --- a/src/main/java/nustorage/logic/parser/AddressBookParser.java +++ b/src/main/java/nustorage/logic/parser/AddressBookParser.java @@ -18,7 +18,6 @@ import nustorage.logic.commands.FindCommand; import nustorage.logic.commands.HelpCommand; import nustorage.logic.commands.ListCommand; -import nustorage.logic.commands.ListInventoryCommand; import nustorage.logic.commands.ListFinanceRecordsCommand; import nustorage.logic.parser.exceptions.ParseException; @@ -48,8 +47,6 @@ public Command parseCommand(String userInput) throws ParseException { final String commandWord = matcher.group("commandWord"); final String arguments = matcher.group("arguments"); switch (commandWord) { - case ListInventoryCommand.COMMAND_WORD: - return new ListInventoryCommand(); case AddInventoryCommand.COMMAND_WORD: return new AddInventoryCommandParser().parse(arguments); diff --git a/src/main/java/nustorage/model/Model.java b/src/main/java/nustorage/model/Model.java index 588c4de07b0..51188c56de2 100644 --- a/src/main/java/nustorage/model/Model.java +++ b/src/main/java/nustorage/model/Model.java @@ -18,7 +18,6 @@ public interface Model { /** {@code Predicate} that always evaluate to true */ Predicate PREDICATE_SHOW_ALL_PERSONS = unused -> true; - Predicate PREDICATE_SHOW_ALL_INVENTORY = unused -> true; /** * Replaces user prefs data with the data in {@code userPrefs}. @@ -93,13 +92,9 @@ public interface Model { /** Returns an unmodifiable view of the filtered person list */ ObservableList getFilteredPersonList(); - ObservableList getFilteredInventory(); - /** * Updates the filter of the filtered person list to filter by the given {@code predicate}. * @throws NullPointerException if {@code predicate} is null. */ void updateFilteredPersonList(Predicate predicate); - - void updateFilteredInventoryList(Predicate predicate); } diff --git a/src/main/java/nustorage/model/ModelManager.java b/src/main/java/nustorage/model/ModelManager.java index 8938102cc60..91a7971a4e0 100644 --- a/src/main/java/nustorage/model/ModelManager.java +++ b/src/main/java/nustorage/model/ModelManager.java @@ -31,7 +31,6 @@ public class ModelManager implements Model { private final AddressBook addressBook; private final UserPrefs userPrefs; private final FilteredList filteredPersons; - private final FilteredList filteredInventory; /** * Initializes a ModelManager with the given addressBook and userPrefs. @@ -43,7 +42,6 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs); this.inventory = new Inventory(); - filteredInventory = new FilteredList<>(this.inventory.asUnmodifiableObservableList()); this.financeAccount = new FinanceAccount(); this.addressBook = new AddressBook(addressBook); this.userPrefs = new UserPrefs(userPrefs); @@ -95,19 +93,6 @@ public void addInventoryRecord(InventoryRecord newRecord) { inventory.addInventoryRecord(newRecord); } - public ObservableList getFilteredInventory() { - return filteredInventory; - } - - /** - * Applies a predicate to the Inventory and returns those that pass it. - * @param predicate the predicate used to filter Inventory - */ - public void updateFilteredInventoryList(Predicate predicate) { - requireNonNull(predicate); - filteredInventory.setPredicate(predicate); - } - //=========== FinanceAccount ================================================================================ @Override @@ -178,7 +163,6 @@ public void updateFilteredPersonList(Predicate predicate) { filteredPersons.setPredicate(predicate); } - @Override public boolean equals(Object obj) { // short circuit if same object diff --git a/src/main/java/nustorage/model/item/Inventory.java b/src/main/java/nustorage/model/item/Inventory.java index 817faa13288..2518b69d2be 100644 --- a/src/main/java/nustorage/model/item/Inventory.java +++ b/src/main/java/nustorage/model/item/Inventory.java @@ -1,26 +1,23 @@ package nustorage.model.item; -import java.util.Iterator; +import java.util.ArrayList; +import java.util.List; import java.util.stream.Collectors; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import nustorage.model.record.InventoryRecord; /** * Class to store different InventoryRecords. */ -public class Inventory implements Iterable, ReadOnlyInventory { +public class Inventory { - private final ObservableList internalList = FXCollections.observableArrayList(); - private final ObservableList internalUnmodifiableList = - FXCollections.unmodifiableObservableList(internalList); + private final List inventory; /** * Constructs inventory object to hold InventoryRecords. */ public Inventory() { - + this.inventory = new ArrayList<>(); } /** @@ -28,7 +25,7 @@ public Inventory() { * @param inventoryRecord to be added. */ public void addInventoryRecord(InventoryRecord inventoryRecord) { - internalList.add(inventoryRecord); + inventory.add(inventoryRecord); } /** @@ -36,25 +33,12 @@ public void addInventoryRecord(InventoryRecord inventoryRecord) { * @param inventoryRecord to be removed. */ public void deleteInventoryRecord(InventoryRecord inventoryRecord) { - internalList.remove(inventoryRecord); - } - - public ObservableList getInventoryList() { - return internalList; - } - - public ObservableList asUnmodifiableObservableList() { - return internalUnmodifiableList; - } - - @Override - public Iterator iterator() { - return internalList.iterator(); + inventory.remove(inventoryRecord); } @Override public String toString() { - return internalList.stream() + return inventory.stream() .map(InventoryRecord::toString) .collect(Collectors.joining("\n")); } diff --git a/src/main/java/nustorage/model/item/ReadOnlyInventory.java b/src/main/java/nustorage/model/item/ReadOnlyInventory.java deleted file mode 100644 index 2dc56590dc5..00000000000 --- a/src/main/java/nustorage/model/item/ReadOnlyInventory.java +++ /dev/null @@ -1,16 +0,0 @@ -package nustorage.model.item; - -import javafx.collections.ObservableList; -import nustorage.model.record.InventoryRecord; - -/** - * Unmodifiable view of an address book - */ -public interface ReadOnlyInventory { - - /** - * Returns an unmodifiable view of the persons list. - * This list will not contain any duplicate persons. - */ - ObservableList asUnmodifiableObservableList(); -} diff --git a/src/main/java/nustorage/ui/InventoryPanel.java b/src/main/java/nustorage/ui/InventoryPanel.java deleted file mode 100644 index 605be23841a..00000000000 --- a/src/main/java/nustorage/ui/InventoryPanel.java +++ /dev/null @@ -1,46 +0,0 @@ -package nustorage.ui; - -import java.util.logging.Logger; - -import javafx.collections.ObservableList; -import javafx.fxml.FXML; -import javafx.scene.control.ListCell; -import javafx.scene.control.ListView; -import javafx.scene.layout.Region; -import nustorage.commons.core.LogsCenter; -import nustorage.model.record.InventoryRecord; - -public class InventoryPanel extends UiPart { - private static final String FXML = "InventoryPanel.fxml"; - private final Logger logger = LogsCenter.getLogger(InventoryPanel.class); - - @FXML - private ListView inventoryView; - - /** - * Creates a {@code PersonListPanel} with the given {@code ObservableList}. - */ - public InventoryPanel(ObservableList recordList) { - super(FXML); - inventoryView.setItems(recordList); - inventoryView.setCellFactory(listView -> new InventoryPanel.InventoryViewCell()); - } - - /** - * Custom {@code ListCell} that displays the graphics of a {@code Person} using a {@code PersonCard}. - */ - class InventoryViewCell extends ListCell { - @Override - protected void updateItem(InventoryRecord record, boolean empty) { - super.updateItem(record, empty); - - if (empty || record == null) { - setGraphic(null); - setText(null); - } else { - setGraphic(new InventoryRecordCard(record, getIndex() + 1).getRoot()); - } - } - } - -} diff --git a/src/main/java/nustorage/ui/InventoryRecordCard.java b/src/main/java/nustorage/ui/InventoryRecordCard.java deleted file mode 100644 index ca8ce6f3738..00000000000 --- a/src/main/java/nustorage/ui/InventoryRecordCard.java +++ /dev/null @@ -1,70 +0,0 @@ -package nustorage.ui; - - -import javafx.fxml.FXML; -import javafx.scene.control.Label; -import javafx.scene.layout.HBox; -import javafx.scene.layout.Region; -import nustorage.model.record.InventoryRecord; - -/** - * An UI component that displays information of a {@code Person}. - */ -public class InventoryRecordCard extends UiPart { - - private static final String FXML = "InventoryCard.fxml"; - - /** - * Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX. - * As a consequence, UI elements' variable names cannot be set to such keywords - * or an exception will be thrown by JavaFX during runtime. - * - * @see The issue on AddressBook level 4 - */ - - public final InventoryRecord record; - - @FXML - private HBox cardPane; - @FXML - private Label name; - @FXML - private Label id; - @FXML - private Label quantity; - @FXML - private Label date; - @FXML - private Label time; - - /** - * Creates a {@code PersonCode} with the given {@code Person} and index to display. - */ - public InventoryRecordCard(InventoryRecord record, int displayedIndex) { - super(FXML); - this.record = record; - id.setText(displayedIndex + ". "); - name.setText(record.getItemName()); - quantity.setText(Integer.toString(record.getQuantity())); - date.setText(record.getDate().toString()); - time.setText(record.getTime().toString()); - } - - @Override - public boolean equals(Object other) { - // short circuit if same object - if (other == this) { - return true; - } - - // instanceof handles nulls - if (!(other instanceof InventoryRecordCard)) { - return false; - } - - // state check - InventoryRecordCard card = (InventoryRecordCard) other; - return id.getText().equals(card.id.getText()) - && record.equals(card.record); - } -} diff --git a/src/main/java/nustorage/ui/MainWindow.java b/src/main/java/nustorage/ui/MainWindow.java index 1d6d8337617..7f3269ecdc6 100644 --- a/src/main/java/nustorage/ui/MainWindow.java +++ b/src/main/java/nustorage/ui/MainWindow.java @@ -32,7 +32,6 @@ public class MainWindow extends UiPart { // Independent Ui parts residing in this Ui container private PersonListPanel personListPanel; - private InventoryPanel inventoryPanel; private ResultDisplay resultDisplay; private HelpWindow helpWindow; @@ -45,9 +44,6 @@ public class MainWindow extends UiPart { @FXML private StackPane personListPanelPlaceholder; - @FXML - private StackPane inventoryPanelPlaceholder; - @FXML private StackPane resultDisplayPlaceholder; @@ -127,20 +123,6 @@ void fillInnerParts() { commandBoxPlaceholder.getChildren().add(commandBox.getRoot()); } - void fillInnerPartsWithInventory() { - inventoryPanel = new InventoryPanel(logic.getFilteredInventory()); - inventoryPanelPlaceholder.getChildren().add(inventoryPanel.getRoot()); - - resultDisplay = new ResultDisplay(); - resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot()); - - StatusBarFooter statusBarFooter = new StatusBarFooter(logic.getAddressBookFilePath()); - statusbarPlaceholder.getChildren().add(statusBarFooter.getRoot()); - - CommandBox commandBox = new CommandBox(this::executeCommand); - commandBoxPlaceholder.getChildren().add(commandBox.getRoot()); - } - /** * Sets the default size based on {@code guiSettings}. */ diff --git a/src/main/java/nustorage/ui/UiManager.java b/src/main/java/nustorage/ui/UiManager.java index fe1266bcc8f..78612e5a931 100644 --- a/src/main/java/nustorage/ui/UiManager.java +++ b/src/main/java/nustorage/ui/UiManager.java @@ -43,7 +43,7 @@ public void start(Stage primaryStage) { try { mainWindow = new MainWindow(primaryStage, logic); mainWindow.show(); //This should be called before creating other UI parts - mainWindow.fillInnerPartsWithInventory(); + mainWindow.fillInnerParts(); } catch (Throwable e) { logger.severe(StringUtil.getDetails(e)); diff --git a/src/main/resources/view/InventoryCard.fxml b/src/main/resources/view/InventoryCard.fxml deleted file mode 100644 index 44e60c7a8ad..00000000000 --- a/src/main/resources/view/InventoryCard.fxml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/resources/view/InventoryPanel.fxml b/src/main/resources/view/InventoryPanel.fxml deleted file mode 100644 index 42bbc9845e5..00000000000 --- a/src/main/resources/view/InventoryPanel.fxml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/src/main/resources/view/MainWindow.fxml b/src/main/resources/view/MainWindow.fxml index ac874728a0f..a431648f6c0 100644 --- a/src/main/resources/view/MainWindow.fxml +++ b/src/main/resources/view/MainWindow.fxml @@ -50,7 +50,7 @@ - + diff --git a/src/test/java/nustorage/logic/commands/AddCommandTest.java b/src/test/java/nustorage/logic/commands/AddCommandTest.java index e250a45d453..2fc433a75d2 100644 --- a/src/test/java/nustorage/logic/commands/AddCommandTest.java +++ b/src/test/java/nustorage/logic/commands/AddCommandTest.java @@ -106,11 +106,6 @@ public void setGuiSettings(GuiSettings guiSettings) { @Override public void addInventoryRecord(InventoryRecord newRecord) {} - @Override - public ObservableList getFilteredInventory() { - throw new AssertionError("This method should not be called."); - } - @Override public void addFinanceRecord(FinanceRecord newRecord) { @@ -175,13 +170,6 @@ public ObservableList getFilteredPersonList() { public void updateFilteredPersonList(Predicate predicate) { throw new AssertionError("This method should not be called."); } - - @Override - public void updateFilteredInventoryList(Predicate predicate) { - - } - - } /**