Skip to content

Commit

Permalink
Fix #136 : Clear Schedule at end of the day (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Yong Jek authored and tysg committed Nov 8, 2019
1 parent 131a5d7 commit 86b415b
Show file tree
Hide file tree
Showing 15 changed files with 287 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public interface Logic {
/** Returns an unmodifiable view of the filtered list of customers */
ObservableList<Customer> getFilteredCustomerList();

/**
* Returns a list of incomplete tasks from previous days
*/
ObservableList<Task> getIncompleteTaskList();

/**
* Returns the user prefs' address book file path.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ public ObservableList<Task> getFilteredAssignedTaskList() {
return model.getAssignedTaskList();
}

@Override
public ObservableList<Task> getIncompleteTaskList() {
return model.getIncompleteTaskList();
}

@Override
public ObservableList<Driver> getFilteredDriverList() {
return model.getFilteredDriverList();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import javafx.collections.transformation.FilteredList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.logic.GlobalClock;
import seedu.address.model.id.IdManager;
import seedu.address.model.legacy.ReadOnlyAddressBook;
import seedu.address.model.pdfmanager.exceptions.PdfNoTaskToDisplayException;
Expand Down Expand Up @@ -48,6 +49,16 @@ public interface Model {
*/
Predicate<Task> PREDICATE_SHOW_ASSIGNED = task -> task.getStatus().equals(TaskStatus.ON_GOING);

/**
* {@code Predicate} that filters the task to completed status
*/
Predicate<Task> PREDICATE_SHOW_COMPLETED = task -> task.getStatus().equals(TaskStatus.COMPLETED);

/**
* {@code Predicate} that filters the task to both incomplete and ongoing status
*/
Predicate<Task> PREDICATE_SHOW_PREVIOUS_DAYS = task -> task.getDate().isBefore(GlobalClock.dateToday());

/**
* Returns the user prefs.
*/
Expand Down Expand Up @@ -160,6 +171,11 @@ public interface Model {
*/
ObservableList<Task> getAssignedTaskList();

/**
* Return a list of incomplete tasks from the previous days
*/
ObservableList<Task> getIncompleteTaskList();

// customer manager

CustomerManager getCustomerManager();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,20 @@ public ObservableList<Task> getAssignedTaskList() {
return filteredTasks;
}

/**
* Returns a observable view of the list of incomplete tasks from the previous days
*/
@Override
public ObservableList<Task> getIncompleteTaskList() {
FilteredList<Task> incompleteTasks = new FilteredList<>(this.taskManager.getList());
updateFilteredTaskList(PREDICATE_SHOW_ASSIGNED.and(PREDICATE_SHOW_PREVIOUS_DAYS), incompleteTasks);
return incompleteTasks;
}

/**
* Refreshes the display of task list.
*/
@Override
public void refreshFilteredTaskList() {
//refresh assigned task list
updateFilteredTaskList(PREDICATE_SHOW_EMPTY_TASKS, filteredTasks);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/person/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ public boolean remove(EventTime eventTime) {
return schedule.remove(eventTime);
}


private boolean isOutsideWorkingHours(EventTime eventTime) {
return (eventTime.getEnd().compareTo(eventTime.getStart()) <= 0)
|| (eventTime.getStart().compareTo(workingHours.getStart()) < 0)
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/model/task/TaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
Expand Down Expand Up @@ -127,6 +128,10 @@ public List<Task> getFilteredList(Predicate<Task> predicate) {
.collect(Collectors.toList());
}

public Iterator<Task> getIterator() {
return tasks.iterator();
}

public void setTaskList(List<Task> savedTasks) {
tasks.setAll(savedTasks);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/task/TaskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javafx.collections.ObservableList;


/**
* Manages the task list.
* It contains the minimal set of list operations.
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/ui/HelpWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.scene.control.Label;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import seedu.address.commons.core.LogsCenter;

Expand All @@ -21,12 +22,21 @@ public class HelpWindow extends UiPart<Stage> {
private static final Logger logger = LogsCenter.getLogger(HelpWindow.class);
private static final String FXML = "HelpWindow.fxml";

private DriverListPanel driverListPanel;
private IncompleteTaskListPanel incompleteTaskListPanel;

@FXML
private StackPane driverListPanelPlaceholder;

@FXML
private Button copyButton;

@FXML
private Label helpMessage;

@FXML
private StackPane incompleteTaskListPanelPlaceholder;

/**
* Creates a new HelpWindow.
*
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/seedu/address/ui/IncompleteTaskListPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package seedu.address.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 seedu.address.commons.core.LogsCenter;
import seedu.address.model.task.Task;

/**
* Panel containing the list of persons.
*/
public class IncompleteTaskListPanel extends UiPart<Region> {
private static final String FXML = "IncompleteTaskListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(IncompleteTaskListPanel.class);

@FXML
private ListView<Task> incompleteTaskListView;

public IncompleteTaskListPanel(ObservableList<Task> incompleteTaskList) {
super(FXML);
incompleteTaskListView.setItems(incompleteTaskList);
incompleteTaskListView.setCellFactory(listView -> new IncompleteTaskListPanel.IncompleteTaskListViewCell());
}

/**
* Custom {@code ListCell} that displays the graphics of a {@code Task} using a {@code TaskCard}.
*/
class IncompleteTaskListViewCell extends ListCell<Task> {
@Override
protected void updateItem(Task task, boolean empty) {
super.updateItem(task, empty);

if (empty || task == null) {
setGraphic(null);
setText(null);
} else {
setGraphic(new TaskCard(task, getIndex() + 1).getRoot());
}
}
}
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MainWindow extends UiPart<Stage> {
// Independent Ui parts residing in this Ui container
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
private NotificationWindow notificationWindow;
private AssignedTaskListPanel assignedTaskListPanel;
private UnassignedTaskListPanel unassignedTaskListPanel;
private CustomerListPanel customerListPanel;
Expand Down
114 changes: 114 additions & 0 deletions src/main/java/seedu/address/ui/NotificationWindow.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package seedu.address.ui;

import java.util.logging.Logger;

import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.Logic;
import seedu.address.logic.commands.FreeCommand;
import seedu.address.model.person.Driver;
import seedu.address.model.task.Task;

/**
* Controller for a help page
*/
public class NotificationWindow extends UiPart<Stage> {

private static final Logger logger = LogsCenter.getLogger(NotificationWindow.class);
private static final String FXML = "NotificationWindow.fxml";

private Logic logic;

private IncompleteTaskListPanel incompleteTaskListPanel;

@FXML
private StackPane incompleteTaskListPanelPlaceholder;

@FXML
private Button okayButton;

@FXML
private StackPane okayButtonPlaceholder;

/**
* Creates a new HelpWindow.
*
* @param root Stage to use as the root of the HelpWindow.
*/
public NotificationWindow(Stage root, Logic logic) {
super(FXML, root);
this.logic = logic;

incompleteTaskListPanel = new IncompleteTaskListPanel(this.logic.getIncompleteTaskList());
incompleteTaskListPanelPlaceholder.getChildren().add(incompleteTaskListPanel.getRoot());
}

/**
* Creates a new HelpWindow.
*/
public NotificationWindow(Logic logic) {
this(new Stage(), logic);
}

/**
* Shows the notification window.
* @throws IllegalStateException
* <ul>
* <li>
* if this method is called on a thread other than the JavaFX Application Thread.
* </li>
* <li>
* if this method is called during animation or layout processing.
* </li>
* <li>
* if this method is called on the primary stage.
* </li>
* <li>
* if {@code dialogStage} is already showing.
* </li>
* </ul>
*/
public void show() {
logger.fine("Showing page about the incomplete task from the previous day.");
getRoot().show();
getRoot().centerOnScreen();
}

/**
* Returns true if the help window is currently being shown.
*/
public boolean isShowing() {
return getRoot().isShowing();
}

/**
* Hides the help window.
*/
public void hide() {
getRoot().hide();
}

/**
* Focuses on the help window.
*/
public void focus() {
getRoot().requestFocus();
}

/**
* Frees driver's schedule from tasks in the past
*/
@FXML
private void freeDriver() {
ObservableList<Task> tasksToBeCleared = logic.getIncompleteTaskList();
for (Task task: tasksToBeCleared) {
Driver driver = task.getDriver().orElseThrow();
FreeCommand.freeDriverFromTask(driver, task);
}
this.hide();
}
}
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/ui/UiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class UiManager implements Ui {

private Logic logic;
private MainWindow mainWindow;
private NotificationWindow notificationWindow;

public UiManager(Logic logic) {
super();
Expand All @@ -41,7 +42,9 @@ public void start(Stage primaryStage) {
mainWindow = new MainWindow(primaryStage, logic);
mainWindow.show(); //This should be called before creating other UI parts
mainWindow.fillInnerParts();

notificationWindow = new NotificationWindow(logic);
notificationWindow.show();
notificationWindow.focus();
} catch (Throwable e) {
logger.severe(StringUtil.getDetails(e));
showFatalErrorDialogAndShutdown("Fatal error during initializing", e);
Expand Down
15 changes: 15 additions & 0 deletions src/main/resources/view/IncompleteTaskListPanel.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.VBox?>

<VBox xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<ToolBar prefHeight="36.0" prefWidth="248.0">
<items>
<Label text="Uncompleted Delivery Tasks from Previous Days" />
</items>
</ToolBar>
<ListView fx:id="incompleteTaskListView" VBox.vgrow="ALWAYS" />
</VBox>
Loading

0 comments on commit 86b415b

Please sign in to comment.