7 this.fetch = function() {
10 self.message = 'Enter part of username to search';
13 self.url = '/g/' + self.function_name + '/' + self.args + '?callback=JSON_CALLBACK';
14 $xhr('JSON', self.url, function(code, response) {
16 self.response = response;
17 self.message = response.length + ' results for <tt>'+self.args+'</tt>';
19 self.message = 'loading '+self.url;
22 this.clear = function() {
26 self.selected_username = null;
43 'Davolink': [ 'Max_down', 'Max_up' ],
44 // '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' ],
48 this.keys = function(h) {
49 if ( angular.isArray(h) ) h = h[0];
51 for(i in h) if (h.hasOwnProperty(i))
58 this.select = function(crm) {
59 console.log( 'crm = ',crm );
60 self.selected_username = crm.USERNAME;
63 , '/g/LDAP_search/' + self.selected_username + '?callback=JSON_CALLBACK'
64 , function(code, response) {
65 console.debug( code, response );
66 if ( ! response[0] ) {
67 self.message = 'no user ' + self.selected_username + ' in LDAP';
71 self._cpe_parser = response[0]._cpe_parser;
72 self.username = response[0].cn;
74 parser: self._cpe_parser,
75 table: 'cpe_' + self._cpe_parser,
78 $xhr('JSON', '/table/' + self.cpe.table + '?username='+self.username+';callback=JSON_CALLBACK', function( code, table ) {
79 self.cpe.rows = table.rows;
80 self.message = 'loaded cpe_'+self.cpe.parser+' rows';
82 self.message = 'loading cpe_'+self.cpe.parser+' rows...';
84 if ( h_cols = self.cpe_hash[self.cpe.parser] ) {
85 var cols = [ 'timestamp' ];
86 for ( var i = 0; i < h_cols.length; i++ ) {
87 cols.push( 'h->\'' + h_cols[i] + '\' as "' + h_cols[i] + '"' );
89 console.debug( cols );
90 self.gnuplot.sql = 'select ' + cols.join(',') + ' from cpe_' + self.cpe.parser + ' where username = \'' + self.username + '\' order by timestamp desc limit 100';
92 console.info( 'gnuplot', self.gnuplot );
93 self.message = 'generating ADSL graph for '+self.username;
94 self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql;
96 self.message = 'no graph defined for ' + self.cpe.parser;
101 self.message = 'LDAP search for '+self.selected_username;
106 CRM.$inject = ['$xhr'];
109 <style type="text/css">
131 border-collapse:collapse;
135 border-bottom: 2px solid gray;
139 border-left: 1em solid white;
140 border-right: 1em solid white;
157 <div ng:controller="CRM">
159 <form ng:submit="fetch()">
160 <input type="hidden" name="function_name" value="CRM_search" size="20"/>
161 <label for="args">CRM username:
162 <input type="text" name="args" placeholder="test" size="10"/>
164 <input type="submit" ng:click="fetch()" value="search">
165 <input type="reset" ng:click="clear()" value="clear">
167 <span id="message" ng:show="message">{{message | html}}</span>
171 <div id="columns" ng:show="response">
172 <span>Add columns</span>
174 <li ng:repeat="c in keys(response)" ng:show="columns.indexOf(c) < 0" ng:click="columns.push(c)">{{c}}
178 <table ng:show="response">
180 <th ng:repeat="c in columns" ng:click="columns.$remove(c)">{{c}}</th>
182 <tr ng:repeat="u in response" ng:click="select(u)" ng:class-even="'zebra'">
183 <td ng:repeat="c in columns" ng:show="! selected_username || selected_username == u.USERNAME">{{u[c]}}</td>
187 <input type=button value="Show ALL results, not just {{selected_username}}" ng:click="selected_username=''" ng:show="selected_username">
189 <div ng:show="selected_username">
191 <h2><tt>{{selected_username}}</tt> LDAP entry</h2>
194 <li ng:repeat="c in keys(ldap)"><tt>{{c}}</tt> {{ldap[0][c]}}</li>
197 <div ng:show="cpe.rows">
198 <h2>{{cpe.table}} {{username}}</h2>
199 <pre>{{cpe.rows[0]}}</pre>
202 <ng:include src="gnuplot.img" ng:show="gnuplot.img" onload="message = 'done'">
203 <pre ng:show="gnuplot.sql">{{gnuplot.sql}}</pre>
207 <input type=checkbox name=debug value=1>