Updated AddUser component view
This commit is contained in:
parent
6a8319724e
commit
138377da77
@ -17,6 +17,7 @@ import ru.dragonestia.picker.api.repository.response.type.RUser;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
public class AddUsers extends Details {
|
public class AddUsers extends Details {
|
||||||
@ -25,6 +26,7 @@ public class AddUsers extends Details {
|
|||||||
private final BiConsumer<Collection<RUser>, Boolean> onCommit;
|
private final BiConsumer<Collection<RUser>, Boolean> onCommit;
|
||||||
private final Checkbox ignoreSlots;
|
private final Checkbox ignoreSlots;
|
||||||
private final VerticalLayout usersLayout;
|
private final VerticalLayout usersLayout;
|
||||||
|
private final AtomicInteger freeUserIdNumber = new AtomicInteger(1);
|
||||||
|
|
||||||
public AddUsers(RRoom room, BiConsumer<Collection<RUser>, Boolean> onCommit) {
|
public AddUsers(RRoom room, BiConsumer<Collection<RUser>, Boolean> onCommit) {
|
||||||
super(new H2("Add users"));
|
super(new H2("Add users"));
|
||||||
@ -35,15 +37,16 @@ public class AddUsers extends Details {
|
|||||||
|
|
||||||
add(addUserToTransacionButton());
|
add(addUserToTransacionButton());
|
||||||
add(usersLayout);
|
add(usersLayout);
|
||||||
usersLayout.add(new UserEntry(false));
|
usersLayout.add(new UserEntry(false, freeUserIdNumber.getAndIncrement()));
|
||||||
add(ignoreSlots = new Checkbox("Ignore slot limitation", false));
|
add(ignoreSlots = new Checkbox("Ignore slot limitation", false));
|
||||||
add(createAddUsersButton());
|
add(createAddUsersButton());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
freeUserIdNumber.set(1);
|
||||||
ignoreSlots.setValue(false);
|
ignoreSlots.setValue(false);
|
||||||
usersLayout.removeAll();
|
usersLayout.removeAll();
|
||||||
usersLayout.add(new UserEntry(false));
|
usersLayout.add(new UserEntry(false, freeUserIdNumber.getAndIncrement()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<RUser> readAllUsers() {
|
public List<RUser> readAllUsers() {
|
||||||
@ -60,7 +63,7 @@ public class AddUsers extends Details {
|
|||||||
private Button addUserToTransacionButton() {
|
private Button addUserToTransacionButton() {
|
||||||
var button = new Button("Add user to transaction");
|
var button = new Button("Add user to transaction");
|
||||||
button.addClickListener(event -> {
|
button.addClickListener(event -> {
|
||||||
usersLayout.add(new UserEntry(true));
|
usersLayout.add(new UserEntry(true, freeUserIdNumber.getAndIncrement()));
|
||||||
});
|
});
|
||||||
button.setPrefixComponent(new Icon(VaadinIcon.PLUS));
|
button.setPrefixComponent(new Icon(VaadinIcon.PLUS));
|
||||||
return button;
|
return button;
|
||||||
@ -87,14 +90,16 @@ public class AddUsers extends Details {
|
|||||||
|
|
||||||
private final TextField userIdentifierField;
|
private final TextField userIdentifierField;
|
||||||
|
|
||||||
public UserEntry(boolean canBeDeleted) {
|
public UserEntry(boolean canBeDeleted, int number) {
|
||||||
add(userIdentifierField = createUserIdentifierField(canBeDeleted));
|
add(userIdentifierField = createUserIdentifierField(canBeDeleted, number));
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextField createUserIdentifierField(boolean canBeDeleted) {
|
private TextField createUserIdentifierField(boolean canBeDeleted, int number) {
|
||||||
var field = new TextField("User id");
|
var field = new TextField("User id");
|
||||||
field.setPlaceholder("example-user-id");
|
field.setPlaceholder("example-user-id-" + number);
|
||||||
|
if (!canBeDeleted) {
|
||||||
field.setHelperText("It can be UUID, username, numeric ids, etc");
|
field.setHelperText("It can be UUID, username, numeric ids, etc");
|
||||||
|
}
|
||||||
field.setMinWidth(20, Unit.REM);
|
field.setMinWidth(20, Unit.REM);
|
||||||
|
|
||||||
if (canBeDeleted) {
|
if (canBeDeleted) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user