Repository: yagoferrer/map-tools
Pull request #275 (2015-05-01 19:45:59)

fixed - #268, multi tag search- cleaned up per comments on PR #274


Patch:
diff --git a/eslint.json b/eslint.json
deleted file mode 100644
index 3596476..0000000
--- a/eslint.json
+++ /dev/null
@@ -1,13 +0,0 @@
-{
-  "env": {
-    "browser": true,
-    "node": true,
-    "mocha": true
-  },
-  "rules": {
-    "quotes": [
-      2,
-      "single"
-    ]
-  }
-}
diff --git a/lib/map-tools/filter.js b/lib/map-tools/filter.js
index c7fefb9..691f0a7 100644
--- a/lib/map-tools/filter.js
+++ b/lib/map-tools/filter.js
@@ -32,7 +32,10 @@ module.exports = function(global, that, type) {
   }
 
   function filterByTag(query) {
-
+    // if the search query is an array with only one item then just use that string
+    if(typeof query === "object" && query.length === 1){
+      query = query[0];
+    }
     if (typeof query === "string"){
       if (that[type].tags[query]) {
         return utils.toArray(that[type].tags[query]);
@@ -40,38 +43,27 @@ module.exports = function(global, that, type) {
         return [];
       }
     } else {
+      var markers =  fetchByTag(query);
+      if(typeof markers === "object"){
+        markers = utils.toArray(markers);
+      }
+      return markers;
+    }
+  }
 
-      function fetchByTag(query){
-        for (var i in query) {
-          var tag = query[i];
-          var nextTag = query[parseInt(i)+parseInt(1)];
-          var res; // store first set of markers to compare
-
-          try{
-            res = getCommonObject(that[type].tags[tag],that[type].tags[nextTag])
-          } catch(e){
-            // end of the array
-          }
+  function fetchByTag(query){
+    var res; // store first set of markers to compare
 
-        }
+    for (var i in query) {
+      var tag = query[i];
+      var nextTag = query[parseInt(i)+parseInt(1)];
+      // null check kicks in when we get to the end of the for loop
+      if(nextTag === undefined){
         return res;
       }
-      function getCommonObject(list1, list2){
-        if(list1 === undefined || list2 === undefined){
-          return error("one of the marker lists you are trying to compare is undefined");
-        }
-        var result = {};
-        for (var uid in list1){
-          var match =  list2[uid];
-          if (typeof match !== "undefined"){
-            result[uid] = match;
-          }
-        }
-        return result;
-      }
-       return utils.toArray(fetchByTag(query));
-
+      res = utils.getCommonObject(that[type].tags[tag],that[type].tags[nextTag])
     }
+    return res;
   }
 
 
diff --git a/lib/map-tools/utils.js b/lib/map-tools/utils.js
index 835a2a1..4d0b3ed 100644
--- a/lib/map-tools/utils.js
+++ b/lib/map-tools/utils.js
@@ -63,11 +63,24 @@ function defaultDimension(item) {
   };
 }
 
+// compares two lists and returns the common items
+function getCommonObject(list1, list2){
+  var result = {};
+  for (var uid in list1){
+    var match =  list2[uid];
+    if (typeof match !== "undefined"){
+      result[uid] = match;
+    }
+  }
+  return result;
+}
+
 module.exports = {
   clone: clone,
   createUid: createUid,
   prepareOptions: prepareOptions,
   isArray: isArray,
   toArray: toArray,
-  defaultDimension: defaultDimension
+  defaultDimension: defaultDimension,
+  getCommonObject: getCommonObject
 };
diff --git a/package.json b/package.json
index 78bf353..54469c9 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,6 @@
     "chai": "^2.2.0",
     "codeclimate-test-reporter": "0.0.4",
     "coveralls": "^2.11.2",
-    "eslint": "^0.20.0",
     "gmaps": "^0.4.12",
     "install": "^0.1.8",
     "istanbul": "^0.3.5",
@@ -72,4 +71,4 @@
     "browser": true,
     "mocha": true
   }
-}
+}
\ No newline at end of file


Test patch:
diff --git a/test/functional/tags.Spec.js b/test/functional/tags.Spec.js
index dda3df7..d6c63a2 100644
--- a/test/functional/tags.Spec.js
+++ b/test/functional/tags.Spec.js
@@ -116,6 +116,10 @@ describe('Given the Tag Feature', function () {
       expect(result2[1].title).to.eql('Zaragoza');
       expect(result2.length).to.eql(2);
 
+      var result3 = map.findMarker({tags: ['tag3']});
+      expect(result3[0].title).to.eql('Barcelona');
+      expect(result3[1].title).to.eql('Zaragoza');
+      expect(result3.length).to.eql(2);
     });
 
   });