Skip to content

Commit b4caff7

Browse files
authored
Merge pull request #54 from Maurice2n97/add-Delete-Meeting
Add delete meeting
2 parents fa1e735 + 9e37448 commit b4caff7

22 files changed

Lines changed: 392 additions & 141 deletions

src/main/java/seedu/address/commons/core/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ public class Messages {
99
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
1010
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
1111
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
12+
public static final String MESSAGE_INVALID_MEETING_DISPLAYED_INDEX = "The person index provided is invalid";
13+
1214

1315
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package seedu.address.logic.commands.meetings;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import java.util.List;
6+
7+
import seedu.address.commons.core.Messages;
8+
import seedu.address.commons.core.index.Index;
9+
import seedu.address.logic.commands.Command;
10+
import seedu.address.logic.commands.CommandResult;
11+
import seedu.address.logic.commands.exceptions.CommandException;
12+
import seedu.address.model.Model;
13+
import seedu.address.model.meeting.Meeting;
14+
15+
16+
public class DeleteMeetingCommand extends Command {
17+
public static final String COMMAND_WORD = "deleteMeeting";
18+
19+
public static final String MESSAGE_USAGE = COMMAND_WORD
20+
+ ": Deletes the meeting identified by the index number used in the displayed meeting list.\n"
21+
+ "Parameters: INDEX (must be a positive integer)\n"
22+
+ "Example: " + COMMAND_WORD + " 1";
23+
24+
public static final String MESSAGE_DELETE_MEETING_SUCCESS = "Deleted Meeting: %1$s";
25+
26+
27+
private final Index targetIndex;
28+
29+
public DeleteMeetingCommand(Index targetIndex) {
30+
this.targetIndex = targetIndex;
31+
}
32+
33+
@Override
34+
public CommandResult execute(Model model) throws CommandException {
35+
requireNonNull(model);
36+
List<Meeting> lastShownList = model.getFilteredMeetingList();
37+
38+
if (targetIndex.getZeroBased() >= lastShownList.size()) {
39+
throw new CommandException(Messages.MESSAGE_INVALID_MEETING_DISPLAYED_INDEX);
40+
}
41+
42+
Meeting meetingToDelete = lastShownList.get(targetIndex.getZeroBased());
43+
model.deleteMeeting(meetingToDelete);
44+
return new CommandResult(String.format(MESSAGE_DELETE_MEETING_SUCCESS, meetingToDelete));
45+
}
46+
47+
@Override
48+
public boolean equals(Object other) {
49+
return other == this // short circuit if same object
50+
|| (other instanceof DeleteMeetingCommand // instanceof handles nulls
51+
&& targetIndex.equals(((DeleteMeetingCommand) other).targetIndex)); // state check
52+
}
53+
54+
}

src/main/java/seedu/address/logic/parser/CliSyntax.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class CliSyntax {
1818
/* Prefix specific for meeting */
1919
public static final Prefix PREFIX_START_TIME = new Prefix("st/");
2020
public static final Prefix PREFIX_END_TIME = new Prefix("ed/");
21-
public static final Prefix PREFIX_DESCRIPTION = new Prefix("des/");
21+
public static final Prefix PREFIX_DESCRIPTION = new Prefix("desc/");
2222
public static final Prefix PREFIX_PRIORITY = new Prefix("pr/");
2323

2424

src/main/java/seedu/address/logic/parser/MeetBuddyParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import seedu.address.logic.commands.ExitCommand;
1111
import seedu.address.logic.commands.HelpCommand;
1212
import seedu.address.logic.commands.meetings.AddMeetingCommand;
13+
import seedu.address.logic.commands.meetings.DeleteMeetingCommand;
1314
import seedu.address.logic.commands.persons.AddPersonCommand;
1415
import seedu.address.logic.commands.persons.ClearPersonCommand;
1516
import seedu.address.logic.commands.persons.DeletePersonCommand;
@@ -19,6 +20,7 @@
1920
import seedu.address.logic.commands.persons.ListPersonCommand;
2021
import seedu.address.logic.parser.exceptions.ParseException;
2122
import seedu.address.logic.parser.meetings.AddMeetingCommandParser;
23+
import seedu.address.logic.parser.meetings.DeleteMeetingCommandParser;
2224
import seedu.address.logic.parser.persons.AddPersonCommandParser;
2325
import seedu.address.logic.parser.persons.DeletePersonCommandParser;
2426
import seedu.address.logic.parser.persons.EditPersonCommandParser;
@@ -77,6 +79,9 @@ public Command parseCommand(String userInput) throws ParseException {
7779
case AddMeetingCommand.COMMAND_WORD:
7880
return new AddMeetingCommandParser().parse(arguments);
7981

82+
case DeleteMeetingCommand.COMMAND_WORD:
83+
return new DeleteMeetingCommandParser().parse(arguments);
84+
8085
//============================= General ==============================
8186
case ExitCommand.COMMAND_WORD:
8287
return new ExitCommand();
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package seedu.address.logic.parser.meetings;
2+
3+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4+
5+
import seedu.address.commons.core.index.Index;
6+
import seedu.address.logic.commands.meetings.DeleteMeetingCommand;
7+
import seedu.address.logic.parser.Parser;
8+
import seedu.address.logic.parser.ParserUtil;
9+
import seedu.address.logic.parser.exceptions.ParseException;
10+
11+
12+
public class DeleteMeetingCommandParser implements Parser<DeleteMeetingCommand> {
13+
14+
15+
@Override
16+
public DeleteMeetingCommand parse(String args) throws ParseException {
17+
try {
18+
Index index = ParserUtil.parseIndex(args);
19+
return new DeleteMeetingCommand(index);
20+
} catch (ParseException pe) {
21+
throw new ParseException(
22+
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteMeetingCommand.MESSAGE_USAGE), pe);
23+
}
24+
}
25+
}

src/main/java/seedu/address/model/Model.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public interface Model {
9898
*/
9999
void setMeetingBook(ReadOnlyMeetingBook meetingBook);
100100

101-
/** Returns the AddressBook */
101+
/** Returns the Book */
102102
ReadOnlyMeetingBook getMeetingBook();
103103

104104
/**

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,42 @@ public class ModelManager implements Model {
2929
private final FilteredList<Person> filteredPersons;
3030

3131
// TODO: Modify the signature of ModelManager so that we can add meetings inside it.
32-
private final MeetingBook meetingBook = new MeetingBook();
33-
private final FilteredList<Meeting> filteredMeetings = new FilteredList<Meeting>(this.meetingBook.getMeetingList());
34-
32+
private final MeetingBook meetingBook;
33+
private final FilteredList<Meeting> filteredMeetings;
3534
/**
36-
* Initializes a ModelManager with the given addressBook and userPrefs.
35+
* Initializes a ModelManager with the given addressBook and userPrefs. MeetingBook will be set to default.
3736
*/
3837
public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs) {
3938
super();
4039
requireAllNonNull(addressBook, userPrefs);
4140

4241
logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs);
4342

43+
this.meetingBook = new MeetingBook();
44+
this.filteredMeetings = new FilteredList<Meeting>(this.meetingBook.getMeetingList());
4445
this.addressBook = new AddressBook(addressBook);
4546
this.userPrefs = new UserPrefs(userPrefs);
4647
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
4748
}
4849

50+
/**
51+
* Initializes a ModelManager with the given addressBook, meetingBOok and userPrefs
52+
*/
53+
public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meetingBook,
54+
ReadOnlyUserPrefs userPrefs) {
55+
super();
56+
requireAllNonNull(addressBook, userPrefs);
57+
58+
logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs);
59+
60+
this.meetingBook = new MeetingBook(meetingBook);
61+
this.filteredMeetings = new FilteredList<Meeting>(this.meetingBook.getMeetingList());
62+
this.addressBook = new AddressBook(addressBook);
63+
this.userPrefs = new UserPrefs(userPrefs);
64+
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
65+
}
66+
67+
4968
public ModelManager() {
5069
this(new AddressBook(), new UserPrefs());
5170
}
@@ -153,7 +172,6 @@ public void addMeeting(Meeting meeting) {
153172
@Override
154173
public void setMeeting(Meeting target, Meeting editedMeeting) {
155174
requireAllNonNull(target, editedMeeting);
156-
157175
meetingBook.setMeeting(target, editedMeeting);
158176
}
159177
//=========== Filtered Person List Accessors =============================================================
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package seedu.address.model.meeting;
2+
3+
4+
import java.util.List;
5+
import java.util.function.Predicate;
6+
7+
import seedu.address.commons.util.StringUtil;
8+
9+
/**
10+
* Tests that a {@code Meeting}'s {@code MeetingName} matches any of the keywords given.
11+
*/
12+
public class NameContainsKeywordsPredicate implements Predicate<Meeting> {
13+
private final List<String> keywords;
14+
15+
public NameContainsKeywordsPredicate(List<String> keywords) {
16+
this.keywords = keywords;
17+
}
18+
19+
@Override
20+
public boolean test(Meeting meeting) {
21+
return keywords.stream()
22+
.anyMatch(keyword -> StringUtil.containsWordIgnoreCase(meeting.getName().fullName, keyword));
23+
}
24+
25+
26+
@Override
27+
//TODO: Do we have to include full path name to disntinguish from other NamePredicate? Feels redundant.
28+
public boolean equals(Object other) {
29+
return other == this // short circuit if same object
30+
|| (other instanceof NameContainsKeywordsPredicate // instanceof handles
31+
// nulls
32+
&& keywords.equals(((NameContainsKeywordsPredicate) other).keywords));
33+
// state check
34+
}
35+
36+
}

src/main/resources/view/MainWindow.fxml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
<?import javafx.scene.layout.VBox?>
1212
<?import javafx.stage.Stage?>
1313

14-
<fx:root minHeight="600" minWidth="450" onCloseRequest="#handleExit" title="Address App" type="javafx.stage.Stage" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1">
14+
<fx:root minHeight="600" minWidth="450" onCloseRequest="#handleExit" title="Address App" type="javafx.stage.Stage"
15+
xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1">
1516

1617
<scene>
1718
<Scene>
@@ -32,14 +33,16 @@
3233
<MenuItem fx:id="helpMenuItem" mnemonicParsing="false" onAction="#handleHelp" text="Help" />
3334
</Menu>
3435
</MenuBar>
35-
36-
<StackPane fx:id="commandBoxPlaceholder" maxHeight="25.0" prefHeight="25.0" styleClass="pane-with-border" VBox.vgrow="NEVER">
36+
37+
<StackPane fx:id="commandBoxPlaceholder" maxHeight="25.0" prefHeight="25.0" styleClass="pane-with-border"
38+
VBox.vgrow="NEVER">
3739
<padding>
3840
<Insets bottom="5" left="10" right="10" top="5" />
3941
</padding>
4042
</StackPane>
41-
42-
<StackPane fx:id="resultDisplayPlaceholder" minHeight="90.0" styleClass="pane-with-border" VBox.vgrow="ALWAYS">
43+
44+
<StackPane fx:id="resultDisplayPlaceholder" minHeight="90.0" styleClass="pane-with-border"
45+
VBox.vgrow="ALWAYS">
4346
<padding>
4447
<Insets bottom="5" left="10" right="10" top="5" />
4548
</padding>
@@ -68,7 +71,7 @@
6871
<center>
6972
<StackPane fx:id="meetingDashboardPlaceholder" BorderPane.alignment="CENTER" />
7073
</center>
71-
74+
7275
</BorderPane>
7376
</Scene>
7477
</scene>

src/main/resources/view/PersonListCard.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<?import javafx.scene.layout.VBox?>
1212
<?import javafx.scene.shape.Circle?>
1313

14-
<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1">
14+
<HBox id="cardPane" fx:id="cardPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
1515
<GridPane HBox.hgrow="ALWAYS">
1616
<columnConstraints>
1717
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />

0 commit comments

Comments
 (0)