diff options
Diffstat (limited to 'web')
| -rw-r--r-- | web/nms.gathering.org/index.html | 6 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms-color-util.js | 1 | ||||
| -rw-r--r-- | web/nms.gathering.org/js/nms.js | 146 | 
3 files changed, 87 insertions, 66 deletions
| diff --git a/web/nms.gathering.org/index.html b/web/nms.gathering.org/index.html index 4cece1a..8e9a49a 100644 --- a/web/nms.gathering.org/index.html +++ b/web/nms.gathering.org/index.html @@ -66,7 +66,7 @@  		<li><a href="#disco" onclick="setUpdater(handler_disco)">DISCO</a></li>  		<li class="divider"> </li>  		<li><a href="#" onclick="toggleLayer('nowPickerBox');startNowPicker();">Travel in time</a></li> -		<li><a href="#" onclick="startReplay();" title="Replay from opening 120 minutes per second">Replay TG</a></li> +		<li><a href="#" onclick="nms.playback.startReplay('2015-04-01T09:00:00','2015-04-05T12:00:00');" title="Replay from opening 120 minutes per second">Replay TG</a></li>  		<li class="divider"> </li>  		<li class="dropdown-header">View</li>  		<li><a href="#" onclick="toggleNightMode()">Toggle Night Mode</a></li> @@ -305,8 +305,8 @@              <div class="form-group">                <input type="text" class="form-control" placeholder="YYYY-MM-DDThh:mm:ss" id="nowPicker">                <div class="button-group"> -                <button class="btn btn-primary" onclick="changeNow(document.getElementById('nowPicker').dataset.iso,false);">Travel</button> -                <button class="btn btn-danger" onclick="startNowPicker(Date.now());changeNow(false,true);">Back to reality</button> +                <button class="btn btn-primary" onclick="nms.playback.setNow(document.getElementById('nowPicker').dataset.iso,false);hideLayer('nowPickerBox');">Travel</button> +                <button class="btn btn-danger" onclick="startNowPicker(Date.now());nms.playback.setNow(false,true);">Back to reality</button>                  <button class="btn btn-info" data-toggle="button" onclick="toggleLayer('nowPickerInfo');">Info</button>                </div>              </div> diff --git a/web/nms.gathering.org/js/nms-color-util.js b/web/nms.gathering.org/js/nms-color-util.js index 72d6f61..965a10e 100644 --- a/web/nms.gathering.org/js/nms-color-util.js +++ b/web/nms.gathering.org/js/nms-color-util.js @@ -14,6 +14,7 @@ var green = "#5cb85c";  var teal = "#5bc0de"; // Or whatever the hell that is  var orange = "#f0ad4e";  var red = "#d9534f"; +var white = "#ffffff";  function gradient_from_latency(latency_ms, latency_secondary_ms)  { diff --git a/web/nms.gathering.org/js/nms.js b/web/nms.gathering.org/js/nms.js index 0aba266..1405b7c 100644 --- a/web/nms.gathering.org/js/nms.js +++ b/web/nms.gathering.org/js/nms.js @@ -84,7 +84,16 @@ var nms = {  		'p':moveTimeFromKey,  		'r':moveTimeFromKey,  		'not-default':keyDebug -	} +	}, +  /* +   * Playback controllers and variables +   */ +  playback:{ +    startTime: undefined, +    stopTime: undefined, +    replayTime: 0, +    replayIncrement: 60 * 60 +  }  };  /* @@ -171,21 +180,6 @@ var margin = {  };  /* - * All of these should be moved into nms.* - * - * tgStart/tgEnd are "constants". - * replayTime is the current time as far as the replay-function is. This - * should be merged with nms.now. - * - * replayIncrement is how many seconds to add for each replay timer tick - * (e.g.: 30 minutes added for every 1 second display-time). - */ -var tgStart = stringToEpoch('2015-04-01T09:00:00'); -var tgEnd = stringToEpoch('2015-04-05T12:00:00'); -var replayTime = 0; -var replayIncrement = 60 * 60; - -/*   * Convenience-function to populate the 'dr' structure.   *   * Only run once. @@ -307,76 +301,89 @@ function epochToString(t)  }  /* - * Move 'nms.now' forward in time, unless we're at the end of the event. + * Move 'nms.now' forward in time, unless we're are after stopTime.   *   * This is run on a timer (nms.timers.replay) every second when we are   * replaying.   */  function timeReplay()  { -	replayTime = stringToEpoch(nms.now); -	if (replayTime >= tgEnd) { +	nms.playback.replayTime = stringToEpoch(nms.now); +	if (nms.playback.replayTime >= nms.playback.stopTime) {  		nms.timers.replay.stop();  		return;  	} -	replayTime = parseInt(replayTime) + parseInt(replayIncrement); -	nms.now = epochToString(replayTime); +	nms.playback.replayTime = parseInt(nms.playback.replayTime) + parseInt(nms.playback.replayIncrement); +	nms.now = epochToString(nms.playback.replayTime);  	updatePorts();  	updatePing();  }  /* - * Start replaying the event. + * Start replaying historical data.   * - * I want this to be more generic: - *  - Set time - *  - Set end-time - *  - Start/stop/pause - *  - Set speed increment + * Todo: + * Currently playback of historical data is handled separately from normal + * playback. I recon we can simplify and combine both in generic play, pause, + * jump, etc. methods that can easily be controlled from the UI-side. + * + * To do this we could remove the separate replay timer, and implement basic stopTime + * checks to the other playback functions.   * - * Once the lib supports this, I can move 'tgStart' and 'tgEnd' to the GUI - * and just provide them as default values or templates.   */ -function startReplay() { -	nms.timers.replay.stop(); -	resetColors(); -	nms.now = epochToString(tgStart); -	timeReplay(); -	nms.timers.replay.start();; -	nms.timers.ping.stop();; -	nms.timers.ports.stop();; -} +nms.playback.startReplay = function(startTime,stopTime) { +  if(!startTime || !stopTime) +    return false; +  nms.timers.replay.stop(); +  nms.playback.startTime = stringToEpoch(startTime); +  nms.playback.stopTime = stringToEpoch(stopTime); +  resetColors(); +  nms.now = epochToString(nms.playback.startTime); +  timeReplay(); +  nms.timers.replay.start(); +  nms.timers.ping.stop(); +  nms.timers.ports.stop(); +} +/* + * Pause playback + */ +nms.playback.pause = function() { +  nms.timers.replay.stop(); +  nms.timers.ping.stop(); +  nms.timers.ports.stop(); +}  /* - * Used to move to a specific time + * Start playback   */ -function changeNow(newnow,playing) { -	if (newnow == "") -		newnow = false; +nms.playback.play = function() { +  nms.timers.ping.start(); +  nms.timers.ports.start(); +} +/* + * Jump to place in time + */ +nms.playback.setNow = function(now,playing) { +  nms.playback.pause(); + +  if (now == "") +    now = false;    if (playing == "")      playing = false; -  if(newnow)  -    newnow = parseNow(newnow); -	 -  nms.timers.replay.stop(); -	nms.now = newnow; -	resetColors(); +  if(now)  +    now = parseNow(now); -	if (!playing) { -		nms.timers.ping.stop(); -		nms.timers.ports.stop(); -	} else { -    nms.timers.ping.start(); -    nms.timers.ports.start(); +  resetSwitchStates(); +  nms.now = now; +  nms.updater.updater(); + +  if (playing) { +    nms.playback.play();    } -	updatePorts(); -	updatePing(); -	var boxHide = document.getElementById("nowPickerBox"); -	if (boxHide) { -		boxHide.style.display = "none"; -	} +  updatePorts(); +  updatePing();  }  function stepTime(n) @@ -701,10 +708,23 @@ function updateSwitches(switchdata,target) {   * while the current state of the switch data is unknown.   */  function updateSwitchProperty(sw,property,data,target) { -	if(target.switches[sw] == undefined) -		target.switches[sw] = {}; +  if(target.switches[sw] == undefined) +    target.switches[sw] = {}; + +  target.switches[sw][property] = data; +} -	target.switches[sw][property] = data; +/* + * Helper function for reseting switch state data (and keeping more permanent data) + */ +function resetSwitchStates() { +  for (var sw in nms.switches_now.switches) { +    for (var property in nms.switches_now.switches[sw]) { +      if (['ports','temp','temp_time'].indexOf(property) > -1) { +        nms.switches_now.switches[sw][property] = undefined; +      } +    } +  }  }  /* | 
