diff --git a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/QueryJSONResolver.java b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/QueryJSONResolver.java index b4286ecae..305b6e40f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/QueryJSONResolver.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/delivery/webserver/resolver/json/QueryJSONResolver.java @@ -67,7 +67,7 @@ public class QueryJSONResolver implements Resolver { return Response.builder() .setMimeType(MimeType.JSON) .setJSONContent(Maps.builder(String.class, Object.class) - .put("path", result.getResultPath(",")) + .put("path", result.getResultPath()) .put("uuids", result.getResultUUIDs()) .build()) .build(); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java index ee15ba134..cf42e9705 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/Filter.java @@ -16,10 +16,7 @@ */ package com.djrapitops.plan.storage.database.queries.filter; -import java.util.Collections; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; /** * Represents a query filter for /query page. @@ -82,15 +79,26 @@ public interface Filter { return currentUUIDs; } - public StringBuilder getResultPath(String separator) { - StringBuilder builder; - if (previous == null) { - // First Result in chain - builder = new StringBuilder(); - } else { - builder = previous.getResultPath(separator); + public List getResultPath() { + List path = new ArrayList<>(); + + Result current = this; + while (current != null) { + path.add(new ResultPath(current.filterKind, current.resultSize)); + current = current.previous; } - return builder.append(separator).append("-> ").append(filterKind).append(": ").append(resultSize); + + return path; + } + } + + class ResultPath { + final String kind; + final int size; + + public ResultPath(String kind, int size) { + this.kind = kind; + this.size = size; } } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/filters/MultiOptionFilter.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/filters/MultiOptionFilter.java index c018a4798..47e2d536f 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/filters/MultiOptionFilter.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/queries/filter/filters/MultiOptionFilter.java @@ -18,9 +18,9 @@ package com.djrapitops.plan.storage.database.queries.filter.filters; import com.djrapitops.plan.storage.database.queries.filter.Filter; import com.djrapitops.plan.storage.database.queries.filter.FilterQuery; -import org.apache.commons.lang3.StringUtils; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; -import java.util.Arrays; import java.util.List; public abstract class MultiOptionFilter implements Filter { @@ -32,10 +32,6 @@ public abstract class MultiOptionFilter implements Filter { protected List getSelected(FilterQuery query) { String selected = query.get("selected").orElseThrow(IllegalArgumentException::new); - return Arrays.asList(deserializeOptions(selected)); - } - - private String[] deserializeOptions(String selected) { - return StringUtils.split(selected, ','); + return new Gson().fromJson(selected, new TypeToken>() {}.getType()); } } diff --git a/Plan/common/src/main/resources/assets/plan/web/js/query.js b/Plan/common/src/main/resources/assets/plan/web/js/query.js index 15a049c93..e741553a0 100644 --- a/Plan/common/src/main/resources/assets/plan/web/js/query.js +++ b/Plan/common/src/main/resources/assets/plan/web/js/query.js @@ -15,8 +15,8 @@ class Filter { return 'Unimplemented render function' } - updateParameters() { - + toObject() { + return {kind: this.kind} } } @@ -45,13 +45,17 @@ class MultipleChoiceFilter extends Filter { return html; } - updateParameters() { - let selected = ""; + toObject() { + let selected = []; for (let option of document.querySelector('#' + filter.id + " select").selectedOptions) { - selected += option.text + ','; + selected.push(option.text); + } + selected = JSON.stringify(selected); + + return { + kind: this.kind, + parameters: {selected} } - selected = selected.substr(0, selected.length - 1); // Remove trailing comma - this.parameters = {selected}; } } @@ -92,10 +96,10 @@ class BetweenDateFilter extends Filter { super(kind); this.id = id; this.label = label; - this.afterDate = options.after[0]; - this.afterTime = options.after[1]; - this.beforeDate = options.before[0]; - this.beforeTime = options.before[1]; + this.dateAfter = options.after[0]; + this.timeAfter = options.after[1]; + this.dateBefore = options.before[0]; + this.timeBefore = options.before[1]; } render(filterCount) { @@ -106,31 +110,34 @@ class BetweenDateFilter extends Filter { `
` + `
` + `
` + - `` + + `` + `
` + `
` + `
` + - `` + + `` + `
` + `
` + `
` + `
` + - `` + + `` + `
` + `
` + `
` + - `` + + `` + `
` + `
` ); } - updateParameters() { - this.parameters = { - dateAfter: this.afterDate, - timeAfter: this.afterTime, - dateBefore: this.beforeDate, - timeBefore: this.beforeTime + toObject() { + return { + kind: this.kind, + parameters: { + dateAfter: this.dateAfter, + timeAfter: this.timeAfter, + dateBefore: this.dateBefore, + timeBefore: this.timeBefore + } } } } @@ -245,11 +252,14 @@ function setFilterOption( } function performQuery() { - for (filter of filterQuery) filter.updateParameters(); + const query = []; + for (filter of filterQuery) { + query.push(filter.toObject()); + } - jsonRequest(`./v1/query?q=${encodeURIComponent(JSON.stringify(filterQuery))}`, function (json, error) { + jsonRequest(`./v1/query?q=${encodeURIComponent(JSON.stringify(query))}`, function (json, error) { console.log(filterQuery); - console.log(json); - console.error(error); + if (json) console.log(json); + if (error) console.error(error); }); } \ No newline at end of file