Skip to content

Commit

Permalink
🚧 #80
Browse files Browse the repository at this point in the history
  • Loading branch information
rucko24 committed Nov 18, 2024
1 parent 0696ccf commit 6c892f4
Show file tree
Hide file tree
Showing 22 changed files with 388 additions and 135 deletions.
38 changes: 38 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<properties>
<java.version>21</java.version>
<vaadin.version>24.5.4</vaadin.version>
<org.mapstruct.version>1.5.5.Final</org.mapstruct.version>
<org.projectlombok.version>1.18.32</org.projectlombok.version>
</properties>

<parent>
Expand Down Expand Up @@ -121,6 +123,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -176,6 +179,12 @@
<version>2.3.0</version>
</dependency>

<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>${org.mapstruct.version}</version>
</dependency>

</dependencies>

<build>
Expand All @@ -198,6 +207,35 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>21</source> <!-- depending on your project -->
<target>21</target> <!-- depending on your project -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${org.mapstruct.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${org.projectlombok.version}</version>
</path>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-mapstruct-binding</artifactId>
<version>0.2.0</version>
</path>
<!-- other annotation processors -->
</annotationProcessorPaths>
</configuration>
</plugin>

</plugins>
</build>

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions src/main/java/com/esp/espflow/entity/WizardFlashEspEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.esp.espflow.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.Data;

@Data
@Entity
@Table(name = "wizard_flashesp")
public class WizardFlashEspEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private boolean enableWizard;
private String name;

}
16 changes: 16 additions & 0 deletions src/main/java/com/esp/espflow/entity/dto/WizardFlashEspDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.esp.espflow.entity.dto;

import lombok.Builder;
import lombok.Getter;
import lombok.Value;

/**
* @author rub'n
*/
@Builder
@Value
@Getter
public class WizardFlashEspDto {
boolean enableWizard;
String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.esp.espflow.entity.event;

public enum DialogHideEvent {
HIDE
}
2 changes: 1 addition & 1 deletion src/main/java/com/esp/espflow/generator/DataGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.esp.espflow.entity.User;
import com.esp.espflow.enums.Role;
import com.esp.espflow.service.UserRepository;
import com.esp.espflow.service.respository.UserRepository;
import com.vaadin.flow.spring.annotation.SpringComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/esp/espflow/mappers/WizardFlashEspMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.esp.espflow.mappers;

import com.esp.espflow.entity.WizardFlashEspEntity;
import com.esp.espflow.entity.dto.WizardFlashEspDto;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

@Mapper(componentModel = "spring")
public interface WizardFlashEspMapper {

WizardFlashEspMapper INSTANCE = Mappers.getMapper(WizardFlashEspMapper.class);

WizardFlashEspEntity dtoToEntity(final WizardFlashEspDto wizardFlashEspDto);

@InheritInverseConfiguration
WizardFlashEspDto entityToDto(final WizardFlashEspEntity wizardFlashEspDto);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.esp.espflow.security;

import com.esp.espflow.entity.User;
import com.esp.espflow.service.UserRepository;
import com.esp.espflow.service.respository.UserRepository;
import com.vaadin.flow.spring.security.AuthenticationContext;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.esp.espflow.security;

import com.esp.espflow.entity.User;
import com.esp.espflow.service.UserRepository;
import com.esp.espflow.service.respository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/esp/espflow/service/UserService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.esp.espflow.service;

import com.esp.espflow.entity.User;
import com.esp.espflow.service.respository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.esp.espflow.service;
package com.esp.espflow.service.respository;


import com.esp.espflow.entity.User;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.esp.espflow.service.respository;

import com.esp.espflow.entity.WizardFlashEspEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface WizardFlashEspRepository extends JpaRepository<WizardFlashEspEntity, Long> {

Optional<WizardFlashEspEntity> findByName(String name);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.esp.espflow.service.respository.impl;

import com.esp.espflow.entity.WizardFlashEspEntity;
import com.esp.espflow.entity.dto.WizardFlashEspDto;
import com.esp.espflow.mappers.WizardFlashEspMapper;
import com.esp.espflow.service.respository.WizardFlashEspRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
* @author rub'n
*/
@Log4j2
@Service
@RequiredArgsConstructor
public class WizardFlashEspService {

private final WizardFlashEspRepository wizardFlashEspRepository;

/**
* @param wizardFlashEspDto
*/
public void save(WizardFlashEspDto wizardFlashEspDto) {
var entity = WizardFlashEspMapper.INSTANCE.dtoToEntity(wizardFlashEspDto);
this.wizardFlashEspRepository.findByName(entity.getName())
.ifPresentOrElse(hideButton -> {
hideButton.setEnableWizard(entity.isEnableWizard());
wizardFlashEspRepository.save(hideButton);
log.info("Entity updated {}", hideButton);
}, () -> {
wizardFlashEspRepository.save(entity);
log.info("Entity saved {}", entity);
});
}

/**
*
* @param name of this Wizard
*
* @return A {@link Optional<WizardFlashEspEntity>}
*/
@Transactional
public Optional<WizardFlashEspDto> findWizardFlashEsp(String name) {
return this.wizardFlashEspRepository.findByName(name)
.map(WizardFlashEspMapper.INSTANCE::entityToDto);
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/esp/espflow/util/EspFlowConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,7 @@ public class EspFlowConstants {
public static final String FREE_BSD_ICON = "freebsd.svg";
public static final String NO_OS_ICON = "no-os.svg";
public static final String ESPFLOW_SOURCE_CODE = "https://github.com/rucko24/EspFlow";
public static final String WIZARD_FLASHESP_VIEW = "wizardFlashEspView";
public static final String INNER_HTML = "innerHTML";

}
5 changes: 3 additions & 2 deletions src/main/java/com/esp/espflow/views/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ public class MainLayout extends AppLayout {
private final AccessAnnotationChecker accessChecker;
private final Flux<EspMessageListItemEvent> subscribersMessageListItems;

private final SettingsDialogView settingsDialogView = new SettingsDialogView();
private final SettingsDialogView settingsDialogView;

public MainLayout(AuthenticatedUser authenticatedUser, AccessAnnotationChecker accessChecker,
Flux<EspMessageListItemEvent> subscribersMessageListItems) {
Flux<EspMessageListItemEvent> subscribersMessageListItems, SettingsDialogView settingsDialogView) {
this.authenticatedUser = authenticatedUser;
this.accessChecker = accessChecker;
this.subscribersMessageListItems = subscribersMessageListItems;
this.settingsDialogView = settingsDialogView;

setPrimarySection(Section.DRAWER);
addDrawerContent();
Expand Down
20 changes: 1 addition & 19 deletions src/main/java/com/esp/espflow/views/about/AboutView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.esp.espflow.views.MainLayout;
import com.infraleap.animatecss.Animated;
import com.vaadin.flow.component.AttachEvent;
import com.vaadin.flow.component.DetachEvent;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Div;
Expand All @@ -18,13 +17,12 @@
import jakarta.annotation.security.RolesAllowed;
import lombok.extern.log4j.Log4j2;

import java.util.Objects;

import static com.esp.espflow.util.EspFlowConstants.BOX_SHADOW_PROPERTY;
import static com.esp.espflow.util.EspFlowConstants.BOX_SHADOW_VALUE;
import static com.esp.espflow.util.EspFlowConstants.CURSOR_POINTER;
import static com.esp.espflow.util.EspFlowConstants.ESPFLOW_SOURCE_CODE;
import static com.esp.espflow.util.EspFlowConstants.FRONTEND_IMAGES_ABOUT;
import static com.esp.espflow.util.EspFlowConstants.INNER_HTML;

@Log4j2
@UIScope
Expand All @@ -35,7 +33,6 @@
public class AboutView extends VerticalLayout {

private static final String TARGET_BLANK = "_blank";
private static final String INNER_HTML = "innerHTML";

public AboutView() {
init();
Expand Down Expand Up @@ -108,19 +105,4 @@ protected void onDetach(DetachEvent detachEvent) {
super.onDetach(detachEvent);
}

@Override
protected void onAttach(AttachEvent attachEvent) {
super.onAttach(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();
// }
}
});
});
}
}
16 changes: 13 additions & 3 deletions src/main/java/com/esp/espflow/views/flashesp/FlashEspView.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.esp.espflow.mappers.ExtractChipIsFromStringMapper;
import com.esp.espflow.service.EsptoolPathService;
import com.esp.espflow.service.EsptoolService;
import com.esp.espflow.service.respository.impl.WizardFlashEspService;
import com.esp.espflow.util.CommandsOnFirstLine;
import com.esp.espflow.util.ResponsiveHeaderDiv;
import com.esp.espflow.util.console.OutPutConsole;
Expand Down Expand Up @@ -64,6 +65,7 @@
import static com.esp.espflow.util.EspFlowConstants.OVERFLOW_Y;
import static com.esp.espflow.util.EspFlowConstants.PORT;
import static com.esp.espflow.util.EspFlowConstants.SIZE_25_PX;
import static com.esp.espflow.util.EspFlowConstants.WIZARD_FLASHESP_VIEW;

/**
* @author rubn
Expand Down Expand Up @@ -102,6 +104,11 @@ public class FlashEspView extends Div implements ResponsiveHeaderDiv {
* Publisher for MessageListItem
*/
private final Sinks.Many<EspMessageListItemEvent> publishMessageListItem;
/*
* initial wizard
*/
private final WizardFlashEspDialog wizardFlashEspDialog;
private final WizardFlashEspService wizardFlashEspRepository;

@PostConstruct
public void init() {
Expand Down Expand Up @@ -377,8 +384,6 @@ protected void onDetach(DetachEvent detachEvent) {
super.onDetach(detachEvent);
}

private final WizardFlashEspDialog wizardFlashEspDialog = new WizardFlashEspDialog();

@Override
protected void onAttach(AttachEvent attachEvent) {
if (attachEvent.isInitialAttach()) {
Expand All @@ -402,7 +407,12 @@ protected void onAttach(AttachEvent attachEvent) {
final String ref = StringUtils.defaultIfEmpty(url.getRef(), StringUtils.EMPTY);
if (!ref.contains("settings")) {
this.add(this.wizardFlashEspDialog);
this.wizardFlashEspDialog.open();
this.wizardFlashEspRepository.findWizardFlashEsp(WIZARD_FLASHESP_VIEW)
.ifPresent((hide) -> {
if (hide.isEnableWizard()) {
this.wizardFlashEspDialog.open();
}
});
}
});
}
Expand Down
Loading

0 comments on commit 6c892f4

Please sign in to comment.