Browse Source

recap: add input to control how much data to fetch

develop
Arthur POULET 10 months ago
parent
commit
b36249ae76
Signed by: Sceptique GPG Key ID: C108A668349EE601
  1. 30
      public/js/recap.js
  2. 9
      src/views/recap.slim
  3. 2
      test/user_system_test.rb

30
public/js/recap.js

@ -16,10 +16,26 @@ function setupChart(...cumuls) {
});
}
document.addEventListener('DOMContentLoaded', async function () {
function objectToQueryParam(obj) {
return Object.entries(obj).map(tuple => tuple.join("=")).join("&");
}
function urlWithQueryParams(base, object_with_params) {
if (Object.keys(object_with_params).length > 0) {
return `${base}?${objectToQueryParam(object_with_params)}`;
}
return base;
}
async function requestChart() {
let url = "/api/pex/v1/recap";
const days_ago = document.querySelector("#inputDaysAgo").value;
if (days_ago.length > 0) {
url = urlWithQueryParams(url, { days_ago });
}
ajax({
method: "GET",
url: "/api/pex/v1/recap",
url: url,
body: null,
headers: { Accept: "application/json" },
on_success: (body) => {
@ -27,4 +43,14 @@ document.addEventListener('DOMContentLoaded', async function () {
setupChart(...json_output.pex_tables);
},
});
}
document.addEventListener('DOMContentLoaded', async function () {
requestChart();
const form = document.querySelector(".recap-xp form#reloader");
form.addEventListener("submit", (event) => {
event.preventDefault();
requestChart();
});
});

9
src/views/recap.slim

@ -21,6 +21,15 @@ h1 Recap
| #{level.xp_from_current_level.round} / #{level.xp_for_complete_level.round}
.recap-xp
.float-end
form#reloader.col-md-6 method="GET"
== csrf_tag
.form-group.row
label.col-form-label for="inputDaysAgo" Load how many days since today ?
input#inputDaysAgo.form-control.form-control-lg name="days_ago" type="number" min="3" max="365" step="1" value=(params["days_ago"] || "60") /
.form-group.row
p
input.btn.btn-lg.btn-block type="submit" value="Reload"
#recap-xp-container style="width:100%; height:400px;"
.recap-success

2
test/user_system_test.rb

@ -22,7 +22,7 @@ class UserSystemTest < LifePexTest
api_post '/api/user/v1/register', data
assert last_response.ok?
assert_not_empty last_response.headers["Set-Cookie"]
assert_match /auth=[\-\.\w]+; domain=example.org; path=\//, last_response.headers["Set-Cookie"]
assert_match (/auth=[\-\.\w]+; domain=example.org; path=\//), last_response.headers["Set-Cookie"]
end
def test_register_refuse_duplicate

Loading…
Cancel
Save