Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2223S1#94 from CFSY/ui
Browse files Browse the repository at this point in the history
UI
  • Loading branch information
CFSY authored Oct 25, 2022
2 parents 387e09c + 4eff085 commit 9b31aad
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private static Item createEditedItem(Item itemToEdit,
Duration updatedDuration = editItemDescriptor.getDuration().orElse(itemToEdit.getDuration());

Item editedItem = new Item(updatedDescription, updatedPriority, updatedCost, updatedDuration);
editedItem.setStartTime(editItemDescriptor.getStartTime().orElse(itemToEdit.getStartTime()));
editedItem.setStartTime(editItemDescriptor.getStartTime().orElse(itemToEdit.getStartTime().orElse(null)));

return editedItem;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/seedu/waddle/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ public static String parseDescription(String description) {
public static Priority parsePriority(String priority) throws ParseException {
requireNonNull(priority);
String trimmedPriority = priority.trim();
if (!Priority.isValidPriority(trimmedPriority)) {
Integer stars = Integer.parseInt(trimmedPriority);
if (!Priority.isValidPriority(stars)) {
throw new ParseException(Priority.MESSAGE_CONSTRAINTS);
}
return new Priority(trimmedPriority);
return new Priority(stars);
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/seedu/waddle/model/item/Day.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Day {
private final Comparator<Item> startTimeComparator = new Comparator<Item>() {
@Override
public int compare(Item item1, Item item2) {
return item1.getStartTime().compareTo(item2.getStartTime());
return item1.getStartTime().get().compareTo(item2.getStartTime().get());
}
};
private final int dayNumber;
Expand Down Expand Up @@ -90,11 +90,11 @@ public ArrayList<Item> getConflictingItems(Item newItem) {
// same start time
boolean sameStartTime = item.getStartTime().equals(newItem.getStartTime());
// start time of new item is within the duration of a preceding item
boolean startTimeConflict = newItem.getStartTime().isAfter(item.getStartTime())
&& newItem.getStartTime().isBefore(item.getEndTime());
boolean startTimeConflict = newItem.getStartTime().get().isAfter(item.getStartTime().get())
&& newItem.getStartTime().get().isBefore(item.getEndTime().get());
// end time of new item eats into a proceeding item
boolean endTimeConflict = newItem.getEndTime().isAfter(item.getStartTime())
&& newItem.getEndTime().isBefore(item.getEndTime());
boolean endTimeConflict = newItem.getEndTime().get().isAfter(item.getStartTime().get())
&& newItem.getEndTime().get().isBefore(item.getEndTime().get());


if (sameStartTime || startTimeConflict || endTimeConflict) {
Expand Down
40 changes: 26 additions & 14 deletions src/main/java/seedu/waddle/model/item/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
import static seedu.waddle.commons.util.CollectionUtil.requireAllNonNull;

import java.time.LocalTime;
import java.util.Optional;

/**
* Represents an item in the itinerary.
*/
public class Item {
private String description;
private Priority priority;
private Cost cost;
private Duration duration;

private final String description;
private final Priority priority;
private final Cost cost;
private final Duration duration;
private LocalTime startTime;
// private Category category;

/**
* Constructor for an item.
*
* @param description description of the item
*/
public Item(String description, Priority priority, Cost cost, Duration duration) {
Expand All @@ -37,27 +38,38 @@ public Priority getPriority() {
}

public Cost getCost() {
return cost;
return this.cost;
}

public Duration getDuration() {
return duration;
}

public LocalTime getStartTime() {
return this.startTime;
public Optional<LocalTime> getStartTime() {
return Optional.ofNullable(this.startTime);
}

public LocalTime getEndTime() {
return this.startTime.plusMinutes(this.duration.getDuration());
public void setStartTime(LocalTime startTime) {
this.startTime = startTime;
}

public void resetStartTime() {
this.startTime = null;
public Optional<LocalTime> getEndTime() {
return Optional.ofNullable(this.startTime.plusMinutes(this.duration.getDuration()));
}

public void setStartTime(LocalTime startTime) {
this.startTime = startTime;
public Optional<String> getTimeString() {
if (this.startTime != null) {
if (this.duration != null) {
return Optional.of(this.startTime + " - " + getEndTime().get());
} else {
return Optional.of(this.startTime.toString());
}
}
return Optional.empty();
}

public void resetStartTime() {
this.startTime = null;
}

/**
Expand Down
33 changes: 15 additions & 18 deletions src/main/java/seedu/waddle/model/item/Priority.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,51 +12,48 @@ public class Priority {
public static final String MESSAGE_CONSTRAINTS =
"Priority should only contain a number between 1 and 5";

/*
* The first character of the country must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[1-5]";

public final String priority;
private final Integer stars;

/**
* Constructs a {@code Priority}.
*
* @param priority A valid priority.
* @param stars A valid priority.
*/
public Priority(String priority) {
requireNonNull(priority);
checkArgument(isValidPriority(priority), MESSAGE_CONSTRAINTS);
this.priority = priority;
public Priority(Integer stars) {
requireNonNull(stars);
checkArgument(isValidPriority(stars), MESSAGE_CONSTRAINTS);
this.stars = stars;
}

/**
* Returns true if a given string is a valid priority.
*/
public static boolean isValidPriority(String test) {
return test.matches(VALIDATION_REGEX);
public static boolean isValidPriority(Integer test) {
return test > 0 && test <= 5;
}

public int getStars() {
return this.stars;
}

@Override
public String toString() {
return priority;
return this.stars.toString();
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof Priority // instanceof handles nulls
&& priority.equals(((Priority) other).priority)); // state check
&& this.stars.equals(((Priority) other).getStars())); // state check
}

@Override
public int hashCode() {
return priority.hashCode();
return this.stars.hashCode();
}

public int compareTo(Priority p) {
return this.priority.compareToIgnoreCase(p.priority);
return this.stars.compareTo(p.getStars());
}
}
14 changes: 7 additions & 7 deletions src/main/java/seedu/waddle/storage/JsonAdaptedItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class JsonAdaptedItem {
public static final String MISSING_FIELD_MESSAGE_FORMAT = "Item's %s field is missing!";

private final String description;
private final String priority;
private final Integer stars;
private final String cost;
//private final String duration;

Expand All @@ -26,11 +26,11 @@ public class JsonAdaptedItem {
*/
@JsonCreator
public JsonAdaptedItem(@JsonProperty("description") String description,
@JsonProperty("priority") String priority,
@JsonProperty("priority") Integer stars,
@JsonProperty("cost") String cost,
@JsonProperty("duration") String duration) {
this.description = description;
this.priority = priority;
this.stars = stars;
this.cost = cost;
//this.duration = duration;
}
Expand All @@ -40,7 +40,7 @@ public JsonAdaptedItem(@JsonProperty("description") String description,
*/
public JsonAdaptedItem(Item source) {
description = source.getDescription();
priority = source.getPriority().priority;
stars = source.getPriority().getStars();
cost = source.getCost().toString();
//TODO duration and startTime null error
//duration = source.getDuration().toString();
Expand All @@ -65,15 +65,15 @@ public Item toModelType() throws IllegalValueException {
*/
final String modelDescription = description;

if (priority == null) {
if (stars == null) {
throw new IllegalValueException(
String.format(MISSING_FIELD_MESSAGE_FORMAT, Priority.class.getSimpleName()));
}
if (!Priority.isValidPriority(priority)) {
if (!Priority.isValidPriority(stars)) {
throw new IllegalValueException(Priority.MESSAGE_CONSTRAINTS);
}

final Priority modelPriority = new Priority(priority);
final Priority modelPriority = new Priority(stars);
final Cost modelCost = new Cost(cost);
//final Duration modelDuration = new Duration(duration);

Expand Down
26 changes: 19 additions & 7 deletions src/main/java/seedu/waddle/ui/ItemCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,33 @@ public class ItemCard extends UiPart<Region> {
@FXML
private Label id;
// Priority and Category have not yet been implemented
// @FXML
// private Label priority;
@FXML
private Label priority;
@FXML
private Label duration;
@FXML
private Label time;
@FXML
private Label cost;
// @FXML
// private Label category;

/**
* Creates a {@code ItemCode} with the given {@code Item} and index to display.
*/
public ItemCard(Item item, int displayedIndex) {
public ItemCard(Item item, int dayNumber, int displayedIndex) {
super(FXML);
this.item = item;
id.setText(displayedIndex + ". ");
description.setText(item.getDescription());
// priority.setText(item.getPriority());
// category.setText(item.getCategory());
if (dayNumber > 0) {
this.id.setText(dayNumber + "." + displayedIndex + " ");
} else {
this.id.setText(displayedIndex + ". ");
}
this.description.setText(item.getDescription());
this.priority.setText("Stars: " + item.getPriority().getStars());
this.duration.setText("Duration: " + item.getDuration());
this.time.setText("Time: " + item.getTimeString().orElseGet(() -> "(Not planned)"));
this.cost.setText("Cost: " + item.getCost().getValue());
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/seedu/waddle/ui/ItemGroupCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public class ItemGroupCard extends UiPart<Region> {
/**
* Creates a {@code ItineraryCode} with the given {@code Itinerary} and index to display.
*/
public ItemGroupCard(ObservableList<Item> itemGroup, int displayedIndex) {
public ItemGroupCard(ObservableList<Item> itemGroup, int dayNumber) {
super(FXML);
this.itemGroup = itemGroup;
if (displayedIndex == 0) {
if (dayNumber == 0) {
this.id.setText("Wishlist");
} else {
this.id.setText("Day " + displayedIndex);
this.id.setText("Day " + dayNumber);
}
this.itemListPanelPlaceholder.getChildren().add(new ItemListPanel(itemGroup).getRoot());
this.itemListPanelPlaceholder.getChildren().add(new ItemListPanel(itemGroup, dayNumber).getRoot());
this.itemListPanelPlaceholder.setMinHeight(UiSizes.ITEM_LIST_MIN_HEIGHT);
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/waddle/ui/ItemListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
public class ItemListPanel extends ListPanel {
private static final String FXML = "ItemListPanel.fxml";
private final Logger logger = LogsCenter.getLogger(ItemListPanel.class);
private final int dayNumber;

@FXML
private ListView<Item> itemListView;

/**
* Creates a {@code ItemListPanel} with the given {@code ObservableList}.
*/
public ItemListPanel(ObservableList<Item> itemList) {
public ItemListPanel(ObservableList<Item> itemList, int dayNumber) {
super(FXML);
this.dayNumber = dayNumber;
itemListView.setItems(itemList);
itemListView.setCellFactory(listView -> new ItemListPanel.ItemListViewCell());
itemListView.prefHeightProperty().bind(Bindings.size(itemList).multiply(UiSizes.ITEM_CARD_HEIGHT));
Expand All @@ -42,7 +44,7 @@ protected void updateItem(Item item, boolean empty) {
setGraphic(null);
setText(null);
} else {
setGraphic(new ItemCard(item, getIndex() + 1).getRoot());
setGraphic(new ItemCard(item, dayNumber, getIndex() + 1).getRoot());
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/view/ItemListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
</Label>
<Label fx:id="description" text="\$first" styleClass="cell_big_label" />
</HBox>
<Label fx:id="priority" styleClass="cell_small_label" text="\$priority" />
<Label fx:id="duration" styleClass="cell_small_label" text="\$duration" />
<Label fx:id="time" styleClass="cell_small_label" text="\$time" />
<Label fx:id="cost" styleClass="cell_small_label" text="\$cost" />
</VBox>
</GridPane>
</HBox>

0 comments on commit 9b31aad

Please sign in to comment.