Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[unfold.git] / portal / templates / servicedirectory.html
1 {% extends "layout_wide.html" %}
2
3 {% block head %} 
4 <!-- <script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script> -->
5 {% endblock head %}
6
7 {% block content %}
8 <div class="container">
9         <div class="row">
10                 <div class="col-md-12">
11                         <ul class="nav nav-tabs nav-section-mod">
12                                 <li class="active"><a href="#appservices"> Application Services </a></li>
13                                 <li><a href="#fedservices"> Federation Services </a></li>
14                         </ul>
15             </div>
16         </div>
17 </div>
18 <div class="container tab-content">
19         <div class="tab-pane active row" id="appservices">
20                 <div class="col-md-12">
21                         <div id="appservices-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Services" /></div>
22                     <div id="appservices-tab-loaded" style="display:none;">
23             <div class="container" id="appservices-tab">
24
25                         <!-- <table class="table" id="appservices-tab">
26                         <tr>
27                             <th>Name</th>
28                             <th>Provider</th>
29                             <th>Endpoint URL</th>
30                             <th>Protocol</th>
31                             <th>Basic API</th>
32                             <th>Brief Description</th>
33                         </tr>
34                     </table> -->
35               </div>
36                     </div>
37            </div>
38         </div>
39
40         <div class="tab-pane row" id="fedservices" data-authority="{{user_details.parent_authority}}">
41                 <div class="col-md-12">
42                         <div id="fedservices-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Services" /></div>
43                                 <div id="fedservices-tab-loaded" style="display:none;">
44                                 <table class="table" id="fedservices-tab">
45                                         <tr>
46                                         <th>Name</th>
47                                         <th>Brief Description</th>
48                                         <th>URL</th>
49                                         </tr>
50                                 </table>
51                              </div>
52                 </div>
53         </div>
54 </div>
55
56 <script>
57
58 $(document).ready(function() {
59
60 loadedTabs = [];
61   
62   $('.nav-tabs a').click(function (e) {
63     e.preventDefault();
64     $(this).tab('show');
65     // id = $(this).attr('href').substr(1);
66     // if (!(id in loadedTabs)) {
67     //   switch(id) {
68     //     case 'users':
69     //       //loadUsers();
70     //       loadedTabs[id] = true;
71     //     break;
72     //   }
73     // }
74     
75   });
76
77     {% if person %}
78
79         $.ajax({
80             type: "GET",
81             dataType: "json",
82             async: "false",
83             url: "{{ servdirurl }}appservices/",
84             success: function(data, status, jqXHR){
85                 // console.log(data);
86                 // $.each(data, function(i, item){
87                 //     console.log(item);
88                 //     var tr = $('<tr>').append(
89                 //         $('<td id="name">').text(item.name),
90                 //         $('<td>').text(item.provider),
91                 //         $('<td>').append('<a href="' + item.endPoint + '">' + item.endPoint + "</a>"),
92                 //         $('<td>').text(item.protocol),
93                 //         $('<td>').text(item.APIBasic),
94                 //         $('<td>').text(item.briefDescription)
95                 //     );
96                 //     $("#appservices-tab > tbody:last").append(tr);
97                 //     $("td#name").click(function(){
98                 //         window.location.href = data.endPoint;
99                 //     });
100                 // });
101                   function createToggle(name){
102                       return function(){
103                         var el = $('p#expandable-' + name);
104                         if(!el.is(':animated')){
105                           $(el).toggle(300);
106                         }
107                       }
108                     }
109
110                   $.each(data, function(i, item){
111
112                     console.log(item);
113                     var row = $('<div class="row">').append(
114                       $('<div>').addClass("col-md-3 portfolio-item").append(
115                         $('<img>').attr('src', "http://placehold.it/150x150")
116                      ),
117                       $('<div>').addClass("col-md-6 portfolio-item").append(
118                         $('<p id="name-' + item.name.replace(/ /g,'') + '">').text(item.name),
119                         $('<p>').text(item.briefDescription),
120                         $('<p>').text("Provider: " + item.provider),
121                         $('<p>').append('Endpoint: <a href="' + item.endPoint + '">' + item.endPoint + "</a>"),
122                         $('<p id="expandable-' + item.name.replace(/ /g,'') + '">').text(item.fullDescription).hide(),
123                         $('<p id="expandable-' + item.name.replace(/ /g,'') + '">').text("Protocol: " + item.protocol).hide(),
124                         $('<p id="expandable-' + item.name.replace(/ /g,'') + '">')
125                               .append('API documentation: <a href="' + item.APILink + '">' + item.APILink + "</a>").hide(),
126                         $('<p id="expandable-' + item.name.replace(/ /g,'') + '">').text(item.APIBasic).hide()
127                       )
128                     );
129                     $("#appservices-tab").append(row);
130                     $('p#name-' + item.name.replace(/ /g,'')).click(createToggle(item.name.replace(/ /g,'')));
131                 });
132
133
134                 $("div#appservices-tab-loaded").css("display","block");
135                 $("div#appservices-tab-loading").css("display","none");
136             },
137             error: function(jqXHR, status){
138                 console.log("ERROR: " + status);
139             }
140         });
141
142         $.ajax({
143             type: "GET",
144             dataType: "json",
145             async: "false",
146             url: "{{ servdirurl }}fedservices/",
147             success: function(data, status, jqXHR){
148                 // console.log(data);
149                 $.each(data, function(i, item){
150                     console.log(item);
151                     var tr = $('<tr>').append(
152                         $('<td>').text(item.name),
153                         $('<td>').text(item.briefDescription),
154                         $('<td>').append('<a href="' + item.endPoint + '">' + item.endPoint + "</a>")
155                     );
156                     $("#fedservices-tab > tbody:last").append(tr);
157                 });
158
159
160                 $("div#fedservices-tab-loaded").css("display","block");
161                 $("div#fedservices-tab-loading").css("display","none");
162             },
163             error: function(jqXHR, status){
164                 console.log("ERROR: " + status);
165             }
166         });
167         
168   //       $.post("/rest/authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
169   //           var authority_data = [];
170   //           var onelab_data = [];
171                 //      /* 'city','enabled','legal','longitude','onelab_membership','address','parent_authority','slice','user','country',
172   //           'tech','abbreviated_name','url','postcode','description','scientific','authority_hrn','latitude','name'  */
173   //           $.each( data, function( key, val ) {
174   //               authority_row = "<img src='{{ STATIC_URL }}img/institutions/{{user_details.parent_authority}}.gif' alt='' /><br>";
175   //               authority_row += "<br>";
176   //               authority_row += "<b>authority:</b> "+val.authority_hrn+"<br>";
177   //               authority_data.push(authority_row);
178   //           });
179   //           $("div#authority-data").html(authority_data.join( "" ));
180   //           $("div#onelab-data").html(onelab_data.join( "" ));
181   //           $("div#authority-tab-loaded").css("display","block");
182   //           $("div#authority-tab-loading").css("display","none");
183   //        });
184
185   //       $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
186   //           var list_slices = [];
187   //           var table_slices = [];
188   //           /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
189   //           $.each( data, function( key, val ) {
190   //               list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
191   //               if(val.nodes=="undefined" || val.nodes==null){
192   //                   nodes_length=0;
193   //               }else{
194   //                   nodes_length=val.nodes.length;
195   //               }
196   //               if(val.users=="undefined" || val.users==null){
197   //                   users_length=0;
198   //               }else{
199   //                   users_length=val.users.length;
200   //               }
201
202   //               if(val.slice_url=="undefined" || val.slice_url==null){
203   //                   slice_url="";
204   //               }else{
205   //                   slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
206   //               }
207                 
208   //               slice_row = "<tr id='"+val.slice_hrn+"'>";
209   //               slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
210   //               slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
211   //               slice_row += "<td>"+users_length+"</td>";
212   //               slice_row += "<td>"+slice_url+"</td>";
213   //               //slice_row += "<td>"+nodes_length+"</td>";
214   //               slice_row += "<td>"+val.slice_expires+"</td>";
215   //               slice_row += "</tr>";
216   //               table_slices.push(slice_row);
217                 
218   //           });
219            
220   //           /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
221   //           $("table#slice-tab tr:last").after(table_slices.join( "" ));
222   //           $("div#slice-tab-loaded").css("display","block");
223   //           $("div#slice-tab-loading").css("display","none");
224   //       });
225
226                 // $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
227   //            var list_users = [];
228   //            var table_users = [];
229                 //       /* Available fields
230                 //       user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
231                 //       user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
232                 //       */
233   //            $.each( data, function( key, val ) {
234   //                list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
235   //                user_row = "<tr id='"+val.user_hrn+"'>";
236   //                user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
237   //                user_row += "<td>"+val.user_email+"</td>";
238   //                user_row += "<td>"+val.user_hrn+"</td>";
239   //                user_row += "<td>"+val.user_first_name+"</td>";
240   //                user_row += "<td>"+val.user_last_name+"</td>";
241                 //               user_row += "<td>"+val.user_enabled+"</td>";
242   //                user_row += "</tr>";
243   //                table_users.push(user_row);
244   //            });
245   //            $("table#user-tab tr:last").after(table_users.join( "" ));
246   //            $("div#user-tab-loaded").css("display","block");
247   //            $("div#user-tab-loading").css("display","none");
248   //         });
249
250    {% endif %}
251
252 }); // end document.ready
253 </script>
254 {% endblock %}