Skip to content

Commit

Permalink
Merge pull request #104 from DanKhoo/fix_UI_bug
Browse files Browse the repository at this point in the history
Fix ui bug
  • Loading branch information
IamRENCE authored Nov 7, 2018
2 parents 0b44bbd + 439536d commit 92e7785
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package seedu.address.commons.events.ui;

import seedu.address.commons.events.BaseEvent;

/**
* A UI event class that is used to hide the {@code StaffPanel}
*/
public class HideStaffPanelEvent extends BaseEvent {

@Override
public String toString() {
return getClass().getSimpleName();
}
}
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import java.util.List;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.HideStaffPanelEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand Down Expand Up @@ -43,6 +45,11 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
model.commitAddressBook();

if (lastShownList.isEmpty()) {
EventsCenter.getInstance().post(new HideStaffPanelEvent());
}

return new CommandResult(String.format(MESSAGE_DELETE_PERSON_SUCCESS, personToDelete));
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.JumpToListRequestEvent;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
Expand Down Expand Up @@ -105,6 +107,10 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
model.updatePerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();

Index indexEdited = Index.fromZeroBased(model.getFilteredPersonList().indexOf(editedPerson));
EventsCenter.getInstance().post(new JumpToListRequestEvent(indexEdited));

return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, editedPerson));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import java.util.List;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.JumpToListRequestEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand Down Expand Up @@ -64,6 +66,10 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
model.updatePerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();

Index indexEdited = Index.fromZeroBased(model.getFilteredPersonList().indexOf(editedPerson));
EventsCenter.getInstance().post(new JumpToListRequestEvent(indexEdited));

return new CommandResult(String.format(MESSAGE_FEEDBACK_PERSON_SUCCESS, editedPerson));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import java.util.Optional;
import java.util.Set;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.JumpToListRequestEvent;
import seedu.address.commons.util.CollectionUtil;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
Expand Down Expand Up @@ -79,6 +81,10 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
model.updatePerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();

Index indexEdited = Index.fromZeroBased(model.getFilteredPersonList().indexOf(editedPerson));
EventsCenter.getInstance().post(new JumpToListRequestEvent(indexEdited));

return new CommandResult(String.format(MESSAGE_EDIT_PRIVACY_SUCCESS, editedPerson));
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/logic/commands/RateCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import java.util.List;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.commons.events.ui.JumpToListRequestEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand Down Expand Up @@ -70,6 +72,10 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
model.updatePerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
model.commitAddressBook();

Index indexEdited = Index.fromZeroBased(model.getFilteredPersonList().indexOf(editedPerson));
EventsCenter.getInstance().post(new JumpToListRequestEvent(indexEdited));

return new CommandResult(String.format(MESSAGE_RATING_PERSON_SUCCESS, editedPerson));
}

Expand Down
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/logic/commands/RedoCommand.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.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.events.ui.HideStaffPanelEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand All @@ -13,7 +15,8 @@
public class RedoCommand extends Command {

public static final String COMMAND_WORD = "redo";
public static final String MESSAGE_SUCCESS = "Redo success!";
public static final String MESSAGE_SUCCESS = "Redo success!" + "\n"
+ "Any staff panel previously selected will now be unselected";
public static final String MESSAGE_FAILURE = "No more commands to redo!";

@Override
Expand All @@ -26,6 +29,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

model.redoAddressBook();
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

EventsCenter.getInstance().post(new HideStaffPanelEvent());
return new CommandResult(MESSAGE_SUCCESS);
}
}
7 changes: 6 additions & 1 deletion src/main/java/seedu/address/logic/commands/UndoCommand.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.model.Model.PREDICATE_SHOW_ALL_PERSONS;

import seedu.address.commons.core.EventsCenter;
import seedu.address.commons.events.ui.HideStaffPanelEvent;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
Expand All @@ -13,7 +15,8 @@
public class UndoCommand extends Command {

public static final String COMMAND_WORD = "undo";
public static final String MESSAGE_SUCCESS = "Undo success!";
public static final String MESSAGE_SUCCESS = "Undo success!" + "\n"
+ "Any staff panel previously selected will now be unselected";
public static final String MESSAGE_FAILURE = "No more commands to undo!";

@Override
Expand All @@ -26,6 +29,8 @@ public CommandResult execute(Model model, CommandHistory history) throws Command

model.undoAddressBook();
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);

EventsCenter.getInstance().post(new HideStaffPanelEvent());
return new CommandResult(MESSAGE_SUCCESS);
}
}
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
public class Manager {

public static final String MESSAGE_CONSTRAINTS =
"Managers should only contain alphanumeric characters and spaces, and it should not be blank";
"Managers should only contain alphabetical characters and spaces, and it should not be blank";

/**
* The first character of the manager must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "[\\p{Alpha}][\\p{Alpha} ]*";

public final String fullName;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/model/person/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
public class Name {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
"Names should only contain alphabetical characters and spaces, and it should not be blank";

/*
* The first character of the address must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[\\p{Alnum}][\\p{Alnum} ]*";
public static final String VALIDATION_REGEX = "[\\p{Alpha}][\\p{Alpha} ]*";

public final String fullName;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.ExitAppRequestEvent;
import seedu.address.commons.events.ui.HideStaffPanelEvent;
import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent;
import seedu.address.commons.events.ui.ShowHelpRequestEvent;
import seedu.address.logic.Logic;
Expand Down Expand Up @@ -209,4 +210,10 @@ private void handlePersonPanelSelectionChangedEvent(PersonPanelSelectionChangedE
logger.info(LogsCenter.getEventHandlingLogMessage(event));
enableStaffPanel();
}

@Subscribe
private void handleHideStaffPanelEvent(HideStaffPanelEvent event) {
logger.info(LogsCenter.getEventHandlingLogMessage(event));
staffPlaceholder.setVisible(false);
}
}
8 changes: 4 additions & 4 deletions src/main/resources/view/PersonListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
<Region fx:constant="USE_PREF_SIZE" />
</minWidth>
</Label>
<Label fx:id="name" styleClass="cell_big_label" />
<Label fx:id="favouritedName" styleClass="cell_favourite_label" />
<Label fx:id="name" wrapText="true" styleClass="cell_big_label" />
<Label fx:id="favouritedName" wrapText="true" styleClass="cell_favourite_label" />
</HBox>
<FlowPane fx:id="tags" />
<Label fx:id="department" styleClass="cell_small_label" text="\$department" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="department" wrapText="true" styleClass="cell_small_label" text="\$department" />
<Label fx:id="email" wrapText="true" styleClass="cell_small_label" text="\$email" />
</VBox>
<rowConstraints>
<RowConstraints />
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/model/person/ManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public void isValidManager() {
assertFalse(Manager.isValidManager(" ")); // spaces only
assertFalse(Manager.isValidManager("^")); // only non-alphanumeric characters
assertFalse(Manager.isValidManager("peter*")); // contains non-alphanumeric characters
assertFalse(Manager.isValidManager("peter the 2nd")); // alphanumeric characters
assertFalse(Manager.isValidManager("12345")); // numbers only

// valid manager
assertTrue(Manager.isValidManager("peter jack")); // alphabets only
assertTrue(Manager.isValidManager("12345")); // numbers only
assertTrue(Manager.isValidManager("peter the 2nd")); // alphanumeric characters
assertTrue(Manager.isValidManager("Capital Tan")); // with capital letters
assertTrue(Manager.isValidManager("David Roger Jackson Ray Jr 2nd")); // long names
assertTrue(Manager.isValidManager("David Roger Jackson Ray Jr")); // long names
}
}
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/model/person/NameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public void isValidName() {
assertFalse(Name.isValidName(" ")); // spaces only
assertFalse(Name.isValidName("^")); // only non-alphanumeric characters
assertFalse(Name.isValidName("peter*")); // contains non-alphanumeric characters
assertFalse(Name.isValidName("12345")); // numbers only
assertFalse(Name.isValidName("peter the 2nd")); // alphanumeric characters

// valid name
assertTrue(Name.isValidName("peter jack")); // alphabets only
assertTrue(Name.isValidName("12345")); // numbers only
assertTrue(Name.isValidName("peter the 2nd")); // alphanumeric characters
assertTrue(Name.isValidName("Capital Tan")); // with capital letters
assertTrue(Name.isValidName("David Roger Jackson Ray Jr 2nd")); // long names
assertTrue(Name.isValidName("David Roger Jackson Ray Jr nd")); // long names
}
}
6 changes: 5 additions & 1 deletion src/test/java/seedu/address/ui/PersonListPanelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ private Path createXmlFileWithPersons(int personCount) throws Exception {
builder.append("<addressbook>\n");
for (int i = 0; i < personCount; i++) {
builder.append("<persons>\n");
builder.append("<name>").append(i).append("a</name>\n");
builder.append("<name>");
for (int n = 0; n < i; n++) {
builder.append("a");
}
builder.append("a</name>\n");
builder.append("<phone>91239090</phone>\n");
builder.append("<email>a@aa</email>\n");
builder.append("<address>a</address>\n");
Expand Down

0 comments on commit 92e7785

Please sign in to comment.