From b3ed2ea2d56e36f60f1109e6745a8570dd43b43a Mon Sep 17 00:00:00 2001 From: Ian Murray Date: Wed, 6 Jun 2012 13:59:42 +0100 Subject: [PATCH] [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. --- src/backend/dataproxy.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/backend/dataproxy.js b/src/backend/dataproxy.js index a2731f00..eb305189 100644 --- a/src/backend/dataproxy.js +++ b/src/backend/dataproxy.js @@ -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}; })