Projects on the Dashboard for Fed4Fire
authorLoic Baron <loic.baron@lip6.fr>
Tue, 20 Jan 2015 16:04:27 +0000 (17:04 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Tue, 20 Jan 2015 16:04:27 +0000 (17:04 +0100)
portal/static/js/myslice.js
portal/templates/base.html
portal/templates/fed4fire/fed4fire_home-view.html
portal/templates/fed4fire/fed4fire_registration_view.html

index 1ccc1c1..4b8fc83 100644 (file)
@@ -1,6 +1,10 @@
 /*
  * MySlice Class
  */
+function isFunction(functionToCheck) {
+ var getType = {};
+ return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
+}
 
 function list() {
        this.elements = [];
@@ -114,6 +118,20 @@ var myslice = {
                }
                return this.user;
        },
+       projects: {},
+       
+       projects: function() {
+               if ($.isEmptyObject(this.projects)) {
+                       //this.login(function() { return this.user; });
+            if(localStorage.getItem('projects')!='undefined'){
+                           this.projects = JSON.parse(localStorage.getItem('projects'));
+            }else{
+                return false;
+            }
+               }
+               return this.projects;
+       },
+
     loadSlices: function(slices) {
         if (typeof(slices) == "undefined"){
 
@@ -154,12 +172,43 @@ var myslice = {
         if($.isEmptyObject(user)){
             // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
                    $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) {
-                           //myslice.user = new user(data[0]);
                            localStorage.setItem('user', JSON.stringify(data[0]));
                 myslice.loadSlices(data[0].slices);
+                if(isFunction(fn)){
+                    fn();
+                }
                    });
+        }else{
+            if(isFunction(fn)){
+                fn();
+            }
+        }
+
+       },
+       loadProjects: function(fn) {
+        user = JSON.parse(localStorage.getItem('user'));
+        projects = localStorage.getItem('projects');
+        if($.isEmptyObject(projects)){
+            if($.isEmptyObject(user) || $.isEmptyObject(user.parent_authority)){
+                       $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'},'fields':['parent_authority']}, function( data ) {
+                    parent_authority = data[0].parent_authority;
+
+                });
+            }else{
+                parent_authority = user.parent_authority;
+            }
+            // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
+            $.post("/rest/authority/",{'fields':['authority_hrn'],'filters':{'authority_hrn':'CONTAINS'+parent_authority}}, function( data ) {
+                localStorage.setItem('projects', JSON.stringify(data));
+            });
+        }else{
+            if(isFunction(fn)){
+                fn();
+            }
         }
+
        },
+
     getSlices: function(name) {
        
     },
index 0bf9ab4..a4f146c 100644 (file)
@@ -48,48 +48,50 @@ XXX TODO: session
 This list of slices should go into SESSION !
 */
 $(document).ready(function() {
-    {% if username %}
-    myslice.login();
+{% if username %}
+    myslice.login(function(){
+        user = myslice.user();
 
-    user = myslice.user();
+        var slices = [];
+        if($.isEmptyObject(user)){
+            $("div#home-slice-list").html(
+                       "<div>You do not yet have a slice</div>");
+            $("ul#dropdown-slice-list").append("<li>no slice</li>");
+            slices.push("no slice");
+        }else{
+            slices = user.slices;
+            drawSlices(slices);
+        }
+        {% if theme == "fed4fire" %}
+        myslice.loadProjects(function(){
+            p = myslice.projects();
+            drawProjects(p);
+        });
+        {% endif %}
+    });
 
-    var slices = [];
-    if($.isEmptyObject(user)){
-        $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) {
-            if(data.length > 0){
-                drawSlices(data[0].slices);  
-            }else{
-               $("div#home-slice-list").html(
-                                       "<div>You do not yet have a slice</div>");
-                       $("ul#dropdown-slice-list").append("<li>no slice</li>");
-                slices.push("no slice");
-            }
-       });
-    }else{
-        slices = user.slices;
-        drawSlices(slices);
-    }
-   
-    /*
-        Launch queries to get the resources and leases in Manifold Cache
-    */
-        
     function drawSlices(slices){
         var items = [];
                
         $.each( slices, function(i, val) {
             items.push( "<li><a href=\"/resources/"+val+"\">" + val + "</a></li>" );
-            /*
-            // Launch a Query for each slice to get resources and leases in Manifold Cache
-            // Now only done in Homeview to speed up the other pages
-            $.post("/rest/slice/", { 'filters': { 'slice_hrn' : val } }, function(data) {
-            });
-            */
         });
         $("div#home-slice-list").html($( "<ul/>", { html: items.join( "" ) }));
         $("ul#dropdown-slice-list").append(items.join( "" ));
     }
+    
+    {% if theme == "fed4fire" %}
+    function drawProjects(projects){
+        var items = [];
+               
+        $.each( projects, function(i, val) {
+            items.push( "<li><a href=\"/project/"+val.authority_hrn+"\">" + val.authority_hrn + "</a></li>" );
+        });
+        $("div#home-project-list").html($( "<ul/>", { html: items.join( "" ) }));
+        $("ul#dropdown-project-list").append(items.join( "" ));
+    }
     {% endif %}
+{% endif %}
        jQuery('[title!=""]').qtip();
 });
 </script>
index 385f698..5938eac 100644 (file)
                        <div>
                                <a href="/portal/institution"><img src="{{ STATIC_URL }}img/icon_authority_color.png" alt="" /></a>
                        </div>
+                       <div>
+                               <button id="projectrequestbtn" type="button" class="btn btn-default" style="width:165px;"><span class="glyphicon glyphicon-plus"></span> Join Project</button>
+                       </div>
                        <div>
                                <button id="validaterequestbtn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> Validate Requests</button>
                        </div>
+                       <div>
+                               <p><strong>Your projects </strong>
+                                       <span title="A project is a sub-authority under the responsability of your institution gathering users, who will be able to create slices for their experiments."
+                                       class="glyphicon glyphicon-info-sign">
+                               </span>
+                               </p>
+                       </div>
+                       <div>   
+                               <div id="home-project-list"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading projects" /></div>
+                       </div>
+
                </div>
                <div class="col-md-3">
                        <h3>
                        </div>
                        <p></p>
                        <div>
-                       <button id="statbtn" type="button" style="width: 150px;" class="btn btn-default"><span class="glyphicon glyphicon-stats"></span>Testbeds' status</button>
+                       <button id="statbtn" type="button" style="width: 170px;" class="btn btn-default"><span class="glyphicon glyphicon-stats" style="margin-right: 10px;"></span>Testbeds' status</button>
                        </div>
                        <div>
                        <button id="repbtn" type="button" style="width: 170px;" class="btn btn-default"><span class="glyphicon glyphicon-stats"></span>Testbeds' reputation</button>
                $('button#slicerequestbtn').click(function() {
                        window.location="/portal/slice_request/";
                });
+               $('button#projectrequestbtn').click(function() {
+                       window.location="/portal/project_request/";
+               });
 
         myslice.loadSlices();
 });
index de03e3c..6c4bee3 100644 (file)
@@ -42,7 +42,7 @@
                         {% else %}
                             <option value="{{ authority.authority_hrn }}">{{authority.authority_hrn}}</option>
                         {% endif %}
-                    {% endfor %}    
+                    {% endfor %}
                 {% else %}
                     <option value:"">No authority found !!!</option>
                 {% endif %}
 <div class="row">
        <div class="col-md-12">
                <div class="form-group" id="register">
-                       <p></p> 
+                       <p></p>
                <input class="submit btn btn-onelab" type="submit" value="Sign up" />
                </form>
            </div>
 
     
 <script>
-//setting the default value in the org_list
-$(function() {
-    var temp="fed4fire.global"; 
-    $("#org_name").val(temp);
-});
 
 $(document).ready(function(){
+    /*
     var availableTags = [
     {% if authorities %}
         {% for authority in authorities %}
@@ -181,8 +177,24 @@ $(document).ready(function(){
                }
        return 0;
        }); 
+    */
+    
        // auto-complete the form
     jQuery("#org_name").combobox();
+
+    //setting the default value in the org_list
+    var temp="fed4fire.global"; 
+    $("#org_name").val(temp);
+
+    /*
+    // Must be executed in Python as Admin Query - User is not logged in
+
+    $.post("/rest/authority/",{'filters':{'authority_hrn':'CONTAINS'+temp}}, function( data ) {
+        $.each( data, function( key, val ) {
+            console.log(val);
+        });
+    });
+    */
        $('[title!=""]').qtip();
        $("form").validate();
        $("form").submit(function() {