[#166,closed,gdocs/backend] Added title to GDocs backend metadata

This commit is contained in:
Krzysztof Trzewiczek
2012-08-09 17:59:25 +02:00
parent d7fc9ba1f8
commit 532f777f78
4 changed files with 219 additions and 106 deletions

View File

@@ -55,6 +55,7 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
dfd.resolve({ dfd.resolve({
metadata: { metadata: {
title: response.spreadsheetTitle +" :: "+ result.worksheetTitle,
spreadsheetTitle: response.spreadsheetTitle, spreadsheetTitle: response.spreadsheetTitle,
worksheetTitle : result.worksheetTitle worksheetTitle : result.worksheetTitle
}, },

View File

@@ -523,7 +523,8 @@ my.Query = Backbone.Model.extend({
// crude deep copy // crude deep copy
var ourfilter = JSON.parse(JSON.stringify(filter)); var ourfilter = JSON.parse(JSON.stringify(filter));
// not full specified so use template and over-write // not full specified so use template and over-write
if (_.keys(filter).length <= 2) { // 3 as for 'type', 'field' and 'fieldType'
if (_.keys(filter).length <= 3) {
ourfilter = _.extend(this._filterTemplates[filter.type], ourfilter); ourfilter = _.extend(this._filterTemplates[filter.type], ourfilter);
} }
var filters = this.get('filters'); var filters = this.get('filters');

View File

@@ -1,170 +1,275 @@
(function ($) { (function ($) {
module("Backend GDocs"); module("Backend GDocs");
var sample_gdocs_spreadsheet_data = { var sampleGDocsSpreadsheetMetadata = {
"feed": { feed: {
"category": [ category: [
{
term: "http://schemas.google.com/spreadsheets/2006#worksheet",
scheme: "http://schemas.google.com/spreadsheets/2006"
}
],
updated: {
$t: "2010-07-13T09:57:28.408Z"
},
xmlns: "http://www.w3.org/2005/Atom",
title: {
$t: "javascript-test",
type: "text"
},
author: [
{
name: {
$t: "okfn.rufus.pollock"
},
email: {
$t: "okfn.rufus.pollock@gmail.com"
}
}
],
openSearch$startIndex: {
$t: "1"
},
xmlns$gs: "http://schemas.google.com/spreadsheets/2006",
xmlns$openSearch: "http://a9.com/-/spec/opensearchrss/1.0/",
entry: [
{
category: [
{
term: "http://schemas.google.com/spreadsheets/2006#worksheet",
scheme: "http://schemas.google.com/spreadsheets/2006"
}
],
updated: {
$t: "2010-07-13T09:57:28.408Z"
},
title: {
$t: "Sheet1",
type: "text"
},
content: {
$t: "Sheet1",
type: "text"
},
link: [
{
href: "https://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/basic",
type: "application/atom+xml",
rel: "http://schemas.google.com/spreadsheets/2006#listfeed"
},
{
href: "https://spreadsheets.google.com/feeds/cells/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/basic",
type: "application/atom+xml",
rel: "http://schemas.google.com/spreadsheets/2006#cellsfeed"
},
{
href: "https://spreadsheets.google.com/tq?key=0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc&sheet=od6&pub=1",
type: "application/atom+xml",
rel: "http://schemas.google.com/visualization/2008#visualizationApi"
},
{
href: "https://spreadsheets.google.com/feeds/worksheets/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/public/basic/od6",
type: "application/atom+xml",
rel: "self"
}
],
id: {
$t: "https://spreadsheets.google.com/feeds/worksheets/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/public/basic/od6"
}
}
],
link: [
{
href: "https://spreadsheets.google.com/pub?key=0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc",
type: "text/html",
rel: "alternate"
},
{
href: "https://spreadsheets.google.com/feeds/worksheets/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/public/basic",
type: "application/atom+xml",
rel: "http://schemas.google.com/g/2005#feed"
},
{
href: "https://spreadsheets.google.com/feeds/worksheets/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/public/basic?alt=json",
type: "application/atom+xml",
rel: "self"
}
],
openSearch$totalResults: {
$t: "1"
},
id: {
$t: "https://spreadsheets.google.com/feeds/worksheets/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/public/basic"
}
},
version: "1.0",
encoding: "UTF-8"
}
var sampleGDocsSpreadsheetData = {
feed: {
category: [
{ {
"term": "http://schemas.google.com/spreadsheets/2006#list", term: "http://schemas.google.com/spreadsheets/2006#list",
"scheme": "http://schemas.google.com/spreadsheets/2006" scheme: "http://schemas.google.com/spreadsheets/2006"
} }
], ],
"updated": { updated: {
"$t": "2010-07-12T18:32:16.200Z" $t: "2010-07-12T18:32:16.200Z"
}, },
"xmlns": "http://www.w3.org/2005/Atom", xmlns: "http://www.w3.org/2005/Atom",
"xmlns$gsx": "http://schemas.google.com/spreadsheets/2006/extended", xmlns$gsx: "http://schemas.google.com/spreadsheets/2006/extended",
"title": { title: {
"$t": "Sheet1", $t: "Sheet1",
"type": "text" type: "text"
}, },
"author": [ author: [
{ {
"name": { name: {
"$t": "okfn.rufus.pollock" $t: "okfn.rufus.pollock"
}, },
"email": { email: {
"$t": "okfn.rufus.pollock@gmail.com" $t: "okfn.rufus.pollock@gmail.com"
} }
} }
], ],
"openSearch$startIndex": { openSearch$startIndex: {
"$t": "1" $t: "1"
}, },
"link": [ link: [
{ {
"href": "http://spreadsheets.google.com/pub?key=0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc", href: "http://spreadsheets.google.com/pub?key=0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc",
"type": "text/html", type: "text/html",
"rel": "alternate" rel: "alternate"
}, },
{ {
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values", href: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values",
"type": "application/atom+xml", type: "application/atom+xml",
"rel": "http://schemas.google.com/g/2005#feed" rel: "http://schemas.google.com/g/2005#feed"
}, },
{ {
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json-in-script", href: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values?alt=json-in-script",
"type": "application/atom+xml", type: "application/atom+xml",
"rel": "self" rel: "self"
} }
], ],
"xmlns$openSearch": "http://a9.com/-/spec/opensearchrss/1.0/", xmlns$openSearch: "http://a9.com/-/spec/opensearchrss/1.0/",
"entry": [ entry: [
{ {
"category": [ category: [
{ {
"term": "http://schemas.google.com/spreadsheets/2006#list", term: "http://schemas.google.com/spreadsheets/2006#list",
"scheme": "http://schemas.google.com/spreadsheets/2006" scheme: "http://schemas.google.com/spreadsheets/2006"
} }
], ],
"updated": { updated: {
"$t": "2010-07-12T18:32:16.200Z" $t: "2010-07-12T18:32:16.200Z"
}, },
"gsx$column-2": { 'gsx$column-2': {
"$t": "1" $t: "1"
}, },
"gsx$column-1": { 'gsx$column-1': {
"$t": "A" $t: "A"
}, },
"title": { title: {
"$t": "A", $t: "A",
"type": "text" type: "text"
}, },
"content": { content: {
"$t": "column-2: 1", $t: "column-2: 1",
"type": "text" type: "text"
}, },
"link": [ link: [
{ {
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr", href: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr",
"type": "application/atom+xml", type: "application/atom+xml",
"rel": "self" rel: "self"
} }
], ],
"id": { id: {
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr" $t: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cokwr"
} }
}, },
{ {
"category": [ category: [
{ {
"term": "http://schemas.google.com/spreadsheets/2006#list", term: "http://schemas.google.com/spreadsheets/2006#list",
"scheme": "http://schemas.google.com/spreadsheets/2006" scheme: "http://schemas.google.com/spreadsheets/2006"
} }
], ],
"updated": { updated: {
"$t": "2010-07-12T18:32:16.200Z" $t: "2010-07-12T18:32:16.200Z"
}, },
"gsx$column-2": { 'gsx$column-2': {
"$t": "2" $t: "2"
}, },
"gsx$column-1": { 'gsx$column-1': {
"$t": "b" $t: "b"
}, },
"title": { title: {
"$t": "b", $t: "b",
"type": "text" type: "text"
}, },
"content": { content: {
"$t": "column-2: 2", $t: "column-2: 2",
"type": "text" type: "text"
}, },
"link": [ link: [
{ {
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4", href: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4",
"type": "application/atom+xml", type: "application/atom+xml",
"rel": "self" rel: "self"
} }
], ],
"id": { id: {
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4" $t: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cpzh4"
} }
}, },
{ {
"category": [ category: [
{ {
"term": "http://schemas.google.com/spreadsheets/2006#list", term: "http://schemas.google.com/spreadsheets/2006#list",
"scheme": "http://schemas.google.com/spreadsheets/2006" scheme: "http://schemas.google.com/spreadsheets/2006"
} }
], ],
"updated": { updated: {
"$t": "2010-07-12T18:32:16.200Z" $t: "2010-07-12T18:32:16.200Z"
}, },
"gsx$column-2": { 'gsx$column-2': {
"$t": "3" $t: "3"
}, },
"gsx$column-1": { 'gsx$column-1': {
"$t": "c" $t: "c"
}, },
"title": { title: {
"$t": "c", $t: "c",
"type": "text" type: "text"
}, },
"content": { content: {
"$t": "column-2: 3", $t: "column-2: 3",
"type": "text" type: "text"
}, },
"link": [ link: [
{ {
"href": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l", href: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l",
"type": "application/atom+xml", type: "application/atom+xml",
"rel": "self" rel: "self"
} }
], ],
"id": { id: {
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l" $t: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values/cre1l"
} }
} }
], ],
"openSearch$totalResults": { openSearch$totalResults: {
"$t": "3" $t: "3"
}, },
"id": { id: {
"$t": "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values" $t: "http://spreadsheets.google.com/feeds/list/0Aon3JiuouxLUdDQwZE1JdV94cUd6NWtuZ0IyWTBjLWc/od6/public/values"
} }
}, },
"version": "1.0", version: "1.0",
"encoding": "UTF-8" encoding: "UTF-8"
} }
test("GDocs Backend", function() { test("GDocs Backend", function() {
@@ -174,9 +279,14 @@ test("GDocs Backend", function() {
}); });
var stub = sinon.stub($, 'getJSON', function(options, cb) { var stub = sinon.stub($, 'getJSON', function(options, cb) {
var partialUrl = 'spreadsheets.google.com'; var spreadsheetUrl = 'spreadsheets.google.com/feeds/worksheets/';
if (options.indexOf(partialUrl) != -1) { var worksheetUrl = 'spreadsheets.google.com/feeds/list/';
cb(sample_gdocs_spreadsheet_data)
if (options.indexOf(spreadsheetUrl) !== -1) {
cb(sampleGDocsSpreadsheetMetadata)
}
else if(options.indexOf(worksheetUrl) !== -1) {
cb(sampleGDocsSpreadsheetData)
} }
}); });
@@ -185,6 +295,7 @@ test("GDocs Backend", function() {
deepEqual(['column-2', 'column-1'], _.pluck(dataset.fields.toJSON(), 'id')); deepEqual(['column-2', 'column-1'], _.pluck(dataset.fields.toJSON(), 'id'));
equal(3, docList.length); equal(3, docList.length);
equal("A", docList.models[0].get('column-1')); equal("A", docList.models[0].get('column-1'));
equal('javascript-test :: Sheet1', dataset.get('title'));
}); });
$.getJSON.restore(); $.getJSON.restore();
}); });

View File

@@ -55,8 +55,8 @@ test('geo_distance', function () {
// now check we have new filter // now check we have new filter
$editForm = view.el.find('form.js-edit'); $editForm = view.el.find('form.js-edit');
equal($editForm.find('.filter-geo_distance').length, 1) equal($editForm.find('.filter-geo_distance').length, 1)
deepEqual(_.keys(dataset.queryState.attributes.filters[0]), ['distance', deepEqual(_.sortBy(_.keys(dataset.queryState.attributes.filters[0]),_.identity),
'unit', 'point', 'type', 'field']); ["distance", "field", "fieldType", "point", "type", "unit"]);
// now set filter value and apply // now set filter value and apply
$editForm.find('input[name="lat"]').val(10); $editForm.find('input[name="lat"]').val(10);