Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Bad FlashCards/ Deadline - v1.3 #150

Merged
merged 8 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
40 changes: 0 additions & 40 deletions data/addressbook.json

This file was deleted.

4 changes: 2 additions & 2 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...
****

Expand Down
78 changes: 78 additions & 0 deletions src/main/java/seedu/address/logic/commands/BadCommand.java
Original file line number Diff line number Diff line change
@@ -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<FlashCard> 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);
Comment on lines +49 to +76
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider SLAPing it

}
}
31 changes: 31 additions & 0 deletions src/main/java/seedu/address/logic/parser/BadCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//@@author: dalsontws
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct format is //@@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<BadCommand> {

/**
* 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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/KeyboardFlashCards.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/seedu/address/model/deadline/BadQuestions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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<String, String> internalMap = new HashMap<String, String>();
//private JsonBadDeadlines jsonBadDeadlines;

public BadQuestions() {
//TODO: add initialisation of bad deadline list - load json
}

public HashMap<String, String> getBadQuestionsList() {
return internalMap;
}

public void setBadQuestionsList(HashMap<String, String> 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);
}

/**
* Save as json.
*/
public void saveAsJson(BadQuestions badQuestions) {
Gson gson = new Gson();

// convert java object to JSON format,
// and returned as JSON formatted string
String json = gson.toJson(badQuestions.getBadQuestionsList());
try {
//write converted json data to a file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Writing a method to abstract these steps might be better than to explain it through comments

//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();
}
}
}
1 change: 0 additions & 1 deletion src/main/java/seedu/address/model/deadline/DueDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ public String toString() {
public int hashCode() {
return dateStr.hashCode();
}

}
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/DeadlineListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public DeadlineListPanel(ObservableList<Deadline> 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<Deadline> {
@Override
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/ui/DeadlinePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public DeadlinePanel(Deadline deadline, int displayedIndex) {
this.deadline = deadline;
id.setText(displayedIndex + ". ");
task.setText(deadline.getTask().toString());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can change the task from label to Textflow so that the text will not be concatenated and you can change the color of the text.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

//TODO: use date to colour code each deadline
//LocalDate today = LocalDate.now();
//deadline.getDueDate();
dueDate.setText("Due Date: " + deadline.getDueDate().toString());
}

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/view/DeadlineListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Region?>
Expand Down
Original file line number Diff line number Diff line change
@@ -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()));
}
}