diff --git a/build.gradle b/build.gradle index 318157f4523..257b403e799 100644 --- a/build.gradle +++ b/build.gradle @@ -45,6 +45,8 @@ dependencies { String jUnitVersion = '5.4.0' String javaFxVersion = '11' + implementation 'com.google.code.gson:gson:2.8.6' + implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac' implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'linux' diff --git a/data/addressbook.json b/data/addressbook.json deleted file mode 100644 index ce7f3eaa31d..00000000000 --- a/data/addressbook.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "flashcards" : [ { - "question" : "What is pointer in C ?", - "answer" : "A pointer variable stores the address of a memory location", - "rating" : "easy", - "categories" : [ "CS2100", "C", "POINTER" ] - }, { - "question" : "How to declare a pointer in C ?", - "answer" : "& + variable name", - "rating" : "good", - "categories" : [ "CS2100" ] - }, { - "question" : "What is internet", - "answer" : "The Internet is a network of connected computing devices", - "rating" : "good", - "categories" : [ "CS2105" ] - }, { - "question" : "How is data transmitted through net?", - "answer" : "Circuit switching / Packet switching", - "rating" : "easy", - "categories" : [ ] - }, { - "question" : "What is link transmission rate?", - "answer" : "It is aka link capacity or link bandwidth", - "rating" : "easy", - "categories" : [ ] - }, { - "question" : "Transmission delay", - "answer" : "L (bit) / R (bits.sec)", - "rating" : "good", - "categories" : [ ] - } ], - "deadlines" : [ { - "task" : "CS2103 Final Project Submission", - "date" : "10/11/2019" - }, { - "task" : "CS2101 User Guide Submission", - "date" : "12/11/2019" - } ] -} diff --git a/docs/UserGuide.adoc b/docs/UserGuide.adoc index adac200c5d2..d4ad7ff6f9e 100644 --- a/docs/UserGuide.adoc +++ b/docs/UserGuide.adoc @@ -245,8 +245,8 @@ image::deadline-entered.png[][width="600"] Removes a specific deadline into the deadline list. The list on the right-side pane will no longer have the deadline. `remove 2` - -**** +]= +]**** * Removes the deadline at the specified `INDEX` from the list. The index refers to the index number shown in the displayed deadline list on the right-sde pane. The index *must be a positive integer* 1, 2, 3, ... **** diff --git a/src/main/java/seedu/address/logic/commands/BadCommand.java b/src/main/java/seedu/address/logic/commands/BadCommand.java new file mode 100644 index 00000000000..c50509b1480 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/BadCommand.java @@ -0,0 +1,78 @@ +//@@author: dalsontws + +package seedu.address.logic.commands; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import seedu.address.commons.core.Messages; +import seedu.address.commons.core.index.Index; + +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.deadline.BadQuestions; +import seedu.address.model.deadline.Deadline; +import seedu.address.model.deadline.DueDate; +import seedu.address.model.deadline.Task; +import seedu.address.model.deadline.exceptions.DuplicateDeadlineException; +import seedu.address.model.flashcard.FlashCard; +import seedu.address.model.flashcard.Question; + +/** + * Set certain FlashCards as 'Bad' + * This will then add these set of flashcards into a certain Deadline + */ +public class BadCommand extends Command { + + public static final String COMMAND_WORD = "bad"; + + public static final String MESSAGE_USAGE = COMMAND_WORD + + ": Sets a specific flashCard identified by the\n " + + "index number used in the displayed flashCard list.\n" + + "as a 'Bad' flashcard that will require re-test.\n" + + "Parameters: INDEX (must be a positive integer)\n" + + "Example: " + COMMAND_WORD + " 1"; + + public static final String MESSAGE_SUCCESS = "Flashcard has been added into Deadlines!"; + public static final String DUPLICATE_DEADLINE = "Flashcard has been added into an existing deadline!"; + + private final Index index; + + public BadCommand(Index index) { + requireNonNull(index); + this.index = index; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredFlashCardList(); + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_FLASHCARD_DISPLAYED_INDEX); + } + + FlashCard badFlashcard = lastShownList.get(index.getZeroBased()); + + Task task = new Task("To Do: Bad Questions"); + DueDate d = BadQuestions.getBadDeadline(); + Deadline deadline = new Deadline(task, d); + + //TODO: add questions and due date into filtered bad flashcards list + Question q = badFlashcard.getQuestion(); + + BadQuestions badQuestions = new BadQuestions(); + + badQuestions.addBadQuestion(d, q); + + badQuestions.saveAsJson(badQuestions); + + try { + model.addDeadline(deadline); + } catch (DuplicateDeadlineException e) { + return new CommandResult(DUPLICATE_DEADLINE); + } + + return new CommandResult(MESSAGE_SUCCESS); + } +} diff --git a/src/main/java/seedu/address/logic/parser/BadCommandParser.java b/src/main/java/seedu/address/logic/parser/BadCommandParser.java new file mode 100644 index 00000000000..0a421803414 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/BadCommandParser.java @@ -0,0 +1,31 @@ +//@@author dalsontws + +package seedu.address.logic.parser; + +import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.BadCommand; +import seedu.address.logic.parser.exceptions.ParseException; + +/** + * Parses input arguments and creates a new DeleteCommand object + */ +public class BadCommandParser implements Parser { + + /** + * Parses the given {@code String} of arguments in the context of the DeleteCommand + * and returns a DeleteCommand object for execution. + * @throws ParseException if the user input does not conform the expected format + */ + public BadCommand parse(String args) throws ParseException { + try { + Index index = ParserUtil.parseIndex(args); + return new BadCommand(index); + } catch (ParseException pe) { + throw new ParseException( + String.format(MESSAGE_INVALID_COMMAND_FORMAT, BadCommand.MESSAGE_USAGE), pe); + } + } + +} diff --git a/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java b/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java index bda5da95458..7f342ae742e 100644 --- a/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java +++ b/src/main/java/seedu/address/logic/parser/KeyboardFlashCardsParser.java @@ -8,6 +8,7 @@ import java.util.regex.Pattern; import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.BadCommand; import seedu.address.logic.commands.CalendarCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.Command; @@ -144,6 +145,9 @@ private Command parseNormalCommand(Matcher matcher) throws ParseException { case DeadlineCommand.COMMAND_WORD: return new DeadlineCommandParser().parse(arguments); + case BadCommand.COMMAND_WORD: + return new BadCommandParser().parse(arguments); + case RemoveCommand.COMMAND_WORD: return new RemoveCommandParser().parse(arguments); diff --git a/src/main/java/seedu/address/model/KeyboardFlashCards.java b/src/main/java/seedu/address/model/KeyboardFlashCards.java index 2b18102dea9..a76a04459c2 100644 --- a/src/main/java/seedu/address/model/KeyboardFlashCards.java +++ b/src/main/java/seedu/address/model/KeyboardFlashCards.java @@ -92,7 +92,7 @@ public boolean hasFlashcard(FlashCard flashCard) { * Adds a flashCard to the address book. * The flashCard must not already exist in the address book. */ - public void addFlashcard (FlashCard c) { + public void addFlashcard(FlashCard c) { flashCards.add(c); //update the categoryList addCategory(c.getCategories()); diff --git a/src/main/java/seedu/address/model/deadline/BadQuestions.java b/src/main/java/seedu/address/model/deadline/BadQuestions.java new file mode 100644 index 00000000000..7ef1f4d24e3 --- /dev/null +++ b/src/main/java/seedu/address/model/deadline/BadQuestions.java @@ -0,0 +1,79 @@ +//@@author dalsontws + +package seedu.address.model.deadline; + +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; + +import com.google.gson.Gson; + +import seedu.address.model.Model; +import seedu.address.model.flashcard.Question; + +/** + * BadQuestions class. + * Contains a Hashmap with questions that are rated as 'bad' + * Each Question will be tagged to a specific DueDate, which will be referred to + * in the list of Deadlines + */ +public class BadQuestions { + + private HashMap internalMap = new HashMap(); + //private JsonBadDeadlines jsonBadDeadlines; + + public BadQuestions() { + //TODO: add initialisation of bad deadline list - load json + } + + public HashMap getBadQuestionsList() { + return internalMap; + } + + public void setBadQuestionsList(HashMap map) { + internalMap = map; + } + + public void addBadQuestion(DueDate d, Question q) { + internalMap.put(d.toString(), q.toString()); + } + + public void loadBadQuestions() throws FileNotFoundException { + //internalMap = jsonBadDeadlines.loadJsonBadDeadlines(); + } + + public static DueDate getBadDeadline() { + LocalDate today = LocalDate.now(); + LocalDate due = today.plusDays(3); + String formattedDate = due.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")); + DueDate d = new DueDate(formattedDate); + return d; + } + + public void setBadQuestionsAsDeadline(Model model) { + Task task = new Task("Bad Questions"); + Deadline deadline = new Deadline(task, getBadDeadline()); + model.addDeadline(deadline); + } + + /** + * Using Google's Gson library, save HashMap as a JSON Object and store it + * in BadQuestions.json. This can later be used to fetch the 'bad' questions + * to test in a future date. + */ + public void saveAsJson(BadQuestions badQuestions) { + Gson gson = new Gson(); + String json = gson.toJson(badQuestions.getBadQuestionsList()); + try { + //TODO: fix load and save json, json save replace file instead of appending + FileWriter writer = new FileWriter("data/BadDeadlines.json", true); + writer.write(json); + writer.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/seedu/address/model/deadline/DueDate.java b/src/main/java/seedu/address/model/deadline/DueDate.java index e55b9e522af..1d836d1b1cd 100644 --- a/src/main/java/seedu/address/model/deadline/DueDate.java +++ b/src/main/java/seedu/address/model/deadline/DueDate.java @@ -59,5 +59,4 @@ public String toString() { public int hashCode() { return dateStr.hashCode(); } - } diff --git a/src/main/java/seedu/address/ui/DeadlineListPanel.java b/src/main/java/seedu/address/ui/DeadlineListPanel.java index 36b61d0b98d..acc8f18207e 100644 --- a/src/main/java/seedu/address/ui/DeadlineListPanel.java +++ b/src/main/java/seedu/address/ui/DeadlineListPanel.java @@ -28,7 +28,7 @@ public DeadlineListPanel(ObservableList deadlineList) { } /** - * Custom {@code ListCell} that displays the graphics of a {@code FlashCard} using a {@code FlashCardPanel}. + * Custom {@code ListCell} that displays the graphics of a {@code FlashCard} using a {@code DeadlinePanel}. */ class DeadlineListViewCell extends ListCell { @Override diff --git a/src/main/java/seedu/address/ui/DeadlinePanel.java b/src/main/java/seedu/address/ui/DeadlinePanel.java index 726dbfd3706..6d456cf1498 100644 --- a/src/main/java/seedu/address/ui/DeadlinePanel.java +++ b/src/main/java/seedu/address/ui/DeadlinePanel.java @@ -30,6 +30,9 @@ public DeadlinePanel(Deadline deadline, int displayedIndex) { this.deadline = deadline; id.setText(displayedIndex + ". "); task.setText(deadline.getTask().toString()); + //TODO: use date to colour code each deadline + //LocalDate today = LocalDate.now(); + //deadline.getDueDate(); dueDate.setText("Due Date: " + deadline.getDueDate().toString()); } diff --git a/src/main/resources/view/DeadlineListCard.fxml b/src/main/resources/view/DeadlineListCard.fxml index ca0fe3451a0..47ce058d22a 100644 --- a/src/main/resources/view/DeadlineListCard.fxml +++ b/src/main/resources/view/DeadlineListCard.fxml @@ -3,7 +3,6 @@ - diff --git a/src/test/java/seedu/address/logic/commands/DeadlineCommandTest.java b/src/test/java/seedu/address/logic/commands/DeadlineCommandTest.java new file mode 100644 index 00000000000..41bbd0e48bf --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/DeadlineCommandTest.java @@ -0,0 +1,63 @@ +package seedu.address.logic.commands; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +import seedu.address.model.deadline.Deadline; +import seedu.address.testutil.DeadlineBuilder; + +public class DeadlineCommandTest { + + @Test + public void constructor_nullDeadline_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new DeadlineCommand(null)); + } + + @Test + public void equals() { + Deadline test = new DeadlineBuilder().withTask("Test").build(); + Deadline exam = new DeadlineBuilder().withTask("Exam").build(); + DeadlineCommand addTestCommand = new DeadlineCommand(test); + DeadlineCommand addExamCommand = new DeadlineCommand(exam); + + // same object -> returns true + assertTrue(addTestCommand.equals(addTestCommand)); + + // same values -> returns true + DeadlineCommand addTestCommandCopy = new DeadlineCommand(test); + assertTrue(addTestCommand.equals(addTestCommandCopy)); + + // different types -> returns false + assertFalse(addTestCommand.equals(1)); + + // null -> returns false + assertFalse(addTestCommand.equals(null)); + + // different flashCard -> returns false + assertFalse(addTestCommand.equals(addExamCommand)); + + //same question different answer + Deadline testCopy = new DeadlineBuilder(test).withDueDate("22/12/2019").build(); + addTestCommandCopy = new DeadlineCommand(testCopy); + assertFalse(addTestCommandCopy.equals(testCopy)); + } + + @Test + public void toStringTest() { + Deadline validDeadline = new DeadlineBuilder().build(); + DeadlineCommand deadlineCommand = new DeadlineCommand(validDeadline); + //same object + assertTrue(deadlineCommand.toString().equals(deadlineCommand.toString())); + + //same value + DeadlineCommand deadlineCommandCopy = new DeadlineCommand(validDeadline); + assertTrue(deadlineCommand.toString().equals(deadlineCommandCopy.toString())); + + //same question diff answer + deadlineCommandCopy = new DeadlineCommand(new DeadlineBuilder(validDeadline).withDueDate("10/10/2019").build()); + assertFalse(deadlineCommand.toString().equals(deadlineCommandCopy.toString())); + } +}