2 <html xmlns:ng="http://angularjs.org">
3 <script src="http://code.angularjs.org/angular-0.9.17.min.js" ng:autobind></script>
6 function user($xhr,$resource,$log) {
11 self.r.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 );
16 self.message.CRM = 'search for '+username;
17 self.r.CRM_search.query({username: username}, function(CRM) {
19 $log.info( 'CRM', CRM )
21 self.message.CRM = 'no results';
24 self.message.CRM = null;
25 if ( CRM.length == 1 ) {
26 self.selected_username = CRM[0].USERNAME;
27 $log.info( 'auto-selected ', self.selected_username );
32 self.r.LDAP_search = $resource('/g/LDAP_search/:username', {username:'@selected_username'});
33 self.LDAP_search = function(username) {
34 if ( self.selected_username == username ) {
35 $log.error("LDAP_search - not changed", username);
39 if ( ! username ) username = self.selected_username;
42 self.message.LDAP = 'no username';
45 $log.info( 'LDAP_search', username );
47 self.selected_username = username;
48 self.message.LDAP = 'search '+username;
49 self.r.LDAP_search.query({ username: username }, function(LDAP) {
51 $log.info( 'LDAP', LDAP );
52 if ( self.LDAP.length == 0 ) {
53 self.message.LDAP ='no results for '+username;
56 self.cpe.parser = LDAP[0]._cpe_parser;
57 self.cpe.table_name = 'cpe_' + LDAP[0]._cpe_parser;
58 self.username = LDAP[0].cn;
59 self.message.LDAP = null;
60 $log.info( 'cpe', self.cpe );
63 self.$watch('selected_username', self.LDAP_search );
65 self.gnuplot_draw = function(h_cols) {
66 $log.info( 'gnuplot_draw', h_cols );
68 self.gnuplot.cols = h_cols;
70 $log.warn("no columns for gnuplot");
74 self.message.gnuplot = 'redrawing '+h_cols.join(' ');
76 var cols = [ 'timestamp' ];
77 for ( var i = 0; i < h_cols.length; i++ ) {
78 cols.push( 'h->\'' + h_cols[i] + '\' as "' + h_cols[i] + '"' );
80 console.debug( cols );
81 self.gnuplot.sql = 'select ' + cols.join(',') + ' from cpe_' + self.cpe.parser + ' where username = \'' + self.username + '\' order by timestamp desc limit 100';
83 $log.info( 'gnuplot', self.gnuplot );
84 self.gnuplot.img = '/gnuplot?hide=1;with=points;sql=' + self.gnuplot.sql;
88 self.r.table = $resource('/table/:table');
89 self.table_update = function () {
90 if ( ! self.username || ! self.cpe.table_name ) return;
91 self.message.table = self.username + ' loading from ' + self.cpe.table_name;
92 self.r.table.get({ username: self.username, table: self.cpe.table_name, limit: self.cpe_limit }, function(table) {
93 $log.info( 'table', table );
94 self.cpe.table = table;
95 self.message.table = null;
96 if ( table.rows.length == 0 ) {
97 self.message.table = 'no results for '+self.username;
101 if ( h_cols = self.cpe_hash[self.cpe.parser] ) {
102 self.gnuplot_draw( h_cols );
104 self.message.gnuplot = 'no graph for ' + self.cpe.parser;
108 self.$watch('username', self.table_update );
110 this.clear = function() {
116 this.clear_LDAP = function() {
117 $log.info('clear_LDAP');
119 self.selected_username = null;
127 self.$watch('selected_username', function() {
128 if ( self.selected_username == null ) self.clear_LDAP();
132 self.$watch('cpe_limit', function() {
133 $log.info( 'cpe_limit', self.cpe_limit );
148 'Davolink': [ 'Max_down', 'Max_up' ],
149 'EasyGateway': [ 'upstreamCurrRate', 'upstreamMaxRate', 'upstreamNoiseMargin' ],
152 this.keys = function(h) {
153 if ( angular.isArray(h) ) h = h[0];
155 for(i in h) if (h.hasOwnProperty(i))
164 user.$inject = ['$xhr','$resource','$log'];
166 // http://jsfiddle.net/gronky/cLEck/
167 angular.formatter('include', {
168 parse: function(apply, value, list) {
169 angular.Array[apply ? 'add' : 'remove'](list, value);
172 format: function(apply, value, list) {
173 return angular.Array.indexOf(list, value) != -1;
179 <style type="text/css">
182 border-collapse:collapse;
186 border-bottom: 2px solid gray;
190 border-left: 1em solid white;
191 border-right: 1em solid white;
218 .panel_right ul > li {
219 list-style-type: none;
222 .panel_right > label {
232 <div ng:controller="user">
234 <form ng:submit="CRM_search()">
235 <label for="args">username:
236 <input type="text" name="search_username" placeholder="test" size="10" autofocus ng:required />
238 <input type="submit" value="search in CRM">
239 <input type="reset" ng:click="clear()" value="clear">
241 <span id="message" ng:show="message.$size()" ng:click="message={}" title="click to close">
242 <div ng:repeat="(category,status) in message" ng:show="status"><b>{{category}}</b> {{status}}</div>
248 <div class="panel_right" ng:show="CRM">
251 <input type=checkbox name=show_columns>
253 <ul ng:show="show_columns">
254 <li ng:repeat="c in keys(CRM)" ng:show="columns.indexOf(c) < 0" ng:click="columns.push(c)">{{c}}
258 <table ng:show="CRM">
260 <th ng:repeat="c in columns" ng:click="columns.$remove(c)">{{c}}</th>
262 <tr ng:repeat="u in CRM" ng:click="LDAP_search(u.USERNAME)" ng:class-even="'zebra'">
263 <td ng:repeat="c in columns" ng:show="! selected_username || selected_username == u.USERNAME">{{u[c]}}</td>
267 <input type=button value="Show ALL results, not just {{selected_username}}" ng:click="selected_username=''" ng:show="selected_username">
269 <div ng:show="selected_username">
271 <h2><tt>{{selected_username}}</tt> LDAP entry</h2>
274 <li ng:repeat="c in keys(LDAP)"><tt>{{c}}</tt> {{LDAP[0][c]}}</li>
277 <div class="panel_right" ng:show="cpe.table">
280 <input type=checkbox name=show_gnuplot_cols>
282 <ul ng:show="show_gnuplot_cols">
283 <input type=button ng:click="gnuplot_draw(gnuplot.cols)" value="Redraw graph">
284 <li ng:repeat="(k,v) in cpe.table.rows[0][cpe.table.hash_col]">
286 <input type="checkbox" name="gnuplot_cols" ng:format="include:k:gnuplot.cols" ng:change="$log.debug(gnuplot_cols)">
290 <input type=button ng:click="gnuplot_draw(gnuplot.cols)" value="Redraw graph">
294 <ng:include src="gnuplot.img" ng:show="gnuplot.img" onload="message.gnuplot = null" ></ng:include>
296 <h2 ng:show="cpe.table_name">{{cpe.table_name}} {{username}}</h2>
298 <table ng:show="cpe.table">
300 <th ng:repeat="c in cpe.table.columns">{{c}}</th>
302 <tr ng:repeat="r in cpe.table.rows" ng:class-even="'zebra'">
303 <td ng:repeat="v in r">{{v}}</td>
306 <td colspan="{{cpe.table.columns.length}}">
308 <label>1<input name="cpe_limit" type="radio" value=1></label>
309 · · ·
310 <label>5<input name="cpe_limit" type="radio" value=5></label>
311 · · ·
312 <label>10<input name="cpe_limit" type="radio" value=10></label>
319 <input type=checkbox name=debug value=1>