4 function isFunction(functionToCheck) {
6 return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]';
13 list.prototype.add = function(element) {
14 if (!this.has(element)) {
15 this.elements.push(element);
19 list.prototype.del = function(element) {
20 if (this.has(element)) {
21 this.elements.splice(index, 1);
25 list.prototype.has = function(element) {
26 index = $.inArray( element, this.elements );
33 list.prototype.count = function() {
34 return this.elements.length;
39 * resources, users, leases
42 function resources() {
66 function slice(name) {
68 this.resources = new resources();
69 this.users = new users();
70 this.leases = new leases();
80 this.testbeds = new list();
81 this.slices = new list();
83 for (i = 0; i < this.user.slices.length; i++) {
84 this.slices[this.user.slices[i]] = new slice(this.user.slices[i]);
88 user.prototype.slice = function(name) {
89 return this.slices[name];
92 user.prototype.list = function() {
93 for (s in this.slices) {
95 if (typeof o != 'function') {
111 if ($.isEmptyObject(this.user)) {
112 //this.login(function() { return this.user; });
113 if(localStorage.getItem('user')!='undefined'){
114 this.user = JSON.parse(localStorage.getItem('user'));
123 projects: function() {
124 if ($.isEmptyObject(this.projects)) {
125 //this.login(function() { return this.user; });
126 if(localStorage.getItem('projects')!='undefined'){
127 this.projects = JSON.parse(localStorage.getItem('projects'));
132 return this.projects;
135 loadSlices: function(slices) {
136 if (typeof(slices) == "undefined"){
138 if(myslice.user != null && typeof(myslice.user.slices) != "undefined" && myslice.user.slices.length>0){
139 slices = myslice.user.slices
142 // myslice.user is in LocalStorage
143 if(typeof(slices) != "undefined"){
145 This allows progressive loading per AM platform
146 Launch queries to get the resources and leases in Manifold Cache
148 TODO support cache for prefixed objects
149 XXX Disabled until it's supported on Manifold side
152 $.post("/rest/platform/", function( data ) {
153 $.each(data, function(index, p) {
154 $.post("/rest/"+p.platform+":resource/", function( data ) {
156 $.post("/rest/"+p.platform+":lease/", function( data ) {
158 $.each( slices, function(i, val) {
159 // Launch a Query for each slice to get it in Manifold Cache
160 $.post("/rest/"+p.platform+":slice/", { 'filters': { 'slice_hrn' : val } }, function(data) {
170 login: function(fn) {
171 user = localStorage.getItem('user');
172 if($.isEmptyObject(user)){
173 // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
174 $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'}}, function( data ) {
175 if (data.length > 0) {
176 localStorage.setItem('user', JSON.stringify(data[0]));
177 myslice.loadSlices(data[0].slices);
190 loadProjects: function(fn) {
191 var u = localStorage.getItem('user');
192 if (u !== 'undefined') {
193 user = JSON.parse(u);
194 projects = localStorage.getItem('projects');
195 if($.isEmptyObject(projects)){
196 if($.isEmptyObject(user) || $.isEmptyObject(user.parent_authority)){
197 $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'},'fields':['parent_authority']}, function( data ) {
198 parent_authority = data[0].parent_authority;
202 parent_authority = user.parent_authority;
204 // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
205 $.post("/rest/myslice:authority/",{'fields':['authority_hrn'],'filters':{'authority_hrn':'CONTAINS'+parent_authority}}, function( data ) {
206 localStorage.setItem('projects', JSON.stringify(data));
220 getSlices: function(name) {
224 refreshUser: function() {
230 //$('div#loading').show();
233 //setTimeout(function(){
234 //$('div#loading').hide();
235 //window.location.href = '/resources/' + this.slice + '?message=true';
240 $.post("/rest/slice/", { 'fields': ['resource','slice_hrn'], 'filters': { 'slice_hrn' : this.slice } }, function(data) {
245 if ('resource' in data[0]) {
246 $.each(data[0].resource, function(idx, r) {
247 resources.push(r.urn);
251 console.log(myslice.pending);
252 console.log(resources);
253 $.each(resources.concat(myslice.pending), function(idx, v) {
257 $.post("/update/slice/", { 'filters': { 'slice_hrn' : myslice.slice }, 'params' : update }, function(data) {
261 console.log(this.slice);
269 // var Reflector = function(obj) {
270 // this.getProperties = function() {
271 // var properties = [];
272 // for (var prop in obj) {
273 // if (typeof obj[prop] != 'function') {
274 // properties.push(prop);
275 // console.log("prop: " + prop);
277 // console.log("func: " + prop);
280 // return properties;
283 // var reflector = new Reflector(myslice.slices[0].resources.pending);
284 // reflector.getProperties();
287 $(document).ready(function() {
288 //console.log(myslice.user().slices);
290 // $.post("/rest/user/",{'filters':{'user_hrn':'$user_hrn'}}, function(data) {
291 // myslice.user = new user(data[0]);
292 // console.log(myslice.user.slices);
293 // myslice.user.list();
295 // }).fail(function() {
296 // throw "error retreiving user data";
298 // Put the object into storage
299 //localStorage.setItem('testObject', JSON.stringify(testObject));
301 // Retrieve the object from storage
307 // add a resource to pending
309 //myslice.user.slice('ple.upmc.myslicedemo').resources.pending.add(resource);