Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #55 from ShirleyWangxt/master
Browse files Browse the repository at this point in the history
[Wang Xueting] Implement listq and deleteq features for Question
  • Loading branch information
Parcly-Taxel authored Oct 17, 2019
2 parents d9fd55a + 269eb78 commit 9b56a13
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.address.logic.commands.questioncommands;

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.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.question.Question;

/**
* Deletes a question by index number.
*/
public class DeleteQuestionCommand extends Command {
public static final String COMMAND_WORD = "deleteq";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Deletes the question with the specified index number.\n"
+ "Parameters: INDEX (must be a positive integer)\n"
+ "Example: " + COMMAND_WORD + " 1";

public static final String MESSAGE_DELETE_QUESTION_SUCCESS = "Deleted question: %1$s";

private final Index targetIndex;

public DeleteQuestionCommand(Index targetIndex) {
this.targetIndex = targetIndex;
}

@Override
public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);
List<Question> lastShownList = model.getFilteredQuestionList();

if (targetIndex.getZeroBased() >= lastShownList.size()) {
throw new CommandException(Messages.MESSAGE_INVALID_QUESTION_DISPLAYED_INDEX);
}

Question questionToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deleteQuestion(questionToDelete);
model.updateFilteredQuestionList(Model.PREDICATE_SHOW_ALL_QUESTIONS);
return new CommandResult(String.format(MESSAGE_DELETE_QUESTION_SUCCESS, questionToDelete));
}

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
|| (other instanceof DeleteQuestionCommand // instanceof handles nulls
&& targetIndex.equals(((DeleteQuestionCommand) other).targetIndex)); // state check
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package seedu.address.logic.commands.questioncommands;

import static java.util.Objects.requireNonNull;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_QUESTIONS;

import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.CommandResult;
import seedu.address.model.Model;

/**
* Lists all questions.
*/
public class ListQuestionCommand extends Command {
public static final String COMMAND_WORD = "listq";

public static final String MESSAGE_SUCCESS = "Listed all questions.";

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredQuestionList(PREDICATE_SHOW_ALL_QUESTIONS);
return new CommandResult(MESSAGE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListNoteCommand;
import seedu.address.logic.commands.questioncommands.AddQuestionCommand;
import seedu.address.logic.commands.questioncommands.DeleteQuestionCommand;
import seedu.address.logic.commands.questioncommands.ListQuestionCommand;
import seedu.address.logic.commands.quiz.QuizModeCommand;
import seedu.address.logic.commands.statistics.GetQnsCommand;
import seedu.address.logic.commands.statistics.GetReportCommand;
Expand All @@ -26,6 +28,7 @@
import seedu.address.logic.commands.task.DoneTaskCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.logic.parser.questionparser.AddQuestionCommandParser;
import seedu.address.logic.parser.questionparser.DeleteQuestionCommandParser;
import seedu.address.logic.parser.quiz.QuizModeCommandParser;
import seedu.address.logic.parser.statistics.GetQnsCommandParser;
import seedu.address.logic.parser.statistics.GetReportCommandParser;
Expand Down Expand Up @@ -100,6 +103,12 @@ public Command parseCommand(String userInput) throws ParseException {
case AddQuestionCommand.COMMAND_WORD:
return new AddQuestionCommandParser().parse(arguments);

case DeleteQuestionCommand.COMMAND_WORD:
return new DeleteQuestionCommandParser().parse(arguments);

case ListQuestionCommand.COMMAND_WORD:
return new ListQuestionCommand();

case AddTaskForNoteCommand.COMMAND_WORD:
return new AddTaskForNoteCommandParser().parse(arguments);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package seedu.address.logic.parser.questionparser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.questioncommands.DeleteQuestionCommand;
import seedu.address.logic.parser.Parser;
import seedu.address.logic.parser.ParserUtil;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* Parses input arguments and creates a new DeleteQuestionCommand object
*/
public class DeleteQuestionCommandParser implements Parser<DeleteQuestionCommand> {

/**
* Parses the given {@code String} of arguments in the context of the DeleteQuestionCommand
* and returns a DeleteQuestionCommand object for execution.
* @throws ParseException if the user input does not conform the expected format
*/
public DeleteQuestionCommand parse(String args) throws ParseException {
try {
Index index = ParserUtil.parseIndex(args);
return new DeleteQuestionCommand(index);
} catch (ParseException pe) {
throw new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteQuestionCommand.MESSAGE_USAGE), pe);
}
}

}
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class MainWindow extends UiPart<Stage> {
// Independent Ui parts residing in this Ui container
private NoteListPanel noteListPanel;
private TaskListPanel taskListPanel;
private QuestionListPanel questionListPanel;
private QuizQuestionListPanel quizQuestionListPanel;
private ResultDisplay resultDisplay;
private HelpWindow helpWindow;
Expand All @@ -52,6 +53,9 @@ public class MainWindow extends UiPart<Stage> {
@FXML
private StackPane taskListPanelPlaceholder;

@FXML
private StackPane questionListPanelPlaceholder;

@FXML
private StackPane quizQuestionListPanelPlaceholder;

Expand Down Expand Up @@ -110,6 +114,9 @@ void fillInnerParts() {
taskListPanel = new TaskListPanel(logic.getFilteredTaskList());
taskListPanelPlaceholder.getChildren().add(taskListPanel.getRoot());

questionListPanel = new QuestionListPanel(logic.getFilteredQuestionList());
questionListPanelPlaceholder.getChildren().add(questionListPanel.getRoot());

quizQuestionListPanel = new QuizQuestionListPanel(logic.getFilteredQuizQuestionList());
quizQuestionListPanelPlaceholder.getChildren().add(quizQuestionListPanel.getRoot());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/**
* An UI component that displays information of a {@code Question}.
*/
public class QuestionCard extends UiPart<Region> {
public class QuestionListCard extends UiPart<Region> {
private static final String FXML = "QuestionListCard.fxml";

public final Question question;
Expand All @@ -27,7 +27,7 @@ public class QuestionCard extends UiPart<Region> {
@FXML
private Label difficulty;

public QuestionCard(Question question, int displayedIndex) {
public QuestionListCard(Question question, int displayedIndex) {
super(FXML);
this.question = question;
id.setText(displayedIndex + ". ");
Expand All @@ -45,12 +45,12 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof QuestionCard)) {
if (!(other instanceof QuestionListCard)) {
return false;
}

// state check
QuestionCard card = (QuestionCard) other;
QuestionListCard card = (QuestionListCard) other;
return id.getText().equals(card.id.getText())
&& question.equals(card.question);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/QuestionListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected void updateItem(Question question, boolean empty) {
setGraphic(null);
setText(null);
} else {
setGraphic(new QuestionCard(question, getIndex() + 1).getRoot());
setGraphic(new QuestionListCard(question, getIndex() + 1).getRoot());
}
}
}
Expand Down

0 comments on commit 9b56a13

Please sign in to comment.