From 193141d3e783ab15cf86a956d7533dcb80b0d02f Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sat, 19 Mar 2016 23:21:10 +0100 Subject: NMS: Fix disappearing BG on resizeEvent --- web/nms.gathering.org/js/nms-map.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index 9bba1bf..3749a16 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -138,6 +138,9 @@ nmsMap._resizeEvent = function() { continue; nmsMap._c[a].c.height = nmsMap._canvas.height; nmsMap._c[a].c.width = nmsMap._canvas.width; + if(a == 'bg') { + nmsMap._drawBG(); + } } if (nmsMap._init != true) { console.log("Drawing shit"); -- cgit v1.2.3 From d98c48eeb7b3d3ae0bf49012160dfde907c014b2 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Sun, 20 Mar 2016 10:53:28 +0100 Subject: NMS: Fix nms-map load not triggering --- web/nms.gathering.org/js/nms-map.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index 3749a16..bbb304f 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -59,7 +59,7 @@ nmsMap.init = function() { this._init = true; nmsData.addHandler("switches","nmsMap",function(){nmsMap._resizeEvent();}); window.addEventListener('resize',nmsMap._resizeEvent,true); - document.addEventListener('load',nmsMap._loadEvent,true); + window.addEventListener('load',nmsMap._loadEvent,true); } nmsMap.setSwitchColor = function(sw, color) { @@ -143,7 +143,6 @@ nmsMap._resizeEvent = function() { } } if (nmsMap._init != true) { - console.log("Drawing shit"); nmsMap._blurDrawn = false; nmsMap._drawBG(); nmsMap._drawAllSwitches(); -- cgit v1.2.3 From 9294a2f2b20a9289a9b5c4a4b72f308de85d8c30 Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Mon, 21 Mar 2016 11:57:33 +0100 Subject: NMS: Fix switch movement and poll timeout --- web/nms.gathering.org/js/nms-map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index bbb304f..b74626a 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -433,7 +433,7 @@ nmsMap._moveSubmit = function() { var myData = JSON.stringify([data]); $.ajax({ type: "POST", - url: "/api/private/switch-add", + url: "/api/private/switch-update", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { -- cgit v1.2.3 From 90632b710fa8798c0eeda1bb10ff25b328634e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Kir=C3=B8?= Date: Mon, 21 Mar 2016 16:25:14 +0100 Subject: js linting / code fixup. --- web/nms.gathering.org/js/nms-map.js | 77 +++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 37 deletions(-) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index b74626a..c6bad49 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -48,19 +48,20 @@ var nmsMap = nmsMap || { _color: { }, _highlight: { }, _c: {} -} +}; nmsMap._loadEvent = function(e) { nmsMap._init = false; nmsMap._drawAllSwitches(); -} +}; + nmsMap.init = function() { this._initContexts(); this._init = true; nmsData.addHandler("switches","nmsMap",function(){nmsMap._resizeEvent();}); window.addEventListener('resize',nmsMap._resizeEvent,true); window.addEventListener('load',nmsMap._loadEvent,true); -} +}; nmsMap.setSwitchColor = function(sw, color) { if (this._color[sw] != color) { @@ -70,7 +71,7 @@ nmsMap.setSwitchColor = function(sw, color) { } else { this.stats.colorSame++; } -} +}; nmsMap.setSwitchHighlight = function(sw, highlight) { if(highlight) @@ -80,12 +81,12 @@ nmsMap.setSwitchHighlight = function(sw, highlight) { this._drawSwitch(sw); this.stats.highlightChange++; } -} +}; nmsMap.removeAllSwitchHighlights = function() { for(var sw in this._highlight) this.setSwitchHighlight(sw,false); -} +}; nmsMap.reset = function() { for (var sw in this._color) { @@ -94,7 +95,7 @@ nmsMap.reset = function() { for (var sw in this._info) { nmsMap.setSwitchInfo(sw, undefined); } -} +}; nmsMap.setSwitchInfo = function(sw,info) { if (this._info[sw] != info) { @@ -104,19 +105,19 @@ nmsMap.setSwitchInfo = function(sw,info) { } else { this.stats.switchInfoSame++; } -} +}; nmsMap._initContext = function(name) { this._c[name] = {}; this._c[name].c = document.getElementById(name + "Canvas"); this._c[name].ctx = this._c[name].c.getContext('2d'); -} +}; nmsMap._initContexts = function() { for (var context in this.contexts) { this._initContext(this.contexts[context]); } -} +}; nmsMap._resizeEvent = function() { var width = window.innerWidth - nmsMap._c.bg.c.offsetLeft; @@ -149,7 +150,7 @@ nmsMap._resizeEvent = function() { nmsMap.drawNow(); nmsMap.stats.resizeEvents++; } -} +}; /* * Draw current time-window @@ -177,10 +178,10 @@ nmsMap.drawNow = function () ctx.fillStyle = "white"; ctx.strokeStyle = "black"; ctx.lineWidth = nms.fontLineFactor; - ctx.strokeText(now, 0 + this._settings.textMargin, 25); - ctx.fillText(now, 0 + this._settings.textMargin, 25); + ctx.strokeText(now, this._settings.textMargin, 25); + ctx.fillText(now, this._settings.textMargin, 25); ctx.restore(); -} +}; nmsMap.setNightMode = function(toggle) { if (this._nightmode == toggle) @@ -196,14 +197,14 @@ nmsMap.setNightMode = function(toggle) { this._c.blur.c.style.display = ""; } nmsMap._drawBG(); -} +}; nmsMap._drawBG = function() { var imageObj = document.getElementById('source'); this._c.bg.ctx.drawImage(imageObj, 0, 0, nmsMap._canvas.width, nmsMap._canvas.height); if(this._nightmode) nmsMap._invertBG(); -} +}; nmsMap._invertBG = function() { var imageData = this._c.bg.ctx.getImageData(0, 0, nmsMap._canvas.width, nmsMap._canvas.height); @@ -215,7 +216,7 @@ nmsMap._invertBG = function() { data[i + 2] = 255 - data[i + 2]; } this._c.bg.ctx.putImageData(imageData, 0, 0); -} +}; nmsMap._getBox = function(sw) { var box = nmsData.switches.switches[sw]['placement']; @@ -224,7 +225,7 @@ nmsMap._getBox = function(sw) { box.width = parseInt(box.width); box.height = parseInt(box.height); return box; -} +}; nmsMap._drawSwitchBlur = function(sw) { @@ -238,7 +239,8 @@ nmsMap._drawSwitchBlur = function(sw) this._c.blur.ctx.scale(this.scale, this.scale); // FIXME this._c.blur.ctx.fillRect(box['x'],box['y'],box['width'],box['height']); this._c.blur.ctx.restore(); -} +}; + nmsMap._drawSwitch = function(sw) { // XXX: If a handler sets a color before switches are loaded... The @@ -257,7 +259,7 @@ nmsMap._drawSwitch = function(sw) this._drawBox(this._c.switch.ctx, box['x'],box['y'],box['width'],box['height']); this._c.switch.ctx.shadowBlur = 0; this._drawText(this._c.text.ctx, sw,box); -} +}; nmsMap._drawSwitchInfo = function(sw) { var box = this._getBox(sw); @@ -266,14 +268,14 @@ nmsMap._drawSwitchInfo = function(sw) { } else { this._drawText(this._c.textInfo.ctx, this._info[sw], box, "right"); } -} +}; nmsMap._clearBox = function(ctx,box) { ctx.save(); ctx.scale(this.scale,this.scale); ctx.clearRect(box['x'], box['y'], box['width'], box['height']); ctx.restore(); -} +}; nmsMap._drawText = function(ctx, text, box, align) { var rotate = false; @@ -309,7 +311,7 @@ nmsMap._drawText = function(ctx, text, box, align) { ctx.strokeText(text, 0, 0); ctx.fillText(text, 0, 0); ctx.restore(); -} +}; nmsMap._drawAllSwitches = function() { if (nmsData.switches == undefined) { @@ -321,7 +323,7 @@ nmsMap._drawAllSwitches = function() { } if (this._nightmode) this._drawAllBlur(); -} +}; nmsMap._drawAllBlur = function() { if (nmsMap._blurDrawn == true) @@ -330,7 +332,7 @@ nmsMap._drawAllBlur = function() { for (var sw in nmsData.switches.switches) { nmsMap._drawSwitchBlur(sw); } -} +}; nmsMap._drawBox = function(ctx, x, y, boxw, boxh) { ctx.save(); @@ -340,12 +342,12 @@ nmsMap._drawBox = function(ctx, x, y, boxw, boxh) { ctx.strokeStyle = "#000000"; ctx.strokeRect(x,y, boxw, boxh); ctx.restore(); -} +}; nmsMap._connectSwitches = function(sw1, sw2, color1, color2) { nmsMap._connectBoxes(this._getBox(sw1), this._getBox(sw2), color1, color2); -} +}; /* * Draw a line between two boxes, with a gradient going from color1 to @@ -372,13 +374,13 @@ nmsMap._connectBoxes = function(box1, box2,color1, color2) { ctx.lineWidth = 5; ctx.stroke(); ctx.restore(); -} +}; nmsMap.moveSet = function(toggle) { nmsMap._moveInProgress = toggle; if (!toggle) nmsMap._moveStopListen(); -} +}; /* * onclick handler for the canvas. @@ -395,7 +397,7 @@ nmsMap.canvasClick = function(e) nmsInfoBox.click(sw); } } -} +}; nmsMap._clearOld = function(box) { if (box) { @@ -405,7 +407,7 @@ nmsMap._clearOld = function(box) { nmsMap._c.top.ctx.clearRect(box['x'] - 5, box['y'] - 5, box['width'] + 10, box['height'] + 10); nmsMap._c.top.ctx.restore(); } -} +}; nmsMap._moveMove = function(e) { nmsMap._moveX = (e.pageX - e.target.offsetLeft) / nmsMap.scale; @@ -423,13 +425,13 @@ nmsMap._moveMove = function(e) { nmsMap._c.top.ctx.fillStyle = "red"; nmsMap._drawBox(nmsMap._c.top.ctx, box['x'], box['y'], box['width'], box['height']); nmsMap._c.top.ctx.restore(); -} +}; nmsMap._moveSubmit = function() { var data = { sysname: nmsMap._moving, placement: nmsMap._moveOldBox - } + }; var myData = JSON.stringify([data]); $.ajax({ type: "POST", @@ -440,11 +442,12 @@ nmsMap._moveSubmit = function() { nmsData.invalidate("switches"); } }); -} +}; + nmsMap._moveStopListen = function() { nmsMap._c.input.c.removeEventListener('mousemove',nmsMap._moveMove, true); nmsMap._c.input.c.removeEventListener('mouseup',nmsMap._moveDone, true); -} +}; nmsMap._moveDone = function(e) { nmsMap._moveStopListen(); @@ -453,7 +456,7 @@ nmsMap._moveDone = function(e) { } nmsMap._moveSubmit(); nmsMap._clearOld(nmsMap._moveOldBox); -} +}; nmsMap._moveStart = function(sw, e) { @@ -464,7 +467,7 @@ nmsMap._moveStart = function(sw, e) nmsMap._moveBox = nmsData.switches.switches[sw].placement; nmsMap._c.input.c.addEventListener('mousemove',nmsMap._moveMove,true); nmsMap._c.input.c.addEventListener('mouseup',nmsMap._moveDone,true); -} +}; /* -- cgit v1.2.3 From d528cad67897dd2c3b98ec15a82868ac2764e2c7 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Mon, 21 Mar 2016 20:26:58 +0100 Subject: NMS: Tweak search highlight and hotkeys --- web/nms.gathering.org/js/nms-map.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index b74626a..11ee142 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -10,7 +10,8 @@ * nmsMap.setSwitchColor(switch,color) * nmsMap.setSwitchInfo(switch,info) * nmsMap.setSwitchHighlight(switch,true/false) - * nmsMap.removeAllSwitchHighlights() + * nmsMap.enableHighlights() + * nmsMap.disableHighlights() */ @@ -47,6 +48,7 @@ var nmsMap = nmsMap || { _color: { }, _highlight: { }, + _highlightActive: false, _c: {} } @@ -76,15 +78,19 @@ nmsMap.setSwitchHighlight = function(sw, highlight) { if(highlight) highlight == true; if (this._highlight[sw] != highlight) { - this._highlight[sw] = highlight; - this._drawSwitch(sw); this.stats.highlightChange++; + this._highlight[sw] = highlight; } + this._drawSwitch(sw); } -nmsMap.removeAllSwitchHighlights = function() { - for(var sw in this._highlight) - this.setSwitchHighlight(sw,false); +nmsMap.enableHighlights = function() { + this._highlightActive = true; +} + +nmsMap.disableHighlights = function() { + this._highlightActive = false; + this._drawAllSwitches(); } nmsMap.reset = function() { @@ -247,8 +253,12 @@ nmsMap._drawSwitch = function(sw) return; var box = this._getBox(sw); var color = nmsMap._color[sw]; - if(nmsMap._highlight[sw]) { - color = red; + if(this._highlightActive) { + if(nmsMap._highlight[sw]) { + color = green; + } else { + color = white; + } } if (color == undefined) { color = blue; -- cgit v1.2.3 From e3a11ccb7f67d036c1556f51efc509ee8038ca8a Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 13:18:52 +0100 Subject: NMS: Implement read/write separation in frontend --- web/nms.gathering.org/js/nms-map.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index ffedcbf..d595c4a 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -449,7 +449,7 @@ nmsMap._moveSubmit = function() { var myData = JSON.stringify([data]); $.ajax({ type: "POST", - url: "/api/private/switch-update", + url: "/api/write/switch-update", dataType: "text", data:myData, success: function (data, textStatus, jqXHR) { -- cgit v1.2.3 From 05fedaa7461c6fd67c402671f0e129b3d1772fbf Mon Sep 17 00:00:00 2001 From: Kristian Lyngstol Date: Tue, 22 Mar 2016 19:53:30 +0100 Subject: NMS: Tweak NMS public API and draw linknets --- web/nms.gathering.org/js/nms-map.js | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index d595c4a..1f4d6b7 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -47,6 +47,7 @@ var nmsMap = nmsMap || { }, _color: { }, + _linknets: {} , _highlight: { }, _highlightActive: false, _c: {} @@ -157,6 +158,7 @@ nmsMap._resizeEvent = function() { nmsMap._blurDrawn = false; nmsMap._drawBG(); nmsMap._drawAllSwitches(); + nmsMap._drawAllLinknets(); nmsMap.drawNow(); nmsMap.stats.resizeEvents++; } @@ -327,6 +329,40 @@ nmsMap._drawText = function(ctx, text, box, align) { ctx.restore(); }; +nmsMap._setLinknetColor = function(l, color1, color2) +{ + var oldcolor1; + var oldcolor2; + try { + oldcolor1 = nmsMap._linknets[l].sysname1; + oldcolor2 = nmsMap._linknets[l].sysname2; + if (oldcolor1 == color1 && oldcolor2 == color2) { + return ; + } + } catch (e) {} + nmsMap._linknets[l] = {}; + nmsMap._linknets[l].sysname1 = color1; + nmsMap._linknets[l].sysname2 = color2; + nmsMap._drawLinknet(l) +} + +nmsMap._drawLinknet = function(l) { + try { + var color1 = blue; + var color2 = blue; + try { + color1 = nmsMap._linknets[l].sysname1; + color2 = nmsMap._linknets[l].sysname2; + } catch(e) { } + nmsMap._connectSwitches(nmsData.switches.linknets[l].sysname1, nmsData.switches.linknets[l].sysname2, color1, color2); + } catch(e) { } +} + +nmsMap._drawAllLinknets = function() { + for (var l in nmsData.switches.linknets) { + nmsMap._drawLinknet(l); + } +} nmsMap._drawAllSwitches = function() { if (nmsData.switches == undefined) { this.stats.earlyDrawAll++; @@ -383,10 +419,12 @@ nmsMap._connectBoxes = function(box1, box2,color1, color2) { gradient.addColorStop(0, color1); gradient.addColorStop(1, color2); ctx.strokeStyle = gradient; + ctx.beginPath(); ctx.moveTo(x0,y0); ctx.lineTo(x1,y1); ctx.lineWidth = 5; ctx.stroke(); + ctx.closePath(); ctx.restore(); }; -- cgit v1.2.3 From c70e294a0425a7d417bcf41677a55970e9e59489 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 20:34:56 +0100 Subject: NMS: Make sure switch redraw also redraws infotext --- web/nms.gathering.org/js/nms-map.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index d595c4a..33c98b7 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -273,6 +273,9 @@ nmsMap._drawSwitch = function(sw) this._drawBox(this._c.switch.ctx, box['x'],box['y'],box['width'],box['height']); this._c.switch.ctx.shadowBlur = 0; this._drawText(this._c.text.ctx, sw,box); + + if(this._info[sw]) + this._drawSwitchInfo(sw); }; nmsMap._drawSwitchInfo = function(sw) { -- cgit v1.2.3 From 047b729a1e92446a1c5ce68f806b932b79c98642 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Tue, 22 Mar 2016 21:00:57 +0100 Subject: NMS: Hide infobox when clicking empty canvas area --- web/nms.gathering.org/js/nms-map.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index 33c98b7..7cbf274 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -413,6 +413,8 @@ nmsMap.canvasClick = function(e) } else { nmsInfoBox.click(sw); } + } else { + nmsInfoBox.hide(); } }; -- cgit v1.2.3 From 14dbbc1451b4d5ea99e1937020e4fc79fe7ba1a7 Mon Sep 17 00:00:00 2001 From: Nicolai Tellefsen Date: Fri, 25 Mar 2016 07:56:24 +0100 Subject: NMS: Temporary map time adjustment Convert now-time from nmsData before displaying it in nmsMap in order to go from UTC to local time and a cleaner output format. --- web/nms.gathering.org/js/nms-map.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'web/nms.gathering.org/js/nms-map.js') diff --git a/web/nms.gathering.org/js/nms-map.js b/web/nms.gathering.org/js/nms-map.js index ada6886..c64a387 100644 --- a/web/nms.gathering.org/js/nms-map.js +++ b/web/nms.gathering.org/js/nms-map.js @@ -172,10 +172,16 @@ nmsMap._resizeEvent = function() { * * FIXME: 2: Should really just use _drawText() instead somehow. Font size * being an issue. + * + * FIXME 3: Currently assuming that time from api is UTC and converting to + * local time zone with js. Should find a more robust solution. + * */ nmsMap.drawNow = function () { var now = nmsData.now; + now = new Date(nmsData.now); //Date assumes UTC + now = now.toString().split(' ').splice(1,4).join(' '); //Date returns local time if (nmsMap._lastNow == now) { nmsMap.stats.nowDups++; return; -- cgit v1.2.3