Skip to content

Commit

Permalink
[Optimize]
Browse files Browse the repository at this point in the history
Optimize the code for improved readability.
  • Loading branch information
keke125 committed Jun 10, 2023
1 parent fab4c9c commit 2f9d632
Show file tree
Hide file tree
Showing 27 changed files with 1,593 additions and 686 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM eclipse-temurin:17-jre
MAINTAINER admin@keke125.com
LABEL maintainer="admin@keke125.com"

COPY target/*.jar /app/pafw.jar
EXPOSE 8080
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/keke125/pixel/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.keke125.pixel.data.service.UserRepository;
import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme;

import javax.sql.DataSource;

import org.springframework.boot.SpringApplication;
Expand All @@ -13,10 +14,9 @@

/**
* The entry point of the Spring Boot application.
*
* <p>
* Use the @PWA annotation make the application installable on phones, tablets
* and some desktop browsers.
*
*/
@SpringBootApplication
@Theme(value = "pixel-art-filter-web")
Expand All @@ -28,10 +28,12 @@ public static void main(String[] args) {
}

@Bean
SqlDataSourceScriptDatabaseInitializer dataSourceScriptDatabaseInitializer(DataSource dataSource,
SqlInitializationProperties properties, UserRepository repository) {
SqlDataSourceScriptDatabaseInitializer dataSourceScriptDatabaseInitializer
(DataSource dataSource, SqlInitializationProperties properties,
UserRepository repository) {
// This bean ensures the database is only initialized when empty
return new SqlDataSourceScriptDatabaseInitializer(dataSource, properties) {
return new SqlDataSourceScriptDatabaseInitializer(dataSource,
properties) {
@Override
public boolean initializeDatabase() {
if (repository.count() == 0L) {
Expand Down
19 changes: 8 additions & 11 deletions src/main/java/com/keke125/pixel/components/appnav/AppNav.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.dom.Element;

import java.util.Optional;

@JsModule("@vaadin-component-factory/vcf-nav")
Expand All @@ -23,8 +24,7 @@ public AppNav() {
/**
* Creates a new menu with the given label.
*
* @param label
* the label to use
* @param label the label to use
*/
public AppNav(String label) {
setLabel(label);
Expand All @@ -33,8 +33,7 @@ public AppNav(String label) {
/**
* Adds menu item(s) to the menu.
*
* @param appNavItems
* the menu item(s) to add
* @param appNavItems the menu item(s) to add
* @return the menu for chaining
*/
public AppNav addItem(AppNavItem... appNavItems) {
Expand All @@ -50,8 +49,7 @@ public AppNav addItem(AppNavItem... appNavItems) {
* <p>
* If the given menu item is not a child of this menu, does nothing.
*
* @param appNavItem
* the menu item to remove
* @param appNavItem the menu item to remove
* @return the menu for chaining
*/
public AppNav removeItem(AppNavItem appNavItem) {
Expand Down Expand Up @@ -88,8 +86,7 @@ public String getLabel() {
* This can help the end user to distinguish groups of navigation items. The
* label is also available for screen reader users.
*
* @param label
* the label to set
* @param label the label to set
* @return this instance for chaining
*/
public AppNav setLabel(String label) {
Expand Down Expand Up @@ -127,9 +124,9 @@ public boolean isCollapsible() {
* <p>
* NOTE: The navigation has to have a label for it to be collapsible.
*
* @param collapsible
* true to make the whole navigation component collapsible, false
* otherwise
* @param collapsible true to make the whole navigation component
* collapsible, false
* otherwise
* @return this instance for chaining
*/
public AppNav setCollapsible(boolean collapsible) {
Expand Down
105 changes: 48 additions & 57 deletions src/main/java/com/keke125/pixel/components/appnav/AppNavItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.vaadin.flow.router.RouteConfiguration;
import com.vaadin.flow.router.Router;
import com.vaadin.flow.server.VaadinService;

import java.util.Optional;

/**
Expand All @@ -20,36 +21,34 @@
public class AppNavItem extends Component {

/**
* Creates a menu item which does not link to any view but only shows the given
* Creates a menu item which does not link to any view but only shows the
* given
* label.
*
* @param label
* the label for the item
*
* @param label the label for the item
*/
public AppNavItem(String label) {
setLabel(label);
}

/**
* Creates a new menu item using the given label that links to the given path.
*
* @param label
* the label for the item
* @param path
* the path to link to
* Creates a new menu item using the given label that links to the given
* path.
*
* @param label the label for the item
* @param path the path to link to
*/
public AppNavItem(String label, String path) {
setPath(path);
setLabel(label);
}

/**
* Creates a new menu item using the given label that links to the given view.
*
* @param label
* the label for the item
* @param view
* the view to link to
* Creates a new menu item using the given label that links to the given
* view.
*
* @param label the label for the item
* @param view the view to link to
*/
public AppNavItem(String label, Class<? extends Component> view) {
setPath(view);
Expand All @@ -59,13 +58,10 @@ public AppNavItem(String label, Class<? extends Component> view) {
/**
* Creates a new menu item using the given label and icon that links to the
* given path.
*
* @param label
* the label for the item
* @param path
* the path to link to
* @param icon
* the icon for the item
*
* @param label the label for the item
* @param path the path to link to
* @param icon the icon for the item
*/
public AppNavItem(String label, String path, Component icon) {
setPath(path);
Expand All @@ -74,26 +70,24 @@ public AppNavItem(String label, String path, Component icon) {
}

/**
* Creates a new menu item using the given label that links to the given view.
*
* @param label
* the label for the item
* @param view
* the view to link to
* @param icon
* the icon for the item
* Creates a new menu item using the given label that links to the given
* view.
*
* @param label the label for the item
* @param view the view to link to
* @param icon the icon for the item
*/
public AppNavItem(String label, Class<? extends Component> view, Component icon) {
public AppNavItem(String label, Class<? extends Component> view,
Component icon) {
setPath(view);
setLabel(label);
setIcon(icon);
}

/**
* Adds menu item(s) inside this item, creating a hierarchy.
*
* @param appNavItems
* the menu item(s) to add
*
* @param appNavItems the menu item(s) to add
* @return this item for chaining
*/
public AppNavItem addItem(AppNavItem... appNavItems) {
Expand All @@ -109,9 +103,8 @@ public AppNavItem addItem(AppNavItem... appNavItems) {
* Removes the given menu item from this item.
* <p>
* If the given menu item is not a child of this menu item, does nothing.
*
* @param appNavItem
* the menu item to remove
*
* @param appNavItem the menu item to remove
* @return this item for chaining
*/
public AppNavItem removeItem(AppNavItem appNavItem) {
Expand All @@ -125,7 +118,7 @@ public AppNavItem removeItem(AppNavItem appNavItem) {

/**
* Removes all menu items from this item.
*
*
* @return this item for chaining
*/
public AppNavItem removeAllItems() {
Expand All @@ -135,7 +128,7 @@ public AppNavItem removeAllItems() {

/**
* Gets the label for the item.
*
*
* @return the label or null if no label has been set
*/
public String getLabel() {
Expand All @@ -146,9 +139,8 @@ public String getLabel() {
* Set a textual label for the item.
* <p>
* The label is also available for screen rader users.
*
* @param label
* the label to set
*
* @param label the label to set
* @return this instance for chaining
*/
public AppNavItem setLabel(String label) {
Expand All @@ -170,9 +162,8 @@ private Element getLabelElement() {

/**
* Sets the path this item links to.
*
* @param path
* the path to link to
*
* @param path the path to link to
* @return this instance for chaining
*/
public AppNavItem setPath(String path) {
Expand All @@ -182,13 +173,13 @@ public AppNavItem setPath(String path) {

/**
* Sets the view this item links to.
*
* @param view
* the view to link to
*
* @param view the view to link to
* @return this instance for chaining
*/
public AppNavItem setPath(Class<? extends Component> view) {
String url = RouteConfiguration.forRegistry(getRouter().getRegistry()).getUrl(view);
String url =
RouteConfiguration.forRegistry(getRouter().getRegistry()).getUrl(view);
setPath(url);
return this;
}
Expand All @@ -203,7 +194,8 @@ private Router getRouter() {
router = VaadinService.getCurrent().getRouter();
}
if (router == null) {
throw new IllegalStateException("Implicit router instance is not available. "
throw new IllegalStateException("Implicit router instance is not " +
"available. "
+ "Use overloaded method with explicit router parameter.");
}
return router;
Expand All @@ -225,10 +217,10 @@ private int getIconElementIndex() {
/**
* Sets the icon for the item.
* <p>
* Can also be used to set a custom component to be shown in front of the label.
*
* @param icon
* the icon to show
* Can also be used to set a custom component to be shown in front of the
* label.
*
* @param icon the icon to show
* @return this instance for chaining
*/
public AppNavItem setIcon(Component icon) {
Expand All @@ -245,8 +237,7 @@ public AppNavItem setIcon(Component icon) {
/**
* Sets the expanded status of the item.
*
* @param value
* true to expand the item, false to collapse it
* @param value true to expand the item, false to collapse it
*/
public AppNavItem setExpanded(boolean value) {
if (value) {
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/com/keke125/pixel/core/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,58 @@
@Component
@Data
public class AppConfig {

// default password encoder can be set by idForEncode
// BCrypt pbkdf2 argon2
// @Value("{security.password.encoder:argon2}")
private String idForEncode;

// only file size below 10MB can be uploaded
// you can modify this value, but the limit is 2047MB
// @Value("{upload.image.size:10}")
private int maxImageSizeInMegaBytes;

// max 3 files can be uploaded
// you can modify this value
// @Value("{upload.image.number:3}")
private int maxImageFiles;

// only file size below 3MB can be uploaded
// you can modify this value, but the limit is 2047MB
// @Value("{upload.avatar.size:3}")
private int maxAvatarSizeInMegaBytes;

// The default image size limit for new sign-up users
private int newSignupImageSizeLimit;

// website location country
private String webCountry;

// website name
private String webName;

// website link
private String webLink;

// admin contact email
private String adminContactEmail;
// web name

// web name TC
private String webNameTC;

// web name EN
private String webNameEN;
// web description

// web description TC
private String webDescriptionTC;

// web description EN
private String webDescriptionEN;
// login form additional information

// login form additional information TC
private String loginInfoTC;

// login form additional information EN
private String loginInfoEN;

}

0 comments on commit 2f9d632

Please sign in to comment.