Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve body measurement field #223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ A client can have any number of tags (including 0). The remark is also optional.

Examples:
* `add n/John Doe p/98765432 e/[email protected] a/John street Blk 92 g/M m/170_100_40`
* `add n/Betsy Crowe e/[email protected] a/Sesame Street p/1234567 t/important g/F d/160_85_35_81`
* `add n/Betsy Crowe e/[email protected] a/Sesame Street p/1234567 t/important g/F m/160_85_35_81`

### Deleting a client : `delete`

Expand All @@ -171,7 +171,7 @@ Examples:

Edits an existing client in the application.

Format: `edit INDEX n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS m/MEASUREMENT g/GENDER [r/REMARK] [t/TAG]…​`
Format: `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [m/MEASUREMENT] [g/GENDER] [r/REMARK] [t/TAG]…​`

<div markdown="span" class="alert alert-primary">:information_source: **Note:**
Do not forget to edit the body measurements when you modify the client's gender.
Expand Down Expand Up @@ -470,7 +470,7 @@ Action | Format, Examples
**ListClient** | `list`
**AddClient** | `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS m/MEASUREMENT g/GENDER [r/REMARK] [t/TAG]…​` <br> e.g., `add n/John Doe p/98765432 e/[email protected] a/John street Blk 92 g/M m/170_100_40 t/friend`
**DeleteClient** | `delete INDEX`<br> e.g., `delete 3`
**EditClient** | `edit INDEX n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS m/MEASUREMENT g/GENDER [r/REMARK] [t/TAG]…​`<br> e.g.,`edit 2 n/James Lee e/[email protected]`
**EditClient** | `edit INDEX [n/NAME] [p/PHONE_NUMBER] [e/EMAIL] [a/ADDRESS] [m/MEASUREMENT] [g/GENDER] [r/REMARK] [t/TAG]…​`<br> e.g.,`edit 2 n/James Lee e/[email protected]`
**FindClients** | `find KEYWORD [MORE_KEYWORDS]`<br> e.g., `find James Jake`

### Task Commands
Expand All @@ -480,7 +480,7 @@ Action | Format, Examples
**ListTasks** | `listtask`
**AddTask** | `addtask l/LABEL d/DATE [t/TASKTAG]` e.g., `addtask l/sew buttons onto blazer d/20 August 2021 t/SO1`
**DeleteTask** | `deletetask INDEX` e.g., `deletetask 1`
**EditTask** | `edittask INDEX l/LABEL d/DATE [t/TASKTAG]` e.g., `edittask 1 l/order cloth d/19 September 2021 t/General`
**EditTask** | `edittask INDEX [l/LABEL] [d/DATE] [t/TASKTAG]` e.g., `edittask 1 l/order cloth d/19 September 2021 t/General`
**MarkTask** | `marktask INDEX` e.g., `marktask 2`
**FindTasks** | `findtask KEYWORD [MORE_KEYWORDS]`<br> e.g., `findtask buttons`
**CompletedTasks** | `completedtasks`
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ public interface Logic {
*/
Path getAddressBookFilePath();

/**
* Returns the user prefs' task book file path.
*/
Path getTaskBookFilePath();

/**
* Returns the user prefs' order book file path.
*/
Path getOrderBookFilePath();

/**
* Returns the user prefs' GUI settings.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public Path getAddressBookFilePath() {
return model.getAddressBookFilePath();
}

@Override
public Path getTaskBookFilePath() {
return model.getTaskBookFilePath();
}

@Override
public Path getOrderBookFilePath() {
return model.getOrderBookFilePath();
}

@Override
public GuiSettings getGuiSettings() {
return model.getGuiSettings();
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public static Measurement parseMeasurement(String measurement, Gender gender) th
if (!Measurement.isValidMeasurement(trimmedMeasurement, gender.value)) {
throw new ParseException(Measurement.getMessageConstraints(gender.value));
}
if (!Measurement.isValidRange(trimmedMeasurement)) {
throw new ParseException(Measurement.RANGE_MESSAGE_CONSTRAINTS);
}
return new Measurement(trimmedMeasurement);
}

Expand All @@ -118,6 +121,9 @@ public static Measurement parseMeasurement(String measurement) throws ParseExcep
if (!Measurement.isValidMeasurement(trimmedMeasurement)) {
throw new ParseException(Measurement.GENERAL_MESSAGE_CONSTRAINTS);
}
if (!Measurement.isValidRange(trimmedMeasurement)) {
throw new ParseException(Measurement.RANGE_MESSAGE_CONSTRAINTS);
}
return new Measurement(trimmedMeasurement);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public interface Model {
/**
* Returns the user prefs' UniqueTaskList file path.
*/
Path getTaskListFilePath();
Path getTaskBookFilePath();

/**
* Sets the user prefs' UniqueTaskList file path.
Expand Down Expand Up @@ -153,7 +153,7 @@ public interface Model {
/**
* Returns the user prefs' Order books file path.
*/
Path getOrderPath();
Path getOrderBookFilePath();

/**
* Sets the user prefs' Order books file path.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void setPerson(Person target, Person editedPerson) {
//=========== Task Management ==================================================================================

@Override
public Path getTaskListFilePath() {
public Path getTaskBookFilePath() {
return userPrefs.getTaskBookPath();
}

Expand Down Expand Up @@ -209,7 +209,7 @@ public boolean markTask(Task toMark) {
//=========== Order Management ==================================================================================

@Override
public Path getOrderPath() {
public Path getOrderBookFilePath() {
return userPrefs.getOrderBookFilePath();
}

Expand Down
43 changes: 41 additions & 2 deletions src/main/java/seedu/address/model/person/Measurement.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.text.DecimalFormat;

/**
* Represents a Person's body measurements in the address book.
* Guarantees: immutable; is valid as declared in {@link #isValidMeasurement(String, GenderType)}
Expand All @@ -16,7 +18,8 @@ public class Measurement {
public static final String FEMALE_MESSAGE_CONSTRAINTS =
"A female's body measurements should be of the format height_waist_shoulder_bust in cm,"
+ " and it should not be blank";
public static final String IS_NUMBER_REGEX = "\\d+";
public static final String RANGE_MESSAGE_CONSTRAINTS =
"The measurement of each dimension must be a positive value and not larger than 300cm";
public final String value;

/**
Expand All @@ -27,9 +30,24 @@ public class Measurement {
public Measurement(String measurement) {
requireNonNull(measurement);
checkArgument(isValidMeasurement(measurement), GENERAL_MESSAGE_CONSTRAINTS);
checkArgument(isValidRange(measurement), RANGE_MESSAGE_CONSTRAINTS);
value = measurement;
}

public String getValue() {
String[] measurements = value.split("_");
formatMeasurements(measurements);
return String.join("_", measurements);
}

private void formatMeasurements(String[] args) {
DecimalFormat df = new DecimalFormat("#.##");
for (int i = 0; i < args.length; i++) {
double value = Double.parseDouble(args[i]);
args[i] = df.format(value);
}
}

/**
* Returns true if a given string is a valid measurement.
*/
Expand All @@ -50,6 +68,25 @@ public static boolean isValidMeasurement(String test) {
return isArgsNumber && (args.length == 3 || args.length == 4);
}

/**
* Returns true if the measurements is within a valid range.
*/
public static boolean isValidRange(String test) {
requireNonNull(test);
String[] args = test.split("_");
return isValidRange(args);
}

private static boolean isValidRange(String[] args) {
for (String i: args) {
double value = Double.parseDouble(i);
if (value <= 0 || value > 300) {
return false;
}
}
return true;
}

/**
* Returns message constraints based on gender type.
*/
Expand All @@ -64,7 +101,9 @@ public static String getMessageConstraints(GenderType genderType) {

private static boolean isNumber(String[] args) {
for (String i: args) {
if (!i.matches(IS_NUMBER_REGEX)) {
try {
Double.parseDouble(i);
} catch (NumberFormatException e) {
return false;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ public Person toModelType() throws IllegalValueException {
if (!Measurement.isValidMeasurement(measurement, modelGender.value)) {
throw new IllegalValueException(Measurement.GENERAL_MESSAGE_CONSTRAINTS);
}
if (!Measurement.isValidRange(measurement)) {
throw new IllegalValueException(Measurement.RANGE_MESSAGE_CONSTRAINTS);
}
final Measurement modelMeasurement = new Measurement(measurement);

if (address == null) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ void fillInnerParts() {
resultDisplay = new ResultDisplay();
resultDisplayPlaceholder.getChildren().add(resultDisplay.getRoot());

StatusBarFooter statusBarFooter = new StatusBarFooter(logic.getAddressBookFilePath());
StatusBarFooter statusBarFooter = new StatusBarFooter(logic.getAddressBookFilePath(),
logic.getTaskBookFilePath(),
logic.getOrderBookFilePath());
statusbarPlaceholder.getChildren().add(statusBarFooter.getRoot());

CommandBox commandBox = new CommandBox(this::executeCommand);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/PersonCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public PersonCard(Person person, int displayedIndex) {
phone.setText(person.getPhone().value);
email.setText(person.getEmail().value);
address.setText(person.getAddress().value);
measurement.setText(person.getMeasurement().value);
measurement.setText(person.getMeasurement().getValue());
remark.setText(person.getRemark().value);
person.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/seedu/address/ui/StatusBarFooter.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ public class StatusBarFooter extends UiPart<Region> {
/**
* Creates a {@code StatusBarFooter} with the given {@code Path}.
*/
public StatusBarFooter(Path saveLocation) {
public StatusBarFooter(Path addressBookLocation, Path taskBookLocation, Path orderBookLocation) {
super(FXML);
saveLocationStatus.setText(Paths.get(".").resolve(saveLocation).toString());
String paths = getPath(addressBookLocation) + "; "
+ getPath(taskBookLocation) + "; "
+ getPath(orderBookLocation);
saveLocationStatus.setText(paths);
}

private String getPath(Path location) {
return Paths.get(".").resolve(location).toString();
}

}
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/ModelStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void updateFilteredPersonList(Predicate<Person> predicate) {
}

@Override
public Path getTaskListFilePath() {
public Path getTaskBookFilePath() {
throw new AssertionError("This method should not be called.");
}

Expand Down Expand Up @@ -146,7 +146,7 @@ public boolean markTask(Task task) {
}

@Override
public Path getOrderPath() {
public Path getOrderBookFilePath() {
throw new AssertionError("This method should not be called.");
}

Expand Down