diff --git a/frontend/themes/samic/components/vaadin-vertical-layout.css b/frontend/themes/samic/components/vaadin-vertical-layout.css new file mode 100644 index 0000000..885088b --- /dev/null +++ b/frontend/themes/samic/components/vaadin-vertical-layout.css @@ -0,0 +1,4 @@ +:host(.container) { + border: 1px solid lightgray; + border-radius: 10px; +} \ No newline at end of file diff --git a/src/main/java/com/samic/samic/views/MainLayout.java b/src/main/java/com/samic/samic/views/MainLayout.java index 95778f8..827c767 100644 --- a/src/main/java/com/samic/samic/views/MainLayout.java +++ b/src/main/java/com/samic/samic/views/MainLayout.java @@ -2,28 +2,24 @@ import com.samic.samic.data.User; import com.samic.samic.security.AuthenticatedUser; -import com.samic.samic.views.about.AboutView; +import com.samic.samic.views.dashboard.DashboardView; import com.samic.samic.views.helloworld.HelloWorldView; import com.vaadin.flow.component.applayout.AppLayout; import com.vaadin.flow.component.applayout.DrawerToggle; import com.vaadin.flow.component.avatar.Avatar; import com.vaadin.flow.component.contextmenu.MenuItem; -import com.vaadin.flow.component.html.Anchor; -import com.vaadin.flow.component.html.Div; -import com.vaadin.flow.component.html.Footer; -import com.vaadin.flow.component.html.H1; -import com.vaadin.flow.component.html.H2; -import com.vaadin.flow.component.html.Header; +import com.vaadin.flow.component.html.*; import com.vaadin.flow.component.icon.Icon; +import com.vaadin.flow.component.icon.VaadinIcon; import com.vaadin.flow.component.menubar.MenuBar; import com.vaadin.flow.component.orderedlayout.Scroller; import com.vaadin.flow.component.sidenav.SideNav; import com.vaadin.flow.component.sidenav.SideNavItem; +import com.vaadin.flow.dom.Style; import com.vaadin.flow.router.PageTitle; -import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.server.auth.AccessAnnotationChecker; import com.vaadin.flow.theme.lumo.LumoUtility; -import java.io.ByteArrayInputStream; + import java.util.Optional; import org.vaadin.lineawesome.LineAwesomeIcon; @@ -50,14 +46,23 @@ private void addHeaderContent() { DrawerToggle toggle = new DrawerToggle(); toggle.setAriaLabel("Menu toggle"); + + viewTitle = new H2(); viewTitle.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.Margin.NONE); - addToNavbar(true, toggle, viewTitle); + Image logo = new Image("/images/logo_samic.svg", "Samic logo"); + logo.setHeight("34px"); + + addToNavbar(true, toggle, viewTitle, logo); + + logo.getStyle().setFloat(Style.FloatCss.RIGHT); + logo.getStyle().setPosition(Style.Position.ABSOLUTE); + logo.getStyle().setRight("20px"); } private void addDrawerContent() { - H1 appName = new H1("My App"); + H1 appName = new H1(""); appName.addClassNames(LumoUtility.FontSize.LARGE, LumoUtility.Margin.NONE); Header header = new Header(appName); @@ -69,14 +74,15 @@ private void addDrawerContent() { private SideNav createNavigation() { SideNav nav = new SideNav(); + if (accessChecker.hasAccess(DashboardView.class)) { + nav.addItem(new SideNavItem("Dashboard", DashboardView.class, VaadinIcon.DASHBOARD.create())); + } + if (accessChecker.hasAccess(HelloWorldView.class)) { nav.addItem(new SideNavItem("Hello World", HelloWorldView.class, LineAwesomeIcon.GLOBE_SOLID.create())); } - if (accessChecker.hasAccess(AboutView.class)) { - nav.addItem(new SideNavItem("About", AboutView.class, LineAwesomeIcon.FILE.create())); - } return nav; } @@ -88,7 +94,8 @@ private Footer createFooter() { if (maybeUser.isPresent()) { User user = maybeUser.get(); - /*Avatar avatar = new Avatar(user.getName()); + /* TODO remove if attribute gets deleted in backend + Avatar avatar = new Avatar(user.getName()); StreamResource resource = new StreamResource("profile-pic", () -> new ByteArrayInputStream(user.getProfilePicture())); avatar.setImageResource(resource); diff --git a/src/main/java/com/samic/samic/views/about/AboutView.java b/src/main/java/com/samic/samic/views/about/AboutView.java deleted file mode 100644 index 575edcb..0000000 --- a/src/main/java/com/samic/samic/views/about/AboutView.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.samic.samic.views.about; - -import com.samic.samic.views.MainLayout; -import com.vaadin.flow.component.html.H2; -import com.vaadin.flow.component.html.Image; -import com.vaadin.flow.component.html.Paragraph; -import com.vaadin.flow.component.orderedlayout.VerticalLayout; -import com.vaadin.flow.router.PageTitle; -import com.vaadin.flow.router.Route; -import com.vaadin.flow.theme.lumo.LumoUtility.Margin; -import jakarta.annotation.security.PermitAll; - -@PageTitle("About") -@Route(value = "about", layout = MainLayout.class) -@PermitAll -public class AboutView extends VerticalLayout { - - public AboutView() { - setSpacing(false); - - Image img = new Image("images/empty-plant.png", "placeholder plant"); - img.setWidth("200px"); - add(img); - - H2 header = new H2("This place intentionally left empty"); - header.addClassNames(Margin.Top.XLARGE, Margin.Bottom.MEDIUM); - add(header); - add(new Paragraph("It’s a place where you can grow your own UI 🤗")); - - setSizeFull(); - setJustifyContentMode(JustifyContentMode.CENTER); - setDefaultHorizontalComponentAlignment(Alignment.CENTER); - getStyle().set("text-align", "center"); - } - -} diff --git a/src/main/java/com/samic/samic/views/dashboard/DashboardView.java b/src/main/java/com/samic/samic/views/dashboard/DashboardView.java new file mode 100644 index 0000000..7468b96 --- /dev/null +++ b/src/main/java/com/samic/samic/views/dashboard/DashboardView.java @@ -0,0 +1,233 @@ +package com.samic.samic.views.dashboard; + +import com.samic.samic.views.MainLayout; +import com.vaadin.flow.component.Key; +import com.vaadin.flow.component.Text; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.grid.Grid; +import com.vaadin.flow.component.html.*; +import com.vaadin.flow.component.orderedlayout.HorizontalLayout; +import com.vaadin.flow.component.orderedlayout.VerticalLayout; +import com.vaadin.flow.component.textfield.TextField; +import com.vaadin.flow.router.PageTitle; +import com.vaadin.flow.router.Route; +import com.vaadin.flow.router.RouteAlias; +import com.vaadin.flow.theme.lumo.LumoUtility.Margin; +import jakarta.annotation.security.PermitAll; +import jakarta.annotation.security.RolesAllowed; +import lombok.Builder; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.stream.Collectors; + +@PageTitle("Dashboard") +@Route(value = "dashboard", layout = MainLayout.class) +@RouteAlias(value = "", layout = MainLayout.class) +@PermitAll +public class DashboardView extends VerticalLayout { + + public DashboardView() { + + //STATS + VerticalLayout statsContainer = new VerticalLayout(); + + statsContainer.add(new H4("Statistiken")); + statsContainer.addClassName("container"); + add(statsContainer); + + HorizontalLayout statsChildren = new HorizontalLayout(); + statsContainer.add(statsChildren); + + statsChildren.setJustifyContentMode(JustifyContentMode.BETWEEN); + statsChildren.setWidthFull(); + HashMap> map = new HashMap<>(); + + + //Example Data + map.put("Gerät Typ1", List.of(100, 50)); + map.put("Gerät Typ2", List.of(50, 50)); + map.put("Gerät Typ3", List.of(100, 1)); + + map.forEach((key, value) -> { + Span sp = new Span(key + " "+ value.get(0) + "/" + value.get(1)); + if (value.get(0) / value.get(1) >= 25) { + sp.getElement().getThemeList().add("badge error"); + } else if(value.get(0) / value.get(1) >= 2 ) { + sp.getElement().getThemeList().add("badge contrast"); + } else { + sp.getElement().getThemeList().add("badge success"); + } + statsChildren.add(sp); + }); + statsChildren.add(new Span("Empty example")); + statsChildren.add(new Span("Empty example")); + statsChildren.add(new Span("Empty example")); + + + //QUICK_ACCESS + + + VerticalLayout actionContainer = new VerticalLayout(); + actionContainer.add(new H4("Quick-Access")); + actionContainer.addClassName("container"); + add(actionContainer); + + HorizontalLayout actionChildren = new HorizontalLayout(); + actionChildren.setWidthFull(); + actionChildren.setJustifyContentMode(JustifyContentMode.AROUND); + + actionContainer.add(actionChildren); + + + Button btnSoCreate = new Button("Lagerobjekt erfassen"); + btnSoCreate.getStyle().setBackground("#108AB2"); + btnSoCreate.getStyle().setColor("#FFFFFF"); + + Button btnResAdd = new Button("Reservierung hinzufügen"); + btnResAdd.getStyle().setBackground("#108AB2"); + btnResAdd.getStyle().setColor("#FFFFFF"); + + Button btnSoAdd = new Button("Lagerobjekt aufnehmen"); + btnSoAdd.getStyle().setBackground("#108AB2"); + btnSoAdd.getStyle().setColor("#FFFFFF"); + + Button btnStadd = new Button("Lager hinzufügen"); + btnStadd.getStyle().setBackground("#108AB2"); + btnStadd.getStyle().setColor("#FFFFFF"); + + Button btnUserAdd = new Button("Benutzer hinzufügen"); + btnUserAdd.getStyle().setBackground("#108AB2"); + btnUserAdd.getStyle().setColor("#FFFFFF"); + + actionChildren.add(btnSoCreate,btnResAdd, btnSoAdd, btnStadd, btnUserAdd); + + + + //MY_HARDWARE + + VerticalLayout myHardwareContainer = new VerticalLayout(); + myHardwareContainer.add(new H4("Meine Hardware (Fake Überschriften im Grid!!)")); + myHardwareContainer.addClassName("container"); + add(myHardwareContainer); + + HorizontalLayout myHardwareChildren = new HorizontalLayout(); + myHardwareChildren.setWidthFull(); + + + Grid hardwareGrid = new Grid<>(ExampleData.class,false); + + hardwareGrid.isAllRowsVisible(); + hardwareGrid.setMaxHeight("300px"); + + + + List exampleDataList = new ArrayList<>(); + + exampleDataList.add(ExampleData.builder().name("Gerät 1").type("Typ 1") + .status("Status 1").location("Lagerort 1").reserved("Reserviert 1").reservedUntil("Reserviert bis 1").build()); + exampleDataList.add(ExampleData.builder().name("Gerät 2").type("Typ 2") + .status("Status 2").location("Lagerort 2").reserved("Reserviert 2").reservedUntil("Reserviert bis 2").build()); + exampleDataList.add(ExampleData.builder().name("Gerät 3").type("Typ 3") + .status("Status 3").location("Lagerort 3").reserved("Reserviert 3").reservedUntil("Reserviert bis 3").build()); + exampleDataList.add(ExampleData.builder().name("Gerät 4").type("Typ 4") + .status("Status 4").location("Lagerort 4").reserved("Reserviert 4").reservedUntil("Reserviert bis 4").build()); + exampleDataList.add(ExampleData.builder().name("Gerät 5").type("Typ 5") + .status("Status 5").location("Lagerort 5").reserved("Reserviert 5").reservedUntil("Reserviert bis 5").build()); + + + hardwareGrid.addColumn(ExampleData::getName).setHeader("Name"); + hardwareGrid.addColumn(ExampleData::getType).setHeader("Typ"); + hardwareGrid.addColumn(ExampleData::getStatus).setHeader("Status"); + hardwareGrid.addColumn(ExampleData::getLocation).setHeader("Lagerort"); + hardwareGrid.addColumn(ExampleData::getReserved).setHeader("Reserviert"); + hardwareGrid.addColumn(ExampleData::getReservedUntil).setHeader("Reserviert bis"); + + hardwareGrid.setItems(exampleDataList); + + myHardwareContainer.add(myHardwareChildren); + myHardwareChildren.add(hardwareGrid); + + + //MY_RESERVATIONS + + VerticalLayout myReservationContainer = new VerticalLayout(); + myReservationContainer.add(new H4("Meine Reservierungen (Fake Überschriften im Grid!!)")); + myReservationContainer.addClassName("container"); + add(myReservationContainer); + + HorizontalLayout myReservationChildren = new HorizontalLayout(); + myReservationChildren.setWidthFull(); + + + Grid reservationGrid = new Grid<>(ExampleData.class,false); + + reservationGrid.isAllRowsVisible(); + reservationGrid.setMaxHeight("300px"); + + + + reservationGrid.addColumn(ExampleData::getName).setHeader("Name"); + reservationGrid.addColumn(ExampleData::getType).setHeader("Typ"); + reservationGrid.addColumn(ExampleData::getStatus).setHeader("Status"); + reservationGrid.addColumn(ExampleData::getLocation).setHeader("Lagerort"); + reservationGrid.addColumn(ExampleData::getReserved).setHeader("Reserviert"); + reservationGrid.addColumn(ExampleData::getReservedUntil).setHeader("Reserviert bis"); + + reservationGrid.setItems(exampleDataList); + + myReservationContainer.add(myReservationChildren); + myReservationChildren.add(reservationGrid); + + + } + + + + @Builder + static protected class ExampleData{ + private String name; + private String type; + private String status; + private String location; + private String reserved; + private String reservedUntil; + + public ExampleData exampleData(String name, String type, String status, String location, String reserved, String reservedUntil) { + this.name = name; + this.type = type; + this.status = status; + this.location = location; + this.reserved = reserved; + this.reservedUntil = reservedUntil; + + return this; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String getStatus() { + return status; + } + + public String getLocation() { + return location; + } + + public String getReserved() { + return reserved; + } + + public String getReservedUntil() { + return reservedUntil; + } + } +} diff --git a/src/main/java/com/samic/samic/views/helloworld/HelloWorldView.java b/src/main/java/com/samic/samic/views/helloworld/HelloWorldView.java index ca44e56..2266ae5 100644 --- a/src/main/java/com/samic/samic/views/helloworld/HelloWorldView.java +++ b/src/main/java/com/samic/samic/views/helloworld/HelloWorldView.java @@ -13,8 +13,7 @@ import jakarta.annotation.security.PermitAll; @PageTitle("Hello World") -@Route(value = "dashboard", layout = MainLayout.class) -@RouteAlias(value = "", layout = MainLayout.class) +@Route(value = "helloworld", layout = MainLayout.class) @PermitAll public class HelloWorldView extends HorizontalLayout { diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a2bc483..2bb0263 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -14,7 +14,7 @@ spring.sql.init.mode = always #Database -spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/XEPDB1 +#spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/XEPDB1 #spring.datasource.username=system #spring.datasource.password=oracle #spring.datasource.driver-class-name=oracle.jdbc.OracleDriver @@ -26,15 +26,15 @@ spring.datasource.url=jdbc:oracle:thin:@//localhost:1521/XEPDB1 #spring.datasource.hikari.connectionTimeout=30000 #spring.datasource.hikari.poolName=HikariPoolBooks -#spring.datasource.url=jdbc:tc:oracle:21-slim-faststart:///databasename +spring.datasource.url=jdbc:tc:oracle:21-slim-faststart:///databasename #spring.jpa.database=oracle #spring.jpa.database-platform=org.hibernate.dialect.OracleDialect #spring.jpa.hibernate.ddl-auto=create-drop #spring.datasource.url=jdbc:oracle:thin:@//database:1521/XEPDB1 -spring.datasource.username=system -spring.datasource.password=oracle -spring.datasource.driver-class-name=oracle.jdbc.OracleDriver +#spring.datasource.username=system +#spring.datasource.password=oracle +#spring.datasource.driver-class-name=oracle.jdbc.OracleDriver spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect spring.jpa.hibernate.ddl-auto=create-drop