[dataproxy][s] Rename duplicate fieldIds from dataproxy results.

Allow the dataproxy backend to be used for viewing files where
the column names are not unique.  This occurs, for example, when
more than 1 column has not been given a column title at all.

Prior to this commit, when encountering such a file, the dataproxy
backend would error-out leaving the user without any feedback as
to what went wrong.
This commit is contained in:
Ian Murray 2012-06-06 13:59:42 +01:00
parent 56a29c80a7
commit b3ed2ea2d5

View File

@ -56,6 +56,19 @@ this.recline.Backend.DataProxy = this.recline.Backend.DataProxy || {};
if (results.error) {
dfd.reject(results.error);
}
// Rename duplicate fieldIds as each field name needs to be
// unique.
var seen = {};
_.map(results.fields, function(fieldId, index) {
if (fieldId in seen) {
seen[fieldId] += 1;
results.fields[index] = fieldId + "("+seen[fieldId]+")";
} else {
seen[fieldId] = 1;
}
});
dataset.fields.reset(_.map(results.fields, function(fieldId) {
return {id: fieldId};
})