X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifoldapi%2Fstatic%2Fjs%2Fmanifold.js;h=00e5562c769aff22f694176966e590e575516bb4;hb=1eec2e84a12bc7cf746c8e6099031629ca7d3783;hp=b959c10e3d48bd5eb4a8d4ce96d77cbf8182698a;hpb=91bc3561ea98eff799c3055fa6258f910ff97a51;p=unfold.git diff --git a/manifoldapi/static/js/manifold.js b/manifoldapi/static/js/manifold.js index b959c10e..00e5562c 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) { @@ -462,7 +488,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); @@ -731,6 +757,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]]; @@ -1302,7 +1331,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; @@ -1310,7 +1339,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; /* @@ -1824,6 +1861,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); @@ -1833,6 +1871,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);