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

Commit

Permalink
Build dev guide
Browse files Browse the repository at this point in the history
  • Loading branch information
li-kai committed Oct 25, 2016
1 parent 190d863 commit a2fb68b
Show file tree
Hide file tree
Showing 14 changed files with 8,153 additions and 89 deletions.
380 changes: 380 additions & 0 deletions collated/main/A0092382A.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,380 @@
# A0092382A
###### \java\seedu\todo\commons\core\TaskViewFilter.java
``` java
public class TaskViewFilter {
private static final Comparator<ImmutableTask> CHRONOLOGICAL = (a, b) -> ComparisonChain.start()
.compare(a.getEndTime().orElse(null), b.getEndTime().orElse(null), Ordering.natural().nullsLast())
.result();

private static final Comparator<ImmutableTask> LAST_UPDATED = (a, b) ->
b.getCreatedAt().compareTo(a.getCreatedAt());

public static final TaskViewFilter DEFAULT = new TaskViewFilter("all",
null, LAST_UPDATED);

public static final TaskViewFilter INCOMPLETE = new TaskViewFilter("incomplete",
task -> !task.isCompleted(), CHRONOLOGICAL);

public static final TaskViewFilter DUE_SOON = new TaskViewFilter("due soon",
task -> !task.isCompleted() && !task.isEvent() && task.getEndTime().isPresent(), CHRONOLOGICAL);

public static final TaskViewFilter EVENTS = new TaskViewFilter("events",
ImmutableTask::isEvent, CHRONOLOGICAL);

public static final TaskViewFilter COMPLETED = new TaskViewFilter("completed",
ImmutableTask::isCompleted, LAST_UPDATED);

public final String name;

public final Predicate<ImmutableTask> filter;

public final Comparator<ImmutableTask> sort;

public final int shortcutCharPosition;

public TaskViewFilter(String name, Predicate<ImmutableTask> filter, Comparator<ImmutableTask> sort) {
this(name, filter, sort, 0);
}

public TaskViewFilter(String name, Predicate<ImmutableTask> filter, Comparator<ImmutableTask> sort, int underlineCharPosition) {
this.name = name;
this.filter = filter;
this.sort = sort;
this.shortcutCharPosition = underlineCharPosition;
}

public static TaskViewFilter[] all() {
return new TaskViewFilter[]{
DEFAULT, COMPLETED, INCOMPLETE, EVENTS, DUE_SOON,
};
}

@Override
public String toString() {
return name;
}
}
```
###### \java\seedu\todo\commons\util\TimeUtil.java
``` java
public boolean isOngoing(LocalDateTime startTime, LocalDateTime endTime) {
if (endTime == null) {
logger.log(Level.WARNING, "endTime in isOngoing(..., ...) is null.");
return false;
}

if (startTime == null) {
logger.log(Level.WARNING, "startTime in isOngoing(..., ...) is null");
return false;
}

return LocalDateTime.now(clock).isAfter(startTime) && LocalDateTime.now(clock).isBefore(endTime);
}

```
###### \java\seedu\todo\logic\commands\CompleteCommand.java
``` java
public class CompleteCommand extends BaseCommand {
private static final String VERB_COMPLETE = "marked complete";
private static final String VERB_INCOMPLETE = "marked incomplete";

private Argument<Integer> index = new IntArgument("index");

private Argument<String> updateAllFlag = new StringArgument("all").flag("all");

@Override
protected Parameter[] getArguments() {
return new Parameter[] { index, updateAllFlag };
}

@Override
public String getCommandName() {
return "complete";
}

@Override
protected void validateArguments() {
if (updateAllFlag.hasBoundValue() && index.hasBoundValue()) {
errors.put("You must either specify an index or an /all flag, not both!");
} else if (!index.hasBoundValue() && !updateAllFlag.hasBoundValue()) {
errors.put("You must specify an index or a /all flag. You have specified none!");
}
}

@Override
public List<CommandSummary> getCommandSummary() {
return ImmutableList.of(new CommandSummary("Mark task as completed", getCommandName(), getArgumentSummary()));
}

@Override
public CommandResult execute() throws ValidationException {
if (index.hasBoundValue()) {
ImmutableTask task = this.model.update(index.getValue(), t -> t.setCompleted(!t.isCompleted()));
eventBus.post(new HighlightTaskEvent(task));
String feedback = task.isCompleted() ? CompleteCommand.VERB_COMPLETE : CompleteCommand.VERB_INCOMPLETE;
return taskSuccessfulResult(task.getTitle(), feedback);
} else {
this.model.updateAll(t -> t.setCompleted(true));
return new CommandResult("All tasks marked as completed");
}
}

}
```
###### \java\seedu\todo\logic\commands\EditCommand.java
``` java
public class EditCommand extends BaseCommand {
private static final String VERB = "edited";

// These parameters will be sorted out manually by overriding setPositionalArgument
private Argument<Integer> index = new IntArgument("index").required();
private Argument<String> title = new StringArgument("title");

private Argument<String> description = new StringArgument("description")
.flag("m");

private Argument<Boolean> pin = new FlagArgument("pin")
.flag("p");

private Argument<String> location = new StringArgument("location")
.flag("l");

private Argument<DateRange> date = new DateRangeArgument("date")
.flag("d");

@Override
protected Parameter[] getArguments() {
return new Parameter[] { index, title, date, description, pin, location };
}

@Override
public String getCommandName() {
return "edit";
}

@Override
public List<CommandSummary> getCommandSummary() {
return ImmutableList.of(new CommandSummary("Edit task", getCommandName(),
getArgumentSummary()));

}

@Override
protected void setPositionalArgument(String argument) {
String[] tokens = argument.trim().split("\\s+", 2);
Parameter[] positionals = new Parameter[]{ index, title };

for (int i = 0; i < tokens.length; i++) {
try {
positionals[i].setValue(tokens[i].trim());
} catch (IllegalValueException e) {
errors.put(positionals[i].getName(), e.getMessage());
}
}
}

@Override
public CommandResult execute() throws ValidationException {
ImmutableTask editedTask = this.model.update(index.getValue(), task -> {
if (title.hasBoundValue()) {
task.setTitle(title.getValue());
}

if (description.hasBoundValue()) {
task.setDescription(description.getValue());
}

if (pin.hasBoundValue()) {
task.setPinned(pin.getValue());
}

if (location.hasBoundValue()) {
task.setLocation(location.getValue());
}

if (date.hasBoundValue()) {
task.setStartTime(date.getValue().getStartTime());
task.setEndTime(date.getValue().getEndTime());
}
});
eventBus.post(new HighlightTaskEvent(editedTask));
if (description.hasBoundValue()) {
eventBus.post(new ExpandCollapseTaskEvent(editedTask));
}
return taskSuccessfulResult(editedTask.getTitle(), EditCommand.VERB);
}

}
```
###### \java\seedu\todo\logic\commands\PinCommand.java
``` java
public class PinCommand extends BaseCommand {
static private final String PIN = "pinned";
static private final String UNPIN = "unpinned";

private Argument<Integer> index = new IntArgument("index").required();

@Override
protected Parameter[] getArguments() {
return new Parameter[]{ index };
}

@Override
public String getCommandName() {
return "pin";
}

@Override
public List<CommandSummary> getCommandSummary() {
return ImmutableList.of(new CommandSummary("Pin task to top of list", getCommandName(),
getArgumentSummary()));
}

@Override
public CommandResult execute() throws ValidationException {
ImmutableTask task = this.model.update(index.getValue(), t -> t.setPinned(!t.isPinned()));
String verb = task.isPinned() ? PinCommand.PIN : PinCommand.UNPIN;
eventBus.post(new HighlightTaskEvent(task));
return taskSuccessfulResult(task.getTitle(), verb);
}

}
```
###### \java\seedu\todo\logic\commands\ViewCommand.java
``` java
public class ViewCommand extends BaseCommand {
private static final String FEEDBACK_FORMAT = "Displaying %s view";

private Argument<String> view = new StringArgument("view").required();

private TaskViewFilter viewSpecified;

@Override
protected Parameter[] getArguments() {
return new Parameter[]{ view };
}

@Override
public String getCommandName() {
return "view";
}

@Override
public List<CommandSummary> getCommandSummary() {
return ImmutableList.of(new CommandSummary("Switch tabs", getCommandName(), getArgumentSummary()));
}

@Override
protected void validateArguments(){
TaskViewFilter[] viewArray = TaskViewFilter.all();
String viewSpecified = view.getValue().trim().toLowerCase();

for (TaskViewFilter filter : viewArray) {
String viewName = filter.name;
char shortcut = viewName.charAt(filter.shortcutCharPosition);
boolean matchesShortcut = viewSpecified.length() == 1 && viewSpecified.charAt(0) == shortcut;

if (viewName.contentEquals(viewSpecified) || matchesShortcut) {
this.viewSpecified = filter;
return;
}
}

String error = String.format("The view %s does not exist", view.getValue());
errors.put("view", error);
}

@Override
public CommandResult execute() throws ValidationException {
model.view(viewSpecified);
String feedback = String.format(ViewCommand.FEEDBACK_FORMAT, viewSpecified);
return new CommandResult(feedback);
}

}
```
###### \java\seedu\todo\model\TodoList.java
``` java
@Override
public void updateAll(List<Integer> indexes, Consumer<MutableTask> update) throws ValidationException {
for (Integer x: indexes) {
MutableTask task = tasks.get(x);
ValidationTask validationTask = new ValidationTask(task);
update.accept(validationTask);
validationTask.validate();
}

for (Integer i : indexes) {
MutableTask task = tasks.get(i);
update.accept(task);
}

saveTodoList();

}

```
###### \java\seedu\todo\model\TodoListModel.java
``` java
/**
* Carries out the specified update in the fields of all visible tasks. Mutation of all {@link Task}
* objects should only be done in the <code>update</code> lambda. The lambda takes in a single parameter,
* a {@link MutableTask}, and does not expect any return value, as per the {@link update} command. Note that
* the 'All' in this case refers to all the indices specified by the accompanying list of indices.
*
* <pre><code>todo.updateAll (List<Integer> tasks, t -> {
* t.setEndTime(t.getEndTime.get().plusHours(2)); // Push deadline of all specified tasks back by 2h
* t.setPin(true); // Pin all tasks specified
* });</code></pre>
*
* @throws ValidationException if any updates on any of the task objects are considered invalid
*/
void updateAll(List<Integer> indexes, Consumer <MutableTask> update) throws ValidationException;

```
###### \java\seedu\todo\model\TodoModel.java
``` java
@Override
public void updateAll(Consumer<MutableTask> update) throws ValidationException {
saveUndoState();
Map<UUID, Integer> uuidMap = new HashMap<>();
for (int i = 0; i < tasks.size(); i++) {
uuidMap.put(tasks.get(i).getUUID(), i);
}
List<Integer> indexes = new ArrayList<>();
for (ImmutableTask task : getObservableList()) {
indexes.add(uuidMap.get(task.getUUID()));
}
todoList.updateAll(indexes, update);
}

```
###### \resources\style\DefaultStyle.css
``` css
/*Ongoing*/
.ongoing {
-fx-background-color: #388E3C;
}

.ongoing .label {
-fx-text-fill: #FFFFFF;
}

.ongoing .roundLabel {
-fx-background-color: #FFFFFF;
-fx-text-fill: #388E3C;
}

.ongoing .pinImage {
-fx-image: url("../images/star_white.png");
}

.ongoing .dateImage {
-fx-image: url("../images/clock_white.png");
}

.ongoing .locationImage {
-fx-image: url("../images/location_white.png");
}

```
Loading

0 comments on commit a2fb68b

Please sign in to comment.