From d09e3b74f294d4d712ac5ef4abeeb0a18e4b11b9 Mon Sep 17 00:00:00 2001 From: Ciro Scognamiglio Date: Tue, 4 Mar 2014 21:27:05 +0100 Subject: [PATCH] resource reservation work in progress --- portal/sliceresourceview.py | 6 ++- portal/static/js/myslice.js | 37 +++++++++++++++++++ .../static/js/onelab_slice-resource-view.js | 16 ++++++-- .../onelab/onelab_slice-resource-view.html | 13 ++++++- rest/__init__.py | 9 +++-- rest/update.py | 12 +++++- 6 files changed, 83 insertions(+), 10 deletions(-) diff --git a/portal/sliceresourceview.py b/portal/sliceresourceview.py index e66de0ae..3c1e5b54 100644 --- a/portal/sliceresourceview.py +++ b/portal/sliceresourceview.py @@ -20,4 +20,8 @@ class SliceResourceView (LoginRequiredView, ThemeView): template_name = "slice-resource-view.html" def get(self, request, slicename): - return render_to_response(self.template, {"slice": slicename, "theme": self.theme, "username": request.user, "section":"resources"}, context_instance=RequestContext(request)) + if request.GET.get('message') : + msg = "Successfully updated Slice" + else : + msg = None + return render_to_response(self.template, {"msg" : msg, "slice": slicename, "theme": self.theme, "username": request.user, "section":"resources"}, context_instance=RequestContext(request)) diff --git a/portal/static/js/myslice.js b/portal/static/js/myslice.js index e1a6de17..a67e3146 100644 --- a/portal/static/js/myslice.js +++ b/portal/static/js/myslice.js @@ -3,7 +3,9 @@ */ var myslice = { + slice: null, pending: [], + reserved: [], add: function(resource) { if (!this.has(resource)) { @@ -39,6 +41,41 @@ var myslice = { if (!this.pending) { this.pending = []; } + }, + + apply: function() { + $('div#loading').show(); + this.pending = []; + this.save(); + setTimeout(function(){ + $('div#loading').hide(); + window.location.href = '/resources/' + this.slice + '?message=true'; + },6000); + + + + // $.post("/rest/slice/", { 'fields': ['resource','slice_hrn'], 'filters': { 'slice_hrn' : this.slice } }, function(data) { + // console.log(data); + // resources = []; + // reserved = []; + // update = []; + // if ('resource' in data[0]) { + // $.each(data[0].resource, function(idx, r) { + // resources.push(r.urn); + // }); + // } + // //myslice.pending + // console.log(myslice.pending); + // console.log(resources); + // $.each(resources.concat(myslice.pending), function(idx, v) { + // update.push({ 'resource': v }); + // }); + // console.log(update); + // $.post("/update/slice/", { 'filters': { 'slice_hrn' : myslice.slice }, 'params' : update }, function(data) { + // console.log(data); + // }); + // }); + //console.log(this.slice); } }; diff --git a/portal/static/js/onelab_slice-resource-view.js b/portal/static/js/onelab_slice-resource-view.js index 52850a36..28b1a4ef 100644 --- a/portal/static/js/onelab_slice-resource-view.js +++ b/portal/static/js/onelab_slice-resource-view.js @@ -10,16 +10,26 @@ $(document).ready(function() { } }); - $.get("/rest/platform", function(data) { + $.get("/rest/network", function(data) { var list = '
Testbeds
'; for(i=0; i'+data[i].platform_longname+'

'+data[i].platform+'

'; + list += ''+data[i].network_longname+'

'+data[i].network_hrn+'

'; } $('#select-platform').html(list); }).done(function() { }); + $('button#ApplyPendind').click(function() { + myslice.apply(); + // $.each(myslice.pending, function(k, p) { + // console.log(p); + // }); + // $.post("/update/slice", {}, function() { +// + // }); + }); + //google.maps.event.addDomListener(window, 'load', initialize); }); @@ -47,7 +57,7 @@ function mapInit() { }); var infowindow = new google.maps.InfoWindow(); - google.maps.event.addListener(marker, 'click', (function(marker, i) { + google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(data[i].hostname); infowindow.open(map, marker); diff --git a/portal/templates/onelab/onelab_slice-resource-view.html b/portal/templates/onelab/onelab_slice-resource-view.html index 1fcecf9d..d6682d2c 100644 --- a/portal/templates/onelab/onelab_slice-resource-view.html +++ b/portal/templates/onelab/onelab_slice-resource-view.html @@ -3,6 +3,9 @@ {% block head %} + {% endblock %} {% block content %} @@ -29,11 +32,19 @@
  • Reserved
  • Pending
  • - +
  • +
  • + +
  • +
    + {% if msg %} +

    {{ msg }}

    + {% endif %} +