Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'bnchdrff-pretty_column_titles'
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoma committed Dec 11, 2014
2 parents a6417e2 + bfbde9f commit da3e111
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -120,6 +120,8 @@ You pass in either `key` as the actual spreadsheet key, or just the full publish

`callbackContext` sets the `this` for your callback. It's the tabletop object by default.

`prettyColumnNames` can be true or false (default to false). It adds an object `pretty_columns` as a sibling to `column_names` which contains human-readable column names.

### Tabletop itself

Once you've initialized a `tabletop` object you can access its good parts.
Expand Down
34 changes: 34 additions & 0 deletions src/tabletop.js
Expand Up @@ -69,6 +69,7 @@
this.singleton = !!options.singleton;
this.simple_url = !!options.simple_url;
this.callbackContext = options.callbackContext;
this.prettyColumnNames = !!options.prettyColumnNames;

if(typeof(options.proxy) !== 'undefined') {
// Remove trailing slash, it will break the app
Expand Down Expand Up @@ -367,6 +368,39 @@
if(ttIndexOf(this.model_names, model.name) === -1) {
this.model_names.push(model.name);
}
if (this.prettyColumnNames) {
var cellurl = data.feed.link[3].href.replace('/feeds/list/', '/feeds/cells/').replace('https://spreadsheets.google.com', '');
this.requestData(cellurl, this.loadPrettyColumnNames);
} else {
this.sheetsToLoad--;
if(this.sheetsToLoad === 0)
this.doCallback();
}
},

/*
* Store column names as an object
* with keys of Google-formatted "columnName"
* and values of uman-readable "Column name"
*/
loadPrettyColumnNames: function(data) {
var pretty_columns = {};

var column_names = this.models[data.feed.title.$t].column_names;

var i = 0;
var l = column_names.length;

for (; i < l; i++) {
if (typeof data.feed.entry[i].content.$t !== 'undefined') {
pretty_columns[column_names[i]] = data.feed.entry[i].content.$t;
} else {
pretty_columns[column_names[i]] = column_names[i];
}
}

this.models[data.feed.title.$t].pretty_columns = pretty_columns;

this.sheetsToLoad--;
if(this.sheetsToLoad === 0)
this.doCallback();
Expand Down

0 comments on commit da3e111

Please sign in to comment.