Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update UI to display Organization and Recruiter information #37

Merged
merged 6 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/seedu/address/commons/util/StringUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,25 @@ public static boolean isNonZeroUnsignedInteger(String s) {
return false;
}
}

/**
* Formats the given values with the format string, but return null if any of the given values are null or empty.
*
* @param format The format string to use.
* @param values The values to insert into the format string.
* @return The formatted string, or null if any of the values are null.
*/
public static String formatWithNullFallback(String format, Object... values) {
if (format == null) {
return null;
}

for (Object v : values) {
if (v == null || v.toString().isBlank()) {
return null;
}
}

return String.format(format, values);
}
}
91 changes: 87 additions & 4 deletions src/main/java/seedu/address/ui/ContactCard.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package seedu.address.ui;

import java.util.Comparator;
import java.util.function.Supplier;

import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import seedu.address.commons.util.StringUtil;
import seedu.address.model.person.Contact;
import seedu.address.model.person.Id;
import seedu.address.model.person.Organization;
import seedu.address.model.person.Recruiter;

/**
* An UI component that displays information of a {@code Contact}.
Expand All @@ -29,16 +35,28 @@ public class ContactCard extends UiPart<Region> {
@FXML
private HBox cardPane;
@FXML
private VBox cardPaneInnerVbox;
@FXML
private Label name;
@FXML
private Label index;
@FXML
private Label id;
@FXML
private Label linkedParentOrganization;
@FXML
private Label phone;
@FXML
private Label address;
@FXML
private Label email;
@FXML
private Label status;
@FXML
private Label position;
@FXML
private Label url;
@FXML
private FlowPane tags;

/**
Expand All @@ -47,13 +65,78 @@ public class ContactCard extends UiPart<Region> {
public ContactCard(Contact contact, int displayedIndex) {
super(FXML);
this.contact = contact;
id.setText(displayedIndex + ". ");

index.setText(String.format("%d. ", displayedIndex));
id.setText(contact.getId().value);
name.setText(contact.getName().fullName);
phone.setText(contact.getPhone().value);
address.setText(contact.getAddress().value);
email.setText(contact.getEmail().value);

final Label typeLabel = new Label(contact.getType().toString());
typeLabel.setId("type");
tags.getChildren().add(typeLabel); // add it to the front of tags

setVboxInnerLabelText(phone, () -> contact.getPhone().value);
setVboxInnerLabelText(address, () -> contact.getAddress().value);
setVboxInnerLabelText(email, () -> contact.getEmail().value);
setVboxInnerLabelText(url, () -> contact.getUrl().value);

switch (contact.getType()) {
case ORGANIZATION: {
Organization organization = (Organization) contact;
final String statusString = organization.getStatus().applicationStatus;
final String positionString = organization.getPosition().jobPosition;

setVboxInnerLabelText(
status, () -> StringUtil.formatWithNullFallback("Application Status: %s", statusString)
);
setVboxInnerLabelText(
position, () -> StringUtil.formatWithNullFallback("Application Position: %s", positionString)
);
cardPaneInnerVbox.getChildren().remove(linkedParentOrganization);
break;
}
case RECRUITER: {
Recruiter recruiter = (Recruiter) contact;

final Id linkedOrgId = recruiter.getOrganizationId();

setVboxInnerLabelText(
linkedParentOrganization, () -> linkedOrgId == null
? null
: String.format(
"from %s (%s)", "organization" /* TODO: Use org name instead */, linkedOrgId.value
)
);
cardPaneInnerVbox.getChildren().removeAll(status, position);
break;
}
default:
cardPaneInnerVbox.getChildren().removeAll(status, position, linkedParentOrganization);
break;
}

contact.getTags().stream()
.sorted(Comparator.comparing(tag -> tag.tagName))
.forEach(tag -> tags.getChildren().add(new Label(tag.tagName)));
}

/**
* Configures the inner label contained within the vbox container to show the given string,
* or remove the label entirely if the string is empty or null.
*
* @param label The label to set the text to.
* @param valueSupplier The string value supplier. This may be expressed as a lambda function.
*/
private void setVboxInnerLabelText(Label label, Supplier<String> valueSupplier) {
if (label == null) {
return;
}

String value = valueSupplier.get();
if (value == null || value.isBlank()) {
label.setText(null);
cardPaneInnerVbox.getChildren().remove(label);
} else {
label.setText(value);
}
}
}
9 changes: 7 additions & 2 deletions src/main/resources/view/ContactListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,28 @@
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10" prefWidth="150" />
</columnConstraints>
<VBox alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<VBox fx:id="cardPaneInnerVbox" alignment="CENTER_LEFT" minHeight="105" GridPane.columnIndex="0">
<padding>
<Insets top="5" right="5" bottom="5" left="15" />
</padding>
<HBox spacing="5" alignment="CENTER_LEFT">
<Label fx:id="id" styleClass="cell_big_label">
<Label fx:id="index" styleClass="cell_big_label">
<minWidth>
<!-- Ensures that the label text is never truncated -->
<Region fx:constant="USE_PREF_SIZE" />
</minWidth>
</Label>
<Label fx:id="name" text="\$first" styleClass="cell_big_label" />
</HBox>
<Label fx:id="linkedParentOrganization" styleClass="cell_small_label" text="\$linkedOrganization" />
<Label fx:id="id" styleClass="cell_small_label" text="\$id" />
<FlowPane fx:id="tags" />
<Label fx:id="phone" styleClass="cell_small_label" text="\$phone" />
<Label fx:id="address" styleClass="cell_small_label" text="\$address" />
<Label fx:id="email" styleClass="cell_small_label" text="\$email" />
<Label fx:id="status" styleClass="cell_small_label" text="\$status" />
<Label fx:id="position" styleClass="cell_small_label" text="\$position" />
<Label fx:id="url" styleClass="cell_small_label" text="\$url" />
</VBox>
</GridPane>
</HBox>
10 changes: 10 additions & 0 deletions src/main/resources/view/DarkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@
-fx-background-radius: 0;
}

.label#id {
-fx-text-fill: #d0d0d088;
-fx-font-size: 10px;
-fx-font-style: italic;
}

#tags {
-fx-hgap: 7;
-fx-vgap: 3;
Expand All @@ -350,3 +356,7 @@
-fx-background-radius: 2;
-fx-font-size: 11;
}

#tags .label#type {
-fx-background-color: #3f917e;
}
Loading