Skip to content

Commit

Permalink
Current Code does not allow for updating of task
Browse files Browse the repository at this point in the history
User may have made small errors when adding task and needs to delete and add

This is not user friendly and waste a lot of time

Hence new gui allows for updating of task easily
  • Loading branch information
yulonglim committed Sep 7, 2021
1 parent 08ca499 commit 0340b8a
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 90 deletions.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand Down
22 changes: 4 additions & 18 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -54,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -64,28 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
117 changes: 75 additions & 42 deletions src/main/java/duke/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import javafx.scene.control.TextField;

import java.io.IOException;
import java.util.ArrayList;


/**
* Controller class for the JavaFX application
* Controls the input given by user
*/
public class Controller {

private static final Storage storage = new Storage("C:\\Users\\65906\\IdeaProjects\\ip\\duke.txt");
private static Storage storage = new Storage("C:\\Users\\65906\\IdeaProjects\\ip\\duke.txt");
private static TaskList tasks;

@FXML
Expand Down Expand Up @@ -47,27 +45,39 @@ public class Controller {
@FXML
private TextField findText;

/**
* Loads the tasklist when the load button is pressed
*
* @param a action of pressing load button
*/
@FXML
private TextField updateIndex;

@FXML
private TextField updateDescription;

@FXML
private Label updateError;

@FXML
private DatePicker updateDate;

public void load(ActionEvent a) {
{
try {
tasks = new TaskList(storage.load());
} catch (IOException | DukeException e) {
tasks = new TaskList();
}
listLabel.setText(tasks.toString());
String listContent = "";
for (int i = 0; i < tasks.size(); i++) {
listContent += (i + 1) + ". " + tasks.getTask(i).toString() + "\n";
}
listLabel.setText("Here are the tasks in your list:\n" + listContent);
}
}

/**
* Loads updated tasklist when other buttons are pressed
*/
public void load() {
listLabel.setText(tasks.toString());
String listContent = "";
for (int i = 0; i < tasks.size(); i++) {
listContent += (i + 1) + ". " + tasks.getTask(i).toString() + "\n";
}
listLabel.setText("Here are the tasks in your list:\n" + listContent);
try {
storage.save(tasks);
} catch (IOException e) {
Expand All @@ -76,20 +86,28 @@ public void load() {
addTaskError.setText("");
deleteError.setText("");
doneError.setText("");
updateError.setText("");
}

public Task taskParse(String type, String description, String dateTime){
if (type.equalsIgnoreCase("T")) {
return new Todo(description);
} else if (type.equalsIgnoreCase("D")) {
return new Deadline(description,dateTime);
} else if (type.equalsIgnoreCase("E")) {
return new Event(description,dateTime);
} else {
return null;
}
}

/**
* Adds a task to the list when add button is pressed
*
* @param a action of pressing add button
*/
public void add(ActionEvent a) {
if (taskType.getText().equalsIgnoreCase("T")) {
tasks.addTask(Parser.taskParse(taskType.getText(), taskDescription.getText(), ""));
tasks.addTask(taskParse(taskType.getText(), taskDescription.getText(), ""));
this.load();
} else if (taskType.getText().equalsIgnoreCase("D") || taskType.getText().equalsIgnoreCase("E")) {
tasks.addTask(Parser.taskParse(taskType.getText(), taskDescription.getText(),
assert addTaskError.getText().equals("");
} else if (taskType.getText().equalsIgnoreCase("D") || taskType.getText().equalsIgnoreCase( "E")) {
tasks.addTask(taskParse(taskType.getText(), taskDescription.getText(),
taskDate.getValue().toString()));
this.load();
assert addTaskError.getText().equals("");
Expand All @@ -99,15 +117,10 @@ public void add(ActionEvent a) {

}

/**
* Mark a task as done on the list when done button is pressed
*
* @param a action of press add button
*/
public void done(ActionEvent a) {
try {
int doneIndex = Integer.parseInt(doneText.getText()) - 1;
if (doneIndex > tasks.size() - 1 || doneIndex < 0) {
if(doneIndex > tasks.size() - 1 || doneIndex < 0) {
doneError.setText("Please enter a number in the list");
} else {
tasks.markAsDone(doneIndex);
Expand All @@ -119,15 +132,10 @@ public void done(ActionEvent a) {
}
}

/**
* Deletes a task to the list when delete button is pressed
*
* @param a action of press delete button
*/
public void delete(ActionEvent a) {
public void delete(ActionEvent a){
try {
int deleteIndex = Integer.parseInt(deleteText.getText()) - 1;
if (deleteIndex > tasks.size() - 1 || deleteIndex < 0) {
if(deleteIndex > tasks.size() - 1 || deleteIndex < 0) {
deleteError.setText("Please enter a number in the list");
} else {
tasks.removeTask(deleteIndex);
Expand All @@ -139,12 +147,37 @@ public void delete(ActionEvent a) {
}
}

/**
* Displays a filtered tasklist given a string to find
*
* @param a action of press find button
*/
public void update(ActionEvent a) {
try {
int index = Integer.parseInt(updateIndex.getText()) - 1;
if(index > tasks.size() - 1 || index < 0) {
updateError.setText("Please enter a number in the list");
} else {
tasks.updateTask(index, updateDescription.getText(), updateDate.getValue());
this.load();
assert updateError.getText().equals("");
}
} catch (NumberFormatException e) {
updateError.setText("Please enter integer");
}
}

public void find(ActionEvent a) {
listLabel.setText(tasks.findTask(findText.getText()) + "Press load to go back!");
ArrayList<Task> result = new ArrayList<>();
String listContent = "";

for (int i = 0; i < tasks.size(); i++) {
if (tasks.getTask(i).description.contains(findText.getText())) {
result.add(tasks.getTask(i));
}
}
if (result.size() == 0) {
listLabel.setText("There are no matching task in your list!\nPress load to go back!");
} else {
for (int i = 0; i < result.size(); i++) {
listContent += (i + 1) + ". " + result.get(i).toString() + "\n";
}
listLabel.setText("Here are the matching tasks in your list:\n" + listContent + "Press load to go back!");
}
}
}
4 changes: 4 additions & 0 deletions src/main/java/duke/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Deadline(String description, String by) {
}
}

public void changeDate(LocalDate date) {
this.date = date;
}

@Override
public String toString() {
return "[D]" + super.toString() + " (by: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/duke/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public Event(String description, String at) {
}
}

public void changeDate(LocalDate date) {
this.date = date;
}

@Override
public String toString() {
return "[E]" + super.toString() + " (at: " + date.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/duke/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public void markAsDone() {
this.isDone = true;
}

/**
* Marks task as not done
*/
public void markUndone() { this.isDone = false; }

/**
* Changes description of task
*
* @param description to change into
*/
public void changeDescription(String description) {
this.description = description;
}

@Override
public String toString() {
return String.format("[%s] %s", this.getStatusIcon(), this.description);
Expand Down
26 changes: 24 additions & 2 deletions src/main/java/duke/TaskList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package duke;

import java.time.LocalDate;
import java.util.ArrayList;

public class TaskList {
Expand Down Expand Up @@ -33,6 +34,27 @@ public Task getTask(int index) {
return this.list.get(index);
}

public void updateTask(int index, String description, LocalDate date) {
if (description.equalsIgnoreCase("")) {
if (date != null) {
if (this.list.get(index) instanceof Event) {
((Event) this.list.get(index)).changeDate(date);
} else if (this.list.get(index) instanceof Deadline) {
((Deadline) this.list.get(index)).changeDate(date);
}
}
} else {
this.getTask(index).changeDescription(description);
if (date != null) {
if (this.list.get(index) instanceof Event) {
((Event) this.list.get(index)).changeDate(date);
} else if (this.list.get(index) instanceof Deadline) {
((Deadline) this.list.get(index)).changeDate(date);
}
}
}
}

public int size() {
return this.list.size();
}
Expand All @@ -58,11 +80,11 @@ public String findTask(String find) {

@Override
public String toString() {
if(this.list.isEmpty()) {
if (this.list.isEmpty()) {
return "There are no tasks in your list!\n";
} else {
String listContent = "Here are the tasks in your list:\n";
for (int i = 0 ; i < list.size() ; i++) {
for (int i = 0; i < list.size(); i++) {
listContent += (i + 1) + ". " + list.get(i).toString() + "\n";
}
return listContent;
Expand Down
Loading

0 comments on commit 0340b8a

Please sign in to comment.