show just last 100 rows with points
[APKPM.git] / templates / user.html.ep
1 % layout 'angular';
2
3   <script>
4     function CRM($xhr) {
5       var self = this;
6    
7       this.fetch = function() {
8         if ( ! self.args ) return;
9         self.url = '/g/' + self.function_name + '/' + self.args + '?callback=JSON_CALLBACK';
10         $xhr('JSON', self.url, function(code, response) {
11           self.code = code;
12           self.response = response;
13         });
14       };
15    
16       this.clear = function() {
17         self.url = null;
18         self.code = null;
19         self.response = null;
20         self.selected_username = null;
21         self.gnuplot_sql = null;
22         self.ldap = null;
23       };
24
25         this.columns = [
26                 'USERNAME',
27                 'BROJ',
28                 'USLUGA',
29                 'IP_MANAGEMENT',
30                 'IP_VOICE',
31                 'KOLOKACIJA',
32                 'OPT82'
33         ];
34
35       this.keys = function(h) {
36              if ( angular.isArray(h) ) h = h[0];
37              var keys = [];
38              for(i in h) if (h.hasOwnProperty(i))
39              {
40                keys.push(i);
41              }
42              return keys;
43       };
44
45         this.select = function(crm) {
46                 console.log( 'crm = ',crm );
47                 self.selected_username = crm.USERNAME;
48                 self.gnuplot_sql = null;
49                 $xhr('JSON'
50                         , '/g/LDAP_search/' + self.selected_username + '?callback=JSON_CALLBACK'
51                         , function(code, response) {
52                                 console.debug( code, response );
53                                 self.ldap = response;
54                                 self.gnuplot_sql = '/gnuplot?hide=1;with=points;sql=select timestamp,snrtx,attntx,pwrtx,pwrrx,attnrx,snrrx from adsl where username = \'' + response[0].cn + '\' order by timestamp desc limit 100';
55                         }
56                 );
57         };
58
59     }
60
61     CRM.$inject = ['$xhr'];
62   </script>
63
64 <style type="text/css">
65 #columns {
66         position: fixed;
67         top: 0;
68         right: 0;
69         z-index: 10;
70         background: #eee;
71 }
72
73 #columns > span {
74         float: right;
75 }
76
77 #columns ul {
78         display: none;
79 }
80
81 #columns:hover ul {
82         display: block;
83 }
84
85 table {
86         border-collapse:collapse;
87 }
88
89 th {
90         border-bottom: 2px solid gray;
91 }
92
93 th, td {
94         border-left: 1em solid white;
95         border-right: 1em solid white;
96 }
97
98 .zebra {
99         background: #eee;
100 }
101
102 </style>
103
104   <div ng:controller="CRM">
105    <form ng:submit="fetch()">
106     <input type="hidden" name="function_name" value="CRM_search"      size="20"/>
107     <label for="args">username:
108     <input type="text" name="args"     placeholder="test" size="10"/>
109     </label>
110     <input type="submit" ng:click="fetch()" value="search">
111     <input type="reset"  ng:click="clear()" value="clear">
112
113     <b ng:show="url && ! code">loading {{url}}</b>
114     <b ng:show="response">{{response.length}} results for <tt>{{args}}</tt></b>
115    </form>
116
117 <div id="columns" ng:show="response">
118 <span>Add columns</span>
119 <ul>
120 <li ng:repeat="c in keys(response)" ng:show="columns.indexOf(c) < 0" ng:click="columns.push(c)">{{c}}
121 </ul>
122 </div>
123
124     <table ng:show="response">
125     <tr>
126         <th ng:repeat="c in columns" ng:click="columns.$remove(c)">{{c}}</th>
127     </tr>
128     <tr ng:repeat="u in response" ng:click="select(u)" ng:class-even="'zebra'">
129         <td ng:repeat="c in columns" ng:show="! selected_username || selected_username == u.USERNAME">{{u[c]}}</td>
130     </tr>
131     </table>
132
133     <input type=button value="Show ALL results, not just {{selected_username}}" ng:click="selected_username=''" ng:show="selected_username">
134
135   <div ng:show="selected_username">
136
137     <tt>{{selected_username}}</tt>
138
139     <ul ng:show="ldap">
140     <li ng:repeat="c in keys(ldap)"><tt>{{c}}</tt> {{ldap[0][c]}}</li>
141     </ul>
142
143     <ng:include src="gnuplot_sql" ng:show="gnuplot_sql">
144
145   </div>
146
147     <input type=checkbox name=debug value=1>
148     <pre ng:show=debug>
149 url={{url}}
150 code={{code}}
151 response={{response}}
152 username={{username}}
153     </pre>
154   </div>