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'}),
11 LDAP_search: $resource('/g/LDAP_search/:username', {username:'@selected_username'}),
13 self.CRM_search = function(username) {
14 if ( ! username ) username = self.search_username;
15 $log.info( 'CRM_search', username );
17 self.r.CRM_search.query({username: username}, function(CRM) {
19 $log.info( 'CRM', CRM )
20 if ( CRM.length == 1 ) {
21 self.selected_username = CRM[0].USERNAME;
22 $log.info( 'auto-selected', self.selected_username );
27 self.LDAP_search = function(username) {
28 if ( ! username ) username = self.selected_username;
30 $log.error( 'no username for LDAP_search' );
33 $log.info( 'LDAP_search', username );
34 self.r.LDAP_search.query({ username: username }, function(LDAP) {
36 $log.info( 'LDAP', LDAP );
37 self.username = LDAP[0].cn;
39 parser: LDAP[0]._cpe_parser,
40 table: 'cpe_' + LDAP[0]._cpe_parser,
44 self.$watch('selected_username', self.LDAP_search );
46 this.clear = function() {
49 self.selected_username = null;
66 'Davolink': [ 'Max_down', 'Max_up' ],
67 // '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' ],
71 this.keys = function(h) {
72 if ( angular.isArray(h) ) h = h[0];
74 for(i in h) if (h.hasOwnProperty(i))
81 this.select = function(crm) {
82 console.log( 'crm = ',crm );
83 self.selected_username = crm.USERNAME;
86 , '/g/LDAP_search/' + self.selected_username + '?callback=JSON_CALLBACK'
87 , function(code, response) {
88 console.debug( code, response );
89 if ( ! response[0] ) {
90 self.message = 'no user ' + self.selected_username + ' in LDAP';
94 self._cpe_parser = response[0]._cpe_parser;
95 self.username = response[0].cn;
97 parser: self._cpe_parser,
98 table: 'cpe_' + self._cpe_parser,
101 $xhr('JSON', '/table/' + self.cpe.table + '?username='+self.username+';callback=JSON_CALLBACK', function( code, table ) {
102 console.debug( self.cpe.table, code, table );
103 self.cpe.rows = table.rows;
104 self.message = 'loaded cpe_'+self.cpe.parser+' rows';
106 self.message = 'loading cpe_'+self.cpe.parser+' rows...';
108 if ( h_cols = self.cpe_hash[self.cpe.parser] ) {
109 var cols = [ 'timestamp' ];
110 for ( var i = 0; i < h_cols.length; i++ ) {
111 cols.push( 'h->\'' + h_cols[i] + '\' as "' + h_cols[i] + '"' );
113 console.debug( cols );
114 self.gnuplot.sql = 'select ' + cols.join(',') + ' from cpe_' + self.cpe.parser + ' where username = \'' + self.username + '\' order by timestamp desc limit 100';
116 console.info( 'gnuplot', self.gnuplot );
117 self.message = 'generating ADSL graph for '+self.username;
118 self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql;
120 self.message = 'no graph defined for ' + self.cpe.parser;
125 self.message = 'LDAP search for '+self.selected_username;
130 user.$inject = ['$xhr','$resource','$log'];
133 <style type="text/css">
155 border-collapse:collapse;
159 border-bottom: 2px solid gray;
163 border-left: 1em solid white;
164 border-right: 1em solid white;
181 <div ng:controller="user">
183 <form ng:submit="CRM_search()">
184 <label for="args">username:
185 <input type="text" name="search_username" placeholder="test" size="10" ng:required />
187 <input type="submit" value="search in CRM">
188 <input type="reset" ng:click="clear()" value="clear">
190 <span id="message" ng:show="message">{{message | html}}</span>
194 <div id="columns" ng:show="CRM">
195 <span>Add columns</span>
197 <li ng:repeat="c in keys(CRM)" ng:show="columns.indexOf(c) < 0" ng:click="columns.push(c)">{{c}}
201 <table ng:show="CRM">
203 <th ng:repeat="c in columns" ng:click="columns.$remove(c)">{{c}}</th>
205 <tr ng:repeat="u in CRM" ng:click="select(u)" ng:class-even="'zebra'">
206 <td ng:repeat="c in columns" ng:show="! selected_username || selected_username == u.USERNAME">{{u[c]}}</td>
210 <input type=button value="Show ALL results, not just {{selected_username}}" ng:click="selected_username=''" ng:show="selected_username">
212 <div ng:show="selected_username">
214 <h2><tt>{{selected_username}}</tt> LDAP entry</h2>
217 <li ng:repeat="c in keys(LDAP)"><tt>{{c}}</tt> {{LDAP[0][c]}}</li>
220 <div ng:show="cpe.rows">
221 <h2>{{cpe.table}} {{username}}</h2>
222 <pre>{{cpe.rows[0]}}</pre>
225 <ng:include src="gnuplot.img" ng:show="gnuplot.img" onload="message = 'done'">
229 <input type=checkbox name=debug value=1>