mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-20 07:25:15 +02:00
In Taginfo results sort keys w ':' below keys w/o ':' (closes #2376)
This commit is contained in:
@@ -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));
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user