From 7eaf0a0c7b22342a3cb2dfca0564acc6b2f37bed Mon Sep 17 00:00:00 2001 From: Falkvinge Date: Thu, 16 Mar 2017 09:39:11 +0100 Subject: [PATCH] Experimenting with list updates from server --- FrontSocket/FrontendLoop.cs | 27 ++++++++++++++++---- Site/Master-v5.master | 8 +++--- Site/Scripts/Swarmops-v5.js | 51 +++++++++++++++++++++++++++++++++++++ todo.txt | 3 ++- 4 files changed, 78 insertions(+), 11 deletions(-) diff --git a/FrontSocket/FrontendLoop.cs b/FrontSocket/FrontendLoop.cs index c79ac14a..3aaa70c4 100644 --- a/FrontSocket/FrontendLoop.cs +++ b/FrontSocket/FrontendLoop.cs @@ -203,6 +203,9 @@ namespace Swarmops.Frontend.Socket private static int _sandboxDummy1 = 500; private static int _sandboxDummy2 = 50000; + private static int _malfunctionTestCounter = 0; + private static string[] malfunctionStrings = {"One", "Two", "Three", "Four"}; + private static void OnEveryTenSeconds() { SystemSettings.HeartbeatFrontend = DateTime.UtcNow.ToUnix(); @@ -212,12 +215,26 @@ namespace Swarmops.Frontend.Socket _sandboxDummy1 += new Random().Next(10) - 3; _sandboxDummy2 += new Random().Next(1000) - 200; - JObject data = new JObject(); - data["MessageType"] = "SandboxUpdate"; - data["Local"] = _sandboxDummy1.ToString(CultureInfo.InvariantCulture); - data["Profit"] = _sandboxDummy2.ToString(CultureInfo.InvariantCulture); + JObject data1 = new JObject(); + data1["MessageType"] = "SandboxUpdate"; + data1["Local"] = _sandboxDummy1.ToString(CultureInfo.InvariantCulture); + data1["Profit"] = _sandboxDummy2.ToString(CultureInfo.InvariantCulture); - _socketServer.WebSocketServices.Broadcast(data.ToString()); + _socketServer.WebSocketServices.Broadcast(data1.ToString()); + + JArray malfunctionsArray = new JArray(); + for (int loop = 0; loop < _malfunctionTestCounter; loop++) + { + JObject malfunctionObject = new JObject(); + malfunctionObject["Id"] = "Mal" + loop.ToString(); + malfunctionObject["Text"] = malfunctionStrings[loop]; + malfunctionsArray.Add(malfunctionObject); + } + + JObject data2 = new JObject(); + data2["MessageType"] = "Malfunctions"; + data2["MalfunctionsData"] = malfunctionsArray.ToString(); + _socketServer.WebSocketServices.Broadcast(data2.ToString()); } } diff --git a/Site/Master-v5.master b/Site/Master-v5.master index 4549421a..93cadc26 100644 --- a/Site/Master-v5.master +++ b/Site/Master-v5.master @@ -250,12 +250,10 @@ -

Tech Malfunctions

+

Tech Malfunctions

-
- Any malfunctions go here
- Line two
- (This is under construction) +
+
diff --git a/Site/Scripts/Swarmops-v5.js b/Site/Scripts/Swarmops-v5.js index 914fb074..495a67fe 100644 --- a/Site/Scripts/Swarmops-v5.js +++ b/Site/Scripts/Swarmops-v5.js @@ -47,6 +47,10 @@ function _masterInitializeSocket(authenticationTicket) { alertify.log("Bitcoin received: " + message.Currency + " " + message.CentsFormatted); } } + else if (message.MessageType == "Malfunctions") { + console.log(message.MalfunctionsList); + updateListBox($('#divMalfunctionsList'), message.MalfunctionsList); + } else if (message.MessageType == "SandboxUpdate") { if (odoLocalParticipation != undefined) { // Real ugly accessing specific page elements here, but it's temporary odoLocalParticipation.innerHTML = message.Local; @@ -67,6 +71,53 @@ function getMasterSocketAddress() { } } +// ------------------- List updating -------------------------- + + +function updateListBox(box, listData) { + // list is an array of object { id, text } + // box is a div-div-ul-li nest containing the li:s with the id + // the function syncs the box to the list with some nice fades + + // Is the box visible right now? + + var boxVisible = $(box).is(":visible"); + + // Step 1: Iterate through list, build id array + + var idListLookup = {}; + listData.forEach(function(item, index) { + idListLookup[item.id] = item; + }); + + // Step 2: Iterate through box, change texts of matching ids, + // remove items that aren't in list, build id array + + var idBoxLookup = {}; + var listContainer = $(box).firstChild.firstChild; + console.log($(box)); + console.log(listContainer); + var listElements = $(listContainer).children; + + // Step 3: Iterate through list, add missing items + + /* + var newItem = $("
  • Item " + listItem.text + "
  • ").hide(); + $("#mylist").prepend(newItem); + newItem.slideDown();*/ + + // Step 4: Adjust visibility as required + + if (!boxVisible && listData.length > 0) { + box.fadeIn(); + } + else if (boxVisible && listData.length == 0) { + box.fadeOut(); + } +} + + + // ------------------- SwarmopsJS object ---------------------- var SwarmopsJS = (function () { diff --git a/todo.txt b/todo.txt index 5c7fb14f..fe968e51 100644 --- a/todo.txt +++ b/todo.txt @@ -70,4 +70,5 @@ SWARMOPS VI [ ] Controlify financialtransaction to show on balancetx page [ ] Close ledger year -[X] Internal TX account type \ No newline at end of file +[X] Internal TX account type +[ ] Create TX