2 <html xmlns:ng="http://angularjs.org">
3 <script src="http://code.angularjs.org/angular-0.9.12.min.js" ng:autobind></script>
9 this.fetch = function() {
12 self.message = 'Enter part of username to search';
15 self.url = '/g/' + self.function_name + '/' + self.args + '?callback=JSON_CALLBACK';
16 $xhr('JSON', self.url, function(code, response) {
18 self.response = response;
19 self.message = response.length + ' results for <tt>'+self.args+'</tt>';
21 self.message = 'loading '+self.url;
24 this.clear = function() {
28 self.selected_username = null;
45 'Davolink': [ 'Max_down', 'Max_up' ],
46 // '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' ],
50 this.keys = function(h) {
51 if ( angular.isArray(h) ) h = h[0];
53 for(i in h) if (h.hasOwnProperty(i))
60 this.select = function(crm) {
61 console.log( 'crm = ',crm );
62 self.selected_username = crm.USERNAME;
65 , '/g/LDAP_search/' + self.selected_username + '?callback=JSON_CALLBACK'
66 , function(code, response) {
67 console.debug( code, response );
68 if ( ! response[0] ) {
69 self.message = 'no user ' + self.selected_username + ' in LDAP';
73 self._cpe_parser = response[0]._cpe_parser;
74 self.username = response[0].cn;
76 parser: self._cpe_parser,
77 table: 'cpe_' + self._cpe_parser,
80 $xhr('JSON', '/table/' + self.cpe.table + '?username='+self.username+';callback=JSON_CALLBACK', function( code, table ) {
81 self.cpe.rows = table.rows;
82 self.message = 'loaded cpe_'+self.cpe.parser+' rows';
84 self.message = 'loading cpe_'+self.cpe.parser+' rows...';
86 if ( h_cols = self.cpe_hash[self.cpe.parser] ) {
87 var cols = [ 'timestamp' ];
88 for ( var i = 0; i < h_cols.length; i++ ) {
89 cols.push( 'h->\'' + h_cols[i] + '\' as "' + h_cols[i] + '"' );
91 console.debug( cols );
92 self.gnuplot.sql = 'select ' + cols.join(',') + ' from cpe_' + self.cpe.parser + ' where username = \'' + self.username + '\' order by timestamp desc limit 100';
94 console.info( 'gnuplot', self.gnuplot );
95 self.message = 'generating ADSL graph for '+self.username;
96 self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql;
98 self.message = 'no graph defined for ' + self.cpe.parser;
103 self.message = 'LDAP search for '+self.selected_username;
108 CRM.$inject = ['$xhr'];
111 <style type="text/css">
133 border-collapse:collapse;
137 border-bottom: 2px solid gray;
141 border-left: 1em solid white;
142 border-right: 1em solid white;
159 <div ng:controller="CRM">
161 <form ng:submit="fetch()">
162 <input type="hidden" name="function_name" value="CRM_search" size="20"/>
163 <label for="args">CRM username:
164 <input type="text" name="args" placeholder="test" size="10"/>
166 <input type="submit" ng:click="fetch()" value="search">
167 <input type="reset" ng:click="clear()" value="clear">
169 <span id="message" ng:show="message">{{message | html}}</span>
173 <div id="columns" ng:show="response">
174 <span>Add columns</span>
176 <li ng:repeat="c in keys(response)" ng:show="columns.indexOf(c) < 0" ng:click="columns.push(c)">{{c}}
180 <table ng:show="response">
182 <th ng:repeat="c in columns" ng:click="columns.$remove(c)">{{c}}</th>
184 <tr ng:repeat="u in response" ng:click="select(u)" ng:class-even="'zebra'">
185 <td ng:repeat="c in columns" ng:show="! selected_username || selected_username == u.USERNAME">{{u[c]}}</td>
189 <input type=button value="Show ALL results, not just {{selected_username}}" ng:click="selected_username=''" ng:show="selected_username">
191 <div ng:show="selected_username">
193 <h2><tt>{{selected_username}}</tt> LDAP entry</h2>
196 <li ng:repeat="c in keys(ldap)"><tt>{{c}}</tt> {{ldap[0][c]}}</li>
199 <div ng:show="cpe.rows">
200 <h2>{{cpe.table}} {{username}}</h2>
201 <pre>{{cpe.rows[0]}}</pre>
204 <ng:include src="gnuplot.img" ng:show="gnuplot.img" onload="message = 'done'">
205 <pre ng:show="gnuplot.sql">{{gnuplot.sql}}</pre>
209 <input type=checkbox name=debug value=1>