Fix minor javascript problems

- Make sure that the growth rates values used for the charts are Number
- Send the catalogue version as FormData instead of json for the update
- Fix a bug that prevented the display of the characters in the home
page at application startup
This commit is contained in:
dario-cfpt
2020-03-09 22:47:03 +01:00
parent 2d2bf6ea88
commit 7d98eddfe8
3 changed files with 10 additions and 10 deletions

View File

@ -140,12 +140,12 @@ function computeCharacterGrowthRatesWithClass(char) {
charData.name = charName; charData.name = charName;
charGrowthRates.forEach(gr => { charGrowthRates.forEach(gr => {
let grValue = gr.value; let grValue = Number(gr.value);
if (classGrowthRates != null) { if (classGrowthRates != null) {
// Compute the growth rates of the character with the growth rates of the class // Compute the growth rates of the character with the growth rates of the class
let classGr = classGrowthRates.find(x => x.idStat == gr.idStat); let classGr = classGrowthRates.find(x => x.idStat == gr.idStat);
if (classGr != null) { if (classGr != null) {
grValue += classGr.value; grValue += Number(classGr.value);
} }
} }
statsValues.push(grValue); statsValues.push(grValue);

View File

@ -3,16 +3,16 @@ File name : database.js
Description : Communicates with the server to ensure that the data is up to date. Description : Communicates with the server to ensure that the data is up to date.
*/ */
const BASE_URL = "http://localhost:3000/"; const BASE_URL = "http://localhost/";
let feData = JSON.parse(localStorage.getItem("feData")); let feData = JSON.parse(localStorage.getItem("feData"));
if (feData != null) { if (feData != null) {
let body = new FormData();
body.append('version', feData.version);
fetch(BASE_URL + "update", { fetch(BASE_URL + "update", {
method: "POST", method: "POST",
body: JSON.stringify({version: feData.version}), body: body,
headers: {
'Content-Type': 'application/json'
},
}) })
.then(res => { .then(res => {
if (res.ok) { if (res.ok) {
@ -47,7 +47,7 @@ if (feData != null) {
function updateData(data) { function updateData(data) {
// If the data received from the server are not empty then we can save them in the local storage // If the data received from the server are not empty then we can save them in the local storage
if (Object.keys(data).length > 0) { if (data != null && Object.keys(data).length > 0) {
localStorage.setItem("feData", JSON.stringify(data)); localStorage.setItem("feData", JSON.stringify(data));
feData = data; feData = data;
} }

View File

@ -29,7 +29,7 @@ function displayColumnChartOfClassGrowthRates() {
}; };
classGrowthRates.forEach(gr => { classGrowthRates.forEach(gr => {
statsValues.push(gr.value); statsValues.push(Number(gr.value));
}); });
classData.data = statsValues; classData.data = statsValues;
@ -39,7 +39,7 @@ function displayColumnChartOfClassGrowthRates() {
function displayPolarSpiderOfClassGrowthRates() { function displayPolarSpiderOfClassGrowthRates() {
const classGrowthRates = getClassGrowthRates(actualClassId); const classGrowthRates = getClassGrowthRates(actualClassId);
const statsNames = feData.stats.map(x => x.name); const statsNames = feData.stats.map(x => x.name);
const statsValues = classGrowthRates.map(x => x.value); const statsValues = classGrowthRates.map(x => Number(x.value));
const classData = [{ const classData = [{
name: feData.classes.find(x => x.id == actualClassId).name, name: feData.classes.find(x => x.id == actualClassId).name,