Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2021S1#56 from ryanlimjr/branch-viewg…
Browse files Browse the repository at this point in the history
…rp-cmd

Branch viewgrp cmd
  • Loading branch information
Nijnxw authored Oct 5, 2020
2 parents c17c36a + 03ecf67 commit dcc285a
Show file tree
Hide file tree
Showing 39 changed files with 1,055 additions and 64 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ task coverage(type: JacocoReport) {

dependencies {
String jUnitVersion = '5.4.0'
String javaFxVersion = '11'
String javaFxVersion = '11.0.1'

implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-base', version: javaFxVersion, classifier: 'mac'
Expand Down
2 changes: 1 addition & 1 deletion docs/AboutUs.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ We are a team based in the [School of Computing, National University of Singapor
[portfolio](team/johndoe.md)

* Role: Developer
* Responsibilities: Scheduling and tracking, Integration
* Responsibilities: Scheduling and tracking, Integration
1 change: 1 addition & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

title: "Serenity"
theme: minima

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public class Messages {
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";

//serenity messages

public static final String MESSAGE_GROUP_LISTED_OVERVIEW = "You are in tutorial group %1$s.";
public static final String MESSAGE_GROUP_EMPTY = "no such group!";
}
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlySerenity;
import seedu.address.model.group.Group;
import seedu.address.model.group.Lesson;
import seedu.address.model.group.Student;
import seedu.address.model.person.Person;

/**
Expand Down Expand Up @@ -66,6 +68,16 @@ public interface Logic {
*/
ObservableList<Group> getFilteredGroupList();

/**
* Returns an unmodifiable view of the filtered list of Students from a group.
*/
ObservableList<Student> getStudentList();

/**
* Returns an unmodifiable view of the list of lesson from a group.
*/
ObservableList<Lesson> getLessonList();

/**
* Returns the user prefs' serenity file path.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlySerenity;
import seedu.address.model.group.Group;
import seedu.address.model.group.Lesson;
import seedu.address.model.group.Student;
import seedu.address.model.person.Person;
import seedu.address.storage.Storage;

Expand Down Expand Up @@ -93,6 +95,16 @@ public ObservableList<Group> getFilteredGroupList() {
return model.getFilteredGroupList();
}

@Override
public ObservableList<Student> getStudentList() {
return model.getStudentList();
}

@Override
public ObservableList<Lesson> getLessonList() {
return model.getLessonList();
}

@Override
public Path getSerenityFilePath() {
return model.getSerenityFilePath();
Expand Down
40 changes: 40 additions & 0 deletions src/main/java/seedu/address/logic/commands/ViewGrpCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package seedu.address.logic.commands;

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRP;

import seedu.address.commons.core.Messages;
import seedu.address.model.Model;
import seedu.address.model.group.GrpContainsKeywordPredicate;

/**
* Finds and lists all students and lessons in the group specifeied. Keyword matching is case insensitive.
*/
public class ViewGrpCommand extends Command {

public static final String COMMAND_WORD = "viewgrp";
public static final Object MESSAGE_USAGE = COMMAND_WORD
+ ": Finds all students who are part of "
+ "the specified group and displays them as a list with index numbers.\n"
+ "Parameters: GROUP \n"
+ "Example: " + COMMAND_WORD + " " + PREFIX_GRP + " G04";

private final GrpContainsKeywordPredicate predicate;

public ViewGrpCommand(GrpContainsKeywordPredicate predicate) {
this.predicate = predicate;
}

private String getMessage(Model model) {
return model.getFilteredGroupList().isEmpty()
? Messages.MESSAGE_GROUP_EMPTY
: String.format(Messages.MESSAGE_GROUP_LISTED_OVERVIEW, model.getFilteredGroupList().get(0).getName());
}

@Override
public CommandResult execute(Model model) {
requireNonNull(model);
model.updateFilteredGroupList(predicate);
return new CommandResult(this.getMessage(model));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.ViewGrpCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down Expand Up @@ -51,6 +52,9 @@ public Command parseCommand(String userInput) throws ParseException {
case AddGrpCommand.COMMAND_WORD:
return new AddGrpCommandParser().parse(arguments);

case ViewGrpCommand.COMMAND_WORD:
return new ViewGrpCommandParser().parse(arguments);

case AddCommand.COMMAND_WORD:
return new AddCommandParser().parse(arguments);

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/seedu/address/logic/parser/ViewGrpCommandParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_GRP;

import java.util.stream.Stream;

import seedu.address.logic.commands.ViewGrpCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.group.GrpContainsKeywordPredicate;

public class ViewGrpCommandParser implements Parser<ViewGrpCommand> {

private final ParseException viewGrpCommandParserException = new ParseException(
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ViewGrpCommand.MESSAGE_USAGE));

@Override
public ViewGrpCommand parse(String args) throws ParseException {

ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_GRP);

if (!arePrefixesPresent(argMultimap, PREFIX_GRP) || !argMultimap.getPreamble().isEmpty()) {
throw viewGrpCommandParserException;
}

String[] grpKeyword = argMultimap.getValue(PREFIX_GRP).get().split("\\s+");

if (grpKeyword.length > 1) {
throw viewGrpCommandParserException;
}

return new ViewGrpCommand(new GrpContainsKeywordPredicate(grpKeyword[0]));
}

/**
* Returns true if none of the prefixes contains empty {@code Optional} values in the given {@code
* ArgumentMultimap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}
}
46 changes: 46 additions & 0 deletions src/main/java/seedu/address/model/ArrayObservableList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package seedu.address.model;


import java.util.ArrayList;
import java.util.List;

import javafx.collections.ModifiableObservableListBase;
import javafx.collections.ObservableList;

/**
* A modifiable observable list to support rendering of different
* set of information when navigating to different groups
*/
public class ArrayObservableList<E> extends ModifiableObservableListBase<E> {

private final List<E> delegate = new ArrayList<>();

/**
* Creates a generic ArrayObservableList
*/
public ArrayObservableList(ObservableList<E> list) {
for (E e : list) {
delegate.add(e);
}
}

public E get(int index) {
return delegate.get(index);
}

public int size() {
return delegate.size();
}

protected void doAdd(int index, E element) {
delegate.add(index, element);
}

protected E doSet(int index, E element) {
return delegate.set(index, element);
}

protected E doRemove(int index) {
return delegate.remove(index);
}
}
25 changes: 25 additions & 0 deletions src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.group.Group;
import seedu.address.model.group.Lesson;
import seedu.address.model.group.Student;
import seedu.address.model.person.Person;

/**
Expand All @@ -17,6 +19,7 @@ public interface Model {
* {@code Predicate} that always evaluate to true
*/
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
Predicate<Student> PREDICATE_SHOW_ALL_STUDENTS = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
Expand Down Expand Up @@ -122,8 +125,30 @@ public interface Model {
*/
void addGroup(Group group);

/**
* Updates the filter of the filtered group list to filter by the given {@code predicate}.
*
* @throws NullPointerException if {@code predicate} is null.
*/
void updateFilteredGroupList(Predicate<Group> predicate);

/**
* Updates the student list when changing to another group of interest.
*/
void updateStudentList();


/**
* Updates the lesson list to filter when changing to another group of interest.
*/
public void updateLessonList();

/**
* Returns an unmodifiable view of the filtered group list
*/
ObservableList<Group> getFilteredGroupList();

ObservableList<Student> getStudentList();

ObservableList<Lesson> getLessonList();
}
49 changes: 45 additions & 4 deletions src/main/java/seedu/address/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.model.group.Group;
import seedu.address.model.group.Lesson;
import seedu.address.model.group.Student;
import seedu.address.model.group.UniqueLessonList;
import seedu.address.model.group.UniqueStudentList;
import seedu.address.model.person.Person;

/**
Expand All @@ -27,25 +31,29 @@ public class ModelManager implements Model {

private final FilteredList<Person> filteredPersons;
private final FilteredList<Group> filteredGroups;
private final ArrayObservableList<Student> students;
private final ArrayObservableList<Lesson> lessons;

/**
* Initializes a ModelManager with the given addressBook, userPrefs and serenity.
*/
public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs,
ReadOnlySerenity serenity) {
ReadOnlySerenity serenity) {
super();
requireAllNonNull(addressBook, userPrefs, serenity);

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

this.addressBook = new AddressBook(addressBook);
this.serenity = new Serenity(serenity);
this.userPrefs = new UserPrefs(userPrefs);

filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
filteredGroups = new FilteredList<>(this.serenity.getGroupList());
students = new ArrayObservableList<>(new UniqueStudentList().asUnmodifiableObservableList());
lessons = new ArrayObservableList<>(new UniqueLessonList().asUnmodifiableObservableList());
}

/**
Expand All @@ -63,6 +71,8 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs

filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
filteredGroups = new FilteredList<>(this.serenity.getGroupList());
students = new ArrayObservableList<>(new UniqueStudentList().asUnmodifiableObservableList());
lessons = new ArrayObservableList<>(new UniqueLessonList().asUnmodifiableObservableList());
}

public ModelManager() {
Expand Down Expand Up @@ -136,7 +146,6 @@ public void addPerson(Person person) {
@Override
public void setPerson(Person target, Person editedPerson) {
requireAllNonNull(target, editedPerson);

addressBook.setPerson(target, editedPerson);
}

Expand Down Expand Up @@ -175,11 +184,43 @@ public void addGroup(Group group) {
serenity.addGroup(group);
}

@Override
public void updateFilteredGroupList(Predicate<Group> predicate) {
requireAllNonNull(predicate);
this.filteredGroups.setPredicate(predicate);
updateStudentList();
updateLessonList();
}

@Override
public void updateStudentList() {
if (!filteredGroups.isEmpty()) {
this.students.setAll(this.filteredGroups.get(0).getStudentsAsUnmodifiableObservableList());
}
}

@Override
public void updateLessonList() {
if (!filteredGroups.isEmpty()) {
this.lessons.setAll(this.filteredGroups.get(0).getLessonsAsUnmodifiableObservableList());
}
}

@Override
public ObservableList<Group> getFilteredGroupList() {
return filteredGroups;
}

@Override
public ObservableList<Student> getStudentList() {
return students;
}

@Override
public ObservableList<Lesson> getLessonList() {
return lessons;
}

//=========== Filtered Person List Accessors =============================================================

/**
Expand Down
Loading

0 comments on commit dcc285a

Please sign in to comment.