Show deprecated tags in save commit, validate them, add deprecatedTags

to entity type.
This commit is contained in:
Tom MacWright
2013-02-04 16:45:18 -05:00
parent 3d8f2ffb84
commit bd7f302730
7 changed files with 47 additions and 10 deletions
+22 -5
View File
@@ -9,22 +9,22 @@ iD.Entity = function(attrs) {
return (new iD.Entity()).initialize(arguments);
};
iD.Entity.id = function (type) {
iD.Entity.id = function(type) {
return iD.Entity.id.fromOSM(type, iD.Entity.id.next[type]--);
};
iD.Entity.id.next = {node: -1, way: -1, relation: -1};
iD.Entity.id.fromOSM = function (type, id) {
iD.Entity.id.fromOSM = function(type, id) {
return type[0] + id;
};
iD.Entity.id.toOSM = function (id) {
iD.Entity.id.toOSM = function(id) {
return id.slice(1);
};
// A function suitable for use as the second argument to d3.selection#data().
iD.Entity.key = function (entity) {
iD.Entity.key = function(entity) {
return entity.id;
};
@@ -84,7 +84,7 @@ iD.Entity.prototype = {
},
hasInterestingTags: function() {
return _.keys(this.tags).some(function (key) {
return _.keys(this.tags).some(function(key) {
return key != "attribution" &&
key != "created_by" &&
key != "source" &&
@@ -93,6 +93,23 @@ iD.Entity.prototype = {
});
},
deprecatedTags: function() {
var tags = _.pairs(this.tags);
var deprecated = {};
iD.data.deprecated.forEach(function(d) {
var match = _.pairs(d.old)[0];
tags.forEach(function(t) {
if (t[0] == match[0] &&
(t[1] == match[1] || match[1] == '*')) {
deprecated[t[0]] = t[1];
}
});
});
return deprecated;
},
friendlyName: function() {
// Generate a string such as 'river' or 'Fred's House' for an entity.
if (!this.tags || !Object.keys(this.tags).length) { return ''; }
+1
View File
@@ -17,6 +17,7 @@ iD.ui.save = function(context) {
d3.select('.shaded').remove();
var l = iD.ui.loading(t('uploading_changes'), true);
connection.putChangeset(history.changes(),
e.comment,
history.imagery_used(), function(err, changeset_id) {
+2 -2
View File
@@ -8,8 +8,8 @@ iD.util.trueObj = function(arr) {
iD.util.tagText = function(entity) {
return d3.entries(entity.tags).map(function(e) {
return e.key + ': ' + e.value;
}).join('\n');
return e.key + '=' + e.value;
}).join(', ');
};
iD.util.stringQs = function(str) {
+8
View File
@@ -29,6 +29,14 @@ iD.validate = function(changes, graph) {
warnings.push({ message: t('validations.untagged_line'), entity: change });
}
var deprecatedTags = change.deprecatedTags();
if (!_.isEmpty(deprecatedTags)) {
warnings.push({
message: t('validations.deprecated_tags', {
tags: iD.util.tagText({ tags: deprecatedTags })
}), entity: change });
}
if (change.geometry(graph) === 'area' && _.isEmpty(change.tags)) {
warnings.push({ message: t('validations.untagged_area'), entity: change });
}
+2 -1
View File
@@ -127,7 +127,8 @@ locale.en = {
untagged_point: "Untagged point which is not part of a line or area",
untagged_line: "Untagged line",
untagged_area: "Untagged area",
tag_suggests_area: "The tag {tag} suggests line should be area, but it is not an area"
tag_suggests_area: "The tag {tag} suggests line should be area, but it is not an area",
deprecated_tags: "Deprecated tags: {tags}"
},
"save": "Save",
+10
View File
@@ -114,6 +114,16 @@ describe('iD.Entity', function () {
});
});
describe("#hasDeprecatedTags", function () {
it("returns false if entity has no tags", function () {
expect(iD.Entity().deprecatedTags()).to.eql({});
});
it("returns true if entity has deprecated tags", function () {
expect(iD.Entity({ tags: { barrier: 'wire_fence' } }).deprecatedTags()).to.eql({ barrier: 'wire_fence' });
});
});
describe("#hasInterestingTags", function () {
it("returns false if the entity has no tags", function () {
expect(iD.Entity().hasInterestingTags()).to.equal(false);
+2 -2
View File
@@ -6,8 +6,8 @@ describe('iD.Util', function() {
it('.tagText', function() {
expect(iD.util.tagText({})).to.eql('');
expect(iD.util.tagText({tags:{foo:'bar'}})).to.eql('foo: bar');
expect(iD.util.tagText({tags:{foo:'bar',two:'three'}})).to.eql('foo: bar\ntwo: three');
expect(iD.util.tagText({tags:{foo:'bar'}})).to.eql('foo=bar');
expect(iD.util.tagText({tags:{foo:'bar',two:'three'}})).to.eql('foo=bar, two=three');
});
it('.stringQs', function() {