Skip to content
Snippets Groups Projects
Commit f80ee109 authored by Otto Visser's avatar Otto Visser
Browse files

Merge branch '232-clear-filters-button-shows-up-after-empty-filter-submit' into 'development'

Fix "clear filter" button appearing

See merge request !217
parents 2db137b5 326592e4
Branches
Tags
2 merge requests!222Development,!217Fix "clear filter" button appearing
......@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Unauthorized students for labs/courses now redirects to enroll pages by [@cedricwilleken](https://gitlab.ewi.tudelft.nl/cedricwilleken)
- "Clear filters" button won't appear after submission with no filters on Requests page by [@sjuhosova](https://gitlab.ewi.tudelft.nl/sjuhosova)
## [1.0.0] - 2019-10-24
Initial public release
\ No newline at end of file
......@@ -15,9 +15,7 @@
*/
package nl.tudelft.ewi.queue.service;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -38,6 +36,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.BooleanExpression;
......@@ -59,6 +58,9 @@ import com.querydsl.core.types.dsl.BooleanExpression;
public class RequestTableService {
private static final String PREDICATE_POSTFIX = "_filter_predicate";
private static final String PARAMETERS_POSTFIX = "_filter_parameters";
private static final Set<String> FILTERS = Sets.newHashSet(
"lab.course", "lab", "assignment", "room", "assistant", "status", "requestType"
);
@Autowired
private RoomRepository roomRepository;
......@@ -71,8 +73,8 @@ public class RequestTableService {
/**
* Analyses the given parameters and performs an action based on it. If the parameters contain a 'clear'
* attribute, the filters stored in the current session are removed. Otherwise, the given parameters and
* predicate are stored in the current session.
* attribute, the filters stored in the current session are removed. If the parameters do not contain a filtering
* attribute, nothing is submitted. Otherwise, the given parameters and predicate are stored in the current session.
*
* @param request The HttpServletRequest used to get the session.
* @param parameters The parameters to store.
......@@ -81,10 +83,8 @@ public class RequestTableService {
public void submitFilters(HttpServletRequest request,
MultiValueMap<String, String> parameters,
Predicate predicate) {
if (parameters == null) {
return;
}
if (containsFilterParams(parameters)) {
String key = pathFromRequest(request);
if (parameters.containsKey("clear")) {
clearFilters(request, key);
......@@ -92,6 +92,7 @@ public class RequestTableService {
storeFilters(request, key, parameters, predicate);
}
}
}
/**
* Stores the given parameters and predicates under the given key in the current session.
......@@ -267,6 +268,15 @@ public class RequestTableService {
.orElse(new LinkedMultiValueMap<>());
}
/**
* Checks whether the query parameters include filters.
* @param parameters the query parameters of the request
* @return true if there is at least one filtering query parameter
*/
private boolean containsFilterParams(MultiValueMap<String, String> parameters) {
return parameters != null && !(Sets.intersection(FILTERS, parameters.keySet())).isEmpty();
}
/**
* Flatmaps a list of courses to a list of labs.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment