Skip to content

Commit

Permalink
Add HardwareGridComponent, fix stats, add Rights to Views
Browse files Browse the repository at this point in the history
Known-Issues: Not all Forms have buttons

Signed-off-by: Aleksandar Zivkovic <[email protected]>
  • Loading branch information
anywaywayany committed Feb 26, 2024
1 parent 86557ea commit 7dcaf8c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 51 deletions.
20 changes: 9 additions & 11 deletions src/main/java/com/samic/samic/views/abfragen/AbfragenView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@
import com.vaadin.flow.data.converter.StringToIntegerConverter;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import java.util.List;
import org.atmosphere.interceptor.AtmosphereResourceStateRecovery.B;

@PageTitle("Abfragen")
@Route(value = "abfragen", layout = MainLayout.class)
@PermitAll
@RolesAllowed({"MANAGMENT", "STORAGEADMINISTRATOR"})
public class AbfragenView extends VerticalLayout {

private static final List<String> MONTH_NAMES = List.of("Januar", "Februar", "März", "April",
"Mai",
"Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
private static final List<String> WEEK_DAYS_NAMES = List.of
("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
private static final List<String> WEEK_DAYS_NAMES_SHORT = List.of("So", "Mo", "Di", "Mi", "Do",
"Fr", "Sa");
private final DatePicker dateFrom = new DatePicker("Von");
private final DatePicker dateTo = new DatePicker("Bis");
private final RadioButtonGroup<String> inOut = new RadioButtonGroup<>("Flussrichtung");
Expand All @@ -35,14 +41,6 @@ public class AbfragenView extends VerticalLayout {
private final Binder<StatObject> statObjectBinder = new Binder<>(StatObject.class);
private final DataProviderAbfragen dataProviderAbfragen;

private static final List<String> MONTH_NAMES = List.of("Januar", "Februar", "März", "April",
"Mai",
"Juni", "Juli", "August", "September", "Oktober", "November", "Dezember");
private static final List<String> WEEK_DAYS_NAMES = List.of
("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag");
private static final List<String> WEEK_DAYS_NAMES_SHORT = List.of("So", "Mo", "Di", "Mi", "Do",
"Fr", "Sa");

public AbfragenView(DataProviderAbfragen dataProviderAbfragen) {
this.dataProviderAbfragen = dataProviderAbfragen;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import com.vaadin.flow.component.tabs.TabSheet;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;


@PageTitle("Administration")
@Route(value = "administration", layout = MainLayout.class)
@PermitAll
@RolesAllowed("STORAGEADMIN")
public class AdministrationView extends TabSheet {

private final UserManagement userManagement;
Expand Down
47 changes: 21 additions & 26 deletions src/main/java/com/samic/samic/views/dashboard/DashboardView.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.samic.samic.components.form.StorageForm;
import com.samic.samic.components.form.SupplyForm;
import com.samic.samic.components.form.UserForm;
import com.samic.samic.components.grid.ReservationGrid;
import com.samic.samic.components.grid.StorageObjectGrid;
import com.samic.samic.data.entity.CPE;
import com.samic.samic.data.entity.Producer;
import com.samic.samic.data.entity.Profile;
Expand All @@ -27,7 +29,6 @@
import com.vaadin.flow.component.contextmenu.MenuItem;
import com.vaadin.flow.component.contextmenu.SubMenu;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.menubar.MenuBar;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
Expand Down Expand Up @@ -69,8 +70,8 @@ public class DashboardView extends VerticalLayout implements BeforeEnterObserver
private final ComboBox<Producer> producerComboBox = new ComboBox<>("Hersteller");


Grid<StorageObject> reservationGrid = new Grid<>(StorageObject.class, false);
Grid<StorageObject> hardwareGrid = new Grid<>(StorageObject.class, false);
private final ReservationGrid reservationGrid;
private final StorageObjectGrid hardwareGrid;


public DashboardView(ServiceReservation reservationService,
Expand All @@ -79,7 +80,8 @@ public DashboardView(ServiceReservation reservationService,
ServiceObjectType serviceObjectType,
CPEForm cpeForm, SFPForm sfpForm, SupplyForm supplyForm, UserForm userForm,
ServiceObjectType objectTypeService, ServiceStorage stoageService,
ServiceProducer producerService1, StorageForm storageForm) {
ServiceProducer producerService1, StorageForm storageForm, ReservationGrid reservationGrid,
StorageObjectGrid hardwareGrid) {
this.reservationService = reservationService;
this.storageObjectService = storageObjectService;
this.authenticatedUser = authenticatedUser;
Expand All @@ -92,6 +94,8 @@ public DashboardView(ServiceReservation reservationService,
this.stoageService = stoageService;
this.producerService = producerService1;
this.storageForm = storageForm;
this.reservationGrid = reservationGrid;
this.hardwareGrid = hardwareGrid;

initUI();
}
Expand All @@ -118,11 +122,11 @@ private void initStats() {
AtomicInteger objectTypeMin = new AtomicInteger();
serviceObjectType.findObjectTypeByNameOptional(key)
.ifPresent(o -> objectTypeMin.set(o.getMinValue().intValue()));
Span sp = new Span(key + " " + value + "/" + value);
Span sp = new Span(key + " " + value + "/" + objectTypeMin);

if (value / objectTypeMin.get() > 2) {
if (objectTypeMin.get() - value < 5) {
sp.getElement().getThemeList().add("badge error");
} else if (value / objectTypeMin.get() == 2) {
} else if (objectTypeMin.get() - value < 50) {
sp.getElement().getThemeList().add("badge contrast");
} else {
sp.getElement().getThemeList().add("badge success");
Expand All @@ -134,19 +138,22 @@ private void initStats() {
}

private void initQuickAccess() {
var role = authenticatedUser.getUser().get().getRole();
menuBar.setOpenOnHover(true);
menuBar.addItem("Lagerobjekt aufnehmen", onClick -> onGetDevice());
menuBar.setWidth("100%");
menuBar.getStyle().setJustifyContent(JustifyContent.SPACE_BETWEEN);

MenuItem addSo = menuBar.addItem("Lagerobjekt erfassen");
SubMenu addSoSubmenu = addSo.getSubMenu();
addSoSubmenu.addItem("CPE", onClick -> onAddCPE());
addSoSubmenu.addItem("SFP", onClick -> onAddSFP());
addSoSubmenu.addItem("Verbrauchsmaterial", onClick -> onAddSupply());
if (role == Role.STORAGEADMIN || role == Role.FIELDSERVICETECHNICIAN) {
menuBar.addItem("Lagerobjekt erfassen", onClick -> onAddCPE());

if (authenticatedUser.getUser().isPresent()
&& authenticatedUser.getUser().get().getRole() == Role.MANAGMENT) {
MenuItem addSo = menuBar.addItem("Lagerobjekt erfassen");
SubMenu addSoSubmenu = addSo.getSubMenu();
addSoSubmenu.addItem("CPE", onClick -> onAddCPE());
addSoSubmenu.addItem("SFP", onClick -> onAddSFP());
addSoSubmenu.addItem("Verbrauchsmaterial", onClick -> onAddSupply());
}
if (role == Role.STORAGEADMIN) {
menuBar.addItem("Lager hinzufügen", onClick -> {
Dialog dialog = new Dialog();
dialog.add(storageForm);
Expand Down Expand Up @@ -320,18 +327,6 @@ private void initReservation() {
reservationGrid.setMaxHeight("300px");
reservationGrid.getStyle().setBorder("0px");

reservationGrid.addColumn(so -> Guard.isNotNull.test(so) ? so.getId() : Long.valueOf(12L))
.setHeader("Lager ID");
reservationGrid.addColumn(
so -> Guard.isNotNull.test(so.getReservation()) ? so.getRemark() : "Test")
.setHeader("Reservierungsbeschreibung").setAutoWidth(true);
reservationGrid.addColumn(
so -> Guard.isNotNull.test(so.getReservation()) ? so.getReservation().getReservedAt()
: "Test")
.setHeader("Reserviert bis(mom. res. am)").setAutoWidth(true); //Fehlt im Backend
reservationGrid.addColumn(
so -> Guard.isNotNull.test(so.getReservation()) ? so.getObjectTypeName() : "Test")
.setHeader("Gerätetyp Name").setAutoWidth(true);
initReservationData();

// MY RESERVATION - PUT UI TOGETHER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
import com.vaadin.flow.data.converter.StringToLongConverter;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import java.util.NoSuchElementException;


@PageTitle("Lagerobjekt aufnehmen")
@Route(value = "lagerobjektAufnehmen", layout = MainLayout.class)
@PermitAll
@RolesAllowed({"FIELDSERVICETECHNICIAN", "STORAGEADMINISTRATOR"})
public class LagerobjektAufnehmenView extends VerticalLayout {

private final ServiceStorageObject storageObjectService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.samic.samic.components.form.SFPForm;
import com.samic.samic.components.form.SupplyForm;
import com.samic.samic.data.entity.CPE;
import com.samic.samic.data.entity.Customer;
import com.samic.samic.data.entity.ObjectType;
import com.samic.samic.data.entity.Producer;
import com.samic.samic.data.entity.SFP;
Expand All @@ -23,17 +22,14 @@
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.BeforeLeaveEvent;
import com.vaadin.flow.router.BeforeLeaveObserver;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import java.util.List;
import java.util.stream.Stream;

@PageTitle("Lagerobjekt erfassen")
@Route(value = "lagerobjektErfassen", layout = MainLayout.class)
@PermitAll
@RolesAllowed({"FIELDSERVICETECHNICIAN", "STORAGEADMINISTRATOR"})
public class LagerobjektErfassenView extends VerticalLayout {

private final ServiceProducer producerService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import com.vaadin.flow.component.tabs.TabSheet;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;
import java.util.List;
import org.vaadin.lineawesome.LineAwesomeIcon;

@PageTitle("Meine Hardware")
@Route(value = "meineHardware", layout = MainLayout.class)
@PermitAll
@RolesAllowed({"FIELDSERVICETECHNICIAN", "STORAGEADMINISTRATOR"})
public class MeineHardwareView extends TabSheet {

private final ReservationGrid reservationGrid;
Expand Down Expand Up @@ -90,9 +90,9 @@ private void initReservationGridData() {
// (cut off stream from repository), or make repo return list
//TODO reservation does not contain storageobject

reservationGrid.setItems(
reservationGrid.setItems(
reservationService.findAllReservationByGivenUser(authenticatedUser.getUser()
.get()));
.get()));
}

private void initStorageObjectGrid() {
Expand Down

0 comments on commit 7dcaf8c

Please sign in to comment.