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
This commit is contained in:
David Huynh 2011-08-12 21:32:45 +00:00
parent e955ed05ae
commit 8ded93008a
5 changed files with 61 additions and 31 deletions

View File

@ -99,6 +99,7 @@ Refine.GDataSourceUI.prototype._renderDocuments = function(o) {
var table = $(
'<table><tr>' +
'<th></th>' + // starred
'<th>Type</th>' +
'<th>Title</th>' +
'<th>Authors</th>' +
'<th>Updated</th>' +
@ -112,7 +113,10 @@ Refine.GDataSourceUI.prototype._renderDocuments = function(o) {
if (doc.isStarred) {
$('<img>').attr('src', 'images/star.png').appendTo(td);
}
td = tr.insertCell(tr.cells.length);
$('<span>').text(doc.type).appendTo(td);
td = tr.insertCell(tr.cells.length);
var title = $('<a>')
.addClass('gdata-doc-title')
@ -132,6 +136,7 @@ Refine.GDataSourceUI.prototype._renderDocuments = function(o) {
td = tr.insertCell(tr.cells.length);
$('<span>')
.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();

View File

@ -11,6 +11,6 @@
<td>Google Docs documents</td>
<td style="text-align: right;"><button class="gdata-signin button">re-sign in</button> with another account</td>
</tr>
<tr><td colspan="2"><div bind="listingContainer" class="grid-layout layout-tight"></div></td></tr>
<tr><td colspan="2"><div bind="listingContainer" class="grid-layout layout-tight gdata-document-container"></div></td></tr>
</table></div>
</div>

View File

@ -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 {

View File

@ -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 {

View File

@ -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" ;