From 8ded93008af9e1fb4f0e70522cc116af43eca0b8 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Fri, 12 Aug 2011 21:32:45 +0000 Subject: [PATCH] Generalized GData document listing to support other types of document in the future. git-svn-id: http://google-refine.googlecode.com/svn/trunk@2199 7d457c2a-affb-35e4-300a-418c747d4874 --- .../module/scripts/index/gdata-source-ui.js | 16 ++++- .../scripts/index/import-from-gdata-form.html | 2 +- .../module/styles/importing-controller.less | 8 ++- .../gdata/GDataImportingController.java | 62 ++++++++++++------- main/webapp/modules/core/scripts/util/misc.js | 4 +- 5 files changed, 61 insertions(+), 31 deletions(-) diff --git a/extensions/gdata/module/scripts/index/gdata-source-ui.js b/extensions/gdata/module/scripts/index/gdata-source-ui.js index 72ca0173d..e21715ddd 100644 --- a/extensions/gdata/module/scripts/index/gdata-source-ui.js +++ b/extensions/gdata/module/scripts/index/gdata-source-ui.js @@ -99,6 +99,7 @@ Refine.GDataSourceUI.prototype._renderDocuments = function(o) { var table = $( '' + '' + // starred + '' + '' + '' + '' + @@ -112,7 +113,10 @@ Refine.GDataSourceUI.prototype._renderDocuments = function(o) { if (doc.isStarred) { $('').attr('src', 'images/star.png').appendTo(td); } - + + td = tr.insertCell(tr.cells.length); + $('').text(doc.type).appendTo(td); + td = tr.insertCell(tr.cells.length); var title = $('') .addClass('gdata-doc-title') @@ -132,6 +136,7 @@ Refine.GDataSourceUI.prototype._renderDocuments = function(o) { td = tr.insertCell(tr.cells.length); $('') + .addClass('gdata-doc-authors') .text(doc.authors.join(', ')) .appendTo(td); @@ -144,8 +149,13 @@ Refine.GDataSourceUI.prototype._renderDocuments = function(o) { .appendTo(td); } }; - for (var i = 0; i < o.documents.length; i++) { - renderDocument(o.documents[i]); + + var docs = o.documents; + $.each(docs, function() { this.updatedDate = (this.updated) ? new Date(this.updated) : new Date(); }); + docs.sort(function(a, b) { return b.updatedDate.getTime() - a.updatedDate.getTime(); }); + + for (var i = 0; i < docs.length; i++) { + renderDocument(docs[i]); } this._body.find('.gdata-page').hide(); diff --git a/extensions/gdata/module/scripts/index/import-from-gdata-form.html b/extensions/gdata/module/scripts/index/import-from-gdata-form.html index 9b4a7bea0..3b4596d51 100644 --- a/extensions/gdata/module/scripts/index/import-from-gdata-form.html +++ b/extensions/gdata/module/scripts/index/import-from-gdata-form.html @@ -11,6 +11,6 @@ - +
TypeTitleAuthorsUpdatedGoogle Docs documents with another account
\ No newline at end of file diff --git a/extensions/gdata/module/styles/importing-controller.less b/extensions/gdata/module/styles/importing-controller.less index da04a65e1..672f07dd3 100644 --- a/extensions/gdata/module/styles/importing-controller.less +++ b/extensions/gdata/module/styles/importing-controller.less @@ -39,6 +39,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. height: 500px; } +.gdata-document-container > table { + color: @metadata_grey; +} + a.gdata-doc-title { color: @link_primary; text-decoration: none; @@ -61,8 +65,10 @@ a.gdata-doc-preview:hover { text-decoration: underline; } +.gdata-doc-authors { +} + .gdata-doc-date { - color: @metadata_grey; } .gdata-importing-wizard-header { diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java b/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java index 5c65fd23f..852a13a1b 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java @@ -49,12 +49,15 @@ import org.json.JSONException; import org.json.JSONObject; import org.json.JSONWriter; +import com.google.gdata.client.Query; import com.google.gdata.client.docs.DocsService; import com.google.gdata.client.spreadsheet.SpreadsheetService; +import com.google.gdata.data.Category; import com.google.gdata.data.DateTime; import com.google.gdata.data.Person; +import com.google.gdata.data.docs.DocumentListEntry; +import com.google.gdata.data.docs.DocumentListFeed; import com.google.gdata.data.spreadsheet.SpreadsheetEntry; -import com.google.gdata.data.spreadsheet.SpreadsheetFeed; import com.google.gdata.data.spreadsheet.WorksheetEntry; import com.google.gdata.util.ServiceException; @@ -121,29 +124,7 @@ public class GDataImportingController implements ImportingController { try { DocsService service = getDocsService(token); - - URL metafeedUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full"); - SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class); - for (SpreadsheetEntry entry : feed.getEntries()) { - writer.object(); - writer.key("docId"); writer.value(entry.getId()); - writer.key("docLink"); writer.value(entry.getHtmlLink().getHref()); - writer.key("docSelfLink"); writer.value(entry.getSelfLink().getHref()); - writer.key("title"); writer.value(entry.getTitle().getPlainText()); - - DateTime updated = entry.getUpdated(); - if (updated != null) { - writer.key("updated"); writer.value(updated.toStringRfc822()); - } - - writer.key("authors"); writer.array(); - for (Person person : entry.getAuthors()) { - writer.value(person.getName()); - } - writer.endArray(); - - writer.endObject(); - } + listDocumentsOfType(service, writer, "http://schemas.google.com/docs/2007#spreadsheet"); } catch (ServiceException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -159,6 +140,39 @@ public class GDataImportingController implements ImportingController { } } + private void listDocumentsOfType(DocsService service, JSONWriter writer, String type) + throws IOException, ServiceException, JSONException { + URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full"); + + Query query = new Query(feedUrl); + query.addCategoryFilter( + new Query.CategoryFilter( + new Category("http://schemas.google.com/g/2005#kind", type))); + + DocumentListFeed feed = service.query(query, DocumentListFeed.class); + for (DocumentListEntry entry : feed.getEntries()) { + writer.object(); + writer.key("docId"); writer.value(entry.getId()); + writer.key("docLink"); writer.value(entry.getHtmlLink().getHref()); + writer.key("docSelfLink"); writer.value(entry.getSelfLink().getHref()); + writer.key("title"); writer.value(entry.getTitle().getPlainText()); + writer.key("type"); writer.value(entry.getType()); + + DateTime updated = entry.getUpdated(); + if (updated != null) { + writer.key("updated"); writer.value(updated.toStringRfc822()); + } + + writer.key("authors"); writer.array(); + for (Person person : entry.getAuthors()) { + writer.value(person.getName()); + } + writer.endArray(); + + writer.endObject(); + } + } + private void doInitializeParserUI( HttpServletRequest request, HttpServletResponse response, Properties parameters) throws ServletException, IOException { diff --git a/main/webapp/modules/core/scripts/util/misc.js b/main/webapp/modules/core/scripts/util/misc.js index 06790c642..2e1f2b84b 100644 --- a/main/webapp/modules/core/scripts/util/misc.js +++ b/main/webapp/modules/core/scripts/util/misc.js @@ -64,10 +64,10 @@ function formatRelativeDate(d) { var tomorrow = Date.today().add({ days: 1 }); if (d.between(today, tomorrow)) { - return "today " + d.toString("H:mm tt"); + return "today " + d.toString("h:mm tt"); } else if (d.between(last_week, today)) { var diff = Math.floor(today.getDayOfYear() - d.getDayOfYear()); - return (diff <= 1) ? ("yesterday " + d.toString("H:mm tt")) : (diff + " days ago"); + return (diff <= 1) ? ("yesterday " + d.toString("h:mm tt")) : (diff + " days ago"); } else if (d.between(last_month, today)) { var diff = Math.floor((today.getDayOfYear() - d.getDayOfYear()) / 7); return (diff == 1) ? "a week ago" : diff.toFixed(0) + " weeks ago" ;