Skip to content

Commit

Permalink
Refactor multiple Views' code, make HWV-Grids use fullheight
Browse files Browse the repository at this point in the history
refactor AbfragenVie
refactor AppSettings
refactor UserForm
refactor UserForm, AdministrationView, UserManagement
refactor FreieLagerobjekteView
refactor LagerobjektErfassenView
refactor UIFactory, Reservation Grid, MeineHardwareView

make Grids in MeineHardwareView use full height

Signed-off-by: aleks <[email protected]>
  • Loading branch information
aleks committed Feb 22, 2024
1 parent 44fd159 commit d168b8d
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 278 deletions.
11 changes: 1 addition & 10 deletions src/main/java/com/samic/samic/components/UIFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ public static Button btnPrimary(String text, HashMap<String, String> cssKeyValue
return btnPrimary;
}

public static Button btnPrimary(
String text,
ComponentEventListener<ClickEvent<Button>> listener,
HashMap<String, String> cssKeyValuePairs) {
Button btnPrimary = UIFactory.btnPrimary(text, cssKeyValuePairs);
btnPrimary.addClickListener(listener);
return btnPrimary;
}

public static Button btnPrimaryError(String text) {
Button btnPrimary = new Button(text);
btnPrimary.getStyle().setBackground("#FF3101").setColor("#FFFFFF");
Expand Down Expand Up @@ -140,7 +131,7 @@ public static Notification notificationInfoNoDuration(String text) {
///////////---------------------GridUtils≈---------------------///////////
public static VerticalLayout LazyComponent(SerializableSupplier<? extends Component> component) {
VerticalLayout container = UIFactory.rootComponentContainer("");

container.setHeightFull();
container.addAttachListener(e -> {
if (container.getElement().getChildCount() == 1) {
container.add(component.get());
Expand Down
55 changes: 35 additions & 20 deletions src/main/java/com/samic/samic/components/form/UserForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,53 @@
@Component
@Scope("prototype")
public class UserForm extends VerticalLayout {
private TextField mail = new TextField("Email");
private PasswordField password = new PasswordField("Passwort");
private PasswordField passwordConfirm = new PasswordField("Passwort bestätigen");
private TextField surename = new TextField("Vorname");
private TextField lastname = new TextField("Nachname");
private TextField username = new TextField("Benutzername");
private ComboBox<Role> role = new ComboBox<>("Rolle");

private Binder<User> binderUser = new Binder<>(User.class);
private final TextField mail = new TextField("Email");
private final PasswordField password = new PasswordField("Passwort");
private final PasswordField passwordConfirm = new PasswordField("Passwort bestätigen");
private final TextField surname = new TextField("Vorname");
private final TextField lastname = new TextField("Nachname");
private final TextField username = new TextField("Benutzername");
private final ComboBox<Role> role = new ComboBox<>("Rolle");

private final Binder<User> binderUser = new Binder<>(User.class);


@PostConstruct
private void initUI() {
binderUser.forField(mail).asRequired().withValidator(new EmailValidator("Eingabe ist keine E-Mail")).bind(User::getMail, User::setMail);
binderUser.forField(password).asRequired().bind(User::getHashedPassword, User::setHashedPassword);
binderUser.forField(surename).asRequired().bind("profile.firstName");
add(
UIFactory.childContainer(JustifyContentMode.BETWEEN,
role),
UIFactory.childContainer(JustifyContentMode.START, mail, password, passwordConfirm),
UIFactory.childContainer(JustifyContentMode.START, surname, lastname, username)
);

initBinder();
initRolesComboBox();
initRolesData();
}

private void initBinder() {
binderUser.forField(mail).asRequired()
.withValidator(new EmailValidator("Eingabe ist keine E-Mail"))
.bind(User::getMail, User::setMail);
binderUser.forField(password).asRequired()
.bind(User::getHashedPassword, User::setHashedPassword);
binderUser.forField(surname).asRequired().bind("profile.firstName");
binderUser.forField(lastname).asRequired().bind("profile.lastName");
binderUser.forField(username).bind("profile.username");
binderUser.forField(role).asRequired().bind(User::getRole, User::setRole);
}

role.setItems(Role.values());
private void initRolesComboBox() {
role.setItemLabelGenerator(Role::getLongVersion);
role.setAllowCustomValue(false);
role.setWidth("300px");
role.setRequired(true);
add(
UIFactory.childContainer(JustifyContentMode.BETWEEN,
role),
UIFactory.childContainer(JustifyContentMode.START,mail, password, passwordConfirm),
UIFactory.childContainer(JustifyContentMode.START,surename, lastname, username)
);
}

private void initRolesData() {
role.setItems(Role.values());
}

public void setBean(User user) {
Expand All @@ -58,7 +74,7 @@ public User saveBean() {
return binderUser.getBean();
}

public Boolean isValid(){
public Boolean isValid() {
binderUser.validate();
return binderUser.isValid();
}
Expand All @@ -70,5 +86,4 @@ public void clearFields() {
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ReservationGrid extends Grid<Reservation> {
@PostConstruct
private void initUI() {
addColumn(r -> r.getStorageObject() != null ? r.getStorageObject().getId() : ""
).setHeader("Lager ID");
).setHeader("LagerID");
addColumn(r -> r.getStorageObject().getObjectTypeName().getName()).setHeader(
"Gerätetyp").setAutoWidth(true);
addColumn(Reservation::getReservedDescription).setHeader("Beschreibung");
Expand Down
98 changes: 51 additions & 47 deletions src/main/java/com/samic/samic/views/abfragen/AbfragenView.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,35 @@
@PermitAll
public class AbfragenView extends VerticalLayout {

private DatePicker dateFrom = new DatePicker("Von");
private DatePicker dateTo = new DatePicker("Bis");

private RadioButtonGroup<String> inOut = new RadioButtonGroup<>("Flussrichtung");

private ComboBox<Type> deviceType = new ComboBox("Gerätetyp");

private TextField usageAsProjectHardwareValue = new TextField();
private TextField usagAsStandardHardware = new TextField();
private TextField amountPrepared = new TextField();
private TextField amountNew = new TextField();

private final DatePicker dateFrom = new DatePicker("Von");
private final DatePicker dateTo = new DatePicker("Bis");
private final RadioButtonGroup<String> inOut = new RadioButtonGroup<>("Flussrichtung");
private final ComboBox<Type> deviceType = new ComboBox<>("Gerätetyp");
private final TextField usageAsProjectHardwareValue = new TextField();
private final TextField usagAsStandardHardware = new TextField();
private final TextField amountPrepared = new TextField();
private final TextField amountNew = new TextField();
private final Binder<StatObject> statObjectBinder = new Binder<>(StatObject.class);

private final DataProviderAbfragen dataProviderAbfragen;

public AbfragenView(DataProviderAbfragen dataProviderAbfragen){
this.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");

statObjectBinder.forField(usagAsStandardHardware)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountStandardHardware, null);
statObjectBinder.forField(usageAsProjectHardwareValue)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountProjectHardware, null);
statObjectBinder.forField(amountNew)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountnewHardware, null);
statObjectBinder.forField(amountPrepared)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountPrepared, null);
public AbfragenView(DataProviderAbfragen dataProviderAbfragen) {
this.dataProviderAbfragen = dataProviderAbfragen;

initBinder();
initUI();
};
initActions();
}


private void initUI() {
dateFrom.addValueChangeListener(e -> dateFrom.setMin(e.getValue()));
dateTo.addValueChangeListener(e -> dateTo.setMin(e.getValue()));

usagAsStandardHardware.isReadOnly();
usageAsProjectHardwareValue.isReadOnly();
amountNew.isReadOnly();
Expand All @@ -77,15 +66,11 @@ private void initUI() {
deviceType.setItemLabelGenerator(Type::getLongVersion);
deviceType.setItems(Type.values());

//Internationalization

DatePicker.DatePickerI18n germanI18n = new DatePickerI18n();

germanI18n.setMonthNames(List.of("Januar", "Februar", "März", "April", "Mai", "Juni",
"Juli", "August", "September", "Oktober", "November", "Dezember"));
germanI18n.setWeekdays(List.of
("Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"));
germanI18n.setWeekdaysShort(List.of("So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"));
germanI18n.setMonthNames(MONTH_NAMES);
germanI18n.setWeekdays(WEEK_DAYS_NAMES);
germanI18n.setWeekdaysShort(WEEK_DAYS_NAMES_SHORT);
germanI18n.setFirstDayOfWeek(1);
germanI18n.setDateFormat("dd.MM.yyyy");

Expand All @@ -94,24 +79,43 @@ private void initUI() {

inOut.setItems("Rein", "Raus");
add(UIFactory.rootComponentContainer("",
UIFactory.childContainer(JustifyContentMode.START,
dateFrom,
dateTo,
inOut,
deviceType
)),
UIFactory.childContainer(JustifyContentMode.START,
dateFrom,
dateTo,
inOut,
deviceType
)),
UIFactory.rootComponentContainer("",
UIFactory.childContainer(JustifyContentMode.BETWEEN,
new FormLayout(new Text("Verbr. als Projekthardware"), usageAsProjectHardwareValue),
new FormLayout(new Text("Verbr. als Standard Hardware"), usagAsStandardHardware),
new FormLayout(new Text("Anz. Aufbereitet"), amountPrepared),
new FormLayout(new Text("Anz. Neu"), amountNew)
)
));

)
));

//Display dummy Object
statObjectBinder.setBean(dataProviderAbfragen.getStatObject());
}

private void initActions() {
dateFrom.addValueChangeListener(e -> dateFrom.setMin(e.getValue()));
dateTo.addValueChangeListener(e -> dateTo.setMin(e.getValue()));

}

private void initBinder() {
statObjectBinder.forField(usagAsStandardHardware)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountStandardHardware, null);
statObjectBinder.forField(usageAsProjectHardwareValue)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountProjectHardware, null);
statObjectBinder.forField(amountNew)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountnewHardware, null);
statObjectBinder.forField(amountPrepared)
.withConverter(new StringToIntegerConverter(""))
.bind(StatObject::getAmountPrepared, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class AdministrationView extends TabSheet {

private final UserManagement userManagement;
private final AppSettings appSettings;

public AdministrationView(UserManagement userManagement,
AppSettings appSettings) {

Expand All @@ -22,9 +23,9 @@ public AdministrationView(UserManagement userManagement,

initUI();
}

public void initUI() {
add("App Einstellungen", appSettings);
add("Benutzerverwaltung", userManagement);

}
}
Loading

0 comments on commit d168b8d

Please sign in to comment.