Skip to content

Commit

Permalink
Merge 11e524c into e7c9236
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aslam-mj2 committed Nov 9, 2018
2 parents e7c9236 + 11e524c commit 2e8a4e1
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 86 deletions.
1 change: 1 addition & 0 deletions docs/team/m-aslam-mj2.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Trajectory is a lightweight management system for those who need a no-frills sol
* *Minor enhancement*: built an utility class for the rendering of data into HTML (Bootstrap).

* *Code contributed*: [https://github.com[Functional code]] [https://github.com[Test code]] _{give links to collated code files}_
* *Code contributed*: https://nuscs2113-ay1819s1.github.io/dashboard/#=undefined&search=m-aslam-mj2[Project Code Dashboard]

* *Other contributions*:

Expand Down
3 changes: 3 additions & 0 deletions inputs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
course add c/ECONS n/Economics f/Faculty of Arts and Social Science
course delete c/ECONS
course list
4 changes: 4 additions & 0 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import seedu.address.commons.exceptions.DataConversionException;
import seedu.address.commons.util.ConfigUtil;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.ExpeditedInputs;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.AddressBook;
Expand Down Expand Up @@ -69,6 +70,7 @@ public void init() throws Exception {
initLogging(config);

StorageController.retrieveData();
ExpeditedInputs.loadInputData();

model = initModelManager(storage, userPrefs);
StudentManager sm = StudentManager.getInstance();
Expand All @@ -79,6 +81,8 @@ public void init() throws Exception {
ui = new UiManager(logic, config, userPrefs);

initEventsCenter();


}

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

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

/**
* This class provides for the expediting of user input,
* by way of pre-typed commands to speed up the flow of a presentation.
*/
public class ExpeditedInputs {
// DEBUG CLASS FOR PRESENTATION
private static ArrayList<String> commands = new ArrayList<String>();
private static int counter = 0;

/**
* Loads input data (pre-typed commands).
*/
public static void loadInputData() {
try (BufferedReader br = new BufferedReader(new FileReader("inputs.txt"))) {
String line;
while ((line = br.readLine()) != null) {
commands.add(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}


public static String getNextCommand() {
counter++;
return commands.get(counter - 1);
}

public static String getPreviousCommand() {
counter--;
return commands.get(counter + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class CourseListCommand extends Command {

public static final String COMMAND_WORD = "course list";

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


@Override
public CommandResult execute(Model model, CommandHistory history) {
CourseManager cm = CourseManager.getInstance();
return new CommandResult(MESSAGE_SUCCESS + "\n" + "", cm.getTableRepresentation());
return new CommandResult(MESSAGE_SUCCESS, cm.getTableRepresentation());
}
}
57 changes: 55 additions & 2 deletions src/main/java/seedu/address/logic/commands/DebugCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
package seedu.address.logic.commands;

import java.util.HashSet;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.StorageController;
import seedu.address.model.course.Course;
import seedu.address.model.course.CourseCode;
import seedu.address.model.course.CourseManager;
import seedu.address.model.course.CourseName;
import seedu.address.model.course.FacultyName;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.MatricNo;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.student.StudentManager;
import seedu.address.ui.HtmlTableProcessor;


/**
* This class is designed for debug use only.
*/
Expand All @@ -14,8 +30,45 @@ public class DebugCommand extends Command {
public CommandResult execute(Model model, CommandHistory history) throws CommandException {

StringBuilder sb = new StringBuilder();
sb.append(StudentManager.getInstance().retrieveStudentByMatricNo("A01").getEmail());

StorageController.wipeAllProductionData();
StorageController.createFiles();
CourseManager.getInstance().clearAll();
StudentManager.getInstance().initializeModel(model);
model.resetData(new AddressBook());
model.commitAddressBook();

CourseManager.getInstance().addCourse(new Course(new CourseCode("CEG"),
new CourseName("Computer Engineering"), new FacultyName("Faculty of Engineering")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("MECHENG"),
new CourseName("Mechanical Engineering"), new FacultyName("Faculty of Engineering")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("EEE"),
new CourseName("Electrical Engineering"), new FacultyName("Faculty of Engineering")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("CS"),
new CourseName("Computer Science"), new FacultyName("School of Computing")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("IS"),
new CourseName("Information Systems"), new FacultyName("School of Computing")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("INFOSEC"),
new CourseName("Information Security"), new FacultyName("School of Computing")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("BA"),
new CourseName("Business Analytics"), new FacultyName("School of Computing")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("POLSCI"),
new CourseName("Political Science"), new FacultyName("Faculty of Arts and Social Sciences")));
CourseManager.getInstance().saveCourseList();

model.addPerson(new Person(new Name("Megan Nicole"), new Phone("91234567"),
new Email("megannicole@u.nus.edu"), new Address("1 Park Avenue"),
new HashSet<>(), new CourseCode("CEG"), new MatricNo("A0168372L")));
model.addPerson(new Person(new Name("James Bond"), new Phone("98367527"),
new Email("jamesbond@u.nus.edu"), new Address("Blk 211 Bedok Avenue 3"),
new HashSet<>(), new CourseCode("CEG"), new MatricNo("A0166371K")));
model.addPerson(new Person(new Name("Natalie Shimmie"), new Phone("81112222"),
new Email("natalie_s@u.nus.edu"), new Address("Blk 92 Punggol"),
new HashSet<>(), new CourseCode("EEE"), new MatricNo("A0196361C")));
model.commitAddressBook();


return new CommandResult("DEBUG COMMAND EXECUTED. ",
HtmlTableProcessor.getH1Representation(sb.toString()));
HtmlTableProcessor.getH1Representation("Populated data set."));
}
}
14 changes: 13 additions & 1 deletion src/main/java/seedu/address/model/StorageController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ public static void wipeAllTestData() {
}
}

}

/**
* This method wipes all production files.
*/
public static void wipeAllProductionData() {
for (File file: new File(BASE_DIRECTORY).listFiles()) {
if (!file.isDirectory()) {
file.delete();
}
}

}
/**
* This method retrieves all datasets saved locally.
Expand Down Expand Up @@ -143,7 +155,7 @@ public static void retrieveData() {
/**
* This method creates files for all datasets if they do not exist on the local filesystem.
*/
private static void createFiles() {
public static void createFiles() {
new File(BASE_DIRECTORY).mkdirs();
File classes = new File(storageClasses);
File courses = new File(storageCourses);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/seedu/address/model/course/CourseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ public boolean hasCourse(String courseCode) {
return false;
}

/**
* Removes all courses.
*/
public void clearAll() {
courseList = new ArrayList<Course>();
}

public String getTableRepresentation() {
StringBuilder sb = new StringBuilder();

sb.append(HtmlTableProcessor.getH3Representation("Course List"));
sb.append(HtmlTableProcessor.getBanner("Course List"));
sb.append(HtmlTableProcessor.renderTableStart(new ArrayList<String>(
Arrays.asList("Course Name", "Course Code", "School/Faculty"))));

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.NewInfoMessageEvent;
import seedu.address.commons.events.ui.NewResultAvailableEvent;
import seedu.address.logic.ExpeditedInputs;
import seedu.address.logic.ListElementPointer;
import seedu.address.logic.Logic;
import seedu.address.logic.commands.CommandResult;
Expand Down Expand Up @@ -56,6 +57,13 @@ private void handleKeyPress(KeyEvent keyEvent) {
keyEvent.consume();
navigateToNextInput();
break;
case RIGHT:
commandTextField.setText(ExpeditedInputs.getNextCommand());
break;
case LEFT:
commandTextField.setText(ExpeditedInputs.getPreviousCommand());
break;

default:
// let JavaFx handle the keypress
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/ui/HtmlTableProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public static String renderCard(String text) {
+ "</div></div></div></div>";
}

public static String getBanner(String text) {
return "<nav class=\"navbar navbar-expand-lg navbar-dark bg-primary\">\n"
+ " <h3>" + text + "</h3>\n"
+ "\n"
+ "</nav>";
}

public static String getH3Representation(String text) {
return "<h3>" + text + "</h3>\n";
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/resources/view/default.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="DarkTheme.css">
<link rel="stylesheet" href="">
</head>

<body class="background">
<div class="jumbotron">
<h1 class="display-4">Welcome to Trajectory!</h1>
<p class="lead">Try the 'help' command to see what you can do with the system.</p>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class CommandTestUtil {
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
public static final String VALID_COURSE_CODE_CEG = "CEG";
public static final String VALID_COURSE_CODE_CS = "CS";
public static final String VALID_COURSE_NAME_CEG = "Computer Engineering";
public static final String VALID_COURSE_NAME_CS = "Computer Science";
public static final String VALID_MATRIC_NO_MEGAN = "A0168412C";
public static final String VALID_MATRIC_NO_TAYLOR = "A0168412D";
public static final String VALID_CLASS_T16 = "T16";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package seedu.address.logic.commands;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CourseAddCommand.MESSAGE_SUCCESS;

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

import seedu.address.logic.CommandHistory;

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.StorageController;
import seedu.address.model.course.Course;
import seedu.address.model.course.CourseCode;
import seedu.address.model.course.CourseManager;
import seedu.address.model.course.CourseName;
import seedu.address.model.course.FacultyName;
import seedu.address.testutil.CourseBuilder;

import java.util.ArrayList;
import java.util.Arrays;

import static java.util.Objects.requireNonNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CourseAddCommand.MESSAGE_SUCCESS;

/**
* This is a test class for CourseAddCommand
*/
public class CourseAddCommandTest {

private static final CommandHistory EMPTY_COMMAND_HISTORY = new CommandHistory();
Expand All @@ -40,14 +40,15 @@ public void constructor_nullCourse_throwsNullPointerException() {

@Test
public void execute_addSuccessful() {

StorageController.enterTestMode();
final CourseCode courseCode = new CourseCode("CES");
final CourseName courseName = new CourseName("Computer Engineering");
final FacultyName faculty = new FacultyName("School of Computing");
final CourseCode courseCode = new CourseCode("CES");
final CourseName courseName = new CourseName("Computer Engineering");
final FacultyName faculty = new FacultyName("School of Computing");

assertCommandSuccess(new CourseAddCommand(new Course(courseCode,courseName,faculty)), new CommandHistory(),
assertCommandSuccess(new CourseAddCommand(new Course(courseCode, courseName, faculty)), new CommandHistory(),
String.format(MESSAGE_SUCCESS, courseName));
assertEquals(EMPTY_COMMAND_HISTORY, commandHistory);
assertEquals(EMPTY_COMMAND_HISTORY, commandHistory);

}

Expand All @@ -56,7 +57,7 @@ public void execute_duplicateCourse_throwsCommandException() throws Exception {
StorageController.enterTestMode();
Course validCourse = new CourseBuilder().build();
CourseAddCommand addCommand = new CourseAddCommand(validCourse);
CourseManagerStub cmStub = new CourseManagerStubWithCourse(validCourse);


thrown.expect(CommandException.class);
thrown.expectMessage(CourseAddCommand.MESSAGE_DUPLICATE_COURSE);
Expand All @@ -71,37 +72,17 @@ public void equals() {
Course ceg = new CourseBuilder().withCourseName("CEG").build();
Course cs = new CourseBuilder().withCourseName("CS").build();

CourseAddCommand addCEGCommand = new CourseAddCommand(ceg);
CourseAddCommand addCSCommand = new CourseAddCommand(cs);

assertTrue(addCEGCommand.equals(addCEGCommand));


CourseAddCommand addCEGCommandCopy = new CourseAddCommand(ceg);
assertTrue(addCEGCommand.equals(addCEGCommand));
assertFalse(addCEGCommand.equals(1));
assertFalse(addCEGCommand.equals(null));
assertFalse(addCEGCommand.equals(addCSCommand));


}
private class CourseManagerStub {
private ArrayList<Course> courseList = new ArrayList<Course>();

}
CourseAddCommand addCegCommand = new CourseAddCommand(ceg);
CourseAddCommand addCsCommand = new CourseAddCommand(cs);

private class CourseManagerStubWithCourse extends CourseManagerStub {
private final Course course;
assertTrue(addCegCommand.equals(addCegCommand));

CourseManagerStubWithCourse(Course course) {
requireNonNull(course);
this.course = course;
}
CourseAddCommand addCegCommandCopy = new CourseAddCommand(ceg);
assertTrue(addCegCommand.equals(addCegCommand));
assertFalse(addCegCommand.equals(1));
assertFalse(addCegCommand.equals(null));
assertFalse(addCegCommand.equals(addCsCommand));

public boolean hasCourse(Course course){
requireNonNull(course);
return this.course.equals(course);
}

}
}
Expand Down

0 comments on commit 2e8a4e1

Please sign in to comment.