X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifoldapi%2Fstatic%2Fjs%2Fmanifold.js;h=74fb5d9d6c5e265ffc3600f9881e19faa9e51899;hb=0f9507be5bc87bdef40b3f34d6514bd888ee2abe;hp=57a6c390dadde66daf1a6ada314e610329756ba9;hpb=7254a83bc514a64c05059067bacfe13efaf6284f;p=unfold.git diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index 57a6c390..74fb5d9d 100644 --- a/manifoldapi/static/js/manifold.js +++ b/manifoldapi/static/js/manifold.js @@ -17,6 +17,32 @@ function debug_query (msg, query) { else messages.debug ("debug_query: " + msg + " query= " + query); } +// http://stackoverflow.com/questions/7837456/comparing-two-arrays-in-javascript +// attach the .equals method to Array's prototype to call it on any array +Array.prototype.equals = function (array) { + // if the other array is a falsy value, return + if (!array) + return false; + + // compare lengths - can save a lot of time + if (this.length != array.length) + return false; + + for (var i = 0, l=this.length; i < l; i++) { + // Check if we have nested arrays + if (this[i] instanceof Array && array[i] instanceof Array) { + // recurse into the nested arrays + if (!this[i].equals(array[i])) + return false; + } + else if (this[i] != array[i]) { + // Warning - two different object instances will never be equal: {x:20} != {x:20} + return false; + } + } + return true; +} + // http://javascriptweblog.wordpress.com/2011/08/08/fixing-the-javascript-typeof-operator/ Object.toType = (function toType(global) { return function(obj) { @@ -318,12 +344,20 @@ function QueryStore() { default_set = (default_set === undefined) ? STATE_SET_OUT : default_set; var self = this; - var query_ext = this.find_analyzed_query_ext(query_uuid); - var record_key = manifold.metadata.get_key(query_ext.query.object); + var key, object, query_ext, record_key; + + query_ext = this.find_analyzed_query_ext(query_uuid); + object = query_ext.query.object; + if (object.indexOf(':') != -1) { + object = object.split(':')[1]; + } + record_key = manifold.metadata.get_key(object); + + // ["start_time", "resource", "end_time"] + // ["urn"] + $.each(records, function(i, record) { - var key = manifold.metadata.get_key(query_ext.query.object); - // ["start_time", "resource", "end_time"] - // ["urn"] + //var key = manifold.metadata.get_key(query_ext.query.object); var record_key_value = manifold.record_get_value(record, record_key); query_ext.records.put(record_key_value, record); @@ -351,6 +385,12 @@ function QueryStore() { return query_ext.records.remove(record_key); } + this.del_state = function(query_uuid, record_key) + { + var query_ext = this.find_analyzed_query_ext(query_uuid); + return query_ext.state.remove(record_key); + } + this.add_record = function(query_uuid, record, new_state) { var query_ext, key, record_key; @@ -386,6 +426,7 @@ function QueryStore() { // Leases that are marked out are in fact leases from other slices // We need to _remove_ leases that we mark as OUT manifold.query_store.del_record(query_uuid, record_key); + manifold.query_store.del_state(query_uuid, record_key); } else { manifold.query_store.set_record_state(query_uuid, record_key, STATE_SET, new_state); } @@ -455,7 +496,7 @@ function QueryStore() { { var query_ext = this.find_analyzed_query_ext(query_uuid); query_ext.filters = $.grep(query_ext.filters, function(x) { - return x == filter; + return !(x.equals(filter)); }); this.apply_filters(query_uuid); @@ -519,6 +560,8 @@ function QueryStore() { this.iter_records(query_uuid, function(record_key, record) { var is_reserved, is_pending, in_set, is_unconfigured; + + /* By default, a record is visible unless a filter says the opposite */ var visible = true; var record_state = manifold.query_store.get_record_state(query_uuid, record_key, STATE_SET); @@ -588,13 +631,16 @@ function QueryStore() { if (op == '=' || op == '==') { if ( col_value != value || col_value==null || col_value=="" || col_value=="n/a") visible = false; + }else if (op == 'included') { + /* By default, the filter returns false unless the record + * field match at least one value of the included statement + */ + visible = false; $.each(value, function(i,x) { if(x == col_value){ visible = true; return false; // ~ break - }else{ - visible = false; } }); }else if (op == '!=') { @@ -625,7 +671,7 @@ function QueryStore() { }); var end = new Date().getTime(); - console.log("APPLY FILTERS took", end - start, "ms"); + console.log("APPLY FILTERS [", filters, "] took", end - start, "ms"); } @@ -724,6 +770,9 @@ var manifold = { _record_equals: function(self, other, key_fields) { + if ((typeof self === "string") && (typeof other === "string")) { + return self == other; + } for (var i=0; i < key_fields.length; i++) { var this_value = self[key_fields[i]]; var other_value = other[key_fields[i]]; @@ -1165,7 +1214,15 @@ var manifold = { make_record: function(object, record) { // To make an object a record, we just add the hash function - var key = manifold.metadata.get_key(object); + var key, new_object; + + if (object.indexOf(':') != -1) { + new_object = object.split(':')[1]; + } else { + new_object = object; + } + + key = manifold.metadata.get_key(new_object); record.hashCode = manifold.record_hashcode(key.sort()); record.equals = manifold.record_equals(key); @@ -1295,7 +1352,7 @@ case TYPE_LIST_OF_VALUES: */ case TYPE_LIST_OF_VALUES: // XXX Until fixed case TYPE_LIST_OF_RECORDS: - var new_state,cur_query_uuid; + var key, new_state, cur_query_uuid; cur_query_uuid = query.analyzed_query.subqueries[field].query_uuid; @@ -1303,7 +1360,15 @@ case TYPE_LIST_OF_VALUES: // - update_query_orig.params.resource = resources in slice before update // - update_query.params.resource = resource requested in slice // - keys from field = resources obtained - var key = manifold.metadata.get_key(field); + + if (field == 'lease') { + // lease_id has been added to be repeated when + // constructing request rspec. We don't want it for + // comparisons + key = ['start_time', 'end_time', 'resource']; + } else { + key = manifold.metadata.get_key(field); + } if (!key) continue; /* @@ -1817,6 +1882,7 @@ case TYPE_LIST_OF_VALUES: // FILTERS case FILTER_ADDED: + console.log("FILTER ADDED", data); /* Update internal record state */ manifold.query_store.add_filter(query_uuid, data); @@ -1826,6 +1892,7 @@ case TYPE_LIST_OF_VALUES: break; case FILTER_REMOVED: + console.log("FILTER REMOVED", data); /* Update internal record state */ manifold.query_store.remove_filter(query_uuid, data);