]> gitweb.ps.run Git - lolstats/blobdiff - html/script.js
changes
[lolstats] / html / script.js
index 25f1565c26f2f69cc3f5805cd2cc4c7f0054bfae..11052629613b6c2d3d9407ffaabb20073b74e19a 100644 (file)
@@ -1,8 +1,15 @@
 function getRegions() {
-  return [ "euw", "na", "kr", "br" ];
+  $.ajax("/lol/regions")
+    .done((data) => {
+      app.regions = JSON.parse(data);
+      setTimeout(() => $("#regionselect").val(app.region), 0);
+    });
 }
 function getChampions() {
-  return [ {name: "Aatrox"}, {name: "Annie"}, {name: "Braum"}, {name: "Not"} ];
+  $.ajax("/lol/champions")
+    .done((data) => {
+      app.champions = JSON.parse(data);
+    });
 }
 function getMatchProps() {
   return [
@@ -11,10 +18,16 @@ function getMatchProps() {
   ];
 }
 function getMatches() {
-  return [
-    {champ: "Xerath", lane: "Middle"},
-    {champ: "Quinn", lane: "Bottom"},
-  ];
+  $.ajax("/lol/matches?region=" + app.region + "&summoner=" + app.summoner)
+    .done((data) => {
+      app.matches = data;
+      for (p in app.matches[0]) {
+        app.matchprops.push({
+          name: p,
+          text: p.toUpperCase(),
+        });
+      }
+    });
 }
 function getInfo() {
   app.summoner = $("#nameinput").val();
@@ -92,10 +105,10 @@ let app = new Vue({
     summoner: "",
     region: "",
     view: "",
-    regions: getRegions(),
-    champions: getChampions(),
-    matchprops: getMatchProps(),
-    matches: getMatches(),
+    regions: [],
+    champions: [],
+    matchprops: [],
+    matches: [],
   },
   methods: {
     submit: function() {
@@ -113,6 +126,7 @@ let app = new Vue({
       setUrl();
     },
     refreshHistory: function() {
+      getMatches();
     },
   },
 });
@@ -125,7 +139,6 @@ function parseUrl() {
   }
   if (url.searchParams.has("region")) {
     app.region = url.searchParams.get("region");
-    $("#regionselect").val(app.region);
   }
   if (url.searchParams.has("view")) {
     let view = url.searchParams.get("view");
@@ -142,7 +155,9 @@ window.addEventListener('popstate', () => {
   let view = parseUrl();
   changeView(view);
 });
-window.addEventListener('load', () => {
+window.addEventListener('load', async () => {
   let view = parseUrl();
   setView(view);
+  getRegions();
+  getChampions();
 });