From 8dba194013914995e669f3d74c1a3909fef32241 Mon Sep 17 00:00:00 2001 From: Aaron Boodman Date: Thu, 31 Jul 2014 12:30:29 -0700 Subject: [PATCH] Render containers with the camliContentImage attr as folders for now. Something fancier would be better, but without this change they'd get rendered as single images, which would be confusing. Change-Id: Icd08eb1716ae1f3bebe2f064388cac822a0a4e63 --- .../ui/blob_item_generic_content.js | 2 ++ .../camlistored/ui/blob_item_image_content.js | 22 +++++++++++++------ server/camlistored/ui/container_detail.js | 2 +- server/camlistored/ui/permanode_utils.js | 4 ++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/server/camlistored/ui/blob_item_generic_content.js b/server/camlistored/ui/blob_item_generic_content.js index 2e965a9c7..dc09ddac3 100644 --- a/server/camlistored/ui/blob_item_generic_content.js +++ b/server/camlistored/ui/blob_item_generic_content.js @@ -103,6 +103,7 @@ cam.BlobItemGenericContent.Handler.prototype.getAspectRatio = function() { }; cam.BlobItemGenericContent.Handler.prototype.createContent = function(size) { + // TODO(aa): In the case of a permanode that is a container (cam.permanodeUtils.isContainer()) and has a camliContentImage, it would be nice to show that image somehow along with the folder icon. return cam.BlobItemGenericContent({ href: this.href_, size: size, @@ -127,6 +128,7 @@ cam.BlobItemGenericContent.Handler.prototype.getThumbType_ = function() { } // Using the directory icon for any random permanode is a bit weird. Ideally we'd use file for that. The problem is that we can't tell the difference between a permanode that is representing an empty dynamic set and a permanode that is representing something else entirely. + // And unfortunately, the UI has a big prominent button that says 'new set', and it looks funny if the new set is shown as a file icon :( if (m.camliType == 'permanode') { return 'folder'; } diff --git a/server/camlistored/ui/blob_item_image_content.js b/server/camlistored/ui/blob_item_image_content.js index 9d1bcddd9..d9f420741 100644 --- a/server/camlistored/ui/blob_item_image_content.js +++ b/server/camlistored/ui/blob_item_image_content.js @@ -19,6 +19,7 @@ goog.provide('cam.BlobItemImageContent'); goog.require('goog.math.Size'); goog.require('cam.math'); +goog.require('cam.permanodeUtils'); goog.require('cam.PyramidThrobber'); goog.require('cam.Thumber'); @@ -110,13 +111,20 @@ cam.BlobItemImageContent.getHandler = function(blobref, searchSession, href) { } var m = searchSession.getMeta(blobref); - if (m.camliType == 'permanode') { - var cci = cam.permanodeUtils.getSingleAttr(m.permanode, 'camliContentImage'); - if (cci) { - var ccim = searchSession.getResolvedMeta(cci); - if (ccim) { - return new cam.BlobItemImageContent.Handler(ccim, href, searchSession.getTitle(blobref)); - } + if (m.camliType != 'permanode') { + return null; + } + + // Sets can have the camliContentImage attr to indicate a user-chosen "cover image" for the entire set. Until we have some rendering for those, the folder in the generic handler is a better fit than the single image. + if (cam.permanodeUtils.isContainer(m.permanode)) { + return null; + } + + var cci = cam.permanodeUtils.getSingleAttr(m.permanode, 'camliContentImage'); + if (cci) { + var ccim = searchSession.getResolvedMeta(cci); + if (ccim) { + return new cam.BlobItemImageContent.Handler(ccim, href, searchSession.getTitle(blobref)); } } diff --git a/server/camlistored/ui/container_detail.js b/server/camlistored/ui/container_detail.js index 0362524a3..facbc52dc 100644 --- a/server/camlistored/ui/container_detail.js +++ b/server/camlistored/ui/container_detail.js @@ -27,7 +27,7 @@ cam.ContainerDetail.getAspect = function(detailURL, handlers, history, getSearch } // TODO(aa): Also handle directories and static sets. - if (!goog.object.some(m.permanode.attr, function(v, k) { return k == 'camliMember' || goog.string.startsWith(k, 'camliPath:'); })) { + if (!cam.permanodeUtils.isContainer(m.permanode)) { return null; } diff --git a/server/camlistored/ui/permanode_utils.js b/server/camlistored/ui/permanode_utils.js index f88ed594a..f2db1b1ed 100644 --- a/server/camlistored/ui/permanode_utils.js +++ b/server/camlistored/ui/permanode_utils.js @@ -25,3 +25,7 @@ cam.permanodeUtils.getSingleAttr = function(permanode, name) { } return null; }; + +cam.permanodeUtils.isContainer = function(permanode) { + return goog.object.some(permanode.attr, function(v, k) { return k == 'camliMember' || goog.string.startsWith(k, 'camliPath:'); }); +};