diff options
author | Josh Blum | 2013-03-31 22:31:13 -0700 |
---|---|---|
committer | Josh Blum | 2013-03-31 22:31:13 -0700 |
commit | a6cfe0fc89473d6f39d3376147f1de1658b47c46 (patch) | |
tree | bdf6bbf333607c27456a0e6bb989283e0cad6234 /python/gras | |
parent | 9b96f5791d3cf743ff69be1665f6096bee683e32 (diff) | |
parent | bd00a7db0d10287b2b5d65bb9401b47108b35c10 (diff) | |
download | sandhi-a6cfe0fc89473d6f39d3376147f1de1658b47c46.tar.gz sandhi-a6cfe0fc89473d6f39d3376147f1de1658b47c46.tar.bz2 sandhi-a6cfe0fc89473d6f39d3376147f1de1658b47c46.zip |
Merge branch 'query_work'
Diffstat (limited to 'python/gras')
-rw-r--r-- | python/gras/query/chart_factory.js | 72 | ||||
-rw-r--r-- | python/gras/query/main.css | 4 | ||||
-rw-r--r-- | python/gras/query/main.html | 6 | ||||
-rw-r--r-- | python/gras/query/main.js | 20 |
4 files changed, 57 insertions, 45 deletions
diff --git a/python/gras/query/chart_factory.js b/python/gras/query/chart_factory.js index ae23728..e4382d3 100644 --- a/python/gras/query/chart_factory.js +++ b/python/gras/query/chart_factory.js @@ -81,15 +81,25 @@ function gras_chart_save(registry) { all_args.push(info.args); }); - localStorage.setItem(registry.top_id, JSON.stringify(all_args)); + localStorage.setItem(registry.top_id, JSON.stringify({ + chart_args: all_args, + overall_rate: registry.overall_rate, + overall_active: registry.overall_active, + })); } function gras_chart_load(registry) { if (typeof(Storage) === "undefined") return; - var chart_args = JSON.parse(localStorage.getItem(registry.top_id)); - if (!chart_args) return; - $.each(chart_args, function(args_i, args) + var storage = JSON.parse(localStorage.getItem(registry.top_id)); + if (!storage) return; + + //restore misc settings in storage + registry.overall_rate = storage.overall_rate; + registry.overall_active = storage.overall_active; + + //rebuild all charts from args + $.each(storage.chart_args, function(args_i, args) { //check that the blocks saved in the args actually exist var do_make = true; @@ -188,15 +198,16 @@ function gras_chart_factory_make(registry, args) //set the cursor on the title bar so its obvious tr_title.hover( - function(){$(this).css('cursor','move');}, - function(){$(this).css('cursor','auto');} + function(){$(this).css('cursor','move'); close_div.show();}, + function(){$(this).css('cursor','auto'); close_div.hide();} ); + close_div.hide(); } /*********************************************************************** * chart factory init **********************************************************************/ -function gras_chart_factory_init(registry, done_cb) +function gras_chart_factory_init(registry) { //init registry containers registry.active_charts = new Array(); @@ -217,50 +228,53 @@ function gras_chart_factory_init(registry, done_cb) $('#chart_type_selector').append(option); }); - //init overall config gui element for rate + //init chart overall gui controls var overall_rate = $('#chart_update_rate').attr({size:3}); overall_rate.spinner({ - min: 1, max: 10, stop: function(event, ui){$(this).change();} - }); - overall_rate.val(registry.overall_rate); - overall_rate.change(function() - { - registry.overall_rate = overall_rate.val(); + min: 1, max: 10, step: 0.5, stop: function(event, ui){$(this).change();} }); - - //init overall config gui element for activity - registry.overall_active = true; var overall_active = $('#chart_active_state'); - overall_active.attr('checked', registry.overall_active); - overall_active.change(function() + overall_active.button(); + + //callback for overall gui events + function handle_gui_event() { registry.overall_active = overall_active.is(':checked'); - if (registry.overall_active) gras_query_stats(registry); - else window.clearInterval(registry.timeout_handle); - }); + registry.overall_rate = overall_rate.val(); + gras_chart_save(registry); + } + overall_rate.change(handle_gui_event); + overall_active.change(handle_gui_event); //block registry and checkboxes init $.getJSON('/blocks.json', function(data) { + var container = $('#chart_designer_blocks'); $.each(data.blocks, function(index, id) { registry.block_ids.push(id); - var container = $('#chart_designer_blocks'); + var cb_id = "chart_designer_blocks " + id; var div = $('<div />'); - $(div).append('<label>' + id + '</label>'); + var label = $('<label />').text(id).attr({'for':cb_id}); var input = $('<input />').attr({ type: 'checkbox', - name: id + name: id, + id: cb_id, }); input.attr('checked', false); - $(div).append(input); - $(container).append(div); + div.append(input); + div.append(label); + container.append(div); }); + //container.buttonset(); //try to load last settings try{gras_chart_load(registry);}catch(e){} - //done callback because getJSON was async - done_cb(registry); + //init gui elements after settings restore + overall_rate.val(registry.overall_rate); + overall_active.attr('checked', registry.overall_active); + handle_gui_event(); + gras_query_stats(registry); }); } diff --git a/python/gras/query/main.css b/python/gras/query/main.css index 2665e32..a428111 100644 --- a/python/gras/query/main.css +++ b/python/gras/query/main.css @@ -27,8 +27,8 @@ text-decoration:underline; #chart_designer_blocks input { -margin-right:10px; -margin-left:2px; +margin-right:2px; +margin-left:10px; } #charts_panel diff --git a/python/gras/query/main.html b/python/gras/query/main.html index 04e5a49..b64d53f 100644 --- a/python/gras/query/main.html +++ b/python/gras/query/main.html @@ -34,13 +34,13 @@ <td id="chart_designer_blocks" rowspan='2'></td> <td><select id="chart_type_selector" /></td> <td> - <label for="spinner">Updates/sec:</label> + <label for="chart_update_rate">Updates/sec:</label> <input id="chart_update_rate" type="spinner" /> </td> </tr> <tr> - <td><input type="submit" value="Create New Chart" id="chart_factory_button" /></td> - <td><label>Active?</label><input id="chart_active_state" type="checkbox" name="active" /></td> + <td><input type="button" value="Create New Chart" id="chart_factory_button" /></td> + <td><input id="chart_active_state" type="checkbox" /><label for="chart_active_state">Active</label></td> </tr> </table> </div> diff --git a/python/gras/query/main.js b/python/gras/query/main.js index a9c255b..b17af63 100644 --- a/python/gras/query/main.js +++ b/python/gras/query/main.js @@ -3,7 +3,7 @@ **********************************************************************/ var GrasStatsRegistry = function() { - this.overall_rate = 2.0; + this.overall_rate = 3.0; this.overall_active = true; this.block_ids = new Array(); this.top_id = 'top'; @@ -38,21 +38,19 @@ var gras_query_stats = function(registry) { registry.online = true; gras_handle_offline(registry); - if (registry.overall_active) - { - gras_chart_factory_update(registry, response); + if (registry.overall_active) gras_chart_factory_update(registry, response); - registry.timeout_handle = window.setTimeout(function() - { - gras_query_stats(registry); - }, Math.round(1000/registry.overall_rate)); - } + var timeout = registry.overall_active? Math.round(1000/registry.overall_rate) : 1000; + window.setTimeout(function() + { + gras_query_stats(registry); + }, timeout); }, error: function() { registry.online = false; gras_handle_offline(registry); - registry.timeout_handle = window.setTimeout(function() + window.setTimeout(function() { gras_query_stats(registry); }, 1000); @@ -77,5 +75,5 @@ var gras_stats_main = function() }); //initialize the charts factory - gras_chart_factory_init(registry, gras_query_stats); + gras_chart_factory_init(registry); } |