Skip to content

Commit

Permalink
Merge pull request nus-cs2113-AY2223S2#44 from kyrixn/master
Browse files Browse the repository at this point in the history
improved ui and implemented delete all
  • Loading branch information
kyrixn authored Mar 15, 2023
2 parents 1445855 + aed7645 commit 8e8b5a8
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 50 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/duke/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Event(String eventDescription, LocalDateTime start, boolean hasSt) {
this.startTime = start;
this.hasEndTime = false;
this.hasStartTime = hasSt;
this.hasEndTime = false;
this.hasEndInfo = false;
}

public String getDescription() {
Expand Down Expand Up @@ -78,7 +78,7 @@ public void changeTimeInfo(LocalDateTime start, boolean hasSt) {
this.startTime = start;
this.hasEndTime = false;
this.hasStartTime = hasSt;
this.hasEndTime = false;
this.hasEndInfo = false;
}

public LocalDateTime getStartTime() {
Expand Down
21 changes: 17 additions & 4 deletions src/main/java/seedu/duke/EventList.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ public String getDetails(int index) {
return taskList.get(index).toString();
}

public String getDescription(int index) {
return taskList.get(index).getDescription();
}

public String getTime(int index) {
return taskList.get(index).getTime();
}

public void deleteThisTask(int index) {
taskList.remove(index);
listSize--;
}

public ArrayList<Event> fullList() {
return this.taskList;
}

private LocalDateTime changeToDate(String time, String date) {
String combination = date + " " + time;
return LocalDateTime.parse(combination, dfWithTime);
Expand Down Expand Up @@ -145,6 +149,15 @@ public int searchTaskIndex(String description) {
}
return -1;
}

public String getLastTaskDescription() {
return taskList.get(listSize-1).toString();
}

public void deleteAll() {
this.taskList = new ArrayList<Event>();
this.listSize = 0;
}
}

final class TimeAndFlag {
Expand Down
35 changes: 27 additions & 8 deletions src/main/java/seedu/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.util.Arrays;

// import javax.swing.plaf.basic.BasicTreeUI.SelectionModelPropertyChangeHandler;

public class Parser {

private static final int OFFSET = 1;
Expand Down Expand Up @@ -46,20 +48,37 @@ public static void parseCommand(String userInput, EventList eventList) {
}

private static void parseListCommand(EventList eventList) {
Ui.listTask(eventList.fullList());
Ui.listTask(eventList.getFullList());
}

private static void parseDeleteCommand(String remainder, EventList eventList) {
eventList.deleteThisTask(Integer.parseInt(remainder) - OFFSET);

//TODO: Show successful add on UI. (For all cases)
Ui.deleteSuccessMsg();
private static void parseDeleteCommand(String remainder, EventList eventList) throws NPExceptions {
String[] details = remainder.split("-");

if(details.length <= 1) {
throw new NPExceptions("need a flag to specify your action!");
}

String information = details[1].substring(0,1).trim();
if(information.equals("s")) {
int index = Integer.parseInt(details[1].substring(1).trim()) - OFFSET;
String deletedTask = eventList.getDetails(index);
eventList.deleteThisTask(index);
//TODO: Show successful add on UI. (For all cases)
Ui.deleteSuccessMsg(deletedTask);
} else if(details[1].substring(0,3).trim().equals("all")) {
eventList.deleteAll();
Ui.deleteAllSuccess();
} else {
throw new NPExceptions("please input a valid flag!");
}

}

private static void parseAddCommand(String remainder, EventList eventList) throws NPExceptions {
// Method is still broken, someone will have to fix it fully later on when handling exceptions
// Note no "-" anywhere else.
String[] details = remainder.split("-");

if(details.length <= 1) {
throw new NPExceptions("Event description and start day of your event are strictly required!");
}
Expand Down Expand Up @@ -103,7 +122,7 @@ private static void parseAddCommand(String remainder, EventList eventList) throw
eventList.addEvent(eventName, startTime, startDate);
}

Ui.addSuccessMsg();
Ui.addSuccessMsg(eventList.getLastTaskDescription());
}
private static void parseEditCommand(String remainder, EventList eventList) throws NPExceptions{
String[] details = remainder.split("-");
Expand Down Expand Up @@ -133,7 +152,6 @@ private static void parseEditCommand(String remainder, EventList eventList) thro
throw new NPExceptions("Empty starting date detected! Please add starting date.");
} else {
int eventIndex = -1;

details[0] = details[0].trim();
try{
eventIndex = Integer.parseInt(details[0]);
Expand All @@ -151,6 +169,7 @@ private static void parseEditCommand(String remainder, EventList eventList) thro
} else {
eventList.reviseTimeInfo(eventIndex, information[0], information[1]);
}
Ui.editSuccessMsg(eventList.getDescription(eventIndex), eventList.getTime(eventIndex));
}
}
private static void addFormatChecker(String[] information) throws NPExceptions {
Expand Down
66 changes: 35 additions & 31 deletions src/main/java/seedu/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@

public class Ui {
/**
* Prints a line of dashes for
* better readability
* Prints a line of dashes for better readability
*/
public static void printDash() {
System.out.println("____________________________________________________________");
}

/**
* Obtains user input and interprets
* what needs to be performed by
* certain keywords.
* Obtains user input and interprets what needs to be performed by certain keywords.
*/
public static void getUserCommand(EventList eventList) {

Scanner in = new Scanner(System.in);

String cmd;
Expand All @@ -29,26 +25,25 @@ public static void getUserCommand(EventList eventList) {
cmd = in.nextLine();
}

in.close();
}

/**
* Prints a welcome message for
* users when application is launched
* Prints a welcome message for users when application is launched
*/
public static void showWelcome() {
String logo = "█▄ █ █ █ ▄▀▀ █▀▄ █ ▄▀▄ █▄ █ █▄ █ ██▀ █▀▄\n"
+ "█ ▀█ ▀▄█ ▄██ █▀ █▄▄ █▀█ █ ▀█ █ ▀█ █▄▄ █▀▄\n\n";
String logo = "???";
System.out.println(logo + "Hello there! What can we do for you today?");
printDash();
}

/**
* Prints success message for
* users when event is added
* Prints success message for users when event is added
*/
public static void addSuccessMsg() {
public static void addSuccessMsg(String taskDetail) {
printDash();
System.out.println("Event successfully added!");
System.out.println("Event successfully added: "+System.lineSeparator());
System.out.println(" > " + taskDetail);
printDash();
}

Expand All @@ -66,30 +61,21 @@ public static void addSuccessEditMsg() {
* Prints error message for
* users when there is unrecognised
* command
* Prints error message for users when there is unrecognised command
*/
public static void addErrorMsg() {
printDash();
System.out.println("Sorry, I don't understand you!");
printDash();
}

/**
* Prints error message for
* users with any error occurs
/*
* Prints success message for users when event is deleted
*/
public static void printErrorMsg(String s){
public static void deleteSuccessMsg(String taskDetail) {
printDash();
System.out.println(s);
printDash();
}

/**
* Prints success message for
* users when event is deleted
*/
public static void deleteSuccessMsg() {
printDash();
System.out.println("Event(s) successfully deleted!");
System.out.println("This event is deleted: "+System.lineSeparator());
System.out.println(" > "+taskDetail);
printDash();
}

Expand All @@ -110,12 +96,30 @@ public static void listTask(ArrayList<Event> eventList) {
}

/**
* Prints an exit message when
* user intends to exit Duke
* Prints an exit message when user intends to exit Duke
*/
public static void printExit() {
printDash();
System.out.println("Bye, see ya soon!");
printDash();
}

public static void printErrorMsg (String errorMessage) {
printDash();
System.out.println(errorMessage);
printDash();
}

public static void editSuccessMsg(String description, String time) {
printDash();
System.out.println("Time of event: " + description + " is changed to: ");
System.out.println(" > " + time);
printDash();
}

public static void deleteAllSuccess() {
printDash();
System.out.println(" > all events are deleted!");
printDash();
}
}
2 changes: 1 addition & 1 deletion src/test/java/seedu/duke/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void testParseAddCommand() {
}
@Test
void testParserDeleteCOmmand(){
parser.parseCommand("delete 1", eventList);
parser.parseCommand("delete -s 1", eventList);
assert(eventList.getSize()==0);
}
// @Test
Expand Down
5 changes: 1 addition & 4 deletions text-ui-test/EXPECTED.TXT
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
█▄ █ █ █ ▄▀▀ █▀▄ █ ▄▀▄ █▄ █ █▄ █ ██▀ █▀▄
█ ▀█ ▀▄█ ▄██ █▀ █▄▄ █▀█ █ ▀█ █ ▀█ █▄▄ █▀▄

Hello there! What can we do for you today?
???Hello there! What can we do for you today?
____________________________________________________________

0 comments on commit 8e8b5a8

Please sign in to comment.