diff --git a/webgui/main.js b/webgui/main.js index 8c9fec226..f28857f79 100644 --- a/webgui/main.js +++ b/webgui/main.js @@ -67,22 +67,48 @@ require([ self.initWebsocket(); self.fire = function(json) { - var koObservable = self.listeners[json.path] || null; - if (!koObservable) - return; + var value = json.value; + var listeners = self.listeners[json.path] || []; + listeners.forEach(function(koObservable) { + koObservable(value) + }); koObservable(json.value); } + function resolvePropertyPath(self, pathOrAlias) { + if (pathOrAlias in self.aliases) + return self.aliases[pathOrAlias]; + if (pathOrAlias.charAt(0) == '/') + return pathOrAlias; + return null; + } + self.listeners = {} - self.getListener = function(pathOrAlias) { - if( pathOrAlias in self.listeners ) { - return self.listeners[pathOrAlias]; + self.removeListener = function(pathOrAlias, koObservable) { + var path = resolvePropertyPath(self, pathOrAlias); + if (path == null) { + console.log("can't remove listener for " + pathOrAlias + ": unknown alias or invalid path."); + return self; } - } - self.removeListener = function(pathOrAlias) { + var listeners = self.listeners[path] || []; + var idx = listeners.indexOf(koObservable); + if (idx == -1) { + console.log("can't remove listener for " + path + ": not a listener."); + return self; + } + listeners.splice(idx, 1); + + if (0 == listeners.length) { + self.ws.send(JSON.stringify({ + command : 'removeListener', + node : path + })); + } + + return self; } self.addListener = function(alias, koObservable) { @@ -92,29 +118,35 @@ require([ "prop" : alias, "koObservable" : koObservable }); - return; + return self; } - var path = this.aliases[alias] || ""; - if (path.length == 0) { - if (alias.charAt(0) == '/') { - path = alias; - } else { - console.log("can't listen to " + alias + ": unknown alias."); - return; - } + var path = resolvePropertyPath(self, alias); + if (path == null) { + console.log("can't listen to " + alias + ": unknown alias or invalid path."); + return self; } - self.listeners[path] = koObservable; + var listeners = self.listeners[path] = (self.listeners[path] || []); + if (listeners.indexOf(koObservable) != -1) { + console.log("won't listen to " + path + ": duplicate."); + return self; + } - self.ws.send(JSON.stringify({ - command : 'addListener', - node : path - })); + listeners.push(koObservable); + + if (1 == listeners.length) { + self.ws.send(JSON.stringify({ + command : 'addListener', + node : path + })); + } self.ws.send(JSON.stringify({ command : 'get', node : path })); + + return self; } self.aliases = aliases || {}; @@ -365,9 +397,9 @@ require([ update : function(element, valueAccessor, allBindings) { var value = valueAccessor() || {}; - var data = ko.unwrap( value.data ); - var options = ko.unwrap( value.options ); - jquery.plot(element, data, options ); + var data = ko.unwrap(value.data); + var options = ko.unwrap(value.options); + jquery.plot(element, data, options); }, diff --git a/webgui/topics/Aircraft.js b/webgui/topics/Aircraft.js index ee3122fd4..c78893c9f 100644 --- a/webgui/topics/Aircraft.js +++ b/webgui/topics/Aircraft.js @@ -17,6 +17,10 @@ define([ require : 'topics/Aircraft/Help' }); + ko.components.register('Aircraft/Panel', { + require : 'topics/Aircraft/Panel' + }); + function ViewModel(params) { var self = this; diff --git a/webgui/topics/Aircraft/Help.html b/webgui/topics/Aircraft/Help.html index fc790f896..828b17536 100644 --- a/webgui/topics/Aircraft/Help.html +++ b/webgui/topics/Aircraft/Help.html @@ -1,6 +1,10 @@ +
+
+
+
diff --git a/webgui/topics/Aircraft/Help.js b/webgui/topics/Aircraft/Help.js index 30a634931..2304e7cde 100644 --- a/webgui/topics/Aircraft/Help.js +++ b/webgui/topics/Aircraft/Help.js @@ -6,6 +6,16 @@ define([ self.helpTitle = ko.observable(""); self.helpContent = ko.observableArray([]); + self.description = ko.observable(''); + self.longDescription = ko.observable(''); + + jquery.get('/json/sim/description', null, function(data) { + self.description(data.value); + }); + + jquery.get('/json/sim/long-description', null, function(data) { + self.longDescription(data.value); + }); jquery.get('/json/sim/help?d=2', null, function(data) { diff --git a/webgui/topics/Simulator/Properties.js b/webgui/topics/Simulator/Properties.js index d0399d72a..7241d41d0 100644 --- a/webgui/topics/Simulator/Properties.js +++ b/webgui/topics/Simulator/Properties.js @@ -11,8 +11,10 @@ define([ this.samples = []; this.sample = function(timeStamp) { - while (this.samples.length >= this.maxSamples) + console.log(this.samples.length,this.maxSamples); + while (this.samples.length >= this.maxSamples) { this.samples.shift(); + } this.samples.push([ timeStamp, this.source() ]); @@ -42,8 +44,9 @@ define([ } this.removeSource = function(source) { + var s = this.sources[source].source; delete this.sources[source]; - return this; + return s; } this.containsSource = function(source) { @@ -242,19 +245,23 @@ define([ self.toggleProp = function(prop) { if (self.propertySampler.containsSource(prop.path)) { - self.propertySampler.removeSource(prop.path); + var obs = self.propertySampler.removeSource(prop.path); + ko.utils.knockprops.removeListener(prop.path, obs); return; } - var obs = ko.utils.knockprops.getListener(prop.path); - if (obs) { - self.propertySampler.addSource(new SampleSource(prop, obs, { - maxSamples : 1000, - })); - } + var obs = ko.observable(0); + ko.utils.knockprops.addListener(prop.path, obs); + self.propertySampler.addSource(new SampleSource(prop, obs, { + maxSamples : 300, + })); } - self.update = function() { + self.updateId = 0; + self.update = function(id) { + + if (self.updateId != id) + return; var sources = self.propertySampler.sources; var data = []; @@ -265,7 +272,7 @@ define([ data.push({ // color : 'rgb(192, 128, 0)', data : source.samples, - label : key, + label : "hallO", lines : { show : true }, @@ -276,23 +283,24 @@ define([ show : false }, shadowSize : 0, - yaxis: i++, + yaxis : i++, }); } self.flotData(data); setTimeout(function() { - self.update(); + self.update(id); }, 100); } - self.update(); + self.update(++self.updateId); } ViewModel.prototype.dispose = function() { console.log("disposing pal"); this.propertySampler.stop(); + this.updateId++; } // Return component definition