Skip to content

Commit

Permalink
Merge pull request #44 from IronBiscuit/master
Browse files Browse the repository at this point in the history
List Inventory
  • Loading branch information
IronBiscuit authored Oct 4, 2020
2 parents 4e80e61 + a7f16cf commit cb63615
Show file tree
Hide file tree
Showing 20 changed files with 302 additions and 23 deletions.
4 changes: 2 additions & 2 deletions docs/AboutUs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -64,7 +64,7 @@ You can reach us at the email `seer[at]comp.nus.edu.sg`

<img src="images/howtoosee.png" width="200px">

[[github](https://github.com/howtoosee)]
[[github](https://github.com/howtoosee)]
[[portfolio](team/xihao.md)]

* Role: Developer
Expand Down
20 changes: 10 additions & 10 deletions docs/DeveloperGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand All @@ -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**
Expand Down Expand Up @@ -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**
Expand All @@ -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**
Expand All @@ -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
Expand All @@ -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.

--------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -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
Expand All @@ -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`<br>
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` <br>
Expected: No record is added. Error details shown in the status message.

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/nustorage/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand All @@ -33,6 +34,8 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of persons */
ObservableList<Person> getFilteredPersonList();

ObservableList<InventoryRecord> getFilteredInventory();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/nustorage/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import nustorage.model.Model;
import nustorage.model.ReadOnlyAddressBook;
import nustorage.model.person.Person;
import nustorage.model.record.InventoryRecord;
import nustorage.storage.Storage;

/**
Expand Down Expand Up @@ -64,6 +65,10 @@ public ObservableList<Person> getFilteredPersonList() {
return model.getFilteredPersonList();
}

public ObservableList<InventoryRecord> getFilteredInventory() {
return model.getFilteredInventory();
}

@Override
public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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));
Expand Down
1 change: 1 addition & 0 deletions src/main/java/nustorage/logic/commands/CommandResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CommandResult {
/** The application should exit. */
private final boolean exit;


/**
* Constructs a {@code CommandResult} with the specified fields.
*/
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/nustorage/logic/commands/ListInventoryCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
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<InventoryRecord> inventory = model.getFilteredInventory();
return new CommandResult(MESSAGE_SUCCESS);
}
}
3 changes: 3 additions & 0 deletions src/main/java/nustorage/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;

Expand Down Expand Up @@ -47,6 +48,8 @@ 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);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/nustorage/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public interface Model {
/** {@code Predicate} that always evaluate to true */
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
Predicate<InventoryRecord> PREDICATE_SHOW_ALL_INVENTORY = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
Expand Down Expand Up @@ -92,9 +93,13 @@ public interface Model {
/** Returns an unmodifiable view of the filtered person list */
ObservableList<Person> getFilteredPersonList();

ObservableList<InventoryRecord> 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<Person> predicate);

void updateFilteredInventoryList(Predicate<InventoryRecord> predicate);
}
16 changes: 16 additions & 0 deletions src/main/java/nustorage/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ModelManager implements Model {
private final AddressBook addressBook;
private final UserPrefs userPrefs;
private final FilteredList<Person> filteredPersons;
private final FilteredList<InventoryRecord> filteredInventory;

/**
* Initializes a ModelManager with the given addressBook and userPrefs.
Expand All @@ -42,6 +43,7 @@ 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);
Expand Down Expand Up @@ -93,6 +95,19 @@ public void addInventoryRecord(InventoryRecord newRecord) {
inventory.addInventoryRecord(newRecord);
}

public ObservableList<InventoryRecord> 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<InventoryRecord> predicate) {
requireNonNull(predicate);
filteredInventory.setPredicate(predicate);
}

//=========== FinanceAccount ================================================================================

@Override
Expand Down Expand Up @@ -163,6 +178,7 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
filteredPersons.setPredicate(predicate);
}


@Override
public boolean equals(Object obj) {
// short circuit if same object
Expand Down
32 changes: 24 additions & 8 deletions src/main/java/nustorage/model/item/Inventory.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,60 @@
package nustorage.model.item;

import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
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 {
public class Inventory implements Iterable<InventoryRecord>, ReadOnlyInventory {

private final List<InventoryRecord> inventory;
private final ObservableList<InventoryRecord> internalList = FXCollections.observableArrayList();
private final ObservableList<InventoryRecord> internalUnmodifiableList =
FXCollections.unmodifiableObservableList(internalList);

/**
* Constructs inventory object to hold InventoryRecords.
*/
public Inventory() {
this.inventory = new ArrayList<>();

}

/**
* Adds InventoryRecord into inventory.
* @param inventoryRecord to be added.
*/
public void addInventoryRecord(InventoryRecord inventoryRecord) {
inventory.add(inventoryRecord);
internalList.add(inventoryRecord);
}

/**
* Removes InventoryRecord from inventory.
* @param inventoryRecord to be removed.
*/
public void deleteInventoryRecord(InventoryRecord inventoryRecord) {
inventory.remove(inventoryRecord);
internalList.remove(inventoryRecord);
}

public ObservableList<InventoryRecord> getInventoryList() {
return internalList;
}

public ObservableList<InventoryRecord> asUnmodifiableObservableList() {
return internalUnmodifiableList;
}

@Override
public Iterator<InventoryRecord> iterator() {
return internalList.iterator();
}

@Override
public String toString() {
return inventory.stream()
return internalList.stream()
.map(InventoryRecord::toString)
.collect(Collectors.joining("\n"));
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/nustorage/model/item/ReadOnlyInventory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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<InventoryRecord> asUnmodifiableObservableList();
}
46 changes: 46 additions & 0 deletions src/main/java/nustorage/ui/InventoryPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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<Region> {
private static final String FXML = "InventoryPanel.fxml";
private final Logger logger = LogsCenter.getLogger(InventoryPanel.class);

@FXML
private ListView<InventoryRecord> inventoryView;

/**
* Creates a {@code PersonListPanel} with the given {@code ObservableList}.
*/
public InventoryPanel(ObservableList<InventoryRecord> 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<InventoryRecord> {
@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());
}
}
}

}
Loading

0 comments on commit cb63615

Please sign in to comment.