In Taginfo results sort keys w ':' below keys w/o ':' (closes #2376)

This commit is contained in:
Bryan Housel
2015-12-20 01:12:31 -05:00
parent ea1e626d41
commit 0720b03f66
2 changed files with 22 additions and 1 deletions
+8 -1
View File
@@ -58,6 +58,13 @@ iD.taginfo = function() {
};
}
// sort keys with ':' lower than keys without ':'
function sortKeys(a, b) {
return (a.key.indexOf(':') === -1 && b.key.indexOf(':') !== -1) ? -1
: (a.key.indexOf(':') !== -1 && b.key.indexOf(':') === -1) ? 1
: 0;
}
var debounced = _.debounce(d3.json, 100, true);
function request(url, debounce, callback) {
@@ -86,7 +93,7 @@ iD.taginfo = function() {
page: 1
}, parameters)), debounce, function(err, d) {
if (err) return callback(err);
callback(null, d.data.filter(popularKeys(parameters)).map(valKey));
callback(null, d.data.filter(popularKeys(parameters)).sort(sortKeys).map(valKey));
});
};
+14
View File
@@ -55,6 +55,20 @@ describe("iD.taginfo", function() {
expect(callback).to.have.been.calledWith(null, [{"value":"amenity"}]);
});
it("sorts keys with ':' below keys without ':'", function() {
var callback = sinon.spy();
taginfo.keys({query: "ref"}, callback);
server.respondWith("GET", new RegExp("https://taginfo.openstreetmap.org/api/4/keys/all"),
[200, { "Content-Type": "application/json" },
'{"data":[{"key":"ref:bag","count_all":9790586,"count_all_fraction":0.0028},\
{"key":"ref","count_all":7933528,"count_all_fraction":0.0023}]}']);
server.respond();
expect(callback).to.have.been.calledWith(null, [{"value":"ref"},{"value":"ref:bag"}]);
});
});
describe("#values", function() {