Skip to content

Commit

Permalink
Frontend/Dashboard - Add Dashboard, make minor changes
Browse files Browse the repository at this point in the history
Add Dashboard

Minor Changes:

add Logo to Drawer/Navbar
fix application.properties (change datasoure url)

changed files

vaadin-vertical-layout.css
MainLayout.java
DashboardView.java
HelloWorldView.java
application.properties

Known Issues: Dashboard is not mobile compatible (Overflows etc.)

Signed-off: Aleksandar Zivkovic ([email protected])
  • Loading branch information
anywaywayany committed Nov 26, 2023
1 parent d88622c commit 850719f
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 58 deletions.
4 changes: 4 additions & 0 deletions frontend/themes/samic/components/vaadin-vertical-layout.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
:host(.container) {
border: 1px solid lightgray;
border-radius: 10px;
}
37 changes: 22 additions & 15 deletions src/main/java/com/samic/samic/views/MainLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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;
}
Expand All @@ -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);
Expand Down
36 changes: 0 additions & 36 deletions src/main/java/com/samic/samic/views/about/AboutView.java

This file was deleted.

233 changes: 233 additions & 0 deletions src/main/java/com/samic/samic/views/dashboard/DashboardView.java
Original file line number Diff line number Diff line change
@@ -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<String, List<Integer>> 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<ExampleData> hardwareGrid = new Grid<>(ExampleData.class,false);

hardwareGrid.isAllRowsVisible();
hardwareGrid.setMaxHeight("300px");



List<ExampleData> 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<ExampleData> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Loading

0 comments on commit 850719f

Please sign in to comment.