Experimenting with list updates from server

This commit is contained in:
Falkvinge
2017-03-16 09:39:11 +01:00
parent a806ad89aa
commit 7eaf0a0c7b
4 changed files with 78 additions and 11 deletions
+22 -5
View File
@@ -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());
}
}
+3 -5
View File
@@ -250,12 +250,10 @@
</div>
</div>
<h2 class="flashheader orange">Tech Malfunctions</h2>
<h2 class="flashheader orange">Tech Malfunctions<span class="arrow"></span></h2>
<div class="box">
<div class="content">
Any malfunctions go here<br/>
Line two<br/>
(This is under construction)
<div id="divMalfunctionsList" class="content">
</div>
</div>
+51
View File
@@ -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 = $("<li>Item " + listItem.text + "</li>").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 () {
+2 -1
View File
@@ -70,4 +70,5 @@ SWARMOPS VI
[ ] Controlify financialtransaction
to show on balancetx page
[ ] Close ledger year
[X] Internal TX account type
[X] Internal TX account type
[ ] Create TX