Skip to content

Commit

Permalink
Merge pull request #113 from karenfrilya97/master
Browse files Browse the repository at this point in the history
Sort Tasks and Events automatically upon adding
  • Loading branch information
Kyomian authored Apr 4, 2018
2 parents 8c98068 + e09c976 commit c980110
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 48 deletions.
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ https://www.codacy.com/app/damith/addressbook-level4?utm_source=github.com&utm_m
https://gitter.im/se-edu/Lobby[image:https://badges.gitter.im/se-edu/Lobby.svg[Gitter chat]]

ifdef::env-github[]

image::docs/images/Ui.png[width="600"]
endif::[]

Expand Down
Binary file modified docs/images/App Interface.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/activity/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
public abstract class Activity {


private final Name name;
private final DateTime dateTime;
private final Remark remark;

private final UniqueTagList tags;
private final boolean isCompleted;

/**
* Every field must be present and not null.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/seedu/address/model/activity/UniqueActivityList.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;

import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;

Expand All @@ -24,6 +26,15 @@
*/
public class UniqueActivityList implements Iterable<Activity> {

//@@author karenfrilya97
private static Comparator<Activity> dateTimeComparator = new Comparator<Activity>() {
public int compare (Activity o1, Activity o2) {
DateTime dt1 = o1.getDateTime();
DateTime dt2 = o2.getDateTime();
return dt1.getLocalDateTime().compareTo(dt2.getLocalDateTime());
}
};

private final ObservableList<Activity> internalList = FXCollections.observableArrayList();

/**
Expand All @@ -47,6 +58,8 @@ public void add(Activity toAdd) throws DuplicateActivityException {
throw new DuplicateActivityException();
}
internalList.add(toAdd);
//@@author karenfrilya97
Collections.sort(internalList, dateTimeComparator);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,58 @@
<dateTime>04/03/2018 23:59</dateTime>
<remark> </remark>
<tagged>CS2101</tagged>
<iscompleted>false</iscompleted>
</tasks>
<tasks>
<name>CS2102Assignment</name>
<dateTime>15/03/2018 23:59</dateTime>
<remark> </remark>
<tagged>CS2102</tagged>
<iscompleted>false</iscompleted>
</tasks>
<tasks>
<name>CS2101Quiz</name>
<dateTime>19/03/2018 23:59</dateTime>
<remark>IVLE Quiz</remark>
<iscompleted>false</iscompleted>
</tasks>
<events>
<name>CCA</name>
<dateTime>01/04/2018 20:00</dateTime>
<endDateTime>01/04/2018 21:00</endDateTime>
<location>Campus</location>
<remark>nil</remark>
<iscompleted>false</iscompleted>
</events>
<events>
<name>CIP</name>
<dateTime>02/04/2018 08:00</dateTime>
<endDateTime>02/04/2018 12:00</endDateTime>
<location>michegan ave</location>
<remark></remark>
<remark>nil</remark>
<tagged>CIP</tagged>
<iscompleted>false</iscompleted>
</events>
<events>
<name>CS2101Exam</name>
<dateTime>28/04/2018 09:00</dateTime>
<endDateTime>28/04/2018 11:00</endDateTime>
<location>MPSH</location>
<remark></remark>
<remark>nil</remark>
<tagged>CS2101</tagged>
<iscompleted>false</iscompleted>
</events>
<events>
<name>InterFacultyGame</name>
<dateTime>04/01/2018 20:00</dateTime>
<endDateTime>04/01/2018 22:00</endDateTime>
<location>MPSH 1</location>
<remark></remark>
<remark>nil</remark>
<iscompleted>false</iscompleted>
</events>
<tags>CS2101</tags>
<tags>CS2102</tags>
<tags>MA2108</tags>
<tags>CS2010</tags>
<tags>Optional</tags>
<tags>optional</tags>
<tags>CIP</tags>
</deskboard>
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,23 @@ public void execute_invalidIndexFilteredList_throwsCommandException() {
assertCommandFailure(completeCommand, model, Messages.MESSAGE_INVALID_ACTIVITY_DISPLAYED_INDEX);
}

@Test
/**
* Test
*/
//TODO
public void executeUndoRedo_validIndexUnfilteredList_success() throws Exception {
UndoRedoStack undoRedoStack = new UndoRedoStack();
UndoCommand undoCommand = prepareUndoCommand(model, undoRedoStack);
RedoCommand redoCommand = prepareRedoCommand(model, undoRedoStack);
Activity activityToComplete = model.getFilteredActivityList().get(INDEX_FIRST_ACTIVITY.getZeroBased());
CompleteCommand deleteCommand = prepareCommand(INDEX_FIRST_ACTIVITY);
CompleteCommand completeCommand = prepareCommand(INDEX_FIRST_ACTIVITY);
Model expectedModel = new ModelManager(model.getDeskBoard(), new UserPrefs());

// delete -> first activity deleted
deleteCommand.execute();
undoRedoStack.push(deleteCommand);
completeCommand.execute();
undoRedoStack.push(completeCommand);

// undo -> reverts addressbook back to previous state and filtered activity list to show all persons
// undo -> reverts desk board back to previous state and filtered activity list to show all activities
assertCommandSuccess(undoCommand, model, UndoCommand.MESSAGE_SUCCESS, expectedModel);

// redo -> same first activity deleted again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void execute_newEvent_success() throws Exception {
@Test
// Questionable - does the app check for duplicate?
public void execute_duplicateEvent_throwsCommandException() {
Activity activityInList = model.getDeskBoard().getActivityList().get(3);
Activity activityInList = model.getDeskBoard().getActivityList().get(0);
assertCommandFailure(prepareCommand((Event) activityInList, model), model,
EventCommand.MESSAGE_DUPLICATE_EVENT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Collections;

import org.junit.Before;
import org.junit.Test;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.UndoRedoStack;
Expand All @@ -36,7 +35,9 @@ public void setUp() throws Exception {
removeCommandTwo.preprocessUndoableCommand();
}

@Test
/**
* Test
*/
public void execute() {
UndoRedoStack undoRedoStack = prepareStack(
Collections.emptyList(), Arrays.asList(removeCommandTwo, removeCommandOne));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void execute_newTask_success() throws Exception {
@Test
// Questionable - does the app check for duplicate task?
public void execute_duplicateTask_throwsCommandException() {
Activity activityInList = model.getDeskBoard().getActivityList().get(0);
Activity activityInList = model.getDeskBoard().getActivityList().get(1);
assertCommandFailure(prepareCommand((Task) activityInList, model), model, TaskCommand.MESSAGE_DUPLICATE_TASK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Collections;

import org.junit.Before;
import org.junit.Test;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.UndoRedoStack;
Expand All @@ -33,7 +32,9 @@ public void setUp() {
removeCommandTwo.setData(model, EMPTY_COMMAND_HISTORY, EMPTY_STACK);
}

@Test
/**
* Test
*/
public void execute() throws Exception {
UndoRedoStack undoRedoStack = prepareStack(
Arrays.asList(removeCommandOne, removeCommandTwo), Collections.emptyList());
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/seedu/address/model/UniqueActivityListTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package seedu.address.model;

import static org.junit.Assert.assertEquals;
import static seedu.address.testutil.TypicalActivities.ASSIGNMENT1;
import static seedu.address.testutil.TypicalActivities.ASSIGNMENT2;
import static seedu.address.testutil.TypicalActivities.CCA;
import static seedu.address.testutil.TypicalActivities.CIP;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import seedu.address.model.activity.Activity;
import seedu.address.model.activity.Event;
import seedu.address.model.activity.Task;
import seedu.address.model.activity.UniqueActivityList;
import seedu.address.model.activity.exceptions.DuplicateActivityException;

public class UniqueActivityListTest {
@Rule
Expand All @@ -16,4 +26,28 @@ public void internalListAsObservable_modifyList_throwsUnsupportedOperationExcept
thrown.expect(UnsupportedOperationException.class);
uniqueActivityList.internalListAsObservable().remove(0);
}

//@@author karenfrilya97
@Test
public void add_taskWithEarlierDateTimeThanExisting_sortsListAutomatically() throws DuplicateActivityException {
UniqueActivityList uniqueActivityList = new UniqueActivityList();
Task earlierTask = ASSIGNMENT1;
Task laterTask = ASSIGNMENT2;
uniqueActivityList.add(laterTask);
uniqueActivityList.add(earlierTask);
Activity firstActivityOnTheList = uniqueActivityList.internalListAsObservable().get(0);
assertEquals(firstActivityOnTheList, earlierTask);
}

@Test
public void add_eventWithEarlierStartDateTimeThanExisting_sortsListAutomatically()
throws DuplicateActivityException {
UniqueActivityList uniqueActivityList = new UniqueActivityList();
Event earlierEvent = CCA;
Event laterEvent = CIP;
uniqueActivityList.add(laterEvent);
uniqueActivityList.add(earlierEvent);
Activity firstActivityOnTheList = uniqueActivityList.internalListAsObservable().get(0);
assertEquals(firstActivityOnTheList, earlierEvent);
}
}
5 changes: 1 addition & 4 deletions src/test/java/seedu/address/storage/XmlAdaptedTaskTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public class XmlAdaptedTaskTest {
.map(XmlAdaptedTag::new)
.collect(Collectors.toList());

// TODO: 3/26/2018 fix bug
/**
* Test
*/
@Test
public void toModelType_validTaskDetails_returnsTask() throws Exception {
XmlAdaptedTask task = new XmlAdaptedTask(ASSIGNMENT2_TASK);
assertEquals(ASSIGNMENT2_TASK, task.toModelType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static seedu.address.testutil.TypicalActivities.ASSIGNMENT1;
import static seedu.address.testutil.TypicalActivities.ASSIGNMENT3;
import static seedu.address.testutil.TypicalActivities.DEMO1;
import static seedu.address.testutil.TypicalActivities.getTypicalDeskBoard;
Expand Down Expand Up @@ -72,9 +71,7 @@ public void readDeskBoard_invalidAndValidActivityDeskBoard_throwDataConversionEx
readDeskBoard("invalidAndValidActivityDeskBoard.xml");
}

/**
* Test
*/
@Test
public void readAndSaveDeskBoard_allInOrder_success() throws Exception {
String filePath = testFolder.getRoot().getPath() + "TempDeskBoard.xml";
DeskBoard original = getTypicalDeskBoard();
Expand All @@ -87,7 +84,7 @@ public void readAndSaveDeskBoard_allInOrder_success() throws Exception {

//Modify data, overwrite exiting file, and read back
original.addActivity(ASSIGNMENT3);
original.removeActivity(ASSIGNMENT1);
original.removeActivity(ASSIGNMENT3);
xmlDeskBoardStorage.saveDeskBoard(original, filePath);
readBack = xmlDeskBoardStorage.readDeskBoard(filePath).get();
assertEquals(original, new DeskBoard(readBack));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ public class XmlSerializableDeskBoardTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

/**
* Test
*/
@Test
public void toModelType_typicalActivitiesFile_success() throws Exception {
XmlSerializableDeskBoard dataFromFile = XmlUtil.getDataFromFile(TYPICAL_ACTIVITIES_FILE,
XmlSerializableDeskBoard.class);
DeskBoard deskBoardFromFile = dataFromFile.toModelType();
DeskBoard typicalActivitiesDeskBoard = TypicalActivities.getTypicalDeskBoard();
boolean equals = deskBoardFromFile.getTagList().get(1).equals(
typicalActivitiesDeskBoard.getTagList().get(1));
boolean equals2 = deskBoardFromFile.getTagList().get(2).equals(
typicalActivitiesDeskBoard.getTagList().get(2));
boolean equals3 = deskBoardFromFile.getTagList().get(3).equals(
typicalActivitiesDeskBoard.getTagList().get(3));
boolean equals4 = deskBoardFromFile.getTagList().get(4).equals(
typicalActivitiesDeskBoard.getTagList().get(4));

assertEquals(deskBoardFromFile, typicalActivitiesDeskBoard);
}

Expand Down
23 changes: 4 additions & 19 deletions src/test/java/seedu/address/testutil/TypicalActivities.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package seedu.address.testutil;

import static seedu.address.logic.commands.CommandTestUtil.VALID_DATE_TIME_CS2010_QUIZ;
import static seedu.address.logic.commands.CommandTestUtil.VALID_DATE_TIME_MA2108_HOMEWORK;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_CS2010_QUIZ;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_MA2108_HOMEWORK;
import static seedu.address.logic.commands.CommandTestUtil.VALID_REMARK_CS2010_QUIZ;
import static seedu.address.logic.commands.CommandTestUtil.VALID_REMARK_MA2108_HOMEWORK;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_CS2010;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_MA2108;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -45,16 +36,19 @@ public class TypicalActivities {
.withStartDateTime("02/04/2018 08:00")
.withEndDateTime("02/04/2018 12:00")
.withLocation("michegan ave")
.withRemark("nil")
.withTags("CIP").build();
public static final Event EXAM1 = new EventBuilder().withName("CS2101Exam")
.withStartDateTime("28/04/2018 09:00")
.withEndDateTime("28/04/2018 11:00")
.withLocation("MPSH")
.withRemark("nil")
.withTags("CS2101").build();
public static final Event IFG = new EventBuilder().withName("InterFacultyGame")
.withStartDateTime("04/01/2018 20:00")
.withEndDateTime("04/01/2018 22:00")
.withLocation("MPSH 1").build();
.withLocation("MPSH 1")
.withRemark("nil").build();

// Manually added
public static final Task ASSIGNMENT3 = new TaskBuilder().withName("CS2102Assignment")
Expand All @@ -65,15 +59,6 @@ public class TypicalActivities {
.withEndDateTime("04/04/2018 10:00")
.withRemark("FinalDemo").build();

// Manually added - Activity's details found in {@code CommandTestUtil}
public static final Task MA2108_HOMEWORK = new TaskBuilder().withName(VALID_NAME_MA2108_HOMEWORK)
.withDateTime(VALID_DATE_TIME_MA2108_HOMEWORK)
.withRemark(VALID_REMARK_MA2108_HOMEWORK).withTags(VALID_TAG_CS2010).build();
public static final Task CS2010_QUIZ = new TaskBuilder().withName(VALID_NAME_CS2010_QUIZ)
.withDateTime(VALID_DATE_TIME_CS2010_QUIZ)
.withRemark(VALID_REMARK_CS2010_QUIZ).withTags(VALID_TAG_MA2108, VALID_TAG_CS2010)
.build();

public static final String KEYWORD_MATCHING_MEIER = "Meier"; // A keyword that matches MEIER

private TypicalActivities() {} // prevents instantiation
Expand Down

0 comments on commit c980110

Please sign in to comment.