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