Worksheets managed in GDoc Backend
This commit is contained in:
parent
cf3fe1a656
commit
f00a3a712e
@ -57,8 +57,8 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
|
|||||||
// :return: tabular data object (hash with keys: field and data).
|
// :return: tabular data object (hash with keys: field and data).
|
||||||
//
|
//
|
||||||
// Issues: seems google docs return columns in rows in random order and not even sure whether consistent across rows.
|
// Issues: seems google docs return columns in rows in random order and not even sure whether consistent across rows.
|
||||||
my.parseData = function(gdocsSpreadsheet) {
|
my.parseData = function(gdocsSpreadsheet, options) {
|
||||||
var options = arguments[1] || {};
|
var options = options || {};
|
||||||
var colTypes = options.colTypes || {};
|
var colTypes = options.colTypes || {};
|
||||||
var results = {
|
var results = {
|
||||||
fields : [],
|
fields : [],
|
||||||
@ -87,7 +87,6 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
|
|||||||
var value = entry[_keyname].$t;
|
var value = entry[_keyname].$t;
|
||||||
var num;
|
var num;
|
||||||
|
|
||||||
// TODO decide the entry format of percentage data to be parsed
|
|
||||||
// TODO cover this part of code with test
|
// TODO cover this part of code with test
|
||||||
// TODO use the regexp only once
|
// TODO use the regexp only once
|
||||||
// if labelled as % and value contains %, convert
|
// if labelled as % and value contains %, convert
|
||||||
@ -107,15 +106,16 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
|
|||||||
|
|
||||||
// Convenience function to get GDocs JSON API Url from standard URL
|
// Convenience function to get GDocs JSON API Url from standard URL
|
||||||
my.getSpreadsheetAPIUrl = function(url) {
|
my.getSpreadsheetAPIUrl = function(url) {
|
||||||
// https://docs.google.com/spreadsheet/ccc?key=XXXX#gid=0
|
// https://docs.google.com/spreadsheet/ccc?key=XXXX#gid=YYY
|
||||||
var regex = /.*spreadsheet\/ccc?.*key=([^#?&+]+).*/;
|
var regex = /.*spreadsheet\/ccc?.*key=([^#?&+]+).*gid=([\d]+).*/;
|
||||||
var matches = url.match(regex);
|
var matches = url.match(regex);
|
||||||
var key;
|
var key;
|
||||||
// TODO check possible worksheet options
|
var worksheet;
|
||||||
var worksheet = 1;
|
|
||||||
|
|
||||||
if(!!matches) {
|
if(!!matches) {
|
||||||
key = matches[1];
|
key = matches[1];
|
||||||
|
// the gid in url is 0-based and feed url is 1-based
|
||||||
|
worksheet = parseInt(matches[2]) + 1;
|
||||||
url = 'https://spreadsheets.google.com/feeds/list/'+ key +'/'+ worksheet +'/public/values?alt=json';
|
url = 'https://spreadsheets.google.com/feeds/list/'+ key +'/'+ worksheet +'/public/values?alt=json';
|
||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
|
|||||||
@ -191,9 +191,11 @@ test("GDocs Backend", function() {
|
|||||||
|
|
||||||
test("GDocs Backend.getUrl", function() {
|
test("GDocs Backend.getUrl", function() {
|
||||||
var key = 'Abc_dajkdkjdafkj';
|
var key = 'Abc_dajkdkjdafkj';
|
||||||
var url = 'https://docs.google.com/spreadsheet/ccc?key=' + key + '#gid=0'
|
var gid = 0;
|
||||||
|
var worksheet = 1;
|
||||||
|
var url = 'https://docs.google.com/spreadsheet/ccc?key=' + key + '#gid=' + gid
|
||||||
var out = recline.Backend.GDocs.getSpreadsheetAPIUrl(url);
|
var out = recline.Backend.GDocs.getSpreadsheetAPIUrl(url);
|
||||||
var exp = 'https://spreadsheets.google.com/feeds/list/' + key + '/1/public/values?alt=json'
|
var exp = 'https://spreadsheets.google.com/feeds/list/' + key + '/' + worksheet + '/public/values?alt=json'
|
||||||
equal(exp, out);
|
equal(exp, out);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user