2 <html xmlns:ng="http://angularjs.org">
3 <script src="http://code.angularjs.org/angular-0.9.12.min.js" ng:autobind></script>
6 function user($xhr,$resource,$log) {
10 CRM_search: $resource('/g/CRM_search/:username', {username:'@search_username'}),
12 self.CRM_search = function(username) {
13 if ( ! username ) username = self.search_username;
14 $log.info( 'CRM_search', username );
15 self.r.CRM_search.query({username: username}, function(CRM) {
17 $log.info( 'CRM', CRM )
21 this.clear = function() {
24 self.selected_username = null;
41 'Davolink': [ 'Max_down', 'Max_up' ],
42 // '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' ],
46 this.keys = function(h) {
47 if ( angular.isArray(h) ) h = h[0];
49 for(i in h) if (h.hasOwnProperty(i))
56 this.select = function(crm) {
57 console.log( 'crm = ',crm );
58 self.selected_username = crm.USERNAME;
61 , '/g/LDAP_search/' + self.selected_username + '?callback=JSON_CALLBACK'
62 , function(code, response) {
63 console.debug( code, response );
64 if ( ! response[0] ) {
65 self.message = 'no user ' + self.selected_username + ' in LDAP';
69 self._cpe_parser = response[0]._cpe_parser;
70 self.username = response[0].cn;
72 parser: self._cpe_parser,
73 table: 'cpe_' + self._cpe_parser,
76 $xhr('JSON', '/table/' + self.cpe.table + '?username='+self.username+';callback=JSON_CALLBACK', function( code, table ) {
77 console.debug( self.cpe.table, code, table );
78 self.cpe.rows = table.rows;
79 self.message = 'loaded cpe_'+self.cpe.parser+' rows';
81 self.message = 'loading cpe_'+self.cpe.parser+' rows...';
83 if ( h_cols = self.cpe_hash[self.cpe.parser] ) {
84 var cols = [ 'timestamp' ];
85 for ( var i = 0; i < h_cols.length; i++ ) {
86 cols.push( 'h->\'' + h_cols[i] + '\' as "' + h_cols[i] + '"' );
88 console.debug( cols );
89 self.gnuplot.sql = 'select ' + cols.join(',') + ' from cpe_' + self.cpe.parser + ' where username = \'' + self.username + '\' order by timestamp desc limit 100';
91 console.info( 'gnuplot', self.gnuplot );
92 self.message = 'generating ADSL graph for '+self.username;
93 self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql;
95 self.message = 'no graph defined for ' + self.cpe.parser;
100 self.message = 'LDAP search for '+self.selected_username;
105 user.$inject = ['$xhr','$resource','$log'];
108 <style type="text/css">
130 border-collapse:collapse;
134 border-bottom: 2px solid gray;
138 border-left: 1em solid white;
139 border-right: 1em solid white;
156 <div ng:controller="user">
158 <form ng:submit="CRM_search()">
159 <label for="args">username:
160 <input type="text" name="search_username" placeholder="test" size="10" ng:required />
162 <input type="submit" value="search in CRM">
163 <input type="reset" ng:click="clear()" value="clear">
165 <span id="message" ng:show="message">{{message | html}}</span>
169 <div id="columns" ng:show="CRM">
170 <span>Add columns</span>
172 <li ng:repeat="c in keys(CRM)" ng:show="columns.indexOf(c) < 0" ng:click="columns.push(c)">{{c}}
176 <table ng:show="CRM">
178 <th ng:repeat="c in columns" ng:click="columns.$remove(c)">{{c}}</th>
180 <tr ng:repeat="u in CRM" ng:click="select(u)" ng:class-even="'zebra'">
181 <td ng:repeat="c in columns" ng:show="! selected_username || selected_username == u.USERNAME">{{u[c]}}</td>
185 <input type=button value="Show ALL results, not just {{selected_username}}" ng:click="selected_username=''" ng:show="selected_username">
187 <div ng:show="selected_username">
189 <h2><tt>{{selected_username}}</tt> LDAP entry</h2>
192 <li ng:repeat="c in keys(ldap)"><tt>{{c}}</tt> {{ldap[0][c]}}</li>
195 <div ng:show="cpe.rows">
196 <h2>{{cpe.table}} {{username}}</h2>
197 <pre>{{cpe.rows[0]}}</pre>
200 <ng:include src="gnuplot.img" ng:show="gnuplot.img" onload="message = 'done'">
204 <input type=checkbox name=debug value=1>