summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Wall <richard@largo>2010-12-30 17:21:31 +0000
committerRichard Wall <richard@largo>2010-12-30 17:21:31 +0000
commitb3dfd26ce97cd1817f728667a586bf29eace752f (patch)
treeea50c950e44d2c7c4ac85b033a67bc14f8e055ee
parentb3b166f6455b8556b5f14f35f8f755f26d5d87e1 (diff)
display a list of ds names found in the rrd url
-rw-r--r--jarmon/jarmon.js91
-rw-r--r--jarmon/jarmon.test.js2
2 files changed, 73 insertions, 20 deletions
diff --git a/jarmon/jarmon.js b/jarmon/jarmon.js
index 6e1d1f8..c25210d 100644
--- a/jarmon/jarmon.js
+++ b/jarmon/jarmon.js
@@ -256,6 +256,18 @@ jarmon.RrdQuery.prototype.getData = function(startTimeJs, endTimeJs, dsId, cfNam
'lastUpdated': lastUpdated*1000.0};
};
+
+jarmon.RrdQuery.prototype.getDSNames = function() {
+ /**
+ * Return a list of RRD Data Source names
+ *
+ * @method getDSNames
+ * @return {Array} An array of DS names.
+ **/
+ return this.rrd.getDSNames();
+};
+
+
/**
* A wrapper around RrdQuery which provides asynchronous access to the data in a
* remote RRD file.
@@ -332,6 +344,18 @@ jarmon.RrdQueryRemote.prototype.getData = function(startTime, endTime, dsId, cfN
return this._callRemote('getData', [startTime, endTime, dsId, cfName]);
};
+
+jarmon.RrdQueryRemote.prototype.getDSNames = function() {
+ /**
+ * Return a list of RRD Data Source names
+ *
+ * @method getDSNames
+ * @return {Object} A Deferred which calls back with an array of DS names.
+ **/
+ return this._callRemote('getDSNames');
+};
+
+
/**
* Wraps RrdQueryRemote to provide access to a different RRD DSs within a
* single RrdDataSource.
@@ -668,31 +692,60 @@ jarmon.Chart.fromRecipe = function(recipes, templateFactory, downloader) {
**/
jarmon.ChartConfig = function($tpl) {
this.$tpl = $tpl;
+ this.rrdUrl = '';
+ this.dsNames = [];
+ this.errors = [];
};
jarmon.ChartConfig.prototype.draw = function() {
- $('<form/>').append(
- $('<div/>').append(
- $('<label/>').append(
- ['URL', ': '].join(''),
- $('<input/>', {name: 'rrd_url'})
- )
- ),
- $('<div/>').append(
- $('<input/>', {type: 'submit', value: 'submit'})
+ var self = this;
+ this.$tpl.empty();
+
+ $(this.errors).map(function(i, el) {
+ return $('<p/>').text(el.toString());
+ }).appendTo(this.$tpl);
+
+ var $f = $('<form/>')
+ $('<div/>').append(
+ $('<label/>').append(
+ ['URL', ': '].join(''),
+ $('<input/>', {name: 'rrd_url', value: this.rrdUrl})
+ )
+ ).appendTo($f);
+
+ $(this.dsNames).map(function(i, el) {
+ return $('<label/>').append(
+ [el, ': '].join(''),
+ $('<input/>', {
+ type: 'checkbox',
+ name: 'rrd_ds',
+ value: el
+ })
)
- ).submit(
+ }).appendTo($f);
+
+ $('<div/>').append(
+ $('<input/>', {type: 'submit', value: 'submit'})
+ ).appendTo($f);
+
+ $f.submit(
function(e) {
- var d = new jarmon.RrdQueryRemote(this['rrd_url'])
- $(this).append(
- $('<div/>').append(
- $('<label/>').append(
- ['DS', ': '].join(''),
- $('<input/>', {name: 'rrd_ds'})
- )
- )
+ self.rrdUrl = this['rrd_url'].value;
+ self.$tpl.empty();
+ self.dsNames = [];
+ self.errors = [];
+ new jarmon.RrdQueryRemote(self.rrdUrl).getDSNames().addCallbacks(
+ function(dsNames) {
+ self.dsNames = dsNames;
+ },
+ function(err) {
+ self.errors.push(err);
+ }
+ ).addBoth(
+ function() {
+ self.draw();
+ }
);
-
return false;
}
).appendTo(this.$tpl);
diff --git a/jarmon/jarmon.test.js b/jarmon/jarmon.test.js
index 2b4465d..7f34391 100644
--- a/jarmon/jarmon.test.js
+++ b/jarmon/jarmon.test.js
@@ -280,7 +280,7 @@ YUI({ logInclude: { TestRunner: true } }).use('console', 'test', function(Y) {
name: "jarmon.RrdQueryRemote",
setUp: function() {
- this.rq = new jarmon.RrdQueryRemote('build/test.rrd', '')
+ this.rq = new jarmon.RrdQueryRemote('build/test.rrd', '');
},
test_getDataTimeRangeOverlapError: function () {