Skip to content

Commit 4fd632e

Browse files
#46: highlight current client row (#61)
1 parent 86de305 commit 4fd632e

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed
68 Bytes
Binary file not shown.

vpn-router-web/src/main/java/vpnrouter/web/ui/clients/ClientsGridFactory.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import vpnrouter.web.model.Client;
1717
import vpnrouter.web.utility.UiUtility;
1818

19-
@CssImport("./styles/styles.css")
19+
@CssImport(value = "./styles/styles.css", themeFor = "vaadin-grid")
2020
@Slf4j
2121
@Component
2222
@RequiredArgsConstructor
@@ -30,7 +30,7 @@ public class ClientsGridFactory {
3030

3131
public Grid<Client> build() {
3232
var grid = new Grid<Client>();
33-
grid.setClassName("custom-grid-text");
33+
setStyles(grid);
3434
createEditor(grid);
3535
addIpAddressField(grid);
3636
addNameField(grid);
@@ -41,6 +41,15 @@ public Grid<Client> build() {
4141
return grid;
4242
}
4343

44+
private void setStyles(Grid<Client> grid) {
45+
grid.setClassName("custom-grid-text");
46+
UiUtility.getCurrentClientIpAddress().ifPresent(currentClientIpAddress ->
47+
grid.setClassNameGenerator(client ->
48+
client.getIpAddress().equals(currentClientIpAddress) ? "highlight" : null
49+
)
50+
);
51+
}
52+
4453
private void createEditor(Grid<Client> grid) {
4554
var editor = grid.getEditor();
4655
editor.setBinder(new Binder<>());

vpn-router-web/src/main/java/vpnrouter/web/utility/UiUtility.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package vpnrouter.web.utility;
22

33
import com.vaadin.flow.component.UI;
4+
import lombok.extern.slf4j.Slf4j;
45

6+
import java.util.Optional;
7+
8+
@Slf4j
59
public class UiUtility {
610

711
public static String getFullUiId() {
@@ -10,4 +14,12 @@ public static String getFullUiId() {
1014
var sessionId = ui.getSession().getSession().getId();
1115
return "%s/%s".formatted(sessionId, uiId);
1216
}
17+
18+
public static Optional<String> getCurrentClientIpAddress() {
19+
var address = Optional.ofNullable(
20+
UI.getCurrent().getSession().getBrowser().getAddress()
21+
);
22+
log.info("Current client IP address: {}", address);
23+
return address;
24+
}
1325
}

vpn-router-web/src/main/resources/META-INF/resources/frontend/styles/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@
4040
font-size: 16px;
4141
font-family: Arial, sans-serif;
4242
}
43+
44+
.highlight {
45+
background-color: #cefbfb;
46+
}

0 commit comments

Comments
 (0)