mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 19:47:49 +01:00
Show query path with 0 results
This commit is contained in:
parent
db71ad005f
commit
22fb9c4a06
@ -120,9 +120,11 @@ public class QueryJSONResolver implements Resolver {
|
||||
q = URLDecoder.decode(q, "UTF-8");
|
||||
List<FilterQuery> queries = FilterQuery.parse(q);
|
||||
Filter.Result result = filters.apply(queries);
|
||||
List<Filter.ResultPath> resultPath = result.getInverseResultPath();
|
||||
Collections.reverse(resultPath);
|
||||
|
||||
Map<String, Object> json = Maps.builder(String.class, Object.class)
|
||||
.put("path", result.getResultPath())
|
||||
.put("path", resultPath)
|
||||
.put("view", new Gson().fromJson(view, FiltersJSONResolver.ViewJSON.class))
|
||||
.put("timestamp", timestamp)
|
||||
.build();
|
||||
|
@ -68,7 +68,7 @@ public interface Filter {
|
||||
}
|
||||
|
||||
public Result notApplied(Filter filter) {
|
||||
return new Result(this, filter.getKind(), currentUUIDs);
|
||||
return new Result(this, filter.getKind() + " (skip)", currentUUIDs);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
@ -79,7 +79,7 @@ public interface Filter {
|
||||
return currentUUIDs;
|
||||
}
|
||||
|
||||
public List<ResultPath> getResultPath() {
|
||||
public List<ResultPath> getInverseResultPath() {
|
||||
List<ResultPath> path = new ArrayList<>();
|
||||
|
||||
Result current = this;
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.storage.database.queries.filter.filters;
|
||||
|
||||
import com.djrapitops.plan.storage.database.queries.filter.CompleteSetException;
|
||||
import com.djrapitops.plan.storage.database.queries.filter.Filter;
|
||||
import com.djrapitops.plan.storage.database.queries.filter.FilterQuery;
|
||||
import com.google.gson.Gson;
|
||||
@ -31,7 +32,9 @@ public abstract class MultiOptionFilter implements Filter {
|
||||
}
|
||||
|
||||
protected List<String> getSelected(FilterQuery query) {
|
||||
String selected = query.get("selected").orElseThrow(IllegalArgumentException::new);
|
||||
return new Gson().fromJson(selected, new TypeToken<List<String>>() {}.getType());
|
||||
String selectedJSON = query.get("selected").orElseThrow(IllegalArgumentException::new);
|
||||
List<String> selected = new Gson().fromJson(selectedJSON, new TypeToken<List<String>>() {}.getType());
|
||||
if (selected.isEmpty()) throw new CompleteSetException();
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
|
@ -420,23 +420,63 @@ function getQueryAddress() {
|
||||
}
|
||||
|
||||
function runQuery() {
|
||||
const queryButton = document.querySelector('#query-button');
|
||||
const queryButton = document.getElementById('query-button');
|
||||
queryButton.setAttribute('disabled', 'true');
|
||||
queryButton.classList.add('disabled');
|
||||
|
||||
document.querySelector('#content .tab').innerHTML =
|
||||
`<div class="page-loader">
|
||||
<span class="loader"></span>
|
||||
<p class="loader-text">Loading..</p>
|
||||
</div>`;
|
||||
// document.querySelector('#content .tab').innerHTML =
|
||||
// `<div class="page-loader">
|
||||
// <span class="loader"></span>
|
||||
// <p class="loader-text">Loading..</p>
|
||||
// </div>`;
|
||||
|
||||
jsonRequest(getQueryAddress(), function (json, error) {
|
||||
if (!json.data) {
|
||||
// TODO write proper error messages
|
||||
window.history.replaceState({}, '', `${location.pathname}?error=${encodeURIComponent(error ? error : 'Query produced 0 results')}`);
|
||||
const previousPath = document.getElementById('result-path');
|
||||
if (previousPath) previousPath.remove();
|
||||
console.log(json);
|
||||
if (json) {
|
||||
if (json.data) {
|
||||
renderResults(json);
|
||||
} else if (json.path) {
|
||||
// filters resulted in 0 players matched
|
||||
renderResultPath(json);
|
||||
// Reset query
|
||||
queryButton.removeAttribute('disabled');
|
||||
queryButton.classList.remove('disabled');
|
||||
query.splice(0, query.length);
|
||||
} else {
|
||||
// Cached query expired
|
||||
window.history.replaceState({}, '', `${location.pathname}?error=${encodeURIComponent('Cached query has expired')}`);
|
||||
location.reload();
|
||||
}
|
||||
} else if (error) {
|
||||
window.history.replaceState({}, '', `${location.pathname}?error=${encodeURIComponent(error)}`);
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function renderResultPath(json) {
|
||||
let pathHtml = ``;
|
||||
for (let i = 0; i < json.path.length; i++) {
|
||||
const step = json.path[i];
|
||||
pathHtml += `<p class="m-0">`;
|
||||
for (let j = 0; j < i * 4; j++) {
|
||||
pathHtml += " ";
|
||||
}
|
||||
pathHtml += `<i class="fa fa-fw fa-filter"></i> ${step.kind} matched ${step.size} players</p>`
|
||||
}
|
||||
|
||||
const placeBefore = document.querySelector('.tab .row .card');
|
||||
const element = document.createElement('div');
|
||||
element.id = "result-path"
|
||||
element.classList.add("alert", "alert-warning", "shadow");
|
||||
element.innerHTML = pathHtml
|
||||
placeBefore.insertAdjacentElement('beforebegin', element);
|
||||
window.scrollTo(0, 0); // Scroll to top
|
||||
}
|
||||
|
||||
function renderResults(json) {
|
||||
renderDataResultScreen(json.data.players.data.length, json.view ? json.view : {});
|
||||
|
||||
// Set URL so that the query result can be shared
|
||||
@ -495,7 +535,6 @@ function runQuery() {
|
||||
document.querySelector("#data_total_sessions").innerHTML = session_data.total_sessions;
|
||||
document.querySelector("#data_average_sessions").innerHTML = session_data.average_sessions;
|
||||
document.querySelector("#data_average_session_length").innerHTML = session_data.average_session_length;
|
||||
});
|
||||
}
|
||||
|
||||
function renderDataResultScreen(resultCount, view) {
|
||||
|
Loading…
Reference in New Issue
Block a user