Skip to content

Commit

Permalink
Merge pull request #195 from souless94/ttv1.3
Browse files Browse the repository at this point in the history
This commit resolves issue #192,188,186,184,179,182,
  • Loading branch information
souless94 authored Nov 9, 2018
2 parents 68b09d8 + 095cbf9 commit fff970c
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 105 deletions.
40 changes: 29 additions & 11 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Examples:
Edits the phone number and email address of the 1st person to be `91234567` and `[email protected]` respectively.
* `edit 2 n/Betsy Crower t/` +
Edits the name of the 2nd person to be `Betsy Crower` and clears all existing tags.
* `edit 1 sl/C:\Users\admin\Downloads\cs2103\tiredAndSadness` +
* `edit 1 fl/C:\Users\admin\Downloads\cs2103\tiredAndSadness` +
Edits the stored location of the 1st person to be `C:/Users/admin/Downloads/cs2103/tiredAndSadness/` respectively.

=== Finding a person : `find` (ZhiWei)
Expand Down Expand Up @@ -274,30 +274,47 @@ Or right click on timetable and select the reload page option.
Format: `add_timetable INDEX [fl/FILE_LOCATION]`

****
* add details of a timetable csv file to the person specified by `INDEX` from the stored folder of the person specified by `INDEX` if no file location is present.
* Adds details of a timetable csv file to the person specified by the `INDEX` from file location if file location is present.
* Add the timetable at the specified `INDEX`.
* Existing values will be updated to the input values.
* timings are start time of the event. Eg. if timetable shows 0800, it means the event is from 0800 to 0900.
* The index refers to the index number shown in the displayed person list.
* The index *must be a positive integer* 1, 2, 3, ...
* Will not be able to add if timetable is not present in the stored location of person specified by `INDEX`
****

Examples:
Example (user does not provide a file path):

* `add_timetable 1`
* add_timetable will add timetable from the given csv file from the person specified by the `INDEX` from file location if file location is present. If not, NUSHangs will throw an error message if the file cannot be found from the given (typed) file path
* Will not be able to add if timetable is not present in the stored location of person specified by `INDEX`

Example (user provides a file path):

* `add_timetable 1 fl/C:\Users\timetable\timetable.csv`

* FOR WINDOWS:
** `add_timetable fl/C:\Users\timetable\timetable.csv` (absolute pathing) or
** `add_timetable fl/timetable.csv` (relative pathing - if you save the .csv file in the same directory as the .jar file).
* FOR MAC:
** `add_timetable 1 fl//FILEPATH` (absolute pathing - note the double slashes) or
** `add_timetable 1 fl/timetable.csv` (relative pathing).
* add_timetable will add timetable from the given csv file.
* the first row and first column should be left alone
* can only edit in given rows and columns of the timetable.
* any invalid timetable will be ignored.
* example of correctly formatted timetable is given below

image::add_timetable_fl.png[width="700"]

=== Editing a timetable: `edit_timetable`
Edits a timetable timeslot of the timetable from the person specified by the `INDEX`. +
Format: `add_timetable INDEX day/DAY timing/TIMING [m/DETAILS] `
Format: `edit_timetable INDEX day/DAY timing/TIMING [m/DETAILS]`

****
* timings are in 24h format from 0800 to 2300.
* timings are start time of the event. Eg. if timetable shows 0800, it means the event is from 0800 to 0900.
* Existing values will be overwritten by the input details.
* days are days of a week in *full name(case insensitive)* from Monday to Friday.
* edit the timetable at the specified `INDEX`.
* can only edit 1 hour timeslot at a time.
* The index refers to the index number shown in the displayed person list.
* The index *must be a positive integer* 1, 2, 3, ...
****
Expand All @@ -318,6 +335,7 @@ Format: `download_timetable INDEX `
* The index refers to the index number shown in the displayed person list.
* The index *must be a positive integer* 1, 2, 3, ...
* Will not download if there is a file with same filename as the filename of the timetable from the person specified by the `INDEX`.
* Will not download if there is no such folder to download the timetable csv file given by the file location from the person specified by the `INDEX`.
****

Examples:
Expand Down Expand Up @@ -585,13 +603,13 @@ e.g. `list 1`
* *redo*
* *history*: Lists all the commands that you have entered in reverse chronological order.
* *add_timetable*: `add_timetable INDEX [fl/FILE_LOCATION]` +
e.g. `add_timetable 1`
e.g. `add_timetable 1 fl/C:\Users\timetable\timetable.csv`
* *edit_timetable*: `edit_timetable INDEX day/DAY timing/TIMING [m/DETAILS]` +
e.g. `edit_timetable 1 day/wednesday timing/1800 m/do cs2103`
* *download_timetable* : `download_timetable INDEX` +
e.g. `download_timetable 1 l/C://Users/abc/mysecretstash`
* *delete_timetable* : `delete INDEX p/password` +
e.g. `delete_timetable 3 p/password`
e.g. `download_timetable 1`
* *delete_timetable* : `delete_timetable INDEX` +
e.g. `delete_timetable 3`
* *add_group*: `add_group n/GROUPNAME [d/GROUPDESCRIPTION]`` +
e.g. `add_group n/happyfriends d/a group of happy friends`
* *edit_group* : `edit_group OLDGROUPNAME [n/NEWGROUPNAME] [d/NEWGROUPDESCRIPTION]` +
Expand Down
Binary file added docs/images/add_timetable_fl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ public class Messages {
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_DAY = "Days are in full name, from Monday to Friday";
public static final String MESSAGE_INVALID_TIMING = "timings are in 24h format and is from 0800 to 2300";
public static final String MESSAGE_INVALID_DAY_AND_TIMING = MESSAGE_INVALID_DAY + "\n" + MESSAGE_INVALID_TIMING;
public static final String MESSAGE_INVALID_DAY_AND_TIMING =
MESSAGE_INVALID_DAY + "\n" + MESSAGE_INVALID_TIMING;
public static final String MESSAGE_INVALID_FILE_EXTENSION = "timetable can only be in csv";
public static final String MESSAGE_INVALID_FILE_PATH = "That is not a valid file path";
public static final String MESSAGE_NO_MATCH_TO_EXISTING_GROUP = "There is no match to an existing group.";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_GROUPS_LISTED_OVERVIEW = "%1$d groups listed!";
public static final String MESSAGE_TIMETABLE_NOT_FOUND = "timetable to be added is not found";
public static final String MESSAGE_USER_NOT_LOGGED_IN = "Please login or create an account to continue.";
public static final String MESSAGE_USER_ALREADY_LOGGED_IN = "User is already logged in.";
public static final String MESSAGE_NOT_UNIQUE_PREFIX_INPUT = "can only enter 1 input per prefix";
public static final String MESSAGE_IS_FILE_DIRECTORY = "timetable cannot be a file directory(folder)";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
* it creates a new person with a default timetable while not changing other details of person
* Creates and returns a {@code Person} with the details of {@code personToEdit}
*/
private Person createPersonWithNewTimetable(Person personToEdit) {
assert personToEdit != null;
private Person createPersonWithNewTimetable(Person personToDeleteTimetable) {
assert personToDeleteTimetable != null;

Name updatedName = personToEdit.getName();
Phone updatedPhone = personToEdit.getPhone();
Email updatedEmail = personToEdit.getEmail();
Address updatedAddress = personToEdit.getAddress();
Set<Tag> updatedTags = personToEdit.getTags();
Name updatedName = personToDeleteTimetable.getName();
Phone updatedPhone = personToDeleteTimetable.getPhone();
Email updatedEmail = personToDeleteTimetable.getEmail();
Address updatedAddress = personToDeleteTimetable.getAddress();
Set<Tag> updatedTags = personToDeleteTimetable.getTags();
String storedLocation = personToDeleteTimetable.getStoredLocation();

UniqueList<Group> uniqueGroupList = new UniqueList<>();
uniqueGroupList.setElements(personToEdit.getGroups());
uniqueGroupList.setElements(personToDeleteTimetable.getGroups());

return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags,
uniqueGroupList, null, null);
uniqueGroupList, storedLocation, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class DownloadTimetableCommand extends Command {
public static final String MESSAGE_DOWNLOAD_TIMETABLE_SUCCESS = "timetable downloaded successfully to : ";
public static final String MESSAGE_TIMETABLE_IS_PRESENT =
"there is a csv file with same name as your timetable filename at: ";
public static final String MESSAGE_INVALID_FILE_PATH_DOWNLOAD = "That is not a valid file path,"
+ " as there is no such folder present: ";
private final Index index;

/**
Expand All @@ -54,7 +56,13 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
}

Person personToDownloadTimetable = lastShownList.get(index.getZeroBased());
boolean doesFileExists = new File(personToDownloadTimetable.getStoredLocation()).exists();
File timetableToDownload = new File(personToDownloadTimetable.getStoredLocation());
boolean doesFileExists = timetableToDownload.exists();
boolean doesFolderExists = new File(timetableToDownload.getParent()).exists();
if (!doesFolderExists) {
throw new CommandException(
MESSAGE_INVALID_FILE_PATH_DOWNLOAD + timetableToDownload.getParent());
}
if (doesFileExists) {
throw new CommandException(
MESSAGE_TIMETABLE_IS_PRESENT + personToDownloadTimetable.getStoredLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ public class EditTimetableCommand extends Command {
+ "for the timeslot in the timetable"
+ " \n"
+ "Parameters : INDEX (must be a positive integer) "
+ "[" + PREFIX_DAY + "DAY] "
+ "[" + PREFIX_TIMING + "TIMING] "
+ "[" + PREFIX_DETAILS + "DETAILS] "
+ PREFIX_DAY + "DAY"
+ PREFIX_TIMING + "TIMING "
+ PREFIX_DETAILS + "DETAILS "
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_DAY + "Wednesday "
+ PREFIX_TIMING + "1700 "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.commons.core.Messages.MESSAGE_NOT_UNIQUE_PREFIX_INPUT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FILE_LOCATION;

import seedu.address.commons.core.index.Index;
Expand Down Expand Up @@ -35,12 +34,8 @@ public AddTimetableCommand parse(String args) throws ParseException {
}

if (argMultimap.getValue(PREFIX_FILE_LOCATION).isPresent()) {
if (argMultimap.isOnlyOnePrefix(PREFIX_FILE_LOCATION)) {
newFilePath = ParserUtil
.parseLocation(argMultimap.getValue(PREFIX_FILE_LOCATION).get());
} else {
throw new ParseException(MESSAGE_NOT_UNIQUE_PREFIX_INPUT);
}
newFilePath = ParserUtil
.parseLocation(argMultimap.getValue(PREFIX_FILE_LOCATION).get());
}
return new AddTimetableCommand(index, newFilePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ public List<String> getAllValues(Prefix prefix) {
return new ArrayList<>(argMultimap.get(prefix));
}

/**
* checks if there argMultimap contains only 1 prefix for each input by the user
* returns true if there is only 1.
*/
public boolean isOnlyOnePrefix(Prefix prefix) {
int noOfInput = this.getAllValues(prefix).size();
return noOfInput == 1;
}

/**
* Returns the preamble (text before the first valid prefix). Trims any leading/trailing
* spaces.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.commons.core.Messages.MESSAGE_NOT_UNIQUE_PREFIX_INPUT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAY;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DETAILS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIMING;
Expand Down Expand Up @@ -39,17 +38,12 @@ public EditTimetableCommand parse(String args) throws ParseException {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditTimetableCommand.MESSAGE_USAGE));
}
if (!argMultimap.isOnlyOnePrefix(PREFIX_DAY) || !argMultimap
.isOnlyOnePrefix(PREFIX_TIMING)) {
throw new ParseException(String.format(MESSAGE_NOT_UNIQUE_PREFIX_INPUT));
}
ParserUtil.checkBothDayAndTiming(argMultimap.getValue(PREFIX_DAY).get(),
argMultimap.getValue(PREFIX_TIMING).get());
String day = ParserUtil.parseDay(argMultimap.getValue(PREFIX_DAY).get());
String timing = ParserUtil.parseTiming(argMultimap.getValue(PREFIX_TIMING).get());
String details = " ";
if (argMultimap.getValue(PREFIX_DETAILS).isPresent() && argMultimap
.isOnlyOnePrefix(PREFIX_DETAILS)) {
if (argMultimap.getValue(PREFIX_DETAILS).isPresent()) {
details = ParserUtil.parseDetails(argMultimap.getValue(PREFIX_DETAILS).get());
}
return new EditTimetableCommand(index, day, timing, details);
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_FILE_EXTENSION;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_FILE_PATH;
import static seedu.address.commons.core.Messages.MESSAGE_IS_FILE_DIRECTORY;

import java.io.File;
Expand Down Expand Up @@ -166,13 +165,6 @@ public static String parseLocation(String location) throws ParseException {
String fileExtension = FilenameUtils.getExtension(trimmedLocation);
if ("csv".equals(fileExtension)) {
File timetable = new File(trimmedLocation);
if (timetable.getParent() == null) {
throw new ParseException(MESSAGE_INVALID_FILE_PATH);
}
File timetableParent = new File(timetable.getParent());
if (!timetableParent.exists() || !timetableParent.isDirectory()) {
throw new ParseException(MESSAGE_INVALID_FILE_PATH);
}
if (timetable.isDirectory()) {
throw new ParseException(MESSAGE_IS_FILE_DIRECTORY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.DownloadTimetableCommand.MESSAGE_INVALID_FILE_PATH_DOWNLOAD;
import static seedu.address.logic.commands.DownloadTimetableCommand.MESSAGE_TIMETABLE_IS_PRESENT;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;

import seedu.address.logic.CommandHistory;
Expand Down Expand Up @@ -59,4 +62,27 @@ void downloadTimetableDuplicateFailure() {
MESSAGE_TIMETABLE_IS_PRESENT + personToDownloadTimetable.getStoredLocation());
assertTrue(new File(personToDownloadTimetable.getStoredLocation()).exists());
}

@Test
void downloadTimetableFolderNotFoundFailure() {
Person personToDownloadTimetable = model.getFilteredPersonList()
.get(INDEX_FIRST.getZeroBased());
File timetable = new File(personToDownloadTimetable.getStoredLocation());
if (timetable.exists()) {
timetable.delete();
}
File timetableParent = new File(timetable.getParent());
if (timetableParent.exists()) {
try {
FileUtils.deleteDirectory(timetableParent);
} catch (IOException e) {
e.printStackTrace();
}
}
DownloadTimetableCommand downloadTimetableCommand = new DownloadTimetableCommand(
INDEX_FIRST);
assertCommandFailure(downloadTimetableCommand, model, commandHistory,
MESSAGE_INVALID_FILE_PATH_DOWNLOAD + timetable.getParent());
timetableParent.mkdirs(); //create the directory back.
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package seedu.address.logic.parser;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_FILE_EXTENSION;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_FILE_PATH;
import static seedu.address.commons.core.Messages.MESSAGE_IS_FILE_DIRECTORY;
import static seedu.address.commons.core.Messages.MESSAGE_NOT_UNIQUE_PREFIX_INPUT;

import static seedu.address.logic.parser.CliSyntax.PREFIX_FILE_LOCATION;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
Expand Down Expand Up @@ -67,24 +64,6 @@ public void parseAddTimetableWithValidFileLocationSuccess() {
assertParseSuccess(parser, userInput, addTimetableCommand);
}

@Test
public void parseAddTimetableWithInvalidFilePathFailure() {
String targetIndex = INDEX_SECOND.getOneBased() + " ";
String fileLocation = DEFAULT_STORED_INVALID_TIMETABLE_LOCATION + "/test/test.csv";
String expectedMessage = MESSAGE_INVALID_FILE_PATH;
String userInput = targetIndex + PREFIX_FILE_LOCATION + fileLocation;
assertParseFailure(parser, userInput, expectedMessage);
}

@Test
public void parseAddTimetableWithNoDirFilePathFailure() {
String targetIndex = INDEX_SECOND.getOneBased() + " ";
String fileLocation = "gg.csv";
String expectedMessage = MESSAGE_INVALID_FILE_PATH;
String userInput = targetIndex + PREFIX_FILE_LOCATION + fileLocation;
assertParseFailure(parser, userInput, expectedMessage);
}

@Test
public void parseAddTimetableWithInvalidFileExtension() {
String targetIndex = INDEX_SECOND.getOneBased() + " ";
Expand All @@ -109,20 +88,5 @@ public void parse_addTimetableWithAFileDirectory_failure() {
timetable.delete();
}

@Test
public void parseAddTimetableWithTwoFileLocationFailure() {
String targetIndex = INDEX_SECOND.getOneBased() + " ";
String fileLocation = BOB.getStoredLocation();
String expectedMessage = MESSAGE_NOT_UNIQUE_PREFIX_INPUT;
File timetable = new File(BOB.getStoredLocation());
BOB.getTimetable().downloadTimetableAsCsv();
assertTrue(timetable.exists());
String userInput = targetIndex
+ PREFIX_FILE_LOCATION + fileLocation + " "
+ PREFIX_FILE_LOCATION + fileLocation;
assertParseFailure(parser, userInput, expectedMessage);
timetable.delete();
assertFalse(timetable.exists());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_DAY;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_DAY_AND_TIMING;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_TIMING;
import static seedu.address.commons.core.Messages.MESSAGE_NOT_UNIQUE_PREFIX_INPUT;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_DAY_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TIMING_AND_DAY_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TIMING_DESC;
Expand Down Expand Up @@ -132,14 +131,4 @@ public void parseNoDetailsSuccess() {
"0900", " ");
assertParseSuccess(parser, userInput, expectedCommand);
}

@Test
public void parseEditTimetableWithTwoInputsFailure() {
Index targetIndex = INDEX_SECOND;
String userInput = targetIndex.getOneBased() + VALID_EDIT_TIMETABLE_COMMAND_WITH_DETAILS
+ " " + PREFIX_DAY + VALID_DAY;
String expectedMessage = MESSAGE_NOT_UNIQUE_PREFIX_INPUT;
assertParseFailure(parser, userInput, expectedMessage);

}
}

0 comments on commit fff970c

Please sign in to comment.