Skip to content

Commit

Permalink
Merge pull request #123 from rrtheonlyone/home-command
Browse files Browse the repository at this point in the history
Home Command Added
  • Loading branch information
rrtheonlyone committed Nov 1, 2018
2 parents 7754e63 + 9099564 commit 5bacdf5
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/seedu/address/commons/events/ui/BackToHomeEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;

/**
* Indicates a request to go back to the dashboard screen
*/
public class BackToHomeEvent extends BaseEvent {

@Override
public String toString() {
return getClass().getSimpleName();
}
}
27 changes: 27 additions & 0 deletions src/main/java/seedu/address/logic/commands/HomeCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.events.ui.BackToHomeEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;

/**
* Logout the user from FoodZoom.
*/
public class HomeCommand extends Command {

public static final String COMMAND_WORD = "/home";

public static final String MESSAGE_SUCCESS = "Back to Home Page! View your dashboard below.";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Returns back to home screen with dashboard. ";

@Override
public CommandResult execute(Model model, CommandHistory history) {
requireNonNull(model);
EventsCenter.getInstance().post(new BackToHomeEvent());
return new CommandResult(MESSAGE_SUCCESS);
}
}
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/logic/parser/OrderBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.HomeCommand;
import seedu.address.logic.commands.LoginCommand;
import seedu.address.logic.commands.LogoutCommand;
import seedu.address.logic.commands.RedoCommand;
Expand Down Expand Up @@ -82,6 +83,9 @@ public Command parseCommand(String userInput) throws ParseException {
case AssignCommand.COMMAND_WORD:
return new AssignCommandParser().parse(arguments);

case HomeCommand.COMMAND_WORD:
return new HomeCommand();

default:
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/ui/DeliverymanListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.scene.control.ListView;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.BackToHomeEvent;
import seedu.address.commons.events.ui.DeliveryManPanelSelectionChangedEvent;
import seedu.address.commons.events.ui.JumpToDeliveryManListRequestEvent;
import seedu.address.commons.events.ui.OrderPanelSelectionChangedEvent;
Expand Down Expand Up @@ -70,6 +71,11 @@ private void handleOrderPanelSelectionChangedEvent(OrderPanelSelectionChangedEve
deliverymanListView.getSelectionModel().clearSelection();
}

@Subscribe
private void handleBackToHomeRequest(BackToHomeEvent event) {
deliverymanListView.getSelectionModel().clearSelection();
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Order} using a {@code OrderCard}.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/ui/Display.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.BackToHomeEvent;
import seedu.address.commons.events.ui.DeliveryManPanelSelectionChangedEvent;
import seedu.address.commons.events.ui.OrderPanelSelectionChangedEvent;
import seedu.address.model.order.Food;
Expand Down Expand Up @@ -307,6 +308,16 @@ private void removeFromOrderHistory(List<? extends Order> changeList) {
logger.info(orderHistory.toString());
}

@Subscribe
public void handleBackToHomeRequest(BackToHomeEvent event) {
logger.info(LogsCenter.getEventHandlingLogMessage(event));

statisticsPanel = new StatisticsPanel();
displayPanelPlaceholder.getChildren().setAll(statisticsPanel.getRoot());

setupStatistics();
}

@Subscribe
public void handleOrderPanelSelectionChangedEvent(OrderPanelSelectionChangedEvent event) {
logger.info(LogsCenter.getEventHandlingLogMessage(event));
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/ui/OrderListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.scene.control.ListView;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.BackToHomeEvent;
import seedu.address.commons.events.ui.DeliveryManPanelSelectionChangedEvent;
import seedu.address.commons.events.ui.JumpToOrderListRequestEvent;
import seedu.address.commons.events.ui.OrderPanelSelectionChangedEvent;
Expand Down Expand Up @@ -69,6 +70,12 @@ private void handleJumpToOrderListRequestEvent(JumpToOrderListRequestEvent event
private void handleDeliverymanPanelSelectionChangedEvent(DeliveryManPanelSelectionChangedEvent event) {
orderListView.getSelectionModel().clearSelection();
}

@Subscribe
private void handleBackToHomeRequest(BackToHomeEvent event) {
orderListView.getSelectionModel().clearSelection();
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Order} using a {@code OrderCard}.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<icons>
<Image url="@/images/scooter.png"/>
</icons>

<scene>
<Scene>
<stylesheets>
Expand Down Expand Up @@ -51,4 +52,5 @@
</VBox>
</Scene>
</scene>

</fx:root>
30 changes: 30 additions & 0 deletions src/test/java/seedu/address/logic/commands/HomeCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package seedu.address.logic.commands;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.HomeCommand.MESSAGE_SUCCESS;

import org.junit.Rule;
import org.junit.Test;

import seedu.address.commons.events.ui.BackToHomeEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.ui.testutil.EventsCollectorRule;

public class HomeCommandTest {
@Rule
public final EventsCollectorRule eventsCollectorRule = new EventsCollectorRule();

private Model model = new ModelManager();
private CommandHistory commandHistory = new CommandHistory();

@Test
public void execute_home_success() {
CommandResult result = new HomeCommand().execute(model, commandHistory);
assertEquals(MESSAGE_SUCCESS, result.feedbackToUser);
assertTrue(eventsCollectorRule.eventsCollector.getMostRecent() instanceof BackToHomeEvent);
assertTrue(eventsCollectorRule.eventsCollector.getSize() == 1);
}
}

0 comments on commit 5bacdf5

Please sign in to comment.