Random tiny changes to code quality

This commit is contained in:
Risto Lahtela 2020-10-15 19:41:11 +03:00
parent 9648deb853
commit 908d1c6203
5 changed files with 24 additions and 31 deletions

View File

@ -37,7 +37,7 @@ import java.util.Optional;
@Singleton
public class QueryJSONResolver implements Resolver {
private QueryFilters filters;
private final QueryFilters filters;
@Inject
public QueryJSONResolver(

View File

@ -51,11 +51,11 @@ public interface Filter {
}
class Result {
private Result previous;
private final Result previous;
private String filterKind;
private int resultSize;
private Set<UUID> currentUUIDs;
private final String filterKind;
private final int resultSize;
private final Set<UUID> currentUUIDs;
private Result(Result previous, String filterKind, Set<UUID> currentUUIDs) {
this.previous = previous;

View File

@ -31,7 +31,7 @@ import java.util.*;
@Singleton
public class QueryFilters {
private Map<String, Filter> filters;
private final Map<String, Filter> filters;
@Inject
public QueryFilters(Set<Filter> filters) {

View File

@ -1,10 +1,10 @@
var filterCount = 0;
let filterCount = 0;
/* {
id: "DOM id",
options...
}*/
var filterQuery = [];
const filterQuery = [];
function addFilter(parentSelector, filterIndex) {
const id = "f" + filterCount;
@ -59,20 +59,20 @@ function createBetweenSelector(id, label, options) {
`<div id="${id}" class="mt-2 input-group input-row">` +
`<div class="col-3"><div class="input-group mb-2">` +
`<div class="input-group-prepend"><div class="input-group-text"><i class="far fa-calendar"></i></div></div>` +
`<input id="${id}-afterdate" onkeyup="setFilterOption('${id}', '${id}-afterdate', 'afterDate', 'isValidDate', 'correctDate')" class="form-control" placeholder="${query.afterDate}" type="text">` +
`<input id="${id}-afterdate" onkeyup="setFilterOption('${id}', '${id}-afterdate', 'afterDate', isValidDate, correctDate)" class="form-control" placeholder="${query.afterDate}" type="text">` +
`</div></div>` +
`<div class="col-2"><div class="input-group mb-2">` +
`<div class="input-group-prepend"><div class="input-group-text"><i class="far fa-clock"></i></div></div>` +
`<input id="${id}-aftertime" onkeyup="setFilterOption('${id}', '${id}-aftertime', 'afterTime', 'isValidTime', 'correctTime')" class="form-control" placeholder="${query.afterTime}" type="text">` +
`<input id="${id}-aftertime" onkeyup="setFilterOption('${id}', '${id}-aftertime', 'afterTime', isValidTime, correctTime)" class="form-control" placeholder="${query.afterTime}" type="text">` +
`</div></div>` +
`<div class="col-auto"><label class="mt-2 mb-0" for="inlineFormCustomSelectPref">&</label></div>` +
`<div class="col-3"><div class="input-group mb-2">` +
`<div class="input-group-prepend"><div class="input-group-text"><i class="far fa-calendar"></i></div></div>` +
`<input id="${id}-beforedate" onkeyup="setFilterOption('${id}', '${id}-beforedate', 'beforeDate', 'isValidDate', 'correctDate')" class="form-control" placeholder="${query.beforeDate}" type="text">` +
`<input id="${id}-beforedate" onkeyup="setFilterOption('${id}', '${id}-beforedate', 'beforeDate', isValidDate, correctDate)" class="form-control" placeholder="${query.beforeDate}" type="text">` +
`</div></div>` +
`<div class="col-2"><div class="input-group mb-2">` +
`<div class="input-group-prepend"><div class="input-group-text"><i class="far fa-clock"></i></div></div>` +
`<input id="${id}-beforetime" onkeyup="setFilterOption('${id}', '${id}-beforetime', 'beforeTime', 'isValidTime', 'correctTime')" class="form-control" placeholder="${query.beforeTime}" type="text">` +
`<input id="${id}-beforetime" onkeyup="setFilterOption('${id}', '${id}-beforetime', 'beforeTime', isValidTime, correctTime)" class="form-control" placeholder="${query.beforeTime}" type="text">` +
`</div></div>` +
`</div>`
);
@ -105,12 +105,12 @@ function correctDate(value) {
function isValidTime(value) {
if (!value) return true;
const regex = /^[0-2][0-9]\:[0-5][0-9]$/;
const regex = /^[0-2][0-9]:[0-5][0-9]$/;
return regex.test(value);
}
function correctTime(value) {
const d = value.match(/^(\d{2})\:?(\d{2})$/);
const d = value.match(/^(\d{2}):?(\d{2})$/);
if (!d) return value;
let hour = d[1];
while (hour > 23) hour--;
@ -134,10 +134,10 @@ function setFilterOption(
console.log(element, value, id, elementId);
value = window[correctionFunction].apply(element, [value]);
value = correctionFunction.apply(element, [value]);
element.val(value);
const isValid = window[isValidFunction].apply(element, [value]);
const isValid = isValidFunction.apply(element, [value]);
if (isValid) {
element.removeClass("is-invalid");
query[propertyName] = value;

View File

@ -137,7 +137,8 @@
data-toggle="dropdown" id="filterDropdown" type="button">
<i class="fa fa-plus"></i> Add a filter..
</button>
<div aria-labelledby="filterDropdown" class="dropdown-menu">
<div aria-labelledby="filterDropdown" class="dropdown-menu"
id="filter-dropdown">
<a class="dropdown-item" id="dropdown-loading">Loading filters..</a>
</div>
</div>
@ -300,14 +301,6 @@
<script src="./vendor/jquery/jquery.min.js"></script>
<script src="./vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="./vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Page level plugins -->
<script src="./vendor/datatables/jquery.dataTables.min.js"></script>
<script src="./vendor/datatables/dataTables.bootstrap4.min.js"></script>
<script src='./vendor/momentjs/moment.js'></script>
<!-- Custom scripts for all pages-->
<script src="./js/sb-admin-2.js"></script>
<script src="./js/xmlhttprequests.js"></script>
@ -317,16 +310,16 @@
<script src='./js/query.js'></script>
<script id="mainScript">
var filters = [];
const filters = [];
jsonRequest("./v1/filters", function (json, error) {
openPage();
filters.push(...json.filters);
console.log(filters);
var filterElements = [];
for (var i = 0; i < filters.length; i++) {
filterElements.push(createFilterSelector('#filters', i, filters[i]));
let filterElements = '';
for (let i = 0; i < filters.length; i++) {
filterElements += createFilterSelector('#filters', i, filters[i]);
}
$('#dropdown-loading').replaceWith(filterElements);
document.getElementById('filter-dropdown').innerHTML = filterElements;
});
</script>