use persistant worker to query DSLAM
[APKPM.git] / public / user.html
index e8d3f1d..c5062eb 100644 (file)
        };
        self.$watch('selected_username', self.LDAP_search );
 
-       self.gnuplot_draw = function(h_cols) {
-               $log.info( 'gnuplot_draw', h_cols );
-               if (h_cols.length) {
-                       self.gnuplot.cols = h_cols;
-               } else {
+       self.gnuplot_changed = function() {
+               var h_cols = self.gnuplot.cols;
+               $log.info( 'gnuplot_changed', h_cols );
+               if ( ! h_cols || h_cols.length < 1) {
                        $log.warn("no columns for gnuplot");
                        return;
                }
 
-               self.message.gnuplot = 'redrawing '+h_cols.join(' ');
-
                var cols = [ 'timestamp' ];
                for ( var i = 0; i < h_cols.length; i++ ) {
                        cols.push( 'h->\'' + h_cols[i] + '\' as "' + h_cols[i] + '"' );
                }
-console.debug( cols );
                self.gnuplot.sql = 'select ' + cols.join(',') + ' from cpe_' + self.cpe.parser + ' where username = \'' + self.username + '\' order by timestamp desc limit 100';
+               $log.info( 'gnuplot', cols, self.gnuplot );
+       };
+       self.gnuplot_refresh = function() {
+               if ( ! self.gnuplot || ! self.gnuplot.cols || ! self.gnuplot.sql) return;
+               self.message.gnuplot = self.gnuplot.cols.join(' ');
+               self.gnuplot.img = '/gnuplot?hide=1;with='+self.gnuplot.with+';sql=' + self.gnuplot.sql;
+               $log.info('gnuplot_refresh', self.gnuplot.img);
+       };
+       self.$watch('gnuplot.sql', self.gnuplot_refresh );
+       self.$watch('gnuplot.with', self.gnuplot_refresh );
 
-               $log.info( 'gnuplot', self.gnuplot );
-               self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql;
-
+       self.gnuplot_onload = function() {
+               $log.info( 'gnuplot_onload' );
+               self.message.gnuplot = '<a href="#gnuplot">ready</a>';
        };
 
        self.r.table = $resource('/table/:table');
@@ -112,7 +118,8 @@ console.debug( cols );
                        }
 
                        if ( h_cols = self.cpe_hash[self.cpe.parser] ) {
-                               self.gnuplot_draw( h_cols );
+                               self.gnuplot.cols = h_cols;
+                               self.gnuplot_changed();
                        } else {
                                self.message.gnuplot = 'no graph for ' + self.cpe.parser;
                        }
@@ -130,7 +137,7 @@ console.debug( cols );
                $log.info('clear_LDAP');
                self.LDAP = null;
                self.selected_username = null;
-               self.gnuplot = {};
+               self.gnuplot = { 'with': 'points', cols: [] };
                self.cpe = {};
                self.cpe_limit = 1;
        };
@@ -291,25 +298,6 @@ li > tt {
      ping <tt>{{cpe.ping.ip}}</tt> rtt <tt>{{cpe.ping.rtt}}</tt> at <tt>{{cpe.ping.timestamp}}</tt>
     </div>
 
-   <div class="panel_right" ng:show="cpe.table">
-    <label>
-     Graph columns
-     <input type=checkbox name=show_gnuplot_cols>
-    </label>
-    <ul ng:show="show_gnuplot_cols">
-     <input type=button ng:click="gnuplot_draw(gnuplot.cols)" value="Redraw graph">
-     <li ng:repeat="(k,v) in cpe.table.rows[0][cpe.table.hash_col]">
-        <label>
-        <input type="checkbox" name="gnuplot_cols" ng:format="include:k:gnuplot.cols" ng:change="$log.debug(gnuplot_cols)">
-       {{k}} <tt>{{v}}</tt>
-        </label>
-     </li>
-     <input type=button ng:click="gnuplot_draw(gnuplot.cols)" value="Redraw graph">
-    </ul>
-   </div>
-
-    <ng:include src="gnuplot.img" ng:show="gnuplot.img" onload="message.gnuplot = null" ></ng:include>
-
     <h2 ng:show="cpe.table_name">{{cpe.table_name}} {{username}}</h2>
 
     <table ng:show="cpe.table">
@@ -331,6 +319,29 @@ li > tt {
     </tr>
     </table>
 
+    <div class="panel_right" ng:show="cpe.table">
+     <label>
+      Graph columns
+      <input type=checkbox name=show_gnuplot_cols>
+     </label>
+
+     <ul ng:show="show_gnuplot_cols">
+      with <select name="gnuplot.with">
+       <option ng:repeat="with in ['points','dots','steps','lines']">{{with}}</option>
+      </select>
+
+      <li ng:repeat="(k,v) in cpe.table.rows[0][cpe.table.hash_col]">
+         <label>
+         <input type="checkbox" name="checked_cols" ng:format="include:k:gnuplot.cols" ng:click="gnuplot_changed()">
+       {{k}} <tt>{{v}}</tt>
+         </label>
+      </li>
+     </ul>
+    </div>
+
+    <a name="gnuplot"> 
+    <ng:include src="gnuplot.img" ng:show="gnuplot.img" onload="message.gnuplot = gnuplot_onload" ></ng:include>
+
   </div>
 
     <input type=checkbox name=debug value=1>