From 5685ccc110bd05a1d939bc64e4a9ef8dfacd2a20 Mon Sep 17 00:00:00 2001 From: Benjamin Chodoroff Date: Mon, 1 Dec 2014 17:35:19 -0500 Subject: [PATCH 1/4] add a pretty column titles object refs #62 --- src/tabletop.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/tabletop.js b/src/tabletop.js index 6533df2..b5ca4e2 100755 --- a/src/tabletop.js +++ b/src/tabletop.js @@ -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 @@ -368,10 +369,34 @@ this.model_names.push(model.name); } this.sheetsToLoad--; + 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); + } if(this.sheetsToLoad === 0) this.doCallback(); }, + /* + * Add an object storing column names as an object + * with key of Google-formatted "columnName" + * and value 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++) { + pretty_columns[column_names[i]] = data.feed.entry[i].content.$t; + } + + this.models[data.feed.title.$t].pretty_columns = pretty_columns; + }, + /* Execute the callback upon loading! Rely on this.data() because you might only request certain pieces of data (i.e. simpleSheet mode) From 083a23eec0521f605258958ffb3efdeea62dd0f7 Mon Sep 17 00:00:00 2001 From: Benjamin Chodoroff Date: Mon, 1 Dec 2014 22:51:43 -0500 Subject: [PATCH 2/4] add docs to readme, clean up inline doc --- README.md | 2 ++ src/tabletop.js | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3ccd316..56529a3 100755 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/tabletop.js b/src/tabletop.js index b5ca4e2..e7cc131 100755 --- a/src/tabletop.js +++ b/src/tabletop.js @@ -378,9 +378,9 @@ }, /* - * Add an object storing column names as an object - * with key of Google-formatted "columnName" - * and value of uman-readable "Column name" + * 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 = {}; From cc04394df9210358a49ac2756b2445f5516cf10c Mon Sep 17 00:00:00 2001 From: Benjamin Chodoroff Date: Mon, 1 Dec 2014 23:26:23 -0500 Subject: [PATCH 3/4] respect callback order --- src/tabletop.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tabletop.js b/src/tabletop.js index e7cc131..2b9e090 100755 --- a/src/tabletop.js +++ b/src/tabletop.js @@ -372,9 +372,10 @@ 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 { + if(this.sheetsToLoad === 0) + this.doCallback(); } - if(this.sheetsToLoad === 0) - this.doCallback(); }, /* @@ -395,6 +396,9 @@ } this.models[data.feed.title.$t].pretty_columns = pretty_columns; + + if(this.sheetsToLoad === 0) + this.doCallback(); }, /* From 321db27ac7fd4549cc40b296c6b9014f12411cc0 Mon Sep 17 00:00:00 2001 From: Benjamin Chodoroff Date: Mon, 1 Dec 2014 23:41:21 -0500 Subject: [PATCH 4/4] manage things more correctly --- src/tabletop.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tabletop.js b/src/tabletop.js index 2b9e090..6e28497 100755 --- a/src/tabletop.js +++ b/src/tabletop.js @@ -368,11 +368,11 @@ if(ttIndexOf(this.model_names, model.name) === -1) { this.model_names.push(model.name); } - this.sheetsToLoad--; 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(); } @@ -392,11 +392,16 @@ var l = column_names.length; for (; i < l; i++) { - pretty_columns[column_names[i]] = data.feed.entry[i].content.$t; + 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(); },