Skip to content

Commit

Permalink
🚧 #80 resolve #86, Wip #85
Browse files Browse the repository at this point in the history
* Change some icons
  • Loading branch information
rucko24 committed Nov 17, 2024
1 parent dac38f4 commit 31b3211
Show file tree
Hide file tree
Showing 26 changed files with 940 additions and 279 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.esp.espflow.configuration;

import com.vaadin.flow.component.messages.MessageListItem;
import com.esp.espflow.entity.event.EspMessageListItemEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import reactor.core.publisher.Flux;
Expand All @@ -17,15 +17,15 @@
public class EspMessageListItemReactivePublisher {

@Bean(value = "publishMessageListItem")
public Sinks.Many<MessageListItem> publisher() {
public Sinks.Many<EspMessageListItemEvent> publisher() {
return Sinks
.many()
.multicast()
.onBackpressureBuffer();
}

@Bean(value = "subscribersMessageListItems")
public Flux<MessageListItem> subscribers(Sinks.Many<MessageListItem> publisher) {
public Flux<EspMessageListItemEvent> subscribers(Sinks.Many<EspMessageListItemEvent> publisher) {
return publisher
.asFlux();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.esp.espflow.entity.event;

import com.esp.espflow.util.svgfactory.SvgFactory;
import com.vaadin.flow.component.messages.MessageListItem;
import com.vaadin.flow.server.StreamResource;
import lombok.extern.log4j.Log4j2;

import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;

import static com.esp.espflow.util.EspFlowConstants.FRONTEND_IMAGES_SVG_ICONS;

/**
* @author rub'n
*/
@Log4j2
public class EspMessageListItemEvent extends MessageListItem {
/*
* For Custom colors
*/
private static final SecureRandom SECURE_RANDOM = new SecureRandom();

public EspMessageListItemEvent(String operation, String port) {
super.setText(operation);
super.setTime(LocalDateTime.now().toInstant(ZoneOffset.UTC));
super.setUserName(port);
this.setCustomImage();
var colors = Arrays.asList(0, 1, 2, 3, 4, 5, 6);
super.setUserColorIndex(colors.get(SECURE_RANDOM.nextInt(colors.size())));
}

private void setCustomImage() {
final StreamResource resource = new StreamResource("usb-port-black.svg",
() -> SvgFactory.class.getResourceAsStream(FRONTEND_IMAGES_SVG_ICONS + "usb-port-black.svg"));
super.setUserImageResource(resource);
}

}
33 changes: 12 additions & 21 deletions src/main/java/com/esp/espflow/views/MainLayout.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.esp.espflow.views;

import com.esp.espflow.entity.User;
import com.esp.espflow.entity.event.EspMessageListItemEvent;
import com.esp.espflow.security.AuthenticatedUser;
import com.esp.espflow.util.svgfactory.SvgFactory;
import com.esp.espflow.views.about.AboutView;
Expand Down Expand Up @@ -44,7 +45,6 @@
import com.vaadin.flow.component.sidenav.SideNavItem;
import com.vaadin.flow.component.tabs.TabSheet;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.RouteConfiguration;
import com.vaadin.flow.server.auth.AccessAnnotationChecker;
import com.vaadin.flow.theme.lumo.LumoUtility;
import com.vaadin.flow.theme.lumo.LumoUtility.AlignItems;
Expand Down Expand Up @@ -87,10 +87,12 @@ public class MainLayout extends AppLayout {

private final AuthenticatedUser authenticatedUser;
private final AccessAnnotationChecker accessChecker;
private final Flux<MessageListItem> subscribersMessageListItems;
private final Flux<EspMessageListItemEvent> subscribersMessageListItems;

private final SettingsDialogView settingsDialogView = new SettingsDialogView();

public MainLayout(AuthenticatedUser authenticatedUser, AccessAnnotationChecker accessChecker,
Flux<MessageListItem> subscribersMessageListItems) {
Flux<EspMessageListItemEvent> subscribersMessageListItems) {
this.authenticatedUser = authenticatedUser;
this.accessChecker = accessChecker;
this.subscribersMessageListItems = subscribersMessageListItems;
Expand Down Expand Up @@ -272,20 +274,14 @@ private Footer createFooter() {
div.getElement().getStyle().set("gap", "var(--lumo-space-s)");
userName.add(div);

final SettingsDialogView settingsDialogView = new SettingsDialogView();
userName.getSubMenu().addItem("Settings...", e -> {
settingsDialogView.setId("settings-dialog");
settingsDialogView.open();
userName.getSubMenu().addItem("Settings...", event -> {
getUI().ifPresent(ui -> {
ui.getPage().fetchCurrentURL(url -> {

String baseUrl = RouteConfiguration.forSessionScope()
.getUrl(SettingsDialogView.class, "").replace("/", "");

String urlWithParameters = url.getPath().concat(baseUrl);

log.info("fetchCurrentURL {}", url);
String urlWithParameters = url.getPath().concat("#settings");
ui.getPage().getHistory().replaceState(null, urlWithParameters);

settingsDialogView.open();
ui.setChildComponentModal(settingsDialogView, false);
});
});
}).addComponentAsFirst(VaadinIcon.COG.create());
Expand All @@ -295,12 +291,6 @@ private Footer createFooter() {
});
sigOutItem.addComponentAsFirst(SvgFactory.createIconFromSvg("signout.svg", "20px", null));

userName.getSubMenu().getItems().forEach(item -> {
item.getStyle().setCursor(CURSOR_POINTER);
item.setCheckable(false);
item.setChecked(false);
});

layout.add(userMenu, settingsDialogView);
} else {
Anchor loginLink = new Anchor("login", "Sign in");
Expand Down Expand Up @@ -328,7 +318,7 @@ private String getCurrentPageTitle() {
private void subscribe(final UI ui, final MessageListItem messageListItem) {
try {
ui.access(() -> {
System.out.println("MessageListItem listener " + messageListItem.getText());
log.info("MessageListItem listener {}", messageListItem.getText());
messageListItemUnreadList.add(messageListItem);
messageListItemAllList.add(messageListItem);
this.messageListRead.setItems(messageListItemUnreadList);
Expand Down Expand Up @@ -379,6 +369,7 @@ public void removeRedCircleErrorInTheBell() {
@Override
protected void onDetach(DetachEvent detachEvent) {
super.onDetach(detachEvent);
this.settingsDialogView.close();
}

@Override
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/esp/espflow/views/about/AboutView.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.esp.espflow.views.about;

import com.esp.espflow.views.MainLayout;
import com.esp.espflow.views.settings.SettingsDialogView;
import com.infraleap.animatecss.Animated;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.DetachEvent;
Expand Down Expand Up @@ -113,11 +112,11 @@ protected void onAttach(AttachEvent attachEvent) {
getUI().ifPresent(ui -> {
ui.getPage().fetchCurrentURL(url -> {
if (Objects.nonNull(url)) {
if (url.toString().contains("setting")) {
final SettingsDialogView settingsDialogView = new SettingsDialogView();
super.add(settingsDialogView);
settingsDialogView.open();
}
// if (url.toString().contains("setting")) {
// final SettingsDialogView settingsDialogView = new SettingsDialogView();
// super.add(settingsDialogView);
// settingsDialogView.open();
// }
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.SvgIcon;
import com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.progressbar.ProgressBar;
import com.vaadin.flow.component.textfield.PasswordField;
import com.vaadin.flow.data.binder.Binder;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.function.SerializableBiConsumer;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
import com.vaadin.flow.theme.lumo.LumoUtility;
import jakarta.annotation.PostConstruct;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -96,9 +100,21 @@ private ComboBox<String> fillCopyComboBox(ComboBox<String> comboBoxSerialPort) {
copyComboBox.setWidthFull();
copyComboBox.setPrefixComponent(SvgFactory.OsIcon("30px", null));
copyComboBox.setItems(comboBoxSerialPort.getListDataView().getItems().toList());
copyComboBox.setRenderer(rendererIconUsbForEachItem());
return copyComboBox;
}

private ComponentRenderer<Div, String> rendererIconUsbForEachItem() {
final SerializableBiConsumer<Div, String> serializableBiConsumer = (div, itemName) -> {
div.addClassNames(LumoUtility.Display.FLEX, LumoUtility.AlignItems.CENTER);
final SvgIcon icon = SvgFactory.createIconFromSvg("usb-port-black.svg", "25px", null);
final Span span = new Span(itemName);
span.addClassNames(LumoUtility.Padding.Left.SMALL);
div.add(icon, span);
};
return new ComponentRenderer<>(Div::new, serializableBiConsumer);
}

/**
* Initial configuration for the Dialog
*/
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/com/esp/espflow/views/flashesp/DivHeaderPorts.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.function.SerializableBiConsumer;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
import com.vaadin.flow.theme.lumo.LumoUtility;
Expand Down Expand Up @@ -131,21 +132,21 @@ private Div createDivComboBox() {
comboBoxSerialPort.setWidthFull();
comboBoxSerialPort.setPlaceholder("port");
comboBoxSerialPort.setPrefixComponent(SvgFactory.OsIcon("30px", null));
comboBoxSerialPort.setRenderer(new ComponentRenderer<>(this::getIconItemSubMenu));
comboBoxSerialPort.setRenderer(rendererIconUsbForEachItem());
return this.createDiv(this.comboBoxSerialPort, MARGIN, MARGIN_10_PX);
}

private Div getIconItemSubMenu(String serialPortName) {
final Div div = new Div();
div.addClassNames(LumoUtility.Display.FLEX, LumoUtility.AlignItems.CENTER);
final SvgIcon icon = SvgFactory.OsIcon("25px", null);
final Span span = new Span(serialPortName);
span.addClassNames(LumoUtility.Padding.Left.SMALL);
div.add(icon, span);
return div;
private ComponentRenderer<Div, String> rendererIconUsbForEachItem() {
final SerializableBiConsumer<Div, String> serializableBiConsumer = (div, itemName) -> {
div.addClassNames(LumoUtility.Display.FLEX, LumoUtility.AlignItems.CENTER);
final SvgIcon icon = SvgFactory.createIconFromSvg("usb-port-black.svg", "25px", null);
final Span span = new Span(itemName);
span.addClassNames(LumoUtility.Padding.Left.SMALL);
div.add(icon, span);
};
return new ComponentRenderer<>(Div::new, serializableBiConsumer);
}


private Div createH3SerialPort() {
final Div divH3 = new Div(new H3("Serial port"));
divH3.getStyle().set("white-space", "pre");
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/com/esp/espflow/views/flashesp/FlashEspView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.esp.espflow.views.flashesp;

import com.esp.espflow.entity.event.EspMessageListItemEvent;
import com.esp.espflow.enums.BaudRatesEnum;
import com.esp.espflow.enums.EraseFlashEnum;
import com.esp.espflow.enums.FlashModeEnum;
Expand All @@ -11,7 +12,6 @@
import com.esp.espflow.util.console.OutPutConsole;
import com.esp.espflow.util.svgfactory.SvgFactory;
import com.esp.espflow.views.MainLayout;
import com.esp.espflow.views.settings.SettingsDialogView;
import com.infraleap.animatecss.Animated;
import com.infraleap.animatecss.Animated.Animation;
import com.vaadin.flow.component.AttachEvent;
Expand Down Expand Up @@ -100,7 +100,7 @@ public class FlashEspView extends Div implements ResponsiveHeaderDiv {
/*
* Publisher for MessageListItem
*/
private final Sinks.Many<MessageListItem> publishMessageListItem;
private final Sinks.Many<EspMessageListItemEvent> publishMessageListItem;
/*
* Show initial information
*/
Expand Down Expand Up @@ -355,9 +355,10 @@ private void subscribeThis(final Flux<String> reactiveLines, final UI ui) {
LocalDateTime.now().toInstant(ZoneOffset.UTC),
port);

messageListItem.setUserColorIndex(1);
final EspMessageListItemEvent espMessageListItemEvent = new EspMessageListItemEvent(finalTextNotification, port);

log.info("Send post event {}", messageListItem.getText());
publishMessageListItem.tryEmitNext(messageListItem);
publishMessageListItem.tryEmitNext(espMessageListItemEvent);

});
})
Expand Down Expand Up @@ -385,21 +386,24 @@ protected void onAttach(AttachEvent attachEvent) {
super.onAttach(attachEvent);
final UI ui = attachEvent.getUI();
this.outputConsole(ui);
super.add(initialInformationFlashEspViewDialog);
//super.add(initialInformationFlashEspViewDialog);
//super.add(settingsDialogView);
}

getUI().ifPresent(ui -> {
ui.getPage().fetchCurrentURL(url -> {
if (Objects.nonNull(url)) {
String ref = url.getRef();
if (Objects.isNull(ref)) {
this.initialInformationFlashEspViewDialog.open();
//this.initialInformationFlashEspViewDialog.open();
//this.settingsDialogViewCopy.open();
}
if (url.toString().contains("setting")) {
//Abrir los settings aqui
final SettingsDialogView settingsDialogView = new SettingsDialogView();
super.add(settingsDialogView);
settingsDialogView.open();
//final SettingsDialogView settingsDialogView = new SettingsDialogView();
//super.add(settingsDialogView);
//settingsDialogView.open();

}
}
});
Expand Down
Loading

0 comments on commit 31b3211

Please sign in to comment.