Skip to content

Commit

Permalink
Blocked slots replacementText can now be replaced with calling BlockS…
Browse files Browse the repository at this point in the history
…lot again

Fixed replacementText resetting while editing slotlist via website
  • Loading branch information
Alf-Melmac committed Oct 26, 2021
1 parent 1d85ddd commit 0485176
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/main/java/de/webalf/slotbot/model/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ boolean isNotEmpty() {
return !isEmpty();
}

public boolean isBlocked() {
return isNotEmpty() && getUser().isDefaultUser();
}

// Setter

/**
Expand Down Expand Up @@ -146,7 +150,7 @@ void unslotWithoutUpdate(User user) {
}

public void blockSlot(@NonNull User defaultUser, @NotBlank String replacementName) {
if (isNotEmpty()) {
if (isNotEmpty() && !isBlocked()) {
throw BusinessRuntimeException.builder().title("Der Slot ist belegt, die Person muss zuerst ausgeslottet werden.").build();
} else if (getSquad().isReserve()) {
throw BusinessRuntimeException.builder().title("In der Reserve kann kein Slot blockiert werden.").build();
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/de/webalf/slotbot/service/SlotService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.ArrayList;
import java.util.List;

import static de.webalf.slotbot.util.StringUtils.getFirstNotEmpty;

/**
* @author Alf
* @since 27.07.2020
Expand Down Expand Up @@ -79,7 +81,9 @@ private Slot updateOrCreateSlot(@NonNull SlotDto dto, @NonNull Squad squad) {
DtoUtils.ifPresent(dto.getName(), slot::setName);
DtoUtils.ifPresent(dto.getNumber(), slot::setNumber);
DtoUtils.ifPresent(dto.getUser(), slot::setUser);
DtoUtils.ifPresent(dto.getReplacementText(), slot::setReplacementText);
if (slot.isBlocked()) {
slot.setReplacementText(getFirstNotEmpty("Gesperrt", dto.getReplacementText(), slot.getReplacementText()));
}

return slot;
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/de/webalf/slotbot/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,33 @@ public static boolean onlyNumbers(String str) {
public static String removeNonDigitCharacters(String str) {
return str.replaceAll(NON_DIGIT_REGEX, "");
}

/**
* Returns a trimmed version of the given string. The string may be null.
*
* @param str string to trim
* @return trimmed version of the given string
*/
public static String trim(String str) {
if (str == null) {
return null;
}
return str.trim();
}

/**
* Gets the first string that is not empty.
*
* @param fallback to use if all given strings are empty
* @param strs strings that may be null or empty
* @return first found not empty string or the given fallback if non is not empty
*/
public static String getFirstNotEmpty(String fallback, String... strs) {
for (String str : strs) {
if (isNotEmpty(str)) {
return str;
}
}
return fallback;
}
}
1 change: 0 additions & 1 deletion src/main/resources/static/assets/js/eventSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ function getSquads(update = false) {
slot.user = {
id: defaultUserId
}
slot.replacementText = 'Gesperrt'
}
if (update) {
slot.id = $slot.data('slotid');
Expand Down

0 comments on commit 0485176

Please sign in to comment.