using query.object with namespaces was causing issues when looking for object type
[unfold.git] / manifoldapi / static / js / manifold.js
index 1b5f426..17677b9 100644 (file)
@@ -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);
@@ -462,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);
@@ -731,6 +765,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]];
@@ -1172,7 +1209,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);