From: Dobrica Pavlinusic Date: Sat, 9 Jul 2011 19:50:18 +0000 (+0200) Subject: specify just hash names and generate SQL from it X-Git-Url: http://git.rot13.org/?p=APKPM.git;a=commitdiff_plain;h=92c0a1384510c822396225cc8b0a523e23df07f2;hp=1cb01db2f268768f43146bc87ce769b92842c421 specify just hash names and generate SQL from it --- diff --git a/templates/user.html.ep b/templates/user.html.ep index caea7d3..1aa71cf 100644 --- a/templates/user.html.ep +++ b/templates/user.html.ep @@ -39,6 +39,12 @@ 'OPT82' ]; + this.cpe_hash = { + 'Davolink': [ 'Max_down', 'Max_up' ], +// 'Davolink': [ 'select timestamp,h->\'Max_down\' as Max_down,h->\'Max_up\' as Max_up from cpe_Davolink where username = \'', '\' order by timestamp desc limit 100' ], +// 'EasyGateway': + }; + this.keys = function(h) { if ( angular.isArray(h) ) h = h[0]; var keys = []; @@ -57,11 +63,27 @@ , '/g/LDAP_search/' + self.selected_username + '?callback=JSON_CALLBACK' , function(code, response) { console.debug( code, response ); + if ( ! response[0] ) { + self.message = 'no user ' + self.selected_username + ' in LDAP'; + return; + } self.ldap = response; - self.gnuplot.sql = 'select timestamp,h->\'Max_down\' as Max_down,h->\'Max_up\' as Max_up from cpe_Davolink where username = \'' + response[0].cn + '\' order by timestamp desc limit 100'; - self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql; - console.info( 'gnuplot', self.gnuplot ); - self.message = 'generating ADSL graph for '+response[0].cn + ' '; + var parser = response[0]._cpe_parser; + console.info( 'parser', parser ); + if ( h_cols = self.cpe_hash[parser] ) { + 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_' + parser + ' where username = \'' + response[0].cn + '\' order by timestamp desc limit 100'; + + self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql; + console.info( 'gnuplot', self.gnuplot ); + self.message = 'generating ADSL graph for '+response[0].cn + ' '; + } else { + self.message = 'no graph defined for ' + parser; + } } ); self.message = 'LDAP search for '+self.selected_username;