From 1b9bc10f0b1cac51861208bcdd5ec43e83b9f40d Mon Sep 17 00:00:00 2001
From: schneefux
Date: Tue, 4 Apr 2017 17:08:58 +0200
Subject: use db connection in update API
---
index.html | 104 ++++++++++++++++++++++++++++++-------------------------------
1 file changed, 51 insertions(+), 53 deletions(-)
(limited to 'index.html')
diff --git a/index.html b/index.html
index 1a5afe7..e542138 100644
--- a/index.html
+++ b/index.html
@@ -4,10 +4,19 @@
Vainsocial backend status
-
+
+
+
+
+
+
@@ -23,66 +32,55 @@
// http fallback
client = webstomp.over(SockJS("http://localhost:15674/stomp"));
}
- // connect
- client.connect("web", "web", () => {
- $("#updates").append(
- $("")
- .text("connected to socket")
- .css("color", "purple")
- );
- }, (err) => {
+
+ let notif = (text, color) => {
$("#updates").append(
$("")
- .text("error connecting to socket: " + JSON.stringify(err))
- .css("color", "red")
+ .text(text)
+ .css("color", color)
);
- });
+ };
- $("#update-form").submit((e) => {
- let name = $("input:first").val();
+ // connect
+ client.connect("web", "web", () => notif("connected to socket", "purple"),
+ (err) => notif("error connecting to socket: " + JSON.stringify(err), "red"));
+
+ let subscribe = (name) => {
// subscribe
client.subscribe("/topic/player." + name, (msg) => {
- $("#updates").append(
- $("")
- .text(msg.body)
- .css("color", "grey")
- );
-
- if (msg.body == "search_fail") {
- $("#updates").append(
- $("")
- .text(name + ": not found")
- .css("color", "red")
- );
+ notif(msg.body, "grey");
+ switch (msg.body) {
+ case "search_fail":
+ notif(name + ": not found", "red"); break;
+ case "search_success":
+ notif(name + ": found", "green"); break;
+ case "matches_update":
+ notif(name + ": new match(es) available", "orange"); break;
+ case "stats_update":
+ notif(name + ": player profile stats updated", "orange"); break;
}
- if (msg.body == "search_success") {
- $("#updates").append(
- $("")
- .text(name + ": found")
- .css("color", "green")
- );
- }
- if (msg.body == "matches_update") {
- $("#updates").append(
- $("")
- .text(name + ": new match(es) available")
- .css("color", "orange")
- );
- }
- if (msg.body == "stats_update") {
- $("#updates").append(
- $("")
- .text(name + ": player profile stats updated")
- .css("color", "orange")
- );
- }
-
msg.ack();
}, {"ack": "client"});
+ }
- // POST
- $.post("/api/player/" + name + "/search");
+ $("#update-form").submit((e) => {
+ e.preventDefault();
+ let ign = $("#update-name").val(),
+ force = $("#update-force").is(":checked");
+
+ subscribe(ign);
+ if (force) {
+ $.post("/api/player/" + ign + "/search");
+ } else {
+ $.post("/api/player/" + ign + "/update");
+ }
+ });
+ $("#update-random-form").submit((e) => {
e.preventDefault();
+ $.post("/api/player").done((resp) => {
+ notif(resp.name + ": random user", "green");
+ subscribe(resp.name);
+ });
});
--
cgit v1.3.1