From 27a29569ef3897019da57528b2a6cc0aa6c743c0 Mon Sep 17 00:00:00 2001 From: souless94 Date: Wed, 31 Oct 2018 11:26:48 +0800 Subject: [PATCH 1/3] remove format = vertical for all relevant code --- build.gradle | 5 +- docs/Timetable.html | 81 ----------- .../logic/commands/AddTimetableCommand.java | 8 +- .../commands/DeleteTimetableCommand.java | 2 +- .../address/logic/commands/EditCommand.java | 19 +-- .../logic/commands/EditTimetableCommand.java | 5 +- .../logic/parser/AddCommandParser.java | 2 +- .../seedu/address/logic/parser/CliSyntax.java | 1 - .../logic/parser/EditCommandParser.java | 7 +- .../address/logic/parser/ParserUtil.java | 34 +---- .../seedu/address/model/person/Person.java | 18 +-- .../model/person/timetable/Timetable.java | 20 +-- .../model/person/timetable/TimetableData.java | 136 +++--------------- .../address/model/util/SampleDataUtil.java | 12 +- .../address/storage/XmlAdaptedPerson.java | 18 ++- .../java/seedu/address/ui/BrowserPanel.java | 29 ++++ src/main/resources/view/Timetable.html | 47 +++--- .../invalidAndValidPersonAddressBook.xml | 2 - .../duplicatePersonAddressBook.xml | 2 - .../invalidPersonAddressBook.xml | 1 - .../typicalPersonsAddressBook.xml | 7 - .../data/XmlUtilTest/validAddressBook.xml | 9 -- .../address/commons/util/XmlUtilTest.java | 7 +- .../person/timetable/TimetableDataTest.java | 8 +- .../address/storage/XmlAdaptedPersonTest.java | 19 ++- .../testutil/EditPersonDescriptorBuilder.java | 9 -- .../seedu/address/testutil/PersonBuilder.java | 7 +- .../seedu/address/ui/BrowserPanelTest.java | 4 +- .../seedu/address/ui/PersonListPanelTest.java | 3 +- 29 files changed, 143 insertions(+), 379 deletions(-) delete mode 100644 docs/Timetable.html diff --git a/build.gradle b/build.gradle index 8a9b3233ffaf..594f4f4422cf 100644 --- a/build.gradle +++ b/build.gradle @@ -67,6 +67,7 @@ dependencies { implementation group: 'com.sun.xml.bind', name: 'jaxb-core', version: '2.3.0' implementation group: 'javax.activation', name: 'activation', version: '1.1.1' implementation group: 'com.opencsv', name: 'opencsv' ,version: '4.3.2' + implementation group: 'org.jsoup', name: 'jsoup' ,version: '1.11.3' testImplementation group: 'junit', name: 'junit', version: '4.12' testImplementation group: 'org.testfx', name: 'testfx-core', version: testFxVersion, { @@ -83,7 +84,7 @@ dependencies { } shadowJar { - archiveName = 'addressbook.jar' + archiveName = 'nus Hangs.jar' destinationDir = file("${buildDir}/jar/") } @@ -238,7 +239,7 @@ task deployOfflineDocs(type: Copy) { } task copyTimetablePage(type: Copy) { - from 'docs/Timetable.html' + from 'src/main/resources/view/Timetable.html' into "${buildDir}/docs/html5" } diff --git a/docs/Timetable.html b/docs/Timetable.html deleted file mode 100644 index a0529d9bf047..000000000000 --- a/docs/Timetable.html +++ /dev/null @@ -1,81 +0,0 @@ - - - - - Timetable - - - - -
- - - diff --git a/src/main/java/seedu/address/logic/commands/AddTimetableCommand.java b/src/main/java/seedu/address/logic/commands/AddTimetableCommand.java index d6849605c8e7..2ac7229009f5 100644 --- a/src/main/java/seedu/address/logic/commands/AddTimetableCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddTimetableCommand.java @@ -36,9 +36,7 @@ public class AddTimetableCommand extends Command { public static final String MESSAGE_ADD_TIMETABLE_SUCCESS = "timetable added successfully: %1$s"; public static final String MESSAGE_INVALID_TIMETABLE_SIZE = "timetable to be added is wrong: \n" - + "if format is horizontal,timetable should have in total rows: 8 , columns : 17 \n" - + "if format is vertical,timetable should have in total rows: 17 , columns : 8 \n"; - + + "timetable should have in total rows: 8 , columns : 17 \n"; private static final String timings = "correctTimings : \n" + "0800,0900,1000,1100 \n" + "1200,1300,1400,1500,1600 \n" @@ -46,7 +44,7 @@ public class AddTimetableCommand extends Command { private static final String days = "correctDays: {Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday"; public static final String MESSAGE_INVALID_TIMETABLE = "timetable to be added is wrong: \n" - + "does not have correct timings or/and days present in first column or/and first row in the csv file \n" + + "does not have correct timings in first row and correct days in first column in the csv file \n" + timings + "\n" + days + "\n"; @@ -78,7 +76,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command } boolean doesFileExists = new File(filePath).exists(); if (doesFileExists) { - Timetable timetable = new Timetable(filePath, personToEdit.getFormat(), + Timetable timetable = new Timetable(filePath, personToEdit.getTimetable().getTimetableDataString(), 2, null, null, null); if (!timetable.isValid()) { if (!timetable.isCorrectSize()) { diff --git a/src/main/java/seedu/address/logic/commands/DeleteTimetableCommand.java b/src/main/java/seedu/address/logic/commands/DeleteTimetableCommand.java index 3f88d8743af4..4b10b118543a 100644 --- a/src/main/java/seedu/address/logic/commands/DeleteTimetableCommand.java +++ b/src/main/java/seedu/address/logic/commands/DeleteTimetableCommand.java @@ -77,7 +77,7 @@ private Person createPersonWithNewTimetable(Person personToEdit) { Address updatedAddress = personToEdit.getAddress(); Set updatedTags = personToEdit.getTags(); return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, - null, null, null); + null, null); } @Override diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index ae2d8742a56e..31c704889dd0 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -4,7 +4,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_FILE_LOCATION; -import static seedu.address.logic.parser.CliSyntax.PREFIX_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; @@ -46,7 +45,6 @@ public class EditCommand extends Command { + "[" + PREFIX_PHONE + "PHONE] " + "[" + PREFIX_EMAIL + "EMAIL] " + "[" + PREFIX_ADDRESS + "ADDRESS] " - + "[" + PREFIX_FORMAT + "ADDRESS] " + "[" + PREFIX_FILE_LOCATION + "ADDRESS] " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " @@ -107,7 +105,6 @@ public static Person createEditedPerson(Person personToEdit, Address updatedAddress = editPersonDescriptor.getAddress() .orElse(personToEdit.getAddress()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); - String format = editPersonDescriptor.getFormat().orElse(personToEdit.getFormat()); String storedLocation = editPersonDescriptor.getStoredLocation() .orElse(personToEdit.getStoredLocation()); String timetableString = personToEdit.getTimetable().getTimetableDataString(); @@ -115,8 +112,8 @@ public static Person createEditedPerson(Person personToEdit, UniqueList uniqueGroupList = new UniqueList<>(); uniqueGroupList.setElements(personToEdit.getGroups()); - return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, uniqueGroupList, - format, storedLocation, timetableString); + return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, + uniqueGroupList, storedLocation, timetableString); } @Override @@ -147,7 +144,6 @@ public static class EditPersonDescriptor { private Phone phone; private Email email; private Address address; - private String format; private String storedLocation; private Set tags; private List groupList; @@ -163,7 +159,6 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setPhone(toCopy.phone); setEmail(toCopy.email); setAddress(toCopy.address); - setFormat(toCopy.format); setStoredLocation(toCopy.storedLocation); setTags(toCopy.tags); setGroupList(toCopy.groupList); @@ -175,7 +170,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { */ public boolean isAnyFieldEdited() { return CollectionUtil - .isAnyNonNull(name, phone, email, address, tags, format, storedLocation); + .isAnyNonNull(name, phone, email, address, tags, storedLocation); } public void setStoredLocation(String storedLocation) { @@ -186,14 +181,6 @@ public Optional getStoredLocation() { return Optional.ofNullable(storedLocation); } - public void setFormat(String format) { - this.format = format; - } - - public Optional getFormat() { - return Optional.ofNullable(format); - } - public void setName(Name name) { this.name = name; } diff --git a/src/main/java/seedu/address/logic/commands/EditTimetableCommand.java b/src/main/java/seedu/address/logic/commands/EditTimetableCommand.java index 85e52e8120a9..e23696519458 100644 --- a/src/main/java/seedu/address/logic/commands/EditTimetableCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditTimetableCommand.java @@ -67,7 +67,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command requireNonNull(model); Person personToEdit = CommandUtil.retrievePersonFromIndex(model, index); String filePath = personToEdit.getStoredLocation(); - Timetable timetable = new Timetable(filePath, personToEdit.getFormat(), + Timetable timetable = new Timetable(filePath, personToEdit.getTimetable().getTimetableDataString(), 3, day, timing, details); Person updatedPerson = createUpdatedPerson(personToEdit, timetable, filePath); model.update(personToEdit, updatedPerson); @@ -89,12 +89,11 @@ public static Person createUpdatedPerson(Person personToEdit, Timetable timetabl Email updatedEmail = personToEdit.getEmail(); Address updatedAddress = personToEdit.getAddress(); Set updatedTags = personToEdit.getTags(); - String format = personToEdit.getFormat(); String storedLocation = filePath; String timetableString = timetable.getTimetableDataString(); return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, updatedTags, - format, storedLocation, timetableString); + storedLocation, timetableString); } @Override diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 9929752d9f05..640c23b4d044 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -49,7 +49,7 @@ public AddCommand parse(String args) throws ParseException { Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person person = new Person(name, phone, email, address, tagList, "default", "default", + Person person = new Person(name, phone, email, address, tagList, null, null); return new AddCommand(person); diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index d20ab923aa16..4ac58b6992ac 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -17,7 +17,6 @@ public class CliSyntax { public static final Prefix PREFIX_STORED_LOCATION = new Prefix("sl/"); public static final Prefix PREFIX_FILE_LOCATION = new Prefix("fl/"); - public static final Prefix PREFIX_FORMAT = new Prefix("f/"); public static final Prefix PREFIX_DESCRIPTION = new Prefix("d/"); public static final Prefix PREFIX_DAY = new Prefix("day/"); diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 68d4e1dbc1b0..0c8863037ca9 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -4,7 +4,6 @@ import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; import static seedu.address.logic.parser.CliSyntax.PREFIX_STORED_LOCATION; @@ -37,7 +36,7 @@ public EditCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer .tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG, - PREFIX_FORMAT, PREFIX_STORED_LOCATION); + PREFIX_STORED_LOCATION); Index index; @@ -65,10 +64,6 @@ public EditCommand parse(String args) throws ParseException { editPersonDescriptor .setAddress(ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get())); } - if (argMultimap.getValue(PREFIX_FORMAT).isPresent()) { - editPersonDescriptor - .setFormat(ParserUtil.parseFormat(argMultimap.getValue(PREFIX_FORMAT).get())); - } if (argMultimap.getValue(PREFIX_STORED_LOCATION).isPresent()) { editPersonDescriptor .setStoredLocation( diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 3230050a249c..e4b9775857a3 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -179,32 +179,6 @@ public static String parseLocation(String location) throws ParseException { return trimmedLocation; } - /** - * Parses a {@code String fileName} into an {@code String fileName}. Leading and trailing - * whitespaces will be trimmed. - * - * @throws ParseException if the given {@code fileName} is invalid. - */ - public static String parseFilename(String fileName) throws ParseException { - requireNonNull(fileName); - return fileName; - } - - /** - * Parses a {@code String format} into an {@code String format}. Leading and trailing - * whitespaces will be trimmed. - * - * @throws ParseException if the given {@code format} is invalid. - */ - public static String parseFormat(String format) throws ParseException { - requireNonNull(format); - if ("horizontal".equals(format) || "vertical".equals(format)) { - return format; - } else { - throw new ParseException(Messages.MESSAGE_INVALID_TIMETABLE_FORMAT); - } - } - /** * Parses a {@code String day} into an {@code String day}. Leading and trailing whitespaces will * be trimmed. checks if day is any of the days in a week. @@ -214,7 +188,7 @@ public static String parseFormat(String format) throws ParseException { public static String parseDay(String day) throws ParseException { requireNonNull(day); String trimmedDay = day.trim(); - String[] validDays = new TimetableData("horizontal", null, null, 1, null, null, null) + String[] validDays = new TimetableData(null, null, 1, null, null, null) .getDaysInLowerCase(); if (ArrayUtils.contains(validDays, trimmedDay.toLowerCase())) { return trimmedDay; @@ -232,7 +206,7 @@ public static String parseDay(String day) throws ParseException { public static String parseTiming(String timing) throws ParseException { requireNonNull(timing); String trimmedTiming = timing.trim(); - String[] validTiming = new TimetableData("horizontal", null, null, 1, null, null, null) + String[] validTiming = new TimetableData(null, null, 1, null, null, null) .getTimings(); if (ArrayUtils.contains(validTiming, trimmedTiming)) { return trimmedTiming; @@ -262,10 +236,10 @@ public static String parseDetails(String details) { public static void checkBothDayAndTiming(String day, String timing) throws ParseException { String trimmedDay = day.trim(); - String[] validDays = new TimetableData("horizontal", null, null, 1, null, null, null) + String[] validDays = new TimetableData(null, null, 1, null, null, null) .getDaysInLowerCase(); String trimmedTiming = timing.trim(); - String[] validTiming = new TimetableData("horizontal", null, null, 1, null, null, null) + String[] validTiming = new TimetableData(null, null, 1, null, null, null) .getTimings(); if (!ArrayUtils.contains(validDays, trimmedDay.toLowerCase()) && !ArrayUtils.contains(validTiming, trimmedTiming)) { diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 118071e1d466..2a3e27a43315 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -33,7 +33,6 @@ public class Person extends Entity { private final Address address; private final Timetable timetable; private final Set tags = new HashSet<>(); - private final String format; private final String storedLocation; private UniqueList groups; @@ -42,7 +41,7 @@ public class Person extends Entity { * as empty list. */ public Person(Name name, Phone phone, Email email, Address address, Set tags, - String format, String storedLocation, String timetableString) { + String storedLocation, String timetableString) { requireAllNonNull(name, phone, email, address, tags); this.name = name; this.phone = phone; @@ -52,11 +51,6 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.groups = new UniqueList<>(); this.tags.addAll(tags); - if (format == null) { - this.format = "horizontal"; - } else { - this.format = format; - } if (storedLocation == null) { String location = Paths.get("data", "timetable").toString(); File directory = new File(location); @@ -71,7 +65,6 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.storedLocation = storedLocation.replace("\\", "/"); } this.timetable = new Timetable(this.storedLocation, - this.format, timetableString, 1, null, null, null); } @@ -80,8 +73,8 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag */ public Person(Name name, Phone phone, Email email, Address address, Set tags, UniqueList groups, - String format, String storedLocation, String timetableString) { - Person temp = new Person(name, phone, email, address, tags, format, storedLocation, + String storedLocation, String timetableString) { + Person temp = new Person(name, phone, email, address, tags, storedLocation, timetableString); this.name = temp.getName(); @@ -89,7 +82,6 @@ public Person(Name name, Phone phone, Email email, Address address, Set tag this.email = temp.getEmail(); this.address = temp.getAddress(); this.tags.addAll(temp.getTags()); - this.format = temp.getFormat(); this.storedLocation = temp.getStoredLocation(); this.timetable = temp.getTimetable(); @@ -113,10 +105,6 @@ public Address getAddress() { return address; } - public String getFormat() { - return format; - } - public String getStoredLocation() { return storedLocation; } diff --git a/src/main/java/seedu/address/model/person/timetable/Timetable.java b/src/main/java/seedu/address/model/person/timetable/Timetable.java index f66a2c06c32a..1650859bf70e 100644 --- a/src/main/java/seedu/address/model/person/timetable/Timetable.java +++ b/src/main/java/seedu/address/model/person/timetable/Timetable.java @@ -12,7 +12,6 @@ public class Timetable extends Entity { // Identity fields private final String filePath; - private final String format; private final String timetableString; // create timetable data @@ -23,13 +22,12 @@ public class Timetable extends Entity { * Construct a timetable using the timetableString if option is 1 Construct a timetable using * the timetable csv file if option is 2 */ - public Timetable(String filePath, String format, + public Timetable(String filePath, String timetableString, int option, String day, String timing, String message) { this.filePath = filePath; - this.format = format; - this.matrix = new TimetableData(format, this.filePath, timetableString, + this.matrix = new TimetableData(this.filePath, timetableString, option, day, timing, message); - this.timetableString = getTimetableDataString(); + this.timetableString = generateTimetableDataString(); } /** @@ -57,10 +55,18 @@ public String getTimetableAsString() { return timetableString; } + /** * @return a timetable string for the xml storage */ public String getTimetableDataString() { + return this.timetableString; + } + + /** + * generate a timetable string for the xml storage + */ + private String generateTimetableDataString() { String timetableDataString = ""; String[][] timetableMatrix = this.matrix.getTimetable(); for (int i = 0; i < matrix.getRows(); i++) { @@ -78,10 +84,6 @@ public String getTimetableDataString() { return timetableDataString; } - public String getFormat() { - return this.format; - } - public TimetableData getTimetable() { return this.matrix; } diff --git a/src/main/java/seedu/address/model/person/timetable/TimetableData.java b/src/main/java/seedu/address/model/person/timetable/TimetableData.java index c2bac36d6705..e33b179b0802 100644 --- a/src/main/java/seedu/address/model/person/timetable/TimetableData.java +++ b/src/main/java/seedu/address/model/person/timetable/TimetableData.java @@ -31,7 +31,6 @@ public class TimetableData { private final int noOfDays = days.length; private final int noOfRows; private final int noOfColumns; - private final String format; private boolean isCorrectSize; private boolean hasCorrectFirstRowsAndColumns; @@ -39,22 +38,12 @@ public class TimetableData { * uses format and timetableString to create a matrix uses the day and time to find the cell of * the matrix to input the message */ - public TimetableData(String format, String filePath, String timetableString, int option, + public TimetableData(String filePath, String timetableString, int option, String day, String timing, String message) { - this.format = format; - int noOfRows = 0; - int noOfColumns = 0; - if ("vertical".equals(format)) { - noOfRows = noOfTimings; - noOfColumns = noOfDays; - } else if ("horizontal".equals(format)) { - noOfRows = noOfDays; - noOfColumns = noOfTimings; - } this.isCorrectSize = true; this.hasCorrectFirstRowsAndColumns = true; - this.noOfRows = noOfRows; - this.noOfColumns = noOfColumns; + this.noOfRows = noOfDays + 1; + this.noOfColumns = noOfTimings + 1; String[][] timetable; if (option == 1) { timetable = getTimetableFromString(timetableString); @@ -65,20 +54,13 @@ public TimetableData(String format, String filePath, String timetableString, int timetable = getTimetableFromString(timetableString); int rowToChange; int columnToChange; - if ("horizontal".equals(format)) { - rowToChange = ArrayUtils.indexOf(getDaysInLowerCase(), day.toLowerCase()) + 1; - columnToChange = ArrayUtils.indexOf(timings, timing) + 1; - timetable[rowToChange][columnToChange] = message; - } else if ("vertical".equals(format)) { - rowToChange = ArrayUtils.indexOf(timings, timing) + 1; - columnToChange = ArrayUtils.indexOf(getDaysInLowerCase(), day.toLowerCase()) + 1; - timetable[rowToChange][columnToChange] = message; - } - + rowToChange = ArrayUtils.indexOf(getDaysInLowerCase(), day.toLowerCase()) + 1; + columnToChange = ArrayUtils.indexOf(timings, timing) + 1; + timetable[rowToChange][columnToChange] = message; } this.timetable = timetable; - checkTimetableForCorrectRowsAndColumns(this.format); - this.booleanTimetable = booleanTimetableData(format, this.timetable); + checkTimetableForCorrectRowsAndColumns(); + this.booleanTimetable = booleanTimetableData(this.timetable); } /** @@ -86,7 +68,7 @@ public TimetableData(String format, String filePath, String timetableString, int */ private String[][] getTimetableFromString(String timetableString) { String[][] timetableMatrix = createNewTimetable(); - if (timetableString == null) { + if (timetableString == null || timetableString.equals("")) { return timetableMatrix; } else { String[] rows = timetableString.split("\n"); @@ -117,11 +99,11 @@ public String[] getDaysInLowerCase() { } public int getRows() { - return this.noOfRows + 1; + return this.noOfRows; } public int getColumns() { - return this.noOfColumns + 1; + return this.noOfColumns; } /** @@ -131,7 +113,6 @@ public int getColumns() { */ public String[][] getTimetableData(String storedLocation) { String[][] timetableMatrix = createNewTimetable(); - timetableMatrix[0][0] = this.format; File toRead = new File(storedLocation); if (toRead.exists()) { timetableMatrix = readTimetableData(storedLocation, timetableMatrix); @@ -194,20 +175,14 @@ private String[][] createNewMatrix() { */ private String[][] createNewTimetable() { String[][] timetable = createNewMatrix(); - - timetable[0][0] = this.format; - if ("horizontal".equals(this.format)) { - fillHorizontalTimetableData(timetable); - } else if ("vertical".equals(this.format)) { - fillVerticalTimetableData(timetable); - } + fillTimetableData(timetable); return timetable; } /** * set first row of timetable to be timings and set first column of timetable to be days */ - private void fillHorizontalTimetableData(String[][] timetable) { + private void fillTimetableData(String[][] timetable) { // set first column to be days for (int i = 1; i < this.getRows(); i++) { timetable[i][0] = days[i - 1]; @@ -219,64 +194,9 @@ private void fillHorizontalTimetableData(String[][] timetable) { } /** - * set first row of timetable to be days and set first column of timetable to be timings + * to check Timetable for correct first row and column */ - private void fillVerticalTimetableData(String[][] timetable) { - // set first row to be days - for (int i = 1; i < this.getColumns(); i++) { - timetable[0][i] = days[i - 1]; - } - // set first column to be timings - for (int j = 1; j < this.getRows(); j++) { - timetable[j][0] = timings[j - 1]; - } - } - - /** - * checks if timetable has correct rows and columns - */ - private void checkTimetableForCorrectRowsAndColumns(String format) { - if (isCorrectSize) { - if ("vertical".equals(format)) { - checkVerticalTimetableForCorrectRowsAndColumns(); - } else if ("horizontal".equals(format)) { - checkHorizontalTimetableForCorrectRowsAndColumns(); - } - } - } - - /** - * to check verticalTimetable for correct first row and column - */ - private void checkVerticalTimetableForCorrectRowsAndColumns() { - String[] firstRow = this.timetable[0]; - if (!this.timetable[1][0].equals(timings[0]) - || !this.timetable[1][0].equals("800")) { - this.hasCorrectFirstRowsAndColumns = false; - } - if (!this.timetable[2][0].equals(timings[1]) - || !this.timetable[2][0].equals("900")) { - this.hasCorrectFirstRowsAndColumns = false; - } - for (int i = 1; i < getColumns(); i++) { - String firstRowEntry = firstRow[i]; - if (!firstRowEntry.equals(days[i - 1])) { - this.hasCorrectFirstRowsAndColumns = false; - } - } - for (int j = 3; j < getRows(); j++) { - String firstColumnEntry = this.timetable[j][0]; - if (!firstColumnEntry.equals(timings[j - 1])) { - this.hasCorrectFirstRowsAndColumns = false; - } - } - - } - - /** - * to check HorizontalTimetable for correct first row and column - */ - private void checkHorizontalTimetableForCorrectRowsAndColumns() { + private void checkTimetableForCorrectRowsAndColumns() { String[] firstRow = this.timetable[0]; if (!firstRow[1].equals(timings[0]) && !firstRow[1].equals("800")) { @@ -366,26 +286,14 @@ public void downloadTimetableDataAsCsv(String locationTo) { * * @return a boolean 2D array */ - public boolean[][] booleanTimetableData(String format, String[][] timetable) { + public boolean[][] booleanTimetableData(String[][] timetable) { boolean[][] booleanTimetable = new boolean[noOfTimings + 1][noOfTimings + 1]; - if (format.equals("vertical")) { - for (int i = 1; i <= this.noOfColumns; i++) { - for (int j = 1; j <= this.noOfRows; j++) { - if (timetable[i][j].equals(" ")) { - booleanTimetable[i][j] = true; - } else { - booleanTimetable[i][j] = false; - } - } - } - } else if (format.equals("horizontal")) { - for (int i = 1; i <= this.noOfRows; i++) { - for (int j = 1; j <= this.noOfColumns; j++) { - if (timetable[i][j].equals(" ")) { - booleanTimetable[j][i] = true; - } else { - booleanTimetable[j][i] = false; - } + for (int i = 1; i < this.noOfRows; i++) { + for (int j = 1; j < this.noOfColumns; j++) { + if (timetable[i][j].equals(" ")) { + booleanTimetable[j][i] = true; + } else { + booleanTimetable[j][i] = false; } } } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index 389261bd3907..2fe695b3df48 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -23,27 +23,27 @@ public static Person[] getSamplePersons() { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), - getTagSet("friends"), null, null, null), + getTagSet("friends"), null, null), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), - getTagSet("colleagues", "friends"), null, null, null), + getTagSet("colleagues", "friends"), null, null), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), - getTagSet("neighbours"), null, null, null), + getTagSet("neighbours"), null, null), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), - getTagSet("family"), null, null, null), + getTagSet("family"), null, null), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), - getTagSet("classmates"), null, null, null), + getTagSet("classmates"), null, null), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), - getTagSet("colleagues"), null, null, null) + getTagSet("colleagues"), null, null) }; } diff --git a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java index 7f986aae2751..d2e76880289d 100644 --- a/src/main/java/seedu/address/storage/XmlAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/XmlAdaptedPerson.java @@ -17,6 +17,7 @@ import seedu.address.model.person.Name; import seedu.address.model.person.Person; import seedu.address.model.person.Phone; +import seedu.address.model.person.timetable.Timetable; import seedu.address.model.tag.Tag; /** @@ -35,12 +36,9 @@ public class XmlAdaptedPerson { @XmlElement(required = true) private String address; @XmlElement(required = true) - private String format; - @XmlElement(required = true) private String storedLocation; @XmlElement(required = true) private String timetableString; - @XmlElement private List tagged = new ArrayList<>(); @@ -58,12 +56,11 @@ public XmlAdaptedPerson() { * different constructors */ public XmlAdaptedPerson(String name, String phone, String email, String address, - List tagged, String format, String storedLocation, String timetableString) { + List tagged, String storedLocation, String timetableString) { this.name = name; this.phone = phone; this.email = email; this.address = address; - this.format = format; this.storedLocation = storedLocation; this.timetableString = timetableString; if (tagged != null) { @@ -79,12 +76,11 @@ public XmlAdaptedPerson(String name, String phone, String email, String address, */ public XmlAdaptedPerson(String name, String phone, String email, String address, List groups, - List tagged, String format, String storedLocation, String timetableString) { + List tagged, String storedLocation, String timetableString) { this.name = name; this.phone = phone; this.email = email; this.address = address; - this.format = format; this.storedLocation = storedLocation; this.timetableString = timetableString; if (tagged != null) { @@ -105,7 +101,6 @@ public XmlAdaptedPerson(Person source) { phone = source.getPhone().value; email = source.getEmail().value; address = source.getAddress().value; - format = source.getFormat(); storedLocation = source.getStoredLocation(); timetableString = source.getTimetable().getTimetableDataString(); tagged = source.getTags().stream() @@ -172,9 +167,12 @@ public Person toModelType() throws IllegalValueException { final UniqueList modelGroupList = new UniqueList<>(); modelGroupList.setElements(groupList); - + if (timetableString == null) { + throw new IllegalValueException( + String.format(MISSING_FIELD_MESSAGE_FORMAT, Timetable.class.getSimpleName())); + } return new Person(modelName, modelPhone, modelEmail, modelAddress, modelTags, - modelGroupList, format, + modelGroupList, storedLocation, timetableString); } diff --git a/src/main/java/seedu/address/ui/BrowserPanel.java b/src/main/java/seedu/address/ui/BrowserPanel.java index f01c4f6ed530..436340f9c3d6 100644 --- a/src/main/java/seedu/address/ui/BrowserPanel.java +++ b/src/main/java/seedu/address/ui/BrowserPanel.java @@ -10,6 +10,7 @@ import javafx.fxml.FXML; import javafx.scene.layout.Region; import javafx.scene.web.WebView; + import seedu.address.MainApp; import seedu.address.commons.core.LogsCenter; import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent; @@ -41,6 +42,34 @@ public BrowserPanel() { registerAsAnEventHandler(this); } + + /* + import java.io.IOException; + import java.net.URL; + import java.util.logging.Logger; + + import org.jsoup.Jsoup; + import org.jsoup.nodes.Document; + import org.jsoup.nodes.Element; + + import com.google.common.base.Charsets; + import com.google.common.eventbus.Subscribe; + import com.google.common.io.Resources; + Loads the Timetable.html file with the timetable of the person selected for jar + private void loadPersonPage(Person person) { + URL timetablePage = MainApp.class.getResource(FXML_FILE_FOLDER + SEARCH_PAGE_URL); + try { + String location = Resources.toString(timetablePage, Charsets.UTF_8); + Document document = Jsoup.parse(location, "UTF-8"); + Element element = document.getElementById("timetable"); + element.attr("value", person.getTimetable().getTimetableAsString()); + Platform.runLater(() -> browser.getEngine().loadContent(document.toString())); + } catch (IOException e) { + loadPage(timetablePage.toExternalForm()); + e.printStackTrace(); + } + } + */ private void loadPersonPage(Person person) { URL defaultPage = MainApp.class.getResource(FXML_FILE_FOLDER + SEARCH_PAGE_URL); String timetableString = person.getTimetable().getTimetableAsString(); diff --git a/src/main/resources/view/Timetable.html b/src/main/resources/view/Timetable.html index e79171ba7f8d..11f8e012b15b 100644 --- a/src/main/resources/view/Timetable.html +++ b/src/main/resources/view/Timetable.html @@ -3,17 +3,17 @@ Dummy Search Page + + + + +

- -
diff --git a/src/test/data/XmlAddressBookStorageTest/invalidAndValidPersonAddressBook.xml b/src/test/data/XmlAddressBookStorageTest/invalidAndValidPersonAddressBook.xml index f784d80ccc2b..43ce94c2708b 100644 --- a/src/test/data/XmlAddressBookStorageTest/invalidAndValidPersonAddressBook.xml +++ b/src/test/data/XmlAddressBookStorageTest/invalidAndValidPersonAddressBook.xml @@ -6,7 +6,6 @@ 9482424 hans@example.com
4th street
- @@ -16,7 +15,6 @@ 948asdf2424 hans@example.com
4th street
- diff --git a/src/test/data/XmlSerializableAddressBookTest/duplicatePersonAddressBook.xml b/src/test/data/XmlSerializableAddressBookTest/duplicatePersonAddressBook.xml index e77dd2ab2269..b45232899475 100644 --- a/src/test/data/XmlSerializableAddressBookTest/duplicatePersonAddressBook.xml +++ b/src/test/data/XmlSerializableAddressBookTest/duplicatePersonAddressBook.xml @@ -7,7 +7,6 @@ alice@example.com
123, Jurong West Ave 6, #08-111
friends - @@ -18,7 +17,6 @@ 94351253 pauline@example.com
4th street
- diff --git a/src/test/data/XmlSerializableAddressBookTest/invalidPersonAddressBook.xml b/src/test/data/XmlSerializableAddressBookTest/invalidPersonAddressBook.xml index bc0127789839..13d5b1cb1c8a 100644 --- a/src/test/data/XmlSerializableAddressBookTest/invalidPersonAddressBook.xml +++ b/src/test/data/XmlSerializableAddressBookTest/invalidPersonAddressBook.xml @@ -6,6 +6,5 @@ 9482424 hans@exam!32ple
4th street
- horizontal diff --git a/src/test/data/XmlSerializableAddressBookTest/typicalPersonsAddressBook.xml b/src/test/data/XmlSerializableAddressBookTest/typicalPersonsAddressBook.xml index 962914f6fb70..0474ec469c0c 100644 --- a/src/test/data/XmlSerializableAddressBookTest/typicalPersonsAddressBook.xml +++ b/src/test/data/XmlSerializableAddressBookTest/typicalPersonsAddressBook.xml @@ -7,7 +7,6 @@ alice@example.com
123, Jurong West Ave 6, #08-111
friends - @@ -18,7 +17,6 @@
311, Clementi Ave 2, #02-25
owesMoney friends - @@ -27,7 +25,6 @@ 95352563 heinz@example.com
wall street
- @@ -37,7 +34,6 @@ cornelia@example.com
10th street
friends - @@ -46,7 +42,6 @@ 9482224 werner@example.com
michegan ave
- @@ -55,7 +50,6 @@ 9482427 lydia@example.com
little tokyo
- @@ -64,7 +58,6 @@ 9482442 anna@example.com
4th street
- diff --git a/src/test/data/XmlUtilTest/validAddressBook.xml b/src/test/data/XmlUtilTest/validAddressBook.xml index 44a692851350..e3875bb6715f 100644 --- a/src/test/data/XmlUtilTest/validAddressBook.xml +++ b/src/test/data/XmlUtilTest/validAddressBook.xml @@ -5,7 +5,6 @@ 9482424 hans@example.com
4th street
- @@ -14,7 +13,6 @@ 87249245 ruth@example.com
81th street
- @@ -23,7 +21,6 @@ 95352563 heinz@example.com
wall street
- @@ -32,7 +29,6 @@ 87652533 cornelia@example.com
10th street
- @@ -41,7 +37,6 @@ 9482224 werner@example.com
michegan ave
- @@ -50,7 +45,6 @@ 9482427 lydia@example.com
little tokyo
- @@ -59,7 +53,6 @@ 9482442 anna@example.com
4th street
- @@ -68,7 +61,6 @@ 8482424 stefan@example.com
little india
- @@ -77,7 +69,6 @@ 8482131 hans@example.com
chicago ave
- diff --git a/src/test/java/seedu/address/commons/util/XmlUtilTest.java b/src/test/java/seedu/address/commons/util/XmlUtilTest.java index ec9ee2f8460e..ae56701c29f7 100644 --- a/src/test/java/seedu/address/commons/util/XmlUtilTest.java +++ b/src/test/java/seedu/address/commons/util/XmlUtilTest.java @@ -45,7 +45,6 @@ public class XmlUtilTest { private static final String VALID_ADDRESS = "4th street"; private static final List VALID_TAGS = Collections .singletonList(new XmlAdaptedTag("friends")); - private static final String VALID_FORMAT = "horizontal"; private static final String VALID_STORED_LOCATION = Paths.get("src", "test", "data", "timetable").toString() + "/"; private static final String VALID_TIMETABLE_STRING = "default"; @@ -89,7 +88,7 @@ public void xmlAdaptedPersonFromFile_fileWithMissingPersonField_validResult() th XmlAdaptedPerson actualPerson = XmlUtil.getDataFromFile( MISSING_PERSON_FIELD_FILE, XmlAdaptedPersonWithRootElement.class); XmlAdaptedPerson expectedPerson = new XmlAdaptedPerson( - null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_FORMAT, + null, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); assertEquals(expectedPerson, actualPerson); } @@ -99,7 +98,7 @@ public void xmlAdaptedPersonFromFile_fileWithInvalidPersonField_validResult() th XmlAdaptedPerson actualPerson = XmlUtil.getDataFromFile( INVALID_PERSON_FIELD_FILE, XmlAdaptedPersonWithRootElement.class); XmlAdaptedPerson expectedPerson = new XmlAdaptedPerson( - VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_FORMAT, + VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); assertEquals(expectedPerson, actualPerson); } @@ -109,7 +108,7 @@ public void xmlAdaptedPersonFromFile_fileWithValidPerson_validResult() throws Ex XmlAdaptedPerson actualPerson = XmlUtil.getDataFromFile( VALID_PERSON_FILE, XmlAdaptedPersonWithRootElement.class); XmlAdaptedPerson expectedPerson = new XmlAdaptedPerson( - VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_FORMAT, + VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); assertEquals(expectedPerson, actualPerson); } diff --git a/src/test/java/seedu/address/model/person/timetable/TimetableDataTest.java b/src/test/java/seedu/address/model/person/timetable/TimetableDataTest.java index 9eba5de5da13..9ca8ae930fe4 100644 --- a/src/test/java/seedu/address/model/person/timetable/TimetableDataTest.java +++ b/src/test/java/seedu/address/model/person/timetable/TimetableDataTest.java @@ -11,16 +11,16 @@ public class TimetableDataTest { private String timetableString = BOB.getTimetable().getTimetableDataString(); - private TimetableData timetableData = new TimetableData("horizontal", BOB.getStoredLocation(), + private TimetableData timetableData = new TimetableData(BOB.getStoredLocation(), timetableString, 1, null, null, null); - private TimetableData timetableDataWrongSize = new TimetableData("horizontal", + private TimetableData timetableDataWrongSize = new TimetableData( BOB.getStoredLocation(), "0700,800,900,1000," + timetableString, 1, null, null, null); private String wrongTimetableString = - "aG9yaXpvbnRhbA==,aG9yaXpvbnRhbA==," + timetableString.substring(26); - private TimetableData timetableDataWrongFirstRow = new TimetableData("horizontal", + "aG9yaXpvbnRhbA==,aG9yaXpvbnRhbA==," + timetableString.substring(5); + private TimetableData timetableDataWrongFirstRow = new TimetableData( BOB.getStoredLocation(), wrongTimetableString, 1, null, null, null); diff --git a/src/test/java/seedu/address/storage/XmlAdaptedPersonTest.java b/src/test/java/seedu/address/storage/XmlAdaptedPersonTest.java index a376b2b1d3cf..83971896b51a 100644 --- a/src/test/java/seedu/address/storage/XmlAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/XmlAdaptedPersonTest.java @@ -33,7 +33,6 @@ public class XmlAdaptedPersonTest { private static final List VALID_TAGS = BENSON.getTags().stream() .map(XmlAdaptedTag::new) .collect(Collectors.toList()); - private static final String VALID_FORMAT = "horizontal"; private static final String VALID_STORED_LOCATION = Paths .get("src", "test", "data").toString() + "/"; private static final String VALID_TIMETABLE_STRING = "default"; @@ -48,7 +47,7 @@ public void toModelType_validPersonDetails_returnsPerson() throws Exception { public void toModelType_invalidName_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = Name.MESSAGE_NAME_CONSTRAINTS; Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -56,7 +55,7 @@ public void toModelType_invalidName_throwsIllegalValueException() { @Test public void toModelType_nullName_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(null, VALID_PHONE, VALID_EMAIL, - VALID_ADDRESS, VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_ADDRESS, VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = String .format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()); Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); @@ -66,7 +65,7 @@ public void toModelType_nullName_throwsIllegalValueException() { public void toModelType_invalidPhone_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = Phone.MESSAGE_PHONE_CONSTRAINTS; Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -74,7 +73,7 @@ public void toModelType_invalidPhone_throwsIllegalValueException() { @Test public void toModelType_nullPhone_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, - VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = String .format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); @@ -84,7 +83,7 @@ public void toModelType_nullPhone_throwsIllegalValueException() { public void toModelType_invalidEmail_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_ADDRESS, - VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = Email.MESSAGE_EMAIL_CONSTRAINTS; Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -92,7 +91,7 @@ public void toModelType_invalidEmail_throwsIllegalValueException() { @Test public void toModelType_nullEmail_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, - VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = String .format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); @@ -102,7 +101,7 @@ public void toModelType_nullEmail_throwsIllegalValueException() { public void toModelType_invalidAddress_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, - VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = Address.MESSAGE_ADDRESS_CONSTRAINTS; Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); } @@ -110,7 +109,7 @@ public void toModelType_invalidAddress_throwsIllegalValueException() { @Test public void toModelType_nullAddress_throwsIllegalValueException() { XmlAdaptedPerson person = new XmlAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, - VALID_TAGS, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + VALID_TAGS, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); String expectedMessage = String .format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); Assert.assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); @@ -122,7 +121,7 @@ public void toModelType_invalidTags_throwsIllegalValueException() { invalidTags.add(new XmlAdaptedTag(INVALID_TAG)); XmlAdaptedPerson person = new XmlAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_ADDRESS, - invalidTags, VALID_FORMAT, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); + invalidTags, VALID_STORED_LOCATION, VALID_TIMETABLE_STRING); Assert.assertThrows(IllegalValueException.class, person::toModelType); } diff --git a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java index e87e45e85526..8e2a3bc5cd03 100644 --- a/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java +++ b/src/test/java/seedu/address/testutil/EditPersonDescriptorBuilder.java @@ -37,7 +37,6 @@ public EditPersonDescriptorBuilder(Person person) { descriptor.setEmail(person.getEmail()); descriptor.setAddress(person.getAddress()); descriptor.setTags(person.getTags()); - descriptor.setFormat(person.getFormat()); descriptor.setStoredLocation(person.getStoredLocation()); } @@ -49,14 +48,6 @@ public EditPersonDescriptorBuilder withName(String name) { return this; } - /** - * Sets the {@code format} of the {@code EditPersonDescriptor} that we are building. - */ - public EditPersonDescriptorBuilder withFormat(String format) { - descriptor.setFormat(format); - return this; - } - /** * Sets the {@code Phone} of the {@code EditPersonDescriptor} that we are building. */ diff --git a/src/test/java/seedu/address/testutil/PersonBuilder.java b/src/test/java/seedu/address/testutil/PersonBuilder.java index 8afd32025c2b..a8463c1bd65f 100644 --- a/src/test/java/seedu/address/testutil/PersonBuilder.java +++ b/src/test/java/seedu/address/testutil/PersonBuilder.java @@ -26,7 +26,6 @@ public class PersonBuilder { public static final String DEFAULT_PHONE = "85355255"; public static final String DEFAULT_EMAIL = "alice@gmail.com"; public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111"; - public static final String DEFAULT_FORMAT = "horizontal"; public static final String DEFAULT_STORED_LOCATION = Paths .get("src", "test", "data", "timetable").toString(); public static final String DEFAULT_STORED_INVALID_TIMETABLE_LOCATION = Paths @@ -49,7 +48,6 @@ public PersonBuilder() { email = new Email(DEFAULT_EMAIL); address = new Address(DEFAULT_ADDRESS); groups = new UniqueList<>(); - format = DEFAULT_FORMAT; storedLocation = DEFAULT_STORED_LOCATION + "/" + String.valueOf(this.hashCode()) + " timetable.csv"; File testDirectory = new File(DEFAULT_STORED_LOCATION); @@ -60,7 +58,7 @@ public PersonBuilder() { if (!wrongTimetableDirectory.exists()) { wrongTimetableDirectory.mkdirs(); } - timetable = new Timetable(storedLocation, format, DEFAULT_TIMETABLE_STRING, + timetable = new Timetable(storedLocation, DEFAULT_TIMETABLE_STRING, 1, null, null, null); timetableString = timetable.getTimetableDataString(); @@ -77,7 +75,6 @@ public PersonBuilder(Person personToCopy) { address = personToCopy.getAddress(); groups = new UniqueList<>(); groups.setElements(personToCopy.getGroups()); - format = personToCopy.getFormat(); storedLocation = personToCopy.getStoredLocation(); timetable = personToCopy.getTimetable(); timetableString = personToCopy.getTimetable().getTimetableDataString(); @@ -155,7 +152,7 @@ public PersonBuilder withGroups(List groupList) { * @return a person */ public Person build() { - return new Person(name, phone, email, address, tags, format, storedLocation, + return new Person(name, phone, email, address, tags, storedLocation, timetableString); } diff --git a/src/test/java/seedu/address/ui/BrowserPanelTest.java b/src/test/java/seedu/address/ui/BrowserPanelTest.java index ad6e436bac78..1e75db00768e 100644 --- a/src/test/java/seedu/address/ui/BrowserPanelTest.java +++ b/src/test/java/seedu/address/ui/BrowserPanelTest.java @@ -15,6 +15,7 @@ import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent; public class BrowserPanelTest extends GuiUnitTest { + private PersonPanelSelectionChangedEvent selectionChangedEventStub; private BrowserPanel browserPanel; @@ -40,7 +41,8 @@ public void display() throws Exception { /* // associated web page of a person postNow(selectionChangedEventStub); - URL expectedPersonUrl = new URL(BrowserPanel.SEARCH_PAGE_URL); + URL expectedPersonUrl = MainApp.class.getResource(BrowserPanel.SEARCH_PAGE_URL); + waitUntilBrowserLoaded(browserPanelHandle); assertEquals(expectedPersonUrl, browserPanelHandle.getLoadedUrl()); diff --git a/src/test/java/seedu/address/ui/PersonListPanelTest.java b/src/test/java/seedu/address/ui/PersonListPanelTest.java index 30da16adb87e..697df4b6de1f 100644 --- a/src/test/java/seedu/address/ui/PersonListPanelTest.java +++ b/src/test/java/seedu/address/ui/PersonListPanelTest.java @@ -104,10 +104,9 @@ private Path createXmlFileWithPersons(int personCount) throws Exception { builder.append("000\n"); builder.append("a@aa\n"); builder.append("
a
\n"); - builder.append("horizontal\n"); builder.append("default\n"); builder.append( - "aG9yaXpvbnRhbA==,MDgwMA==,MDkwMA==,MTAwMA==,MTEwMA==,MTIwMA==,MTMwMA==," + "IA==,MDgwMA==,MDkwMA==,MTAwMA==,MTEwMA==,MTIwMA==,MTMwMA==," + "MTQwMA==,MTUwMA==,MTYwMA==,MTcwMA==,MTgwMA==,MTkwMA==,MjAwMA==,MjEwMA==,MjIwMA==,MjMwMA==\n" + "TW9uZGF5,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==\n" + "VHVlc2RheQ==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==,IA==\n" From ebad8b770adb855ecee658f55472653cfa9b78bf Mon Sep 17 00:00:00 2001 From: souless94 Date: Wed, 31 Oct 2018 11:40:05 +0800 Subject: [PATCH 2/3] remove format in personcardhandle --- src/test/java/guitests/guihandles/PersonCardHandle.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/guitests/guihandles/PersonCardHandle.java b/src/test/java/guitests/guihandles/PersonCardHandle.java index e66f94474a58..99c4ffec6fc9 100644 --- a/src/test/java/guitests/guihandles/PersonCardHandle.java +++ b/src/test/java/guitests/guihandles/PersonCardHandle.java @@ -21,7 +21,6 @@ public class PersonCardHandle extends NodeHandle { private static final String PHONE_FIELD_ID = "#phone"; private static final String EMAIL_FIELD_ID = "#email"; private static final String TAGS_FIELD_ID = "#tags"; - private static final String FORMAT_FIELD_ID = "#format"; private final Label idLabel; private final Label nameLabel; From d81f1d785bcc5042da24f21e1db3edafbd84cc82 Mon Sep 17 00:00:00 2001 From: souless94 Date: Wed, 31 Oct 2018 13:07:47 +0800 Subject: [PATCH 3/3] updated browser panel --- docs/onlineTimetable.html | 82 ++++++++++++++++ .../java/seedu/address/ui/BrowserPanel.java | 94 +++++++++++++------ src/main/resources/view/Timetable.html | 8 +- .../seedu/address/ui/BrowserPanelTest.java | 9 +- 4 files changed, 155 insertions(+), 38 deletions(-) create mode 100644 docs/onlineTimetable.html diff --git a/docs/onlineTimetable.html b/docs/onlineTimetable.html new file mode 100644 index 000000000000..85b7a8150828 --- /dev/null +++ b/docs/onlineTimetable.html @@ -0,0 +1,82 @@ + + + + + Dummy Search Page + + + + +

+ + +
+ + + diff --git a/src/main/java/seedu/address/ui/BrowserPanel.java b/src/main/java/seedu/address/ui/BrowserPanel.java index 436340f9c3d6..4dbd931e6261 100644 --- a/src/main/java/seedu/address/ui/BrowserPanel.java +++ b/src/main/java/seedu/address/ui/BrowserPanel.java @@ -1,9 +1,18 @@ package seedu.address.ui; +import java.io.IOException; +import java.net.MalformedURLException; import java.net.URL; +import java.net.URLConnection; import java.util.logging.Logger; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.google.common.base.Charsets; import com.google.common.eventbus.Subscribe; +import com.google.common.io.Resources; import javafx.application.Platform; import javafx.event.Event; @@ -22,7 +31,10 @@ public class BrowserPanel extends UiPart { public static final String DEFAULT_PAGE = "default.html"; - public static final String SEARCH_PAGE_URL = + public static final String ONLINE_PAGE_URL = + "https://se-edu.github.io/addressbook-level4/DummySearchPage.html?name="; + + public static final String OFFLINE_PAGE_URL = "Timetable.html"; private static final String FXML = "BrowserPanel.fxml"; @@ -43,37 +55,61 @@ public BrowserPanel() { } - /* - import java.io.IOException; - import java.net.URL; - import java.util.logging.Logger; + /** + * Loads the Timetable.html file with the timetable of the person selected. + * + * Does not require a internet connection. + */ + private void loadOfflinePersonPage(Person person) { + URL timetablePage = MainApp.class.getResource(FXML_FILE_FOLDER + OFFLINE_PAGE_URL); + try { + String location = Resources.toString(timetablePage, Charsets.UTF_8); + Document document = Jsoup.parse(location, "UTF-8"); + Element element = document.getElementById("timetable"); + element.attr("value", person.getTimetable().getTimetableAsString()); + Platform.runLater(() -> browser.getEngine().loadContent(document.toString())); + } catch (IOException e) { + loadPage(timetablePage.toExternalForm()); + e.printStackTrace(); + } + } - import org.jsoup.Jsoup; - import org.jsoup.nodes.Document; - import org.jsoup.nodes.Element; + /** + * checks if internet connection is available + */ + //@@author souless94 -reused + //Solution below gotten from Marcus Junius Brutus + // from https://stackoverflow.com/questions/1402005/how- + // to-check-if-internet-connection-is-present-in-java + private static boolean isInternetAvailable() { + try { + final URL url = new URL(ONLINE_PAGE_URL); + final URLConnection conn = url.openConnection(); + conn.connect(); + conn.getInputStream().close(); + return true; + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } catch (IOException e) { + return false; + } + } + //@@ author - import com.google.common.base.Charsets; - import com.google.common.eventbus.Subscribe; - import com.google.common.io.Resources; - Loads the Timetable.html file with the timetable of the person selected for jar - private void loadPersonPage(Person person) { - URL timetablePage = MainApp.class.getResource(FXML_FILE_FOLDER + SEARCH_PAGE_URL); - try { - String location = Resources.toString(timetablePage, Charsets.UTF_8); - Document document = Jsoup.parse(location, "UTF-8"); - Element element = document.getElementById("timetable"); - element.attr("value", person.getTimetable().getTimetableAsString()); - Platform.runLater(() -> browser.getEngine().loadContent(document.toString())); - } catch (IOException e) { - loadPage(timetablePage.toExternalForm()); - e.printStackTrace(); - } - } - */ + /** + * Loads the Timetable.html file with the timetable of the person selected. + * + * Loads from online first, then if there is no internet connect, load from offline + */ private void loadPersonPage(Person person) { - URL defaultPage = MainApp.class.getResource(FXML_FILE_FOLDER + SEARCH_PAGE_URL); - String timetableString = person.getTimetable().getTimetableAsString(); - loadPage(defaultPage.toExternalForm() + "?name=" + timetableString); + if (isInternetAvailable()) { + String timetableString = person.getTimetable().getTimetableAsString(); + URL defaultPage = MainApp.class.getResource(ONLINE_PAGE_URL); + loadPage(ONLINE_PAGE_URL + timetableString); + } else { + loadOfflinePersonPage(person); + } + } public void loadPage(String url) { diff --git a/src/main/resources/view/Timetable.html b/src/main/resources/view/Timetable.html index 11f8e012b15b..85b7a8150828 100644 --- a/src/main/resources/view/Timetable.html +++ b/src/main/resources/view/Timetable.html @@ -2,11 +2,11 @@ - Dummy Search Page - + Dummy Search Page +