Skip to content

Commit

Permalink
Add sample events and clean up code in ClockView
Browse files Browse the repository at this point in the history
Refactored ClockView to include a method for adding sample events dynamically. Removed unused database initializers in Application and added "@fontsource/anton" dependency in package-lock.json.
  • Loading branch information
LiveNathan committed Aug 16, 2024
1 parent e6bc025 commit b4daab4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 34 deletions.
2 changes: 0 additions & 2 deletions .flow-node-tasks.lock

This file was deleted.

11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/main/bundles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
This directory is automatically generated by Vaadin and contains the pre-compiled
frontend files/resources for your project (frontend development bundle).

It should be added to Version Control System and committed, so that other developers
do not have to compile it again.

Frontend development bundle is automatically updated when needed:
- an npm/pnpm package is added with @NpmPackage or directly into package.json
- CSS, JavaScript or TypeScript files are added with @CssImport, @JsModule or @JavaScript
- Vaadin add-on with front-end customizations is added
- Custom theme imports/assets added into 'theme.json' file
- Exported web component is added.

If your project development needs a hot deployment of the frontend changes,
you can switch Flow to use Vite development server (default in Vaadin 23.3 and earlier versions):
- set `vaadin.frontend.hotdeploy=true` in `application.properties`
- configure `vaadin-maven-plugin`:
```
<configuration>
<frontendHotdeploy>true</frontendHotdeploy>
</configuration>
```
- configure `jetty-maven-plugin`:
```
<configuration>
<systemProperties>
<vaadin.frontend.hotdeploy>true</vaadin.frontend.hotdeploy>
</systemProperties>
</configuration>
```

Read more [about Vaadin development mode](https://vaadin.com/docs/next/flow/configuration/development-mode#precompiled-bundle).
Binary file added src/main/bundles/dev.bundle
Binary file not shown.
20 changes: 0 additions & 20 deletions src/main/java/dev/nathanlively/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.theme.Theme;
import com.vaadin.flow.theme.lumo.Lumo;

import javax.sql.DataSource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.sql.init.SqlDataSourceScriptDatabaseInitializer;
import org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties;
import org.springframework.context.annotation.Bean;

/**
* The entry point of the Spring Boot application.
Expand All @@ -27,19 +22,4 @@ public class Application implements AppShellConfigurator {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
SqlDataSourceScriptDatabaseInitializer dataSourceScriptDatabaseInitializer(DataSource dataSource,
SqlInitializationProperties properties, SamplePersonRepository repository) {
// This bean ensures the database is only initialized when empty
return new SqlDataSourceScriptDatabaseInitializer(dataSource, properties) {
@Override
public boolean initializeDatabase() {
if (repository.count() == 0L) {
return super.initializeDatabase();
}
return false;
}
};
}
}
37 changes: 25 additions & 12 deletions src/main/java/dev/nathanlively/views/clock/ClockView.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import com.vaadin.flow.component.button.ButtonVariant;
import com.vaadin.flow.component.dependency.Uses;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.ListItem;
import com.vaadin.flow.component.html.UnorderedList;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.orderedlayout.FlexComponent;
import com.vaadin.flow.component.orderedlayout.FlexComponent.Alignment;
import com.vaadin.flow.component.orderedlayout.FlexComponent.JustifyContentMode;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
Expand All @@ -30,35 +30,48 @@ public ClockView() {

Button buttonPrimary = new Button();
Button buttonSecondary = new Button();
UnorderedList evnetsList = new UnorderedList();
UnorderedList eventsList = new UnorderedList();

getContent().setWidth("100%");
getContent().getStyle().set("flex-grow", "1");
mainRow.addClassName(Gap.MEDIUM);
mainRow.setWidth("100%");
mainRow.getStyle().set("flex-grow", "1");
column1.getStyle().set("flex-grow", "1");

column1.getStyle().set("flex-grow", "1");
column1.setJustifyContentMode(JustifyContentMode.CENTER);
column1.setAlignItems(Alignment.CENTER);

buttonPrimary.setText("Clock In");
column1.setAlignSelf(FlexComponent.Alignment.CENTER, buttonPrimary);
buttonPrimary.setWidth("min-content");
buttonPrimary.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
buttonSecondary.setText("Clock Out");
column1.setAlignSelf(FlexComponent.Alignment.CENTER, buttonSecondary);
buttonPrimary.setWidth("min-content");
buttonSecondary.setWidth("min-content");
buttonPrimary.addThemeVariants(ButtonVariant.LUMO_PRIMARY);

column2.getStyle().set("flex-grow", "1");
column2.getStyle().set("flex-grow", "1");
evnetsList.setWidth("100%");
evnetsList.setHeight("100%");
// setUnoGridSampleData(basicGrid);
eventsList.setWidth("100%");
eventsList.setHeight("100%");
addSampleEvents(eventsList);
getContent().add(mainRow);
mainRow.add(column1);
column1.add(buttonPrimary);
column1.add(buttonSecondary);
mainRow.add(column2);
column2.add(evnetsList);
column2.add(eventsList);
}

private void addSampleEvents(UnorderedList eventsList) {
String[] sampleEvents = {
"8/15/24 9:12 IN",
"8/15/24 17:12 OUT",
"8/16/24 9:10 IN",
"8/16/24 17:09 OUT"
};

for (String event : sampleEvents) {
ListItem item = new ListItem(event);
eventsList.add(item);
}
}

private void setGridSampleData(Grid grid) {
Expand Down

0 comments on commit b4daab4

Please sign in to comment.