Browse Source

List available games on front page

Stephen McQuay 3 years ago
parent
commit
6bad86730e
2 changed files with 11 additions and 50 deletions
  1. 4
    1
      ui/index.html
  2. 7
    49
      ui/js/botui.js

+ 4
- 1
ui/index.html View File

@@ -19,7 +19,10 @@
19 19
             </div>
20 20
         </div>
21 21
 
22
-        <div class="container" id="game-list"></div>
22
+        <div class="container">
23
+            <ul id="games">
24
+            </ul>
25
+        </div>
23 26
 
24 27
         <script src="/ui/jquery.js"></script>
25 28
         <script src="/ui/bs/js/bootstrap.min.js"></script>

+ 7
- 49
ui/js/botui.js View File

@@ -3,58 +3,16 @@ $(function(){
3 3
     if($("#error > div").text() != "") {
4 4
         $("#error").show();
5 5
     }
6
-    loadServers();
7 6
     loadGames();
8 7
 });
9 8
 
10
-function loadServers() {
11
-    $.get("/ui/servers", function(data) {
12
-        $("#server-list").append(data);
13
-        $(".start").click(function(e) {
14
-            $("#error").hide();
15
-            data = {
16
-                'server': $(this).attr("value"),
17
-            }
18
-            $.post(
19
-                "/api/v1/game/add/",
20
-                JSON.stringify(data),
21
-                function(data) {
22
-                    if (data.ok) {
23
-                        loadGames();
24
-                    } else {
25
-                        $("#error").text(data.error);
26
-                        $("#error").show();
27
-                    }
28
-                }
29
-                );
30
-
31
-        });
32
-    });
33
-}
34
-
35 9
 function loadGames() {
36
-    $.get("/ui/games", function(data) {
37
-        $("#game-list").empty();
38
-        $("#game-list").append(data);
39
-        $(".stop").click(function(e) {
40
-            $("#error").hide();
41
-            data = {
42
-                'name': $(this).attr("server"),
43
-                'game_id': $(this).attr("value"),
44
-            }
45
-            $.post(
46
-                "/api/v1/game/stop/",
47
-                JSON.stringify(data),
48
-                function(data) {
49
-                    if (data.ok) {
50
-                        loadGames();
51
-                    } else {
52
-                        $("#error").text(data.error);
53
-                        $("#error").show();
54
-                    }
55
-                }
56
-                );
57
-
58
-        });
10
+    $.get("/api/v0/game/list/", function(data) {
11
+        $("#games").empty();
12
+        for (var key in data) {
13
+            var name = data[key]["id"];
14
+            var s = "<li><a href='/ui/game/" + name + "/'>join</a> " + name + "</li>";
15
+            $("#games").append(s);
16
+        }
59 17
     });
60 18
 }

Loading…
Cancel
Save